Font::~Font() { //remove references to paths and images for(int i=0;i<m_glyphs.size();i++) clearGlyph(&m_glyphs[i]); RI_ASSERT(m_referenceCount == 0); }
void Font::setGlyphToImage(unsigned int index, VGImage image, const Vector2& origin, const Vector2& escapement) { Glyph* g = findGlyph(index); if(g) { //glyph exists, replace clearGlyph(g); } else { //glyph doesn't exist, allocate a new one g = newGlyph(); } g->m_index = index; g->m_state = Glyph::GLYPH_IMAGE; g->m_path = VG_INVALID_HANDLE; g->m_image = image; g->m_isHinted = false; g->m_origin = origin; g->m_escapement = escapement; if(image != VG_INVALID_HANDLE) { Image* p = (Image*)image; p->addReference(); p->addInUse(); } }
void Font::setGlyphToPath(unsigned int index, VGPath path, bool isHinted, const Vector2& origin, const Vector2& escapement) { Glyph* g = findGlyph(index); if(g) { //glyph exists, replace clearGlyph(g); } else { //glyph doesn't exist, allocate a new one g = newGlyph(); } g->m_index = index; g->m_state = Glyph::GLYPH_PATH; g->m_path = path; g->m_image = VG_INVALID_HANDLE; g->m_isHinted = isHinted; g->m_origin = origin; g->m_escapement = escapement; if(path != VG_INVALID_HANDLE) { Path* p = (Path*)path; p->addReference(); } }
bool GlyphString::shapeFriBidi(bool removeInvisibleCharacters) { if (mState != Analyzed) return false; FriBidiJoiningType *joiningTypes = new FriBidiJoiningType[mSize]; fribidi_get_joining_types(mCodePoints, mSize, joiningTypes); fribidi_join_arabic(mTypes, mSize, mLevels, joiningTypes); fribidi_shape(FRIBIDI_FLAGS_DEFAULT | FRIBIDI_FLAGS_ARABIC, mLevels, mSize, joiningTypes, mCodePoints); delete[] joiningTypes; loadGlyphImages(); if (removeInvisibleCharacters) { for (int i = 0; i < mSize; ++i) { if (mCodePoints[i] == 0xfeff || mCodePoints[i] == 0x061c || (mCodePoints[i] >= 0x202a && mCodePoints[i] <= 0x202e) || (mCodePoints[i] >= 0x2060 && mCodePoints[i] <= 0x2069) || (mCodePoints[i] >= 0x200b && mCodePoints[i] <= 0x200f)) clearGlyph(i); } } mState = Shaped; return true; }
bool GlyphString::layout() { if (mState == Invalid) return false; for (int i = 0; i < mSize; ++i) { mMap[i] = i; mLines[i] = -1; } mLineInfos.clear(); int lineNo = 0; int width = 0; int lineStart = 0; int lastSpace = -1; for (int i = 0; i <= mSize; ++i) { if (i == mSize) { mLineInfos.push_back(newLine(lineStart, i, lineNo++)); break; } //if (mCodePoints[i] == ' ') { if (mTypes[i] == FRIBIDI_TYPE_WS) { if (lineStart == i) { lineStart = i + 1; continue; } else if (lastSpace == i - 1) { clearGlyph(i - 1); lastSpace = i; continue; } lastSpace = i; } width += mGeometries[i].xAdvance; if (mMaxWidth < width) { if (lineStart == i) { return false; } if (lastSpace > lineStart) { mLineInfos.push_back(newLine(lineStart, lastSpace, lineNo++)); width = 0; lineStart = lastSpace + 1; i = lastSpace; continue; } else { mLineInfos.push_back(newLine(lineStart, i, lineNo++)); width = 0; lineStart = i; --i; continue; } } } mState = LaidOut; return true; }