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.

InstreamForeignObject.java 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /*
  2. * $Id$
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.fo.flow;
  52. // FOP
  53. import org.apache.fop.fo.FObj;
  54. import org.apache.fop.fo.PropertyList;
  55. import org.apache.fop.fo.Status;
  56. import org.apache.fop.fo.FONode;
  57. import org.apache.fop.fo.properties.BreakBefore;
  58. import org.apache.fop.fo.properties.BreakAfter;
  59. import org.apache.fop.layout.Area;
  60. import org.apache.fop.layout.AccessibilityProps;
  61. import org.apache.fop.layout.AuralProps;
  62. import org.apache.fop.layout.BorderAndPadding;
  63. import org.apache.fop.layout.BackgroundProps;
  64. import org.apache.fop.layout.MarginInlineProps;
  65. import org.apache.fop.layout.RelativePositionProps;
  66. import org.apache.fop.layout.LineArea;
  67. import org.apache.fop.layout.inline.ForeignObjectArea;
  68. import org.apache.fop.layout.BlockArea;
  69. import org.apache.fop.apps.FOPException;
  70. public class InstreamForeignObject extends FObj {
  71. /**
  72. * inner class for making SVG objects.
  73. */
  74. public static class Maker extends FObj.Maker {
  75. /**
  76. * make an SVG object.
  77. *
  78. * @param parent the parent formatting object
  79. * @param propertyList the explicit properties of this object
  80. *
  81. * @return the SVG object
  82. */
  83. public FObj make(FObj parent, PropertyList propertyList,
  84. String systemId, int line, int column)
  85. throws FOPException {
  86. return new InstreamForeignObject(parent, propertyList,
  87. systemId, line, column);
  88. }
  89. }
  90. /**
  91. * returns the maker for this object.
  92. *
  93. * @return the maker for SVG objects
  94. */
  95. public static FObj.Maker maker() {
  96. return new InstreamForeignObject.Maker();
  97. }
  98. int breakBefore;
  99. int breakAfter;
  100. int scaling;
  101. int width;
  102. int height;
  103. int contwidth;
  104. int contheight;
  105. boolean wauto;
  106. boolean hauto;
  107. boolean cwauto;
  108. boolean chauto;
  109. int spaceBefore;
  110. int spaceAfter;
  111. int startIndent;
  112. int endIndent;
  113. ForeignObjectArea areaCurrent;
  114. /**
  115. * constructs an instream-foreign-object object (called by Maker).
  116. *
  117. * @param parent the parent formatting object
  118. * @param propertyList the explicit properties of this object
  119. */
  120. public InstreamForeignObject(FObj parent, PropertyList propertyList,
  121. String systemId, int line, int column) {
  122. super(parent, propertyList, systemId, line, column);
  123. }
  124. public String getName() {
  125. return "fo:instream-foreign-object";
  126. }
  127. /**
  128. * layout this formatting object.
  129. *
  130. * @param area the area to layout the object into
  131. *
  132. * @return the status of the layout
  133. */
  134. public int layout(Area area) throws FOPException {
  135. if (this.marker == BREAK_AFTER) {
  136. return Status.OK;
  137. }
  138. if (this.marker == START) {
  139. // Common Accessibility Properties
  140. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  141. // Common Aural Properties
  142. AuralProps mAurProps = propMgr.getAuralProps();
  143. // Common Border, Padding, and Background Properties
  144. BorderAndPadding bap = propMgr.getBorderAndPadding();
  145. BackgroundProps bProps = propMgr.getBackgroundProps();
  146. // Common Margin Properties-Inline
  147. MarginInlineProps mProps = propMgr.getMarginInlineProps();
  148. // Common Relative Position Properties
  149. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  150. // this.properties.get("alignment-adjust");
  151. // this.properties.get("alignment-baseline");
  152. // this.properties.get("baseline-shift");
  153. // this.properties.get("block-progression-dimension");
  154. // this.properties.get("content-height");
  155. // this.properties.get("content-type");
  156. // this.properties.get("content-width");
  157. // this.properties.get("display-align");
  158. // this.properties.get("dominant-baseline");
  159. // this.properties.get("height");
  160. // this.properties.get("id");
  161. // this.properties.get("inline-progression-dimension");
  162. // this.properties.get("keep-with-next");
  163. // this.properties.get("keep-with-previous");
  164. // this.properties.get("line-height");
  165. // this.properties.get("line-height-shift-adjustment");
  166. // this.properties.get("overflow");
  167. // this.properties.get("scaling");
  168. // this.properties.get("scaling-method");
  169. // this.properties.get("text-align");
  170. // this.properties.get("width");
  171. /* retrieve properties */
  172. String id = this.properties.get("id").getString();
  173. int align = this.properties.get("text-align").getEnum();
  174. int valign = this.properties.get("vertical-align").getEnum();
  175. int overflow = this.properties.get("overflow").getEnum();
  176. this.breakBefore = this.properties.get("break-before").getEnum();
  177. this.breakAfter = this.properties.get("break-after").getEnum();
  178. this.width = this.properties.get("width").getLength().mvalue();
  179. this.height = this.properties.get("height").getLength().mvalue();
  180. this.contwidth =
  181. this.properties.get("content-width").getLength().mvalue();
  182. this.contheight =
  183. this.properties.get("content-height").getLength().mvalue();
  184. this.wauto = this.properties.get("width").getLength().isAuto();
  185. this.hauto = this.properties.get("height").getLength().isAuto();
  186. this.cwauto =
  187. this.properties.get("content-width").getLength().isAuto();
  188. this.chauto =
  189. this.properties.get("content-height").getLength().isAuto();
  190. this.startIndent =
  191. this.properties.get("start-indent").getLength().mvalue();
  192. this.endIndent =
  193. this.properties.get("end-indent").getLength().mvalue();
  194. this.spaceBefore =
  195. this.properties.get("space-before.optimum").getLength().mvalue();
  196. this.spaceAfter =
  197. this.properties.get("space-after.optimum").getLength().mvalue();
  198. this.scaling = this.properties.get("scaling").getEnum();
  199. try {
  200. area.getIDReferences().createID(id);
  201. }
  202. catch(FOPException e) {
  203. if (!e.isLocationSet()) {
  204. e.setLocation(systemId, line, column);
  205. }
  206. throw e;
  207. }
  208. if (this.areaCurrent == null) {
  209. this.areaCurrent =
  210. new ForeignObjectArea(propMgr.getFontState(area.getFontInfo()),
  211. area.getAllocationWidth());
  212. this.areaCurrent.start();
  213. areaCurrent.setWidth(this.width);
  214. areaCurrent.setHeight(this.height);
  215. areaCurrent.setContentWidth(this.contwidth);
  216. areaCurrent.setContentHeight(this.contheight);
  217. areaCurrent.setScaling(this.scaling);
  218. areaCurrent.setAlign(align);
  219. areaCurrent.setVerticalAlign(valign);
  220. areaCurrent.setOverflow(overflow);
  221. areaCurrent.setSizeAuto(wauto, hauto);
  222. areaCurrent.setContentSizeAuto(cwauto, chauto);
  223. // this means that children can get the fontstate
  224. areaCurrent.setPage(area.getPage());
  225. int numChildren = this.children.size();
  226. if (numChildren > 1) {
  227. throw new FOPException("Only one child element is allowed in an instream-foreign-object", systemId, line, column);
  228. }
  229. /* layout foreign object */
  230. if (this.children.size() > 0) {
  231. FONode fo = (FONode)children.get(0);
  232. int status;
  233. // currently FONode must be an SVG
  234. if (Status.isIncomplete((status =
  235. fo.layout(this.areaCurrent)))) {
  236. return status;
  237. }
  238. /* finish off the foreign object area */
  239. this.areaCurrent.end();
  240. }
  241. }
  242. this.marker = 0;
  243. if (breakBefore == BreakBefore.PAGE
  244. || ((spaceBefore + areaCurrent.getEffectiveHeight())
  245. > area.spaceLeft())) {
  246. return Status.FORCE_PAGE_BREAK;
  247. }
  248. if (breakBefore == BreakBefore.ODD_PAGE) {
  249. return Status.FORCE_PAGE_BREAK_ODD;
  250. }
  251. if (breakBefore == BreakBefore.EVEN_PAGE) {
  252. return Status.FORCE_PAGE_BREAK_EVEN;
  253. }
  254. }
  255. if (this.areaCurrent == null) {
  256. return Status.OK;
  257. }
  258. if (area instanceof BlockArea) {
  259. BlockArea ba = (BlockArea)area;
  260. LineArea la = ba.getCurrentLineArea();
  261. if (la == null) {
  262. return Status.AREA_FULL_NONE;
  263. }
  264. la.addPending();
  265. if (areaCurrent.getEffectiveWidth() > la.getRemainingWidth()) {
  266. la = ba.createNextLineArea();
  267. if (la == null) {
  268. return Status.AREA_FULL_NONE;
  269. }
  270. }
  271. la.addInlineArea(areaCurrent, this.getLinkSet());
  272. } else {
  273. area.addChild(areaCurrent);
  274. area.increaseHeight(areaCurrent.getEffectiveHeight());
  275. }
  276. if (this.isInTableCell) {
  277. startIndent += forcedStartOffset;
  278. /*
  279. * endIndent = areaCurrent.getEffectiveWidth() - forcedWidth -
  280. * forcedStartOffset;
  281. */
  282. }
  283. areaCurrent.setStartIndent(startIndent);
  284. // areaCurrent.setEndIndent(endIndent);
  285. /* if there is a space-before */
  286. if (spaceBefore != 0) {
  287. /* add a display space */
  288. // area.addDisplaySpace(spaceBefore);
  289. }
  290. /* add the SVG area to the containing area */
  291. // area.addChild(areaCurrent);
  292. areaCurrent.setPage(area.getPage());
  293. /* increase the height of the containing area accordingly */
  294. // area.increaseHeight(areaCurrent.getEffectiveHeight());
  295. /* if there is a space-after */
  296. if (spaceAfter != 0) {
  297. /* add a display space */
  298. // area.addDisplaySpace(spaceAfter);
  299. }
  300. if (breakAfter == BreakAfter.PAGE) {
  301. this.marker = BREAK_AFTER;
  302. return Status.FORCE_PAGE_BREAK;
  303. }
  304. if (breakAfter == BreakAfter.ODD_PAGE) {
  305. this.marker = BREAK_AFTER;
  306. return Status.FORCE_PAGE_BREAK_ODD;
  307. }
  308. if (breakAfter == BreakAfter.EVEN_PAGE) {
  309. this.marker = BREAK_AFTER;
  310. return Status.FORCE_PAGE_BREAK_EVEN;
  311. }
  312. areaCurrent = null;
  313. /* return status */
  314. return Status.OK;
  315. }
  316. }