Hello Pierre,
On 12/19/17 14:29, Pierre Clouthier wrote:
> Thank you very much for the work. I was wrong to say "Amyuni doesn't
> embed the fonts", my knowledge of PDF is rudimentary :o) I understand
> (as you explain) that Amyuni embeds a smaller subset of the fonts.
>
> I downloaded and used your new version of hpdf_font_cid.c. It reduced
> the size of my test file from 360K to 300K (see attached). That's a
> good start.
That nice to hear :)
> A few comments:
>
> [1] My program tells Haru to embed Arial, Arial Bold, Arial Italic,
> etc. whereas Amyuni only has Arial. That's because I am naïvely
> assuming that I need all these fonts to do bold & italic. I don't
> understand how Amyuni is achieving bold & italic without including
> these specific font variations in the PDF file. I am not aware of a
> PDF "bold" or "italic" command.
I can see how Amyuni simulates a bold font. But is there any actual
text in italic? I can't see any latin characters in italic style. Of
the arabic characters, I can't tell if there are some in italic :)
Amyuni just simulates a bold font. It does this by using the Tr
command. libharu defines the HPDF_Page_SetTextRenderingMode function
to output this command. By setting the text rendering mode to 2
(HPDF_FILL_THEN_STROKE) and setting a certain line width, characters
will appear bolder. First, the glyphs are drawn as usual, then the
outline is drawn again with a certain line width (your example uses
a width of 0.24). So then the glyphs will appear a bit bolder.
You can do the same in libharu. To switch back to "normal" mode, use
HPDF_Page_SetTextRenderingMode(HPDF_FILL).
However, using a real bold font, will typically produce visually
more appealing results as bold fonts normally aren't just bolder
copies of the normal fonts, but optimized.
But if you really depend on a small file, that's a of a course a
way it can be done (the typographical nerd in the back of head is
now screaming "Noooo, you can't do that, that's totally wrong" ;) ).
I don't know if an italic font can be produced in a similar way -
if you are able to produce it in Amyuni, you can send the file to
me and I can find out how they're doing it.
> [2] "map all characters to glyphs in the PDF driver libharu and set
> /CIDToGIDMap to /Identity"
> I would be very interested in pursuing this. What can I do to help?
There are two possibilities:
a) resolve all characters to glyphs in your application, position
them on the page, use the master branch from my libharu
repository, and call the function HPDF_SetTTFontGIDMode(pdf,
font_name) for every loaded font.
After calling this function the strings written have to only
consist of glyph ids and things like automatic line breaking
will no longer work.
Our application is only using the HPDF_Page_ShowTextNextLine
and HPDF_Page_ShowText functions.
We are using FreeType, GNU FriBidi, and Harfbuzz to produce
the correct string of glyphs and create a text layout.
This allows us to correctly handle texts with mixed left-to-
right and right-to-left parts, shape arabic texts, enable/
disable various features of the used fonts (e.g. using either
proportional or tabular numbers), etc.
b) Use a similar approach, but resolve the texts to glyphs in
libharu.
It's probably enough to intercept the texts in the
InternalWriteText and InternalShowTextNextLine functions. The
function HPDF_TTFontDef_GetGlyphid can be used for a simple
mapping. This is however no longer anough with arabic fonts,
where a full text shaping engine like HarfBuzz should be used
(because there's no simple char->glyph mapping, but instead
glyphs have to be selected according to the context).
Translating characters to glyphs can probably be done by
using the font_attr->encoder->encode_text_fn - however, after
playing a bit around with this and trying to get this cleanly
into libharu, I had given up and reverted to approach a).
Unfortunately, I don't have such a deep insight to libharu to get
these changes cleanly in (without killing other functions), that's
why I haven't done more in that direction.
Thanks,
Adalbert