summaryrefslogtreecommitdiffstats
path: root/awt/java/awt/font/FontRenderContext.java
blob: 766300d7d00d5dc2a9494035cf30771200deacb0 (plain)
1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * @author Ilya S. Okomin
 * @version $Revision$
 */
package java.awt.font;

import java.awt.geom.AffineTransform;

/**
 * The FontRenderContext class contains the information 
 * about text measurement. Anti-aliasing and fractional-metrics
 * modes are defined by an application and affect the size of
 * a character.
 */
public class FontRenderContext {

    // Affine transform of this mode
    /** The transform. */
    private AffineTransform transform;

    // Is the anti-aliased mode used
    /** The anti aliased. */
    private boolean fAntiAliased;

    // Is the fractional metrics used
    /** The fractional metrics. */
    private boolean fFractionalMetrics;


    /**
     * Instantiates a new FontRenderContext object with the specified
     * AffineTransform, anti-aliasing and fractional metrics flags.
     * 
     * @param trans the AffineTransform.
     * @param antiAliased the anti-aliasing flag.
     * @param usesFractionalMetrics the fractional metrics flag.
     */
    public FontRenderContext(AffineTransform trans, boolean antiAliased, 
            boolean usesFractionalMetrics) {
        if (trans != null){
            transform = new AffineTransform(trans);
        }
        fAntiAliased = antiAliased;
        fFractionalMetrics = usesFractionalMetrics;
    }

    /**
     * Instantiates a new FontRenderContext object.
     */
    protected FontRenderContext() {
    }

    /**
     * Compares the specified Object with current FontRenderContext object. 
     * 
     * @param obj the Object to be compared.
     * 
     * @return true, if the specified Object is equal to current
     * FontRenderContext object.
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }

        if (obj != null) {
            try {
                return equals((FontRenderContext) obj);
            } catch (ClassCastException e) {
                return false;
            }
        }
        return false;

    }

    /**
     * Gets the transform which is used for scaling typographical points 
     * to pixels in this FontRenderContext.
     * 
     * @return the AffineTransform which is used for scaling typographical 
     * points to pixels in this FontRenderContext.
     */
    public AffineTransform getTransform() {
        if (transform != null){
            return new AffineTransform(transform);
        }
        return new AffineTransform();
    }

    /**
     * Compares the specified FontRenderContext object with current 
     * FontRenderContext.
     * 
     * @param frc the FontRenderContext object to be compared.
     * 
     * @return true, if the specified FontRenderContext object is
     * equal to current FontRenderContext.
     */
    public boolean equals(FontRenderContext frc) {
        if (this == frc){
            return true;
        }

        if (frc == null){
            return false;
        }

        if (!frc.getTransform().equals(this.getTransform()) &&
            !frc.isAntiAliased() == this.fAntiAliased &&
            !frc.usesFractionalMetrics() == this.fFractionalMetrics){
            return false;
        }
        return true;
    }

    /**
     * Returns true if the text fractional metrics are used in 
     * this FontRenderContext.
     * 
     * @return true, if the text fractional metrics are used in 
     * this FontRenderContext, false otherwise.
     */
    public boolean usesFractionalMetrics() {
        return this.fFractionalMetrics;
    }

    /**
     * Returns true if anti-aliasing is used in this FontRenderContext.
     * 
     * @return true, if is anti-aliasing is used in this FontRenderContext,
     * false otherwise.
     */
    public boolean isAntiAliased() {
        return this.fAntiAliased;
    }

    /**
     * Returns hash code of the FontRenderContext object.
     * 
     * @return the hash code of the FontRenderContext object.
     */
    @Override
    public int hashCode() {
        return this.getTransform().hashCode() ^
                new Boolean(this.fFractionalMetrics).hashCode() ^
                new Boolean(this.fAntiAliased).hashCode();
    }

}