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 66KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704
  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. /* $Id$ */
  18. package org.apache.fop.render.pcl;
  19. //Java
  20. import java.awt.BasicStroke;
  21. import java.awt.Color;
  22. import java.awt.Dimension;
  23. import java.awt.Graphics2D;
  24. import java.awt.Point;
  25. import java.awt.Rectangle;
  26. import java.awt.RenderingHints;
  27. import java.awt.geom.AffineTransform;
  28. import java.awt.geom.GeneralPath;
  29. import java.awt.geom.Line2D;
  30. import java.awt.geom.Point2D;
  31. import java.awt.geom.Rectangle2D;
  32. import java.awt.image.BufferedImage;
  33. import java.awt.image.RenderedImage;
  34. import java.io.FileNotFoundException;
  35. import java.io.IOException;
  36. import java.io.OutputStream;
  37. import java.util.List;
  38. import java.util.Map;
  39. import java.util.Stack;
  40. import org.w3c.dom.Document;
  41. import org.apache.commons.logging.Log;
  42. import org.apache.commons.logging.LogFactory;
  43. import org.apache.xmlgraphics.image.loader.ImageException;
  44. import org.apache.xmlgraphics.image.loader.ImageFlavor;
  45. import org.apache.xmlgraphics.image.loader.ImageInfo;
  46. import org.apache.xmlgraphics.image.loader.ImageManager;
  47. import org.apache.xmlgraphics.image.loader.ImageSessionContext;
  48. import org.apache.xmlgraphics.image.loader.ImageSize;
  49. import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
  50. import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
  51. import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
  52. import org.apache.xmlgraphics.image.loader.util.ImageUtil;
  53. import org.apache.xmlgraphics.java2d.GraphicContext;
  54. import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
  55. import org.apache.xmlgraphics.util.QName;
  56. import org.apache.xmlgraphics.util.UnitConv;
  57. import org.apache.fop.apps.FOPException;
  58. import org.apache.fop.apps.MimeConstants;
  59. import org.apache.fop.area.Area;
  60. import org.apache.fop.area.Block;
  61. import org.apache.fop.area.BlockViewport;
  62. import org.apache.fop.area.CTM;
  63. import org.apache.fop.area.NormalFlow;
  64. import org.apache.fop.area.PageViewport;
  65. import org.apache.fop.area.RegionViewport;
  66. import org.apache.fop.area.Trait;
  67. import org.apache.fop.area.inline.AbstractTextArea;
  68. import org.apache.fop.area.inline.ForeignObject;
  69. import org.apache.fop.area.inline.Image;
  70. import org.apache.fop.area.inline.InlineArea;
  71. import org.apache.fop.area.inline.Leader;
  72. import org.apache.fop.area.inline.SpaceArea;
  73. import org.apache.fop.area.inline.TextArea;
  74. import org.apache.fop.area.inline.Viewport;
  75. import org.apache.fop.area.inline.WordArea;
  76. import org.apache.fop.datatypes.URISpecification;
  77. import org.apache.fop.events.ResourceEventProducer;
  78. import org.apache.fop.fo.extensions.ExtensionElementMapping;
  79. import org.apache.fop.fonts.Font;
  80. import org.apache.fop.fonts.FontCollection;
  81. import org.apache.fop.fonts.FontInfo;
  82. import org.apache.fop.fonts.FontMetrics;
  83. import org.apache.fop.render.Graphics2DAdapter;
  84. import org.apache.fop.render.PrintRenderer;
  85. import org.apache.fop.render.RendererContext;
  86. import org.apache.fop.render.RendererContextConstants;
  87. import org.apache.fop.render.RendererEventProducer;
  88. import org.apache.fop.render.java2d.Base14FontCollection;
  89. import org.apache.fop.render.java2d.ConfiguredFontCollection;
  90. import org.apache.fop.render.java2d.FontMetricsMapper;
  91. import org.apache.fop.render.java2d.InstalledFontCollection;
  92. import org.apache.fop.render.java2d.Java2DRenderer;
  93. import org.apache.fop.render.pcl.extensions.PCLElementMapping;
  94. import org.apache.fop.traits.BorderProps;
  95. /* Note:
  96. * There are some commonalities with AbstractPathOrientedRenderer but it's not possible
  97. * to derive from it due to PCL's restrictions. We may need an additional common subclass to
  98. * avoid methods copied from AbstractPathOrientedRenderer. Or we wait until after the IF redesign.
  99. */
  100. /**
  101. * Renderer for the PCL 5 printer language. It also uses HP GL/2 for certain graphic elements.
  102. */
  103. public class PCLRenderer extends PrintRenderer {
  104. /** logging instance */
  105. private static Log log = LogFactory.getLog(PCLRenderer.class);
  106. /** The MIME type for PCL */
  107. public static final String MIME_TYPE = MimeConstants.MIME_PCL_ALT;
  108. private static final QName CONV_MODE
  109. = new QName(ExtensionElementMapping.URI, null, "conversion-mode");
  110. private static final QName SRC_TRANSPARENCY
  111. = new QName(ExtensionElementMapping.URI, null, "source-transparency");
  112. /** The OutputStream to write the PCL stream to */
  113. protected OutputStream out;
  114. /** The PCL generator */
  115. protected PCLGenerator gen;
  116. private boolean ioTrouble = false;
  117. private final Stack graphicContextStack = new Stack();
  118. private GraphicContext graphicContext = new GraphicContext();
  119. private PCLPageDefinition currentPageDefinition;
  120. private int currentPrintDirection = 0;
  121. private GeneralPath currentPath = null;
  122. private java.awt.Color currentFillColor = null;
  123. /**
  124. * Controls whether appearance is more important than speed. False can cause some FO feature
  125. * to be ignored (like the advanced borders).
  126. */
  127. private boolean qualityBeforeSpeed = false;
  128. /**
  129. * Controls whether all text should be painted as text. This is a fallback setting in case
  130. * the mixture of native and bitmapped text does not provide the necessary quality.
  131. */
  132. private boolean allTextAsBitmaps = false;
  133. /**
  134. * Controls whether an RGB canvas is used when converting Java2D graphics to bitmaps.
  135. * This can be used to work around problems with Apache Batik, for example, but setting
  136. * this to true will increase memory consumption.
  137. */
  138. private final boolean useColorCanvas = false;
  139. /**
  140. * Controls whether the generation of PJL commands gets disabled.
  141. */
  142. private boolean disabledPJL = false;
  143. /** contains the pageWith of the last printed page */
  144. private long pageWidth = 0;
  145. /** contains the pageHeight of the last printed page */
  146. private long pageHeight = 0;
  147. /**
  148. * Create the PCL renderer
  149. */
  150. public PCLRenderer() {
  151. }
  152. /**
  153. * Configures the renderer to trade speed for quality if desired. One example here is the way
  154. * that borders are rendered.
  155. * @param qualityBeforeSpeed true if quality is more important than speed
  156. */
  157. public void setQualityBeforeSpeed(boolean qualityBeforeSpeed) {
  158. this.qualityBeforeSpeed = qualityBeforeSpeed;
  159. }
  160. /**
  161. * Controls whether PJL commands shall be generated by the PCL renderer.
  162. * @param disable true to disable PJL commands
  163. */
  164. public void setPJLDisabled(boolean disable) {
  165. this.disabledPJL = disable;
  166. }
  167. /**
  168. * Indicates whether PJL generation is disabled.
  169. * @return true if PJL generation is disabled.
  170. */
  171. public boolean isPJLDisabled() {
  172. return this.disabledPJL;
  173. }
  174. /**
  175. * {@inheritDoc}
  176. */
  177. public void setupFontInfo(FontInfo inFontInfo) {
  178. //Don't call super.setupFontInfo() here!
  179. //The PCLRenderer uses the Java2D FontSetup which needs a special font setup
  180. //create a temp Image to test font metrics on
  181. fontInfo = inFontInfo;
  182. BufferedImage fontImage = new BufferedImage(100, 100,
  183. BufferedImage.TYPE_INT_RGB);
  184. Graphics2D graphics2D = fontImage.createGraphics();
  185. //The next line is important to get accurate font metrics!
  186. graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
  187. RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  188. FontCollection[] fontCollections = new FontCollection[] {
  189. new Base14FontCollection(graphics2D),
  190. new InstalledFontCollection(graphics2D),
  191. new ConfiguredFontCollection(getFontResolver(), getFontList())
  192. };
  193. userAgent.getFactory().getFontManager().setup(
  194. getFontInfo(), fontCollections);
  195. }
  196. /**
  197. * Central exception handler for I/O exceptions.
  198. * @param ioe IOException to handle
  199. */
  200. protected void handleIOTrouble(IOException ioe) {
  201. if (!ioTrouble) {
  202. RendererEventProducer eventProducer = RendererEventProducer.Provider.get(
  203. getUserAgent().getEventBroadcaster());
  204. eventProducer.ioError(this, ioe);
  205. ioTrouble = true;
  206. }
  207. }
  208. /** {@inheritDoc} */
  209. public Graphics2DAdapter getGraphics2DAdapter() {
  210. return new PCLGraphics2DAdapter();
  211. }
  212. /** @return the GraphicContext used to track coordinate system transformations */
  213. public GraphicContext getGraphicContext() {
  214. return this.graphicContext;
  215. }
  216. /** @return the target resolution */
  217. protected int getResolution() {
  218. int resolution = Math.round(userAgent.getTargetResolution());
  219. if (resolution <= 300) {
  220. return 300;
  221. } else {
  222. return 600;
  223. }
  224. }
  225. /**
  226. * Sets the current font (NOTE: Hard-coded font mappings ATM!)
  227. * @param name the font name (internal F* names for now)
  228. * @param size the font size
  229. * @param text the text to be rendered (used to determine if there are non-printable chars)
  230. * @return true if the font can be mapped to PCL
  231. * @throws IOException if an I/O problem occurs
  232. */
  233. public boolean setFont(String name, float size, String text) throws IOException {
  234. byte[] encoded = text.getBytes("ISO-8859-1");
  235. for (int i = 0, c = encoded.length; i < c; i++) {
  236. if (encoded[i] == 0x3F && text.charAt(i) != '?') {
  237. return false;
  238. }
  239. }
  240. int fontcode = 0;
  241. if (name.length() > 1 && name.charAt(0) == 'F') {
  242. try {
  243. fontcode = Integer.parseInt(name.substring(1));
  244. } catch (Exception e) {
  245. log.error(e);
  246. }
  247. }
  248. //Note "(ON" selects ISO 8859-1 symbol set as used by PCLGenerator
  249. String formattedSize = gen.formatDouble2(size / 1000);
  250. switch (fontcode) {
  251. case 1: // F1 = Helvetica
  252. // gen.writeCommand("(8U");
  253. // gen.writeCommand("(s1p" + formattedSize + "v0s0b24580T");
  254. // Arial is more common among PCL5 printers than Helvetica - so use Arial
  255. gen.writeCommand("(0N");
  256. gen.writeCommand("(s1p" + formattedSize + "v0s0b16602T");
  257. break;
  258. case 2: // F2 = Helvetica Oblique
  259. gen.writeCommand("(0N");
  260. gen.writeCommand("(s1p" + formattedSize + "v1s0b16602T");
  261. break;
  262. case 3: // F3 = Helvetica Bold
  263. gen.writeCommand("(0N");
  264. gen.writeCommand("(s1p" + formattedSize + "v0s3b16602T");
  265. break;
  266. case 4: // F4 = Helvetica Bold Oblique
  267. gen.writeCommand("(0N");
  268. gen.writeCommand("(s1p" + formattedSize + "v1s3b16602T");
  269. break;
  270. case 5: // F5 = Times Roman
  271. // gen.writeCommand("(8U");
  272. // gen.writeCommand("(s1p" + formattedSize + "v0s0b25093T");
  273. // Times New is more common among PCL5 printers than Times - so use Times New
  274. gen.writeCommand("(0N");
  275. gen.writeCommand("(s1p" + formattedSize + "v0s0b16901T");
  276. break;
  277. case 6: // F6 = Times Italic
  278. gen.writeCommand("(0N");
  279. gen.writeCommand("(s1p" + formattedSize + "v1s0b16901T");
  280. break;
  281. case 7: // F7 = Times Bold
  282. gen.writeCommand("(0N");
  283. gen.writeCommand("(s1p" + formattedSize + "v0s3b16901T");
  284. break;
  285. case 8: // F8 = Times Bold Italic
  286. gen.writeCommand("(0N");
  287. gen.writeCommand("(s1p" + formattedSize + "v1s3b16901T");
  288. break;
  289. case 9: // F9 = Courier
  290. gen.writeCommand("(0N");
  291. gen.writeCommand("(s0p" + gen.formatDouble2(120.01f / (size / 1000.00f))
  292. + "h0s0b4099T");
  293. break;
  294. case 10: // F10 = Courier Oblique
  295. gen.writeCommand("(0N");
  296. gen.writeCommand("(s0p" + gen.formatDouble2(120.01f / (size / 1000.00f))
  297. + "h1s0b4099T");
  298. break;
  299. case 11: // F11 = Courier Bold
  300. gen.writeCommand("(0N");
  301. gen.writeCommand("(s0p" + gen.formatDouble2(120.01f / (size / 1000.00f))
  302. + "h0s3b4099T");
  303. break;
  304. case 12: // F12 = Courier Bold Oblique
  305. gen.writeCommand("(0N");
  306. gen.writeCommand("(s0p" + gen.formatDouble2(120.01f / (size / 1000.00f))
  307. + "h1s3b4099T");
  308. break;
  309. case 13: // F13 = Symbol
  310. return false;
  311. //gen.writeCommand("(19M");
  312. //gen.writeCommand("(s1p" + formattedSize + "v0s0b16686T");
  313. // ECMA Latin 1 Symbol Set in Times Roman???
  314. // gen.writeCommand("(9U");
  315. // gen.writeCommand("(s1p" + formattedSize + "v0s0b25093T");
  316. //break;
  317. case 14: // F14 = Zapf Dingbats
  318. return false;
  319. //gen.writeCommand("(14L");
  320. //gen.writeCommand("(s1p" + formattedSize + "v0s0b45101T");
  321. //break;
  322. default:
  323. //gen.writeCommand("(0N");
  324. //gen.writeCommand("(s" + formattedSize + "V");
  325. return false;
  326. }
  327. return true;
  328. }
  329. /** {@inheritDoc} */
  330. public void startRenderer(OutputStream outputStream) throws IOException {
  331. log.debug("Rendering areas to PCL...");
  332. this.out = outputStream;
  333. this.gen = new PCLGenerator(out, getResolution());
  334. if (!isPJLDisabled()) {
  335. gen.universalEndOfLanguage();
  336. gen.writeText("@PJL COMMENT Produced by " + userAgent.getProducer() + "\n");
  337. if (userAgent.getTitle() != null) {
  338. gen.writeText("@PJL JOB NAME = \"" + userAgent.getTitle() + "\"\n");
  339. }
  340. gen.writeText("@PJL SET RESOLUTION = " + getResolution() + "\n");
  341. gen.writeText("@PJL ENTER LANGUAGE = PCL\n");
  342. }
  343. gen.resetPrinter();
  344. gen.setUnitOfMeasure(getResolution());
  345. gen.setRasterGraphicsResolution(getResolution());
  346. }
  347. /** {@inheritDoc} */
  348. public void stopRenderer() throws IOException {
  349. gen.separateJobs();
  350. gen.resetPrinter();
  351. if (!isPJLDisabled()) {
  352. gen.universalEndOfLanguage();
  353. }
  354. }
  355. /** {@inheritDoc} */
  356. public String getMimeType() {
  357. return MIME_TYPE;
  358. }
  359. /** {@inheritDoc} */
  360. public void renderPage(PageViewport page) throws IOException, FOPException {
  361. saveGraphicsState();
  362. //Paper source
  363. String paperSource = page.getForeignAttributeValue(
  364. new QName(PCLElementMapping.NAMESPACE, null, "paper-source"));
  365. if (paperSource != null) {
  366. gen.selectPaperSource(Integer.parseInt(paperSource));
  367. }
  368. // Is Page duplex?
  369. String pageDuplex = page.getForeignAttributeValue(
  370. new QName(PCLElementMapping.NAMESPACE, null, "duplex-mode"));
  371. if (pageDuplex != null) {
  372. gen.selectDuplexMode(Integer.parseInt(pageDuplex));
  373. }
  374. //Page size
  375. final long pagewidth = Math.round(page.getViewArea().getWidth());
  376. final long pageheight = Math.round(page.getViewArea().getHeight());
  377. selectPageFormat(pagewidth, pageheight);
  378. super.renderPage(page);
  379. //Eject page
  380. gen.formFeed();
  381. restoreGraphicsState();
  382. }
  383. private void selectPageFormat(long pagewidth, long pageheight) throws IOException {
  384. //Only set the page format if it changes (otherwise duplex printing won't work)
  385. if ((pagewidth != this.pageWidth) || (pageheight != this.pageHeight)) {
  386. this.pageWidth = pagewidth;
  387. this.pageHeight = pageheight;
  388. this.currentPageDefinition = PCLPageDefinition.getPageDefinition(
  389. pagewidth, pageheight, 1000);
  390. if (this.currentPageDefinition == null) {
  391. this.currentPageDefinition = PCLPageDefinition.getDefaultPageDefinition();
  392. log.warn("Paper type could not be determined. Falling back to: "
  393. + this.currentPageDefinition.getName());
  394. }
  395. if (log.isDebugEnabled()) {
  396. log.debug("page size: " + currentPageDefinition.getPhysicalPageSize());
  397. log.debug("logical page: " + currentPageDefinition.getLogicalPageRect());
  398. }
  399. if (this.currentPageDefinition.isLandscapeFormat()) {
  400. gen.writeCommand("&l1O"); //Landscape Orientation
  401. } else {
  402. gen.writeCommand("&l0O"); //Portrait Orientation
  403. }
  404. gen.selectPageSize(this.currentPageDefinition.getSelector());
  405. gen.clearHorizontalMargins();
  406. gen.setTopMargin(0);
  407. }
  408. }
  409. /** Saves the current graphics state on the stack. */
  410. protected void saveGraphicsState() {
  411. graphicContextStack.push(graphicContext);
  412. graphicContext = (GraphicContext)graphicContext.clone();
  413. }
  414. /** Restores the last graphics state from the stack. */
  415. protected void restoreGraphicsState() {
  416. graphicContext = (GraphicContext)graphicContextStack.pop();
  417. }
  418. /**
  419. * Clip an area. write a clipping operation given coordinates in the current
  420. * transform. Coordinates are in points.
  421. *
  422. * @param x the x coordinate
  423. * @param y the y coordinate
  424. * @param width the width of the area
  425. * @param height the height of the area
  426. */
  427. protected void clipRect(float x, float y, float width, float height) {
  428. //PCL cannot clip (only HP GL/2 can)
  429. }
  430. private Point2D transformedPoint(float x, float y) {
  431. return transformedPoint(Math.round(x), Math.round(y));
  432. }
  433. private Point2D transformedPoint(int x, int y) {
  434. AffineTransform at = graphicContext.getTransform();
  435. if (log.isTraceEnabled()) {
  436. log.trace("Current transform: " + at);
  437. }
  438. Point2D.Float orgPoint = new Point2D.Float(x, y);
  439. Point2D.Float transPoint = new Point2D.Float();
  440. at.transform(orgPoint, transPoint);
  441. //At this point we have the absolute position in FOP's coordinate system
  442. //Now get PCL coordinates taking the current print direction and the logical page
  443. //into account.
  444. Dimension pageSize = currentPageDefinition.getPhysicalPageSize();
  445. Rectangle logRect = currentPageDefinition.getLogicalPageRect();
  446. switch (currentPrintDirection) {
  447. case 0:
  448. transPoint.x -= logRect.x;
  449. transPoint.y -= logRect.y;
  450. break;
  451. case 90:
  452. float ty = transPoint.x;
  453. transPoint.x = pageSize.height - transPoint.y;
  454. transPoint.y = ty;
  455. transPoint.x -= logRect.y;
  456. transPoint.y -= logRect.x;
  457. break;
  458. case 180:
  459. transPoint.x = pageSize.width - transPoint.x;
  460. transPoint.y = pageSize.height - transPoint.y;
  461. transPoint.x -= pageSize.width - logRect.x - logRect.width;
  462. transPoint.y -= pageSize.height - logRect.y - logRect.height;
  463. //The next line is odd and is probably necessary due to the default value of the
  464. //Text Length command: "1/2 inch less than maximum text length"
  465. //I wonder why this isn't necessary for the 90 degree rotation. *shrug*
  466. transPoint.y -= UnitConv.in2mpt(0.5);
  467. break;
  468. case 270:
  469. float tx = transPoint.y;
  470. transPoint.y = pageSize.width - transPoint.x;
  471. transPoint.x = tx;
  472. transPoint.x -= pageSize.height - logRect.y - logRect.height;
  473. transPoint.y -= pageSize.width - logRect.x - logRect.width;
  474. break;
  475. default:
  476. throw new IllegalStateException("Illegal print direction: " + currentPrintDirection);
  477. }
  478. return transPoint;
  479. }
  480. private void changePrintDirection() {
  481. AffineTransform at = graphicContext.getTransform();
  482. int newDir;
  483. try {
  484. if (at.getScaleX() == 0 && at.getScaleY() == 0
  485. && at.getShearX() == 1 && at.getShearY() == -1) {
  486. newDir = 90;
  487. } else if (at.getScaleX() == -1 && at.getScaleY() == -1
  488. && at.getShearX() == 0 && at.getShearY() == 0) {
  489. newDir = 180;
  490. } else if (at.getScaleX() == 0 && at.getScaleY() == 0
  491. && at.getShearX() == -1 && at.getShearY() == 1) {
  492. newDir = 270;
  493. } else {
  494. newDir = 0;
  495. }
  496. if (newDir != this.currentPrintDirection) {
  497. this.currentPrintDirection = newDir;
  498. gen.changePrintDirection(this.currentPrintDirection);
  499. }
  500. } catch (IOException ioe) {
  501. handleIOTrouble(ioe);
  502. }
  503. }
  504. /**
  505. * {@inheritDoc}
  506. */
  507. protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
  508. saveGraphicsState();
  509. AffineTransform at = new AffineTransform(ctm.toArray());
  510. graphicContext.transform(at);
  511. changePrintDirection();
  512. if (log.isDebugEnabled()) {
  513. log.debug("startVPArea: " + at + " --> " + graphicContext.getTransform());
  514. }
  515. }
  516. /**
  517. * {@inheritDoc}
  518. */
  519. protected void endVParea() {
  520. restoreGraphicsState();
  521. changePrintDirection();
  522. if (log.isDebugEnabled()) {
  523. log.debug("endVPArea() --> " + graphicContext.getTransform());
  524. }
  525. }
  526. /**
  527. * Handle block traits.
  528. * The block could be any sort of block with any positioning
  529. * so this should render the traits such as border and background
  530. * in its position.
  531. *
  532. * @param block the block to render the traits
  533. */
  534. protected void handleBlockTraits(Block block) {
  535. int borderPaddingStart = block.getBorderAndPaddingWidthStart();
  536. int borderPaddingBefore = block.getBorderAndPaddingWidthBefore();
  537. float startx = currentIPPosition / 1000f;
  538. float starty = currentBPPosition / 1000f;
  539. float width = block.getIPD() / 1000f;
  540. float height = block.getBPD() / 1000f;
  541. startx += block.getStartIndent() / 1000f;
  542. startx -= block.getBorderAndPaddingWidthStart() / 1000f;
  543. width += borderPaddingStart / 1000f;
  544. width += block.getBorderAndPaddingWidthEnd() / 1000f;
  545. height += borderPaddingBefore / 1000f;
  546. height += block.getBorderAndPaddingWidthAfter() / 1000f;
  547. drawBackAndBorders(block, startx, starty, width, height);
  548. }
  549. /**
  550. * {@inheritDoc}
  551. * @todo Copied from AbstractPathOrientedRenderer
  552. */
  553. protected void handleRegionTraits(RegionViewport region) {
  554. Rectangle2D viewArea = region.getViewArea();
  555. float startx = (float)(viewArea.getX() / 1000f);
  556. float starty = (float)(viewArea.getY() / 1000f);
  557. float width = (float)(viewArea.getWidth() / 1000f);
  558. float height = (float)(viewArea.getHeight() / 1000f);
  559. if (region.getRegionReference().getRegionClass() == FO_REGION_BODY) {
  560. currentBPPosition = region.getBorderAndPaddingWidthBefore();
  561. currentIPPosition = region.getBorderAndPaddingWidthStart();
  562. }
  563. drawBackAndBorders(region, startx, starty, width, height);
  564. }
  565. /**
  566. * {@inheritDoc}
  567. */
  568. protected void renderText(final TextArea text) {
  569. renderInlineAreaBackAndBorders(text);
  570. String fontname = getInternalFontNameForArea(text);
  571. final int fontsize = text.getTraitAsInteger(Trait.FONT_SIZE);
  572. //Determine position
  573. int saveIP = currentIPPosition;
  574. final int rx = currentIPPosition + text.getBorderAndPaddingWidthStart();
  575. int bl = currentBPPosition + text.getOffset() + text.getBaselineOffset();
  576. try {
  577. final Color col = (Color)text.getTrait(Trait.COLOR);
  578. boolean pclFont = allTextAsBitmaps
  579. ? false
  580. : setFont(fontname, fontsize, text.getText());
  581. if (pclFont) {
  582. //this.currentFill = col;
  583. if (col != null) {
  584. //useColor(ct);
  585. gen.setTransparencyMode(true, false);
  586. gen.selectGrayscale(col);
  587. }
  588. saveGraphicsState();
  589. graphicContext.translate(rx, bl);
  590. setCursorPos(0, 0);
  591. gen.setTransparencyMode(true, true);
  592. if (text.hasUnderline()) {
  593. gen.writeCommand("&d0D");
  594. }
  595. super.renderText(text); //Updates IPD and renders words and spaces
  596. if (text.hasUnderline()) {
  597. gen.writeCommand("&d@");
  598. }
  599. restoreGraphicsState();
  600. } else {
  601. //Use Java2D to paint different fonts via bitmap
  602. final Font font = getFontFromArea(text);
  603. final int baseline = text.getBaselineOffset();
  604. //for cursive fonts, so the text isn't clipped
  605. int extraWidth = font.getFontSize() / 3;
  606. final FontMetricsMapper mapper = (FontMetricsMapper)fontInfo.getMetricsFor(
  607. font.getFontName());
  608. int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000;
  609. final int additionalBPD = maxAscent - baseline;
  610. Graphics2DAdapter g2a = getGraphics2DAdapter();
  611. final Rectangle paintRect = new Rectangle(
  612. rx, currentBPPosition + text.getOffset() - additionalBPD,
  613. text.getIPD() + extraWidth, text.getBPD() + additionalBPD);
  614. RendererContext rc = createRendererContext(paintRect.x, paintRect.y,
  615. paintRect.width, paintRect.height, null);
  616. Map atts = new java.util.HashMap();
  617. atts.put(CONV_MODE, "bitmap");
  618. atts.put(SRC_TRANSPARENCY, "true");
  619. rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts);
  620. Graphics2DImagePainter painter = new Graphics2DImagePainter() {
  621. public void paint(Graphics2D g2d, Rectangle2D area) {
  622. g2d.setFont(mapper.getFont(font.getFontSize()));
  623. g2d.translate(0, baseline + additionalBPD);
  624. g2d.scale(1000, 1000);
  625. g2d.setColor(col);
  626. Java2DRenderer.renderText(text, g2d, font);
  627. renderTextDecoration(g2d, mapper, fontsize, text, 0, 0);
  628. }
  629. public Dimension getImageSize() {
  630. return paintRect.getSize();
  631. }
  632. };
  633. g2a.paintImage(painter, rc,
  634. paintRect.x, paintRect.y, paintRect.width, paintRect.height);
  635. currentIPPosition = saveIP + text.getAllocIPD();
  636. }
  637. } catch (IOException ioe) {
  638. handleIOTrouble(ioe);
  639. }
  640. }
  641. /**
  642. * Paints the text decoration marks.
  643. * @param g2d Graphics2D instance to paint to
  644. * @param fm Current typeface
  645. * @param fontsize Current font size
  646. * @param inline inline area to paint the marks for
  647. * @param baseline position of the baseline
  648. * @param startx start IPD
  649. */
  650. private static void renderTextDecoration(Graphics2D g2d,
  651. FontMetrics fm, int fontsize, InlineArea inline,
  652. int baseline, int startx) {
  653. boolean hasTextDeco = inline.hasUnderline()
  654. || inline.hasOverline()
  655. || inline.hasLineThrough();
  656. if (hasTextDeco) {
  657. float descender = fm.getDescender(fontsize) / 1000f;
  658. float capHeight = fm.getCapHeight(fontsize) / 1000f;
  659. float lineWidth = (descender / -4f) / 1000f;
  660. float endx = (startx + inline.getIPD()) / 1000f;
  661. if (inline.hasUnderline()) {
  662. Color ct = (Color) inline.getTrait(Trait.UNDERLINE_COLOR);
  663. g2d.setColor(ct);
  664. float y = baseline - descender / 2f;
  665. g2d.setStroke(new BasicStroke(lineWidth));
  666. g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f,
  667. endx, y / 1000f));
  668. }
  669. if (inline.hasOverline()) {
  670. Color ct = (Color) inline.getTrait(Trait.OVERLINE_COLOR);
  671. g2d.setColor(ct);
  672. float y = (float)(baseline - (1.1 * capHeight));
  673. g2d.setStroke(new BasicStroke(lineWidth));
  674. g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f,
  675. endx, y / 1000f));
  676. }
  677. if (inline.hasLineThrough()) {
  678. Color ct = (Color) inline.getTrait(Trait.LINETHROUGH_COLOR);
  679. g2d.setColor(ct);
  680. float y = (float)(baseline - (0.45 * capHeight));
  681. g2d.setStroke(new BasicStroke(lineWidth));
  682. g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f,
  683. endx, y / 1000f));
  684. }
  685. }
  686. }
  687. /**
  688. * Sets the current cursor position. The coordinates are transformed to the absolute position
  689. * on the logical PCL page and then passed on to the PCLGenerator.
  690. * @param x the x coordinate (in millipoints)
  691. * @param y the y coordinate (in millipoints)
  692. */
  693. void setCursorPos(float x, float y) {
  694. try {
  695. Point2D transPoint = transformedPoint(x, y);
  696. gen.setCursorPos(transPoint.getX(), transPoint.getY());
  697. } catch (IOException ioe) {
  698. handleIOTrouble(ioe);
  699. }
  700. }
  701. /** Clip using the current path. */
  702. protected void clip() {
  703. if (currentPath == null) {
  704. throw new IllegalStateException("No current path available!");
  705. }
  706. //TODO Find a good way to do clipping. PCL itself cannot clip.
  707. currentPath = null;
  708. }
  709. /**
  710. * Closes the current subpath by appending a straight line segment from
  711. * the current point to the starting point of the subpath.
  712. */
  713. protected void closePath() {
  714. currentPath.closePath();
  715. }
  716. /**
  717. * Appends a straight line segment from the current point to (x, y). The
  718. * new current point is (x, y).
  719. * @param x x coordinate
  720. * @param y y coordinate
  721. */
  722. protected void lineTo(float x, float y) {
  723. if (currentPath == null) {
  724. currentPath = new GeneralPath();
  725. }
  726. currentPath.lineTo(x, y);
  727. }
  728. /**
  729. * Moves the current point to (x, y), omitting any connecting line segment.
  730. * @param x x coordinate
  731. * @param y y coordinate
  732. */
  733. protected void moveTo(float x, float y) {
  734. if (currentPath == null) {
  735. currentPath = new GeneralPath();
  736. }
  737. currentPath.moveTo(x, y);
  738. }
  739. /**
  740. * Fill a rectangular area.
  741. * @param x the x coordinate (in pt)
  742. * @param y the y coordinate (in pt)
  743. * @param width the width of the rectangle
  744. * @param height the height of the rectangle
  745. */
  746. protected void fillRect(float x, float y, float width, float height) {
  747. try {
  748. setCursorPos(x * 1000, y * 1000);
  749. gen.fillRect((int)(width * 1000), (int)(height * 1000),
  750. this.currentFillColor);
  751. } catch (IOException ioe) {
  752. handleIOTrouble(ioe);
  753. }
  754. }
  755. /**
  756. * Sets the new current fill color.
  757. * @param color the color
  758. */
  759. protected void updateFillColor(java.awt.Color color) {
  760. this.currentFillColor = color;
  761. }
  762. /**
  763. * {@inheritDoc}
  764. */
  765. protected void renderWord(WordArea word) {
  766. //Font font = getFontFromArea(word.getParentArea());
  767. String s = word.getWord();
  768. try {
  769. gen.writeText(s);
  770. } catch (IOException ioe) {
  771. handleIOTrouble(ioe);
  772. }
  773. super.renderWord(word);
  774. }
  775. /**
  776. * {@inheritDoc}
  777. */
  778. protected void renderSpace(SpaceArea space) {
  779. AbstractTextArea textArea = (AbstractTextArea)space.getParentArea();
  780. String s = space.getSpace();
  781. char sp = s.charAt(0);
  782. Font font = getFontFromArea(textArea);
  783. int tws = (space.isAdjustable()
  784. ? textArea.getTextWordSpaceAdjust()
  785. + 2 * textArea.getTextLetterSpaceAdjust()
  786. : 0);
  787. double dx = (font.getCharWidth(sp) + tws) / 100f;
  788. try {
  789. gen.writeCommand("&a+" + gen.formatDouble2(dx) + "H");
  790. } catch (IOException ioe) {
  791. handleIOTrouble(ioe);
  792. }
  793. super.renderSpace(space);
  794. }
  795. /**
  796. * Render an inline viewport.
  797. * This renders an inline viewport by clipping if necessary.
  798. * @param viewport the viewport to handle
  799. * @todo Copied from AbstractPathOrientedRenderer
  800. */
  801. public void renderViewport(Viewport viewport) {
  802. float x = currentIPPosition / 1000f;
  803. float y = (currentBPPosition + viewport.getOffset()) / 1000f;
  804. float width = viewport.getIPD() / 1000f;
  805. float height = viewport.getBPD() / 1000f;
  806. // TODO: Calculate the border rect correctly.
  807. float borderPaddingStart = viewport.getBorderAndPaddingWidthStart() / 1000f;
  808. float borderPaddingBefore = viewport.getBorderAndPaddingWidthBefore() / 1000f;
  809. float bpwidth = borderPaddingStart
  810. + (viewport.getBorderAndPaddingWidthEnd() / 1000f);
  811. float bpheight = borderPaddingBefore
  812. + (viewport.getBorderAndPaddingWidthAfter() / 1000f);
  813. drawBackAndBorders(viewport, x, y, width + bpwidth, height + bpheight);
  814. if (viewport.getClip()) {
  815. saveGraphicsState();
  816. clipRect(x + borderPaddingStart, y + borderPaddingBefore, width, height);
  817. }
  818. super.renderViewport(viewport);
  819. if (viewport.getClip()) {
  820. restoreGraphicsState();
  821. }
  822. }
  823. /**
  824. * {@inheritDoc}
  825. */
  826. protected void renderBlockViewport(BlockViewport bv, List children) {
  827. // clip and position viewport if necessary
  828. // save positions
  829. int saveIP = currentIPPosition;
  830. int saveBP = currentBPPosition;
  831. CTM ctm = bv.getCTM();
  832. int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
  833. int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore();
  834. //This is the content-rect
  835. float width = bv.getIPD() / 1000f;
  836. float height = bv.getBPD() / 1000f;
  837. if (bv.getPositioning() == Block.ABSOLUTE
  838. || bv.getPositioning() == Block.FIXED) {
  839. //For FIXED, we need to break out of the current viewports to the
  840. //one established by the page. We save the state stack for restoration
  841. //after the block-container has been painted. See below.
  842. List breakOutList = null;
  843. if (bv.getPositioning() == Block.FIXED) {
  844. breakOutList = breakOutOfStateStack();
  845. }
  846. AffineTransform positionTransform = new AffineTransform();
  847. positionTransform.translate(bv.getXOffset(), bv.getYOffset());
  848. //"left/"top" (bv.getX/YOffset()) specify the position of the content rectangle
  849. positionTransform.translate(-borderPaddingStart, -borderPaddingBefore);
  850. saveGraphicsState();
  851. //Viewport position
  852. concatenateTransformationMatrix(UnitConv.mptToPt(positionTransform));
  853. //Background and borders
  854. float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f;
  855. float bpheight = (borderPaddingBefore + bv.getBorderAndPaddingWidthAfter()) / 1000f;
  856. drawBackAndBorders(bv, 0, 0, width + bpwidth, height + bpheight);
  857. //Shift to content rectangle after border painting
  858. AffineTransform contentRectTransform = new AffineTransform();
  859. contentRectTransform.translate(borderPaddingStart, borderPaddingBefore);
  860. concatenateTransformationMatrix(UnitConv.mptToPt(contentRectTransform));
  861. //Clipping
  862. if (bv.getClip()) {
  863. clipRect(0f, 0f, width, height);
  864. }
  865. saveGraphicsState();
  866. //Set up coordinate system for content rectangle
  867. AffineTransform contentTransform = ctm.toAffineTransform();
  868. concatenateTransformationMatrix(UnitConv.mptToPt(contentTransform));
  869. currentIPPosition = 0;
  870. currentBPPosition = 0;
  871. renderBlocks(bv, children);
  872. restoreGraphicsState();
  873. restoreGraphicsState();
  874. if (breakOutList != null) {
  875. restoreStateStackAfterBreakOut(breakOutList);
  876. }
  877. currentIPPosition = saveIP;
  878. currentBPPosition = saveBP;
  879. } else {
  880. currentBPPosition += bv.getSpaceBefore();
  881. //borders and background in the old coordinate system
  882. handleBlockTraits(bv);
  883. //Advance to start of content area
  884. currentIPPosition += bv.getStartIndent();
  885. CTM tempctm = new CTM(containingIPPosition, currentBPPosition);
  886. ctm = tempctm.multiply(ctm);
  887. //Now adjust for border/padding
  888. currentBPPosition += borderPaddingBefore;
  889. Rectangle2D clippingRect = null;
  890. if (bv.getClip()) {
  891. clippingRect = new Rectangle(currentIPPosition, currentBPPosition,
  892. bv.getIPD(), bv.getBPD());
  893. }
  894. startVParea(ctm, clippingRect);
  895. currentIPPosition = 0;
  896. currentBPPosition = 0;
  897. renderBlocks(bv, children);
  898. endVParea();
  899. currentIPPosition = saveIP;
  900. currentBPPosition = saveBP;
  901. currentBPPosition += (bv.getAllocBPD());
  902. }
  903. //currentFontName = saveFontName;
  904. }
  905. /** {@inheritDoc} */
  906. protected void renderReferenceArea(Block block) {
  907. //TODO This is the same code as in AbstractPathOrientedRenderer
  908. //So there's some optimization potential but not otherwise PCLRenderer is a little
  909. //difficult to derive from AbstractPathOrientedRenderer. Maybe an additional layer
  910. //between PrintRenderer and AbstractPathOrientedRenderer is necessary.
  911. // save position and offset
  912. int saveIP = currentIPPosition;
  913. int saveBP = currentBPPosition;
  914. //Establish a new coordinate system
  915. AffineTransform at = new AffineTransform();
  916. at.translate(currentIPPosition, currentBPPosition);
  917. at.translate(block.getXOffset(), block.getYOffset());
  918. at.translate(0, block.getSpaceBefore());
  919. if (!at.isIdentity()) {
  920. saveGraphicsState();
  921. concatenateTransformationMatrix(UnitConv.mptToPt(at));
  922. }
  923. currentIPPosition = 0;
  924. currentBPPosition = 0;
  925. handleBlockTraits(block);
  926. List children = block.getChildAreas();
  927. if (children != null) {
  928. renderBlocks(block, children);
  929. }
  930. if (!at.isIdentity()) {
  931. restoreGraphicsState();
  932. }
  933. // stacked and relative blocks effect stacking
  934. currentIPPosition = saveIP;
  935. currentBPPosition = saveBP;
  936. }
  937. /** {@inheritDoc} */
  938. protected void renderFlow(NormalFlow flow) {
  939. //TODO This is the same code as in AbstractPathOrientedRenderer
  940. //So there's some optimization potential but not otherwise PCLRenderer is a little
  941. //difficult to derive from AbstractPathOrientedRenderer. Maybe an additional layer
  942. //between PrintRenderer and AbstractPathOrientedRenderer is necessary.
  943. // save position and offset
  944. int saveIP = currentIPPosition;
  945. int saveBP = currentBPPosition;
  946. //Establish a new coordinate system
  947. AffineTransform at = new AffineTransform();
  948. at.translate(currentIPPosition, currentBPPosition);
  949. if (!at.isIdentity()) {
  950. saveGraphicsState();
  951. concatenateTransformationMatrix(UnitConv.mptToPt(at));
  952. }
  953. currentIPPosition = 0;
  954. currentBPPosition = 0;
  955. super.renderFlow(flow);
  956. if (!at.isIdentity()) {
  957. restoreGraphicsState();
  958. }
  959. // stacked and relative blocks effect stacking
  960. currentIPPosition = saveIP;
  961. currentBPPosition = saveBP;
  962. }
  963. /**
  964. * Concatenates the current transformation matrix with the given one, therefore establishing
  965. * a new coordinate system.
  966. * @param at the transformation matrix to process (coordinates in points)
  967. */
  968. protected void concatenateTransformationMatrix(AffineTransform at) {
  969. if (!at.isIdentity()) {
  970. graphicContext.transform(UnitConv.ptToMpt(at));
  971. changePrintDirection();
  972. }
  973. }
  974. private List breakOutOfStateStack() {
  975. log.debug("Block.FIXED --> break out");
  976. List breakOutList = new java.util.ArrayList();
  977. while (!this.graphicContextStack.empty()) {
  978. breakOutList.add(0, this.graphicContext);
  979. restoreGraphicsState();
  980. }
  981. return breakOutList;
  982. }
  983. private void restoreStateStackAfterBreakOut(List breakOutList) {
  984. log.debug("Block.FIXED --> restoring context after break-out");
  985. for (int i = 0, c = breakOutList.size(); i < c; i++) {
  986. saveGraphicsState();
  987. this.graphicContext = (GraphicContext)breakOutList.get(i);
  988. }
  989. }
  990. /** {@inheritDoc} */
  991. protected RendererContext createRendererContext(int x, int y, int width, int height,
  992. Map foreignAttributes) {
  993. RendererContext context = super.createRendererContext(
  994. x, y, width, height, foreignAttributes);
  995. context.setProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS,
  996. Boolean.valueOf(this.useColorCanvas));
  997. return context;
  998. }
  999. /** {@inheritDoc} */
  1000. public void renderImage(Image image, Rectangle2D pos) {
  1001. drawImage(image.getURL(), pos, image.getForeignAttributes());
  1002. }
  1003. private static final ImageFlavor[] FLAVORS = new ImageFlavor[]
  1004. {ImageFlavor.GRAPHICS2D,
  1005. ImageFlavor.BUFFERED_IMAGE,
  1006. ImageFlavor.RENDERED_IMAGE,
  1007. ImageFlavor.XML_DOM};
  1008. /**
  1009. * Draw an image at the indicated location.
  1010. * @param uri the URI/URL of the image
  1011. * @param pos the position of the image
  1012. * @param foreignAttributes an optional Map with foreign attributes, may be null
  1013. */
  1014. protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
  1015. uri = URISpecification.getURL(uri);
  1016. Rectangle posInt = new Rectangle(
  1017. (int)pos.getX(),
  1018. (int)pos.getY(),
  1019. (int)pos.getWidth(),
  1020. (int)pos.getHeight());
  1021. Point origin = new Point(currentIPPosition, currentBPPosition);
  1022. int x = origin.x + posInt.x;
  1023. int y = origin.y + posInt.y;
  1024. ImageManager manager = getUserAgent().getFactory().getImageManager();
  1025. ImageInfo info = null;
  1026. try {
  1027. ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
  1028. info = manager.getImageInfo(uri, sessionContext);
  1029. //Only now fully load/prepare the image
  1030. Map hints = ImageUtil.getDefaultHints(sessionContext);
  1031. org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
  1032. info, FLAVORS, hints, sessionContext);
  1033. //...and process the image
  1034. if (img instanceof ImageGraphics2D) {
  1035. ImageGraphics2D imageG2D = (ImageGraphics2D)img;
  1036. RendererContext context = createRendererContext(
  1037. posInt.x, posInt.y,
  1038. posInt.width, posInt.height, foreignAttributes);
  1039. getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
  1040. context, x, y, posInt.width, posInt.height);
  1041. } else if (img instanceof ImageRendered) {
  1042. ImageRendered imgRend = (ImageRendered)img;
  1043. RenderedImage ri = imgRend.getRenderedImage();
  1044. setCursorPos(x, y);
  1045. gen.paintBitmap(ri,
  1046. new Dimension(posInt.width, posInt.height),
  1047. false);
  1048. } else if (img instanceof ImageXMLDOM) {
  1049. ImageXMLDOM imgXML = (ImageXMLDOM)img;
  1050. renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
  1051. pos, foreignAttributes);
  1052. } else {
  1053. throw new UnsupportedOperationException("Unsupported image type: " + img);
  1054. }
  1055. } catch (ImageException ie) {
  1056. ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
  1057. getUserAgent().getEventBroadcaster());
  1058. eventProducer.imageError(this, (info != null ? info.toString() : uri), ie, null);
  1059. } catch (FileNotFoundException fe) {
  1060. ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
  1061. getUserAgent().getEventBroadcaster());
  1062. eventProducer.imageNotFound(this, (info != null ? info.toString() : uri), fe, null);
  1063. } catch (IOException ioe) {
  1064. ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
  1065. getUserAgent().getEventBroadcaster());
  1066. eventProducer.imageIOError(this, (info != null ? info.toString() : uri), ioe, null);
  1067. }
  1068. }
  1069. /** {@inheritDoc} */
  1070. public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
  1071. Document doc = fo.getDocument();
  1072. String ns = fo.getNameSpace();
  1073. renderDocument(doc, ns, pos, fo.getForeignAttributes());
  1074. }
  1075. /**
  1076. * Common method to render the background and borders for any inline area.
  1077. * The all borders and padding are drawn outside the specified area.
  1078. * @param area the inline area for which the background, border and padding is to be
  1079. * rendered
  1080. * @todo Copied from AbstractPathOrientedRenderer
  1081. */
  1082. protected void renderInlineAreaBackAndBorders(InlineArea area) {
  1083. float x = currentIPPosition / 1000f;
  1084. float y = (currentBPPosition + area.getOffset()) / 1000f;
  1085. float width = area.getIPD() / 1000f;
  1086. float height = area.getBPD() / 1000f;
  1087. float borderPaddingStart = area.getBorderAndPaddingWidthStart() / 1000f;
  1088. float borderPaddingBefore = area.getBorderAndPaddingWidthBefore() / 1000f;
  1089. float bpwidth = borderPaddingStart
  1090. + (area.getBorderAndPaddingWidthEnd() / 1000f);
  1091. float bpheight = borderPaddingBefore
  1092. + (area.getBorderAndPaddingWidthAfter() / 1000f);
  1093. if (height != 0.0f || bpheight != 0.0f && bpwidth != 0.0f) {
  1094. drawBackAndBorders(area, x, y - borderPaddingBefore
  1095. , width + bpwidth
  1096. , height + bpheight);
  1097. }
  1098. }
  1099. /**
  1100. * Draw the background and borders. This draws the background and border
  1101. * traits for an area given the position.
  1102. *
  1103. * @param area the area whose traits are used
  1104. * @param startx the start x position
  1105. * @param starty the start y position
  1106. * @param width the width of the area
  1107. * @param height the height of the area
  1108. */
  1109. protected void drawBackAndBorders(Area area, float startx, float starty,
  1110. float width, float height) {
  1111. BorderProps bpsBefore = (BorderProps) area.getTrait(Trait.BORDER_BEFORE);
  1112. BorderProps bpsAfter = (BorderProps) area.getTrait(Trait.BORDER_AFTER);
  1113. BorderProps bpsStart = (BorderProps) area.getTrait(Trait.BORDER_START);
  1114. BorderProps bpsEnd = (BorderProps) area.getTrait(Trait.BORDER_END);
  1115. // draw background
  1116. Trait.Background back;
  1117. back = (Trait.Background) area.getTrait(Trait.BACKGROUND);
  1118. if (back != null) {
  1119. // Calculate padding rectangle
  1120. float sx = startx;
  1121. float sy = starty;
  1122. float paddRectWidth = width;
  1123. float paddRectHeight = height;
  1124. if (bpsStart != null) {
  1125. sx += bpsStart.width / 1000f;
  1126. paddRectWidth -= bpsStart.width / 1000f;
  1127. }
  1128. if (bpsBefore != null) {
  1129. sy += bpsBefore.width / 1000f;
  1130. paddRectHeight -= bpsBefore.width / 1000f;
  1131. }
  1132. if (bpsEnd != null) {
  1133. paddRectWidth -= bpsEnd.width / 1000f;
  1134. }
  1135. if (bpsAfter != null) {
  1136. paddRectHeight -= bpsAfter.width / 1000f;
  1137. }
  1138. if (back.getColor() != null) {
  1139. updateFillColor(back.getColor());
  1140. fillRect(sx, sy, paddRectWidth, paddRectHeight);
  1141. }
  1142. // background image
  1143. if (back.getImageInfo() != null) {
  1144. ImageSize imageSize = back.getImageInfo().getSize();
  1145. saveGraphicsState();
  1146. clipRect(sx, sy, paddRectWidth, paddRectHeight);
  1147. int horzCount = (int) ((paddRectWidth * 1000 / imageSize.getWidthMpt()) + 1.0f);
  1148. int vertCount = (int) ((paddRectHeight * 1000 / imageSize.getHeightMpt()) + 1.0f);
  1149. if (back.getRepeat() == EN_NOREPEAT) {
  1150. horzCount = 1;
  1151. vertCount = 1;
  1152. } else if (back.getRepeat() == EN_REPEATX) {
  1153. vertCount = 1;
  1154. } else if (back.getRepeat() == EN_REPEATY) {
  1155. horzCount = 1;
  1156. }
  1157. // change from points to millipoints
  1158. sx *= 1000;
  1159. sy *= 1000;
  1160. if (horzCount == 1) {
  1161. sx += back.getHoriz();
  1162. }
  1163. if (vertCount == 1) {
  1164. sy += back.getVertical();
  1165. }
  1166. for (int x = 0; x < horzCount; x++) {
  1167. for (int y = 0; y < vertCount; y++) {
  1168. // place once
  1169. Rectangle2D pos;
  1170. // Image positions are relative to the currentIP/BP
  1171. pos = new Rectangle2D.Float(
  1172. sx - currentIPPosition
  1173. + (x * imageSize.getWidthMpt()),
  1174. sy - currentBPPosition
  1175. + (y * imageSize.getHeightMpt()),
  1176. imageSize.getWidthMpt(),
  1177. imageSize.getHeightMpt());
  1178. drawImage(back.getURL(), pos, null);
  1179. }
  1180. }
  1181. restoreGraphicsState();
  1182. }
  1183. }
  1184. Rectangle2D.Float borderRect = new Rectangle2D.Float(startx, starty, width, height);
  1185. drawBorders(borderRect, bpsBefore, bpsAfter, bpsStart, bpsEnd);
  1186. }
  1187. /**
  1188. * Draws borders.
  1189. * @param borderRect the border rectangle
  1190. * @param bpsBefore the border specification on the before side
  1191. * @param bpsAfter the border specification on the after side
  1192. * @param bpsStart the border specification on the start side
  1193. * @param bpsEnd the border specification on the end side
  1194. */
  1195. protected void drawBorders(Rectangle2D.Float borderRect,
  1196. final BorderProps bpsBefore, final BorderProps bpsAfter,
  1197. final BorderProps bpsStart, final BorderProps bpsEnd) {
  1198. if (bpsBefore == null && bpsAfter == null && bpsStart == null && bpsEnd == null) {
  1199. return; //no borders to paint
  1200. }
  1201. if (qualityBeforeSpeed) {
  1202. drawQualityBorders(borderRect, bpsBefore, bpsAfter, bpsStart, bpsEnd);
  1203. } else {
  1204. drawFastBorders(borderRect, bpsBefore, bpsAfter, bpsStart, bpsEnd);
  1205. }
  1206. }
  1207. /**
  1208. * Draws borders. Borders are drawn as shaded rectangles with no clipping.
  1209. * @param borderRect the border rectangle
  1210. * @param bpsBefore the border specification on the before side
  1211. * @param bpsAfter the border specification on the after side
  1212. * @param bpsStart the border specification on the start side
  1213. * @param bpsEnd the border specification on the end side
  1214. */
  1215. protected void drawFastBorders(Rectangle2D.Float borderRect,
  1216. final BorderProps bpsBefore, final BorderProps bpsAfter,
  1217. final BorderProps bpsStart, final BorderProps bpsEnd) {
  1218. float startx = borderRect.x;
  1219. float starty = borderRect.y;
  1220. float width = borderRect.width;
  1221. float height = borderRect.height;
  1222. if (bpsBefore != null) {
  1223. float borderWidth = bpsBefore.width / 1000f;
  1224. updateFillColor(bpsBefore.color);
  1225. fillRect(startx, starty, width, borderWidth);
  1226. }
  1227. if (bpsAfter != null) {
  1228. float borderWidth = bpsAfter.width / 1000f;
  1229. updateFillColor(bpsAfter.color);
  1230. fillRect(startx, (starty + height - borderWidth),
  1231. width, borderWidth);
  1232. }
  1233. if (bpsStart != null) {
  1234. float borderWidth = bpsStart.width / 1000f;
  1235. updateFillColor(bpsStart.color);
  1236. fillRect(startx, starty, borderWidth, height);
  1237. }
  1238. if (bpsEnd != null) {
  1239. float borderWidth = bpsEnd.width / 1000f;
  1240. updateFillColor(bpsEnd.color);
  1241. fillRect((startx + width - borderWidth), starty, borderWidth, height);
  1242. }
  1243. }
  1244. /**
  1245. * Draws borders. Borders are drawn in-memory and painted as a bitmap.
  1246. * @param borderRect the border rectangle
  1247. * @param bpsBefore the border specification on the before side
  1248. * @param bpsAfter the border specification on the after side
  1249. * @param bpsStart the border specification on the start side
  1250. * @param bpsEnd the border specification on the end side
  1251. */
  1252. protected void drawQualityBorders(Rectangle2D.Float borderRect,
  1253. final BorderProps bpsBefore, final BorderProps bpsAfter,
  1254. final BorderProps bpsStart, final BorderProps bpsEnd) {
  1255. Graphics2DAdapter g2a = getGraphics2DAdapter();
  1256. final Rectangle.Float effBorderRect = new Rectangle2D.Float(
  1257. 0,
  1258. 0,
  1259. borderRect.width,
  1260. borderRect.height);
  1261. final Rectangle paintRect = new Rectangle(
  1262. Math.round(borderRect.x * 1000f),
  1263. Math.round(borderRect.y * 1000f),
  1264. (int)Math.floor(borderRect.width * 1000f) + 1,
  1265. (int)Math.floor(borderRect.height * 1000f) + 1);
  1266. //Add one pixel wide safety margin around the paint area
  1267. int pixelWidth = (int)Math.round(UnitConv.in2mpt(1) / userAgent.getTargetResolution());
  1268. final int xoffset = Math.round(-effBorderRect.x * 1000f) + pixelWidth;
  1269. final int yoffset = pixelWidth;
  1270. paintRect.x += xoffset;
  1271. paintRect.y += yoffset;
  1272. paintRect.width += 2 * pixelWidth;
  1273. paintRect.height += 2 * pixelWidth;
  1274. RendererContext rc = createRendererContext(paintRect.x, paintRect.y,
  1275. paintRect.width, paintRect.height, null);
  1276. Map atts = new java.util.HashMap();
  1277. atts.put(CONV_MODE, "bitmap");
  1278. atts.put(SRC_TRANSPARENCY, "true");
  1279. rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts);
  1280. Graphics2DImagePainter painter = new Graphics2DImagePainter() {
  1281. public void paint(Graphics2D g2d, Rectangle2D area) {
  1282. g2d.translate(xoffset, yoffset);
  1283. g2d.scale(1000, 1000);
  1284. float startx = effBorderRect.x;
  1285. float starty = effBorderRect.y;
  1286. float width = effBorderRect.width;
  1287. float height = effBorderRect.height;
  1288. boolean[] b = new boolean[] {
  1289. (bpsBefore != null), (bpsEnd != null),
  1290. (bpsAfter != null), (bpsStart != null)};
  1291. if (!b[0] && !b[1] && !b[2] && !b[3]) {
  1292. return;
  1293. }
  1294. float[] bw = new float[] {
  1295. (b[0] ? bpsBefore.width / 1000f : 0.0f),
  1296. (b[1] ? bpsEnd.width / 1000f : 0.0f),
  1297. (b[2] ? bpsAfter.width / 1000f : 0.0f),
  1298. (b[3] ? bpsStart.width / 1000f : 0.0f)};
  1299. float[] clipw = new float[] {
  1300. BorderProps.getClippedWidth(bpsBefore) / 1000f,
  1301. BorderProps.getClippedWidth(bpsEnd) / 1000f,
  1302. BorderProps.getClippedWidth(bpsAfter) / 1000f,
  1303. BorderProps.getClippedWidth(bpsStart) / 1000f};
  1304. starty += clipw[0];
  1305. height -= clipw[0];
  1306. height -= clipw[2];
  1307. startx += clipw[3];
  1308. width -= clipw[3];
  1309. width -= clipw[1];
  1310. boolean[] slant = new boolean[] {
  1311. (b[3] && b[0]), (b[0] && b[1]), (b[1] && b[2]), (b[2] && b[3])};
  1312. if (bpsBefore != null) {
  1313. //endTextObject();
  1314. float sx1 = startx;
  1315. float sx2 = (slant[0] ? sx1 + bw[3] - clipw[3] : sx1);
  1316. float ex1 = startx + width;
  1317. float ex2 = (slant[1] ? ex1 - bw[1] + clipw[1] : ex1);
  1318. float outery = starty - clipw[0];
  1319. float clipy = outery + clipw[0];
  1320. float innery = outery + bw[0];
  1321. //saveGraphicsState();
  1322. Graphics2D g = (Graphics2D)g2d.create();
  1323. moveTo(sx1, clipy);
  1324. float sx1a = sx1;
  1325. float ex1a = ex1;
  1326. if (bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
  1327. if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
  1328. sx1a -= clipw[3];
  1329. }
  1330. if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
  1331. ex1a += clipw[1];
  1332. }
  1333. lineTo(sx1a, outery);
  1334. lineTo(ex1a, outery);
  1335. }
  1336. lineTo(ex1, clipy);
  1337. lineTo(ex2, innery);
  1338. lineTo(sx2, innery);
  1339. closePath();
  1340. //clip();
  1341. g.clip(currentPath);
  1342. currentPath = null;
  1343. Rectangle2D.Float lineRect = new Rectangle2D.Float(
  1344. sx1a, outery, ex1a - sx1a, innery - outery);
  1345. Java2DRenderer.drawBorderLine(lineRect, true, true,
  1346. bpsBefore.style, bpsBefore.color, g);
  1347. //restoreGraphicsState();
  1348. }
  1349. if (bpsEnd != null) {
  1350. //endTextObject();
  1351. float sy1 = starty;
  1352. float sy2 = (slant[1] ? sy1 + bw[0] - clipw[0] : sy1);
  1353. float ey1 = starty + height;
  1354. float ey2 = (slant[2] ? ey1 - bw[2] + clipw[2] : ey1);
  1355. float outerx = startx + width + clipw[1];
  1356. float clipx = outerx - clipw[1];
  1357. float innerx = outerx - bw[1];
  1358. //saveGraphicsState();
  1359. Graphics2D g = (Graphics2D)g2d.create();
  1360. moveTo(clipx, sy1);
  1361. float sy1a = sy1;
  1362. float ey1a = ey1;
  1363. if (bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
  1364. if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
  1365. sy1a -= clipw[0];
  1366. }
  1367. if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
  1368. ey1a += clipw[2];
  1369. }
  1370. lineTo(outerx, sy1a);
  1371. lineTo(outerx, ey1a);
  1372. }
  1373. lineTo(clipx, ey1);
  1374. lineTo(innerx, ey2);
  1375. lineTo(innerx, sy2);
  1376. closePath();
  1377. //clip();
  1378. g.setClip(currentPath);
  1379. currentPath = null;
  1380. Rectangle2D.Float lineRect = new Rectangle2D.Float(
  1381. innerx, sy1a, outerx - innerx, ey1a - sy1a);
  1382. Java2DRenderer.drawBorderLine(lineRect, false, false,
  1383. bpsEnd.style, bpsEnd.color, g);
  1384. //restoreGraphicsState();
  1385. }
  1386. if (bpsAfter != null) {
  1387. //endTextObject();
  1388. float sx1 = startx;
  1389. float sx2 = (slant[3] ? sx1 + bw[3] - clipw[3] : sx1);
  1390. float ex1 = startx + width;
  1391. float ex2 = (slant[2] ? ex1 - bw[1] + clipw[1] : ex1);
  1392. float outery = starty + height + clipw[2];
  1393. float clipy = outery - clipw[2];
  1394. float innery = outery - bw[2];
  1395. //saveGraphicsState();
  1396. Graphics2D g = (Graphics2D)g2d.create();
  1397. moveTo(ex1, clipy);
  1398. float sx1a = sx1;
  1399. float ex1a = ex1;
  1400. if (bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
  1401. if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
  1402. sx1a -= clipw[3];
  1403. }
  1404. if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
  1405. ex1a += clipw[1];
  1406. }
  1407. lineTo(ex1a, outery);
  1408. lineTo(sx1a, outery);
  1409. }
  1410. lineTo(sx1, clipy);
  1411. lineTo(sx2, innery);
  1412. lineTo(ex2, innery);
  1413. closePath();
  1414. //clip();
  1415. g.setClip(currentPath);
  1416. currentPath = null;
  1417. Rectangle2D.Float lineRect = new Rectangle2D.Float(
  1418. sx1a, innery, ex1a - sx1a, outery - innery);
  1419. Java2DRenderer.drawBorderLine(lineRect, true, false,
  1420. bpsAfter.style, bpsAfter.color, g);
  1421. //restoreGraphicsState();
  1422. }
  1423. if (bpsStart != null) {
  1424. //endTextObject();
  1425. float sy1 = starty;
  1426. float sy2 = (slant[0] ? sy1 + bw[0] - clipw[0] : sy1);
  1427. float ey1 = sy1 + height;
  1428. float ey2 = (slant[3] ? ey1 - bw[2] + clipw[2] : ey1);
  1429. float outerx = startx - clipw[3];
  1430. float clipx = outerx + clipw[3];
  1431. float innerx = outerx + bw[3];
  1432. //saveGraphicsState();
  1433. Graphics2D g = (Graphics2D)g2d.create();
  1434. moveTo(clipx, ey1);
  1435. float sy1a = sy1;
  1436. float ey1a = ey1;
  1437. if (bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
  1438. if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
  1439. sy1a -= clipw[0];
  1440. }
  1441. if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
  1442. ey1a += clipw[2];
  1443. }
  1444. lineTo(outerx, ey1a);
  1445. lineTo(outerx, sy1a);
  1446. }
  1447. lineTo(clipx, sy1);
  1448. lineTo(innerx, sy2);
  1449. lineTo(innerx, ey2);
  1450. closePath();
  1451. //clip();
  1452. g.setClip(currentPath);
  1453. currentPath = null;
  1454. Rectangle2D.Float lineRect = new Rectangle2D.Float(
  1455. outerx, sy1a, innerx - outerx, ey1a - sy1a);
  1456. Java2DRenderer.drawBorderLine(lineRect, false, false,
  1457. bpsStart.style, bpsStart.color, g);
  1458. //restoreGraphicsState();
  1459. }
  1460. }
  1461. public Dimension getImageSize() {
  1462. return paintRect.getSize();
  1463. }
  1464. };
  1465. try {
  1466. g2a.paintImage(painter, rc,
  1467. paintRect.x - xoffset, paintRect.y, paintRect.width, paintRect.height);
  1468. } catch (IOException ioe) {
  1469. handleIOTrouble(ioe);
  1470. }
  1471. }
  1472. /** {@inheritDoc} */
  1473. public void renderLeader(Leader area) {
  1474. renderInlineAreaBackAndBorders(area);
  1475. saveGraphicsState();
  1476. int style = area.getRuleStyle();
  1477. float startx = (currentIPPosition + area.getBorderAndPaddingWidthStart()) / 1000f;
  1478. float starty = (currentBPPosition + area.getOffset()) / 1000f;
  1479. float endx = (currentIPPosition + area.getBorderAndPaddingWidthStart()
  1480. + area.getIPD()) / 1000f;
  1481. float ruleThickness = area.getRuleThickness() / 1000f;
  1482. Color col = (Color)area.getTrait(Trait.COLOR);
  1483. switch (style) {
  1484. case EN_SOLID:
  1485. case EN_DASHED: //TODO Improve me and following (this is just a quick-fix ATM)
  1486. case EN_DOUBLE:
  1487. case EN_DOTTED:
  1488. case EN_GROOVE:
  1489. case EN_RIDGE:
  1490. updateFillColor(col);
  1491. fillRect(startx, starty, endx - startx, ruleThickness);
  1492. break;
  1493. default:
  1494. throw new UnsupportedOperationException("rule style not supported");
  1495. }
  1496. restoreGraphicsState();
  1497. super.renderLeader(area);
  1498. }
  1499. /**
  1500. * Controls whether all text should be generated as bitmaps or only text for which there's
  1501. * no native font.
  1502. * @param allTextAsBitmaps true if all text should be painted as bitmaps
  1503. */
  1504. public void setAllTextAsBitmaps(boolean allTextAsBitmaps) {
  1505. this.allTextAsBitmaps = allTextAsBitmaps;
  1506. }
  1507. }