Closed GoogleCodeExporter closed 9 years ago
It seems that it's more complex than just change attributes value because if
you wish change font size, it's an attribute w:val
------------------------------------
<w:sz w:val="24" />
------------------------------------
but which is included to <w:rPr> :
------------------------------------
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:u w:val="single" />
<w:lang w:val="en-US" />
</w:rPr>
------------------------------------
How to manage that?
More in the docx you can have several <w:rFonts with different values, how to
know if value must be changed or not?
Perhaps a solution to manage that is to use HWPF POI
http://poi.apache.org/hwpf/index.html before XDocreport to manage complex task
like font and after load it to XDocReport?
Original comment by angelo.z...@gmail.com
on 9 Feb 2012 at 4:28
Hi,
I have modified XDocReport API to add custom preprocessor. Preprocessor is used
to modify XML entries of the odt, docx, etc to manage for instance lazy loop
for table.
So now you can do that :
------------------------------------------------------------
IXdocReport report = ...;
IXDocPreprocessor myPreprocessor = ...;
report.addPreprocessor( "word/document.xml", myPreprocessor );
------------------------------------------------------------
to add a preprocessor which will modify the "word/document.xml" (please note
that you have constants for "word/document.xml" in
DocxConstants.WORD_DOCUMENT_XML_ENTRY)
A processor can be implemented with SAX or DOM. In internal processor for docx,
odt, SAX is used (see SAXXDocPreprocessor) but you can use DOM (with
DOMPreprocessor) which is more easy.
Now XDocReport provides utilities classes to work with DOM (DOMUtils) and XPath
(XPathUtils).
Now docx project provides DOMFontsPreprocessor (which is not finished) (see
http://code.google.com/p/xdocreport/source/browse/document/fr.opensagres.xdocrep
ort.document.docx/src/main/java/fr/opensagres/xdocreport/document/docx/preproces
sor/dom/DOMFontsPreprocessor.java) which is enable to modify XML entry to
replace :
------------------------------------------------------------
<w:rFonts w:ascii="Arial"
w:hAnsi="Arial"
w:cs="Arial" />
------------------------------------------------------------
with (for Freemarker) :
------------------------------------------------------------
<w:rFonts w:ascii="[#if ___fontName??]${___fontName}[#else]Arial[/#if]"
w:cs="[#if ___fontName??]${___fontName}[#else]Arial[/#if]"
w:hAnsi="[#if ___fontName??]${___fontName}[#else]Arial[/#if]"/>
------------------------------------------------------------
So after you can use IContext to put the value of ___fontName (ex:with
"Magneto") :
------------------------------------------------------------
context.put( "___fontName", "Magneto" );
------------------------------------------------------------
Not that you have a constants for "___fontName" in
DOMFontsPreprocessor.FONT_NAME_KEY
The XML entries that it must be preprocessed must be word/document.xml but too
word/header1.xml, word/header2.xml..., c, word/header2.xml...
For do that you do like this:
------------------------------------------------------------
IXDocReport report = XDocReportRegistry.getRegistry().loadReport( in,
TemplateEngineKind.Freemarker );
report.addPreprocessor( DocxConstants.WORD_DOCUMENT_XML_ENTRY, DOMFontsPreprocessor.INSTANCE );
report.addPreprocessor( DocxConstants.WORD_HEADER_XML_ENTRY, DOMFontsPreprocessor.INSTANCE );
report.addPreprocessor( DocxConstants.WORD_FOOTER_XML_ENTRY, DOMFontsPreprocessor.INSTANCE );
------------------------------------------------------------
For word/header1.xml, word/header2.xml, ... the
DocxConstants.WORD_HEADER_XML_ENTRY is a wilcard (word/header*.xml)
You have the sample of w:rFonts in the following JUnit:
http://code.google.com/p/xdocreport/source/browse/integrationtests/fr.opensagres
.xdocreport.core.test/src/test/java/fr/opensagres/xdocreport/document/docx/prepr
ocessor/fonts/DocxFontsWithFreemarkerTestCase.java
Original comment by angelo.z...@gmail.com
on 10 Feb 2012 at 1:37
Wow! That's amazing
I'm going to travel today. Monday i will synchronize and test, then i give you
a feedback.
Thanks a lot.
Vinicius
Original comment by vinicius...@gmail.com
on 10 Feb 2012 at 3:27
Hi Vincius,
For your information, DOMFontsPreprocessor works with Freemarker and Velocity
now.
You have 2 samples :
* with Freemarker : http://code.google.com/p/xdocreport/source/browse/integrationtests/fr.opensagres.xdocreport.core.test/src/test/java/fr/opensagres/xdocreport/document/docx/preprocessor/fonts/DocxFontsWithFreemarkerTestCase.java
* with Velocity : http://code.google.com/p/xdocreport/source/browse/integrationtests/fr.opensagres.xdocreport.core.test/src/test/java/fr/opensagres/xdocreport/document/docx/preprocessor/fonts/DocxFontsWithVelocityTestCase.java
If you want understand what the DOMFontsPreprocessor do (generate template
engien directive), you have 2 tests :
* with Velocity:
http://code.google.com/p/xdocreport/source/browse/integrationtests/fr.opensagres
.xdocreport.core.test/src/test/java/fr/opensagres/xdocreport/document/docx/prepr
ocessor/fonts/DOMFontsPreprocessorWithVelocityTestCase.java
* with Freemarker:
http://code.google.com/p/xdocreport/source/browse/integrationtests/fr.opensagres
.xdocreport.core.test/src/test/java/fr/opensagres/xdocreport/document/docx/prepr
ocessor/fonts/DOMFontsPreprocessorWithFreemarkerTestCase.java
Regards Angeelo
Original comment by angelo.z...@gmail.com
on 14 Feb 2012 at 2:19
Hi,
It's works, but the font-size is not the same showing in editor.
If i set:
context.put( DOMFontsPreprocessor.FONT_SIZE_KEY, "32" );
document.xml in font size will be 32
but on editor will be 16.
The font size showing at editor is always a half of FONT_SIZE_KEY
Regards,
Vinicius
Original comment by vinicius...@gmail.com
on 14 Feb 2012 at 11:37
Hi Vincius,
I have seen this problem too. It seems that problem comes from with <w:szCs
w:val="40" />
According the MS doc
http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.fo
ntsizecomplexscript.aspx whn you use <w:szCs Font take the half size.
But I don't understand that because in your docx you have :
------------------------------------
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:u w:val="single" />
<w:lang w:val="en-US" />
</w:rPr>
------------------------------------
and size is 24 for the both <w:sz and <w:szCs?
In my case when I create empty docx and I set a police to a text I have never
<w:szCs?
My question is how to fix the problem?
1) remove everytime <w:szCs element?
2) multiply with 2 the ___fontSize coming from the context for <w:szCs?
3) add a new ___fontSizeCs value coming from the context?
Rgards Angelo
Original comment by angelo.z...@gmail.com
on 15 Feb 2012 at 8:21
Hi Angelo,
I think that multiply with 2 maybe is the best solution, because removing the
element should get incompatible with different plataforms (OpenOffice).. and
add a new ___fontSizeCs value from a context it's a config that the developer
don't need to know.
Thanks!
Vinicius
Original comment by vinicius...@gmail.com
on 15 Feb 2012 at 11:50
Hi Vinicius,
Ok I will change the directive of template engine to multiply with 2 the
___fontSize for <w:szCs element
Rgards Angelo
Original comment by angelo.z...@gmail.com
on 15 Feb 2012 at 12:58
Hi Vinicius,
Every thing is commited (JUnit+Sample). Here rules that I have applied
1) when there is not <w:szCs , <w:sz w:val take ___fontSize value
2) when there is <w:szCs , <w:sz w:val take ___fontSize* value
Pay attention, now you must put a integer value in the context and not a
string. So
DO LIKE THIS:
-----------------------------------------------------------
context.put( DOMFontsPreprocessor.FONT_SIZE_KEY, 32 );
-----------------------------------------------------------
and NOT like this :
-----------------------------------------------------------
context.put( DOMFontsPreprocessor.FONT_SIZE_KEY, "32" );
-----------------------------------------------------------
Regards Angelo
Original comment by angelo.z...@gmail.com
on 16 Feb 2012 at 3:54
I will try today, then i give you feedback.
Thanks,
Original comment by vinicius...@gmail.com
on 22 Feb 2012 at 10:56
It's work!
XdocReport it's the best!
Regards,
Vinicius Pavei
Original comment by vinicius...@gmail.com
on 25 Feb 2012 at 9:30
Hi Vinicius,
Many thanks!
I'm happy this feature please you:)
I fix this bug.
Regards Angelo
Original comment by angelo.z...@gmail.com
on 26 Feb 2012 at 10:46
What version of Xdocreport this feature will be build?
Regards,
Vinicius Pavei
Original comment by vinicius...@gmail.com
on 27 Feb 2012 at 6:40
0.9.6 and it was released.
Regards Angelo
Original comment by angelo.z...@gmail.com
on 27 Feb 2012 at 7:00
cleanup
Original comment by pascal.leclercq
on 10 Oct 2014 at 7:37
Original issue reported on code.google.com by
angelo.z...@gmail.com
on 9 Feb 2012 at 1:25