Browse Source

Bugzilla#51760: PS images stored as an embedded file which has no length limit.


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1175764 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_1rc1old
Peter Hancock 12 years ago
parent
commit
677accf2e9
2 changed files with 74 additions and 24 deletions
  1. 69
    24
      src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
  2. 5
    0
      status.xml

+ 69
- 24
src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java View File

@@ -26,6 +26,7 @@ import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;

import org.apache.fop.render.RenderingContext;
import org.apache.xmlgraphics.image.loader.Image;
import org.apache.xmlgraphics.image.loader.ImageFlavor;
import org.apache.xmlgraphics.image.loader.ImageInfo;
@@ -36,8 +37,6 @@ import org.apache.xmlgraphics.ps.FormGenerator;
import org.apache.xmlgraphics.ps.PSGenerator;
import org.apache.xmlgraphics.ps.PSProcSets;

import org.apache.fop.render.RenderingContext;

/**
* Image handler implementation which handles vector graphics (Java2D) for PostScript output.
*/
@@ -97,34 +96,14 @@ public class PSImageHandlerGraphics2D implements PSImageHandler {
}

/** {@inheritDoc} */
public void generateForm(RenderingContext context, Image image, PSImageFormResource form)
public void generateForm(RenderingContext context, Image image, final PSImageFormResource form)
throws IOException {
PSRenderingContext psContext = (PSRenderingContext)context;
PSGenerator gen = psContext.getGenerator();
final ImageGraphics2D imageG2D = (ImageGraphics2D)image;
ImageInfo info = image.getInfo();
String imageDescription = info.getMimeType() + " " + info.getOriginalURI();
final Dimension2D dimensionsPt = info.getSize().getDimensionPt();
final Dimension2D dimensionsMpt = info.getSize().getDimensionMpt();

FormGenerator formGen = new FormGenerator(
form.getName(), imageDescription, dimensionsPt) {

protected void generatePaintProc(PSGenerator gen)
throws IOException {
gen.getResourceTracker().notifyResourceUsageOnPage(
PSProcSets.EPS_PROCSET);
gen.writeln("BeginEPSF");
PSGraphics2DAdapter adapter = new PSGraphics2DAdapter(gen, false);
adapter.paintImage(imageG2D.getGraphics2DImagePainter(),
null,
0, 0,
(int)Math.round(dimensionsMpt.getWidth()),
(int)Math.round(dimensionsMpt.getHeight()));
gen.writeln("EndEPSF");
}

};
FormGenerator formGen = buildFormGenerator(gen.getPSLevel(), form, info, imageG2D);
formGen.generate(gen);
}
/** {@inheritDoc} */
@@ -150,4 +129,70 @@ public class PSImageHandlerGraphics2D implements PSImageHandler {
return false;
}

private FormGenerator buildFormGenerator(int psLanguageLevel, final PSImageFormResource form,
final ImageInfo info, final ImageGraphics2D imageG2D) {
String imageDescription = info.getMimeType() + " " + info.getOriginalURI();
final Dimension2D dimensionsPt = info.getSize().getDimensionPt();
final Dimension2D dimensionsMpt = info.getSize().getDimensionMpt();
FormGenerator formGen;

if (psLanguageLevel <= 2) {
formGen = new EPSFormGenerator(form.getName(), imageDescription, dimensionsPt) {

@Override
void doGeneratePaintProc(PSGenerator gen) throws IOException {
paintImageG2D(imageG2D, dimensionsMpt, gen);
}
};
} else {
formGen = new EPSFormGenerator(form.getName(), imageDescription, dimensionsPt) {

@Override
protected void generateAdditionalDataStream(PSGenerator gen) throws IOException {
gen.writeln("/" + form.getName() + ":Data currentfile <<");
gen.writeln(" /Filter /SubFileDecode");
gen.writeln(" /DecodeParms << /EODCount 0 /EODString (%FOPEndOfData) >>");
gen.writeln(">> /ReusableStreamDecode filter");
paintImageG2D(imageG2D, dimensionsMpt, gen);
gen.writeln("%FOPEndOfData");
gen.writeln("def");
}

@Override
void doGeneratePaintProc(PSGenerator gen) throws IOException {
gen.writeln(form.getName() + ":Data 0 setfileposition");
gen.writeln(form.getName() + ":Data cvx exec");
}
};
}
return formGen;
}

private static abstract class EPSFormGenerator extends FormGenerator {

EPSFormGenerator(String formName, String title, Dimension2D dimensions) {
super(formName, title, dimensions);
}

protected void paintImageG2D(final ImageGraphics2D imageG2D, Dimension2D dimensionsMpt,
PSGenerator gen) throws IOException {
PSGraphics2DAdapter adapter = new PSGraphics2DAdapter(gen, false);
adapter.paintImage(imageG2D.getGraphics2DImagePainter(),
null,
0, 0,
(int) Math.round(dimensionsMpt.getWidth()),
(int) Math.round(dimensionsMpt.getHeight()));
}

@Override
protected final void generatePaintProc(PSGenerator gen) throws IOException {
gen.getResourceTracker().notifyResourceUsageOnPage(
PSProcSets.EPS_PROCSET);
gen.writeln("BeginEPSF");
doGeneratePaintProc(gen);
gen.writeln("EndEPSF");
}

abstract void doGeneratePaintProc(PSGenerator gen) throws IOException;
}
}

+ 5
- 0
status.xml View File

@@ -60,6 +60,11 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
<release version="FOP Trunk" date="TBD">
<action context="Fonts" dev="PH" type="fix" fixes-bug="51760" due-to="Mehdi Houshmand">
Changes the way PostScript handles Graphics2D images such that if the language is set to
level 3, the image is stored as an embedded file which has no length limit. Previously it
was stored as an array which has a implementation limit of 65535 elements.
</action>
<action context="Fonts" dev="PH" type="fix" fixes-bug="51759" due-to="Mehdi Houshmand">
PDFFactory responsible for asdigning name to a subset font.
</action>

Loading…
Cancel
Save