Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

InstreamForeignObject.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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.datatypes.Length;
  12. import org.apache.fop.area.Area;
  13. import org.apache.fop.area.inline.InlineArea;
  14. import org.apache.fop.area.inline.Viewport;
  15. import org.apache.fop.area.inline.ForeignObject;
  16. import org.apache.fop.layout.FontState;
  17. import org.apache.fop.layout.AccessibilityProps;
  18. import org.apache.fop.layout.AuralProps;
  19. import org.apache.fop.layout.BorderAndPadding;
  20. import org.apache.fop.layout.BackgroundProps;
  21. import org.apache.fop.layout.MarginInlineProps;
  22. import org.apache.fop.layout.RelativePositionProps;
  23. import org.apache.fop.apps.FOPException;
  24. import org.apache.fop.layoutmgr.LayoutManager;
  25. import org.apache.fop.layoutmgr.LeafNodeLayoutManager;
  26. import org.apache.fop.layoutmgr.LayoutInfo;
  27. import org.w3c.dom.Document;
  28. import java.awt.geom.Point2D;
  29. import java.awt.geom.Rectangle2D;
  30. import java.util.List;
  31. public class InstreamForeignObject extends FObj {
  32. int breakBefore;
  33. int breakAfter;
  34. int spaceBefore;
  35. int spaceAfter;
  36. int startIndent;
  37. int endIndent;
  38. Viewport areaCurrent;
  39. /**
  40. * constructs an instream-foreign-object object (called by Maker).
  41. *
  42. * @param parent the parent formatting object
  43. * @param propertyList the explicit properties of this object
  44. */
  45. public InstreamForeignObject(FONode parent) {
  46. super(parent);
  47. }
  48. public void addLayoutManager(List list) {
  49. LeafNodeLayoutManager lm = new LeafNodeLayoutManager(this);
  50. lm.setCurrentArea(getInlineArea());
  51. list.add(lm);
  52. }
  53. /**
  54. * Get the inline area created by this element.
  55. */
  56. protected InlineArea getInlineArea() {
  57. if (children == null) {
  58. return areaCurrent;
  59. }
  60. if (this.children.size() != 1) {
  61. // error
  62. return null;
  63. }
  64. FONode fo = (FONode)children.get(0);
  65. if(!(fo instanceof XMLObj)) {
  66. // error
  67. return null;
  68. }
  69. XMLObj child = (XMLObj)fo;
  70. // Common Accessibility Properties
  71. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  72. // Common Aural Properties
  73. AuralProps mAurProps = propMgr.getAuralProps();
  74. // Common Border, Padding, and Background Properties
  75. BorderAndPadding bap = propMgr.getBorderAndPadding();
  76. BackgroundProps bProps = propMgr.getBackgroundProps();
  77. // Common Margin Properties-Inline
  78. MarginInlineProps mProps = propMgr.getMarginInlineProps();
  79. // Common Relative Position Properties
  80. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  81. // viewport size is determined by block-progression-dimension
  82. // and inline-progression-dimension
  83. // if replaced then use height then ignore block-progression-dimension
  84. //int h = this.properties.get("height").getLength().mvalue();
  85. // use specified line-height then ignore dimension in height direction
  86. boolean hasLH = false;//properties.get("line-height").getSpecifiedValue() != null;
  87. Length len;
  88. int bpd = -1;
  89. int ipd = -1;
  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. len = properties.get("block-progression-dimension.optimum").getLength();
  98. if(!len.isAuto()) {
  99. bpd = len.mvalue();
  100. } else {
  101. len = properties.get("height").getLength();
  102. if(!len.isAuto()) {
  103. bpd = len.mvalue();
  104. }
  105. }
  106. }
  107. len = properties.get("inline-progression-dimension.optimum").getLength();
  108. if(!len.isAuto()) {
  109. ipd = len.mvalue();
  110. } else {
  111. len = properties.get("width").getLength();
  112. if(!len.isAuto()) {
  113. ipd = len.mvalue();
  114. }
  115. }
  116. // if auto then use the intrinsic size of the content scaled
  117. // to the content-height and content-width
  118. int cwidth = -1;
  119. int cheight = -1;
  120. len = properties.get("content-width").getLength();
  121. if(!len.isAuto()) {
  122. /*if(len.scaleToFit()) {
  123. if(ipd != -1) {
  124. cwidth = ipd;
  125. }
  126. } else {*/
  127. cwidth = len.mvalue();
  128. }
  129. len = properties.get("content-height").getLength();
  130. if(!len.isAuto()) {
  131. /*if(len.scaleToFit()) {
  132. if(bpd != -1) {
  133. cwidth = bpd;
  134. }
  135. } else {*/
  136. cheight = len.mvalue();
  137. }
  138. Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f, cheight == -1 ? -1 : cheight / 1000f);
  139. Point2D size = child.getDimension(csize);
  140. if(size == null) {
  141. // error
  142. return null;
  143. }
  144. if(cwidth == -1) {
  145. cwidth = (int)size.getX() * 1000;
  146. }
  147. if(cheight == -1) {
  148. cheight = (int)size.getY() * 1000;
  149. }
  150. int scaling = properties.get("scaling").getEnum();
  151. if(scaling == Scaling.UNIFORM) {
  152. // adjust the larger
  153. double rat1 = cwidth / (size.getX() * 1000f);
  154. double rat2 = cheight / (size.getY() * 1000f);
  155. if(rat1 < rat2) {
  156. // reduce cheight
  157. cheight = (int)(rat1 * size.getY() * 1000);
  158. } else {
  159. cwidth = (int)(rat2 * size.getX() * 1000);
  160. }
  161. }
  162. if(ipd == -1) {
  163. ipd = cwidth;
  164. }
  165. if(bpd == -1) {
  166. bpd = cheight;
  167. }
  168. boolean clip = false;
  169. if(cwidth > ipd || cheight > bpd) {
  170. int overflow = properties.get("overflow").getEnum();
  171. if(overflow == Overflow.HIDDEN) {
  172. clip = true;
  173. } else if(overflow == Overflow.ERROR_IF_OVERFLOW) {
  174. getLogger().error("Instream foreign object overflows the viewport");
  175. clip = true;
  176. }
  177. }
  178. int xoffset = 0;
  179. int yoffset = 0;
  180. int da = properties.get("display-align").getEnum();
  181. switch(da) {
  182. case DisplayAlign.BEFORE:
  183. break;
  184. case DisplayAlign.AFTER:
  185. yoffset = bpd - cheight;
  186. break;
  187. case DisplayAlign.CENTER:
  188. yoffset = (bpd - cheight) / 2;
  189. break;
  190. case DisplayAlign.AUTO:
  191. default:
  192. break;
  193. }
  194. int ta = properties.get("text-align").getEnum();
  195. switch(ta) {
  196. case TextAlign.CENTER:
  197. xoffset = (ipd - cwidth) / 2;
  198. break;
  199. case TextAlign.END:
  200. xoffset = ipd - cwidth;
  201. break;
  202. case TextAlign.START:
  203. break;
  204. case TextAlign.JUSTIFY:
  205. default:
  206. break;
  207. }
  208. Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight);
  209. Document doc = child.getDocument();
  210. String ns = child.getDocumentNamespace();
  211. children = null;
  212. ForeignObject foreign = new ForeignObject(doc, ns);
  213. areaCurrent = new Viewport(foreign);
  214. areaCurrent.setWidth(ipd);
  215. areaCurrent.setHeight(bpd);
  216. areaCurrent.setContentPosition(placement);
  217. areaCurrent.setClip(clip);
  218. areaCurrent.setOffset(0);
  219. areaCurrent.info = new LayoutInfo();
  220. areaCurrent.info.alignment = properties.get("vertical-align").getEnum();
  221. areaCurrent.info.lead = areaCurrent.getHeight();
  222. return areaCurrent;
  223. }
  224. public boolean generatesInlineAreas() {
  225. return true;
  226. }
  227. /*
  228. // Common Accessibility Properties
  229. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  230. // Common Aural Properties
  231. AuralProps mAurProps = propMgr.getAuralProps();
  232. // Common Border, Padding, and Background Properties
  233. BorderAndPadding bap = propMgr.getBorderAndPadding();
  234. BackgroundProps bProps = propMgr.getBackgroundProps();
  235. // Common Margin Properties-Inline
  236. MarginInlineProps mProps = propMgr.getMarginInlineProps();
  237. // Common Relative Position Properties
  238. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  239. // this.properties.get("alignment-adjust");
  240. // this.properties.get("alignment-baseline");
  241. // this.properties.get("baseline-shift");
  242. // this.properties.get("block-progression-dimension");
  243. // this.properties.get("content-height");
  244. // this.properties.get("content-type");
  245. // this.properties.get("content-width");
  246. // this.properties.get("display-align");
  247. // this.properties.get("dominant-baseline");
  248. // this.properties.get("height");
  249. setupID();
  250. // this.properties.get("inline-progression-dimension");
  251. // this.properties.get("keep-with-next");
  252. // this.properties.get("keep-with-previous");
  253. // this.properties.get("line-height");
  254. // this.properties.get("line-height-shift-adjustment");
  255. // this.properties.get("overflow");
  256. // this.properties.get("scaling");
  257. // this.properties.get("scaling-method");
  258. // this.properties.get("text-align");
  259. // this.properties.get("width");
  260. /* retrieve properties *
  261. int align = this.properties.get("text-align").getEnum();
  262. int valign = this.properties.get("vertical-align").getEnum();
  263. int overflow = this.properties.get("overflow").getEnum();
  264. this.breakBefore = this.properties.get("break-before").getEnum();
  265. this.breakAfter = this.properties.get("break-after").getEnum();
  266. this.width = this.properties.get("width").getLength().mvalue();
  267. this.height = this.properties.get("height").getLength().mvalue();
  268. this.contwidth =
  269. this.properties.get("content-width").getLength().mvalue();
  270. this.contheight =
  271. this.properties.get("content-height").getLength().mvalue();
  272. this.wauto = this.properties.get("width").getLength().isAuto();
  273. this.hauto = this.properties.get("height").getLength().isAuto();
  274. this.cwauto =
  275. this.properties.get("content-width").getLength().isAuto();
  276. this.chauto =
  277. this.properties.get("content-height").getLength().isAuto();
  278. this.startIndent =
  279. this.properties.get("start-indent").getLength().mvalue();
  280. this.endIndent =
  281. this.properties.get("end-indent").getLength().mvalue();
  282. this.spaceBefore =
  283. this.properties.get("space-before.optimum").getLength().mvalue();
  284. this.spaceAfter =
  285. this.properties.get("space-after.optimum").getLength().mvalue();
  286. this.scaling = this.properties.get("scaling").getEnum();
  287. */
  288. }