Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

PCLRenderer.java 6.0KB

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