예제 #1
0
void BitmapFont::load(const OTMLNodePtr& fontNode)
{
    OTMLNodePtr textureNode = fontNode->at("texture");
    std::string textureFile = stdext::resolve_path(textureNode->value(), textureNode->source());
    Size glyphSize = fontNode->valueAt<Size>("glyph-size");
    m_glyphHeight = fontNode->valueAt<int>("height");
    m_yOffset = fontNode->valueAt("y-offset", 0);
    m_firstGlyph = fontNode->valueAt("first-glyph", 32);
    m_glyphSpacing = fontNode->valueAt("spacing", Size(0,0));
    int spaceWidth = fontNode->valueAt("space-width", glyphSize.width());

    // load font texture
    m_texture = g_textures.getTexture(textureFile);

    if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) {
        for(int glyph = m_firstGlyph; glyph < 256; ++glyph)
            m_glyphsSize[glyph] = Size(node->value<int>(), m_glyphHeight);
    } else {
        calculateGlyphsWidthsAutomatically(Image::load(textureFile), glyphSize);
    }

    // 32 and 160 are spaces (&nbsp;)
    m_glyphsSize[32].setWidth(spaceWidth);
    m_glyphsSize[160].setWidth(spaceWidth);

    // use 127 as spacer [Width: 1], Important for the current NPC highlighting system
    m_glyphsSize[127].setWidth(1);

    // new line actually has a size that will be useful in multiline algorithm
    m_glyphsSize[(uchar)'\n'] = Size(1, m_glyphHeight);

    // read custom widths
    /*
    if(OTMLNodePtr node = fontNode->get("glyph-widths")) {
        for(const OTMLNodePtr& child : node->children())
            m_glyphsSize[stdext::safe_cast<int>(child->tag())].setWidth(child->value<int>());
    }
    */


    // calculate glyphs texture coords
    int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width();
    for(int glyph = m_firstGlyph; glyph < 256; ++glyph) {
        m_glyphsTextureCoords[glyph].setRect(((glyph - m_firstGlyph) % numHorizontalGlyphs) * glyphSize.width(),
                                                ((glyph - m_firstGlyph) / numHorizontalGlyphs) * glyphSize.height(),
                                                m_glyphsSize[glyph].width(),
                                                m_glyphHeight);
    }
}
예제 #2
0
파일: font.cpp 프로젝트: Cayan/otclient
void Font::load(const OTMLNodePtr& fontNode)
{
    OTMLNodePtr textureNode = fontNode->at("texture");
    std::string textureFile = Fw::resolvePath(textureNode->value(), textureNode->source());
    Size glyphSize = fontNode->valueAt<Size>("glyph-size");
    m_glyphHeight = fontNode->valueAt<int>("height");
    m_yOffset = fontNode->valueAt("y-offset", 0);
    m_firstGlyph = fontNode->valueAt("first-glyph", 32);
    m_glyphSpacing = fontNode->valueAt("spacing", Size(0,0));

    // load font texture
    m_texture = g_textures.getTexture(textureFile);

    if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) {
        for(int glyph = m_firstGlyph; glyph < 256; ++glyph)
            m_glyphsSize[glyph] = Size(node->value<int>(), m_glyphHeight);
    } else {
        calculateGlyphsWidthsAutomatically(Image::load(textureFile), glyphSize);
    }

    // new line actually has a size that will be useful in multiline algorithm
    m_glyphsSize[(uchar)'\n'] = Size(1, m_glyphHeight);

    // read custom widths
    if(OTMLNodePtr node = fontNode->get("glyph-widths")) {
        for(const OTMLNodePtr& child : node->children())
            m_glyphsSize[Fw::safeCast<int>(child->tag())].setWidth(child->value<int>());
    }

    // calculate glyphs texture coords
    int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width();
    for(int glyph = m_firstGlyph; glyph < 256; ++glyph) {
        m_glyphsTextureCoords[glyph].setRect(((glyph - m_firstGlyph) % numHorizontalGlyphs) * glyphSize.width(),
                                                ((glyph - m_firstGlyph) / numHorizontalGlyphs) * glyphSize.height(),
                                                m_glyphsSize[glyph].width(),
                                                m_glyphHeight);
    }
}
예제 #3
0
BorderImagePtr BorderImage::loadFromOTML(const OTMLNodePtr& borderImageNode)
{
    Rect leftBorder;
    Rect rightBorder;
    Rect topBorder;
    Rect bottomBorder;
    Rect topLeftCorner;
    Rect topRightCorner;
    Rect bottomLeftCorner;
    Rect bottomRightCorner;
    Rect center;
    Rect subRect;
    int top, bottom, left, right, border;
    Size size;
    Point offset;

    // load texture
    std::string source = borderImageNode->at("source")->value();
    TexturePtr texture = g_textures.getTexture(source);

    // load basic border confs
    size = texture->getSize();
    size = borderImageNode->valueAt("size", size);
    offset = borderImageNode->valueAt("offset", offset);
    border = borderImageNode->valueAt("border", 0);
    subRect = Rect(offset, size);

    // load border margins
    top = bottom = left = right = border;
    top = borderImageNode->valueAt("border.top", top);
    bottom = borderImageNode->valueAt("border.bottom", bottom);
    left = borderImageNode->valueAt("border.left", left);
    right = borderImageNode->valueAt("border.right", right);

    // calculates border coords
    leftBorder = Rect(subRect.left(), subRect.top() + top, left, subRect.height() - top - bottom);
    rightBorder = Rect(subRect.right() - right + 1, subRect.top() + top, right, subRect.height() - top - bottom);
    topBorder = Rect(subRect.left() + left, subRect.top(), subRect.width() - right - left, top);
    bottomBorder = Rect(subRect.left() + left, subRect.bottom() - bottom + 1, subRect.width() - right - left, bottom);
    topLeftCorner = Rect(subRect.left(), subRect.top(), left, top);
    topRightCorner = Rect(subRect.right() - right + 1, subRect.top(), right, top);
    bottomLeftCorner = Rect(subRect.left(), subRect.bottom() - bottom + 1, left, bottom);
    bottomRightCorner = Rect(subRect.right() - right + 1, subRect.bottom() - bottom + 1, right, bottom);
    center = Rect(subRect.left() + left, subRect.top() + top, subRect.width() - right - left, subRect.height() - top - bottom);

    // load individual border conf if supplied
    /*
    leftBorder = borderImageNode->valueAt("left border", leftBorder);
    rightBorder = borderImageNode->valueAt("right border", rightBorder);
    topBorder = borderImageNode->valueAt("top border", topBorder);
    bottomBorder = borderImageNode->valueAt("bottom border", bottomBorder);
    topLeftCorner = borderImageNode->valueAt("top left corner", topLeftCorner);
    topRightCorner = borderImageNode->valueAt("top right corner", topRightCorner);
    bottomLeftCorner = borderImageNode->valueAt("bottom left corner", bottomLeftCorner);
    bottomRightCorner = borderImageNode->valueAt("bottom right corner", bottomRightCorner);
    center = borderImageNode->valueAt("center", center);
    */

    return BorderImagePtr(new BorderImage(texture,
                            leftBorder,
                            rightBorder,
                            topBorder,
                            bottomBorder,
                            topLeftCorner,
                            topRightCorner,
                            bottomLeftCorner,
                            bottomRightCorner,
                            center));
}