Migrate to TouchGFX 4.22.0
This commit is contained in:
		@ -1,4 +1,4 @@
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:1
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:1 FU:0
 | 
			
		||||
32
 | 
			
		||||
37
 | 
			
		||||
46
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:0
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:0 FU:0
 | 
			
		||||
32
 | 
			
		||||
45
 | 
			
		||||
48
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:0
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:0 FU:0
 | 
			
		||||
32
 | 
			
		||||
33
 | 
			
		||||
63
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:1
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:1 FU:0
 | 
			
		||||
44
 | 
			
		||||
45
 | 
			
		||||
46
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:0
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:0 FU:0
 | 
			
		||||
32
 | 
			
		||||
44
 | 
			
		||||
45
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:1
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:1 FU:0
 | 
			
		||||
32
 | 
			
		||||
33
 | 
			
		||||
34
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:1
 | 
			
		||||
AH:0 BA:1 FC:63 EC:0 FF:0 CF:1 FU:0
 | 
			
		||||
32
 | 
			
		||||
33
 | 
			
		||||
34
 | 
			
		||||
 | 
			
		||||
@ -49,6 +49,7 @@ public:
 | 
			
		||||
    virtual int8_t getKerning(Unicode::UnicodeChar prevChar, const GlyphNode* glyph) const;
 | 
			
		||||
 | 
			
		||||
    void setFontCache(FontCache& cache);
 | 
			
		||||
 | 
			
		||||
    FontId getFontId() const
 | 
			
		||||
    {
 | 
			
		||||
        return fontId;
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@ public:
 | 
			
		||||
    virtual ~FontDataReader()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void open() = 0;
 | 
			
		||||
    virtual void close() = 0;
 | 
			
		||||
    virtual void setPosition(uint32_t position) = 0;
 | 
			
		||||
@ -36,6 +37,7 @@ public:
 | 
			
		||||
    bool cacheLigatures(CachedFont* font, TypedText t, const Unicode::UnicodeChar* string);
 | 
			
		||||
 | 
			
		||||
    const GlyphNode* getGlyph(Unicode::UnicodeChar unicode, FontId font) const;
 | 
			
		||||
 | 
			
		||||
    uint32_t getMemoryUsage()
 | 
			
		||||
    {
 | 
			
		||||
        return memorySize - (gsubStart - top);
 | 
			
		||||
@ -46,8 +48,9 @@ public:
 | 
			
		||||
 | 
			
		||||
    static inline const uint8_t* getPixelData(const GlyphNode* glyph)
 | 
			
		||||
    {
 | 
			
		||||
        return ((const uint8_t*)glyph) + SizeGlyphNode + 4;
 | 
			
		||||
        return ((const uint8_t*)glyph) + SizeGlyphNode + sizeof(void*);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static inline bool isCached(const GlyphNode* g)
 | 
			
		||||
    {
 | 
			
		||||
        return g->dataOffset == 0xFFFFFFFF;
 | 
			
		||||
@ -57,10 +60,10 @@ private:
 | 
			
		||||
    static const uint32_t SizeGlyphNode = 16;
 | 
			
		||||
 | 
			
		||||
    bool contains(Unicode::UnicodeChar unicode, FontId font) const;
 | 
			
		||||
    void insert(Unicode::UnicodeChar unicode, FontId font, uint32_t bpp, bool& outOfMemory);
 | 
			
		||||
    uint8_t* copyGlyph(uint8_t* top, Unicode::UnicodeChar unicode, FontId font, uint32_t bpp, bool& outOfMemory);
 | 
			
		||||
    void insert(Unicode::UnicodeChar unicode, FontId font, bool& outOfMemory);
 | 
			
		||||
    uint8_t* copyGlyph(uint8_t* top, Unicode::UnicodeChar unicode, FontId font, bool& outOfMemory);
 | 
			
		||||
 | 
			
		||||
    void cacheData(uint32_t bpp, GlyphNode* first);
 | 
			
		||||
    void cacheData(GlyphNode* first);
 | 
			
		||||
    bool cacheSortedString(TypedText t);
 | 
			
		||||
    bool createSortedString(const Unicode::UnicodeChar* string);
 | 
			
		||||
    bool createSortedLigatures(CachedFont* font, TypedText t, const Unicode::UnicodeChar* string, ...);
 | 
			
		||||
@ -69,6 +72,17 @@ private:
 | 
			
		||||
    void setPosition(uint32_t position);
 | 
			
		||||
    void readData(void* out, uint32_t numberOfBytes);
 | 
			
		||||
 | 
			
		||||
    uint32_t getGlyphSize(const GlyphNode* gn)
 | 
			
		||||
    {
 | 
			
		||||
        if (byteAlignRow)
 | 
			
		||||
        {
 | 
			
		||||
            // Round up line width to byte boundary and multiply by height
 | 
			
		||||
            return (gn->width() * bpp + 7) / 8 * gn->height();
 | 
			
		||||
        }
 | 
			
		||||
        // Calculate number of pixels and round up to byte bounday
 | 
			
		||||
        return (gn->width() * gn->height() * bpp + 7) / 8;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    struct
 | 
			
		||||
    {
 | 
			
		||||
        uint8_t* first; // First GlyphNode, glyph in cache;
 | 
			
		||||
@ -89,6 +103,8 @@ private:
 | 
			
		||||
    uint32_t glyphDataOffset;
 | 
			
		||||
    uint16_t numGlyphs;
 | 
			
		||||
    uint16_t currentFileGlyphNumber;
 | 
			
		||||
    uint8_t bpp;
 | 
			
		||||
    uint8_t byteAlignRow;
 | 
			
		||||
    GlyphNode currentFileGlyphNode;
 | 
			
		||||
};
 | 
			
		||||
} // namespace touchgfx
 | 
			
		||||
 | 
			
		||||
@ -42,6 +42,21 @@ protected:
 | 
			
		||||
    const FontContextualFormsTable* arabicTable; ///< Contextual forms
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class FusedFont : public GeneratedFont
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FusedFont(const GlyphNode* glyphs, uint16_t numGlyphs, uint16_t height, uint16_t baseline, uint8_t pixAboveTop, uint8_t pixBelowBottom, uint8_t bitsPerPixel, uint8_t byteAlignRow, uint8_t maxLeft, uint8_t maxRight, const uint8_t* const* glyphDataInternalFlash, const KerningNode* kerningList, const Unicode::UnicodeChar fallbackChar, const Unicode::UnicodeChar ellipsisChar, const uint16_t* const gsubData, const FontContextualFormsTable* formsTable, GlyphNode& fontFusedNode)
 | 
			
		||||
        : GeneratedFont(glyphs, numGlyphs, height, baseline, pixAboveTop, pixBelowBottom, bitsPerPixel, byteAlignRow,
 | 
			
		||||
                        maxLeft, maxRight, glyphDataInternalFlash, kerningList, fallbackChar, ellipsisChar,
 | 
			
		||||
                        gsubData, formsTable), fusedNode(fontFusedNode)
 | 
			
		||||
    { }
 | 
			
		||||
 | 
			
		||||
    using GeneratedFont::getGlyph;
 | 
			
		||||
    virtual const GlyphNode* getGlyph(Unicode::UnicodeChar unicode, const uint8_t*& pixelData, uint8_t& bitsPerPixel) const;
 | 
			
		||||
private:
 | 
			
		||||
    GlyphNode& fusedNode;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct BinaryFontData
 | 
			
		||||
{
 | 
			
		||||
    uint32_t fontIndex;                // The font index (as used by TypedTextDatabase)
 | 
			
		||||
@ -110,6 +125,7 @@ protected:
 | 
			
		||||
private:
 | 
			
		||||
    typedef const Unicode::UnicodeChar (*array5ptr)[5];
 | 
			
		||||
    typedef const Unicode::UnicodeChar (*array4ptr)[4];
 | 
			
		||||
 | 
			
		||||
    void setupContextualTable(const struct touchgfx::BinaryFontData* data)
 | 
			
		||||
    {
 | 
			
		||||
        const uint16_t* const base = (const uint16_t*)(((const uint8_t*)data) + data->offsetToArabicTable);
 | 
			
		||||
 | 
			
		||||
@ -107,6 +107,7 @@ protected:
 | 
			
		||||
        : Font(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), glyphList(0), unicodes(0), glyphDataList(0), kerningData(0), gsubTable(0)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int lookupUnicode(uint16_t unicode) const;
 | 
			
		||||
 | 
			
		||||
    const GlyphNode* glyphList;     ///< The list of glyphs
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,7 @@ void FontCache::clear(bool keepGsubOrContextTable /* = false */)
 | 
			
		||||
        gsubStart = memory + memorySize;
 | 
			
		||||
 | 
			
		||||
        // Round down to 32bit address
 | 
			
		||||
        gsubStart = (uint8_t*)((uintptr_t)gsubStart & ~(uintptr_t)0x3);
 | 
			
		||||
        gsubStart = (uint8_t*)((uintptr_t)gsubStart & ~(sizeof(void*) - 1));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -100,13 +100,11 @@ void FontCache::initializeCachedFont(TypedText t, CachedFont* font, bool loadGsu
 | 
			
		||||
 | 
			
		||||
        if (top + sizeOfGSUB < gsubStart) // Room for this GSUB table
 | 
			
		||||
        {
 | 
			
		||||
            uint8_t* const gsubPosition = gsubStart - sizeOfGSUB;
 | 
			
		||||
            // Round down to aligned address
 | 
			
		||||
            uint8_t* const gsubPosition = (uint8_t*)((uintptr_t)(gsubStart - sizeOfGSUB) & ~(sizeof(void*) - 1));
 | 
			
		||||
            readData(gsubPosition, sizeOfGSUB);
 | 
			
		||||
            font->setGSUBTable(reinterpret_cast<uint16_t*>(gsubPosition));
 | 
			
		||||
            gsubStart -= sizeOfGSUB;
 | 
			
		||||
 | 
			
		||||
            // Round down to 32bit address
 | 
			
		||||
            gsubStart = (uint8_t*)((uintptr_t)gsubStart & ~(uintptr_t)0x3);
 | 
			
		||||
            gsubStart = gsubPosition;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
@ -125,7 +123,7 @@ void FontCache::initializeCachedFont(TypedText t, CachedFont* font, bool loadGsu
 | 
			
		||||
            // Allocate FontContextualFormsTable first
 | 
			
		||||
            gsubStart -= sizeof(FontContextualFormsTable);
 | 
			
		||||
            // Round down to 32bit address
 | 
			
		||||
            gsubStart = (uint8_t*)((uintptr_t)gsubStart & ~(uintptr_t)0x3);
 | 
			
		||||
            gsubStart = (uint8_t*)((uintptr_t)gsubStart & ~(sizeof(void*) - 1));
 | 
			
		||||
 | 
			
		||||
            FontContextualFormsTable* table = (FontContextualFormsTable*)gsubStart;
 | 
			
		||||
            font->setContextualFormsTable(table);
 | 
			
		||||
@ -194,7 +192,8 @@ bool FontCache::cacheSortedString(TypedText t)
 | 
			
		||||
    readData(&numGlyphs, sizeof(uint16_t));       // numberOfGlyphs
 | 
			
		||||
 | 
			
		||||
    FontId fontId = t.getFontId();                 // Get font index from typed text
 | 
			
		||||
    uint32_t bpp = t.getFont()->getBitsPerPixel(); // Get BPP from standard font
 | 
			
		||||
    bpp = t.getFont()->getBitsPerPixel();          // Get BPP from standard font
 | 
			
		||||
    byteAlignRow = t.getFont()->getByteAlignRow(); // Get ByteAlign from font
 | 
			
		||||
 | 
			
		||||
    setPosition(glyphNodeOffset); // Go to glyph nodes for font
 | 
			
		||||
    currentFileGlyphNumber = 0;
 | 
			
		||||
@ -211,7 +210,7 @@ bool FontCache::cacheSortedString(TypedText t)
 | 
			
		||||
        {
 | 
			
		||||
            if (!contains(ch, fontId))
 | 
			
		||||
            {
 | 
			
		||||
                insert(ch, fontId, bpp, outOfMemory);
 | 
			
		||||
                insert(ch, fontId, outOfMemory);
 | 
			
		||||
                if (outOfMemory)
 | 
			
		||||
                {
 | 
			
		||||
                    break;
 | 
			
		||||
@ -226,7 +225,7 @@ bool FontCache::cacheSortedString(TypedText t)
 | 
			
		||||
        string++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cacheData(bpp, firstNewGlyph);
 | 
			
		||||
    cacheData(firstNewGlyph);
 | 
			
		||||
    return !outOfMemory;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -245,11 +244,11 @@ bool FontCache::contains(Unicode::UnicodeChar unicode, FontId font) const
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FontCache::insert(Unicode::UnicodeChar unicode, FontId font, uint32_t bpp, bool& outOfMemory)
 | 
			
		||||
void FontCache::insert(Unicode::UnicodeChar unicode, FontId font, bool& outOfMemory)
 | 
			
		||||
{
 | 
			
		||||
    // Insert new glyphnode and glyph after last for font.
 | 
			
		||||
    uint8_t* oldTop = top;
 | 
			
		||||
    top = copyGlyph(top, unicode, font, bpp, outOfMemory);
 | 
			
		||||
    top = copyGlyph(top, unicode, font, outOfMemory);
 | 
			
		||||
 | 
			
		||||
    if (top == oldTop)
 | 
			
		||||
    {
 | 
			
		||||
@ -273,7 +272,7 @@ void FontCache::insert(Unicode::UnicodeChar unicode, FontId font, uint32_t bpp,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t* FontCache::copyGlyph(uint8_t* top, Unicode::UnicodeChar unicode, FontId font, uint32_t bpp, bool& outOfMemory)
 | 
			
		||||
uint8_t* FontCache::copyGlyph(uint8_t* top, Unicode::UnicodeChar unicode, FontId font, bool& outOfMemory)
 | 
			
		||||
{
 | 
			
		||||
    while (currentFileGlyphNumber < numGlyphs && currentFileGlyphNode.unicode < unicode)
 | 
			
		||||
    {
 | 
			
		||||
@ -287,9 +286,10 @@ uint8_t* FontCache::copyGlyph(uint8_t* top, Unicode::UnicodeChar unicode, FontId
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // GlyphNode found
 | 
			
		||||
    uint32_t glyphSize = ((currentFileGlyphNode.width() + 1) & ~1) * currentFileGlyphNode.height() * bpp / 8;
 | 
			
		||||
    glyphSize = (glyphSize + 3) & ~0x03;
 | 
			
		||||
    uint32_t requiredMem = SizeGlyphNode + 4 + glyphSize; // GlyphNode + next ptr + glyph
 | 
			
		||||
    uint32_t glyphSize = getGlyphSize(¤tFileGlyphNode);
 | 
			
		||||
    const int alignment = sizeof(void*);
 | 
			
		||||
    glyphSize = (glyphSize + (alignment - 1)) & ~(alignment - 1);
 | 
			
		||||
    uint32_t requiredMem = SizeGlyphNode + sizeof(void*) + glyphSize; // GlyphNode + next ptr + glyph
 | 
			
		||||
 | 
			
		||||
    // Is space available before sortedString
 | 
			
		||||
    if (top + requiredMem > (uint8_t*)sortedString)
 | 
			
		||||
@ -307,7 +307,7 @@ uint8_t* FontCache::copyGlyph(uint8_t* top, Unicode::UnicodeChar unicode, FontId
 | 
			
		||||
    return top;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FontCache::cacheData(uint32_t bpp, GlyphNode* first)
 | 
			
		||||
void FontCache::cacheData(GlyphNode* first)
 | 
			
		||||
{
 | 
			
		||||
    GlyphNode* gn = first;
 | 
			
		||||
    while (gn)
 | 
			
		||||
@ -317,12 +317,11 @@ void FontCache::cacheData(uint32_t bpp, GlyphNode* first)
 | 
			
		||||
        {
 | 
			
		||||
            p += SizeGlyphNode;
 | 
			
		||||
            // Next pointer
 | 
			
		||||
            p += 4;
 | 
			
		||||
            p += sizeof(void*);
 | 
			
		||||
 | 
			
		||||
            // Seek and copy
 | 
			
		||||
            setPosition(glyphDataOffset + gn->dataOffset);
 | 
			
		||||
            uint32_t glyphSize = ((gn->width() + 1) & ~1) * gn->height() * bpp / 8;
 | 
			
		||||
            readData(p, glyphSize);
 | 
			
		||||
            readData(p, getGlyphSize(gn));
 | 
			
		||||
 | 
			
		||||
            // Mark glyphNode as cached
 | 
			
		||||
            gn->dataOffset = 0xFFFFFFFF;
 | 
			
		||||
 | 
			
		||||
@ -41,4 +41,19 @@ int8_t GeneratedFont::getKerning(Unicode::UnicodeChar prevChar, const GlyphNode*
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const GlyphNode* FusedFont::getGlyph(Unicode::UnicodeChar unicode, const uint8_t*& pixelData, uint8_t& bitsPerPixel) const
 | 
			
		||||
{
 | 
			
		||||
    if (unicode < 0xAC00 || unicode > 0xD7A3)
 | 
			
		||||
    {
 | 
			
		||||
        return GeneratedFont::getGlyph(unicode, pixelData, bitsPerPixel);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        fusedNode.unicode = unicode;
 | 
			
		||||
        bitsPerPixel = 1;
 | 
			
		||||
        pixelData = 0;
 | 
			
		||||
        return const_cast<const GlyphNode*>(&fusedNode);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
} // namespace touchgfx
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user