Skip to content

Bold style is not applied for some windows fonts #374

@Kizuto3

Description

@Kizuto3

Some fonts (like Cascadia Code and Bahnschrift) seem to ignore Bold style. These are default windows fonts.

OS: Win 11
PdfSharp-WPF Version: 6.2.4
Below is the code for the sample app demonstrating this issue:

using PdfSharp.Drawing;
using PdfSharp.Pdf;

using var document = new PdfDocument();
var page = document.AddPage();

page.Width = new XUnit
{
    Millimeter = 100
};

page.Height = new XUnit
{
    Millimeter = 100
};

using var gfx = XGraphics.FromPdfPage(page);

var cascadiaRegular = new XFont("Cascadia Code", 40, XFontStyleEx.Regular);
var rect2 = new XRect(10, 120, page.Width, 0);

gfx.DrawString("Hello world", cascadiaRegular, new XSolidBrush(new XColor() { R = 0, G = 0, B = 0 }), rect2,
                    XStringFormats.BaseLineLeft);

var cascadiaBold = new XFont("Cascadia Code", 40, XFontStyleEx.Bold);
var rect = new XRect(10, 240, page.Width, 0);

gfx.DrawString("Hello world", cascadiaBold, new XSolidBrush(new XColor() { R = 0, G = 0, B = 0}), rect,
                    XStringFormats.BaseLineLeft);

document.Save(@"C:\Users\Public\Documents\HelloWorld.pdf");

And here's the output where both texts seem identical:
HelloWorld.pdf

Here's the archive with the fonts (just in case):
fonts.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions