Skip to content

Commit c1f2203

Browse files
author
Omer
committed
expose add font family method
In order to add custom font that loaded locally in the project, it's essential to insert the font name into the exisiting fonts dictionary. thus I exposed the insert method to the PdfGenerator class
1 parent 2c69713 commit c1f2203

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Source/HtmlRenderer.PdfSharp.Core/Adapters/PdfSharpAdapter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ protected override RFont CreateFontInt(string family, double size, RFontStyle st
127127
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style)
128128
{
129129
var fontStyle = (XFontStyle)((int)style);
130-
var xFont = new XFont(((FontFamilyAdapter)family).FontFamily.Name, size, fontStyle, new XPdfFontOptions(PdfFontEncoding.Unicode));
130+
string fontName = family is FontFamilyAdapter adapter ? adapter.FontFamily.Name : family.Name;
131+
var xFont = new XFont(fontName, size, fontStyle, new XPdfFontOptions(PdfFontEncoding.Unicode));
131132
return new FontAdapter(xFont);
132133
}
134+
133135
}
134136
}

Source/HtmlRenderer.PdfSharp.Core/PdfGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using PdfSharpCore.Drawing;
1515
using PdfSharpCore.Pdf;
1616
using System;
17+
using TheArtOfDev.HtmlRenderer.Adapters;
1718
using TheArtOfDev.HtmlRenderer.Core;
1819
using TheArtOfDev.HtmlRenderer.Core.Entities;
1920
using TheArtOfDev.HtmlRenderer.Core.Utils;
@@ -44,6 +45,11 @@ public static void AddFontFamilyMapping(string fromFamily, string toFamily)
4445
PdfSharpAdapter.Instance.AddFontFamilyMapping(fromFamily, toFamily);
4546
}
4647

48+
public static void AddFontFamily(RFontFamily fontFamily)
49+
{
50+
PdfSharpAdapter.Instance.AddFontFamily(fontFamily);
51+
}
52+
4753
/// <summary>
4854
/// Parse the given stylesheet to <see cref="CssData"/> object.<br/>
4955
/// If <paramref name="combineWithDefault"/> is true the parsed css blocks are added to the

0 commit comments

Comments
 (0)