예제 #1
0
파일: TextNodeList.cs 프로젝트: mokujin/DN
        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;
        }
예제 #2
0
파일: TextNodeList.cs 프로젝트: mokujin/DN
 public void MeasureNodes(FontData fontData, FontRenderOptions options)
 {
     foreach (TextNode node in this)
     {
         if (node.Length == 0f)
             node.Length = MeasureTextNodeLength(node, fontData, options);
     }
 }
예제 #3
0
파일: FontData.cs 프로젝트: mokujin/DN
 public float GetMonoSpaceWidth(FontRenderOptions options)
 {
     return (float)Math.Ceiling(1 + (1 + options.CharacterSpacing) * meanGlyphWidth);
 }
예제 #4
0
파일: FontData.cs 프로젝트: mokujin/DN
 public bool IsMonospacingActive(FontRenderOptions options)
 {
     return (options.Monospacing == FontMonospacing.Natural && naturallyMonospaced) || options.Monospacing == FontMonospacing.Yes;
 }
예제 #5
0
        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;
        }