StimVinsh / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

incorrect paragraph styling in ODT->PDF via iText converter #58

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi
I've tested your odt to pdf converter and I've noticed that paragraph text is 
incorrectly converted. Some paragraph styling attributes are ignored or 
incorrectly interpreted.

Below I give a summary of paragraph odt attributes and their itext equivalent
marginLeft -> setIndentLeft
marginRight -> setIndentRight
marginTop -> setSpacingBefore
marginBottom -> setSpacingAfter

autoTextIndent - if true it means: indent first line of paragraph text with 
some default value. While exact algorithm of this indentation is not known to 
me, some people claim that it is 1.3*font size.

textIndent -> setFirstLineIndent - use value of this attribute only if 
autoTextIndent is false, otherwise ignore it. First line indent is cumulative 
with whole paragraph left indent.

lineHeight -> setMultipliedLeading or setLeading
lineheight may be proportional to font size (ie 115%). In this case use 
setMultipliedLeading in iText. Or it may be constant (ie 0.6cm). In this case 
use setLeading. Open Office may use other more exotic line height 
(line-height-at-least, line-height-leading) but it probably cannot be 
translated to iText so we can ignore it.

I've fixed it in the code. I attach an example .odt file and 4 files modified 
by me. After my fixes the example odt file is converted much better.
The only difference is when smaller and larger font is used in the same line 
and line height is proportional. Open Office uses the biggest font size to 
compute line height but iText seems to use beginning paragraph font to compute 
line height. I don't know how to change this behaviour but it is rather minor 
issue anyway.

Original issue reported on code.google.com by lesz...@safe-mail.net on 14 Dec 2011 at 9:14

Attachments:

GoogleCodeExporter commented 8 years ago
Hi,

Thank a lot for your contribution! I will study tour code as soon as possible 
and integrate it to XDocReport. I think it should be good if you add your name 
in the code and you create a Git patch too.

Regards Angelo

Original comment by angelo.z...@gmail.com on 14 Dec 2011 at 9:23

GoogleCodeExporter commented 8 years ago
Actually I work with Netbeans with sources from maven repository (0.9.3 
version) and I don't have git plugin. So it would be difficult for me to make a 
patch. But I can give you description what is changed

StyleEngineForIText - changed function public void 
visit(StyleParagraphPropertiesElement ele)
StyleParagraphProperties, StylableParagraph - almost fully rewritten
ODFUtils - added function hasPercentUnit(String s)

if you put my name Leszek Piotrowicz somewhere in these files I would be 
grateful

Regards
Leszek

Original comment by lesz...@safe-mail.net on 14 Dec 2011 at 10:43

GoogleCodeExporter commented 8 years ago
Ok I understand.

I think the better thing is that you resend your java file that you have 
changed with a comment with your name. I could commit that after.

Thank a lot for your help.

Original comment by angelo.z...@gmail.com on 14 Dec 2011 at 12:01

GoogleCodeExporter commented 8 years ago
Ok, one more thing about the code
I added marginLeft, marginTop ... as separate fields to 
StyleParagraphProperties but I've just noticed there is helper class 
StyleMargin. These fields may be replaced by StyleMargin instance but what with 
style merging in this case? Individual fields should be merged rather then the 
whole StyleMargin instance. What do you think about it?

Original comment by lesz...@safe-mail.net on 14 Dec 2011 at 12:31

GoogleCodeExporter commented 8 years ago
> Individual fields should be merged rather then the whole StyleMargin 
instance. What > do you think about it?
Yes you are right, I have coded that quickly and our PDF converter have a lot 
of bugs and must be improved a lot. PDF converter are not our first goal so we 
prefer using our energy for another topics but your help is really welcome!

Regards Angelo

Original comment by angelo.z...@gmail.com on 14 Dec 2011 at 1:10

GoogleCodeExporter commented 8 years ago
I decided to have marginLeft, ... as separate fields to keep it simple

one attribute = one simple field
unless the attribute isn't single value attribute (ie table border)

I also attach updated files

I've noticed that pdf converter isn't perfect. But for simple documents it 
works pretty well and fast (after some fixes). Good work. I will test odt->pdf 
converter in the future and try to provide more fixes if I encounter them.

Regards
Leszek

Original comment by lesz...@safe-mail.net on 15 Dec 2011 at 9:44

Attachments:

GoogleCodeExporter commented 8 years ago
Ok I have commited your classes. Many thanks!
I hav ecreated in the JUnit 
http://code.google.com/p/xdocreport/source/browse/thirdparties-extension/org.odf
toolkit.odfdom.converter/src/test/java/org/odftoolkit/odfdom/converter/AbstractO
DFDOMConverterTest.java the testParagraphFomatting method.

Original comment by angelo.z...@gmail.com on 21 Dec 2011 at 8:25