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.

AFPGraphics2D.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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.afp;
  19. import java.awt.AlphaComposite;
  20. import java.awt.BasicStroke;
  21. import java.awt.Color;
  22. import java.awt.Dimension;
  23. import java.awt.Font;
  24. import java.awt.FontMetrics;
  25. import java.awt.Graphics;
  26. import java.awt.GraphicsConfiguration;
  27. import java.awt.Image;
  28. import java.awt.Paint;
  29. import java.awt.Rectangle;
  30. import java.awt.Shape;
  31. import java.awt.Stroke;
  32. import java.awt.geom.AffineTransform;
  33. import java.awt.geom.Ellipse2D;
  34. import java.awt.geom.Line2D;
  35. import java.awt.geom.PathIterator;
  36. import java.awt.geom.Rectangle2D;
  37. import java.awt.image.BufferedImage;
  38. import java.awt.image.ImageObserver;
  39. import java.awt.image.RenderedImage;
  40. import java.awt.image.renderable.RenderableImage;
  41. import java.io.IOException;
  42. import org.apache.commons.logging.Log;
  43. import org.apache.commons.logging.LogFactory;
  44. import org.apache.xmlgraphics.image.loader.ImageInfo;
  45. import org.apache.xmlgraphics.image.loader.ImageSize;
  46. import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
  47. import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
  48. import org.apache.xmlgraphics.java2d.GraphicContext;
  49. import org.apache.xmlgraphics.java2d.GraphicsConfigurationWithTransparency;
  50. import org.apache.xmlgraphics.java2d.StrokingTextHandler;
  51. import org.apache.xmlgraphics.java2d.TextHandler;
  52. import org.apache.xmlgraphics.util.UnitConv;
  53. import org.apache.fop.afp.goca.GraphicsSetLineType;
  54. import org.apache.fop.afp.modca.GraphicsObject;
  55. import org.apache.fop.afp.util.CubicBezierApproximator;
  56. import org.apache.fop.fonts.FontInfo;
  57. import org.apache.fop.render.afp.AFPImageHandlerRenderedImage;
  58. import org.apache.fop.render.afp.AFPRenderingContext;
  59. import org.apache.fop.svg.NativeImageHandler;
  60. /**
  61. * This is a concrete implementation of {@link AbstractGraphics2D} (and
  62. * therefore of {@link java.awt.Graphics2D}) which is able to generate GOCA byte
  63. * codes.
  64. *
  65. * @see org.apache.xmlgraphics.java2d.AbstractGraphics2D
  66. */
  67. public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHandler {
  68. private static final Log LOG = LogFactory.getLog(AFPGraphics2D.class);
  69. private static final int X = 0;
  70. private static final int Y = 1;
  71. private static final int X1 = 0;
  72. private static final int Y1 = 1;
  73. private static final int X2 = 2;
  74. private static final int Y2 = 3;
  75. private static final int X3 = 4;
  76. private static final int Y3 = 5;
  77. /** graphics object */
  78. private GraphicsObject graphicsObj;
  79. /** Fallback text handler */
  80. protected TextHandler fallbackTextHandler = new StrokingTextHandler();
  81. /** Custom text handler */
  82. protected TextHandler customTextHandler;
  83. /** AFP resource manager */
  84. private AFPResourceManager resourceManager;
  85. /** AFP resource info */
  86. private AFPResourceInfo resourceInfo;
  87. /** Current AFP state */
  88. private AFPPaintingState paintingState;
  89. /** AFP graphics configuration */
  90. private final GraphicsConfigurationWithTransparency graphicsConfig = new GraphicsConfigurationWithTransparency();
  91. /** The AFP FontInfo */
  92. private FontInfo fontInfo;
  93. /**
  94. * Main constructor
  95. *
  96. * @param textAsShapes
  97. * if true, all text is turned into shapes in the convertion. No
  98. * text is output.
  99. * @param paintingState painting state
  100. * @param resourceManager resource manager
  101. * @param resourceInfo resource info
  102. * @param fontInfo font info
  103. */
  104. public AFPGraphics2D(boolean textAsShapes, AFPPaintingState paintingState,
  105. AFPResourceManager resourceManager, AFPResourceInfo resourceInfo,
  106. FontInfo fontInfo) {
  107. super(textAsShapes);
  108. setPaintingState(paintingState);
  109. setResourceManager(resourceManager);
  110. setResourceInfo(resourceInfo);
  111. setFontInfo(fontInfo);
  112. }
  113. /**
  114. * Copy Constructor
  115. *
  116. * @param g2d
  117. * a AFPGraphics2D whose properties should be copied
  118. */
  119. public AFPGraphics2D(AFPGraphics2D g2d) {
  120. super(g2d);
  121. this.paintingState = g2d.paintingState;
  122. this.resourceManager = g2d.resourceManager;
  123. this.resourceInfo = g2d.resourceInfo;
  124. this.fontInfo = g2d.fontInfo;
  125. this.graphicsObj = g2d.graphicsObj;
  126. this.fallbackTextHandler = g2d.fallbackTextHandler;
  127. this.customTextHandler = g2d.customTextHandler;
  128. }
  129. /**
  130. * Sets the AFP resource manager
  131. *
  132. * @param resourceManager the AFP resource manager
  133. */
  134. private void setResourceManager(AFPResourceManager resourceManager) {
  135. this.resourceManager = resourceManager;
  136. }
  137. /**
  138. * Returns the AFP resource manager associated with this {@link java.awt.Graphics2D} instance.
  139. * @return the resource manager
  140. */
  141. public AFPResourceManager getResourceManager() {
  142. return this.resourceManager;
  143. }
  144. /**
  145. * Sets the AFP resource info
  146. *
  147. * @param resourceInfo the AFP resource info
  148. */
  149. private void setResourceInfo(AFPResourceInfo resourceInfo) {
  150. this.resourceInfo = resourceInfo;
  151. }
  152. /**
  153. * Returns the GOCA graphics object
  154. *
  155. * @return the GOCA graphics object
  156. */
  157. public GraphicsObject getGraphicsObject() {
  158. return this.graphicsObj;
  159. }
  160. /**
  161. * Sets the GOCA graphics object
  162. *
  163. * @param obj the GOCA graphics object
  164. */
  165. public void setGraphicsObject(GraphicsObject obj) {
  166. this.graphicsObj = obj;
  167. }
  168. /**
  169. * Sets the AFP painting state
  170. *
  171. * @param paintingState the AFP painting state
  172. */
  173. private void setPaintingState(AFPPaintingState paintingState) {
  174. this.paintingState = paintingState;
  175. }
  176. /**
  177. * Returns the AFP painting state
  178. *
  179. * @return the AFP painting state
  180. */
  181. public AFPPaintingState getPaintingState() {
  182. return this.paintingState;
  183. }
  184. /**
  185. * Sets the FontInfo
  186. *
  187. * @param fontInfo the FontInfo
  188. */
  189. private void setFontInfo(FontInfo fontInfo) {
  190. this.fontInfo = fontInfo;
  191. }
  192. /**
  193. * Returns the FontInfo
  194. *
  195. * @return the FontInfo
  196. */
  197. public FontInfo getFontInfo() {
  198. return this.fontInfo;
  199. }
  200. /**
  201. * Sets the GraphicContext
  202. *
  203. * @param gc
  204. * GraphicContext to use
  205. */
  206. public void setGraphicContext(GraphicContext gc) {
  207. this.gc = gc;
  208. }
  209. private int getResolution() {
  210. return this.paintingState.getResolution();
  211. }
  212. /**
  213. * Converts a length value to an absolute value.
  214. * Please note that this only uses the "ScaleY" factor, so this will result
  215. * in a bad value should "ScaleX" and "ScaleY" be different.
  216. * @param length the length
  217. * @return the absolute length
  218. */
  219. public double convertToAbsoluteLength(double length) {
  220. AffineTransform current = getTransform();
  221. double mult = getResolution() / (double)UnitConv.IN2PT;
  222. double factor = -current.getScaleY() / mult;
  223. return length * factor;
  224. }
  225. /**
  226. * Apply the stroke to the AFP graphics object.
  227. * This takes the java stroke and outputs the appropriate settings
  228. * to the AFP graphics object so that the stroke attributes are handled.
  229. *
  230. * @param stroke the java stroke
  231. */
  232. protected void applyStroke(Stroke stroke) {
  233. if (stroke instanceof BasicStroke) {
  234. BasicStroke basicStroke = (BasicStroke) stroke;
  235. // set line width and correct it; NOTE: apparently we need to correct the width so that the
  236. // output looks OK since the default with depends on the output device
  237. float lineWidth = basicStroke.getLineWidth();
  238. float correction = paintingState.getLineWidthCorrection();
  239. graphicsObj.setLineWidth(lineWidth * correction);
  240. //No line join, miter limit and end cap support in GOCA. :-(
  241. // set line type/style (note: this is an approximation at best!)
  242. float[] dashArray = basicStroke.getDashArray();
  243. if (paintingState.setDashArray(dashArray)) {
  244. byte type = GraphicsSetLineType.DEFAULT; // normally SOLID
  245. if (dashArray != null) {
  246. type = GraphicsSetLineType.DOTTED; // default to plain DOTTED if dashed line
  247. // float offset = basicStroke.getDashPhase();
  248. if (dashArray.length == 2) {
  249. if (dashArray[0] < dashArray[1]) {
  250. type = GraphicsSetLineType.SHORT_DASHED;
  251. } else if (dashArray[0] > dashArray[1]) {
  252. type = GraphicsSetLineType.LONG_DASHED;
  253. }
  254. } else if (dashArray.length == 4) {
  255. if (dashArray[0] > dashArray[1]
  256. && dashArray[2] < dashArray[3]) {
  257. type = GraphicsSetLineType.DASH_DOT;
  258. } else if (dashArray[0] < dashArray[1]
  259. && dashArray[2] < dashArray[3]) {
  260. type = GraphicsSetLineType.DOUBLE_DOTTED;
  261. }
  262. } else if (dashArray.length == 6) {
  263. if (dashArray[0] > dashArray[1]
  264. && dashArray[2] < dashArray[3]
  265. && dashArray[4] < dashArray[5]) {
  266. type = GraphicsSetLineType.DASH_DOUBLE_DOTTED;
  267. }
  268. }
  269. }
  270. graphicsObj.setLineType(type);
  271. }
  272. } else {
  273. LOG.warn("Unsupported Stroke: " + stroke.getClass().getName());
  274. }
  275. }
  276. /**
  277. * Apply the java paint to the AFP.
  278. * This takes the java paint sets up the appropriate AFP commands
  279. * for the drawing with that paint.
  280. * Currently this supports the gradients and patterns from batik.
  281. *
  282. * @param paint the paint to convert to AFP
  283. * @param fill true if the paint should be set for filling
  284. * @return true if the paint is handled natively, false if the paint should be rasterized
  285. */
  286. private boolean applyPaint(Paint paint, boolean fill) {
  287. if (paint instanceof Color) {
  288. return true;
  289. }
  290. LOG.debug("NYI: applyPaint() " + paint + " fill=" + fill);
  291. // if (paint instanceof TexturePaint) {
  292. // TexturePaint texturePaint = (TexturePaint)paint;
  293. // BufferedImage bufferedImage = texturePaint.getImage();
  294. // AffineTransform at = paintingState.getTransform();
  295. // int x = (int)Math.round(at.getTranslateX());
  296. // int y = (int)Math.round(at.getTranslateY());
  297. // drawImage(bufferedImage, x, y, null);
  298. // }
  299. return false;
  300. }
  301. /**
  302. * Handle the Batik drawing event
  303. *
  304. * @param shape
  305. * the shape to draw
  306. * @param fill
  307. * true if the shape is to be drawn filled
  308. */
  309. private void doDrawing(Shape shape, boolean fill) {
  310. if (!fill) {
  311. graphicsObj.newSegment();
  312. }
  313. graphicsObj.setColor(gc.getColor());
  314. applyPaint(gc.getPaint(), fill);
  315. if (fill) {
  316. graphicsObj.beginArea();
  317. } else {
  318. applyStroke(gc.getStroke());
  319. }
  320. AffineTransform trans = gc.getTransform();
  321. PathIterator iter = shape.getPathIterator(trans);
  322. if (shape instanceof Line2D) {
  323. double[] dstPts = new double[6];
  324. iter.currentSegment(dstPts);
  325. int[] coords = new int[4];
  326. coords[X1] = (int) Math.round(dstPts[X]);
  327. coords[Y1] = (int) Math.round(dstPts[Y]);
  328. iter.next();
  329. iter.currentSegment(dstPts);
  330. coords[X2] = (int) Math.round(dstPts[X]);
  331. coords[Y2] = (int) Math.round(dstPts[Y]);
  332. graphicsObj.addLine(coords);
  333. } else if (shape instanceof Rectangle2D) {
  334. double[] dstPts = new double[6];
  335. iter.currentSegment(dstPts);
  336. int[] coords = new int[4];
  337. coords[X2] = (int) Math.round(dstPts[X]);
  338. coords[Y2] = (int) Math.round(dstPts[Y]);
  339. iter.next();
  340. iter.next();
  341. iter.currentSegment(dstPts);
  342. coords[X1] = (int) Math.round(dstPts[X]);
  343. coords[Y1] = (int) Math.round(dstPts[Y]);
  344. graphicsObj.addBox(coords);
  345. } else if (shape instanceof Ellipse2D) {
  346. double[] dstPts = new double[6];
  347. Ellipse2D elip = (Ellipse2D) shape;
  348. double scale = trans.getScaleX();
  349. double radiusWidth = elip.getWidth() / 2;
  350. double radiusHeight = elip.getHeight() / 2;
  351. graphicsObj.setArcParams(
  352. (int)Math.round(radiusWidth * scale),
  353. (int)Math.round(radiusHeight * scale),
  354. 0,
  355. 0
  356. );
  357. double[] srcPts = new double[] {elip.getCenterX(), elip.getCenterY()};
  358. trans.transform(srcPts, 0, dstPts, 0, 1);
  359. final int mh = 1;
  360. final int mhr = 0;
  361. graphicsObj.addFullArc(
  362. (int)Math.round(dstPts[X]),
  363. (int)Math.round(dstPts[Y]),
  364. mh,
  365. mhr
  366. );
  367. } else {
  368. processPathIterator(iter);
  369. }
  370. if (fill) {
  371. graphicsObj.endArea();
  372. }
  373. }
  374. /**
  375. * Processes a path iterator generating the necessary painting operations.
  376. *
  377. * @param iter PathIterator to process
  378. */
  379. private void processPathIterator(PathIterator iter) {
  380. double[] dstPts = new double[6];
  381. double[] currentPosition = new double[2];
  382. for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) {
  383. switch (iter.currentSegment(dstPts)) {
  384. case PathIterator.SEG_LINETO:
  385. graphicsObj.addLine(new int[] {
  386. (int)Math.round(dstPts[X]),
  387. (int)Math.round(dstPts[Y])
  388. }, true);
  389. currentPosition = new double[]{dstPts[X], dstPts[Y]};
  390. break;
  391. case PathIterator.SEG_QUADTO:
  392. graphicsObj.addFillet(new int[] {
  393. (int)Math.round(dstPts[X1]),
  394. (int)Math.round(dstPts[Y1]),
  395. (int)Math.round(dstPts[X2]),
  396. (int)Math.round(dstPts[Y2])
  397. }, true);
  398. currentPosition = new double[]{dstPts[X2], dstPts[Y2]};
  399. break;
  400. case PathIterator.SEG_CUBICTO:
  401. double[] cubicCoords = new double[] {currentPosition[0], currentPosition[1],
  402. dstPts[X1], dstPts[Y1], dstPts[X2], dstPts[Y2], dstPts[X3], dstPts[Y3]};
  403. double[][] quadParts = CubicBezierApproximator.fixedMidPointApproximation(
  404. cubicCoords);
  405. if (quadParts.length >= 4) {
  406. for (int segIndex = 0; segIndex < quadParts.length; segIndex++) {
  407. double[] quadPts = quadParts[segIndex];
  408. if (quadPts != null && quadPts.length == 4) {
  409. graphicsObj.addFillet(new int[]{
  410. (int) Math.round(quadPts[X1]),
  411. (int) Math.round(quadPts[Y1]),
  412. (int) Math.round(quadPts[X2]),
  413. (int) Math.round(quadPts[Y2])
  414. }, true);
  415. currentPosition = new double[]{quadPts[X2], quadPts[Y2]};
  416. }
  417. }
  418. }
  419. break;
  420. case PathIterator.SEG_MOVETO:
  421. openingCoords = new int[] {
  422. (int)Math.round(dstPts[X]),
  423. (int)Math.round(dstPts[Y])
  424. };
  425. currentPosition = new double[]{dstPts[X], dstPts[Y]};
  426. graphicsObj.setCurrentPosition(openingCoords);
  427. break;
  428. case PathIterator.SEG_CLOSE:
  429. graphicsObj.addLine(openingCoords, true);
  430. currentPosition = new double[]{openingCoords[0], openingCoords[1]};
  431. break;
  432. default:
  433. LOG.debug("Unrecognised path iterator type");
  434. break;
  435. }
  436. }
  437. }
  438. /** {@inheritDoc} */
  439. @Override
  440. public void draw(Shape shape) {
  441. LOG.debug("draw() shape=" + shape);
  442. doDrawing(shape, false);
  443. }
  444. /** {@inheritDoc} */
  445. @Override
  446. public void fill(Shape shape) {
  447. LOG.debug("fill() shape=" + shape);
  448. doDrawing(shape, true);
  449. }
  450. /**
  451. * Central handler for IOExceptions for this class.
  452. *
  453. * @param ioe
  454. * IOException to handle
  455. */
  456. public void handleIOException(IOException ioe) {
  457. // TODO Surely, there's a better way to do this.
  458. LOG.error(ioe.getMessage());
  459. ioe.printStackTrace();
  460. }
  461. /** {@inheritDoc} */
  462. @Override
  463. public void drawString(String str, float x, float y) {
  464. try {
  465. if (customTextHandler != null && !textAsShapes) {
  466. customTextHandler.drawString(this, str, x, y);
  467. } else {
  468. fallbackTextHandler.drawString(this, str, x, y);
  469. }
  470. } catch (IOException ioe) {
  471. handleIOException(ioe);
  472. }
  473. }
  474. /** {@inheritDoc} */
  475. @Override
  476. public GraphicsConfiguration getDeviceConfiguration() {
  477. return graphicsConfig;
  478. }
  479. /** {@inheritDoc} */
  480. @Override
  481. public Graphics create() {
  482. return new AFPGraphics2D(this);
  483. }
  484. /** {@inheritDoc} */
  485. @Override
  486. public void dispose() {
  487. this.graphicsObj = null;
  488. }
  489. /** {@inheritDoc} */
  490. @Override
  491. public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
  492. return drawImage(img, x, y, img.getWidth(observer), img.getHeight(observer), observer);
  493. }
  494. private BufferedImage buildBufferedImage(Dimension size) {
  495. return new BufferedImage(size.width, size.height,
  496. BufferedImage.TYPE_INT_ARGB);
  497. }
  498. /**
  499. * Draws an AWT image into a BufferedImage using an AWT Graphics2D implementation
  500. *
  501. * @param img the AWT image
  502. * @param bufferedImage the AWT buffered image
  503. * @param width the image width
  504. * @param height the image height
  505. * @param observer the image observer
  506. * @return true if the image was drawn
  507. */
  508. private boolean drawBufferedImage(Image img, BufferedImage bufferedImage,
  509. int width, int height, ImageObserver observer) {
  510. java.awt.Graphics2D g2d = bufferedImage.createGraphics();
  511. try {
  512. g2d.setComposite(AlphaComposite.SrcOver);
  513. Color color = new Color(1, 1, 1, 0);
  514. g2d.setBackground(color);
  515. g2d.setPaint(color);
  516. g2d.fillRect(0, 0, width, height);
  517. int imageWidth = bufferedImage.getWidth();
  518. int imageHeight = bufferedImage.getHeight();
  519. Rectangle clipRect = new Rectangle(0, 0, imageWidth, imageHeight);
  520. g2d.clip(clipRect);
  521. g2d.setComposite(gc.getComposite());
  522. return g2d.drawImage(img, 0, 0, imageWidth, imageHeight, observer);
  523. } finally {
  524. g2d.dispose(); //drawn so dispose immediately to free system resource
  525. }
  526. }
  527. /** {@inheritDoc} */
  528. @Override
  529. public boolean drawImage(Image img, int x, int y, int width, int height,
  530. ImageObserver observer) {
  531. // draw with AWT Graphics2D
  532. Dimension imageSize = new Dimension(width, height);
  533. BufferedImage bufferedImage = buildBufferedImage(imageSize);
  534. boolean drawn = drawBufferedImage(img, bufferedImage, width, height, observer);
  535. if (drawn) {
  536. drawRenderedImage(bufferedImage, new AffineTransform());
  537. }
  538. return false;
  539. }
  540. /** {@inheritDoc} */
  541. @Override
  542. public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
  543. int imgWidth = img.getWidth();
  544. int imgHeight = img.getHeight();
  545. AffineTransform gat = gc.getTransform();
  546. int graphicsObjectHeight
  547. = graphicsObj.getObjectEnvironmentGroup().getObjectAreaDescriptor().getHeight();
  548. double toMillipointFactor = UnitConv.IN2PT * 1000 / (double)paintingState.getResolution();
  549. double x = gat.getTranslateX();
  550. double y = -(gat.getTranslateY() - graphicsObjectHeight);
  551. x = toMillipointFactor * x;
  552. y = toMillipointFactor * y;
  553. double w = toMillipointFactor * imgWidth * gat.getScaleX();
  554. double h = toMillipointFactor * imgHeight * -gat.getScaleY();
  555. AFPImageHandlerRenderedImage handler = new AFPImageHandlerRenderedImage();
  556. ImageInfo imageInfo = new ImageInfo(null, null);
  557. imageInfo.setSize(new ImageSize(
  558. img.getWidth(), img.getHeight(), paintingState.getResolution()));
  559. imageInfo.getSize().calcSizeFromPixels();
  560. ImageRendered red = new ImageRendered(imageInfo, img, null);
  561. Rectangle targetPos = new Rectangle(
  562. (int)Math.round(x),
  563. (int)Math.round(y),
  564. (int)Math.round(w),
  565. (int)Math.round(h));
  566. AFPRenderingContext context = new AFPRenderingContext(null,
  567. resourceManager, paintingState, fontInfo, null);
  568. try {
  569. handler.handleImage(context, red, targetPos);
  570. } catch (IOException ioe) {
  571. handleIOException(ioe);
  572. }
  573. }
  574. /**
  575. * Sets a custom TextHandler implementation that is responsible for painting
  576. * text. The default TextHandler paints all text as shapes. A custom
  577. * implementation can implement text painting using text painting operators.
  578. *
  579. * @param handler
  580. * the custom TextHandler implementation
  581. */
  582. public void setCustomTextHandler(TextHandler handler) {
  583. this.customTextHandler = handler;
  584. }
  585. /** {@inheritDoc} */
  586. @Override
  587. public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
  588. LOG.debug("drawRenderableImage() NYI: img=" + img + ", xform=" + xform);
  589. }
  590. /** {@inheritDoc} */
  591. @Override
  592. public FontMetrics getFontMetrics(Font f) {
  593. LOG.debug("getFontMetrics() NYI: f=" + f);
  594. return null;
  595. }
  596. /** {@inheritDoc} */
  597. @Override
  598. public void setXORMode(Color col) {
  599. LOG.debug("setXORMode() NYI: col=" + col);
  600. }
  601. /** {@inheritDoc} */
  602. public void addNativeImage(org.apache.xmlgraphics.image.loader.Image image,
  603. float x, float y, float width, float height) {
  604. LOG.debug("NYI: addNativeImage() " + "image=" + image
  605. + ",x=" + x + ",y=" + y + ",width=" + width + ",height=" + height);
  606. }
  607. /** {@inheritDoc} */
  608. @Override
  609. public void copyArea(int x, int y, int width, int height, int dx, int dy) {
  610. LOG.debug("copyArea() NYI: ");
  611. }
  612. }