Esempio n. 1
0
 /// <summary>
 /// Draws the specified text using the format information provided by an SharpDX.DirectWrite.TextFormat object</summary>
 /// <param name="text">A string to draw</param>
 /// <param name="textFormat">An object that describes formatting details of the text to draw, such as
 /// the font, the font size, and flow direction</param>
 /// <param name="layoutRect">The size and position of the area in which the text is drawn</param>
 /// <param name="brush">The brush used to paint the text</param>
 public void DrawText(string text, D2dTextFormat textFormat, RectangleF layoutRect, D2dBrush brush)
 {
     using (var layout = new SharpDX.DirectWrite.TextLayout(D2dFactory.NativeDwFactory, text, textFormat.NativeTextFormat, layoutRect.Width, layoutRect.Height))
     {
         if (textFormat.Underlined)
             layout.SetUnderline(true, new SharpDX.DirectWrite.TextRange(0, text.Length));
         if (textFormat.Strikeout)
             layout.SetStrikethrough(true, new SharpDX.DirectWrite.TextRange(0, text.Length));
         m_renderTarget.DrawTextLayout(
             layoutRect.Location.ToSharpDX(),
             layout, brush.NativeBrush,
             (DrawTextOptions)textFormat.DrawTextOptions);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Draws the specified text using the format information provided at the specified location</summary>
 /// <param name="text">The text string to draw</param>
 /// <param name="textFormat">The text format object to use</param>
 /// <param name="upperLeft">Upper left corner of the text</param>
 /// <param name="brush">The brush to use to draw the text</param>
 public void DrawText(string text, D2dTextFormat textFormat, PointF upperLeft, D2dBrush brush)
 {
     var rtsize = Size;
     using (var layout
         = new SharpDX.DirectWrite.TextLayout(D2dFactory.NativeDwFactory,
             text, textFormat.NativeTextFormat, rtsize.Width, rtsize.Height))
     {
         layout.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
         layout.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near;
         if (textFormat.Underlined)
             layout.SetUnderline(true,new SharpDX.DirectWrite.TextRange(0, text.Length));
         if (textFormat.Strikeout)
             layout.SetStrikethrough(true,new SharpDX.DirectWrite.TextRange(0, text.Length));
         m_renderTarget.DrawTextLayout(upperLeft.ToSharpDX(),
             layout,
             brush.NativeBrush,
             (DrawTextOptions)textFormat.DrawTextOptions);
     }
 }