01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /* $Id$ */
19:
20: package org.apache.fop.layoutmgr.inline;
21:
22: import org.apache.fop.fo.flow.PageNumberCitationLast;
23: import org.apache.fop.area.PageViewport;
24: import org.apache.fop.area.Resolvable;
25: import org.apache.fop.area.inline.InlineArea;
26: import org.apache.fop.area.inline.UnresolvedPageNumber;
27: import org.apache.fop.area.inline.TextArea;
28: import org.apache.fop.layoutmgr.LayoutContext;
29: import org.apache.fop.layoutmgr.LayoutManager;
30:
31: /**
32: * LayoutManager for the fo:page-number-citation-last formatting object
33: */
34: public class PageNumberCitationLastLayoutManager extends
35: PageNumberCitationLayoutManager {
36:
37: private PageNumberCitationLast fobj;
38:
39: /**
40: * Constructor
41: *
42: * @param node the formatting object that creates this area
43: * @todo better retrieval of font info
44: */
45: public PageNumberCitationLastLayoutManager(
46: PageNumberCitationLast node) {
47: super (node);
48: fobj = node;
49: }
50:
51: /** @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#get(LayoutContext) */
52: public InlineArea get(LayoutContext context) {
53: curArea = getPageNumberCitationLastInlineArea(parentLM);
54: return curArea;
55: }
56:
57: /**
58: * if id can be resolved then simply return a word, otherwise
59: * return a resolvable area
60: */
61: private InlineArea getPageNumberCitationLastInlineArea(
62: LayoutManager parentLM) {
63: TextArea text = null;
64: resolved = false;
65: if (!getPSLM().associateLayoutManagerID(fobj.getRefId())) {
66: text = new UnresolvedPageNumber(fobj.getRefId(), font,
67: UnresolvedPageNumber.LAST);
68: getPSLM().addUnresolvedArea(fobj.getRefId(),
69: (Resolvable) text);
70: String str = "MMM"; // reserve three spaces for page number
71: int width = getStringWidth(str);
72: text.setIPD(width);
73: } else {
74: PageViewport page = getPSLM().getLastPVWithID(
75: fobj.getRefId());
76: String str = page.getPageNumberString();
77: // get page string from parent, build area
78: text = new TextArea();
79: int width = getStringWidth(str);
80: text.addWord(str, 0);
81: text.setIPD(width);
82:
83: resolved = true;
84: }
85:
86: updateTextAreaTraits(text);
87:
88: return text;
89: }
90: }
|