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

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