Skip to content

Commit 5939fb6

Browse files
authored
Merge pull request #83 from epsi1on/master
Add support for rendering text
2 parents 9cb1ffd + 1eec1d4 commit 5939fb6

16 files changed

Lines changed: 789 additions & 4 deletions

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Please use the [GitHub Issues functionality](https://github.com/teichgraf/Writea
1212

1313
![wbx_announcement.png](https://4.bp.blogspot.com/-kGQh1bS1qlk/Sx1KnIEhZ3I/AAAAAAAAAI0/z3P5rYjXuk8/s1600/wbx_announcement.png)
1414

15+
16+
# News
17+
* now supports text rendering (outline and fill)
18+
1519
# Features
1620

1721
[GDI+](http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx) like drawing functionality for the WriteableBitmap.
@@ -39,6 +43,8 @@ Support for WPF, Windows 10 UWP (, Windows 8/8.1 WinRT XAML, Windows Phone Silve
3943
* Fast ellipse and rectangle fill method
4044
* Triangle, quad, simple and complex polygons
4145
* Beziér and Cardinal spline curves
46+
* Text
47+
* Fill and draw outline of text strings. text is highly flexible, it is instance of `FormattedText` thus any text and characted which is supported by wpf, can be rendered (options like `FlowDirection`, `FontWeight` and ... can be changed).
4248
* Blitting
4349
* Different blend modes including alpha, additive, subtractive, multiply, mask and none
4450
* Optimized fast path for non blended blitting
@@ -93,7 +99,11 @@ using(writeableBmp.GetBitmapContext())
9399

94100
// Blue anti-aliased line from P1(10, 20) to P2(50, 70) with a stroke of 5
95101
writeableBmp.DrawLineAa(10, 20, 50, 70, Colors.Blue, 5);
96-
102+
103+
// Fills a text on the bitmap, Font, size, weight and almost any option is changable, all text supported with WPF is also supported here including Persian, Arabic, Chinese etc
104+
var formattedText = new FormattedText("Test String", CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(new FontFamily("Sans MS"), FontStyles.Normal, FontWeights.Medium, FontStretches.Normal), 80.0, System.Windows.Media.Brushes.Black);
105+
writeableBmp.FillText(formattedText, 100, 100, Colors.Blue, 5);
106+
97107
// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)
98108
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);
99109

Solution/WriteableBitmapEx_All.sln

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.271
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33213.308
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Wpf", "Wpf", "{299BE8E6-6ACC-43E1-B4AC-DAF1BEAA6362}"
77
EndProject
@@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WriteableBitmapEx.Uwp", "..
2525
EndProject
2626
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WriteableBitmapExBlitSample.Uwp", "..\Source\WriteableBitmapExBlitSample.Uwp\WriteableBitmapExBlitSample.Uwp.csproj", "{5AB055AD-8486-438C-89A4-8795D83C3E9B}"
2727
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WriteableBitmapEx.TextExample", "..\Source\WriteableBitmapExTextExample.Wpf\WriteableBitmapEx.TextExample.csproj", "{B6938491-2107-43BA-A49E-B8EE72DEE0DF}"
29+
EndProject
2830
Global
2931
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3032
Debug|Any CPU = Debug|Any CPU
@@ -247,6 +249,30 @@ Global
247249
{5AB055AD-8486-438C-89A4-8795D83C3E9B}.Release|x86.ActiveCfg = Release|x86
248250
{5AB055AD-8486-438C-89A4-8795D83C3E9B}.Release|x86.Build.0 = Release|x86
249251
{5AB055AD-8486-438C-89A4-8795D83C3E9B}.Release|x86.Deploy.0 = Release|x86
252+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
253+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
254+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|ARM.ActiveCfg = Debug|Any CPU
255+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|ARM.Build.0 = Debug|Any CPU
256+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|ARM64.ActiveCfg = Debug|Any CPU
257+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|ARM64.Build.0 = Debug|Any CPU
258+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
259+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
260+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|x64.ActiveCfg = Debug|Any CPU
261+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|x64.Build.0 = Debug|Any CPU
262+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|x86.ActiveCfg = Debug|Any CPU
263+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Debug|x86.Build.0 = Debug|Any CPU
264+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
265+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|Any CPU.Build.0 = Release|Any CPU
266+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|ARM.ActiveCfg = Release|Any CPU
267+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|ARM.Build.0 = Release|Any CPU
268+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|ARM64.ActiveCfg = Release|Any CPU
269+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|ARM64.Build.0 = Release|Any CPU
270+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
271+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
272+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|x64.ActiveCfg = Release|Any CPU
273+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|x64.Build.0 = Release|Any CPU
274+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|x86.ActiveCfg = Release|Any CPU
275+
{B6938491-2107-43BA-A49E-B8EE72DEE0DF}.Release|x86.Build.0 = Release|Any CPU
250276
EndGlobalSection
251277
GlobalSection(SolutionProperties) = preSolution
252278
HideSolutionNode = FALSE

Source/WriteableBitmapEx.Wpf/WriteableBitmapEx.Wpf.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
<Compile Include="..\WriteableBitmapEx\WriteableBitmapFilterExtensions.cs" Link="WriteableBitmapFilterExtensions.cs" />
6060
<Compile Include="..\WriteableBitmapEx\WriteableBitmapLineExtensions.cs" Link="WriteableBitmapLineExtensions.cs" />
6161
<Compile Include="..\WriteableBitmapEx\WriteableBitmapShapeExtensions.cs" Link="WriteableBitmapShapeExtensions.cs" />
62-
<Compile Include="..\WriteableBitmapEx\WriteableBitmapSplineExtensions.cs" Link="WriteableBitmapSplineExtensions.cs" />
62+
<Compile Include="..\WriteableBitmapEx\WriteableBitmapSplineExtensions.cs" Link="WriteableBitmapSplineExtensions.cs" />
63+
<Compile Include="..\WriteableBitmapEx\WriteableBitmapTextExtensions.cs" Link="WriteableBitmapTextExtensions.cs" />
6364
<Compile Include="..\WriteableBitmapEx\WriteableBitmapTransformationExtensions.cs" Link="WriteableBitmapTransformationExtensions.cs" />
6465
</ItemGroup>
6566

Source/WriteableBitmapEx/WriteableBitmapShapeExtensions.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ public static void DrawPolylineAa(this WriteableBitmap bmp, int[] points, Color
9191
bmp.DrawPolylineAa(points, col);
9292
}
9393

94+
/// <summary>
95+
/// Draws a polyline. Add the first point also at the end of the array if the line should be closed.
96+
/// </summary>
97+
/// <param name="bmp">The WriteableBitmap.</param>
98+
/// <param name="points">The points of the polyline in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, ..., xn, yn).</param>
99+
/// <param name="color">The color for the line.</param>
100+
/// <param name="thickness">The thickness for the line.</param>
101+
public static void DrawPolylineAa(this WriteableBitmap bmp, int[] points, Color color,int thickness)
102+
{
103+
var col = ConvertColor(color);
104+
bmp.DrawPolylineAa(points, col,thickness);
105+
}
106+
94107
/// <summary>
95108
/// Draws a polyline anti-aliased. Add the first point also at the end of the array if the line should be closed.
96109
/// </summary>
@@ -119,6 +132,36 @@ public static void DrawPolylineAa(this WriteableBitmap bmp, int[] points, int co
119132
}
120133
}
121134

135+
136+
137+
/// <summary>
138+
/// Draws a polyline anti-aliased. Add the first point also at the end of the array if the line should be closed.
139+
/// </summary>
140+
/// <param name="bmp">The WriteableBitmap.</param>
141+
/// <param name="points">The points of the polyline in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, ..., xn, yn).</param>
142+
/// <param name="color">The color for the line.</param>
143+
public static void DrawPolylineAa(this WriteableBitmap bmp, int[] points, int color, int thickness)
144+
{
145+
using (var context = bmp.GetBitmapContext())
146+
{
147+
// Use refs for faster access (really important!) speeds up a lot!
148+
var w = context.Width;
149+
var h = context.Height;
150+
var x1 = points[0];
151+
var y1 = points[1];
152+
153+
for (var i = 2; i < points.Length; i += 2)
154+
{
155+
var x2 = points[i];
156+
var y2 = points[i + 1];
157+
158+
DrawLineAa(context, w, h, x1, y1, x2, y2, color, thickness);
159+
x1 = x2;
160+
y1 = y2;
161+
}
162+
}
163+
}
164+
122165
/// <summary>
123166
/// Draws a triangle.
124167
/// </summary>

0 commit comments

Comments
 (0)