1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* $Id$ */
package org.apache.fop.layoutmgr.inline;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.LinkedList;
import org.apache.fop.area.Area;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.datatypes.LengthBase;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.flow.AbstractGraphics;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.TraitSetter;
/**
* LayoutManager handling the common tasks for the fo:instream-foreign-object
* and fo:external-graphics formatting objects
*/
public abstract class AbstractGraphicsLayoutManager extends LeafNodeLayoutManager {
/** The graphics object this LM deals with */
protected AbstractGraphics fobj;
/**
* Constructor
* @param node the formatting object that creates this area
*/
public AbstractGraphicsLayoutManager(AbstractGraphics node) {
super(node);
fobj = node;
}
/**
* Get the inline area created by this element.
*
* @return the viewport inline area
*/
private Viewport getInlineArea() {
Dimension intrinsicSize = new Dimension(
fobj.getIntrinsicWidth(),
fobj.getIntrinsicHeight());
//TODO Investigate if the line-height property has to be taken into the calculation
//somehow. There was some code here that hints in this direction but it was disabled.
ImageLayout imageLayout = new ImageLayout(fobj, this, intrinsicSize);
Rectangle placement = imageLayout.getPlacement();
CommonBorderPaddingBackground borderProps = fobj.getCommonBorderPaddingBackground();
//Determine extra BPD from borders and padding
int beforeBPD = borderProps.getPadding(CommonBorderPaddingBackground.BEFORE, false, this);
beforeBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, false);
placement.y += beforeBPD;
//Determine extra IPD from borders and padding
int startIPD = borderProps.getPadding(CommonBorderPaddingBackground.START, false, this);
startIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, false);
placement.x += startIPD;
Area viewportArea = getChildArea();
TraitSetter.setProducerID(viewportArea, fobj.getId());
transferForeignAttributes(viewportArea);
Viewport vp = new Viewport(viewportArea);
TraitSetter.setProducerID(vp, fobj.getId());
vp.setIPD(imageLayout.getViewportSize().width);
vp.setBPD(imageLayout.getViewportSize().height);
vp.setContentPosition(placement);
vp.setClip(imageLayout.isClipped());
vp.setOffset(0);
// Common Border, Padding, and Background Properties
TraitSetter.addBorders(vp, fobj.getCommonBorderPaddingBackground()
, false, false, false, false, this);
TraitSetter.addPadding(vp, fobj.getCommonBorderPaddingBackground()
, false, false, false, false, this);
TraitSetter.addBackground(vp, fobj.getCommonBorderPaddingBackground(), this);
return vp;
}
/** {@inheritDoc} */
public LinkedList getNextKnuthElements(LayoutContext context,
int alignment) {
Viewport areaCurrent = getInlineArea();
setCurrentArea(areaCurrent);
return super.getNextKnuthElements(context, alignment);
}
/** {@inheritDoc} */
protected AlignmentContext makeAlignmentContext(LayoutContext context) {
return new AlignmentContext(
get(context).getAllocBPD()
, fobj.getAlignmentAdjust()
, fobj.getAlignmentBaseline()
, fobj.getBaselineShift()
, fobj.getDominantBaseline()
, context.getAlignmentContext()
);
}
/**
* {@inheritDoc}
*/
protected void addId() {
getPSLM().addIDToPage(fobj.getId());
}
/**
* Returns the image of foreign object area to be put into
* the viewport.
* @return the appropriate area
*/
abstract Area getChildArea();
// --------- Property Resolution related functions --------- //
/**
* {@inheritDoc}
*/
public int getBaseLength(int lengthBase, FObj fobj) {
switch (lengthBase) {
case LengthBase.IMAGE_INTRINSIC_WIDTH:
return getIntrinsicWidth();
case LengthBase.IMAGE_INTRINSIC_HEIGHT:
return getIntrinsicHeight();
case LengthBase.ALIGNMENT_ADJUST:
return get(null).getBPD();
default: // Delegate to super class
return super.getBaseLength(lengthBase, fobj);
}
}
/**
* Returns the intrinsic width of the e-g.
* @return the width of the element
*/
protected int getIntrinsicWidth() {
return fobj.getIntrinsicWidth();
}
/**
* Returns the intrinsic height of the e-g.
* @return the height of the element
*/
protected int getIntrinsicHeight() {
return fobj.getIntrinsicHeight();
}
}
|