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.

AFPRectanglePainter.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.geom.AffineTransform;
  20. /**
  21. * A painter of rectangles in AFP
  22. */
  23. public class AFPRectanglePainter extends AbstractAFPPainter {
  24. /**
  25. * Main constructor
  26. *
  27. * @param paintingState the AFP painting state
  28. * @param dataStream the AFP datastream
  29. */
  30. public AFPRectanglePainter(AFPPaintingState paintingState, DataStream dataStream) {
  31. super(paintingState, dataStream);
  32. }
  33. /** {@inheritDoc} */
  34. public void paint(PaintingInfo paintInfo) {
  35. RectanglePaintingInfo rectanglePaintInfo = (RectanglePaintingInfo)paintInfo;
  36. int pageWidth = dataStream.getCurrentPage().getWidth();
  37. int pageHeight = dataStream.getCurrentPage().getHeight();
  38. int yNew;
  39. AFPUnitConverter unitConv = paintingState.getUnitConverter();
  40. float width = unitConv.pt2units(rectanglePaintInfo.getWidth());
  41. float height = unitConv.pt2units(rectanglePaintInfo.getHeight());
  42. float x = unitConv.pt2units(rectanglePaintInfo.getX());
  43. float y = unitConv.pt2units(rectanglePaintInfo.getY());
  44. AffineTransform at = paintingState.getData().getTransform();
  45. AFPLineDataInfo lineDataInfo = new AFPLineDataInfo();
  46. lineDataInfo.setColor(paintingState.getColor());
  47. lineDataInfo.setRotation(paintingState.getRotation());
  48. lineDataInfo.setThickness(Math.round(height));
  49. switch (lineDataInfo.getRotation()) {
  50. case 90:
  51. lineDataInfo.setX1(Math.round((float)at.getTranslateY() + x));
  52. yNew = pageWidth - Math.round((float)at.getTranslateX()) + Math.round(y);
  53. lineDataInfo.setY1(yNew);
  54. lineDataInfo.setY2(yNew);
  55. lineDataInfo.setX2(Math.round(width + (float)at.getTranslateY() + x));
  56. break;
  57. case 180:
  58. lineDataInfo.setX1(pageWidth - Math.round((float)at.getTranslateX() - x));
  59. yNew = pageHeight - Math.round((float)at.getTranslateY() - y);
  60. lineDataInfo.setY1(yNew);
  61. lineDataInfo.setY2(yNew);
  62. lineDataInfo.setX2(pageWidth - Math.round((float)at.getTranslateX() - x - width));
  63. break;
  64. case 270:
  65. lineDataInfo.setX1(pageHeight - Math.round((float)at.getTranslateY() - x));
  66. yNew = Math.round((float)at.getTranslateX() + y);
  67. lineDataInfo.setY1(yNew);
  68. lineDataInfo.setY2(yNew);
  69. lineDataInfo.setX2(pageHeight - Math.round((float)at.getTranslateY() - x - width));
  70. break;
  71. case 0:
  72. default:
  73. lineDataInfo.setX1(Math.round((float)at.getTranslateX() + x));
  74. yNew = Math.round((float)at.getTranslateY() + y);
  75. lineDataInfo.setY1(yNew);
  76. lineDataInfo.setY2(yNew);
  77. lineDataInfo.setX2(Math.round((float)at.getTranslateX() + x + width));
  78. break;
  79. }
  80. dataStream.createLine(lineDataInfo);
  81. }
  82. }