Skip to content

Commit 0df3993

Browse files
committed
Migrate HtmlRenderer.PdfSharp to PDFsharp-GDI v6.2.4
- PdfSharpAdapter.cs: XFontStyle -> XFontStyleEx via Utils.Convert(RFontStyle), drop XPdfFontOptions - Utils.cs: add Convert(RFontStyle) -> XFontStyleEx helper - HtmlRenderer.PdfSharp.csproj: PDFsharp 1.50.5147 -> PDFsharp-GDI 6.2.4 Based on PR ArthurHub#238 approach by eXpl0it3r.
1 parent c4257c4 commit 0df3993

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Source/HtmlRenderer.PdfSharp/Adapters/PdfSharpAdapter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ protected override RImage ImageFromStreamInt(Stream memoryStream)
119119

120120
protected override RFont CreateFontInt(string family, double size, RFontStyle style)
121121
{
122-
var fontStyle = (XFontStyle)((int)style);
123-
var xFont = new XFont(family, size, fontStyle, new XPdfFontOptions(PdfFontEncoding.Unicode));
122+
var fontStyle = Utils.Convert(style);
123+
var xFont = new XFont(family, size, fontStyle);
124124
return new FontAdapter(xFont);
125125
}
126126

127127
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style)
128128
{
129-
var fontStyle = (XFontStyle)((int)style);
130-
var xFont = new XFont(((FontFamilyAdapter)family).FontFamily.Name, size, fontStyle, new XPdfFontOptions(PdfFontEncoding.Unicode));
129+
var fontStyle = Utils.Convert(style);
130+
var xFont = new XFont(((FontFamilyAdapter)family).FontFamily.Name, size, fontStyle);
131131
return new FontAdapter(xFont);
132132
}
133133
}

Source/HtmlRenderer.PdfSharp/HtmlRenderer.PdfSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Features and Benefits:
3232
<ProjectReference Include="..\HtmlRenderer\HtmlRenderer.csproj" />
3333
</ItemGroup>
3434
<ItemGroup>
35-
<PackageReference Include="PDFsharp" Version="1.50.5147" />
35+
<PackageReference Include="PDFsharp-GDI" Version="6.2.4" />
3636
<PackageReference Include="System.Drawing.Common" Version="10.0.1" />
3737
</ItemGroup>
3838
</Project>

Source/HtmlRenderer.PdfSharp/Utilities/Utils.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,22 @@ public static RColor Convert(Color c)
9696
return RColor.FromArgb(c.A, c.R, c.G, c.B);
9797
}
9898

99+
/// <summary>
100+
/// Convert from HtmlRenderer font style to PdfSharp v6 XFontStyleEx.
101+
/// </summary>
102+
public static XFontStyleEx Convert(RFontStyle style)
103+
{
104+
XFontStyleEx result = XFontStyleEx.Regular;
105+
if ((style & RFontStyle.Bold) == RFontStyle.Bold)
106+
result |= XFontStyleEx.Bold;
107+
if ((style & RFontStyle.Italic) == RFontStyle.Italic)
108+
result |= XFontStyleEx.Italic;
109+
if ((style & RFontStyle.Underline) == RFontStyle.Underline)
110+
result |= XFontStyleEx.Underline;
111+
if ((style & RFontStyle.Strikeout) == RFontStyle.Strikeout)
112+
result |= XFontStyleEx.Strikeout;
113+
return result;
114+
}
115+
99116
}
100117
}

0 commit comments

Comments
 (0)