public void DrawGlyphRun(
                Vector2 position,
                CanvasFontFace fontFace,
                float fontSize,
                CanvasGlyph[] glyphs,
                bool isSideways,
                uint bidiLevel,
                object brush,
                CanvasTextMeasuringMode measuringMode,
                string locale,
                string textString,
                int[] clusterMapIndices,
                uint startingTextPosition,
                CanvasGlyphOrientation glyphOrientation)
            {
                if (glyphs == null || glyphs.Length == 0)
                {
                    return;
                }

                float scaledFontAscent               = fontFace.Ascent * fontSize;
                float subscriptBaselineDropAmount    = scaledFontAscent * subscriptBaselineScale;
                float superscriptBaselineRaiseAmount = scaledFontAscent * superscriptBaselineScale;

                // Draw glyph-by-glyph.
                for (int i = 0; i < glyphs.Length; ++i)
                {
                    CanvasGlyph[] singleGlyph = new CanvasGlyph[1];
                    singleGlyph[0] = glyphs[i];

                    Vector2 positionForThisGlyph = position;

                    CustomBrushData brushData = (CustomBrushData)brush;
                    if (brushData != null)
                    {
                        if (brushData.BaselineAdjustment == CustomBrushData.BaselineAdjustmentType.Lower)
                        {
                            positionForThisGlyph.Y += subscriptBaselineDropAmount;
                        }
                        else if (brushData.BaselineAdjustment == CustomBrushData.BaselineAdjustmentType.Raise)
                        {
                            positionForThisGlyph.Y -= superscriptBaselineRaiseAmount;
                        }
                    }

                    DrawingSession.DrawGlyphRun(
                        positionForThisGlyph,
                        fontFace,
                        fontSize,
                        singleGlyph,
                        isSideways,
                        bidiLevel,
                        TextBrush);

                    position.X += glyphs[i].Advance;
                }
            }
Ejemplo n.º 2
0
 private void ShrinkFontAndAttachCustomBrushData(
     CanvasTextLayout textLayout, 
     int textPosition, 
     int characterCount, 
     CustomBrushData.BaselineAdjustmentType baselineAdjustmentType)
 {
     textLayout.SetFontSize(textPosition, characterCount, (float)CurrentFontSize * fontSizeShrinkAmount);
     textLayout.SetCustomBrush(textPosition, characterCount, new CustomBrushData() { BaselineAdjustment = baselineAdjustmentType });
 }