KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > gvt > flow > BlockInfo


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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 package org.apache.batik.gvt.flow;
19
20 import java.awt.font.FontRenderContext JavaDoc;
21 import java.awt.font.TextAttribute JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.batik.gvt.font.FontFamilyResolver;
27 import org.apache.batik.gvt.font.GVTFont;
28 import org.apache.batik.gvt.font.GVTFontFamily;
29 import org.apache.batik.gvt.font.GVTLineMetrics;
30 import org.apache.batik.gvt.font.UnresolvedFontFamily;
31
32 public class BlockInfo {
33     public final static int ALIGN_START = 0;
34     public final static int ALIGN_MIDDLE = 1;
35     public final static int ALIGN_END = 2;
36     public final static int ALIGN_FULL = 3;
37
38     protected float top;
39     protected float right;
40     protected float bottom;
41     protected float left;
42
43     protected float indent;
44
45     protected int alignment;
46
47     protected float lineHeight;
48     protected List JavaDoc fontFamilyList;
49     protected Map JavaDoc fontAttrs;
50     protected float ascent=-1;
51     protected float descent=-1;
52
53     protected boolean flowRegionBreak;
54
55
56     public BlockInfo(float top, float right, float bottom, float left,
57                      float indent, int alignment, float lineHeight,
58                      List JavaDoc fontFamilyList, Map JavaDoc fontAttrs,
59                      boolean flowRegionBreak) {
60         this.top = top;
61         this.right = right;
62         this.bottom = bottom;
63         this.left = left;
64
65         this.indent = indent;
66
67         this.alignment = alignment;
68
69         this.lineHeight = lineHeight;
70         this.fontFamilyList = fontFamilyList;
71         this.fontAttrs = fontAttrs;
72
73         this.flowRegionBreak = flowRegionBreak;
74     }
75
76     public BlockInfo(float margin, int alignment) {
77         setMargin(margin);
78         this.indent = 0;
79         this.alignment = alignment;
80         this.flowRegionBreak = false;
81     }
82
83     public void setMargin(float margin) {
84         this.top = margin;
85         this.right = margin;
86         this.bottom = margin;
87         this.left = margin;
88     }
89
90     public void initLineInfo(FontRenderContext JavaDoc frc) {
91         float fontSize = 12;
92         Float JavaDoc fsFloat = (Float JavaDoc)fontAttrs.get(TextAttribute.SIZE);
93         if (fsFloat != null)
94             fontSize = fsFloat.floatValue();
95
96         Iterator JavaDoc i = fontFamilyList.iterator();
97         while (i.hasNext()) {
98             GVTFontFamily fontFamily = (GVTFontFamily)i.next();
99             if (fontFamily instanceof UnresolvedFontFamily) {
100                 fontFamily = FontFamilyResolver.resolve
101                     ((UnresolvedFontFamily)fontFamily);
102             }
103             if (fontFamily == null) continue;
104             
105             
106             GVTFont font = fontFamily.deriveFont(fontSize, fontAttrs);
107             GVTLineMetrics lm = font.getLineMetrics("", frc);
108             this.ascent = lm.getAscent();
109             this.descent = lm.getDescent();
110             break;
111         }
112         if (ascent == -1) {
113             ascent = fontSize * .8f;
114             descent = fontSize * .2f;
115         }
116     }
117
118     public float getTopMargin() { return top; }
119     public float getRightMargin() { return right; }
120     public float getBottomMargin() { return bottom; }
121     public float getLeftMargin() { return left; }
122
123     public float getIndent() { return indent; }
124
125     public int getTextAlignment() { return alignment; }
126
127
128     public float getLineHeight() { return lineHeight; }
129     public List JavaDoc getFontFamilyList() { return fontFamilyList; }
130     public Map JavaDoc getFontAttrs() { return fontAttrs; }
131     public float getAscent() { return ascent; }
132     public float getDescent() { return descent; }
133
134     public boolean isFlowRegionBreak() { return flowRegionBreak; }
135
136 }
137
Popular Tags