Inheritance: ClientDrawingEffect
        public void DrawUnderline(float baselineOriginX, float baselineOriginY, Underline underline, ClientDrawingEffect clientDrawingEffect)
        {
            RectF rect = new RectF(0, underline.Offset, underline.Width, underline.Thickness);

            using (RectangleGeometry rectangleGeometry = _factory.CreateRectangleGeometry(rect))
            {
                SolidColorBrush brush = null;
                if (clientDrawingEffect != null)
                {
                    ColorDrawingEffect drawingEffect = clientDrawingEffect as ColorDrawingEffect;
                    if (drawingEffect != null)
                    {
                        brush = _renderTarget.CreateSolidColorBrush(drawingEffect.Color);
                    }
                }

                Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
                using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(rectangleGeometry, matrix))
                {
                    _renderTarget.FillGeometry(brush == null ? _defaultBrush : brush, transformedGeometry);
                }
                if (brush != null)
                {
                    brush.Dispose();
                }
            }
        }
        protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory)
        {
            base.OnCreateDeviceIndependentResources(factory);

            this._redColorDrawingEffect = new ColorDrawingEffect(Color.FromARGB(Colors.Red, 1));
            this._greenColorDrawingEffect = new ColorDrawingEffect(Color.FromARGB(Colors.Green, 1));
            this._blueColorDrawingEffect = new ColorDrawingEffect(Color.FromARGB(Colors.Blue, 1));

            this._textFormat = DirectWriteFactory.CreateTextFormat("Gabriola",
                FontWeight.Normal,
                FontStyle.Normal,
                FontStretch.Normal,
                72);

            this._textFormat.TextAlignment = TextAlignment.Center;
            this._textFormat.ParagraphAlignment = ParagraphAlignment.Center;

            float width = ClientSize.Width / _dpiScaleX;
            float height = ClientSize.Height / _dpiScaleY;

            this._textLayout = DirectWriteFactory.CreateTextLayout(
                _text,
                this._textFormat,
                width,
                height);

            this._textLayout.SetFontSize(100, new TextRange(20, 6));

            this._textLayout.SetDrawingEffect(_blueColorDrawingEffect, new TextRange(6, 5));
            this._textLayout.SetDrawingEffect(_redColorDrawingEffect, new TextRange(20, 6));
            this._textLayout.SetDrawingEffect(_greenColorDrawingEffect, new TextRange(26, 5));

            ClientDrawingEffect effect = this._textLayout.GetDrawingEffect(7);

            this._textLayout.SetUnderline(true, new TextRange(20, 11));
            this._textLayout.SetFontWeight(FontWeight.Bold, new TextRange(20, 11));

            using (Typography typography = DirectWriteFactory.CreateTypography())
            {
                typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1);
                this._textLayout.SetTypography(typography, new TextRange(0, _text.Length));
            }
        }
        public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, Graphics.Direct2D.MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ClientDrawingEffect clientDrawingEffect)
        {
            using (PathGeometry pathGeometry = _factory.CreatePathGeometry())
            {
                using (GeometrySink sink = pathGeometry.Open())
                {
                    glyphRun.FontFace.GetGlyphRunOutline(
                        glyphRun.EmSize,
                        glyphRun.GlyphIndices,
                        glyphRun.GlyphAdvances,
                        glyphRun.GlyphOffsets,
                        glyphRun.IsSideways,
                        glyphRun.BidiLevel != 0,
                        sink);
                    sink.Close();
                }

                CustomGeometrySink customSink = new CustomGeometrySink();
                pathGeometry.Stream(customSink);
                customSink.Close();
                System.Diagnostics.Debug.WriteLine(customSink.ToString());

                SolidColorBrush brush = null;
                if (clientDrawingEffect != null)
                {
                    ColorDrawingEffect drawingEffect = clientDrawingEffect as ColorDrawingEffect;
                    if (drawingEffect != null)
                    {
                        brush = _renderTarget.CreateSolidColorBrush(drawingEffect.Color);
                    }
                }

                Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
                using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(pathGeometry, matrix))
                {
                    _renderTarget.FillGeometry(brush == null ? _defaultBrush : brush, transformedGeometry);
                }
                if (brush != null)
                {
                    brush.Dispose();
                }
            }
        }
        protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory)
        {
            base.OnCreateDeviceIndependentResources(factory);

            this._redColorDrawingEffect   = new ColorDrawingEffect(Color.FromARGB(Colors.Red, 1));
            this._greenColorDrawingEffect = new ColorDrawingEffect(Color.FromARGB(Colors.Green, 1));
            this._blueColorDrawingEffect  = new ColorDrawingEffect(Color.FromARGB(Colors.Blue, 1));

            this._textFormat = DirectWriteFactory.CreateTextFormat("Gabriola",
                                                                   FontWeight.Normal,
                                                                   FontStyle.Normal,
                                                                   FontStretch.Normal,
                                                                   72);

            this._textFormat.TextAlignment      = TextAlignment.Center;
            this._textFormat.ParagraphAlignment = ParagraphAlignment.Center;

            float width  = ClientSize.Width / _dpiScaleX;
            float height = ClientSize.Height / _dpiScaleY;

            this._textLayout = DirectWriteFactory.CreateTextLayout(
                _text,
                this._textFormat,
                width,
                height);

            this._textLayout.SetFontSize(100, new TextRange(20, 6));

            this._textLayout.SetDrawingEffect(_blueColorDrawingEffect, new TextRange(6, 5));
            this._textLayout.SetDrawingEffect(_redColorDrawingEffect, new TextRange(20, 6));
            this._textLayout.SetDrawingEffect(_greenColorDrawingEffect, new TextRange(26, 5));

            ClientDrawingEffect effect = this._textLayout.GetDrawingEffect(7);

            this._textLayout.SetUnderline(true, new TextRange(20, 11));
            this._textLayout.SetFontWeight(FontWeight.Bold, new TextRange(20, 11));

            using (Typography typography = DirectWriteFactory.CreateTypography())
            {
                typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1);
                this._textLayout.SetTypography(typography, new TextRange(0, _text.Length));
            }
        }