~ubuntu-branches/ubuntu/raring/libfonts-java/raring

« back to all changes in this revision

Viewing changes to source/org/pentaho/reporting/libraries/fonts/truetype/TrueTypeFontMetrics.java

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2011-12-29 23:12:17 UTC
  • mfrom: (1.1.3) (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20111229231217-f0tkh1n7f86opmn8
Tags: 1.1.6.dfsg-3
add missing build-dep on ant-optional... (closes: #652799) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program is free software; you can redistribute it and/or modify it under the
 
3
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 
4
 * Foundation.
 
5
 *
 
6
 * You should have received a copy of the GNU Lesser General Public License along with this
 
7
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 
8
 * or from the Free Software Foundation, Inc.,
 
9
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 
12
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
13
 * See the GNU Lesser General Public License for more details.
 
14
 *
 
15
 * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.  All rights reserved.
 
16
 */
 
17
 
 
18
package org.pentaho.reporting.libraries.fonts.truetype;
 
19
 
 
20
import org.pentaho.reporting.libraries.fonts.registry.BaselineInfo;
 
21
import org.pentaho.reporting.libraries.fonts.registry.FontMetrics;
 
22
import org.pentaho.reporting.libraries.fonts.tools.StrictGeomUtility;
 
23
 
 
24
 
 
25
/**
 
26
 * Creation-Date: 15.12.2005, 12:01:13
 
27
 *
 
28
 * @author Thomas Morgner
 
29
 */
 
30
public class TrueTypeFontMetrics implements FontMetrics
 
31
{
 
32
  private ScalableTrueTypeFontMetrics fontMetrics;
 
33
  private double fontSize;
 
34
 
 
35
  public TrueTypeFontMetrics(final ScalableTrueTypeFontMetrics fontMetrics,
 
36
                             final double fontSize)
 
37
  {
 
38
    if (fontMetrics == null)
 
39
    {
 
40
      throw new NullPointerException("The font must not be null");
 
41
    }
 
42
    this.fontMetrics = fontMetrics;
 
43
    this.fontSize = fontSize;
 
44
  }
 
45
 
 
46
  /**
 
47
   * Is it guaranteed that the font always returns the same baseline info objct?
 
48
   *
 
49
   * @return true, if the baseline info in question is always the same, false otherwise.
 
50
   */
 
51
  public boolean isUniformFontMetrics()
 
52
  {
 
53
    return true;
 
54
  }
 
55
 
 
56
  /**
 
57
   * From the baseline to the
 
58
   *
 
59
   * @return
 
60
   */
 
61
  public long getAscent()
 
62
  {
 
63
    return (long) (fontSize * fontMetrics.getAscent());
 
64
  }
 
65
 
 
66
  public long getDescent()
 
67
  {
 
68
    return (long) (fontSize * fontMetrics.getDescent());
 
69
  }
 
70
 
 
71
  public long getLeading()
 
72
  {
 
73
    return (long) (fontSize * fontMetrics.getLeading());
 
74
  }
 
75
 
 
76
  public long getXHeight()
 
77
  {
 
78
    return (long) (fontSize * fontMetrics.getXHeight());
 
79
  }
 
80
 
 
81
  public long getOverlinePosition()
 
82
  {
 
83
    return getLeading() - Math.max (1000, StrictGeomUtility.toInternalValue(fontSize)/ 20);
 
84
  }
 
85
 
 
86
  public long getUnderlinePosition()
 
87
  {
 
88
    return (long) (fontSize * fontMetrics.getUnderlinePosition());
 
89
  }
 
90
 
 
91
  public long getStrikeThroughPosition()
 
92
  {
 
93
    return (long) (fontSize * fontMetrics.getStrikeThroughPosition());
 
94
  }
 
95
 
 
96
  public long getMaxAscent()
 
97
  {
 
98
    return (long) (fontSize * fontMetrics.getMaxAscent());
 
99
  }
 
100
 
 
101
  public long getMaxDescent()
 
102
  {
 
103
    return (long) (fontSize * fontMetrics.getMaxDescent());
 
104
  }
 
105
 
 
106
  public long getItalicAngle()
 
107
  {
 
108
    return fontMetrics.getItalicAngle();
 
109
  }
 
110
 
 
111
  public long getMaxHeight()
 
112
  {
 
113
    return (long) ((fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent() + fontMetrics.getLeading()) * fontSize);
 
114
  }
 
115
 
 
116
  public long getMaxCharAdvance()
 
117
  {
 
118
    return (long) (fontMetrics.getMaxCharAdvance() * fontSize);
 
119
  }
 
120
 
 
121
  public long getCharWidth(final int character)
 
122
  {
 
123
    return 0;
 
124
  }
 
125
 
 
126
  public long getKerning(final int previous, final int character)
 
127
  {
 
128
    return 0;
 
129
  }
 
130
 
 
131
  /**
 
132
   * Baselines are defined for scripts, not glyphs. A glyph carries script
 
133
   * information most of the time (unless it is a neutral characters or just
 
134
   * weird).
 
135
   *
 
136
   * @param c
 
137
   * @return
 
138
   */
 
139
  public BaselineInfo getBaselines(final int c, final BaselineInfo info)
 
140
  {
 
141
    throw new UnsupportedOperationException("Not yet implemented.");
 
142
  }
 
143
}