KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: PageNumberCitation.java,v 1.19.2.4 2003/04/11 00:24:39 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.datatypes.*;
56 import org.apache.fop.fo.properties.*;
57 import org.apache.fop.layout.*;
58 import org.apache.fop.apps.FOPException;
59
60
61 /**
62  * 6.6.11 fo:page-number-citation
63  *
64  * Common Usage:
65  * The fo:page-number-citation is used to reference the page-number for the page containing the first normal area returned by
66  * the cited formatting object.
67  *
68  * NOTE:
69  * It may be used to provide the page-numbers in the table of contents, cross-references, and index entries.
70  *
71  * Areas:
72  * The fo:page-number-citation formatting object generates and returns a single normal inline-area.
73  * Constraints:
74  *
75  * The cited page-number is the number of the page containing, as a descendant, the first normal area returned by the
76  * formatting object with an id trait matching the ref-id trait of the fo:page-number-citation (the referenced formatting
77  * object).
78  *
79  * The cited page-number string is obtained by converting the cited page-number in accordance with the number to string
80  * conversion properties specified on the ancestor fo:page-sequence of the referenced formatting object.
81  *
82  * The child areas of the generated inline-area are the same as the result of formatting a result-tree fragment consisting of
83  * fo:character flow objects; one for each character in the cited page-number string and with only the "character" property
84  * specified.
85  *
86  * Contents:
87  *
88  * EMPTY
89  *
90  * The following properties apply to this formatting object:
91  *
92  * [7.3 Common Accessibility Properties]
93  * [7.5 Common Aural Properties]
94  * [7.6 Common Border, Padding, and Background Properties]
95  * [7.7 Common Font Properties]
96  * [7.10 Common Margin Properties-Inline]
97  * [7.11.1 "alignment-adjust"]
98  * [7.11.2 "baseline-identifier"]
99  * [7.11.3 "baseline-shift"]
100  * [7.11.5 "dominant-baseline"]
101  * [7.36.2 "id"]
102  * [7.17.4 "keep-with-next"]
103  * [7.17.5 "keep-with-previous"]
104  * [7.14.2 "letter-spacing"]
105  * [7.13.4 "line-height"]
106  * [7.13.5 "line-height-shift-adjustment"]
107  * [7.36.5 "ref-id"]
108  * [7.18.4 "relative-position"]
109  * [7.36.6 "score-spaces"]
110  * [7.14.4 "text-decoration"]
111  * [7.14.5 "text-shadow"]
112  * [7.14.6 "text-transform"]
113  * [7.14.8 "word-spacing"]
114  */

115 public class PageNumberCitation extends FObj {
116
117     public static class Maker extends FObj.Maker {
118         public FObj make(FObj parent, PropertyList propertyList,
119                          String JavaDoc systemId, int line, int column)
120             throws FOPException {
121             return new PageNumberCitation(parent, propertyList,
122                                           systemId, line, column);
123         }
124
125     }
126
127     public static FObj.Maker maker() {
128         return new PageNumberCitation.Maker();
129     }
130
131     float red;
132     float green;
133     float blue;
134     int wrapOption;
135     int whiteSpaceCollapse;
136     Area area;
137     String JavaDoc pageNumber;
138     String JavaDoc refId;
139     String JavaDoc id;
140     TextState ts;
141
142
143     public PageNumberCitation(FObj parent, PropertyList propertyList,
144                               String JavaDoc systemId, int line, int column) {
145         super(parent, propertyList, systemId, line, column);
146     }
147
148     public String JavaDoc getName() {
149         return "fo:page-number-citation";
150     }
151
152     public int layout(Area area) throws FOPException {
153         if (!(area instanceof BlockArea)) {
154             log.warn("page-number-citation outside block area");
155             return Status.OK;
156         }
157
158         IDReferences idReferences = area.getIDReferences();
159         this.area = area;
160         if (this.marker == START) {
161
162             // Common Accessibility Properties
163
AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
164
165             // Common Aural Properties
166
AuralProps mAurProps = propMgr.getAuralProps();
167
168             // Common Border, Padding, and Background Properties
169
BorderAndPadding bap = propMgr.getBorderAndPadding();
170             BackgroundProps bProps = propMgr.getBackgroundProps();
171
172             // Common Font Properties
173
//this.fontState = propMgr.getFontState(area.getFontInfo());
174

175             // Common Margin Properties-Inline
176
MarginInlineProps mProps = propMgr.getMarginInlineProps();
177
178             // Common Relative Position Properties
179
RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
180
181             // this.properties.get("alignment-adjust");
182
// this.properties.get("alignment-baseline");
183
// this.properties.get("baseline-shift");
184
// this.properties.get("dominant-baseline");
185
// this.properties.get("id");
186
// this.properties.get("keep-with-next");
187
// this.properties.get("keep-with-previous");
188
// this.properties.get("letter-spacing");
189
// this.properties.get("line-height");
190
// this.properties.get("line-height-shift-adjustment");
191
// this.properties.get("ref-id");
192
// this.properties.get("score-spaces");
193
// this.properties.get("text-decoration");
194
// this.properties.get("text-shadow");
195
// this.properties.get("text-transform");
196
// this.properties.get("word-spacing");
197

198             ColorType c = this.properties.get("color").getColorType();
199             this.red = c.red();
200             this.green = c.green();
201             this.blue = c.blue();
202
203             this.wrapOption = this.properties.get("wrap-option").getEnum();
204             this.whiteSpaceCollapse =
205                 this.properties.get("white-space-collapse").getEnum();
206
207             this.refId = this.properties.get("ref-id").getString();
208
209             if (this.refId.equals("")) {
210                 throw new FOPException("page-number-citation must contain \"ref-id\"", systemId, line, column);
211             }
212
213             // create id
214
this.id = this.properties.get("id").getString();
215             try {
216                 idReferences.createID(id);
217             }
218             catch(FOPException e) {
219                 if (!e.isLocationSet()) {
220                     e.setLocation(systemId, line, column);
221                 }
222                 throw e;
223             }
224             ts = new TextState();
225
226             this.marker = 0;
227         }
228
229         if (marker == 0) {
230             idReferences.configureID(id, area);
231         }
232
233
234         pageNumber = idReferences.getPageNumber(refId);
235
236         if (pageNumber != null) { // if we already know the page number
237
this.marker =
238                 FOText.addText((BlockArea)area,
239                                propMgr.getFontState(area.getFontInfo()), red,
240                                green, blue, wrapOption, null,
241                                whiteSpaceCollapse, pageNumber.toCharArray(),
242                                0, pageNumber.length(), ts,
243                                VerticalAlign.BASELINE);
244         } else { // add pageNumberCitation to area to be resolved during rendering
245
BlockArea blockArea = (BlockArea)area;
246             LineArea la = blockArea.getCurrentLineArea();
247             if (la == null) {
248                 return Status.AREA_FULL_NONE;
249             }
250             la.changeFont(propMgr.getFontState(area.getFontInfo()));
251             la.changeColor(red, green, blue);
252             la.changeWrapOption(wrapOption);
253             la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
254             /*
255              * la.changeHyphenation(language, country, hyphenate,
256              * hyphenationChar, hyphenationPushCharacterCount,
257              * hyphenationRemainCharacterCount);
258              */

259
260             // blockArea.setupLinkSet(null);
261
la.addPageNumberCitation(refId, null);
262             this.marker = -1;
263         }
264
265
266         if (this.marker == -1) {
267             return Status.OK;
268         } else {
269             return Status.AREA_FULL_NONE;
270         }
271
272     }
273
274 }
275
276
Popular Tags