Issue 71804 - PDF: Wrong kashida export
Summary: PDF: Wrong kashida export
Status: CLOSED FIXED
Alias: None
Product: gsl
Classification: Code
Component: code (show other issues)
Version: 680m193
Hardware: All Windows, all
: P3 Trivial (vote)
Target Milestone: OOo 3.1
Assignee: h.ilter
QA Contact: issues@gsl
URL:
Keywords:
Depends on: 60594
Blocks:
  Show dependency tree
 
Reported: 2006-11-21 10:39 UTC by frank.meies
Modified: 2009-04-22 10:41 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
bugdoc (55.15 KB, application/vnd.oasis.opendocument.text)
2006-11-21 10:40 UTC, frank.meies
no flags Details
pdf (15.32 KB, application/pdf)
2006-11-21 10:41 UTC, frank.meies
no flags Details
Sample pdf file (35.87 KB, application/pdf)
2008-10-29 11:49 UTC, hennerdrewes
no flags Details
kashida document (19.97 KB, application/vnd.oasis.opendocument.text)
2008-10-29 12:16 UTC, hennerdrewes
no flags Details
PDF export on Vista (38.76 KB, application/pdf)
2008-10-31 09:19 UTC, hennerdrewes
no flags Details
small fix (644 bytes, patch)
2008-11-26 12:02 UTC, hennerdrewes
no flags Details | Diff
bugdoc (9.58 KB, application/vnd.oasis.opendocument.text)
2008-11-26 12:35 UTC, hennerdrewes
no flags Details
result of pdf export (17.39 KB, application/pdf)
2008-11-26 12:36 UTC, hennerdrewes
no flags Details
pdf by ghostscript (13.73 KB, application/pdf)
2008-11-26 14:04 UTC, hennerdrewes
no flags Details
OOo pdf on Vista: surprise (17.19 KB, application/pdf)
2008-11-26 18:53 UTC, hennerdrewes
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description frank.meies 2006-11-21 10:39:13 UTC
Kashidas (in justified alignment) are not exported correctly to pdf, see
attached documents.
Comment 1 frank.meies 2006-11-21 10:40:34 UTC
Created attachment 40790 [details]
bugdoc
Comment 2 frank.meies 2006-11-21 10:41:03 UTC
Created attachment 40791 [details]
pdf
Comment 3 hdu@apache.org 2006-11-21 11:03:15 UTC
Accepting.
Problem on Win only.
Comment 4 Martin Hollmichel 2008-01-28 02:31:40 UTC
set target 3.x
Comment 5 hdu@apache.org 2008-10-29 09:29:54 UTC
Fixed in CWS kashidafix.
Comment 6 hennerdrewes 2008-10-29 11:48:38 UTC
@hdu: haven't noticed that there was a separate issue for this (:

seems that there are still kashida-gaps in PDF export. 
Attaching sample.
Comment 7 hennerdrewes 2008-10-29 11:49:46 UTC
Created attachment 57537 [details]
Sample pdf file
Comment 8 hdu@apache.org 2008-10-29 11:58:31 UTC
@hennerdrewes: thank you for checking this. Is this with the latest CWS code? Can you attach the 
corresponding document?
Comment 9 hennerdrewes 2008-10-29 12:15:17 UTC
@hdu: I checked out from CVS this morning. Attaching source file. 
From my previous tryouts, it always seemed a good practice to change formatting
a lot in the source documents (fonts, font size, line width) to discover
possible problems. 

Therefore my source document is not the same as the previously attached PDF, but
you will see the problem also in this version.
Comment 10 hennerdrewes 2008-10-29 12:16:19 UTC
Created attachment 57539 [details]
kashida document
Comment 11 hdu@apache.org 2008-10-29 15:09:26 UTC
Indeed, if there was not enough space for a full injected glyph it wasn't emitted. This is fixed now with the 
new commit to winlayout.cxx in CWS kashidafix.

The more general problem that the extra space should be filled with something even when the minimal 
kashida width is way to big for that extra space is almost unsolvable. Any ideas? In the PDF-case one 
could stretch the font matrix but that is an IMHO horrible workaround and the effort would be quite 
enormous, especially compared to the benefit.
Comment 12 hennerdrewes 2008-10-29 15:33:35 UTC
This is what I was trying to accomplish in KashidaWordFix. Straightening out the
character spacing as much as possible. But maybe this is all what can be done. 

Another horrible scenario came to my mind: Applying expanded or condensed
character spacing... 
Comment 13 hdu@apache.org 2008-10-29 16:35:12 UTC
The stupid bug was that the glyph injection only worked correctly when the extra space was an exact 
multiple of the injected-glyph width. This is fixed now and works if there is reasonable room for it.

AFAIK KashidaWordFix also stopped when there was not sufficient space for rearranging? The scenario you 
mentioned is indeed horribly complex... but thankfully it is not nearly as important to fix than the changes 
needed for the PDF export that we have now in that CWS.
Comment 14 hennerdrewes 2008-10-30 09:14:50 UTC
I know I am a (what they call in Hebrew) nudnik (Nervensäge)...

The glyph overlapping works quite well for e.g. Arial. With TraditionalArabic
(with its huge kashida glyph widths) you still get a lot of gaps. 
Comment 15 hdu@apache.org 2008-10-30 10:45:02 UTC
@nudnik: ;-)

@hennerdrewes: Thanks for checking! We really appreciate your expertise and your patches. When the 
minimal kashida width is still way too big to fill the gaps then what to do? Uniscribe's ScriptTextOut() 
seems to have the exact same problem. AFAIT it was not introduced by your Kashida*Fix() rearrangement. 
Do you happen to know how related apps handle this? Do they use line-drawing instead?
Comment 16 hennerdrewes 2008-10-30 11:58:33 UTC
The TraditionalArabic font reports at point size 24 a minimal kashida width of
20! To compare, other fonts (Arial, ArabicTypesetting) report 4 at the same size.

ScriptTextOut has problems with justification widths larger than the glyph
advance width (usually one or two extra pixels don't cause much harm) and
smaller than the minimal kashida width. These cases are pretty much covered by
the writer engine and by the KashidaWordFix. 

If we now have an extra width of let's say 22, we need to put out two
overlapping kashida glyphs, one justified to the left and one justified to the
right in this 22 pixel space, to cover the two pixel gap.

I can only guess, that this is what ScriptTextOut does. 
Comment 17 hdu@apache.org 2008-10-30 16:37:59 UTC
> ScriptTextOut has problems with justification widths larger than the glyph
> advance width (usually one or two extra pixels don't cause much harm) and
> smaller than the minimal kashida width. These cases are pretty much covered by
> the writer engine and by the KashidaWordFix. 

I'm seeing gaps in the screen output for that case too (for some formattings). Did I break KashidaWordFix?

> If we now have an extra width of let's say 22, we need to put out two
> overlapping kashida glyphs, one justified to the left and one justified to the
> right in this 22 pixel space, to cover the two pixel gap.

Yes, this is done exactly that way in the current version (now resynced to m32, i.e. on SVN). The 
problem is if the gap is e.g. less than 5 pixels.

Comment 18 hennerdrewes 2008-10-31 09:17:18 UTC
> I'm seeing gaps in the screen output for that case too 
> (for some formattings). Did I break KashidaWordFix?

This is not good...
Well this happened all the time, and I did many rounds of debug sessions to
improve things. I haven't encountered the problems in the current version
though. But I am not surprised that it still can happen. 

> Yes, this is done exactly that way in the current version 
> (now resynced to m32, i.e. on SVN). 
> The problem is if the gap is e.g. less than 5 pixels.

I am not sure if I fully understand everything in the GetNextGlyphs() (yet), but
why is there this  if( 4*nExtraWidth >= mnMinKashidaWidth ) ?
It looks like you won't get the needed overlap, if the nExtraWidth is small.

Apart from the gaps the PDF export looked fine. Now I tested it again on my
Vista machine, and everything turns out pretty garbled. (: Attaching sample.


Comment 19 hennerdrewes 2008-10-31 09:20:00 UTC
Created attachment 57606 [details]
PDF export on Vista
Comment 20 hdu@apache.org 2008-11-25 15:43:51 UTC
Now also fixed for vista on the CWS kashidafix (caveat: CWS is on subversion now)
Comment 21 hennerdrewes 2008-11-26 11:52:50 UTC
@hdu: wait a second...
Comment 22 hennerdrewes 2008-11-26 12:02:06 UTC
Created attachment 58316 [details]
small fix
Comment 23 hdu@apache.org 2008-11-26 12:18:27 UTC
@hennerdrewes: nice one, thanks!
Of course glyph injection should fill the whole kashida-space even if the last injected glyph needs to 
overlap with its predecessor.
Comment 24 hennerdrewes 2008-11-26 12:34:48 UTC
with this fix, the pdf output of the bugdos looks much better. With Arial, there
were still a lot of tiny but noticable gaps. They seem to be gone completely now. 

With TraditionalArabic however, there are much less problems, but still, once in
a while, the gaps are there. Attaching samples.
Comment 25 hennerdrewes 2008-11-26 12:35:55 UTC
Created attachment 58318 [details]
bugdoc
Comment 26 hennerdrewes 2008-11-26 12:36:33 UTC
Created attachment 58319 [details]
result of pdf export
Comment 27 hennerdrewes 2008-11-26 12:55:10 UTC
@hdu: for now, I cannot see a reason why this is happening. The glyph injection
code seems to be fine now. 
Comment 28 hdu@apache.org 2008-11-26 13:02:23 UTC
I suspect a discrepancy between the MinKashidaWidth and the actual glyph width for this font, testing...
Comment 29 hennerdrewes 2008-11-26 13:19:35 UTC
What is strange: both kashida stretched words at the beginning of the line are
expanded by exactly the same value (as expected). But the glyph to the right of
the kashida is much wider in the problematic case. 

Maybe the advance width is incorrect (to wide)? And then the glyph is right
aligned (XP) to far away from the kashida? 

I don't  think that there is a problem with MinKashidaWidth in this case.

Comment 30 hennerdrewes 2008-11-26 14:04:33 UTC
Created attachment 58322 [details]
pdf by ghostscript
Comment 31 hennerdrewes 2008-11-26 14:08:09 UTC
some more thoughts: It may be interesting to look at the pdf produced by
ghostscript. 

What I find most peculiar: I opened both pdfs in the reader and enlarged the
zoom to 800%. Measuring the widths of words and glyphs I find that both outputs
are matching, besides the problematic word. There is definitely an additional
width. 

Where does it come from?
Comment 32 hdu@apache.org 2008-11-26 15:42:41 UTC
The output between the two PDFs is matching indeed except there is this offset since the problematic 
glyph (initial form of U+0644). Since the width of the isolated U+0644 is quite different, the offset is in 
the same range as their width-difference...

@pl: since CWS glyphadv there is an optimization in the PDF export which might be related: The 
registerGlyphs() method checks the glyph width for the corresponding isolated codepoint instead of the 
actual glyph?
Comment 33 philipp.lohmann 2008-11-26 16:39:29 UTC
@hdu: you are mistaken. That happens only for embeddable -> type1 fonts where
GF_ISCHAR is set on glyph ids anyway.
Comment 34 hennerdrewes 2008-11-26 18:53:38 UTC
Created attachment 58334 [details]
OOo pdf on Vista: surprise
Comment 35 hennerdrewes 2008-11-26 19:05:24 UTC
@hdu: It looks as if we have to have to focus on the manual right alignment. On
Vista everything looks perfect.
Comment 36 hdu@apache.org 2008-11-27 12:47:20 UTC
Yup, there was a thinko in the glyph injection case. This code-complexity-reduction didn't trigger 
reliably...
Comment 37 hdu@apache.org 2008-11-28 09:06:11 UTC
@hi/@sba: please verify on XP and Vista, please check for regressions on other platforms
Comment 38 stefan.baltzer 2008-12-10 08:47:28 UTC
Verified in CWS kashidafix.
Comment 39 h.ilter 2009-04-22 10:41:11 UTC
Verified with 3.1rc1