Fix: improved verbosity on image conversion errors
This commit is contained in:
parent
8e81b3511c
commit
80b7005066
2 changed files with 23 additions and 1 deletions
|
@ -244,6 +244,13 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
int topOffset = offsets[0];
|
||||
int croppedWidth = width - offsets[3] - offsets[1];
|
||||
int croppedHeight = height - offsets[0] - offsets[2];
|
||||
if ( croppedHeight <= 0) {
|
||||
throw new IOException("Cropped image height < 0");
|
||||
}
|
||||
if ( croppedWidth <= 0 ) {
|
||||
throw new IOException("Cropped image width < 0");
|
||||
}
|
||||
|
||||
BufferedImage croppedImage = new BufferedImage(croppedWidth, croppedHeight, BufferedImage.TYPE_3BYTE_BGR);
|
||||
int px[] = new int[croppedWidth * croppedHeight];
|
||||
image.getRGB(leftOffset, topOffset, croppedWidth, croppedHeight, px, 0, croppedWidth);
|
||||
|
@ -290,8 +297,9 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
if (width > 0) {
|
||||
Integer newWidth = (int) ( width/divider);
|
||||
BufferedImage resizedImage = Scalr.resize(image, newWidth);
|
||||
BufferedImage jpgImage = getJPGImage(resizedImage);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(resizedImage, "JPG", baos);
|
||||
ImageIO.write(jpgImage, "JPG", baos);
|
||||
this.blob = baos.toByteArray();
|
||||
extractPPI();
|
||||
} else {
|
||||
|
@ -303,6 +311,17 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
}
|
||||
}
|
||||
|
||||
private BufferedImage getJPGImage(BufferedImage resizedImage) {
|
||||
if (resizedImage.getType() == BufferedImage.TYPE_3BYTE_BGR){
|
||||
return resizedImage;
|
||||
}
|
||||
BufferedImage jpgImage = new BufferedImage(resizedImage.getWidth(), resizedImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
|
||||
int px[] = new int[resizedImage.getWidth() * resizedImage.getHeight()];
|
||||
resizedImage.getRGB(0, 0, resizedImage.getWidth(), resizedImage.getHeight(), px, 0, resizedImage.getWidth());
|
||||
jpgImage.setRGB(0, 0, resizedImage.getWidth(), resizedImage.getHeight(), px, 0, resizedImage.getWidth());
|
||||
return jpgImage;
|
||||
}
|
||||
|
||||
private boolean isNotCropped(int[] offsets) {
|
||||
return offsets[0] == 0 && offsets[1] == 0 && offsets[2] == 0 && offsets[3] == 0;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ import w2phtml.office.OfficeStyle;
|
|||
import w2phtml.office.PageLayout;
|
||||
import w2phtml.office.StyleWithProperties;
|
||||
import w2phtml.office.XMLString;
|
||||
import w2phtml.pageSplitters.ListBreaksFix;
|
||||
import w2phtml.pageSplitters.SplitFactory;
|
||||
import w2phtml.util.Misc;
|
||||
import w2phtml.xhtml.Converter;
|
||||
|
@ -174,6 +175,8 @@ public class TextParser extends Parser {
|
|||
//ODFPageSplitter.splitOfficeText(onode, ofr);
|
||||
//Debug.prettyPrintXml(onode.getOwnerDocument());
|
||||
SplitFactory splitters = new SplitFactory(ofr);
|
||||
ListBreaksFix listBreaksFix = new ListBreaksFix(ofr);
|
||||
listBreaksFix.addSPBsBeforeBreaksInLists(onode);
|
||||
splitters.split(onode);
|
||||
//Debug.prettyPrintXml(onode.getOwnerDocument());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue