Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AFPAbstractImageFactory.java 3.0KB

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