View Javadoc

1   package org.apache.maven.doxia.module.rtf;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * @version $Id: FontMetrics.java 1090706 2011-04-09 23:15:28Z hboutemy $
24   */
25  class FontMetrics
26  {
27      boolean fixedPitch;
28  
29      short ascent;
30  
31      short descent;
32  
33      CharMetrics bounds;
34  
35      CharMetrics[] charMetrics;
36  
37      FontMetrics( boolean fixedPitch, int ascent, int descent, CharMetrics bounds, CharMetrics[] metrics )
38      {
39          this.fixedPitch = fixedPitch;
40          this.ascent = (short) ascent;
41          this.descent = (short) descent;
42          this.bounds = bounds;
43          this.charMetrics = metrics;
44      }
45  
46      static FontMetrics find( int style )
47          throws Exception
48      {
49          String s = FontMetrics.class.getName();
50          String packageName = s.substring( 0, s.lastIndexOf( '.' ) );
51  
52          StringBuffer buf = new StringBuffer( packageName + "." );
53  
54          switch ( style )
55          {
56              case RtfSink.STYLE_ROMAN:
57              default:
58                  buf.append( "Serif" );
59                  break;
60              case RtfSink.STYLE_ITALIC:
61                  buf.append( "SerifItalic" );
62                  break;
63              case RtfSink.STYLE_BOLD:
64                  buf.append( "SerifBold" );
65                  break;
66              case RtfSink.STYLE_TYPEWRITER:
67                  buf.append( "Monospace" );
68                  break;
69          }
70  
71          String className = buf.toString();
72          Class<?> classObject = Class.forName( className );
73          return (FontMetrics) classObject.newInstance();
74      }
75  
76      static class CharMetrics
77      {
78  
79          short wx;
80  
81          short wy;
82  
83          short llx;
84  
85          short lly;
86  
87          short urx;
88  
89          short ury;
90  
91          CharMetrics( int wx, int wy, int llx, int lly, int urx, int ury )
92          {
93              this.wx = (short) wx;
94              this.wy = (short) wy;
95              this.llx = (short) llx;
96              this.lly = (short) lly;
97              this.urx = (short) urx;
98              this.ury = (short) ury;
99          }
100 
101     }
102 }