Skip to content
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

Fix PDFAsImage scaling and uses of FSImage.scale for immutability changes #442

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
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private ImageMarker makeImageMarker(
return null;
}
if (img.getHeight() > structMetrics.getAscent()) {
img.scale(-1, (int) structMetrics.getAscent());
img = img.scale(-1, (int) structMetrics.getAscent());
}
return new ImageMarker(img, img.getWidth() * 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ public ImageResource get(final String uri) {
public synchronized ImageResource get(final String uri, final int width, final int height) {
if (isEmbeddedBase64Image(uri)) {
ImageResource resource = loadEmbeddedBase64ImageResource(uri);
resource.getImage().scale(width, height);
return resource;
FSImage scaledImage = resource.getImage();
if (scaledImage != null) {
scaledImage = scaledImage.scale(width, height);
}
return new ImageResource(resource.getImageUri(), scaledImage);
} else {
CacheKey key = new CacheKey(uri, width, height);
ImageResource ir = _imageCache.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ReplacedElement createReplacedElement(LayoutContext c, BlockBox box,
FSImage fsImage = uac.getImageResource(srcAttr).getImage();
if (fsImage != null) {
if (cssWidth != -1 || cssHeight != -1) {
fsImage.scale(cssWidth, cssHeight);
fsImage = fsImage.scale(cssWidth, cssHeight);
}
return new ITextImageElement(fsImage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public PDFAsImage(URI source, float width, float height) {
_unscaledHeight = height;
}

private PDFAsImage(URI source, float unscaledWidth, float unscaledHeight, float width, float height) {
_source = source;
_width = width;
_unscaledWidth = unscaledWidth;
_height = height;
_unscaledHeight = unscaledHeight;
}

@Override
public int getWidth() {
return (int)_width;
Expand All @@ -62,7 +70,7 @@ public FSImage scale(int width, int height) {
targetHeight = getHeightAsFloat() * (targetWidth / getWidth());
}

return new PDFAsImage(_source, targetWidth, targetHeight);
return new PDFAsImage(_source, _width, _height, targetWidth, targetHeight);
}

public URI getURI() {
Expand Down