You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PCLRenderer.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.render.pcl;
  8. // FOP
  9. import org.apache.fop.render.PrintRenderer;
  10. import org.apache.fop.image.ImageArea;
  11. import org.apache.fop.image.FopImage;
  12. import org.apache.fop.apps.FOPException;
  13. import org.apache.fop.fo.properties.*;
  14. import org.apache.fop.datatypes.*;
  15. import org.apache.fop.pdf.PDFPathPaint;
  16. import org.apache.fop.pdf.PDFColor;
  17. import org.apache.fop.layout.*;
  18. import org.apache.fop.layout.inline.*;
  19. import org.apache.fop.image.*;
  20. import org.apache.fop.svg.SVGArea;
  21. import org.w3c.dom.svg.SVGSVGElement;
  22. import org.w3c.dom.svg.SVGDocument;
  23. // Java
  24. import java.io.IOException;
  25. import java.io.OutputStream;
  26. import java.util.Enumeration;
  27. /**
  28. * Renderer that renders areas to PCL
  29. * Created by Arthur E Welch III while at M&I EastPoint Technology
  30. * Donated by EastPoint to the Apache FOP project March 2, 2001.
  31. */
  32. public class PCLRenderer extends PrintRenderer {
  33. /**
  34. * the current stream to add PCL commands to
  35. */
  36. public PCLStream currentStream;
  37. private int pageHeight = 7920;
  38. // These variables control the virtual paggination functionality.
  39. public int curdiv = 0;
  40. private int divisions = -1;
  41. public int paperheight = -1; // Paper height in decipoints?
  42. public int orientation =
  43. -1; // -1=default/unknown, 0=portrait, 1=landscape.
  44. public int topmargin = -1; // Top margin in decipoints?
  45. public int leftmargin = -1; // Left margin in decipoints?
  46. private int fullmargin = 0;
  47. private final boolean debug = false;
  48. private int xoffset =
  49. -180; // X Offset to allow for PCL implicit 1/4" left margin.
  50. private java.util.Hashtable options;
  51. /**
  52. * Create the PCL renderer
  53. */
  54. public PCLRenderer() {}
  55. /**
  56. * set the PCL document's producer
  57. *
  58. * @param producer string indicating application producing PCL
  59. */
  60. public void setProducer(String producer) {}
  61. public void setFont(String name, float size) {
  62. int fontcode = 0;
  63. if (name.length() > 1 && name.charAt(0) == 'F') {
  64. try {
  65. fontcode = Integer.parseInt(name.substring(1));
  66. } catch (Exception e) {
  67. e.printStackTrace();
  68. }
  69. }
  70. switch (fontcode) {
  71. case 1: // F1 = Helvetica
  72. // currentStream.add("\033(8U\033(s1p" + (size / 1000) + "v0s0b24580T");
  73. // Arial is more common among PCL5 printers than Helvetica - so use Arial
  74. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  75. + "v0s0b16602T");
  76. break;
  77. case 2: // F2 = Helvetica Oblique
  78. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  79. + "v1s0b16602T");
  80. break;
  81. case 3: // F3 = Helvetica Bold
  82. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  83. + "v0s3b16602T");
  84. break;
  85. case 4: // F4 = Helvetica Bold Oblique
  86. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  87. + "v1s3b16602T");
  88. break;
  89. case 5: // F5 = Times Roman
  90. // currentStream.add("\033(8U\033(s1p" + (size / 1000) + "v0s0b25093T");
  91. // Times New is more common among PCL5 printers than Times - so use Times New
  92. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  93. + "v0s0b16901T");
  94. break;
  95. case 6: // F6 = Times Italic
  96. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  97. + "v1s0b16901T");
  98. break;
  99. case 7: // F7 = Times Bold
  100. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  101. + "v0s3b16901T");
  102. break;
  103. case 8: // F8 = Times Bold Italic
  104. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  105. + "v1s3b16901T");
  106. break;
  107. case 9: // F9 = Courier
  108. currentStream.add("\033(0N\033(s0p"
  109. + (120.01f / (size / 1000.00f)) + "h0s0b4099T");
  110. break;
  111. case 10: // F10 = Courier Oblique
  112. currentStream.add("\033(0N\033(s0p"
  113. + (120.01f / (size / 1000.00f)) + "h1s0b4099T");
  114. break;
  115. case 11: // F11 = Courier Bold
  116. currentStream.add("\033(0N\033(s0p"
  117. + (120.01f / (size / 1000.00f)) + "h0s3b4099T");
  118. break;
  119. case 12: // F12 = Courier Bold Oblique
  120. currentStream.add("\033(0N\033(s0p"
  121. + (120.01f / (size / 1000.00f)) + "h1s3b4099T");
  122. break;
  123. case 13: // F13 = Symbol
  124. currentStream.add("\033(19M\033(s1p" + (size / 1000)
  125. + "v0s0b16686T");
  126. // currentStream.add("\033(9U\033(s1p" + (size / 1000) + "v0s0b25093T"); // ECMA Latin 1 Symbol Set in Times Roman???
  127. break;
  128. case 14: // F14 = Zapf Dingbats
  129. currentStream.add("\033(14L\033(s1p" + (size / 1000)
  130. + "v0s0b45101T");
  131. break;
  132. default:
  133. currentStream.add("\033(0N\033(s" + (size / 1000) + "V");
  134. break;
  135. }
  136. }
  137. public void startRenderer(OutputStream outputStream)
  138. throws IOException {
  139. log.info("rendering areas to PCL");
  140. currentStream = new PCLStream(outputStream);
  141. // Set orientation.
  142. if (orientation > -1)
  143. currentStream.add("\033&l" + orientation + "O");
  144. else
  145. currentStream.add("\033&l0O");
  146. if (orientation == 1 || orientation == 3)
  147. xoffset = -144;
  148. else
  149. xoffset = -180;
  150. // Reset the margins.
  151. currentStream.add("\033" + "9\033&l0E");
  152. }
  153. public void stopRenderer()
  154. throws IOException {
  155. }
  156. }