Пример #1
0
bool
WKCFontInfo::construct(float size, int weight, bool italic, bool horizontal, int family)
{
    m_font = wkcFontNewPeer((int)size, weight, italic, horizontal, true, family, m_familyName.data());

    m_scale = 1.f;
    m_requestSize = size;
    m_createdSize = m_font ? wkcFontGetSizePeer(m_font) : m_requestSize;
    if (gEnableScalingMonosizeFont && m_createdSize!=m_requestSize) {
        m_scale = (float)m_requestSize / (float)m_createdSize;
    }
    m_iscale = 1.f / m_scale;

    m_weight = weight;
    m_isItalic = italic;
    if (m_font) {
        m_canScale = wkcFontCanScalePeer(m_font);
        m_ascent = (float)wkcFontGetAscentPeer(m_font);
        m_descent = (float)wkcFontGetDescentPeer(m_font);
        m_lineSpacing = (float)wkcFontGetLineSpacingPeer(m_font);
    }
    m_unicodeChar = 0;
    m_horizontal = horizontal;

    return true;
}
FontPlatformData::FontPlatformData(const FontDescription& in_desc, const AtomicString& in_family)
{
    int size = 0;
    int weight = WKC_FONT_WEIGHT_NORMAL;
    int family = WKC_FONT_FAMILY_NONE;
    bool italic = in_desc.italic();

    switch (in_desc.genericFamily()) {
    case FontDescription::NoFamily:
        family = WKC_FONT_FAMILY_NONE;
        break;
    case FontDescription::StandardFamily:
        family = WKC_FONT_FAMILY_STANDARD;
        break;
    case FontDescription::SerifFamily:
        family = WKC_FONT_FAMILY_SERIF;
        break;
    case FontDescription::SansSerifFamily:
        family = WKC_FONT_FAMILY_SANSSERIF;
        break;
    case FontDescription::MonospaceFamily:
        family = WKC_FONT_FAMILY_MONOSPACE;
        break;
    case FontDescription::CursiveFamily:
        family = WKC_FONT_FAMILY_CURSIVE;
        break;
    case FontDescription::FantasyFamily:
        family = WKC_FONT_FAMILY_FANTASY;
        break;
    }
    switch (in_desc.weight()) {
    case FontWeight100:
        weight = WKC_FONT_WEIGHT_100;
        break;
    case FontWeight200:
        weight = WKC_FONT_WEIGHT_200;
        break;
    case FontWeight300:
        weight = WKC_FONT_WEIGHT_300;
        break;
    case FontWeight400:
        weight = WKC_FONT_WEIGHT_400;
        break;
    case FontWeight500:
        weight = WKC_FONT_WEIGHT_500;
        break;
    case FontWeight600:
        weight = WKC_FONT_WEIGHT_600;
        break;
    case FontWeight700:
        weight = WKC_FONT_WEIGHT_700;
        break;
    case FontWeight800:
        weight = WKC_FONT_WEIGHT_800;
        break;
    case FontWeight900:
        weight = WKC_FONT_WEIGHT_900;
        break;
    }
    m_requestSize = in_desc.computedPixelSize();
    size = m_requestSize;
    m_weight = weight;
    m_italic = italic;

    m_font = wkcFontNewPeer(size, weight, italic, family, in_family.string().utf8().data());
    m_fontState = VALID;

    m_createdSize = wkcFontGetSizePeer(m_font);
    m_ascent = wkcFontGetAscentPeer(m_font);
    m_descent = wkcFontGetDescentPeer(m_font);
    m_lineSpacing = wkcFontGetLineSpacingPeer(m_font);
    m_canScale = wkcFontCanScalePeer(m_font);

    m_scale = 1.f;
    if (gEnableScalingMonosizeFont && m_createdSize) {
        m_scale = (float)m_requestSize / (float)m_createdSize;
    }
    m_iscale = 1.f / m_scale;

    m_hashValue = calculateHash();
}