Skip to content

[fj-doc-freemarker] handling of svg in html handler #348 #349

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
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- [fj-doc-freemarker] handling of svg in html handler <https://github.com/fugerit-org/fj-doc/issues/348>

## [8.12.5] - 2025-03-24

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ The Apache Software Foundation (http://www.apache.org/).
package org.fugerit.java.doc.base.model;

import java.util.Arrays;
import java.util.Base64;
import java.util.Collection;

import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.doc.base.helper.Base64Helper;
import org.fugerit.java.doc.base.helper.SourceResolverHelper;

import lombok.Getter;
Expand Down Expand Up @@ -83,6 +85,10 @@ public String getResolvedBase64() {
return res;
} );
}

public String getResolvedText() {
return SafeFunction.get( () -> new String( SourceResolverHelper.resolveImage( this ) ) );
}

public String getResolvedType() {
return StringUtils.valueWithDefault( this.getType() , this.getUrl() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,9 @@
}, {
"name" : "getResolvedBase64",
"parameterTypes" : [ ]
}, {
"name" : "getResolvedText",
"parameterTypes" : [ ]
}, {
"name" : "getResolvedType",
"parameterTypes" : [ ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void testElement1() {
Assertions.assertFalse( image.isSvg() );
image.setType( DocImage.TYPE_SVG );
Assertions.assertTrue( image.isSvg() );
image.setUrl( "cl://txt/test.txt" );
Assertions.assertEquals( "test text", image.getResolvedText() );
log.info( "accepted types : {}", DocImage.getAcceptedImageTypes() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@
</#macro>

<#macro handleImage docImage>
<#if (docImage.scaling)??>
<#assign imageScaling="height='${docImage.scaling}%' width='${docImage.scaling}%'"/>
<#if docImage.svg>
${docImage.resolvedText}
<#else>
<#assign imageScaling=""/>
</#if>
<#if (docImage.align)??>
<#if docImage.align = 2>
<#assign imageAlign="style='display: block; margin-left: auto; margin-right: auto;'"/>
<#if (docImage.scaling)??>
<#assign imageScaling="height='${docImage.scaling}%' width='${docImage.scaling}%'"/>
<#else>
<#assign imageScaling=""/>
</#if>
<#if (docImage.align)??>
<#if docImage.align = 2>
<#assign imageAlign="style='display: block; margin-left: auto; margin-right: auto;'"/>
</#if>
</#if>
</#if>
<img <@handleId element=docImage/> ${imageAlign!''} <#if (docImage.alt)??> alt="${docImage.alt}" </#if> ${imageScaling} src="data:image/png;base64, ${docImage.resolvedBase64}" />
<img <@handleId element=docImage/> ${imageAlign!''} <#if (docImage.alt)??> alt="${docImage.alt}" </#if> ${imageScaling} src="data:image/png;base64, ${docImage.resolvedBase64}" />
</#if>
</#macro>

<#macro handleList docList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ void testAsciidoc() {
Assertions.assertTrue( outputFile.exists() );
}

@Test
void testSample() {
String docId = "default_doc_sample";
DocTypeHandler handler = FreeMarkerHtmlTypeHandler.HANDLER_UTF8;
String type = DocConfig.TYPE_HTML;
File outputFile = new File( "target/sample."+type );
SafeFunction.apply( () -> {
try ( InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "coverage/xml/"+docId+".xml" ) );
FileOutputStream fos = new FileOutputStream( outputFile ) ) {
handler.handle( DocInput.newInput( handler.getType() , reader ) , DocOutput.newOutput( fos ) );
}
} );
Assertions.assertTrue( outputFile.exists() );
}

}

@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<doc
xmlns="http://javacoredoc.fugerit.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >

<metadata>
<!-- Margin for document : left;right;top;bottom -->
<info name="margins">10;10;10;30</info>
<info name="excel-table-id">excel-table=print</info>
<!-- documenta meta information -->
<info name="doc-title">Basic example</info>
<info name="doc-subject">fj doc venus sample source xml</info>
<info name="doc-author">fugerit79</info>
<info name="doc-language">en</info>
<!-- additional properties -->
<info name="set-total-page">true</info>
<info name="html-css-link">/css/test.css</info>
<!-- CSV options -->
<info name="csv-table-id">excel-table</info>
<header-ext>
<para align="center" fore-color="#eeeeee">header test</para>
</header-ext>
<footer-ext>
<para align="left">test</para>
<para align="center">${r"${currentPage}"} / ${r"${pageCount}"}</para>
<para align="right">test</para>
</footer-ext>
<bookmark-tree>
<bookmark ref="title">Test</bookmark>
</bookmark-tree>
</metadata>
<body>
<h id="title" head-level="1">main title h1</h>
<para font-name="times-roman" style="bold">Test times roman</para>
<para font-name="courier" style="bolditalic">Courier</para>
<para font-name="symbol" style="italic">Symbol</para>
<para font-name="helvetica" style="underline">Symbol</para>
<para size="3" fore-color="#dddddd">Test default font</para>
<image type="svg" alt="Test logo SVG" url="cl://image/logo.svg"/>
<br/>
<page-break/>
<table space-before="20" columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
<row>
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
<cell align="center"><para style="bold">Surname</para></cell>
<cell align="center"><para style="bold">Title</para></cell>
</row>
<row>
<cell><para><![CDATA[Luthien]]></para></cell>
<cell><para><![CDATA[Tinuviel]]></para></cell>
<cell><para><![CDATA[Queen]]></para></cell>
</row>
<row>
<cell><para><![CDATA[Thorin]]></para></cell>
<cell><para><![CDATA[Oakshield]]></para></cell>
<cell><para><![CDATA[King]]></para></cell>
</row>
<row>
<cell><phrase><![CDATA[Phrase]]></phrase></cell>
<cell><phrase anchor="1"><![CDATA[Oakshield]]></phrase></cell>
<cell><phrase link="1"><![CDATA[King]]></phrase></cell>
</row>
</table>
<list>
<li><para>test 1</para></li>
</list>
<list list-type="ul">
<li><para>test 2</para></li>
</list>
<list list-type="ol">
<li><para>test 3</para></li>
</list>
<list list-type="uld">
<li><para>test 4</para></li>
</list>
<list list-type="ulm">
<li><para>test 5</para></li>
</list>
<list list-type="oll">
<li><para>test 6</para></li>
</list>
<list list-type="oln">
<li><para>test 7</para></li>
</list>
</body>

</doc>
1 change: 1 addition & 0 deletions fj-doc-freemarker/src/test/resources/image/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.