Symbol font rendering to PDF issue


Rendering a character to a PDF using a symbol font has an issue if you send 16 bit unicode character with the high bits already set. It works fine when rendering the same thing to GDI+, but fails for PDFs. I tracked it down to a couple lines that look like this:
glyphID = (int)ch + (descriptor.fontData.os2.usFirstCharIndex & 0xFF00);
It's adding the first symbol character index to the character to get its index, but if the character already includes the index, it shouldn't be adding it. It should be performing a bitwise "or" | instead of an "add" +. Just a 1 byte patch. The line should look like this instead:
glyphID = (int)ch | (descriptor.fontData.os2.usFirstCharIndex & 0xFF00);
There are two similar lines which need to be fixed:
PdfSharp.Drawing.Pdf\XGraphicsPdfRenderer.cs line 523
PdfSharp.Fonts\CMapInfo.cs line 71


bwagner wrote Jan 11, 2013 at 2:28 PM

Sorry for posting here instead of the official forum, but a firewall is blocking my access to the pdfsharp.net forum. Hopefully this issue tracker will be checked occasionally.

wrote Feb 22, 2013 at 12:12 AM

bwagner wrote Sep 17, 2013 at 6:29 PM

I found another location with the same issue:

PdfSharp.Fonts.OpenType\OpenTypeDescriptor.cs line 232

dalqamouny wrote Apr 20, 2016 at 7:19 AM

I tried the above fix over an Arabic writting, and it showed disconnected charecters with reversed directions
appreciated your help