Skip to content

337 enhancement fj doc mod fop add svg support #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- [fj-doc-mod-fop] Support for SVG rendering <https://github.com/fugerit-org/fj-doc/issues/337>
- [fj-doc-freemarker] FreeMarker function 'base64ToString' <https://github.com/fugerit-org/fj-doc/issues/337>
- [fj-doc-base] 'svg' to accepted image types <https://github.com/fugerit-org/fj-doc/issues/337>

### Changed

- [fj-doc-maven-plugin] spring-boot flavour version set to 3.4.4 <https://github.com/fugerit-org/fj-doc/issues/335>
Expand Down
8 changes: 8 additions & 0 deletions fj-doc-base/DocXsdChangelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2.1.0.rc.3 (2025-03-22)
------------------
* Added 'svg' among accepted image types.

2.1.0.rc.2 (2024-10-14)
------------------
* 'h' elemented accepted as child of 'para'.

2.1.0.rc.1 (2023-08-18)
------------------
* Added 'caption' attribute for 'table' element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public class DocImage extends DocElement {
public static final String TYPE_JPG = "jpg";

public static final String TYPE_GIF = "gif";


public static final String TYPE_SVG = "svg";

public static Collection<String> getAcceptedImageTypes() {
return Arrays.asList( TYPE_PNG, TYPE_JPG, TYPE_GIF );
return Arrays.asList( TYPE_PNG, TYPE_JPG, TYPE_GIF, TYPE_SVG );
}

public static final String TAG_NAME = "image";
Expand Down Expand Up @@ -85,5 +87,9 @@ public String getResolvedBase64() {
public String getResolvedType() {
return StringUtils.valueWithDefault( this.getType() , this.getUrl() );
}


public boolean isSvg() {
return TYPE_SVG.equals( this.getResolvedType() );
}

}
3 changes: 2 additions & 1 deletion fj-doc-base/src/main/resources/config/doc-2-1.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @project : fj-doc-base
* @creation : 2023-08-18
* @version : 2.1.0-rc.2 (2024-10-14)
* @version : 2.1.0-rc.3 (2025-03-22)
*
* XSD for fugerit doc configuration
*/
Expand Down Expand Up @@ -543,6 +543,7 @@
<xsd:enumeration value="png"></xsd:enumeration>
<xsd:enumeration value="jpg"></xsd:enumeration>
<xsd:enumeration value="gif"></xsd:enumeration>
<xsd:enumeration value="svg"></xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ void testElement1() {
Assertions.assertEquals( DocImage.TYPE_JPG, image.getResolvedType() );
image.setType( DocImage.TYPE_PNG );
Assertions.assertEquals( DocImage.TYPE_PNG, image.getResolvedType() );
Assertions.assertFalse( image.isSvg() );
image.setType( DocImage.TYPE_SVG );
Assertions.assertTrue( image.isSvg() );
log.info( "accepted types : {}", DocImage.getAcceptedImageTypes() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public int process(DocProcessContext context, DocProcessData data) throws Except
map.put(CleanXmlFun.DEFAULT_NAME, new CleanXmlFun());
map.put(CleanTextFun.DEFAULT_NAME, new CleanTextFun());
map.put(FormatLocalDateTimeFun.DEFAULT_NAME, new FormatLocalDateTimeFun());
map.put(Base64ToStringFun.DEFAULT_NAME, new Base64ToStringFun());
}
return res;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.fugerit.java.doc.freemarker.fun;

import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateScalarModel;

import java.util.Base64;
import java.util.List;

public class Base64ToStringFun implements TemplateMethodModelEx {

public static final String DEFAULT_NAME = "base64ToString";

@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
FMFunHelper.checkParameterNumber( arguments, 1 );
String base64 = ((TemplateScalarModel)arguments.get( 0 )).getAsString();
return new SimpleScalar( new String( Base64.getDecoder().decode( base64 ) ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,42 @@
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"name" : "org.fugerit.java.doc.freemarker.fun.Base64ToStringFun",
"methods" : [ {
"name" : "<init>",
"parameterTypes" : [ ]
}, {
"name" : "equals",
"parameterTypes" : [ "java.lang.Object" ]
}, {
"name" : "exec",
"parameterTypes" : [ "java.util.List" ]
}, {
"name" : "getClass",
"parameterTypes" : [ ]
}, {
"name" : "hashCode",
"parameterTypes" : [ ]
}, {
"name" : "notify",
"parameterTypes" : [ ]
}, {
"name" : "notifyAll",
"parameterTypes" : [ ]
}, {
"name" : "toString",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ "long" ]
}, {
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"name" : "org.fugerit.java.doc.freemarker.fun.CleanTextFun",
"methods" : [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<function name="imageBase64CLFun" value="org.fugerit.java.doc.freemarker.fun.ImageBase64CLFun"/>
<function name="messageFormat" value="org.fugerit.java.doc.freemarker.fun.SimpleMessageFun"/>
<function name="sumLong" value="org.fugerit.java.doc.freemarker.fun.SimpleSumLongFun"/>
<function name="base64ToString" value="org.fugerit.java.doc.freemarker.fun.Base64ToStringFun"/>
</chainStep>
</docChain>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@

<para style="bold">italic ${sumLong(10, 20)}</para>

<para style="bold">italic ${sumLong('VEVTVA==')}</para>

<image url="png" base64="${imageBase64CLFun()}" scaling="25"/>

<para style="bold">italic ${messageFormat()}</para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
wrap-unchecked-exceptions="true"
/>
</chainStep>
<chainStep stepType="function">
<function name="base64ToString" value="org.fugerit.java.doc.freemarker.fun.Base64ToStringFun"/>
</chainStep>
<chainStep stepType="map">
<map name="docBase" value="docBase"/>
<map name="docType" value="docType"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@
</#macro>

<#macro handleImage docImage>
<#if (docImage.scaling)??>
<#assign imageScaling="height='${docImage.scaling}%' content-height='${docImage.scaling}%' content-width='scale-to-fit' scaling='uniform' width='${docImage.scaling}%'"/>
<#else>
<#assign imageScaling=""/>
</#if>
<fo:block <@handleAlign alignValue=docImage.align/>>
<fo:external-graphic <#if (docImage.alt)??> fox:alt-text="${docImage.alt}" </#if> ${imageScaling} xmlns:fo="http://www.w3.org/1999/XSL/Format"
src="data:image;base64,${docImage.resolvedBase64}"/>
<#if docImage.svg>
<fo:instream-foreign-object xmlns:svg="http://www.w3.org/2000/svg">${base64ToString(docImage.resolvedBase64)}</fo:instream-foreign-object>
<#else>
<#if (docImage.scaling)??>
<#assign imageScaling="height='${docImage.scaling}%' content-height='${docImage.scaling}%' content-width='scale-to-fit' scaling='uniform' width='${docImage.scaling}%'"/>
<#else>
<#assign imageScaling=""/>
</#if>
<fo:external-graphic <#if (docImage.alt)??> fox:alt-text="${docImage.alt}" </#if> ${imageScaling} xmlns:fo="http://www.w3.org/1999/XSL/Format" src="data:image;base64,${docImage.resolvedBase64}"/>
</#if>
</fo:block>
</#macro>

Expand Down
3 changes: 3 additions & 0 deletions fj-doc-mod-fop/src/test/resources/sample/doc_alt_01.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
</metadata>
<body>
<h head-level="1">Alternative sample doc</h>
<para><image type="svg" scaling="50" alt="Test SGV"
base64="PHN2ZyBoZWlnaHQ9IjEwMHB4IiB3aWR0aD0iMTAwcHgiIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIAoJIHZpZXdCb3g9IjAgMCA1MTIuMDAxIDUxMi4wMDEiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8Zz4KCTxwYXRoIHN0eWxlPSJmaWxsOiNGRkM4NTU7IiBkPSJNMjU2Ljk1NSwwLjA1bC03MS41Niw0NTguOTQ1TDEyLjA2OSw0ODIuNjNjLTguNjMxLDEuMTc3LTE0LjkyNi03Ljk3MS0xMC43NDMtMTUuNjExTDI1Ni45NTUsMC4wNXoKCQkiLz4KCTxwYXRoIHN0eWxlPSJmaWxsOiNGRkM4NTU7IiBkPSJNMjU2Ljk1NSwwLjA1bDc4LjQ4LDQ1OC45NDVsMTY0LjQzLDIzLjQ5YzguNjM5LDEuMjM1LDE0Ljk5Mi03LjkwNiwxMC44MjUtMTUuNTczTDI1Ni45NTUsMC4wNXoiLz4KPC9nPgo8cG9seWdvbiBzdHlsZT0iZmlsbDojRkFBRjUwOyIgcG9pbnRzPSIyNTYuOTU1LDAuMDUgMjU2Ljk1NSw1MTEuOTUxIDMzNS40MzQsNDU4Ljk5NiAiLz4KPHBvbHlnb24gc3R5bGU9ImZpbGw6I0ZGRTE4MjsiIHBvaW50cz0iMjU2Ljk1NSwwLjA1IDE4NS4zOTQsNDU4Ljk5NiAyNTYuOTU1LDUxMS45NTEgIi8+Cjwvc3ZnPg=="/>
</para>
<table space-before="30" columns="3" colwidths="30;30;40" id="excel-table" padding="2" width="100">
<row>
<cell align="center" back-color="#99aaee">
Expand Down
Loading