bool FontPlatformData::isFixedPitch() const { TTF_POST post; if (m_font && FS_get_table_structure(m_font, TAG_post, &post) == SUCCESS) return post.isFixedPitch; return false; }
void SimpleFontData::platformInit() { FS_FIXED ascender = 0; FS_FIXED descender = 0; FS_FIXED leading = 0; FsAscDescLeadSource source; FS_LONG result; if (m_platformData.size() > 0) { // FIXME: hack! FS_get_ascender_descender_leading() returns ERR_NO_CURRENT_SFNT when size is 0, even though we called FS_set_scale and m_platformData.font()->cur_sfnt is not 0 result = FS_get_ascender_descender_leading(m_platformData.font(), &ascender, &descender, &leading, &source); ASSERT_UNUSED(result, result == SUCCESS); } m_fontMetrics.setAscent(FS_ROUND(ascender)); m_fontMetrics.setDescent(FS_ROUND(descender)); m_fontMetrics.setLineGap(iTypeFixedToFloat(leading)); m_fontMetrics.setLineSpacing(lroundf(m_fontMetrics.ascent()) + lroundf(m_fontMetrics.descent()) + lroundf(m_fontMetrics.lineGap())); FONT_METRICS metrics; result = FS_font_metrics(m_platformData.font(), &metrics); ASSERT_UNUSED(result, result == SUCCESS); // m_fontMetrics.setUnitsPerEm(FS_get_design_units(m_platformData().font())); m_fontMetrics.setUnitsPerEm(metrics.unitsPerEm); FS_USHORT xRange = metrics.font_bbox.xMax - metrics.font_bbox.xMin; m_maxCharWidth = roundf((xRange * roundf(m_platformData.size())) / metrics.unitsPerEm); TTF_OS2 os2; if (FS_get_table_structure(m_platformData.font(), TAG_OS2, &os2) == SUCCESS && os2.sxHeight && os2.xAvgCharWidth) { FS_USHORT yppem = m_platformData.font()->lpm; m_fontMetrics.setXHeight(static_cast<float>(os2.sxHeight) * yppem / metrics.unitsPerEm); m_avgCharWidth = static_cast<float>(os2.xAvgCharWidth) * yppem / metrics.unitsPerEm; } else { // HACK m_fontMetrics.setXHeight(m_fontMetrics.ascent() * 0.56); m_fontMetrics.setHasXHeight(false); m_avgCharWidth = m_fontMetrics.xHeight(); GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); if (glyphPageZero) { static const UChar32 xChar = 'x'; const Glyph xGlyph = glyphPageZero->glyphDataForCharacter(xChar).glyph; if (xGlyph) { // In widthForGlyph(), xGlyph will be compared with // m_zeroWidthSpaceGlyph, which isn't initialized yet here. // Initialize it with zero to make sure widthForGlyph() returns // the right width. m_zeroWidthSpaceGlyph = 0; m_avgCharWidth = widthForGlyph(xGlyph); } } } if (m_platformData.orientation() == Vertical && !isTextOrientationFallback()) m_hasVerticalGlyphs = FS_get_table(m_platformData.font(), openTypeTag('v', 'h', 'e', 'a'), TBL_QUERY, 0) || FS_get_table(m_platformData.font(), openTypeTag('V', 'O', 'R', 'G'), TBL_QUERY, 0); }