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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright 1999-2005 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.render.pcl;
  18. // FOP
  19. import org.apache.fop.apps.MimeConstants;
  20. import org.apache.fop.render.PrintRenderer;
  21. // Java
  22. import java.io.IOException;
  23. import java.io.OutputStream;
  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. /** The MIME type for PCL */
  31. public static final String MIME_TYPE = MimeConstants.MIME_PCL_ALT;
  32. /**
  33. * the current stream to add PCL commands to
  34. */
  35. protected PCLStream currentStream;
  36. private int pageHeight = 7920;
  37. // These variables control the virtual paggination functionality.
  38. private int curdiv = 0;
  39. private int divisions = -1;
  40. private int paperheight = -1; // Paper height in decipoints?
  41. private int orientation = -1; // -1=default/unknown, 0=portrait, 1=landscape.
  42. private int topmargin = -1; // Top margin in decipoints?
  43. private int leftmargin = -1; // Left margin in decipoints?
  44. private int fullmargin = 0;
  45. private final boolean debug = false;
  46. private int xoffset = -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. public void setFont(String name, float size) {
  54. int fontcode = 0;
  55. if (name.length() > 1 && name.charAt(0) == 'F') {
  56. try {
  57. fontcode = Integer.parseInt(name.substring(1));
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. }
  61. }
  62. switch (fontcode) {
  63. case 1: // F1 = Helvetica
  64. // currentStream.add("\033(8U\033(s1p" + (size / 1000) + "v0s0b24580T");
  65. // Arial is more common among PCL5 printers than Helvetica - so use Arial
  66. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  67. + "v0s0b16602T");
  68. break;
  69. case 2: // F2 = Helvetica Oblique
  70. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  71. + "v1s0b16602T");
  72. break;
  73. case 3: // F3 = Helvetica Bold
  74. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  75. + "v0s3b16602T");
  76. break;
  77. case 4: // F4 = Helvetica Bold Oblique
  78. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  79. + "v1s3b16602T");
  80. break;
  81. case 5: // F5 = Times Roman
  82. // currentStream.add("\033(8U\033(s1p" + (size / 1000) + "v0s0b25093T");
  83. // Times New is more common among PCL5 printers than Times - so use Times New
  84. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  85. + "v0s0b16901T");
  86. break;
  87. case 6: // F6 = Times Italic
  88. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  89. + "v1s0b16901T");
  90. break;
  91. case 7: // F7 = Times Bold
  92. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  93. + "v0s3b16901T");
  94. break;
  95. case 8: // F8 = Times Bold Italic
  96. currentStream.add("\033(0N\033(s1p" + (size / 1000)
  97. + "v1s3b16901T");
  98. break;
  99. case 9: // F9 = Courier
  100. currentStream.add("\033(0N\033(s0p"
  101. + (120.01f / (size / 1000.00f)) + "h0s0b4099T");
  102. break;
  103. case 10: // F10 = Courier Oblique
  104. currentStream.add("\033(0N\033(s0p"
  105. + (120.01f / (size / 1000.00f)) + "h1s0b4099T");
  106. break;
  107. case 11: // F11 = Courier Bold
  108. currentStream.add("\033(0N\033(s0p"
  109. + (120.01f / (size / 1000.00f)) + "h0s3b4099T");
  110. break;
  111. case 12: // F12 = Courier Bold Oblique
  112. currentStream.add("\033(0N\033(s0p"
  113. + (120.01f / (size / 1000.00f)) + "h1s3b4099T");
  114. break;
  115. case 13: // F13 = Symbol
  116. currentStream.add("\033(19M\033(s1p" + (size / 1000)
  117. + "v0s0b16686T");
  118. // ECMA Latin 1 Symbol Set in Times Roman???
  119. // currentStream.add("\033(9U\033(s1p" + (size / 1000) + "v0s0b25093T");
  120. break;
  121. case 14: // F14 = Zapf Dingbats
  122. currentStream.add("\033(14L\033(s1p" + (size / 1000)
  123. + "v0s0b45101T");
  124. break;
  125. default:
  126. currentStream.add("\033(0N\033(s" + (size / 1000) + "V");
  127. break;
  128. }
  129. }
  130. public void startRenderer(OutputStream outputStream) throws IOException {
  131. log.info("rendering areas to PCL");
  132. log.fatal("The PCL Renderer is non-functional at this time. Please help resurrect it!");
  133. currentStream = new PCLStream(outputStream);
  134. // Set orientation.
  135. if (orientation > -1) {
  136. currentStream.add("\033&l" + orientation + "O");
  137. } else {
  138. currentStream.add("\033&l0O");
  139. }
  140. if (orientation == 1 || orientation == 3) {
  141. xoffset = -144;
  142. } else {
  143. xoffset = -180;
  144. }
  145. // Reset the margins.
  146. currentStream.add("\033" + "9\033&l0E");
  147. }
  148. public void stopRenderer() throws IOException {
  149. }
  150. /** @see org.apache.fop.render.AbstractRenderer */
  151. public String getMimeType() {
  152. return MIME_TYPE;
  153. }
  154. }