1

I am generating multi-lingual PDF using Apache FOP 2.5, including Latin, Cyrillic and Arabic characters. I managed to include the proper fonts, and I was able to deal with the right-to-left display for Arabic, when needed.

However I am facing an issue with letter-spacing in Arabic characters : the characters are spaced out from each other. This is what I see in the generated PDF

enter image description here

But this is what I have in the original XML (please note how the Arabic characters are close to each other) :

enter image description here

I am using the Deja Vu font and I have computed the metrics of the font using what is described here.

How can I solve this ?

I have read this article which basically inserts letter-spacing="-2pt" everytime the string to be displayed is in Arabic. But I don't want to hardcode tests on the language in the stylesheet.

Any help appreciated !

EDIT :

  • Using FOP 2.5
  • I confirm that complex-script is enabled (added a debug message to be sure)
  • I had set kerning="yes" set in the config file
ThomasFrancart
  • 470
  • 3
  • 13
  • Found similar question at https://stackoverflow.com/questions/49532386/xsl-fo-displaying-arabic-characters – ThomasFrancart Dec 15 '20 at 16:14
  • 1
    Are you stuck on FOP 1.1? The current version is FOP 2.5 (though I have no idea if it actually does Arabic any better). AFAICT, FOP 1.1 dates from 2012. – Tony Graham Dec 15 '20 at 16:49
  • 2
    Adding `letter-spacing` isn't going to fix this anyway. You can't just smash together Arabic letters; they change shape depending on where they are in the word. "مُتغلى" doesn't look anything like "مُ ت غ ل ى". I suspect you've turned off "complex-scripts" somewhere (as mentioned in your linked answer). I'd also try removing all styling (specifically italic, which may not work correctly with Arabic. The concept of "italic" doesn't precisely translate into Arabic script, and support for it is spotty.) I'd also try being explicit with `language="ar"`. – Rob Napier Dec 15 '20 at 17:24
  • I just updated to FOP 2.5 and have the same behavior – ThomasFrancart Dec 15 '20 at 17:27
  • I haven't touched anaything related to complex scripts, which I read is enabled by default. If that matters, FOP is initialized from a config file read from a Java application where it is embedded. I will try enabling complex sciprts explicitely. – ThomasFrancart Dec 15 '20 at 17:30
  • 1
    Consider that the font metrics for that font are just wrong. Test it by switching the font to Arial and see if it is not better, then it is likely the font. – Kevin Brown Dec 15 '20 at 19:56
  • Consider replacing the _image_ of the source FO elements with the actual _XML code_, so as to provide an example people can use to quickly replicate your problem and check what goes wrong. – lfurini Dec 16 '20 at 11:28
  • 1
    Note that font metrics are needed no more in recent versions of FOP; removing them from the font configuration would allow you to check whether they are the source of the problem. – lfurini Dec 16 '20 at 17:48

1 Answers1

3

Thanks to the very valuable comments received, I was able to solve the problem by :

  1. Upgrading to FOP 2.5
  2. Switching to another Font (Traditional Arabic instead of Deja Vu)
  3. And, as FOP 2.5 does not require a font metrics file, removing the font metrics.

In the meanwhile I saw that embedding the fonts in my application was more difficult in FOP 2.5 than in FOP 1.1 because it is harder to set relative URLs in FOP font configuration. I was able to solve this with this other answer.

ThomasFrancart
  • 470
  • 3
  • 13