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.

AFPAbstractImageFactory.java 3.3KB

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