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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. AFPUnitConverter unitConv = paintingState.getUnitConverter();
  39. float width = unitConv.pt2units(rectanglePaintInfo.getWidth());
  40. float height = unitConv.pt2units(rectanglePaintInfo.getHeight());
  41. float x = unitConv.pt2units(rectanglePaintInfo.getX());
  42. float y = unitConv.pt2units(rectanglePaintInfo.getY());
  43. AffineTransform at = paintingState.getData().getTransform();
  44. AFPLineDataInfo lineDataInfo = new AFPLineDataInfo();
  45. lineDataInfo.color = paintingState.getColor();
  46. lineDataInfo.rotation = paintingState.getRotation();
  47. lineDataInfo.thickness = Math.round(height);
  48. switch (lineDataInfo.rotation) {
  49. case 0:
  50. lineDataInfo.x1 = Math.round((float)at.getTranslateX() + x);
  51. lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateY() + y);
  52. lineDataInfo.x2 = Math.round((float)at.getTranslateX() + x + width);
  53. break;
  54. case 90:
  55. lineDataInfo.x1 = Math.round((float)at.getTranslateY() + x);
  56. lineDataInfo.y1 = lineDataInfo.y2
  57. = pageWidth - Math.round((float)at.getTranslateX()) + Math.round(y);
  58. lineDataInfo.x2 = Math.round(width + (float)at.getTranslateY() + x);
  59. break;
  60. case 180:
  61. lineDataInfo.x1 = pageWidth - Math.round((float)at.getTranslateX() - x);
  62. lineDataInfo.y1 = lineDataInfo.y2 = pageHeight - Math.round((float)at.getTranslateY() - y);
  63. lineDataInfo.x2 = pageWidth - Math.round((float)at.getTranslateX() - x - width);
  64. break;
  65. case 270:
  66. lineDataInfo.x1 = pageHeight - Math.round((float)at.getTranslateY() - x);
  67. lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateX() + y);
  68. lineDataInfo.x2 = lineDataInfo.x1 + Math.round(width - x);
  69. break;
  70. }
  71. dataStream.createLine(lineDataInfo);
  72. }
  73. }