jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
234 stars 40 forks source link

Feature/stroked text #96

Closed jingwood closed 1 year ago

jingwood commented 1 year ago

Changes

Add the ability to create path geometry from a text, it allows to draw a stroked or gradient text with custom pen and brush.

Implements the #88.

image

API Sample Code

//
// Example 1: Create a path geometry from text and render it

var textPath1 = this.Device.CreateTextPathGeometry("Hello World", "Arial", 36, D2DFontWeight.ExtraBold);

g.TranslateTransform(100, 100);

g.FillPath(textPath1, D2DColor.Yellow);
g.DrawPath(textPath1, D2DColor.Blue, 3);

g.TranslateTransform(-100, -100);

//
// Example 2: Use a helper method to draw a stroked text in simplest way
//
g.DrawStrokedText("Stroked text rendered using D2DLib", 100, 200,
    D2DColor.DarkOliveGreen, 2, D2DColor.LightCyan, "Consolas", 24);