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.

AFPDataObjectInfoFactory.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.render.afp;
  19. import java.awt.Point;
  20. import java.awt.geom.Rectangle2D;
  21. import java.io.IOException;
  22. import org.apache.fop.afp.AFPDataObjectInfo;
  23. import org.apache.fop.afp.AFPForeignAttributeReader;
  24. import org.apache.fop.afp.AFPObjectAreaInfo;
  25. import org.apache.fop.afp.AFPPaintingState;
  26. import org.apache.fop.afp.AFPResourceInfo;
  27. import org.apache.fop.afp.AFPUnitConverter;
  28. /**
  29. * Abstract image configurator
  30. */
  31. public abstract class AFPDataObjectInfoFactory {
  32. private static final int X = 0;
  33. private static final int Y = 1;
  34. /** the AFP painting state */
  35. protected final AFPPaintingState state;
  36. /** foreign attribute reader */
  37. private final AFPForeignAttributeReader foreignAttributeReader
  38. = new AFPForeignAttributeReader();
  39. /**
  40. * Main constructor
  41. *
  42. * @param state the AFP state
  43. */
  44. public AFPDataObjectInfoFactory(AFPPaintingState state) {
  45. this.state = state;
  46. }
  47. /**
  48. * Configures the data object info
  49. *
  50. * @param rendererImageInfo the afp image info
  51. * @return the data object info
  52. * @throws IOException thrown if an I/O exception of some sort has occurred.
  53. */
  54. public AFPDataObjectInfo create(AFPRendererImageInfo rendererImageInfo) throws IOException {
  55. AFPDataObjectInfo dataObjectInfo = createDataObjectInfo();
  56. // set resource information
  57. AFPResourceInfo resourceInfo
  58. = foreignAttributeReader.getResourceInfo(rendererImageInfo.getForeignAttributes());
  59. resourceInfo.setUri(rendererImageInfo.getURI());
  60. dataObjectInfo.setResourceInfo(resourceInfo);
  61. // set object area
  62. AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo();
  63. Point origin = rendererImageInfo.getOrigin();
  64. Rectangle2D position = rendererImageInfo.getPosition();
  65. float srcX = origin.x + (float)position.getX();
  66. float srcY = origin.y + (float)position.getY();
  67. AFPUnitConverter unitConv = state.getUnitConverter();
  68. int[] coords = unitConv.mpts2units(new float[] {srcX, srcY});
  69. objectAreaInfo.setX(coords[X]);
  70. objectAreaInfo.setY(coords[Y]);
  71. int width = Math.round(unitConv.mpt2units((float)position.getWidth()));
  72. objectAreaInfo.setWidth(width);
  73. int height = Math.round(unitConv.mpt2units((float)position.getHeight()));
  74. objectAreaInfo.setHeight(height);
  75. int resolution = state.getResolution();
  76. objectAreaInfo.setHeightRes(resolution);
  77. objectAreaInfo.setWidthRes(resolution);
  78. objectAreaInfo.setRotation(state.getRotation());
  79. dataObjectInfo.setObjectAreaInfo(objectAreaInfo);
  80. return dataObjectInfo;
  81. }
  82. /**
  83. * Creates the data object information object
  84. *
  85. * @return the data object information object
  86. */
  87. protected abstract AFPDataObjectInfo createDataObjectInfo();
  88. }