Ejemplo n.º 1
0
        public GLFont(Font font, GLFontBuilderConfiguration config = null)
        {
            options = new GLFontRenderOptions();

            if (config == null)
            {
                config = new GLFontBuilderConfiguration();
            }

            fontData = new GLFontBuilder(font, config).BuildFontData();
        }
Ejemplo n.º 2
0
        public void MeasureNodes(GLFontData fontData, GLFontRenderOptions options)
        {
            bool  monospaced     = fontData.IsMonospacingActive(options);
            float monospaceWidth = fontData.GetMonoSpaceWidth(options);

            foreach (GLFontTextNode node in this)
            {
                if (node.Length == 0f)
                {
                    if (node.Type == GLFontTextNodeType.Space)
                    {
                        if (monospaced)
                        {
                            node.Length = monospaceWidth;
                            continue;
                        }
                        node.Length = (float)Math.Ceiling(fontData.meanGlyphWidth * options.WordSpacing);
                        continue;
                    }

                    if (node.Type == GLFontTextNodeType.Tab)
                    {
                        if (monospaced)
                        {
                            node.Length = monospaceWidth * 4;
                            continue;
                        }
                        node.Length = (float)Math.Ceiling(4 * fontData.meanGlyphWidth * options.WordSpacing);
                        continue;
                    }

                    if (node.Type == GLFontTextNodeType.Word)
                    {
                        for (int i = 0; i < node.Text.Length; i++)
                        {
                            char        c = node.Text[i];
                            GLFontGlyph glyph;
                            if (fontData.CharSetMapping.TryGetValue(c, out glyph))
                            {
                                if (monospaced)
                                {
                                    node.Length += monospaceWidth;
                                }
                                else
                                {
                                    node.Length += (float)Math.Ceiling(glyph.Rect.Width + fontData.meanGlyphWidth * options.CharacterSpacing + fontData.GetKerningPairCorrection(i, node.Text, node));
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public float GetMonoSpaceWidth(GLFontRenderOptions options)
 {
     return((float)Math.Ceiling(1 + (1 + options.CharacterSpacing) * meanGlyphWidth));
 }
Ejemplo n.º 4
0
 public bool IsMonospacingActive(GLFontRenderOptions options)
 {
     return((options.Monospacing == GLFontMonospacing.Natural && naturallyMonospaced) || options.Monospacing == GLFontMonospacing.Yes);
 }