Conversation
nimPDF/fontmanager.nim
Outdated
| discard | ||
|
|
||
| method EscapeString*(f: Base14, text: string): string = | ||
| method EscapeString*(f: Base14, text: string, embedFont: bool = false): string = |
There was a problem hiding this comment.
embedFont should passed through setFont, then the table initialization is done once in makeFont.
I prefer users have liberty to choose which font they want to embed. And for the global embedFont flag,
it will override the setFont's embedFont flag.
Built in font have no effect when setting this font.
There was a problem hiding this comment.
I understand. During my testing I used some more fonts from the demo folder an got in trouble with the width, so that's the first commit #da483d4.
For the setFont() I added an embedFont: bool and got it to work partially, so the font got embedded (copy-paste'able) but the rendering broke. So I'm gonna pass on that one for now.
There was a problem hiding this comment.
Hello @jangko
I have gotten help from @bung87 to implement the embedFont parameter. This now works, and it also works with the global setting. For me when setting the embed to false it also becomes a real drawing instead of allowing you to copy which would result in gibberish chars.
Do you need anything else?
There was a problem hiding this comment.
Can you add options to keep the old mapping instead of replacing it with glyph drawing? Drawing glyph using PDF path will increase the document size significantly compared to simple mapping. I mean, make the user able to choose how to render the text. Copyable vs small document size are options, give the user freedom, don't force them if possible.
There was a problem hiding this comment.
shall we replace embedFont param to enum type ?
type
FontRenderMode* = enum
frmDefault ## Do not embed font, render as text
frmEmbed ## Embed font and render as text
frmPathRendering ## Draw glyphs as pathsThere was a problem hiding this comment.
Hi @jangko
Please see the changes made by bung. The global option is gone, but you can now use the enum on each draw.
Embed fonts
- Add FontRenderMode enum with frmDefault, frmEmbed, and frmPathRendering options - Implement full font embedding with proper Unicode mapping for text extraction - Fix ToUnicode CMap generation to use correct GID mapping based on render mode - Update font subsetting logic to handle different rendering modes - Improve character-to-glyph mapping for embedded vs subset fonts - Add renderMode parameter to font creation and management functions
feat: implement font embedding modes and improve text selectability
This PR adds the ability to embed fonts directly into the generated PDF files.
Embedding increases the PDF file size slightly, but enables much better post-processing compatibility - especially when copying text or handling non-ASCII characters.
This also solves my issue from 2021 :) #39
Example
To enable font embedding, simply set the new option:
Notes
I've aimed to keep the implementation as non-intrusive as possible, but it will always load the font cache in the
makeTTFont().