wxPdfDoc - Probblem with WriteXml and align=justify

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
dschmeer
In need of some credit
In need of some credit
Posts: 1
Joined: Fri Apr 13, 2018 10:04 pm

wxPdfDoc - Probblem with WriteXml and align=justify

Postby dschmeer » Fri Apr 13, 2018 10:10 pm

I use WriteXml to draw some paragraphs of text with align=justify. For the standard fonts this works fine, but for other fonts it simply draws the text left-aligned.

Here is the code I use:

Code: Select all

   wxPdfFontManager::GetFontManager()->RegisterSystemFonts();
   wxPdfDocument pdf;
   pdf.SetFont("Helvetica");
   pdf.AddPage();
   pdf.SetMargins(25, 20, 120);
   pdf.SetXY(25, 20);
   pdf.Rect(25, 20, 65, 150);
   pdf.WriteXml("<p align=\"justify\"><font face=\"Helvetica\">The quick brown fox jumps over the lazy dog</font></p>");
   pdf.WriteXml("<p align=\"justify\"><font face=\"Times\">The quick brown fox jumps over the lazy dog</font></p>");
   pdf.WriteXml("<p align=\"justify\"><font face=\"Arial\">The quick brown fox jumps over the lazy dog</font></p>");
   pdf.WriteXml("<p align=\"justify\"><font face=\"Calibri\">The quick brown fox jumps over the lazy dog</font></p>");
   pdf.WriteXml("<p align=\"justify\"><font face=\"Verdana\">The quick brown fox jumps over the lazy dog</font></p>");
   pdf.WriteXml("<p align=\"justify\"><font face=\"Times New Roman\">The quick brown fox jumps over the lazy dog</font></p>");
   pdf.WriteXml("<p align=\"justify\"><font face=\"Georgia\">The quick brown fox jumps over the lazy dog</font></p>");
   pdf.SaveAsFile("test.pdf");


The first two paragraphs are justified, the rest are left aligned.

Has anyone an idea why this is and what I can do to fix this?

Versions:
wxWidgets 3.1.0
wxPdfDoc 0.9.6
Visual C++ 2015
Platform Windows 10

Thanks a lot
Dieter

utelle
Moderator
Moderator
Posts: 813
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDoc - Probblem with WriteXml and align=justify

Postby utelle » Sat Apr 14, 2018 2:07 pm

dschmeer wrote:I use WriteXml to draw some paragraphs of text with align=justify. For the standard fonts this works fine, but for other fonts it simply draws the text left-aligned.

Has anyone an idea why this is and what I can do to fix this?

I used your code sample to investigate the issue. Unfortunately, I have to confirm that justifying text works only for the standard fonts.

In principle, the calculations in wxPdfDocument for adjusting the word spacing are correct. However, I was not aware of a limitation of the PDF specification - the word spacing operator (that is currently used by wxPdfDocument) is only applied to simple fonts. Following the respective paragraph from the PDF reference:
Word spacing shall be applied to every occurrence of the single-byte character code 32 in a string when using a simple font (including Type 3) or a composite font that defines code 32 as a single-byte code. It shall not apply to occurrences of the byte value 32 in multiple-byte codes.

The fonts you are using are handled as TrueType Unicode strings ... and therefore the word spacing operator is not applied.

Unfortunately, it will not be trivial to overcome this limitation, because it will require to break up the text string at every space character and to explicitly adjust the word spacing.

Regards,

Ulrich


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 3 guests