Esempio n. 1
0
        public static RotatedCharBox Get(TexStyle style, TexCharMetric Char, FontStyle fontStyle)
        {
            var box = ObjPool <RotatedCharBox> .Get();

            if (Char == null)
            {
                throw new NullReferenceException();
            }
            box.character = Char;
            //I can't say more but our cached glyph is slightly incorrect because
            //the usage of int in character Info, so we need to...
            var font = Char.ch.font;

            if (font.type == TexFontType.Font && Char.ch.supported)
            {
                CharacterInfo c;
                if (DrawingContext.GetCharInfo(font.Font_Asset, Char.ch.characterIndex,
                                               (int)(TexUtility.RenderTextureSize * Char.appliedScale) + 1, TexUtility.TexStyle2FontStyle(fontStyle), out c))
                {
                    float ratio = (c.size == 0 ? (float)TexUtility.RenderTextureSize : c.size) / Char.appliedScale;
                    //Swap XY
                    box.bearing = 0;
                    box.italic  = (c.maxY - c.minY) / ratio;
                    box.depth   = c.maxX / ratio;
                    box.height  = (-c.minX) / ratio;
                    //No kerning applied?
                    box.width = box.italic;
                    box.c     = c;
                    return(box);
                }
            }

            box.bearing = 0;
            box.italic  = Char.height + Char.depth;
            box.depth   = 0;
            box.height  = Char.italic + Char.bearing;
            box.width   = box.italic;

            return(box);
        }