Exemple #1
0
            private void calculateAllCharacterSizes()
            {
                var stringFormat = StringFormat.GenericTypographic;

                stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;

                using var g = System.Drawing.Graphics.FromImage(measureBitmap);
                applyGraphicsSettings(g);
                var brush   = new SolidBrush(System.Drawing.Color.White);
                var drawPos = new PointF(font.Height, font.Height);

                foreach (var c in supportedCharacters.Concat(new[] { fallbackGlyph }))
                {
                    g.Clear(System.Drawing.Color.FromArgb(0, 0, 0, 0));
                    g.DrawString(c.ToString(), font, brush, drawPos);

                    var(xMin, xMax, yMin, yMax) = findBoundingBoxForCurrentBitmap();

                    var characterInfo = new MutableCharacterInfo
                    {
                        Size         = new Vector2i(xMax - xMin + 1, yMax - yMin + 1),
                        Offset       = new Vector2i(xMin - font.Height, yMin - font.Height),
                        SpacingWidth = g.MeasureString(c.ToString(), font, 0, stringFormat).Width,
                    };
                    characterInfos.Add(c, characterInfo);
                }
            }
Exemple #2
0
            private CharacterInfo toCharacterInfo(MutableCharacterInfo info, int textureWidth, int textureHeight)
            {
                var fontHeightInverse = 1f / font.Height;
                var pixelSize         = new Vector2(1f / textureWidth, 1f / textureHeight);

                return(new CharacterInfo(
                           info.Size.ToVector2() * fontHeightInverse,
                           info.Offset.ToVector2() * fontHeightInverse,
                           info.SpacingWidth * fontHeightInverse,
                           pixelSize * info.TopLeft.ToVector2(),
                           pixelSize * (info.TopLeft + info.Size).ToVector2()));
            }