Skip to content

Commit

Permalink
Merge branch 'asafza-develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Sep 16, 2023
2 parents f816a14 + d6f9752 commit 36e6ca3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,20 @@ public ImageResource getImageResource(String uri) {
BufferedImage image = ImageUtil.loadEmbeddedBase64Image(uri);
ir = createImageResource(null, image);
} else {
uri = resolveURI(uri);
ir = (ImageResource) _imageCache.get(uri);
String unresolvedUri = uri;
ir = (ImageResource) _imageCache.get(unresolvedUri);
//TODO: check that cached image is still valid
if (ir == null) {
InputStream is = resolveAndOpenStream(uri);
uri = resolveURI(uri);
InputStream is = resolveAndOpenStream(uri);
if (is != null) {
try {
BufferedImage img = ImageIO.read(is);
if (img == null) {
throw new IOException("ImageIO.read() returned null");
}
ir = createImageResource(uri, img);
_imageCache.put(uri, ir);
_imageCache.put(unresolvedUri, ir);
} catch (FileNotFoundException e) {
XRLog.exception("Can't read image file; image at URI '" + uri + "' not found");
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class Configuration {
/**
* The Singleton instance of the class.
*/
private static Configuration sInstance;
private static Configuration sInstance = new Configuration();

/**
* List of LogRecords for messages from Configuration startup; used to hold these
Expand Down Expand Up @@ -762,10 +762,7 @@ public static boolean isFalse(String key, boolean defaultVal) {
/**
* @return The singleton instance of the class.
*/
private static synchronized Configuration instance() {
if (Configuration.sInstance == null) {
Configuration.sInstance = new Configuration();
}
private static Configuration instance() {
return Configuration.sInstance;
}// end main()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfReader;

import org.xhtmlrenderer.util.ImageUtil;

public class ITextUserAgent extends NaiveUserAgent {
private static final int IMAGE_CACHE_CAPACITY = 32;

Expand All @@ -62,16 +64,17 @@ private byte[] readStream(InputStream is) throws IOException {
}

public ImageResource getImageResource(String uriStr) {
String unresolvedUri = uriStr;
ImageResource resource;
if (!ImageUtil.isEmbeddedBase64Image(uriStr)) {
uriStr = resolveURI(uriStr);
}
resource = (ImageResource) _imageCache.get(uriStr);
resource = (ImageResource) _imageCache.get(unresolvedUri);

if (resource == null) {
if (ImageUtil.isEmbeddedBase64Image(uriStr)) {
resource = loadEmbeddedBase64ImageResource(uriStr);
_imageCache.put(uriStr, resource);
_imageCache.put(unresolvedUri, resource);
} else {
InputStream is = resolveAndOpenStream(uriStr);
if (is != null) {
Expand All @@ -91,7 +94,7 @@ public ImageResource getImageResource(String uriStr) {
scaleToOutputResolution(image);
resource = new ImageResource(uriStr, new ITextFSImage(image));
}
_imageCache.put(uriStr, resource);
_imageCache.put(unresolvedUri, resource);
} catch (Exception e) {
XRLog.exception("Can't read image file; unexpected problem for URI '" + uriStr + "'", e);
} finally {
Expand Down

0 comments on commit 36e6ca3

Please sign in to comment.