Harald Oehlmann <
wort...@yahoo.com> wrote:
> Am 24.01.2024 um 19:41 schrieb Rich:
>> Harald Oehlmann <
wort...@yahoo.com> wrote:
>>> Thanks for great pdf4tcl !
>>>
>>> I have a string with Chinese characters.
>>> I output them with pdf4tcl:
>>> ...
>>>
>>> I only get question marks.
>>> The interesting ::pdf4tcl::createFont command should be used to select
>>> 256 glyphs. Well, Chinese language has a magnitude of this.
>>
>> You are bumping into a PDF limitation.
>>
>> Each "font" within a PDF can address at most 256 characters. This is a
>> limit from very early in PDF's lifetime, and creates a real PIA for
>> using non-ASCII characters.
>>
>> Basically you have to create a "custom" font in the pdf using
>> ::pdf4tcl::createFontSpecEnc with a custom encoding of codepoints (the
>> ...
>>
> Thank you, Rich. That is what I feared.
> Is there nobody out there who has automated this?
Not that I'm aware of for pdf4tcl. Possibly for some other library for
some other language.
> I suppose, this is not easy...
Not trivial, not rocket science either.
> You also want to have one text field with one font, otherwise, the text
> is interrupted, I suppose.
Depending upon what you mean by text field, you can switch fonts before
drawing each glyph if you like and it will have no impact on the final
viewing of the pdf. If by field you mean a data entry field, then I
have no idea there.
When you delve down into the PDF internals, you find that PDF is
nothing more than instructions to place glyphs at x,y positions on a
sheet of virtual paper. I.e., internally it is very much like the
Tcl canvas widget. Which is why 'font switches' don't cause problems
with the render (unless you, the creator, create vastly different
actual fonts for 'effect'). But if the plural "fonts" are all of the
same size and all from the same base, font switches are invisible in
the final render.
> So, I will try to create a function, which assembles the glyphs of one
> text, then creates a font and then outputs it.
Yes, you either have to decide what glyphs you want ahead of time, and
'pre-create' fonts to draw those glyphs, or you have to analyze the
characters you want to "print" for the pdf (or for the current page)
and create a custom font for those characters.
The one advantage you get for the second method is that most unicode
TTF font files are huge, and if you create a custom internal font for
only the used characters, pdf4tcl only embeds the glyphs for the
characters you actually use, which means if you only use 1% of the
glyphs, you only store 1% of the font file into the pdf, making the pdf
smaller.
> In a 2nd step, an optimization may be done to find one font with 256
> characters, which assembles as many text snippets as possible.
Yes, it will be possible to do so, sometimes. For Chinese, given the
huge number of total characters, this may be difficult to do in a
general sense for all possibilities, but you might come close.