empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.28k stars 589 forks source link

Error while parsing an OpenType font #168

Closed chris-steema closed 2 years ago

chris-steema commented 2 years ago

Expected Behavior

I've modified slightly the PdfSharpIssueSurrogate with this unique substitution:

XFont font = new XFont("MS Pゴシック", 20, XFontStyle.BoldItalic);

This is the MS Gothic font, and I would expect this code to execute to produce text using this font.

Actual Behavior

An error is thrown:

PdfSharp.PdfSharpException
  HResult=0x80131500
  Message=Error while parsing an OpenType font.
  Source=PdfSharp
  StackTrace:
   at PdfSharp.Fonts.OpenType.CMapTable.Read()
   at PdfSharp.Fonts.OpenType.FontData.Read()
   at PdfSharp.Fonts.OpenType.FontData..ctor(XFont font, XPdfFontOptions options)
   at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font, XPdfFontOptions options)
   at PdfSharp.Fonts.FontDescriptorStock.CreateDescriptor(XFont font)
   at PdfSharp.Drawing.XFont.get_Metrics()
   at PdfSharp.Drawing.XFont.Initialize()
   at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyle style)
   at PdfSharpIssueSurrogate.Program.Main(String[] args) in C:\Users\Chris\source\repos\PdfSharpIssueSurrogate\PdfSharpIssueSurrogate\Program.cs:line 27

  This exception was originally thrown at this call stack:
    PdfSharp.Fonts.OpenType.CMapTable.Read()

Inner Exception 1:
InvalidOperationException: Font has no usable platform or encoding ID. It cannot be used with PDFsharp.

Steps to Reproduce the Behavior

Modify the PdfSharpIssueSurrogate as indicated.

TH-Soft commented 2 years ago

I guess this is a known limitation of the current implementation, not a bug.

http://pdfsharp.net/wiki/PostScript_fonts.ashx

chris-steema commented 2 years ago

Thank you for the information @TH-Soft