1 package org.apache.maven.doxia.module.rtf;
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 class Font
27 {
28 private int size;
29
30 private FontMetrics metrics;
31
32 Font( int style, int size )
33 throws Exception
34 {
35 this.size = size;
36 metrics = FontMetrics.find( style );
37 }
38
39 int ascent()
40 {
41 return toTwips( metrics.ascent );
42 }
43
44 int descent()
45 {
46 return toTwips( metrics.descent );
47 }
48
49 TextExtents textExtents( String text )
50 {
51 int i, n;
52 int width = 0;
53 int ascent = 0;
54 int descent = 0;
55
56 for ( i = 0, n = text.length(); i < n; ++i )
57 {
58 char c = text.charAt( i );
59 if ( c > 255 )
60 {
61 c = ' ';
62 }
63 FontMetrics.CharMetrics charMetrics = this.metrics.charMetrics[c];
64 width += charMetrics.wx;
65 if ( charMetrics.ury > ascent )
66 {
67 ascent = charMetrics.ury;
68 }
69 if ( charMetrics.lly < descent )
70 {
71 descent = charMetrics.lly;
72 }
73 }
74
75 int height = ascent + Math.abs( descent );
76
77 return new TextExtents( toTwips( width ), toTwips( height ), toTwips( ascent ) );
78 }
79
80 private int toTwips( int length )
81 {
82 return (int) Math.rint( (double) length * size / 50. );
83 }
84
85 static class TextExtents
86 {
87
88 int width;
89
90 int height;
91
92 int ascent;
93
94 TextExtents( int width, int height, int ascent )
95 {
96 this.width = width;
97 this.height = height;
98 this.ascent = ascent;
99 }
100
101 }
102 }