Skip to content

Bold style is not applied for some fonts #492

@Kizuto3

Description

@Kizuto3

Some fonts (like Cascadia Code and Bahnschrift) seem to ignore Bold style. These are default windows fonts. Weirdly enough, it doesn't ignore italic style.

OS: Win 11
PdfSharpCore Version: 1.3.67
Below is the code for the sample code demonstrating this issue:

using PdfSharpCore.Drawing;
using PdfSharpCore.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 cascadiaBold = new XFont("Cascadia Code", 40, XFontStyle.Bold, XPdfFontOptions.UnicodeDefault);
var rect = new XRect(10, 120, page.Width, 0);

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

var cascadiaRegular = new XFont("Cascadia Code", 40, XFontStyle.Regular, XPdfFontOptions.UnicodeDefault);
var rect2 = new XRect(10, 240, page.Width, 0);

gfx.DrawString("Hello world", cascadiaRegular, new XSolidBrush(new XColor() { R = 0, G = 0, B = 0 }), rect2,
                    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:

fonts.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions