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

« back to all changes in this revision

Viewing changes to source/org/pentaho/reporting/libraries/fonts/monospace/MonospaceFontFamily.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.monospace;
 
19
 
 
20
import org.pentaho.reporting.libraries.fonts.registry.FontFamily;
 
21
import org.pentaho.reporting.libraries.fonts.registry.FontRecord;
 
22
 
 
23
/**
 
24
 * Creation-Date: 13.05.2007, 13:14:25
 
25
 *
 
26
 * @author Thomas Morgner
 
27
 */
 
28
public class MonospaceFontFamily implements FontFamily
 
29
{
 
30
  private String familyName;
 
31
  private FontRecord[] fonts;
 
32
 
 
33
  public MonospaceFontFamily(final String familyName)
 
34
  {
 
35
    if (familyName == null)
 
36
    {
 
37
      throw new NullPointerException();
 
38
    }
 
39
    this.familyName = familyName;
 
40
    this.fonts = new FontRecord[4];
 
41
  }
 
42
 
 
43
  /**
 
44
   * Returns the name of the font family (in english).
 
45
   *
 
46
   * @return
 
47
   */
 
48
  public String getFamilyName()
 
49
  {
 
50
    return familyName;
 
51
  }
 
52
 
 
53
  public String[] getAllNames()
 
54
  {
 
55
    return new String[]{ familyName };
 
56
  }
 
57
 
 
58
  /**
 
59
   * This selects the most suitable font in that family. Italics fonts are preferred over oblique fonts.
 
60
   *
 
61
   * @param bold
 
62
   * @param italics
 
63
   * @return
 
64
   */
 
65
  public FontRecord getFontRecord(final boolean bold, final boolean italics)
 
66
  {
 
67
    int index = 0;
 
68
    if (bold)
 
69
    {
 
70
      index += 1;
 
71
    }
 
72
    if (italics)
 
73
    {
 
74
      index += 2;
 
75
    }
 
76
    if (fonts[index] != null)
 
77
    {
 
78
      return fonts[index];
 
79
    }
 
80
    fonts[index] = new MonospaceFontRecord(this, bold, italics);
 
81
    return fonts[index];
 
82
  }
 
83
 
 
84
  public boolean equals(final Object o)
 
85
  {
 
86
    if (this == o)
 
87
    {
 
88
      return true;
 
89
    }
 
90
    if (o == null || getClass() != o.getClass())
 
91
    {
 
92
      return false;
 
93
    }
 
94
 
 
95
    final MonospaceFontFamily that = (MonospaceFontFamily) o;
 
96
 
 
97
    if (!familyName.equals(that.familyName))
 
98
    {
 
99
      return false;
 
100
    }
 
101
 
 
102
    return true;
 
103
  }
 
104
 
 
105
  public int hashCode()
 
106
  {
 
107
    return familyName.hashCode();
 
108
  }
 
109
}