Exemplo n.º 1
0
bool FontPlatformData::applyState(FS_STATE* font, float scale) const
{
    ASSERT(font);
    ASSERT(m_name);
    if (FS_set_font(font, m_name) != SUCCESS)
        return false;

    if (FS_set_cmap(font, 3, 10) != SUCCESS) // First try Windows Unicode with surrogates...
        if (FS_set_cmap(font, 3, 1) != SUCCESS) // try normal Windows Unicode
            if (FS_set_cmap(font, 1, 0) != SUCCESS)
                return false;

    if (m_syntheticBold) {
        if (FS_set_bold_pct(font, floatToITypeFixed(0.06)) != SUCCESS) // 6% pseudo bold
            return false;
    } else {
        if (FS_set_bold_pct(font, 0) != SUCCESS)
            return false;
    }

    FS_FIXED skew = 0;
    if (m_syntheticOblique)
        skew = 13930; // 12 degrees

    FS_FIXED fixedScale = std::min(FixMul(floatToITypeFixed(scale), floatToITypeFixed(m_size)), MAXITYPEFONTSCALE);
    if (FS_set_scale(font, fixedScale, FixMul(fixedScale, skew), 0, fixedScale) != SUCCESS)
        return false;

    if (FS_set_flags(font, FLAGS_CMAP_OFF) != SUCCESS)
        return false;

    if (FS_set_flags(font, FLAGS_HINTS_OFF) != SUCCESS)
        return false;

    if (FS_set_flags(font, FLAGS_DEFAULT_CSM_OFF) != SUCCESS)
        return false;

    if (m_orientation == Vertical) {
        if (FS_set_flags(font, (m_textOrientation == TextOrientationVerticalRight) ? FLAGS_VERTICAL_ROTATE_LEFT_ON : FLAGS_VERTICAL_ON) != SUCCESS)
            return false;
    }
    return true;
}
float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
{
    FS_SHORT idx, idy;
    FS_FIXED dx, dy;
    FS_FIXED s00, s01, s10, s11;
    bool needsFakeBoldReset = m_platformData.syntheticBold() && m_treatAsFixedPitch;

    if (needsFakeBoldReset) {
        FS_get_scale(m_platformData.font(), &s00, &s01, &s10, &s11);
        FS_set_bold_pct(m_platformData.font(), 0);
        FS_set_scale(m_platformData.font(), s00, s01, s10, s11);
    }

    if (FS_get_advance(m_platformData.font(), glyph, FS_MAP_DISTANCEFIELD | FS_MAP_GRAYMAP8, &idx, &idy, &dx, &dy) != SUCCESS)
        dx = 0;

    if (needsFakeBoldReset) {
        FS_set_bold_pct(m_platformData.font(), ITYPEFAKEBOLDAMOUNT);
        FS_set_scale(m_platformData.font(), s00, s01, s10, s11);
    }

    return iTypeFixedToFloat(dx);
}