Skip to content

Commit d38e538

Browse files
Version 2.2.2.4 (2019-11-30)
---------------------------- - Now one element is mandatory in element 'cell' (minOccurs='1') - PDF FOP Renderer : Implementation of header and footer
1 parent ca0221f commit d38e538

File tree

10 files changed

+125
-19
lines changed

10 files changed

+125
-19
lines changed

fj-doc-base/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Version 2.2.2.4 (2019-11-30)
2+
----------------------------
3+
- Now one element is mandatory in element 'cell' (minOccurs='1')
4+
- PDF FOP Renderer : Implementation of header and footer

fj-doc-base/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Basic infrastructure for generation of [fj-doc XML format](http://www.fugerit.or
1010
*Status* :
1111
All basic features are implemented (plus helpers for other modules).
1212

13+
*[ChangeLog](ChangeLog.md)*
1314

1415
*Quickstart* :
1516

fj-doc-base/src/main/java/org/fugerit/java/doc/base/model/DocBase.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ The Apache Software Foundation (http://www.apache.org/).
3030
import java.util.Iterator;
3131
import java.util.Properties;
3232

33+
import org.fugerit.java.doc.base.typehelper.generic.GenericConsts;
34+
3335
/**
3436
*
3537
*
@@ -156,8 +158,37 @@ public Properties getInfo() {
156158
DocInfo docInfo = (DocInfo) docElement;
157159
info.setProperty( docInfo.getName() , docInfo.getContent().toString() );
158160
}
159-
}
161+
}
160162
return info;
161163
}
162164

165+
private static int getMargin( Properties props, int position ) {
166+
String margins = props.getProperty( GenericConsts.INFO_KEY_MARGINS );
167+
return Integer.parseInt( margins.split( ";")[position] );
168+
}
169+
170+
public int getMarginLeft() {
171+
return getMargin( this.getInfo() , GenericConsts.POSITION_MARGIN_LEFT );
172+
}
173+
174+
public int getMarginRight() {
175+
return getMargin( this.getInfo() , GenericConsts.POSITION_MARGIN_RIGHT );
176+
}
177+
178+
public int getMarginTop() {
179+
return getMargin( this.getInfo() , GenericConsts.POSITION_MARGIN_TOP );
180+
}
181+
182+
public int getMarginBottom() {
183+
return getMargin( this.getInfo() , GenericConsts.POSITION_MARGIN_BOTTOM );
184+
}
185+
186+
public boolean isUseHeader() {
187+
return this.getDocHeader() != null && this.getDocHeader().isUseHeader();
188+
}
189+
190+
public boolean isUseFooter() {
191+
return this.getDocFooter() != null && this.getDocFooter().isUseFooter();
192+
}
193+
163194
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/model/DocCell.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,12 @@ public void setForeColor(String foreColor) {
166166
this.foreColor = foreColor;
167167
}
168168

169+
public int getColumnSpan() {
170+
int res = this.getCSpan();
171+
if ( this.getCSpan() < 1 ) {
172+
res = 1;
173+
}
174+
return res;
175+
}
176+
169177
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/model/DocHeaderFooter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ public boolean isNumbered() {
8888
public void setNumbered(boolean numbered) {
8989
this.numbered = numbered;
9090
}
91+
92+
private int expectedSize;
93+
94+
public int getExpectedSize() {
95+
return expectedSize;
96+
}
9197

98+
public void setExpectedSize(int expectedSize) {
99+
this.expectedSize = expectedSize;
100+
}
92101

93102
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.fugerit.java.doc.base.typehelper.generic;
2+
3+
public class GenericConsts {
4+
5+
public static final String INFO_KEY_MARGINS = "margins";
6+
public static final int POSITION_MARGIN_LEFT = 0;
7+
public static final int POSITION_MARGIN_RIGHT = 1;
8+
public static final int POSITION_MARGIN_TOP = 2;
9+
public static final int POSITION_MARGIN_BOTTOM = 3;
10+
11+
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/xml/DocContentHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ private static void handleHeaderFooter( DocHeaderFooter headerFooter, Properties
214214
headerFooter.setNumbered( Boolean.valueOf( numbered ).booleanValue() );
215215
String borderWidth = atts.getProperty( "border-width", "0" );
216216
headerFooter.setBorderWidth( Integer.valueOf( borderWidth ).intValue() );
217+
String exepectedSize = atts.getProperty( "expected-size", "15" );
218+
headerFooter.setExpectedSize( Integer.parseInt( exepectedSize ) );
217219
}
218220

219221
private DocBorders createBorders( Properties atts ) {

fj-doc-base/src/main/resources/config/doc-1-0.xsd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<xsd:attribute name='align' type='doc:alignType' use='optional' />
6565
<xsd:attribute name='numbered' type='xsd:boolean' use='optional' />
6666
<xsd:attribute name='border-width' type='xsd:string' use='optional' />
67+
<xsd:attribute name='expected-size' type="xsd:int" use='optional' />
6768
</xsd:complexType>
6869
</xsd:element>
6970

@@ -79,6 +80,7 @@
7980
<xsd:attribute name='align' type='doc:alignType' use='optional' />
8081
<xsd:attribute name='numbered' type='xsd:boolean' use='optional' />
8182
<xsd:attribute name='border-width' type='xsd:string' use='optional' />
83+
<xsd:attribute name='expected-size' type="xsd:int" use='optional' />
8284
</xsd:complexType>
8385
</xsd:element>
8486

@@ -212,7 +214,7 @@
212214

213215
<xsd:element name='cell'>
214216
<xsd:complexType>
215-
<xsd:sequence minOccurs='0' maxOccurs='unbounded'>
217+
<xsd:sequence minOccurs='1' maxOccurs='unbounded'>
216218
<xsd:choice>
217219
<xsd:element ref='doc:para' />
218220
<xsd:element ref='doc:table' />

fj-doc-mod-fop/src/main/resources/fm_fop/template/fop_doc.xml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,45 @@
33
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
44
<fo:layout-master-set>
55
<fo:simple-page-master
6-
margin-right="5mm" margin-left="5mm" margin-bottom="5mm" margin-top="5mm"
7-
page-width="21cm" page-height="29.7cm" master-name="simpleA4">
8-
<fo:region-body />
6+
page-width="21cm" page-height="29.7cm"
7+
master-name="simpleA4"
8+
margin-left="${docBase.marginLeft}pt"
9+
margin-right="${docBase.marginRight}pt"
10+
margin-top="${docBase.marginTop}pt"
11+
margin-bottom="${docBase.marginBottom}pt">
12+
<#assign bodyMarginTop="">
13+
<#assign bodyMarginBottom="">
14+
<#if (docBase.useHeader)>
15+
<#assign headerSize="${docBase.docHeader.expectedSize}mm">
16+
<#assign bodyMarginTop=" margin-top='${headerSize}' ">
17+
</#if>
18+
<#if (docBase.useFooter)>
19+
<#assign footerSize="${docBase.docFooter.expectedSize}mm">
20+
<#assign bodyMarginBottom=" margin-bottom='${footerSize}' ">
21+
</#if>
22+
<fo:region-body region-name="xsl-region-body" ${bodyMarginTop} ${bodyMarginBottom}/>
23+
<#if (docBase.useHeader)>
24+
<fo:region-before region-name="xsl-region-before" extent="${headerSize}"/>
25+
</#if>
26+
<#if (docBase.useFooter)>
27+
<fo:region-after region-name="xsl-region-after" extent="${footerSize}"/>
28+
</#if>
929
</fo:simple-page-master>
1030
</fo:layout-master-set>
11-
<fo:page-sequence master-reference="simpleA4">
31+
<fo:page-sequence master-reference="simpleA4" initial-page-number="1">
32+
<#if (docBase.useHeader)>
33+
<fo:static-content flow-name="xsl-region-before">
34+
<@doc_element.handleElementList elements=docBase.docHeader.elementList/>
35+
</fo:static-content>
36+
</#if>
37+
<#if (docBase.useFooter)>
38+
<fo:static-content flow-name="xsl-region-after">
39+
<@doc_element.handleElementList elements=docBase.docFooter.elementList/>
40+
</fo:static-content>
41+
</#if>
1242
<fo:flow flow-name="xsl-region-body" >
1343
<fo:block>
14-
<#list docBase.docBody.elementList as item>
15-
<@doc_element.handleElement current=item/>
16-
</#list>
44+
<@doc_element.handleElementList elements=docBase.docBody.elementList/>
1745
</fo:block>
1846
</fo:flow>
1947
</fo:page-sequence>

fj-doc-mod-fop/src/main/resources/fm_fop/template/macro/doc_element.xml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
<#global defaultBorderColor='black'>
22
<#global defaultFontSize='10'>
33

4+
<#macro handleElementList elements>
5+
<#list elements as item>
6+
<@doc_element.handleElement current=item/>
7+
</#list>
8+
</#macro>
9+
410
<#macro handleElement current>
511
<#assign elementType="${current.class.simpleName}"/>
612
<#if elementType = 'DocPhrase'>
713
<fo:inline <@handleStyle styleValue=current.style/> font-size="${defaultFontSize}pt">${current.text}</fo:inline>
814
<#elseif elementType = 'DocPara'>
9-
<fo:block <@handleStyle styleValue=current.style/> font-size="${defaultFontSize}pt">${current.text}</fo:block>
15+
<fo:block <@handleStyle styleValue=current.style/> font-size="${defaultFontSize}pt">${current.text?replace(r"${currentPage}","<fo:page-number/>")}</fo:block>
1016
<#elseif elementType = 'DocTable'>
1117
<@handleTable docTable=current/>
1218
<#elseif elementType = 'DocImage'>
13-
<@handleImage docImage=current/>
19+
<@handleImage docImage=current/>
1420
<#else>
1521
<fo:block space-after="5mm" font-weight="bold" font-size="${defaultFontSize}pt">Element type non implemented yet : ${elementType}</fo:block>
1622
</#if>
@@ -22,12 +28,13 @@
2228
<#else>
2329
<#assign imageScaling=""/>
2430
</#if>
25-
<fo:external-graphic xmlns:fo="http://www.w3.org/1999/XSL/Format"
26-
src="data:image;base64,${docImage.resolvedBase64}" ${imageScaling}/>
31+
<fo:block>
32+
<fo:external-graphic ${imageScaling} xmlns:fo="http://www.w3.org/1999/XSL/Format"
33+
src="data:image;base64,${docImage.resolvedBase64}"/>
34+
</fo:block>
2735
</#macro>
2836

2937
<#macro handleTable docTable>
30-
<fo:block font-size="10pt">
3138
<fo:table border-collapse="separate" width="${docTable.width}%" table-layout="fixed">
3239
<#list docTable.colWithds as currentColWidth>
3340
<fo:table-column column-width="${currentColWidth}%" />
@@ -36,17 +43,20 @@
3643
<#list docTable.elementList as row>
3744
<fo:table-row>
3845
<#list row.elementList as cell>
39-
<fo:table-cell padding="${docTable.padding}mm" <@handleAlign alignValue=cell.align/> <@handleBorders docBorders=cell.docBorders/>>
40-
<#list cell.elementList as cellElement>
41-
<@handleElement current=cellElement/>
42-
</#list>
46+
<fo:table-cell padding="${docTable.padding}mm" <@handleAlign alignValue=cell.align/> <@handleBorders docBorders=cell.docBorders/> number-columns-spanned="${cell.columnSpan}">
47+
<#if (cell.elementList?size > 0)>
48+
<#list cell.elementList as cellElement>
49+
<@handleElement current=cellElement/>
50+
</#list>
51+
<#else>
52+
<fo:block></fo:block>
53+
</#if>
4354
</fo:table-cell>
4455
</#list>
4556
</fo:table-row>
4657
</#list>
4758
</fo:table-body>
4859
</fo:table>
49-
</fo:block>
5060
</#macro>
5161

5262
<#macro handleBorder mode size color><#if size != 0><#if size = -1><#assign calcSize="1"/><#else><#assign calcSize="${size}"/></#if>${mode}='${calcSize}pt solid ${color}' </#if></#macro>

0 commit comments

Comments
 (0)