Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

InstreamForeignObject.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.fo.flow;
  19. import java.awt.geom.Point2D;
  20. import org.xml.sax.Locator;
  21. import org.apache.xmlgraphics.util.QName;
  22. import org.apache.fop.apps.FOPException;
  23. import org.apache.fop.datatypes.Length;
  24. import org.apache.fop.events.ResourceEventProducer;
  25. import org.apache.fop.fo.FONode;
  26. import org.apache.fop.fo.ValidationException;
  27. import org.apache.fop.fo.XMLObj;
  28. /**
  29. * Class modelling the fo:instream-foreign-object object.
  30. * This is an atomic inline object that contains XML data.
  31. */
  32. public class InstreamForeignObject extends AbstractGraphics {
  33. // The value of properties relevant for fo:instream-foreign-object.
  34. // All property values contained in AbstractGraphics
  35. // End of property values
  36. //Additional value
  37. private Point2D intrinsicDimensions;
  38. private boolean instrisicSizeDetermined;
  39. private Length intrinsicAlignmentAdjust;
  40. /**
  41. * constructs an instream-foreign-object object (called by Maker).
  42. *
  43. * @param parent the parent formatting object
  44. */
  45. public InstreamForeignObject(FONode parent) {
  46. super(parent);
  47. }
  48. /**
  49. * Make sure content model satisfied, if so then tell the
  50. * FOEventHandler that we are at the end of the flow.
  51. * {@inheritDoc}
  52. */
  53. protected void endOfNode() throws FOPException {
  54. if (firstChild == null) {
  55. missingChildElementError("one (1) non-XSL namespace child");
  56. }
  57. getFOEventHandler().foreignObject(this);
  58. }
  59. /**
  60. * {@inheritDoc}
  61. * XSL Content Model: one (1) non-XSL namespace child
  62. */
  63. protected void validateChildNode(Locator loc, String nsURI, String localName)
  64. throws ValidationException {
  65. if (FO_URI.equals(nsURI)) {
  66. invalidChildError(loc, nsURI, localName);
  67. } else if (firstChild != null) {
  68. tooManyNodesError(loc, new QName(nsURI, null, localName));
  69. }
  70. }
  71. /** {@inheritDoc} */
  72. public String getLocalName() {
  73. return "instream-foreign-object";
  74. }
  75. /** {@inheritDoc} */
  76. public int getNameId() {
  77. return FO_INSTREAM_FOREIGN_OBJECT;
  78. }
  79. /** Preloads the image so the intrinsic size is available. */
  80. private void prepareIntrinsicSize() {
  81. if (!this.instrisicSizeDetermined) {
  82. XMLObj child = (XMLObj) firstChild;
  83. Point2D csize = new Point2D.Float(-1, -1);
  84. intrinsicDimensions = child.getDimension(csize);
  85. if (intrinsicDimensions == null) {
  86. ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
  87. getUserAgent().getEventBroadcaster());
  88. eventProducer.ifoNoIntrinsicSize(this, getLocator());
  89. }
  90. intrinsicAlignmentAdjust = child.getIntrinsicAlignmentAdjust();
  91. this.instrisicSizeDetermined = true;
  92. }
  93. }
  94. /** {@inheritDoc} */
  95. public int getIntrinsicWidth() {
  96. prepareIntrinsicSize();
  97. if (intrinsicDimensions != null) {
  98. return (int)(intrinsicDimensions.getX() * 1000);
  99. } else {
  100. return 0;
  101. }
  102. }
  103. /** {@inheritDoc} */
  104. public int getIntrinsicHeight() {
  105. prepareIntrinsicSize();
  106. if (intrinsicDimensions != null) {
  107. return (int)(intrinsicDimensions.getY() * 1000);
  108. } else {
  109. return 0;
  110. }
  111. }
  112. /** {@inheritDoc} */
  113. public Length getIntrinsicAlignmentAdjust() {
  114. prepareIntrinsicSize();
  115. return intrinsicAlignmentAdjust;
  116. }
  117. /** {@inheritDoc} */
  118. protected void addChildNode(FONode child) throws FOPException {
  119. super.addChildNode(child);
  120. }
  121. /** @return the XMLObj child node of the instream-foreign-object. */
  122. public XMLObj getChildXMLObj() {
  123. return (XMLObj) firstChild;
  124. }
  125. }