.netpdf.net-corepdfsharppdfsharpcore

PdfSharpCore font size units is not making sense and doesn't seem right


I'm confused by the font sizes in PdfSharpCore. The documentation for XFont says that the font size is specified as "emSize".

According to w3.org, em size represents the font size. According to W3 Schools, The size of an EM or percent depends on its parent. And according to Wikipedia, it originally meant the width of the letter 'M'.

How is it possible to specify the font size using the size of a font, a value that depends on its "parent" or based on any other attribute of an existing font when there is no existing font?

In practice, the value I specify appears to be interpreted as very close to points. But if it is really specifying points, why would it be documented as "emSize?"

Can anyone clarify how I can use an em size to set the font size? What em size would I use to specify 14 point?


Solution

  • The XFont class has an emSize parameter because it mimics the Font class of GDI+ which already has an emSize parameter. That is the simple explanation why the developer of PDFsharp chose that name (I asked him). I did not yet find further information why Microsoft chose that name.

    emSize is the name of the parameter, but the unit is not em. The default unit is Point, but other units can be set. The emSize parameter defines the em of the font to be used.

    Forget the W3C documentation in this case: This is not CSS, there is no "parent" and no option to use relative sizes (percent values).

    To get a font of size 14 points, just specify 14. The emSize parameter specifies the height of the font.

    The answer by K J might explain how Microsoft came to the name emSize.

    From Wikipedia: "An em (from English em quadrat) is a unit in the field of typography, equal to the currently specified point size. For example, one em in a 16-point typeface is 16 points. Therefore, this unit is the same for all typefaces at a given point size."
    https://en.wikipedia.org/wiki/Em_(typography)

    From the Font documentation linked below: "The em-size, in points, of the new font."
    From the PDFsharp XML documentation: "Gets the em-size of this font measured in the unit of this font object." The default unit is points. So with PDFsharp the value "14" gives a font height of 14 points.

    See also:
    https://learn.microsoft.com/en-us/dotnet/api/system.drawing.font.-ctor?view=windowsdesktop-8.0#system-drawing-font-ctor(system-string-system-single)