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.

PSProcSets.java 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright 2001-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.ps;
  18. import java.io.IOException;
  19. /**
  20. * This class defines the basic resources (procsets) used by FOP's PostScript
  21. * renderer and SVG transcoder.
  22. *
  23. * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
  24. * @version $Id: PSProcSets.java,v 1.3 2003/03/11 08:42:24 jeremias Exp $
  25. */
  26. public final class PSProcSets {
  27. /** the standard FOP procset */
  28. public static final PSResource STD_PROCSET = new StdProcSet();
  29. /** the EPS FOP procset */
  30. public static final PSResource EPS_PROCSET = new EPSProcSet();
  31. private static class StdProcSet extends PSResource {
  32. public StdProcSet() {
  33. super("procset", "Apache FOP Std ProcSet");
  34. }
  35. public void writeTo(PSGenerator gen) throws IOException {
  36. gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE,
  37. new Object[] {"procset", getName(), "1.0", "0"});
  38. gen.writeDSCComment(DSCConstants.VERSION,
  39. new Object[] {"1.0", "0"});
  40. gen.writeDSCComment(DSCConstants.COPYRIGHT, "Copyright 2001-2003 "
  41. + "The Apache Software Foundation. All rights reserved.");
  42. gen.writeDSCComment(DSCConstants.TITLE, "Basic set of procedures used by FOP");
  43. gen.writeln("/bd{bind def}bind def");
  44. gen.writeln("/ld{load def}bd");
  45. gen.writeln("/M/moveto ld");
  46. gen.writeln("/RM/rmoveto ld");
  47. gen.writeln("/t/show ld");
  48. gen.writeln("/A/ashow ld");
  49. gen.writeln("/cp/closepath ld");
  50. gen.writeln("/re {4 2 roll M"); //define rectangle
  51. gen.writeln("1 index 0 rlineto");
  52. gen.writeln("0 exch rlineto");
  53. gen.writeln("neg 0 rlineto");
  54. gen.writeln("cp } bd");
  55. gen.writeln("/_ctm matrix def"); //Holds the current matrix
  56. gen.writeln("/_tm matrix def");
  57. //BT: save currentmatrix, set _tm to identitymatrix and move to 0/0
  58. gen.writeln("/BT { _ctm currentmatrix pop matrix _tm copy pop 0 0 moveto } bd");
  59. //ET: restore last currentmatrix
  60. gen.writeln("/ET { _ctm setmatrix } bd");
  61. gen.writeln("/iTm { _ctm setmatrix _tm concat } bd");
  62. gen.writeln("/Tm { _tm astore pop iTm 0 0 moveto } bd");
  63. gen.writeln("/ux 0.0 def");
  64. gen.writeln("/uy 0.0 def");
  65. // <font> <size> F
  66. gen.writeln("/F {");
  67. gen.writeln(" /Tp exch def");
  68. // gen.writeln(" currentdict exch get");
  69. gen.writeln(" /Tf exch def");
  70. gen.writeln(" Tf findfont Tp scalefont setfont");
  71. gen.writeln(" /cf Tf def /cs Tp def /cw ( ) stringwidth pop def");
  72. gen.writeln("} bd");
  73. gen.writeln("/ULS {currentpoint /uy exch def /ux exch def} bd");
  74. gen.writeln("/ULE {");
  75. gen.writeln(" /Tcx currentpoint pop def");
  76. gen.writeln(" gsave");
  77. gen.writeln(" newpath");
  78. gen.writeln(" cf findfont cs scalefont dup");
  79. gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
  80. gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
  81. gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
  82. gen.writeln(" ux uy To add moveto Tcx uy To add lineto");
  83. gen.writeln(" Tt setlinewidth stroke");
  84. gen.writeln(" grestore");
  85. gen.writeln("} bd");
  86. gen.writeln("/OLE {");
  87. gen.writeln(" /Tcx currentpoint pop def");
  88. gen.writeln(" gsave");
  89. gen.writeln(" newpath");
  90. gen.writeln(" cf findfont cs scalefont dup");
  91. gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
  92. gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
  93. gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
  94. gen.writeln(" ux uy To add cs add moveto Tcx uy To add cs add lineto");
  95. gen.writeln(" Tt setlinewidth stroke");
  96. gen.writeln(" grestore");
  97. gen.writeln("} bd");
  98. gen.writeln("/SOE {");
  99. gen.writeln(" /Tcx currentpoint pop def");
  100. gen.writeln(" gsave");
  101. gen.writeln(" newpath");
  102. gen.writeln(" cf findfont cs scalefont dup");
  103. gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
  104. gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
  105. gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
  106. gen.writeln(" ux uy To add cs 10 mul 26 idiv add moveto "
  107. + "Tcx uy To add cs 10 mul 26 idiv add lineto");
  108. gen.writeln(" Tt setlinewidth stroke");
  109. gen.writeln(" grestore");
  110. gen.writeln("} bd");
  111. gen.writeln("/QUADTO {");
  112. gen.writeln("/Y22 exch store");
  113. gen.writeln("/X22 exch store");
  114. gen.writeln("/Y21 exch store");
  115. gen.writeln("/X21 exch store");
  116. gen.writeln("currentpoint");
  117. gen.writeln("/Y21 load 2 mul add 3 div exch");
  118. gen.writeln("/X21 load 2 mul add 3 div exch");
  119. gen.writeln("/X21 load 2 mul /X22 load add 3 div");
  120. gen.writeln("/Y21 load 2 mul /Y22 load add 3 div");
  121. gen.writeln("/X22 load /Y22 load curveto");
  122. gen.writeln("} bd");
  123. gen.writeDSCComment(DSCConstants.END_RESOURCE);
  124. }
  125. }
  126. private static class EPSProcSet extends PSResource {
  127. public EPSProcSet() {
  128. super("procset", "Apache FOP EPS ProcSet");
  129. }
  130. public void writeTo(PSGenerator gen) throws IOException {
  131. gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE,
  132. new Object[] {"procset", getName(), "1.0", "0"});
  133. gen.writeDSCComment(DSCConstants.VERSION,
  134. new Object[] {"1.0", "0"});
  135. gen.writeDSCComment(DSCConstants.COPYRIGHT, "Copyright 2002-2003 "
  136. + "The Apache Software Foundation. All rights reserved.");
  137. gen.writeDSCComment(DSCConstants.TITLE, "EPS procedures used by FOP");
  138. gen.writeln("/BeginEPSF { %def");
  139. gen.writeln("/b4_Inc_state save def % Save state for cleanup");
  140. gen.writeln("/dict_count countdictstack def % Count objects on dict stack");
  141. gen.writeln("/op_count count 1 sub def % Count objects on operand stack");
  142. gen.writeln("userdict begin % Push userdict on dict stack");
  143. gen.writeln("/showpage { } def % Redefine showpage, { } = null proc");
  144. gen.writeln("0 setgray 0 setlinecap % Prepare graphics state");
  145. gen.writeln("1 setlinewidth 0 setlinejoin");
  146. gen.writeln("10 setmiterlimit [ ] 0 setdash newpath");
  147. gen.writeln("/languagelevel where % If level not equal to 1 then");
  148. gen.writeln("{pop languagelevel % set strokeadjust and");
  149. gen.writeln("1 ne % overprint to their defaults.");
  150. gen.writeln("{false setstrokeadjust false setoverprint");
  151. gen.writeln("} if");
  152. gen.writeln("} if");
  153. gen.writeln("} bd");
  154. gen.writeln("/EndEPSF { %def");
  155. gen.writeln("count op_count sub {pop} repeat % Clean up stacks");
  156. gen.writeln("countdictstack dict_count sub {end} repeat");
  157. gen.writeln("b4_Inc_state restore");
  158. gen.writeln("} bd");
  159. gen.writeDSCComment(DSCConstants.END_RESOURCE);
  160. }
  161. }
  162. /**
  163. * Generates a resource defining standard procset for FOP.
  164. * @param gen PSGenerator to use for output
  165. * @throws IOException In case of an I/O problem
  166. */
  167. public static void writeFOPStdProcSet(PSGenerator gen) throws IOException {
  168. ((StdProcSet)STD_PROCSET).writeTo(gen);
  169. }
  170. /**
  171. * Generates a resource defining a procset for including EPS graphics.
  172. * @param gen PSGenerator to use for output
  173. * @throws IOException In case of an I/O problem
  174. */
  175. public static void writeFOPEPSProcSet(PSGenerator gen) throws IOException {
  176. ((EPSProcSet)EPS_PROCSET).writeTo(gen);
  177. }
  178. }