1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /* $Id$ */ 19 20 21 package embedding; 22 23 import java.awt.Font; 24 import java.io.File; 25 import java.io.FileOutputStream; 26 import java.io.OutputStream; 27 28 import org.apache.fop.configuration.Configuration; 29 import org.apache.fop.configuration.DefaultConfigurationBuilder; 30 import org.apache.xmlgraphics.java2d.GraphicContext; 31 import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D; 32 33 import org.apache.fop.fonts.FontInfo; 34 import org.apache.fop.render.ps.NativeTextHandler; 35 import org.apache.fop.svg.PDFDocumentGraphics2DConfigurator; 36 37 public class ExampleEPS { 38 39 /** 40 * @param args 41 */ main(String[] args)42 public static void main(String[] args) { 43 try { 44 String configFile = "examples/fop-eps.xconf"; 45 DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); 46 Configuration c = cfgBuilder.buildFromFile(new File(configFile)); 47 48 FontInfo fontInfo = PDFDocumentGraphics2DConfigurator.createFontInfo(c, false); 49 50 OutputStream out = new FileOutputStream("example_eps.eps"); 51 EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); 52 g2d.setGraphicContext(new GraphicContext()); 53 g2d.setCustomTextHandler(new NativeTextHandler(g2d, fontInfo)); 54 g2d.setupDocument(out, 200, 100); 55 g2d.setFont(new Font("Arial", Font.PLAIN, 12)); 56 g2d.drawString("Hi there Arial", 50, 50); 57 g2d.finish(); 58 out.close(); 59 } catch (Exception e) { 60 e.printStackTrace(); 61 } 62 } 63 64 } 65