コード例 #1
0
        private void parseFontXml(AsXML fontXml)
        {
            float       scale = mTexture.getScale();
            AsRectangle frame = mTexture.getFrame();

            mName       = fontXml.elements("info").attribute("face");
            mSize       = AsGlobal.parseFloat(fontXml.elements("info").attribute("size")) / scale;
            mLineHeight = AsGlobal.parseFloat(fontXml.elements("common").attribute("lineHeight")) / scale;
            mBaseline   = AsGlobal.parseFloat(fontXml.elements("common").attribute("base")) / scale;
            if (fontXml.elements("info").attribute("smooth").ToString() == "0")
            {
                setSmoothing(AsTextureSmoothing.NONE);
            }
            if (mSize <= 0)
            {
                AsGlobal.trace("[Starling] Warning: invalid font size in '" + mName + "' font.");
                mSize = mSize == 0.0f ? 16.0f : mSize * -1.0f;
            }
            AsXMLList __charElements_ = fontXml.elements("chars").elements("_char");

            if (__charElements_ != null)
            {
                foreach (AsXML charElement in __charElements_)
                {
                    int         id       = (int)(AsGlobal.parseInt(charElement.attribute("id")));
                    float       xOffset  = AsGlobal.parseFloat(charElement.attribute("xoffset")) / scale;
                    float       yOffset  = AsGlobal.parseFloat(charElement.attribute("yoffset")) / scale;
                    float       xAdvance = AsGlobal.parseFloat(charElement.attribute("xadvance")) / scale;
                    AsRectangle region   = new AsRectangle();
                    region.x      = AsGlobal.parseFloat(charElement.attribute("x")) / scale + frame.x;
                    region.y      = AsGlobal.parseFloat(charElement.attribute("y")) / scale + frame.y;
                    region.width  = AsGlobal.parseFloat(charElement.attribute("width")) / scale;
                    region.height = AsGlobal.parseFloat(charElement.attribute("height")) / scale;
                    AsTexture    texture    = AsTexture.fromTexture(mTexture, region);
                    AsBitmapChar bitmapChar = new AsBitmapChar(id, texture, xOffset, yOffset, xAdvance);
                    addChar(id, bitmapChar);
                }
            }
            AsXMLList __kerningElements_ = fontXml.elements("kernings").elements("kerning");

            if (__kerningElements_ != null)
            {
                foreach (AsXML kerningElement in __kerningElements_)
                {
                    int   first  = (int)(AsGlobal.parseInt(kerningElement.attribute("first")));
                    int   second = (int)(AsGlobal.parseInt(kerningElement.attribute("second")));
                    float amount = AsGlobal.parseFloat(kerningElement.attribute("amount")) / scale;
                    if (mChars.containsKey(second))
                    {
                        getChar(second).addKerning(first, amount);
                    }
                }
            }
        }
コード例 #2
0
 protected override void activate(int pass, AsContext3D context, AsTexture texture)
 {
     updateParameters(pass, (int)(texture.getWidth() * texture.getScale()), (int)(texture.getHeight() * texture.getScale()));
     context.setProgramConstantsFromVector(AsContext3DProgramType.VERTEX, 4, mOffsets);
     context.setProgramConstantsFromVector(AsContext3DProgramType.FRAGMENT, 0, mWeights);
     if (mUniformColor && pass == getNumPasses() - 1)
     {
         context.setProgramConstantsFromVector(AsContext3DProgramType.FRAGMENT, 1, mColor);
         context.setProgram(mTintedProgram);
     }
     else
     {
         context.setProgram(mNormalProgram);
     }
 }