aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGlenn Adams <gadams@apache.org>2012-04-08 21:29:28 +0000
committerGlenn Adams <gadams@apache.org>2012-04-08 21:29:28 +0000
commit92ca968f8c1bb90a6b6110c589c0484e08323ca4 (patch)
tree45f1bf19d8cc80512f112b25a2e128d1fe2f0b1a /examples
parent65b52fe3a8ca3ba5a798a7fbb5077cf68469b008 (diff)
downloadxmlgraphics-fop-92ca968f8c1bb90a6b6110c589c0484e08323ca4.tar.gz
xmlgraphics-fop-92ca968f8c1bb90a6b6110c589c0484e08323ca4.zip
Bugzilla #52966: How to use native text with EPSDocumentGraphics2D.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1311103 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'examples')
-rw-r--r--examples/embedding/java/embedding/ExampleEPS.java62
-rw-r--r--examples/embedding/java/embedding/ExampleEPSSimple.java52
2 files changed, 114 insertions, 0 deletions
diff --git a/examples/embedding/java/embedding/ExampleEPS.java b/examples/embedding/java/embedding/ExampleEPS.java
new file mode 100644
index 000000000..ebf2b9a7d
--- /dev/null
+++ b/examples/embedding/java/embedding/ExampleEPS.java
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+/* $Id$ */
+
+
+package embedding;
+
+import java.awt.Font;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.render.ps.NativeTextHandler;
+import org.apache.fop.svg.PDFDocumentGraphics2DConfigurator;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;
+
+public class ExampleEPS {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ try {
+ String configFile = "examples/fop-eps.xconf";
+ DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
+ Configuration c = cfgBuilder.buildFromFile(configFile);
+
+ FontInfo fontInfo = PDFDocumentGraphics2DConfigurator.createFontInfo(c, false);
+
+ OutputStream out = new FileOutputStream("example_eps.eps");
+ EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
+ g2d.setGraphicContext(new GraphicContext());
+ g2d.setCustomTextHandler(new NativeTextHandler(g2d, fontInfo));
+ g2d.setupDocument(out, 200, 100);
+ g2d.setFont(new Font("Arial", Font.PLAIN, 12));
+ g2d.drawString("Hi there Arial", 50, 50);
+ g2d.finish();
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/examples/embedding/java/embedding/ExampleEPSSimple.java b/examples/embedding/java/embedding/ExampleEPSSimple.java
new file mode 100644
index 000000000..cbc353cd5
--- /dev/null
+++ b/examples/embedding/java/embedding/ExampleEPSSimple.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+/* $Id$ */
+
+
+package embedding;
+
+import java.awt.Font;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import org.apache.fop.render.ps.NativeTextHandler;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;
+
+public class ExampleEPSSimple {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ try {
+ OutputStream out = new FileOutputStream("example_eps_simple.eps");
+ EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
+ g2d.setGraphicContext(new GraphicContext());
+ g2d.setCustomTextHandler(new NativeTextHandler(g2d, null));
+ g2d.setupDocument(out, 200, 100);
+ g2d.setFont(new Font("Helvetica", Font.PLAIN, 12));
+ g2d.drawString("Hi there Helvetica", 50, 50);
+ g2d.finish();
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}