Skip to content

Commit ad6b1d5

Browse files
author
Artyom Yanchevsky
committed
Add support to utf-8 image format in svg
DEVSIX-3847
1 parent f7c3c11 commit ad6b1d5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

styled-xml-parser/src/main/java/com/itextpdf/styledxmlparser/resolver/resource/ResourceResolver.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,17 @@ This file is part of the iText (R) project.
6565
*/
6666
// TODO handle <base href=".."> tag?
6767
public class ResourceResolver {
68+
6869
/**
6970
* Identifier string used when loading in base64 images.
7071
*/
72+
public static final String BASE64_IDENTIFIER = "base64";
73+
74+
/**
75+
* Identifier string used when loading in base64 images.
76+
* @deprecated This variable will be replaced by {@link #BASE64_IDENTIFIER} in 7.2 release
77+
*/
78+
@Deprecated
7179
public static final String BASE64IDENTIFIER = "base64";
7280

7381
/**
@@ -330,13 +338,12 @@ public boolean isImageTypeSupportedByImageDataFactory(String src) {
330338
protected PdfXObject tryResolveBase64ImageSource(String src) {
331339
try {
332340
String fixedSrc = src.replaceAll("\\s", "");
333-
fixedSrc = fixedSrc.substring(fixedSrc.indexOf(BASE64IDENTIFIER) + 7);
341+
fixedSrc = fixedSrc.substring(fixedSrc.indexOf(BASE64_IDENTIFIER) + BASE64_IDENTIFIER.length() + 1);
334342
PdfXObject imageXObject = imageCache.getImage(fixedSrc);
335343
if (imageXObject == null) {
336344
imageXObject = new PdfImageXObject(ImageDataFactory.create(Base64.decode(fixedSrc)));
337345
imageCache.putImage(fixedSrc, imageXObject);
338346
}
339-
340347
return imageXObject;
341348
} catch (Exception ignored) {
342349
}
@@ -377,7 +384,7 @@ private byte[] retrieveBytesFromBase64Src(String src) {
377384
if (isContains64Mark(src)) {
378385
try {
379386
String fixedSrc = src.replaceAll("\\s", "");
380-
fixedSrc = fixedSrc.substring(fixedSrc.indexOf(BASE64IDENTIFIER) + 7);
387+
fixedSrc = fixedSrc.substring(fixedSrc.indexOf(BASE64_IDENTIFIER) + BASE64_IDENTIFIER.length() + 1);
381388
return Base64.decode(fixedSrc);
382389
} catch (Exception ignored) {
383390
}
@@ -393,6 +400,6 @@ private byte[] retrieveBytesFromBase64Src(String src) {
393400
* @return true if string contains base64 mark
394401
*/
395402
private boolean isContains64Mark(String src) {
396-
return src.contains(BASE64IDENTIFIER);
403+
return src.contains(BASE64_IDENTIFIER);
397404
}
398405
}

0 commit comments

Comments
 (0)