FairyGUI.DynamicFont.GetGlyph C# (CSharp) Method

GetGlyph() public method

public GetGlyph ( char ch, GlyphInfo glyph ) : bool
ch char
glyph GlyphInfo
return bool
        public override bool GetGlyph(char ch, GlyphInfo glyph)
        {
            if (_font.GetCharacterInfo(ch, out sTempChar, _size, _style))
            {
                float baseline;
                if (_lastFontSize == _size)
                    baseline = _lastBaseLine;
                else
                {
                    _lastFontSize = _size;
                    baseline = GetBaseLine(_size);
                    _lastBaseLine = baseline;
                }
            #if UNITY_5
                glyph.vert.xMin = sTempChar.minX;
                glyph.vert.yMin = sTempChar.minY - baseline;
                glyph.vert.xMax = sTempChar.maxX;
                if (sTempChar.glyphWidth == 0) //zero width, space etc
                    glyph.vert.xMax = glyph.vert.xMin + _size / 2;
                glyph.vert.yMax = sTempChar.maxY - baseline;

                glyph.uvTopLeft = sTempChar.uvTopLeft;
                glyph.uvBottomLeft = sTempChar.uvBottomLeft;
                glyph.uvTopRight = sTempChar.uvTopRight;
                glyph.uvBottomRight = sTempChar.uvBottomRight;

                glyph.width = sTempChar.advance;
                glyph.height = sTempChar.size;
                if (customBold)
                    glyph.width++;
            #else
                glyph.vert.xMin = sTempChar.vert.xMin;
                glyph.vert.yMin = sTempChar.vert.yMax - baseline;
                glyph.vert.xMax = sTempChar.vert.xMax;
                if (sTempChar.vert.width == 0) //zero width, space etc
                    glyph.vert.xMax = glyph.vert.xMin + _size / 2;
                glyph.vert.yMax = sTempChar.vert.yMin - baseline;

                if (!sTempChar.flipped)
                {
                    glyph.uvBottomLeft = new Vector2(sTempChar.uv.xMin, sTempChar.uv.yMin);
                    glyph.uvTopLeft = new Vector2(sTempChar.uv.xMin, sTempChar.uv.yMax);
                    glyph.uvTopRight = new Vector2(sTempChar.uv.xMax, sTempChar.uv.yMax);
                    glyph.uvBottomRight = new Vector2(sTempChar.uv.xMax, sTempChar.uv.yMin);
                }
                else
                {
                    glyph.uvBottomLeft = new Vector2(sTempChar.uv.xMin, sTempChar.uv.yMin);
                    glyph.uvTopLeft = new Vector2(sTempChar.uv.xMax, sTempChar.uv.yMin);
                    glyph.uvTopRight = new Vector2(sTempChar.uv.xMax, sTempChar.uv.yMax);
                    glyph.uvBottomRight = new Vector2(sTempChar.uv.xMin, sTempChar.uv.yMax);
                }

                glyph.width = Mathf.CeilToInt(sTempChar.width);
                glyph.height = sTempChar.size;
                if (customBold)
                    glyph.width++;
            #endif
                if (keepCrisp)
                {
                    glyph.vert.xMin /= UIContentScaler.scaleFactor;
                    glyph.vert.yMin /= UIContentScaler.scaleFactor;
                    glyph.vert.xMax /= UIContentScaler.scaleFactor;
                    glyph.vert.yMax /= UIContentScaler.scaleFactor;
                    glyph.width /= UIContentScaler.scaleFactor;
                    glyph.height /= UIContentScaler.scaleFactor;
                }

                return true;
            }
            else
                return false;
        }

Usage Example

 static public int GetGlyph(IntPtr l)
 {
     try {
         FairyGUI.DynamicFont self = (FairyGUI.DynamicFont)checkSelf(l);
         System.Char          a1;
         checkType(l, 2, out a1);
         var ret = self.GetGlyph(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
All Usage Examples Of FairyGUI.DynamicFont::GetGlyph