KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > flow > InstreamForeignObject


1 /*
2  * $Id: InstreamForeignObject.java,v 1.14.2.7 2003/04/11 00:24:38 pietsch Exp $
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
53 // FOP
54
import org.apache.fop.fo.*;
55 import org.apache.fop.fo.properties.*;
56 import org.apache.fop.layout.*;
57 import org.apache.fop.layout.inline.*;
58 import org.apache.fop.layout.BlockArea;
59 import org.apache.fop.apps.FOPException;
60
61 public class InstreamForeignObject extends FObj {
62
63     /**
64      * inner class for making SVG objects.
65      */

66     public static class Maker extends FObj.Maker {
67
68         /**
69          * make an SVG object.
70          *
71          * @param parent the parent formatting object
72          * @param propertyList the explicit properties of this object
73          *
74          * @return the SVG object
75          */

76         public FObj make(FObj parent, PropertyList propertyList,
77                          String JavaDoc systemId, int line, int column)
78             throws FOPException {
79             return new InstreamForeignObject(parent, propertyList,
80                                              systemId, line, column);
81         }
82
83     }
84
85     /**
86      * returns the maker for this object.
87      *
88      * @return the maker for SVG objects
89      */

90     public static FObj.Maker maker() {
91         return new InstreamForeignObject.Maker();
92     }
93
94     int breakBefore;
95     int breakAfter;
96     int scaling;
97     int width;
98     int height;
99     int contwidth;
100     int contheight;
101     boolean wauto;
102     boolean hauto;
103     boolean cwauto;
104     boolean chauto;
105     int spaceBefore;
106     int spaceAfter;
107     int startIndent;
108     int endIndent;
109
110     ForeignObjectArea areaCurrent;
111
112     /**
113      * constructs an instream-foreign-object object (called by Maker).
114      *
115      * @param parent the parent formatting object
116      * @param propertyList the explicit properties of this object
117      */

118     public InstreamForeignObject(FObj parent, PropertyList propertyList,
119                                  String JavaDoc systemId, int line, int column) {
120         super(parent, propertyList, systemId, line, column);
121     }
122
123     public String JavaDoc getName() {
124         return "fo:instream-foreign-object";
125     }
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
136         if (this.marker == BREAK_AFTER) {
137             return Status.OK;
138         }
139
140         if (this.marker == START) {
141
142             // Common Accessibility Properties
143
AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
144         
145             // Common Aural Properties
146
AuralProps mAurProps = propMgr.getAuralProps();
147
148             // Common Border, Padding, and Background Properties
149
BorderAndPadding bap = propMgr.getBorderAndPadding();
150             BackgroundProps bProps = propMgr.getBackgroundProps();
151
152             // Common Margin Properties-Inline
153
MarginInlineProps mProps = propMgr.getMarginInlineProps();
154
155             // Common Relative Position Properties
156
RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
157
158             // this.properties.get("alignment-adjust");
159
// this.properties.get("alignment-baseline");
160
// this.properties.get("baseline-shift");
161
// this.properties.get("block-progression-dimension");
162
// this.properties.get("content-height");
163
// this.properties.get("content-type");
164
// this.properties.get("content-width");
165
// this.properties.get("display-align");
166
// this.properties.get("dominant-baseline");
167
// this.properties.get("height");
168
// this.properties.get("id");
169
// this.properties.get("inline-progression-dimension");
170
// this.properties.get("keep-with-next");
171
// this.properties.get("keep-with-previous");
172
// this.properties.get("line-height");
173
// this.properties.get("line-height-shift-adjustment");
174
// this.properties.get("overflow");
175
// this.properties.get("scaling");
176
// this.properties.get("scaling-method");
177
// this.properties.get("text-align");
178
// this.properties.get("width");
179

180             /* retrieve properties */
181             String JavaDoc id = this.properties.get("id").getString();
182             int align = this.properties.get("text-align").getEnum();
183             int valign = this.properties.get("vertical-align").getEnum();
184             int overflow = this.properties.get("overflow").getEnum();
185
186             this.breakBefore = this.properties.get("break-before").getEnum();
187             this.breakAfter = this.properties.get("break-after").getEnum();
188             this.width = this.properties.get("width").getLength().mvalue();
189             this.height = this.properties.get("height").getLength().mvalue();
190             this.contwidth =
191                 this.properties.get("content-width").getLength().mvalue();
192             this.contheight =
193                 this.properties.get("content-height").getLength().mvalue();
194             this.wauto = this.properties.get("width").getLength().isAuto();
195             this.hauto = this.properties.get("height").getLength().isAuto();
196             this.cwauto =
197                 this.properties.get("content-width").getLength().isAuto();
198             this.chauto =
199                 this.properties.get("content-height").getLength().isAuto();
200
201             this.startIndent =
202                 this.properties.get("start-indent").getLength().mvalue();
203             this.endIndent =
204                 this.properties.get("end-indent").getLength().mvalue();
205             this.spaceBefore =
206                 this.properties.get("space-before.optimum").getLength().mvalue();
207             this.spaceAfter =
208                 this.properties.get("space-after.optimum").getLength().mvalue();
209
210             this.scaling = this.properties.get("scaling").getEnum();
211
212             try {
213                 area.getIDReferences().createID(id);
214             }
215             catch(FOPException e) {
216                 if (!e.isLocationSet()) {
217                     e.setLocation(systemId, line, column);
218                 }
219                 throw e;
220             }
221             if (this.areaCurrent == null) {
222                 this.areaCurrent =
223                     new ForeignObjectArea(propMgr.getFontState(area.getFontInfo()),
224                                           area.getAllocationWidth());
225
226                 this.areaCurrent.start();
227                 areaCurrent.setWidth(this.width);
228                 areaCurrent.setHeight(this.height);
229                 areaCurrent.setContentWidth(this.contwidth);
230                 areaCurrent.setContentHeight(this.contheight);
231                 areaCurrent.setScaling(this.scaling);
232                 areaCurrent.setAlign(align);
233                 areaCurrent.setVerticalAlign(valign);
234                 areaCurrent.setOverflow(overflow);
235                 areaCurrent.setSizeAuto(wauto, hauto);
236                 areaCurrent.setContentSizeAuto(cwauto, chauto);
237
238                 // this means that children can get the fontstate
239
areaCurrent.setPage(area.getPage());
240
241                 int numChildren = this.children.size();
242                 if (numChildren > 1) {
243                     throw new FOPException("Only one child element is allowed in an instream-foreign-object", systemId, line, column);
244                 }
245                 /* layout foreign object */
246                 if (this.children.size() > 0) {
247                     FONode fo = (FONode)children.get(0);
248                     int status;
249                     // currently FONode must be an SVG
250
if (Status.isIncomplete((status =
251                                                  fo.layout(this.areaCurrent)))) {
252                         return status;
253                     }
254
255                     /* finish off the foreign object area */
256                     this.areaCurrent.end();
257                 }
258             }
259
260             this.marker = 0;
261
262             if (breakBefore == BreakBefore.PAGE
263                     || ((spaceBefore + areaCurrent.getEffectiveHeight())
264                         > area.spaceLeft())) {
265                 return Status.FORCE_PAGE_BREAK;
266             }
267
268             if (breakBefore == BreakBefore.ODD_PAGE) {
269                 return Status.FORCE_PAGE_BREAK_ODD;
270             }
271
272             if (breakBefore == BreakBefore.EVEN_PAGE) {
273                 return Status.FORCE_PAGE_BREAK_EVEN;
274             }
275         }
276
277         if (this.areaCurrent == null) {
278             return Status.OK;
279         }
280
281         if (area instanceof BlockArea) {
282             BlockArea ba = (BlockArea)area;
283             LineArea la = ba.getCurrentLineArea();
284             if (la == null) {
285                 return Status.AREA_FULL_NONE;
286             }
287             la.addPending();
288             if (areaCurrent.getEffectiveWidth() > la.getRemainingWidth()) {
289                 la = ba.createNextLineArea();
290                 if (la == null) {
291                     return Status.AREA_FULL_NONE;
292                 }
293             }
294             la.addInlineArea(areaCurrent, this.getLinkSet());
295         } else {
296             area.addChild(areaCurrent);
297             area.increaseHeight(areaCurrent.getEffectiveHeight());
298         }
299
300         if (this.isInTableCell) {
301             startIndent += forcedStartOffset;
302             /*
303              * endIndent = areaCurrent.getEffectiveWidth() - forcedWidth -
304              * forcedStartOffset;
305              */

306         }
307
308         areaCurrent.setStartIndent(startIndent);
309         // areaCurrent.setEndIndent(endIndent);
310

311         /* if there is a space-before */
312         if (spaceBefore != 0) {
313             /* add a display space */
314             // area.addDisplaySpace(spaceBefore);
315
}
316
317         /* add the SVG area to the containing area */
318         // area.addChild(areaCurrent);
319

320         areaCurrent.setPage(area.getPage());
321
322         /* increase the height of the containing area accordingly */
323         // area.increaseHeight(areaCurrent.getEffectiveHeight());
324

325         /* if there is a space-after */
326         if (spaceAfter != 0) {
327             /* add a display space */
328             // area.addDisplaySpace(spaceAfter);
329
}
330
331
332         if (breakAfter == BreakAfter.PAGE) {
333             this.marker = BREAK_AFTER;
334             return Status.FORCE_PAGE_BREAK;
335         }
336
337         if (breakAfter == BreakAfter.ODD_PAGE) {
338             this.marker = BREAK_AFTER;
339             return Status.FORCE_PAGE_BREAK_ODD;
340         }
341
342         if (breakAfter == BreakAfter.EVEN_PAGE) {
343             this.marker = BREAK_AFTER;
344             return Status.FORCE_PAGE_BREAK_EVEN;
345         }
346
347         areaCurrent = null;
348         /* return status */
349         return Status.OK;
350     }
351
352 }
353
354
Popular Tags