public void Draw(D2D.RenderTarget target, float fontSize, string text, PointF point, DW.TextAlignment alignment, D2D.SolidColorBrush fillBrush, D2D.SolidColorBrush edgeBrush, float edgeWidth) { D2D.Geometry geometry = CreateGeometry(fontSize, text); switch (alignment) { case DW.TextAlignment.Leading: target.Transform = Matrix3x2.Translation(point); break; case DW.TextAlignment.Center: { RectangleF bounds = D2D.Geometry.GetBounds(geometry); target.Transform = Matrix3x2.Translation(point.X - bounds.Width / 2f, point.Y); } break; case DW.TextAlignment.Trailing: { RectangleF bounds = D2D.Geometry.GetBounds(geometry); target.Transform = Matrix3x2.Translation(point.X - bounds.Width, point.Y); } break; } target.DrawGeometry(geometry, edgeBrush, edgeWidth); target.FillGeometry(geometry, fillBrush); }
/// <summary> /// GDI互換コンテクストでレンダーターゲットが初期化された際の処理 /// </summary> private void context_TargetsInitialized(object sender, EventArgs e) { _gdiContext.D2DRenderTarget.AntialiasMode = D2D.AntialiasMode.Aliased; _gdiContext.D2DRenderTarget.TextAntialiasMode = D2D.TextAntialiasMode.Aliased; #if DEBUG _textFormat = _deviceManager.DWFactory.CreateTextFormat("MS Gothic", DW.FontWeight.Normal, DW.FontStyle.Normal, DW.FontStretch.Normal, 20, ""); _textFormat.TextAlignment = DW.TextAlignment.Center; _textFormat.ParagraphAlignment = DW.ParagraphAlignment.Center; _textBrush = new D2D.SolidColorBrush(_gdiContext.D2DRenderTarget, new Color4(1.0f, 1.0f, 0.2f, 1.0f)); #endif }