size_t IFont::getStringWidth(const std::string & data) const { size_t width = 0; for(size_t i=0; i<data.size(); i += getCharacterSize(data[i])) { width += getGlyphWidth(data.data() + i); } return width; }
void XeTeXFontInst::getGlyphSidebearings(GlyphID gid, float* lsb, float* rsb) { float width = getGlyphWidth(gid); GlyphBBox bbox; getGlyphBounds(gid, &bbox); if (lsb) *lsb = bbox.xMin; if (rsb) *rsb = width - bbox.xMax; }
float XeTeXFontInst::getGlyphItalCorr(GlyphID gid) { float rval = 0.0; float width = getGlyphWidth(gid); GlyphBBox bbox; getGlyphBounds(gid, &bbox); if (bbox.xMax > width) rval = bbox.xMax - width; return rval; }
float getKerning (HDC dc, const int glyph1, const int glyph2) { KerningPair kp; kp.glyph1 = glyph1; kp.glyph2 = glyph2; int index = kerningPairs.indexOf (kp); if (index < 0) { kp.glyph2 = -1; index = kerningPairs.indexOf (kp); if (index < 0) { kp.glyph2 = -1; kp.kerning = getGlyphWidth (dc, kp.glyph1) / (float) tm.tmHeight; kerningPairs.add (kp); return kp.kerning; } } return kerningPairs.getReference (index).kerning; }
void createKerningPairs (HDC dc, const float height) { HeapBlock<KERNINGPAIR> rawKerning; const DWORD numKPs = GetKerningPairs (dc, 0, 0); rawKerning.calloc (numKPs); GetKerningPairs (dc, numKPs, rawKerning); kerningPairs.ensureStorageAllocated ((int) numKPs); for (DWORD i = 0; i < numKPs; ++i) { KerningPair kp; kp.glyph1 = getGlyphForChar (dc, rawKerning[i].wFirst); kp.glyph2 = getGlyphForChar (dc, rawKerning[i].wSecond); const int standardWidth = getGlyphWidth (dc, kp.glyph1); kp.kerning = (standardWidth + rawKerning[i].iKernAmount) / height; kerningPairs.add (kp); kp.glyph2 = -1; // add another entry for the standard width version.. kp.kerning = standardWidth / height; kerningPairs.add (kp); } }