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 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.fo.flow;
  8. // FOP
  9. import org.apache.fop.fo.*;
  10. import org.apache.fop.fo.properties.*;
  11. import org.apache.fop.area.Area;
  12. import org.apache.fop.area.inline.InlineArea;
  13. import org.apache.fop.area.inline.Viewport;
  14. import org.apache.fop.area.inline.ForeignObject;
  15. import org.apache.fop.layout.FontState;
  16. import org.apache.fop.layout.AccessibilityProps;
  17. import org.apache.fop.layout.AuralProps;
  18. import org.apache.fop.layout.BorderAndPadding;
  19. import org.apache.fop.layout.BackgroundProps;
  20. import org.apache.fop.layout.MarginInlineProps;
  21. import org.apache.fop.layout.RelativePositionProps;
  22. import org.apache.fop.apps.FOPException;
  23. import org.apache.fop.layoutmgr.LayoutManager;
  24. import org.apache.fop.layoutmgr.LeafNodeLayoutManager;
  25. import org.w3c.dom.Document;
  26. public class InstreamForeignObject extends FObj {
  27. int breakBefore;
  28. int breakAfter;
  29. int scaling;
  30. int width;
  31. int height;
  32. int contwidth;
  33. int contheight;
  34. boolean wauto;
  35. boolean hauto;
  36. boolean cwauto;
  37. boolean chauto;
  38. int spaceBefore;
  39. int spaceAfter;
  40. int startIndent;
  41. int endIndent;
  42. Viewport areaCurrent;
  43. /**
  44. * constructs an instream-foreign-object object (called by Maker).
  45. *
  46. * @param parent the parent formatting object
  47. * @param propertyList the explicit properties of this object
  48. */
  49. public InstreamForeignObject(FONode parent) {
  50. super(parent);
  51. }
  52. public LayoutManager getLayoutManager() {
  53. LeafNodeLayoutManager lm = new LeafNodeLayoutManager(this);
  54. lm.setCurrentArea(getInlineArea());
  55. return lm;
  56. }
  57. /**
  58. * Get the inline area created by this element.
  59. */
  60. protected InlineArea getInlineArea() {
  61. if (children == null) {
  62. return areaCurrent;
  63. }
  64. if (this.children.size() != 1) {
  65. // error
  66. }
  67. FONode fo = (FONode)children.get(0);
  68. if(!(fo instanceof XMLObj)) {
  69. // error
  70. }
  71. XMLObj child = (XMLObj)fo;
  72. // Common Accessibility Properties
  73. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  74. // Common Aural Properties
  75. AuralProps mAurProps = propMgr.getAuralProps();
  76. // Common Border, Padding, and Background Properties
  77. BorderAndPadding bap = propMgr.getBorderAndPadding();
  78. BackgroundProps bProps = propMgr.getBackgroundProps();
  79. // Common Margin Properties-Inline
  80. MarginInlineProps mProps = propMgr.getMarginInlineProps();
  81. // Common Relative Position Properties
  82. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  83. // viewport size is determined by block-progression-dimension
  84. // and inline-progression-dimension
  85. // if replaced then use height then ignore block-progression-dimension
  86. //int h = this.properties.get("height").getLength().mvalue();
  87. // use specified line-height then ignore dimension in height direction
  88. boolean hasLH = properties.get("line-height").getSpecifiedValue() != null;
  89. int bpd = 0;
  90. boolean bpdauto = false;
  91. if(hasLH) {
  92. bpd = properties.get("line-height").getLength().mvalue();
  93. } else {
  94. // this property does not apply when the line-height applies
  95. // isn't the block-progression-dimension always in the same
  96. // direction as the line height?
  97. bpdauto = properties.get("block-progression-dimension").getLength().isAuto();
  98. bpd = properties.get("block-progression-dimension").getLength().mvalue();
  99. }
  100. //boolean ipdauto = properties.get("inline-progression-dimension").getLength().isAuto();
  101. //int ipd = properties.get("inline-progression-dimension").getLength().mvalue();
  102. // if auto then use the intrinsic size of the content scaled
  103. // to the content-height and content-width
  104. Document doc = child.getDocument();
  105. String ns = child.getNameSpace();
  106. children = null;
  107. ForeignObject foreign = new ForeignObject(doc, ns);
  108. areaCurrent = new Viewport(foreign);
  109. return areaCurrent;
  110. }
  111. /**
  112. * layout this formatting object.
  113. *
  114. * @param area the area to layout the object into
  115. *
  116. * @return the status of the layout
  117. *
  118. public Status layout(Area area) throws FOPException {
  119. if (this.marker == BREAK_AFTER) {
  120. return new Status(Status.OK);
  121. }
  122. if (this.marker == START) {
  123. // Common Accessibility Properties
  124. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  125. // Common Aural Properties
  126. AuralProps mAurProps = propMgr.getAuralProps();
  127. // Common Border, Padding, and Background Properties
  128. BorderAndPadding bap = propMgr.getBorderAndPadding();
  129. BackgroundProps bProps = propMgr.getBackgroundProps();
  130. // Common Margin Properties-Inline
  131. MarginInlineProps mProps = propMgr.getMarginInlineProps();
  132. // Common Relative Position Properties
  133. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  134. // this.properties.get("alignment-adjust");
  135. // this.properties.get("alignment-baseline");
  136. // this.properties.get("baseline-shift");
  137. // this.properties.get("block-progression-dimension");
  138. // this.properties.get("content-height");
  139. // this.properties.get("content-type");
  140. // this.properties.get("content-width");
  141. // this.properties.get("display-align");
  142. // this.properties.get("dominant-baseline");
  143. // this.properties.get("height");
  144. // this.properties.get("id");
  145. // this.properties.get("inline-progression-dimension");
  146. // this.properties.get("keep-with-next");
  147. // this.properties.get("keep-with-previous");
  148. // this.properties.get("line-height");
  149. // this.properties.get("line-height-shift-adjustment");
  150. // this.properties.get("overflow");
  151. // this.properties.get("scaling");
  152. // this.properties.get("scaling-method");
  153. // this.properties.get("text-align");
  154. // this.properties.get("width");
  155. /* retrieve properties *
  156. String id = this.properties.get("id").getString();
  157. int align = this.properties.get("text-align").getEnum();
  158. int valign = this.properties.get("vertical-align").getEnum();
  159. int overflow = this.properties.get("overflow").getEnum();
  160. this.breakBefore = this.properties.get("break-before").getEnum();
  161. this.breakAfter = this.properties.get("break-after").getEnum();
  162. this.width = this.properties.get("width").getLength().mvalue();
  163. this.height = this.properties.get("height").getLength().mvalue();
  164. this.contwidth =
  165. this.properties.get("content-width").getLength().mvalue();
  166. this.contheight =
  167. this.properties.get("content-height").getLength().mvalue();
  168. this.wauto = this.properties.get("width").getLength().isAuto();
  169. this.hauto = this.properties.get("height").getLength().isAuto();
  170. this.cwauto =
  171. this.properties.get("content-width").getLength().isAuto();
  172. this.chauto =
  173. this.properties.get("content-height").getLength().isAuto();
  174. this.startIndent =
  175. this.properties.get("start-indent").getLength().mvalue();
  176. this.endIndent =
  177. this.properties.get("end-indent").getLength().mvalue();
  178. this.spaceBefore =
  179. this.properties.get("space-before.optimum").getLength().mvalue();
  180. this.spaceAfter =
  181. this.properties.get("space-after.optimum").getLength().mvalue();
  182. this.scaling = this.properties.get("scaling").getEnum();
  183. area.getIDReferences().createID(id);
  184. if (this.areaCurrent == null) {
  185. this.areaCurrent =
  186. new ForeignObjectArea(propMgr.getFontState(area.getFontInfo()),
  187. area.getAllocationWidth());
  188. this.areaCurrent.start();
  189. areaCurrent.setWidth(this.width);
  190. areaCurrent.setHeight(this.height);
  191. areaCurrent.setContentWidth(this.contwidth);
  192. areaCurrent.setContentHeight(this.contheight);
  193. areaCurrent.setScaling(this.scaling);
  194. areaCurrent.setAlign(align);
  195. areaCurrent.setVerticalAlign(valign);
  196. areaCurrent.setOverflow(overflow);
  197. areaCurrent.setSizeAuto(wauto, hauto);
  198. areaCurrent.setContentSizeAuto(cwauto, chauto);
  199. // this means that children can get the fontstate
  200. areaCurrent.setPage(area.getPage());
  201. int numChildren = this.children.size();
  202. if (numChildren > 1) {
  203. throw new FOPException("Only one child element is allowed in an instream-foreign-object");
  204. }
  205. /* layout foreign object *
  206. if (this.children.size() > 0) {
  207. FONode fo = (FONode)children.get(0);
  208. Status status;
  209. if ((status =
  210. fo.layout(this.areaCurrent)).isIncomplete()) {
  211. return status;
  212. }
  213. /* finish off the foreign object area *
  214. this.areaCurrent.end();
  215. }
  216. }
  217. this.marker = 0;
  218. if (breakBefore == BreakBefore.PAGE
  219. || ((spaceBefore + areaCurrent.getEffectiveHeight())
  220. > area.spaceLeft())) {
  221. return new Status(Status.FORCE_PAGE_BREAK);
  222. }
  223. if (breakBefore == BreakBefore.ODD_PAGE) {
  224. return new Status(Status.FORCE_PAGE_BREAK_ODD);
  225. }
  226. if (breakBefore == BreakBefore.EVEN_PAGE) {
  227. return new Status(Status.FORCE_PAGE_BREAK_EVEN);
  228. }
  229. }
  230. if (this.areaCurrent == null) {
  231. return new Status(Status.OK);
  232. }
  233. if (area instanceof BlockArea) {
  234. BlockArea ba = (BlockArea)area;
  235. LineArea la = ba.getCurrentLineArea();
  236. if (la == null) {
  237. return new Status(Status.AREA_FULL_NONE);
  238. }
  239. la.addPending();
  240. if (areaCurrent.getEffectiveWidth() > la.getRemainingWidth()) {
  241. la = ba.createNextLineArea();
  242. if (la == null) {
  243. return new Status(Status.AREA_FULL_NONE);
  244. }
  245. }
  246. la.addInlineArea(areaCurrent);
  247. } else {
  248. area.addChild(areaCurrent);
  249. area.increaseHeight(areaCurrent.getEffectiveHeight());
  250. }
  251. if (this.isInTableCell) {
  252. startIndent += forcedStartOffset;
  253. /*
  254. * endIndent = areaCurrent.getEffectiveWidth() - forcedWidth -
  255. * forcedStartOffset;
  256. *
  257. }
  258. areaCurrent.setStartIndent(startIndent);
  259. // areaCurrent.setEndIndent(endIndent);
  260. /* if there is a space-before *
  261. if (spaceBefore != 0) {
  262. /* add a display space *
  263. // area.addDisplaySpace(spaceBefore);
  264. }
  265. /* add the SVG area to the containing area *
  266. // area.addChild(areaCurrent);
  267. areaCurrent.setPage(area.getPage());
  268. /* increase the height of the containing area accordingly *
  269. // area.increaseHeight(areaCurrent.getEffectiveHeight());
  270. /* if there is a space-after *
  271. if (spaceAfter != 0) {
  272. /* add a display space *
  273. // area.addDisplaySpace(spaceAfter);
  274. }
  275. if (breakAfter == BreakAfter.PAGE) {
  276. this.marker = BREAK_AFTER;
  277. return new Status(Status.FORCE_PAGE_BREAK);
  278. }
  279. if (breakAfter == BreakAfter.ODD_PAGE) {
  280. this.marker = BREAK_AFTER;
  281. return new Status(Status.FORCE_PAGE_BREAK_ODD);
  282. }
  283. if (breakAfter == BreakAfter.EVEN_PAGE) {
  284. this.marker = BREAK_AFTER;
  285. return new Status(Status.FORCE_PAGE_BREAK_EVEN);
  286. }
  287. areaCurrent = null;
  288. /* return status *
  289. return new Status(Status.OK);
  290. }
  291. */
  292. }