icepdf解析pdf文件空白bug修改
http://jira.icesoft.org/browse/PDF-436
问题修改如下:
Modify TilingPattern.java
1. public void init() {
if (inited) {
return;
}
//Modify bug by
[email protected], see bug PDF-436
inited = true;
//Modify bug by
[email protected] end.
...
}
2. public void paintPattern(Graphics2D g, Page parentPage) {
if (patternPaint == null) {
AffineTransform matrixInv = getInvMatrix();
Rectangle2D bBoxMod = matrix.createTransformedShape(bBox).getBounds2D();
int width = (int) bBoxMod.getWidth();
int height = (int) bBoxMod.getHeight();
// corner cases where some bBoxes don't have a dimension.
if (width == 0) {
width = 1;
}
if (height == 0) {
height = 1;
}
// create the new image to write too.
final BufferedImage bi = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
Graphics2D canvas = bi.createGraphics();
// apply current hints
canvas.setRenderingHints(g.getRenderingHints());
// copy over the rendering hints
// get shapes and paint them.
Shapes tilingShapes = getShapes();
//Modify bug by
[email protected], see bug PDF-436
// finally paint the graphic using the current gs.
patternPaint = new TexturePaint(bi, bBoxMod);
g.setPaint(patternPaint);
//Modify by
[email protected] end.
if (tilingShapes != null) {
// setup resource parent
tilingShapes.setPageParent(parentPage);
canvas.setClip(0, 0, width, height);
// apply the pattern space
canvas.setTransform(matrix);
// move it back by any shear/rotation distance.
canvas.translate(matrixInv.getTranslateX(),
matrixInv.getTranslateY());
if (paintType == TilingPattern.PAINTING_TYPE_UNCOLORED_TILING_PATTERN) {
canvas.setColor(unColored);
}
// paint the pattern content stream.
tilingShapes.paint(canvas);
// do a little tiling if there is a shear so that we
// don't end up with any white space around the rotate
// pattern cell. Java texture paint can't take a transform
// when painting so this will have to do.
if (matrix.getShearX() > 0 ||
matrix.getShearY() > 0) {
canvas.translate(bBox.getWidth(), 0);
tilingShapes.paint(canvas);
canvas.translate(0, -bBox.getHeight());
tilingShapes.paint(canvas);
canvas.translate(-bBox.getWidth(), 0);
tilingShapes.paint(canvas);
canvas.translate(-bBox.getWidth(), 0);
tilingShapes.paint(canvas);
canvas.translate(0, bBox.getHeight());
tilingShapes.paint(canvas);
canvas.translate(0, bBox.getHeight());
tilingShapes.paint(canvas);
canvas.translate(bBox.getWidth(), 0);
tilingShapes.paint(canvas);
canvas.translate(bBox.getWidth(), 0);
tilingShapes.paint(canvas);
}
// release the page parent
tilingShapes.setPageParent(null);
}
// show it in a frame
// final JFrame f = new JFrame("Test");
// f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
// f.getContentPane().add(new JComponent() {
// @Override
// public void paint(Graphics g_) {
// super.paint(g_);
// g_.drawImage(bi, 0, 0, f);
// }
// });
// f.setSize(new Dimension(800, 800));
// f.setVisible(true);
// post paint cleanup
canvas.dispose();
bi.flush();
} else {
g.setPaint(patternPaint);
}
}