jdk/src/share/classes/sun/font/AttributeValues.java
author darcy
Sat, 08 Feb 2014 18:03:38 -0800
changeset 23288 b7183846db97
parent 5506 202f599c92aa
permissions -rw-r--r--
8033624: Fix raw and unchecked lint warnings in sun.font Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 2005 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The original version of this source code and documentation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * copyrighted and owned by IBM. These materials are provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * under terms of a License Agreement between IBM and Sun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to IBM may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
package sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import static sun.font.EAttribute.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import static java.lang.Math.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.font.GraphicAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.font.NumericShaper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.font.TransformAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.geom.NoninvertibleTransformException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.awt.im.InputMethodHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.text.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.text.AttributedCharacterIterator.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public final class AttributeValues implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private int defined;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private int nondefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private String family = "Default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private float weight = 1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private float width = 1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private float posture; // 0f
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private float size = 12f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private float tracking; // 0f
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private NumericShaper numericShaping; // null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private AffineTransform transform; // null == identity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private GraphicAttribute charReplacement; // null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private Paint foreground; // null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private Paint background; // null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private float justification = 1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private Object imHighlight; // null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // (can be either Attribute wrapping IMH, or IMH itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private Font font; // here for completeness, don't actually use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private byte imUnderline = -1; // same default as underline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private byte superscript; // 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private byte underline = -1; // arrgh, value for ON is 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private byte runDirection = -2; // BIDI.DIRECTION_DEFAULT_LEFT_TO_RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private byte bidiEmbedding; // 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private byte kerning; // 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private byte ligatures; // 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private boolean strikethrough; // false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private boolean swapColors; // false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private AffineTransform baselineTransform; // derived from transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private AffineTransform charTransform; // derived from transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static final AttributeValues DEFAULT = new AttributeValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // type-specific API
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public String getFamily() { return family; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public void setFamily(String f) { this.family = f; update(EFAMILY); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public float getWeight() { return weight; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public void setWeight(float f) { this.weight = f; update(EWEIGHT); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public float getWidth() { return width; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public void setWidth(float f) { this.width = f; update(EWIDTH); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public float getPosture() { return posture; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void setPosture(float f) { this.posture = f; update(EPOSTURE); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public float getSize() { return size; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public void setSize(float f) { this.size = f; update(ESIZE); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public AffineTransform getTransform() { return transform; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public void setTransform(AffineTransform f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.transform = (f == null || f.isIdentity())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            ? DEFAULT.transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            : new AffineTransform(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        updateDerivedTransforms();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        update(ETRANSFORM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public void setTransform(TransformAttribute f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.transform = (f == null || f.isIdentity())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            ? DEFAULT.transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            : f.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        updateDerivedTransforms();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        update(ETRANSFORM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public int getSuperscript() { return superscript; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public void setSuperscript(int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      this.superscript = (byte)f; update(ESUPERSCRIPT); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public Font getFont() { return font; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void setFont(Font f) { this.font = f; update(EFONT); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public GraphicAttribute getCharReplacement() { return charReplacement; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void setCharReplacement(GraphicAttribute f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      this.charReplacement = f; update(ECHAR_REPLACEMENT); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public Paint getForeground() { return foreground; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void setForeground(Paint f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
      this.foreground = f; update(EFOREGROUND); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public Paint getBackground() { return background; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public void setBackground(Paint f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      this.background = f; update(EBACKGROUND); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public int getUnderline() { return underline; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public void setUnderline(int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      this.underline = (byte)f; update(EUNDERLINE); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public boolean getStrikethrough() { return strikethrough; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void setStrikethrough(boolean f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      this.strikethrough = f; update(ESTRIKETHROUGH); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public int getRunDirection() { return runDirection; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public void setRunDirection(int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
      this.runDirection = (byte)f; update(ERUN_DIRECTION); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public int getBidiEmbedding() { return bidiEmbedding; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void setBidiEmbedding(int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      this.bidiEmbedding = (byte)f; update(EBIDI_EMBEDDING); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public float getJustification() { return justification; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void setJustification(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      this.justification = f; update(EJUSTIFICATION); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public Object getInputMethodHighlight() { return imHighlight; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void setInputMethodHighlight(Annotation f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      this.imHighlight = f; update(EINPUT_METHOD_HIGHLIGHT); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public void setInputMethodHighlight(InputMethodHighlight f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      this.imHighlight = f; update(EINPUT_METHOD_HIGHLIGHT); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public int getInputMethodUnderline() { return imUnderline; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public void setInputMethodUnderline(int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      this.imUnderline = (byte)f; update(EINPUT_METHOD_UNDERLINE); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public boolean getSwapColors() { return swapColors; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void setSwapColors(boolean f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      this.swapColors = f; update(ESWAP_COLORS); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public NumericShaper getNumericShaping() { return numericShaping; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public void setNumericShaping(NumericShaper f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
      this.numericShaping = f; update(ENUMERIC_SHAPING); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public int getKerning() { return kerning; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public void setKerning(int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      this.kerning = (byte)f; update(EKERNING); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public float getTracking() { return tracking; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public void setTracking(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      this.tracking = (byte)f; update(ETRACKING); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public int getLigatures() { return ligatures; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void setLigatures(int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      this.ligatures = (byte)f; update(ELIGATURES); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public AffineTransform getBaselineTransform() { return baselineTransform; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public AffineTransform getCharTransform() { return charTransform; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    // mask api
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public static int getMask(EAttribute att) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return att.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public static int getMask(EAttribute ... atts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        int mask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        for (EAttribute a: atts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            mask |= a.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public static final int MASK_ALL =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        getMask(EAttribute.class.getEnumConstants());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void unsetDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        defined &= nondefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public void defineAll(int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        defined |= mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if ((defined & EBASELINE_TRANSFORM.mask) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            throw new InternalError("can't define derived attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public boolean allDefined(int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return (defined & mask) == mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public boolean anyDefined(int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return (defined & mask) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public boolean anyNonDefault(int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return (nondefault & mask) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    // generic EAttribute API
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public boolean isDefined(EAttribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return (defined & a.mask) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public boolean isNonDefault(EAttribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return (nondefault & a.mask) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public void setDefault(EAttribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (a.att == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            throw new InternalError("can't set default derived attribute: " + a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        i_set(a, DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        defined |= a.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        nondefault &= ~a.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public void unset(EAttribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (a.att == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            throw new InternalError("can't unset derived attribute: " + a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        i_set(a, DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        defined &= ~a.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        nondefault &= ~a.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public void set(EAttribute a, AttributeValues src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (a.att == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            throw new InternalError("can't set derived attribute: " + a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (src == null || src == DEFAULT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            setDefault(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            if ((src.defined & a.mask) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                i_set(a, src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                update(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void set(EAttribute a, Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (a.att == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            throw new InternalError("can't set derived attribute: " + a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                i_set(a, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                update(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        setDefault(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public Object get(EAttribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if (a.att == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            throw new InternalError("can't get derived attribute: " + a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if ((nondefault & a.mask) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return i_get(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    // merging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public AttributeValues merge(Map<? extends Attribute, ?>map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return merge(map, MASK_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public AttributeValues merge(Map<? extends Attribute, ?>map,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                 int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (map instanceof AttributeMap &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            ((AttributeMap) map).getValues() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            merge(((AttributeMap)map).getValues(), mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        } else if (map != null && !map.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            for (Map.Entry<? extends Attribute, ?> e: map.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    EAttribute ea = EAttribute.forAttribute(e.getKey());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    if (ea!= null && (mask & ea.mask) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                        set(ea, e.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                } catch (ClassCastException cce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    // IGNORED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public AttributeValues merge(AttributeValues src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return merge(src, MASK_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public AttributeValues merge(AttributeValues src, int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        int m = mask & src.defined;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        for (EAttribute ea: EAttribute.atts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            if (m == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            if ((m & ea.mask) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                m &= ~ea.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                i_set(ea, src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                update(ea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    // creation API
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public static AttributeValues fromMap(Map<? extends Attribute, ?> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return fromMap(map, MASK_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public static AttributeValues fromMap(Map<? extends Attribute, ?> map,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                                          int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return new AttributeValues().merge(map, mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public Map<TextAttribute, Object> toMap(Map<TextAttribute, Object> fill) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (fill == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            fill = new HashMap<TextAttribute, Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        for (int m = defined, i = 0; m != 0; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            EAttribute ea = EAttribute.atts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if ((m & ea.mask) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                m &= ~ea.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                fill.put(ea.att, get(ea));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return fill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    // key must be serializable, so use String, not Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    private static final String DEFINED_KEY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        "sun.font.attributevalues.defined_key";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public static boolean is16Hashtable(Hashtable<Object, Object> ht) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        return ht.containsKey(DEFINED_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public static AttributeValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    fromSerializableHashtable(Hashtable<Object, Object> ht)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        AttributeValues result = new AttributeValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (ht != null && !ht.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            for (Map.Entry<Object, Object> e: ht.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                Object key = e.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                Object val = e.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                if (key.equals(DEFINED_KEY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    result.defineAll(((Integer)val).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        EAttribute ea =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                            EAttribute.forAttribute((Attribute)key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                        if (ea != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                            result.set(ea, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    catch (ClassCastException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public Hashtable<Object, Object> toSerializableHashtable() {
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 5506
diff changeset
   413
        Hashtable<Object, Object> ht = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        int hashkey = defined;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        for (int m = defined, i = 0; m != 0; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            EAttribute ea = EAttribute.atts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if ((m & ea.mask) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                m &= ~ea.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                Object o = get(ea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    // hashkey will handle it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                } else if (o instanceof Serializable) { // check all...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    ht.put(ea.att, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    hashkey &= ~ea.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        ht.put(DEFINED_KEY, Integer.valueOf(hashkey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return ht;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    // boilerplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return defined << 8 ^ nondefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public boolean equals(Object rhs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return equals((AttributeValues)rhs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public boolean equals(AttributeValues rhs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        // test in order of most likely to differ and easiest to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // also assumes we're generally calling this only if family,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        // size, weight, posture are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (rhs == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (rhs == this) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return defined == rhs.defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            && nondefault == rhs.nondefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            && underline == rhs.underline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            && strikethrough == rhs.strikethrough
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            && superscript == rhs.superscript
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            && width == rhs.width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            && kerning == rhs.kerning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            && tracking == rhs.tracking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            && ligatures == rhs.ligatures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            && runDirection == rhs.runDirection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            && bidiEmbedding == rhs.bidiEmbedding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            && swapColors == rhs.swapColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            && equals(transform, rhs.transform)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            && equals(foreground, rhs.foreground)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            && equals(background, rhs.background)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            && equals(numericShaping, rhs.numericShaping)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            && equals(justification, rhs.justification)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            && equals(charReplacement, rhs.charReplacement)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            && size == rhs.size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            && weight == rhs.weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            && posture == rhs.posture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            && equals(family, rhs.family)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            && equals(font, rhs.font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            && imUnderline == rhs.imUnderline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            && equals(imHighlight, rhs.imHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public AttributeValues clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            AttributeValues result = (AttributeValues)super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            if (transform != null) { // AffineTransform is mutable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                result.transform = new AffineTransform(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                result.updateDerivedTransforms();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            // if transform is null, derived transforms are null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            // so there's nothing to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            // never happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        StringBuilder b = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        b.append('{');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        for (int m = defined, i = 0; m != 0; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            EAttribute ea = EAttribute.atts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            if ((m & ea.mask) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                m &= ~ea.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                if (b.length() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    b.append(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                b.append(ea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                b.append('=');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                switch (ea) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                case EFAMILY: b.append('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                  b.append(family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                  b.append('"'); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                case EWEIGHT: b.append(weight); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                case EWIDTH: b.append(width); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                case EPOSTURE: b.append(posture); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                case ESIZE: b.append(size); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                case ETRANSFORM: b.append(transform); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                case ESUPERSCRIPT: b.append(superscript); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                case EFONT: b.append(font); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                case ECHAR_REPLACEMENT: b.append(charReplacement); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                case EFOREGROUND: b.append(foreground); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                case EBACKGROUND: b.append(background); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                case EUNDERLINE: b.append(underline); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                case ESTRIKETHROUGH: b.append(strikethrough); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                case ERUN_DIRECTION: b.append(runDirection); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                case EBIDI_EMBEDDING: b.append(bidiEmbedding); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                case EJUSTIFICATION: b.append(justification); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                case EINPUT_METHOD_HIGHLIGHT: b.append(imHighlight); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                case EINPUT_METHOD_UNDERLINE: b.append(imUnderline); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                case ESWAP_COLORS: b.append(swapColors); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                case ENUMERIC_SHAPING: b.append(numericShaping); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                case EKERNING: b.append(kerning); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                case ELIGATURES: b.append(ligatures); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                case ETRACKING: b.append(tracking); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                default: throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                if ((nondefault & ea.mask) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    b.append('*');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        b.append("[btx=" + baselineTransform + ", ctx=" + charTransform + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        b.append('}');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return b.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    // internal utilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    private static boolean equals(Object lhs, Object rhs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        return lhs == null ? rhs == null : lhs.equals(rhs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    private void update(EAttribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        defined |= a.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if (i_validate(a)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            if (i_equals(a, DEFAULT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                nondefault &= ~a.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                nondefault |= a.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            setDefault(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    // dispatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    private void i_set(EAttribute a, AttributeValues src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        switch (a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        case EFAMILY: family = src.family; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        case EWEIGHT: weight = src.weight; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        case EWIDTH: width = src.width; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        case EPOSTURE: posture = src.posture; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        case ESIZE: size = src.size; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        case ETRANSFORM: transform = src.transform; updateDerivedTransforms(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        case ESUPERSCRIPT: superscript = src.superscript; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        case EFONT: font = src.font; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        case ECHAR_REPLACEMENT: charReplacement = src.charReplacement; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        case EFOREGROUND: foreground = src.foreground; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        case EBACKGROUND: background = src.background; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        case EUNDERLINE: underline = src.underline; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        case ESTRIKETHROUGH: strikethrough = src.strikethrough; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        case ERUN_DIRECTION: runDirection = src.runDirection; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        case EBIDI_EMBEDDING: bidiEmbedding = src.bidiEmbedding; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        case EJUSTIFICATION: justification = src.justification; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        case EINPUT_METHOD_HIGHLIGHT: imHighlight = src.imHighlight; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        case EINPUT_METHOD_UNDERLINE: imUnderline = src.imUnderline; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        case ESWAP_COLORS: swapColors = src.swapColors; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        case ENUMERIC_SHAPING: numericShaping = src.numericShaping; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        case EKERNING: kerning = src.kerning; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        case ELIGATURES: ligatures = src.ligatures; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        case ETRACKING: tracking = src.tracking; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        default: throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    private boolean i_equals(EAttribute a, AttributeValues src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        switch (a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        case EFAMILY: return equals(family, src.family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        case EWEIGHT: return weight == src.weight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        case EWIDTH: return width == src.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        case EPOSTURE: return posture == src.posture;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        case ESIZE: return size == src.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        case ETRANSFORM: return equals(transform, src.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        case ESUPERSCRIPT: return superscript == src.superscript;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        case EFONT: return equals(font, src.font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        case ECHAR_REPLACEMENT: return equals(charReplacement, src.charReplacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        case EFOREGROUND: return equals(foreground, src.foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        case EBACKGROUND: return equals(background, src.background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        case EUNDERLINE: return underline == src.underline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        case ESTRIKETHROUGH: return strikethrough == src.strikethrough;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        case ERUN_DIRECTION: return runDirection == src.runDirection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        case EBIDI_EMBEDDING: return bidiEmbedding == src.bidiEmbedding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        case EJUSTIFICATION: return justification == src.justification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        case EINPUT_METHOD_HIGHLIGHT: return equals(imHighlight, src.imHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        case EINPUT_METHOD_UNDERLINE: return imUnderline == src.imUnderline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        case ESWAP_COLORS: return swapColors == src.swapColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        case ENUMERIC_SHAPING: return equals(numericShaping, src.numericShaping);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        case EKERNING: return kerning == src.kerning;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        case ELIGATURES: return ligatures == src.ligatures;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        case ETRACKING: return tracking == src.tracking;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        default: throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    private void i_set(EAttribute a, Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        switch (a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        case EFAMILY: family = ((String)o).trim(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        case EWEIGHT: weight = ((Number)o).floatValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        case EWIDTH: width = ((Number)o).floatValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        case EPOSTURE: posture = ((Number)o).floatValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        case ESIZE: size = ((Number)o).floatValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        case ETRANSFORM: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            if (o instanceof TransformAttribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                TransformAttribute ta = (TransformAttribute)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                if (ta.isIdentity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    transform = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    transform = ta.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                transform = new AffineTransform((AffineTransform)o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            updateDerivedTransforms();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        } break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        case ESUPERSCRIPT: superscript = (byte)((Integer)o).intValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        case EFONT: font = (Font)o; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        case ECHAR_REPLACEMENT: charReplacement = (GraphicAttribute)o; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        case EFOREGROUND: foreground = (Paint)o; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        case EBACKGROUND: background = (Paint)o; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        case EUNDERLINE: underline = (byte)((Integer)o).intValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        case ESTRIKETHROUGH: strikethrough = ((Boolean)o).booleanValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        case ERUN_DIRECTION: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            if (o instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                runDirection = (byte)(TextAttribute.RUN_DIRECTION_LTR.equals(o) ? 0 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                runDirection = (byte)((Integer)o).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        } break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        case EBIDI_EMBEDDING: bidiEmbedding = (byte)((Integer)o).intValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        case EJUSTIFICATION: justification = ((Number)o).floatValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        case EINPUT_METHOD_HIGHLIGHT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            if (o instanceof Annotation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                Annotation at = (Annotation)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                imHighlight = (InputMethodHighlight)at.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                imHighlight = (InputMethodHighlight)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        } break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        case EINPUT_METHOD_UNDERLINE: imUnderline = (byte)((Integer)o).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        case ESWAP_COLORS: swapColors = ((Boolean)o).booleanValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        case ENUMERIC_SHAPING: numericShaping = (NumericShaper)o; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        case EKERNING: kerning = (byte)((Integer)o).intValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        case ELIGATURES: ligatures = (byte)((Integer)o).intValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        case ETRACKING: tracking = ((Number)o).floatValue(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        default: throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private Object i_get(EAttribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        switch (a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        case EFAMILY: return family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        case EWEIGHT: return Float.valueOf(weight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        case EWIDTH: return Float.valueOf(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        case EPOSTURE: return Float.valueOf(posture);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        case ESIZE: return Float.valueOf(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        case ETRANSFORM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            return transform == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                ? TransformAttribute.IDENTITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                : new TransformAttribute(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        case ESUPERSCRIPT: return Integer.valueOf(superscript);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        case EFONT: return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        case ECHAR_REPLACEMENT: return charReplacement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        case EFOREGROUND: return foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        case EBACKGROUND: return background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        case EUNDERLINE: return Integer.valueOf(underline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        case ESTRIKETHROUGH: return Boolean.valueOf(strikethrough);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        case ERUN_DIRECTION: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            switch (runDirection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                // todo: figure out a way to indicate this value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                // case -1: return Integer.valueOf(runDirection);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            case 0: return TextAttribute.RUN_DIRECTION_LTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            case 1: return TextAttribute.RUN_DIRECTION_RTL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            default: return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        } // not reachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        case EBIDI_EMBEDDING: return Integer.valueOf(bidiEmbedding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        case EJUSTIFICATION: return Float.valueOf(justification);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        case EINPUT_METHOD_HIGHLIGHT: return imHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        case EINPUT_METHOD_UNDERLINE: return Integer.valueOf(imUnderline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        case ESWAP_COLORS: return Boolean.valueOf(swapColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        case ENUMERIC_SHAPING: return numericShaping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        case EKERNING: return Integer.valueOf(kerning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        case ELIGATURES: return Integer.valueOf(ligatures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        case ETRACKING: return Float.valueOf(tracking);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        default: throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    private boolean i_validate(EAttribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        switch (a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        case EFAMILY: if (family == null || family.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
          family = DEFAULT.family; return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        case EWEIGHT: return weight > 0 && weight < 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        case EWIDTH: return width >= .5f && width < 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        case EPOSTURE: return posture >= -1 && posture <= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        case ESIZE: return size >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        case ETRANSFORM: if (transform != null && transform.isIdentity())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            transform = DEFAULT.transform; return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        case ESUPERSCRIPT: return superscript >= -7 && superscript <= 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        case EFONT: return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        case ECHAR_REPLACEMENT: return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        case EFOREGROUND: return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        case EBACKGROUND: return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        case EUNDERLINE: return underline >= -1 && underline < 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        case ESTRIKETHROUGH: return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        case ERUN_DIRECTION: return runDirection >= -2 && runDirection <= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        case EBIDI_EMBEDDING: return bidiEmbedding >= -61 && bidiEmbedding < 62;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        case EJUSTIFICATION: justification = max(0, min (justification, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        case EINPUT_METHOD_HIGHLIGHT: return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        case EINPUT_METHOD_UNDERLINE: return imUnderline >= -1 && imUnderline < 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        case ESWAP_COLORS: return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        case ENUMERIC_SHAPING: return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        case EKERNING: return kerning >= 0 && kerning <= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        case ELIGATURES: return ligatures >= 0 && ligatures <= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        case ETRACKING: return tracking >= -1 && tracking <= 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        default: throw new InternalError("unknown attribute: " + a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    // Until textlayout is fixed to use AttributeValues, we'll end up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    // creating a map from the values for it.  This is a compromise between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    // creating the whole map and just checking a particular value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    // Plan to remove these.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    public static float getJustification(Map<?, ?> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if (map instanceof AttributeMap &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                ((AttributeMap) map).getValues() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                return ((AttributeMap)map).getValues().justification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            Object obj = map.get(TextAttribute.JUSTIFICATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            if (obj != null && obj instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                return max(0, min(1, ((Number)obj).floatValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        return DEFAULT.justification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    public static NumericShaper getNumericShaping(Map<?, ?> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            if (map instanceof AttributeMap &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                ((AttributeMap) map).getValues() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                return ((AttributeMap)map).getValues().numericShaping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            Object obj = map.get(TextAttribute.NUMERIC_SHAPING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            if (obj != null && obj instanceof NumericShaper) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                return (NumericShaper)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        return DEFAULT.numericShaping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * If this has an imHighlight, create copy of this with those attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * applied to it.  Otherwise return this unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    public AttributeValues applyIMHighlight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        if (imHighlight != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            InputMethodHighlight hl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            if (imHighlight instanceof InputMethodHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                hl = (InputMethodHighlight)imHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                hl = (InputMethodHighlight)((Annotation)imHighlight).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 5506
diff changeset
   801
            Map<TextAttribute, ?> imStyles = hl.getStyle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            if (imStyles == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                imStyles = tk.mapInputMethodHighlight(hl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            if (imStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                return clone().merge(imStyles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 5506
diff changeset
   815
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    public static AffineTransform getBaselineTransform(Map<?, ?> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            AttributeValues av = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            if (map instanceof AttributeMap &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                ((AttributeMap) map).getValues() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                av = ((AttributeMap)map).getValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            } else if (map.get(TextAttribute.TRANSFORM) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                av = AttributeValues.fromMap((Map<Attribute, ?>)map); // yuck
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            if (av != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                return av.baselineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 5506
diff changeset
   832
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    public static AffineTransform getCharTransform(Map<?, ?> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            AttributeValues av = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            if (map instanceof AttributeMap &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                ((AttributeMap) map).getValues() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                av = ((AttributeMap)map).getValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            } else if (map.get(TextAttribute.TRANSFORM) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                av = AttributeValues.fromMap((Map<Attribute, ?>)map); // yuck
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            if (av != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                return av.charTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    public void updateDerivedTransforms() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        // this also updates the mask for the baseline transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        if (transform == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            baselineTransform = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            charTransform = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            charTransform = new AffineTransform(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            baselineTransform = extractXRotation(charTransform, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            if (charTransform.isIdentity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
              charTransform = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            if (baselineTransform.isIdentity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
              baselineTransform = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (baselineTransform == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            nondefault &= ~EBASELINE_TRANSFORM.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            nondefault |= EBASELINE_TRANSFORM.mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    public static AffineTransform extractXRotation(AffineTransform tx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                                                   boolean andTranslation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        return extractRotation(new Point2D.Double(1, 0), tx, andTranslation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    public static AffineTransform extractYRotation(AffineTransform tx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                                                   boolean andTranslation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        return extractRotation(new Point2D.Double(0, 1), tx, andTranslation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    private static AffineTransform extractRotation(Point2D.Double pt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        AffineTransform tx, boolean andTranslation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        tx.deltaTransform(pt, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            AffineTransform rtxi = rtx.createInverse();
533
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents: 2
diff changeset
   892
            double dx = tx.getTranslateX();
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents: 2
diff changeset
   893
            double dy = tx.getTranslateY();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            tx.preConcatenate(rtxi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            if (andTranslation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                if (dx != 0 || dy != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                    tx.setTransform(tx.getScaleX(), tx.getShearY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                                    tx.getShearX(), tx.getScaleY(), 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    rtx.setTransform(rtx.getScaleX(), rtx.getShearY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                                     rtx.getShearX(), rtx.getScaleY(), dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        catch (NoninvertibleTransformException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        return rtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
}