1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57: import ;
58: import ;
59: import ;
60:
61: public class XFontPeer2
62: extends ClasspathFontPeer
63: {
64:
65: private class XLineMetrics
66: extends LineMetrics
67: {
68:
69: private Font font;
70:
71:
72:
73: private FontRenderContext fontRenderContext;
74: XLineMetrics(Font f, CharacterIterator ci, int b, int l,
75: FontRenderContext rc)
76: {
77: font = f;
78:
79:
80:
81: fontRenderContext = rc;
82: }
83:
84: public float getAscent()
85: {
86: return fontDelegate.getAscent(font.getSize(), fontRenderContext.getTransform(),
87: fontRenderContext.isAntiAliased(),
88: fontRenderContext.usesFractionalMetrics(), true);
89: }
90:
91: public int getBaselineIndex()
92: {
93:
94: throw new UnsupportedOperationException("Not yet implemented");
95: }
96:
97: public float[] getBaselineOffsets()
98: {
99:
100: throw new UnsupportedOperationException("Not yet implemented");
101: }
102:
103: public float getDescent()
104: {
105: return (int) fontDelegate.getDescent(font.getSize(),
106: new AffineTransform(), false, false,
107: false);
108: }
109:
110: public float getHeight()
111: {
112:
113: throw new UnsupportedOperationException("Not yet implemented");
114: }
115:
116: public float getLeading()
117: {
118:
119: throw new UnsupportedOperationException("Not yet implemented");
120: }
121:
122: public int getNumChars()
123: {
124:
125: throw new UnsupportedOperationException("Not yet implemented");
126: }
127:
128: public float getStrikethroughOffset()
129: {
130: return 0.F;
131: }
132:
133: public float getStrikethroughThickness()
134: {
135: return 0.F;
136: }
137:
138: public float getUnderlineOffset()
139: {
140: return 0.F;
141: }
142:
143: public float getUnderlineThickness()
144: {
145: return 0.F;
146: }
147:
148: }
149:
150: private class XFontMetrics
151: extends FontMetrics
152: {
153: XFontMetrics(Font f)
154: {
155: super(f);
156: }
157:
158: public int getAscent()
159: {
160: return (int) fontDelegate.getAscent(getFont().getSize(),
161: new AffineTransform(), false, false,
162: false);
163: }
164:
165: public int getDescent()
166: {
167: return (int) fontDelegate.getDescent(getFont().getSize(),
168: new AffineTransform(), false, false,
169: false);
170: }
171:
172: public int getHeight()
173: {
174: GlyphVector gv = fontDelegate.createGlyphVector(getFont(),
175: new FontRenderContext(new AffineTransform(), false, false),
176: new StringCharacterIterator("m"));
177: Rectangle2D b = gv.getVisualBounds();
178: return (int) b.getHeight();
179: }
180:
181: public int charWidth(char c)
182: {
183: Point2D advance = new Point2D.Double();
184: fontDelegate.getAdvance(c, getFont().getSize(), new AffineTransform(),
185: false, false, true, advance);
186: return (int) advance.getX();
187: }
188:
189: public int charsWidth(char[] chars, int offs, int len)
190: {
191: return stringWidth(new String(chars, offs, len));
192: }
193:
194: public int stringWidth(String s)
195: {
196: GlyphVector gv = fontDelegate.createGlyphVector(getFont(),
197: new FontRenderContext(new AffineTransform(), false, false),
198: new StringCharacterIterator(s));
199: Rectangle2D b = gv.getVisualBounds();
200: return (int) b.getWidth();
201: }
202: }
203:
204: private FontDelegate fontDelegate;
205:
206: XFontPeer2(String name, int style, int size)
207: {
208: super(name, style, size);
209: try
210: {
211: File fontfile = new File("/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf");
212: FileInputStream in = new FileInputStream(fontfile);
213: FileChannel ch = in.getChannel();
214: ByteBuffer buffer = ch.map(FileChannel.MapMode.READ_ONLY, 0,
215: fontfile.length());
216: fontDelegate = FontFactory.createFonts(buffer)[0];
217: }
218: catch (Exception ex)
219: {
220: ex.printStackTrace();
221: }
222: }
223:
224: XFontPeer2(String name, Map atts)
225: {
226: super(name, atts);
227: try
228: {
229: File fontfile = new File("/usr/share/fonts/truetype/freefont/FreeSans.ttf");
230: FileInputStream in = new FileInputStream(fontfile);
231: FileChannel ch = in.getChannel();
232: ByteBuffer buffer = ch.map(FileChannel.MapMode.READ_ONLY, 0,
233: fontfile.length());
234: fontDelegate = FontFactory.createFonts(buffer)[0];
235: }
236: catch (Exception ex)
237: {
238: ex.printStackTrace();
239: }
240: }
241:
242: public boolean canDisplay(Font font, char c)
243: {
244:
245: throw new UnsupportedOperationException("Not yet implemented");
246: }
247:
248: public int canDisplayUpTo(Font font, CharacterIterator i, int start, int limit)
249: {
250:
251: throw new UnsupportedOperationException("Not yet implemented");
252: }
253:
254: public String getSubFamilyName(Font font, Locale locale)
255: {
256:
257: throw new UnsupportedOperationException("Not yet implemented");
258: }
259:
260: public String getPostScriptName(Font font)
261: {
262:
263: throw new UnsupportedOperationException("Not yet implemented");
264: }
265:
266: public int getNumGlyphs(Font font)
267: {
268:
269: throw new UnsupportedOperationException("Not yet implemented");
270: }
271:
272: public int getMissingGlyphCode(Font font)
273: {
274:
275: throw new UnsupportedOperationException("Not yet implemented");
276: }
277:
278: public byte getBaselineFor(Font font, char c)
279: {
280:
281: throw new UnsupportedOperationException("Not yet implemented");
282: }
283:
284: public String getGlyphName(Font font, int glyphIndex)
285: {
286:
287: throw new UnsupportedOperationException("Not yet implemented");
288: }
289:
290: public GlyphVector createGlyphVector(Font font, FontRenderContext frc, CharacterIterator ci)
291: {
292: return fontDelegate.createGlyphVector(font, frc, ci);
293: }
294:
295: public GlyphVector createGlyphVector(Font font, FontRenderContext ctx, int[] glyphCodes)
296: {
297:
298: throw new UnsupportedOperationException("Not yet implemented");
299: }
300:
301: public GlyphVector layoutGlyphVector(Font font, FontRenderContext frc, char[] chars, int start, int limit, int flags)
302: {
303: StringCharacterIterator i = new StringCharacterIterator(new String(chars), start, limit, 0);
304: return fontDelegate.createGlyphVector(font, frc, i);
305: }
306:
307: public FontMetrics getFontMetrics(Font font)
308: {
309: return new XFontMetrics(font);
310: }
311:
312: public boolean hasUniformLineMetrics(Font font)
313: {
314:
315: throw new UnsupportedOperationException("Not yet implemented");
316: }
317:
318: public LineMetrics getLineMetrics(Font font, CharacterIterator ci, int begin, int limit, FontRenderContext rc)
319: {
320: return new XLineMetrics(font, ci, begin, limit, rc);
321: }
322:
323: public Rectangle2D getMaxCharBounds(Font font, FontRenderContext rc)
324: {
325:
326: throw new UnsupportedOperationException("Not yet implemented");
327: }
328:
329: public Rectangle2D getStringBounds(Font font, CharacterIterator ci, int begin, int limit, FontRenderContext frc)
330: {
331:
332: throw new UnsupportedOperationException("Not yet implemented");
333: }
334:
335: }