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. default:
  51. case 0:
  52. lineDataInfo.setX1 ( Math.round((float)at.getTranslateX() + x) );
  53. yNew = Math.round((float)at.getTranslateY() + y);
  54. lineDataInfo.setY1 ( yNew );
  55. lineDataInfo.setY2 ( yNew );
  56. lineDataInfo.setX2 ( Math.round((float)at.getTranslateX() + x + width) );
  57. break;
  58. case 90:
  59. lineDataInfo.setX1 ( Math.round((float)at.getTranslateY() + x) );
  60. yNew = pageWidth - Math.round((float)at.getTranslateX()) + Math.round(y);
  61. lineDataInfo.setY1 ( yNew );
  62. lineDataInfo.setY2 ( yNew );
  63. lineDataInfo.setX2 ( Math.round(width + (float)at.getTranslateY() + x) );
  64. break;
  65. case 180:
  66. lineDataInfo.setX1 ( pageWidth - Math.round((float)at.getTranslateX() - x) );
  67. yNew = pageHeight - Math.round((float)at.getTranslateY() - y);
  68. lineDataInfo.setY1 ( yNew );
  69. lineDataInfo.setY2 ( yNew );
  70. lineDataInfo.setX2 ( pageWidth - Math.round((float)at.getTranslateX() - x - width) );
  71. break;
  72. case 270:
  73. lineDataInfo.setX1 ( pageHeight - Math.round((float)at.getTranslateY() - x) );
  74. yNew = Math.round((float)at.getTranslateX() + y);
  75. lineDataInfo.setY1 ( yNew );
  76. lineDataInfo.setY2 ( yNew );
  77. lineDataInfo.setX2 ( pageHeight - Math.round((float)at.getTranslateY() - x - width) );
  78. break;
  79. }
  80. dataStream.createLine(lineDataInfo);
  81. }
  82. }