Esempio n. 1
0
        void SplitJustifiedGlyphsIntoRuns(CanvasTextAnalyzer textAnalyzer, LayoutBox layoutBox, CanvasGlyph[] justifiedGlyphs, bool needsAdditionalJustificationCharacters)
        {
            int glyphIndex = 0;

            float xPosition = (float)layoutBox.Rectangle.Right;

            for (int i = 0; i < layoutBox.GlyphRuns.Count; i++)
            {
                if (layoutBox.GlyphRuns[i].Glyphs.Count == 0)
                {
                    continue;
                }

                int originalGlyphCountForThisRun = layoutBox.GlyphRuns[i].Glyphs.Count;

                if (needsAdditionalJustificationCharacters)
                {
                    // Replace the glyph data, since justification can modify glyphs
                    CanvasGlyph[] justifiedGlyphsForThisGlyphRun = new CanvasGlyph[layoutBox.GlyphRuns[i].Glyphs.Count];
                    for (int j = 0; j < layoutBox.GlyphRuns[i].Glyphs.Count; j++)
                    {
                        justifiedGlyphsForThisGlyphRun[j] = justifiedGlyphs[glyphIndex + j];
                    }

                    CanvasCharacterRange range = layoutBox.GlyphRuns[i].GetRange();

                    var glyphRunClusterMap = layoutBox.GlyphRuns[i].GetClusterMap(range);
                    var glyphRunShaping    = layoutBox.GlyphRuns[i].GetShaping();

                    CanvasGlyph[] newSetOfGlyphs = textAnalyzer.AddGlyphsAfterJustification(
                        layoutBox.GlyphRuns[i].FormattingSpan.FontFace,
                        layoutBox.GlyphRuns[i].FormattingSpan.FontSize,
                        layoutBox.GlyphRuns[i].FormattingSpan.Script,
                        glyphRunClusterMap,
                        layoutBox.GlyphRuns[i].Glyphs.ToArray(),
                        justifiedGlyphsForThisGlyphRun,
                        glyphRunShaping);

                    layoutBox.GlyphRuns[i].Glyphs = new List <CanvasGlyph>(newSetOfGlyphs);
                }
                else
                {
                    for (int j = 0; j < layoutBox.GlyphRuns[i].Glyphs.Count; j++)
                    {
                        layoutBox.GlyphRuns[i].Glyphs[j] = justifiedGlyphs[glyphIndex + j];
                    }
                }

                glyphIndex += originalGlyphCountForThisRun;
            }
        }
Esempio n. 2
0
        void SplitJustifiedGlyphsIntoRuns(CanvasTextAnalyzer textAnalyzer, int startingGlyphRunIndex, int endingGlyphRunIndex, CanvasGlyph[] justifiedGlyphs, bool needsAdditionalJustificationCharacters)
        {
            int glyphIndex = 0;

            float xPosition = glyphRuns[startingGlyphRunIndex].Position.X;

            for (int i = startingGlyphRunIndex; i < endingGlyphRunIndex; ++i)
            {
                if (glyphRuns[i].Glyphs.Count == 0)
                {
                    continue;
                }

                // Adjust glyph run positioning based on justification
                glyphRuns[i].Position = new Vector2()
                {
                    X = xPosition, Y = glyphRuns[i].Position.Y
                };

                // Update running total glyph run advance
                for (int j = 0; j < glyphRuns[i].Glyphs.Count; j++)
                {
                    xPosition += glyphRuns[i].Glyphs[j].Advance;
                }

                if (needsAdditionalJustificationCharacters)
                {
                    // Replace the glyph data, since justification can modify glyphs
                    CanvasGlyph[] justifiedGlyphsForThisGlyphRun = new CanvasGlyph[glyphRuns[i].Glyphs.Count];
                    for (int j = 0; j < glyphRuns[i].Glyphs.Count; j++)
                    {
                        justifiedGlyphsForThisGlyphRun[j] = justifiedGlyphs[glyphIndex + j];
                    }

                    CanvasCharacterRange range = glyphRuns[i].GetRange();

                    var glyphRunClusterMap = glyphRuns[i].GetClusterMap(range);
                    var glyphRunShaping    = glyphRuns[i].GetShaping();

                    CanvasGlyph[] newSetOfGlyphs = textAnalyzer.AddGlyphsAfterJustification(
                        glyphRuns[i].FormattingSpan.FontFace,
                        glyphRuns[i].FormattingSpan.FontSize,
                        glyphRuns[i].FormattingSpan.Script,
                        glyphRunClusterMap,
                        glyphRuns[i].Glyphs.ToArray(),
                        justifiedGlyphsForThisGlyphRun,
                        glyphRunShaping);

                    glyphRuns[i].Glyphs = new List <CanvasGlyph>(newSetOfGlyphs);
                }
                else
                {
                    for (int j = 0; j < glyphRuns[i].Glyphs.Count; j++)
                    {
                        glyphRuns[i].Glyphs[j] = justifiedGlyphs[glyphIndex + j];
                    }
                }

                glyphIndex += glyphRuns[i].Glyphs.Count;
            }
        }