Skip to content

Commit 8f6fde2

Browse files
committed
feat: set svg image in element content #580
1 parent 11e968a commit 8f6fde2

File tree

21 files changed

+95
-27
lines changed

21 files changed

+95
-27
lines changed

fj-doc-base-kotlin/src/main/java/org/fugerit/java/doc/base/kotlin/dsl/Background.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class Background : HelperDSL.TagWithText( "background" ) {
1010
* Creates a new default Image instance.
1111
* @return the new instance.
1212
*/
13-
fun image( init: Image.() -> Unit = {} ): Image {
14-
return initTag(Image(), init);
13+
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
14+
return initTag(Image(text), init);
1515
}
1616

1717

fj-doc-base-kotlin/src/main/java/org/fugerit/java/doc/base/kotlin/dsl/Body.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Body : HelperDSL.TagWithText( "body" ) {
3131
* Creates a new default Image instance.
3232
* @return the new instance.
3333
*/
34-
fun image( init: Image.() -> Unit = {} ): Image {
35-
return initTag(Image(), init);
34+
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
35+
return initTag(Image(text), init);
3636
}
3737
/**
3838
* Creates a new default Phrase instance.

fj-doc-base-kotlin/src/main/java/org/fugerit/java/doc/base/kotlin/dsl/Cell.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class Cell : HelperDSL.TagWithText( "cell" ) {
2424
* Creates a new default Image instance.
2525
* @return the new instance.
2626
*/
27-
fun image( init: Image.() -> Unit = {} ): Image {
28-
return initTag(Image(), init);
27+
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
28+
return initTag(Image(text), init);
2929
}
3030
/**
3131
* Creates a new default Phrase instance.

fj-doc-base-kotlin/src/main/java/org/fugerit/java/doc/base/kotlin/dsl/Footer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Footer : HelperDSL.TagWithText( "footer" ) {
1717
* Creates a new default Image instance.
1818
* @return the new instance.
1919
*/
20-
fun image( init: Image.() -> Unit = {} ): Image {
21-
return initTag(Image(), init);
20+
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
21+
return initTag(Image(text), init);
2222
}
2323
/**
2424
* Creates a new default Phrase instance.

fj-doc-base-kotlin/src/main/java/org/fugerit/java/doc/base/kotlin/dsl/FooterExt.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class FooterExt : HelperDSL.TagWithText( "footer-ext" ) {
2424
* Creates a new default Image instance.
2525
* @return the new instance.
2626
*/
27-
fun image( init: Image.() -> Unit = {} ): Image {
28-
return initTag(Image(), init);
27+
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
28+
return initTag(Image(text), init);
2929
}
3030
/**
3131
* Creates a new default Phrase instance.

fj-doc-base-kotlin/src/main/java/org/fugerit/java/doc/base/kotlin/dsl/Header.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Header : HelperDSL.TagWithText( "header" ) {
1717
* Creates a new default Image instance.
1818
* @return the new instance.
1919
*/
20-
fun image( init: Image.() -> Unit = {} ): Image {
21-
return initTag(Image(), init);
20+
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
21+
return initTag(Image(text), init);
2222
}
2323
/**
2424
* Creates a new default Phrase instance.

fj-doc-base-kotlin/src/main/java/org/fugerit/java/doc/base/kotlin/dsl/HeaderExt.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class HeaderExt : HelperDSL.TagWithText( "header-ext" ) {
2424
* Creates a new default Image instance.
2525
* @return the new instance.
2626
*/
27-
fun image( init: Image.() -> Unit = {} ): Image {
28-
return initTag(Image(), init);
27+
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
28+
return initTag(Image(text), init);
2929
}
3030
/**
3131
* Creates a new default Phrase instance.

fj-doc-base-kotlin/src/main/java/org/fugerit/java/doc/base/kotlin/dsl/Image.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ package org.fugerit.java.doc.base.kotlin.dsl
55
*
66
* This class will provide function to handle all image attributes and kids
77
*/
8-
class Image : HelperDSL.TagWithText( "image" ) {
8+
class Image( text: String = "" ) : HelperDSL.TagWithText( "image" ) {
9+
10+
init { setText(text) }
11+
/**
12+
* Function to set text content for this element.
13+
*/
14+
15+
fun setText( value: String ) { addKid( HelperDSL.TextElement( value ) ) }
16+
917

1018
/**
1119
* Function handling url attribute of the Image with specific check on type.

fj-doc-base/src/main/docs/doc_xsd_config_ref.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ <h1 style="font-weight: bold;">Reference xsd documentation for Venus - Fugerit
410410
<span >An image to include in the document (roughly comparable to a HTML 'image' element)</span>
411411
</td>
412412
<td id="cell_19_2" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
413+
<span >mixed </span>
413414
</td>
414415
</tr>
415416
<tr>

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The Apache Software Foundation (http://www.apache.org/).
3131
import java.net.URI;
3232
import java.net.URISyntaxException;
3333
import java.net.URL;
34+
import java.nio.charset.StandardCharsets;
3435
import java.util.Arrays;
3536
import java.util.Collection;
3637

@@ -82,7 +83,9 @@ public static Collection<String> getAcceptedImageTypes() {
8283
@Getter @Setter private String alt;
8384

8485
@Getter @Setter private int align;
85-
86+
87+
@Getter @Setter private String content = "";
88+
8689
public String getResolvedBase64() {
8790
return SafeFunction.get( () -> {
8891
String res = this.getBase64();
@@ -94,7 +97,13 @@ public String getResolvedBase64() {
9497
}
9598

9699
public String getResolvedText() {
97-
return SafeFunction.get( () -> new String( resolveImage( this ) ) );
100+
return SafeFunction.get( () -> {
101+
if ( StringUtils.isEmpty( this.content ) ) {
102+
return new String( resolveImage( this ) );
103+
} else {
104+
return this.content;
105+
}
106+
});
98107
}
99108

100109
public String getResolvedType() {
@@ -134,6 +143,8 @@ public static byte[] resolveImage( DocImage img ) throws IOException {
134143
data = Base64Helper.decodeBase64String( base64 );
135144
} else if ( path != null ) {
136145
data = byteResolverHelper( path );
146+
} else if ( StringUtils.isNotEmpty( img.getContent() ) ) {
147+
data = img.getContent().getBytes( StandardCharsets.UTF_8 );
137148
} else {
138149
throw new IOException( "Null path provided!" );
139150
}

0 commit comments

Comments
 (0)