Author: ssteiner
Date: Fri Oct 13 12:12:52 2017
New Revision: 1812122
URL: http://svn.apache.org/viewvc?rev=1812122&view=rev
Log:
FOP-2753: PDF to PS allow fop fonts as fallback
Added:
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphics2DAdapterTestCase.java
(with props)
Modified:
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSFontUtils.java
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
xmlgraphics/fop/trunk/fop/lib/xmlgraphics-commons-svn-trunk.jar
Modified:
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSFontUtils.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSFontUtils.java?rev=1812122&r1=1812121&r2=1812122&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSFontUtils.java
(original)
+++
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSFontUtils.java
Fri Oct 13 12:12:52 2017
@@ -36,6 +36,7 @@ import org.apache.commons.logging.LogFac
import org.apache.fontbox.cff.CFFStandardString;
import org.apache.xmlgraphics.fonts.Glyphs;
+import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter;
import org.apache.xmlgraphics.ps.DSCConstants;
import org.apache.xmlgraphics.ps.PSGenerator;
import org.apache.xmlgraphics.ps.PSResource;
@@ -50,6 +51,7 @@ import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.EmbeddingMode;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.FontType;
import org.apache.fop.fonts.LazyFont;
import org.apache.fop.fonts.MultiByteFont;
@@ -907,4 +909,12 @@ public class PSFontUtils extends org.apa
gen.getResourceTracker().registerSuppliedResource(res);
return res;
}
+
+ public static void addFallbackFonts(FontInfo fontInfo,
GeneralGraphics2DImagePainter painter) throws IOException {
+ for (Map.Entry<FontTriplet, String> x :
fontInfo.getFontTriplets().entrySet()) {
+ String name = x.getKey().getName();
+ Typeface typeface = fontInfo.getFonts().get(x.getValue());
+ painter.addFallbackFont(name, typeface);
+ }
+ }
}
Modified:
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java?rev=1812122&r1=1812121&r2=1812122&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
(original)
+++
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
Fri Oct 13 12:12:52 2017
@@ -31,6 +31,7 @@ import org.apache.xmlgraphics.java2d.Gra
import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.fop.fonts.FontInfo;
import org.apache.fop.pdf.PDFFactory;
import org.apache.fop.render.AbstractGraphics2DAdapter;
import org.apache.fop.render.ImageHandlerUtil;
@@ -45,15 +46,17 @@ public class PSGraphics2DAdapter extends
private PSGenerator gen;
private boolean clip = true;
+ private FontInfo fontInfo;
/**
* Creates a new instance.
* @param gen the PostScript generator
* @param clip true if the image should be clipped
*/
- public PSGraphics2DAdapter(PSGenerator gen, boolean clip) {
+ public PSGraphics2DAdapter(PSGenerator gen, boolean clip, FontInfo
fontInfo) {
this.gen = gen;
this.clip = clip;
+ this.fontInfo = fontInfo;
}
/** {@inheritDoc} */
@@ -113,6 +116,9 @@ public class PSGraphics2DAdapter extends
/ context.getUserAgent().getTargetResolution();
graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0,
0), null);
} else {
+ if (painter instanceof GeneralGraphics2DImagePainter) {
+ PSFontUtils.addFallbackFonts(fontInfo,
(GeneralGraphics2DImagePainter) painter);
+ }
Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
painter.paint(graphics, area);
}
Modified:
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java?rev=1812122&r1=1812121&r2=1812122&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
(original)
+++
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
Fri Oct 13 12:12:52 2017
@@ -37,6 +37,7 @@ import org.apache.xmlgraphics.ps.FormGen
import org.apache.xmlgraphics.ps.PSGenerator;
import org.apache.xmlgraphics.ps.PSProcSets;
+import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.RenderingContext;
/**
@@ -94,6 +95,9 @@ public class PSImageHandlerGraphics2D im
transform.translate(fx, fy);
gen.getCurrentState().concatMatrix(transform);
Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+ if (painter instanceof GeneralGraphics2DImagePainter) {
+ PSFontUtils.addFallbackFonts(psContext.getFontInfo(),
(GeneralGraphics2DImagePainter) painter);
+ }
painter.paint(graphics, area);
gen.restoreGraphicsState();
gen.commentln("%FOPEndGraphics2D");
@@ -107,7 +111,7 @@ public class PSImageHandlerGraphics2D im
final ImageGraphics2D imageG2D = (ImageGraphics2D)image;
ImageInfo info = image.getInfo();
- FormGenerator formGen = buildFormGenerator(gen.getPSLevel(), form,
info, imageG2D);
+ FormGenerator formGen = buildFormGenerator(gen.getPSLevel(), form,
info, imageG2D, psContext.getFontInfo());
formGen.generate(gen);
}
/** {@inheritDoc} */
@@ -133,8 +137,8 @@ public class PSImageHandlerGraphics2D im
return false;
}
- private FormGenerator buildFormGenerator(int psLanguageLevel, final
PSImageFormResource form,
- final ImageInfo info, final ImageGraphics2D imageG2D) {
+ private FormGenerator buildFormGenerator(int psLanguageLevel, final
PSImageFormResource form, final ImageInfo info,
+ final ImageGraphics2D imageG2D,
final FontInfo fontInfo) {
String imageDescription = info.getMimeType() + " " +
info.getOriginalURI();
final Dimension2D dimensionsPt = info.getSize().getDimensionPt();
final Dimension2D dimensionsMpt = info.getSize().getDimensionMpt();
@@ -145,7 +149,7 @@ public class PSImageHandlerGraphics2D im
@Override
void doGeneratePaintProc(PSGenerator gen) throws IOException {
- paintImageG2D(imageG2D, dimensionsMpt, gen);
+ paintImageG2D(imageG2D, dimensionsMpt, gen, fontInfo);
}
};
} else {
@@ -157,7 +161,7 @@ public class PSImageHandlerGraphics2D im
gen.writeln(" /Filter /SubFileDecode");
gen.writeln(" /DecodeParms << /EODCount 0 /EODString
(%FOPEndOfData) >>");
gen.writeln(">> /ReusableStreamDecode filter");
- paintImageG2D(imageG2D, dimensionsMpt, gen);
+ paintImageG2D(imageG2D, dimensionsMpt, gen, fontInfo);
gen.writeln("%FOPEndOfData");
gen.writeln("def");
}
@@ -179,8 +183,8 @@ public class PSImageHandlerGraphics2D im
}
protected void paintImageG2D(final ImageGraphics2D imageG2D,
Dimension2D dimensionsMpt,
- PSGenerator gen) throws IOException {
- PSGraphics2DAdapter adapter = new PSGraphics2DAdapter(gen, false);
+ PSGenerator gen, FontInfo fontInfo) throws IOException {
+ PSGraphics2DAdapter adapter = new PSGraphics2DAdapter(gen, false,
fontInfo);
adapter.paintImage(imageG2D.getGraphics2DImagePainter(),
null,
0, 0,
Added:
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphics2DAdapterTestCase.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphics2DAdapterTestCase.java?rev=1812122&view=auto
==============================================================================
---
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphics2DAdapterTestCase.java
(added)
+++
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphics2DAdapterTestCase.java
Fri Oct 13 12:12:52 2017
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.fop.render.ps;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter;
+import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
+import org.apache.xmlgraphics.ps.PSGenerator;
+
+import org.apache.fop.fonts.FontInfo;
+
+public class PSGraphics2DAdapterTestCase {
+ @Test
+ public void testFontFallback() throws IOException {
+ PSGenerator gen = new PSGenerator(new ByteArrayOutputStream());
+ FontInfo fi = new FontInfo();
+ fi.addFontProperties("a", "b", "c", 400);
+ PSGraphics2DAdapter psGraphics2DAdapter = new PSGraphics2DAdapter(gen,
true, fi);
+ MyPainter painter = new MyPainter();
+ psGraphics2DAdapter.paintImage(painter, null, 0, 0, 0, 0);
+ Assert.assertEquals(painter.font, "b");
+ }
+
+ static class MyPainter implements GeneralGraphics2DImagePainter {
+ String font;
+ public Graphics2D getGraphics(boolean textAsShapes, PSGenerator gen) {
+ return new PSGraphics2D(true);
+ }
+
+ public void addFallbackFont(String name, Object font) {
+ this.font = name;
+ }
+
+ public void paint(Graphics2D g2d, Rectangle2D area) {
+ }
+
+ public Dimension getImageSize() {
+ return new Dimension();
+ }
+ }
+}
Propchange:
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphics2DAdapterTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop/trunk/fop/lib/xmlgraphics-commons-svn-trunk.jar
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop/lib/xmlgraphics-commons-svn-trunk.jar?rev=1812122&r1=1812121&r2=1812122&view=diff
==============================================================================
Binary files - no diff available.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]