Esempio n. 1
0
        private float MeasureTextNodeLength(TextNode node, FontData fontData, FontRenderOptions options)
        {
            bool monospaced = fontData.IsMonospacingActive(options);
            float monospaceWidth = fontData.GetMonoSpaceWidth(options);

            if (node.Type == TextNodeType.Space)
            {
                if (monospaced)
                    return monospaceWidth;

                return (float)Math.Ceiling(fontData.meanGlyphWidth * options.WordSpacing);
            }

            float length = 0f;
            if (node.Type == TextNodeType.Word)
            {
                for (int i = 0; i < node.Text.Length; i++)
                {
                    char c = node.Text[i];
                    if (fontData.CharSetMapping.ContainsKey(c))
                    {
                        if (monospaced)
                            length += monospaceWidth;
                        else
                            length += (float)Math.Ceiling(fontData.CharSetMapping[c].rect.Width + fontData.meanGlyphWidth * options.CharacterSpacing + fontData.GetKerningPairCorrection(i, node.Text, node));
                    }
                }
            }
            return length;
        }
Esempio n. 2
0
 public void MeasureNodes(FontData fontData, FontRenderOptions options)
 {
     foreach (TextNode node in this)
     {
         if (node.Length == 0f)
             node.Length = MeasureTextNodeLength(node, fontData, options);
     }
 }
Esempio n. 3
0
 public float GetMonoSpaceWidth(FontRenderOptions options)
 {
     return (float)Math.Ceiling(1 + (1 + options.CharacterSpacing) * meanGlyphWidth);
 }
Esempio n. 4
0
 public bool IsMonospacingActive(FontRenderOptions options)
 {
     return (options.Monospacing == FontMonospacing.Natural && naturallyMonospaced) || options.Monospacing == FontMonospacing.Yes;
 }
        public FontRenderOptions CreateClone()
        {
            var clone = new FontRenderOptions();

            clone.CharacterSpacing = CharacterSpacing;
            clone.WordSpacing = WordSpacing;
            clone.LineSpacing = LineSpacing;
            clone.Monospacing = Monospacing;
            clone.JustifyCharacterWeightForExpand = JustifyCharacterWeightForExpand;
            clone.justifyCharWeightForExpand = justifyCharWeightForExpand;
            clone.JustifyCharacterWeightForContract = JustifyCharacterWeightForContract;
            clone.justifyCharWeightForContract = justifyCharWeightForContract;
            clone.JustifyCapExpand = JustifyCapExpand;
            clone.JustifyCapContract = JustifyCapContract;
            clone.JustifyContractionPenalty = JustifyContractionPenalty;

            return clone;
        }