Beispiel #1
0
        public static CharacterLayout[] LayoutCharacters(RuntimeFont font, string str, int startX, int startY)
        {
            CharacterLayout[] layout = new CharacterLayout[str.Length];

            int curX = startX;
            int curY = startY;

            for (int i = 0; i < str.Length; i++)
            {
                int whichCharacter = font.FindCharacter(str[i]);
                if (whichCharacter == -1)
                {
                    continue;
                }

                layout[i].SudoFontIndex = whichCharacter;
                layout[i].XOffset       = (int)(curX + font.Characters[whichCharacter].XOffset * font.RuntimeScale);
                layout[i].YOffset       = (int)(curY + font.Characters[whichCharacter].YOffset * font.RuntimeScale);

                float totalXAdvance = font.Characters[whichCharacter].XAdvance * font.RuntimeScale;

                if (i + 1 < str.Length)
                {
                    totalXAdvance += font.Characters[whichCharacter].GetKerning(str[i + 1]) * font.RuntimeScale;
                }

                curX += (int)Math.Ceiling(totalXAdvance);
            }

            return(layout);
        }
Beispiel #2
0
        public static CharacterLayout[] LayoutCharacters( RuntimeFont font, string str, int startX, int startY )
        {
            CharacterLayout[] layout = new CharacterLayout[ str.Length ];

            int curX = startX;
            int curY = startY;

            for ( int i=0; i < str.Length; i++ )
            {
                int whichCharacter = font.FindCharacter( str[i] );
                if ( whichCharacter == -1 )
                    continue;

                layout[i].SudoFontIndex = whichCharacter;
                layout[i].XOffset = (int)( curX + font.Characters[whichCharacter].XOffset * font.RuntimeScale );
                layout[i].YOffset = (int)( curY + font.Characters[whichCharacter].YOffset * font.RuntimeScale );

                float totalXAdvance = font.Characters[whichCharacter].XAdvance * font.RuntimeScale;

                if ( i+1 < str.Length )
                    totalXAdvance += font.Characters[whichCharacter].GetKerning( str[i+1] ) * font.RuntimeScale;

                curX += (int)Math.Ceiling( totalXAdvance );
            }

            return layout;
        }
Beispiel #3
0
        public static int MeasureStringWidth( RuntimeFont font, string str )
        {
            int width = 0;
            for ( int i=0; i < str.Length; i++ )
            {
                Char ch = str[i];
                int ic = font.FindCharacter( ch );
                if ( ic != -1 )
                {
                    float totalXAdvance = font.Characters[ic].XAdvance * font.RuntimeScale;

                    if ( i < str.Length-1 )
                        totalXAdvance += font.Characters[ic].GetKerning( str[i+1] ) * font.RuntimeScale;

                    width += (int)Math.Ceiling( totalXAdvance );
                }
            }

            return width;
        }
Beispiel #4
0
        public static int MeasureStringWidth(RuntimeFont font, string str)
        {
            int width = 0;

            for (int i = 0; i < str.Length; i++)
            {
                Char ch = str[i];
                int  ic = font.FindCharacter(ch);
                if (ic != -1)
                {
                    float totalXAdvance = font.Characters[ic].XAdvance * font.RuntimeScale;

                    if (i < str.Length - 1)
                    {
                        totalXAdvance += font.Characters[ic].GetKerning(str[i + 1]) * font.RuntimeScale;
                    }

                    width += (int)Math.Ceiling(totalXAdvance);
                }
            }

            return(width);
        }