FileDocCategorySizeDatePackage
HKern.javaAPI DocphoneME MR2 API (J2ME)11112Wed May 02 18:00:34 BST 2007com.sun.perseus.model

HKern

public class HKern extends ElementNode
A HKern corresponds to an SVG <hkern> element.
version
$Id: HKern.java,v 1.5 2006/06/29 10:47:32 ln156897 Exp $

Fields Summary
static final String[]
REQUIRED_TRAITS
Only the k trait is required on
protected int[]
u1
Unicode ranges
protected int[]
u2
protected String[]
g1
Name matches
protected String[]
g2
protected float
k
Adjusted horizontal advance
protected HKern
nextHKern
For use by Font
Constructors Summary
public HKern(DocumentNode ownerDocument)
Constructor.

param
ownerDocument this element's owner DocumentNode


                
        
        super(ownerDocument);
    
Methods Summary
public java.lang.String[]getG1()

return
this node's matching glyphs names for the first glyph

        return g1;
    
public java.lang.String[]getG2()

return
this node's matching glyph names for the second glyph

        return g2;
    
public floatgetK()

return
this kerning entry's advance.

        return k;
    
public java.lang.StringgetLocalName()

return
the SVGConstants.SVG_HKERN_TAG value

        return SVGConstants.SVG_HKERN_TAG;
    
public java.lang.String[]getRequiredTraits()

return
an array of traits that are required by this element.

        return REQUIRED_TRAITS;
    
public java.lang.StringgetTraitImpl(java.lang.String name)
HKern handles the u1, u2, g1, g2 and k traits.

param
name the requested trait name (e.g., "horiz-adv-x")
return
the trait's value, as a string.
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if requested trait's computed value cannot be converted to a String (SVG Tiny only).

        if (SVGConstants.SVG_U1_ATTRIBUTE == name) {
            return unicodeRangeToStringTrait(u1);
        } else if (SVGConstants.SVG_U2_ATTRIBUTE == name) {
            return unicodeRangeToStringTrait(u2);
        } else if (SVGConstants.SVG_G1_ATTRIBUTE == name) {
            return toStringTrait(g1);
        } else if (SVGConstants.SVG_G2_ATTRIBUTE == name) {
            return toStringTrait(g2);
        } else if (SVGConstants.SVG_K_ATTRIBUTE == name) {
            return Float.toString(k);
        } else {
            return super.getTraitImpl(name);
        }
    
public int[][]getU1()

return
this node's matching unicode ranges for the first glyph

        return u1;
    
public int[][]getU2()

return
this node's matching unicode ranges for the second glyph

        return u2;
    
booleanmatches(Glyph glyph, int[][] u, java.lang.String[] g)
Checks if the input glyph is a match for the input set of unicode ranges and/or glyph names.

param
glyph the glyph to match.
param
u the set of unicode ranges
param
g the set of glyph names.
return
true if there is a match.

        String gu = glyph.getUnicode();
        String[] gg = glyph.getGlyphName();

        if (u != null && gu != null && gu.length() == 1) {
            char c = gu.charAt(0);
            for (int i = 0; i < u.length; i++) {
                if (c >= u[i][0] && c <= u[i][1]) {
                    return true;
                }
            }
        }

        if (gg != null && g != null) {
            for (int i = 0; i < gg.length; i++) {
                String gn = gg[i];
                for (int j = 0; j < g.length; j++) {
                    if (g[j].equals(gn)) {
                        return true;
                    }
                }
            }
        }

        return false;
    
public booleanmatchesFirst(Glyph g)
Checks if the input glyph is a match for u1 or g1.

param
g the glyph to match.
return
true if the unicode range or glyph name of the input Glyph matches the kerning's u1 or g1 setting.

        return matches(g, u1, g1);
    
public booleanmatchesSecond(Glyph g)
Checks if the input glyph is a match for u2 or g2.

param
g the glyph to match.
return
true if the unicode range or glyph name of the input Glyph matches the kerning's u2 or g2 setting.

        return matches(g, u2, g2);
    
public ElementNodenewInstance(DocumentNode doc)
Used by DocumentNode to create a new instance from a prototype HKern.

param
doc the DocumentNode for which a new node is should be created.
return
a new HKern for the requested document.

        return new HKern(doc);
    
public voidsetG1(java.lang.String[] g1)
Sets this kerning entry first glyph names matches.

param
g1 the list of matching names.

        if (equal(g1, this.g1)) {
            return;
        }
        modifyingNode();
        this.g1 = g1;
        modifiedNode();
    
public voidsetG2(java.lang.String[] g2)
Sets this kerning entry second glyph names matches.

param
g2 the list of matching names.

        if (equal(g2, this.g2)) {
            return;
        }
        modifyingNode();
        this.g2 = g2;
        modifiedNode();
    
public voidsetK(float k)
Sets this kernixng entry's advance.

param
k the new kerning advance

        if (this.k == k) {
            return;
        }
        modifyingNode();
        this.k = k;
        modifiedNode();
    
public voidsetTraitImpl(java.lang.String name, java.lang.String value)
HKern handles the u1, u2, g1, g2 and k traits.

param
name the trait's name (e.g., "units-per-em")
param
value the new trait string value (e.g., "1000")
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if the requested trait's value cannot be specified as a String
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is an invalid value for the given trait or null.
throws
DOMException with error code NO_MODIFICATION_ALLOWED_ERR: if attempt is made to change readonly trait.

        if (SVGConstants.SVG_U1_ATTRIBUTE == name) {
            checkWriteLoading(name);
            setU1(parseUnicodeRangeTrait(name, value));
        } else if (SVGConstants.SVG_U2_ATTRIBUTE == name) {
            checkWriteLoading(name);
            setU2(parseUnicodeRangeTrait(name, value));
        } else if (SVGConstants.SVG_G1_ATTRIBUTE == name) {
            checkWriteLoading(name);
            setG1(parseStringArrayTrait(name, value, SVGConstants.COMMA_STR));
        } else if (SVGConstants.SVG_G2_ATTRIBUTE == name) {
            checkWriteLoading(name);
            setG2(parseStringArrayTrait(name, value, SVGConstants.COMMA_STR));
        } else if (SVGConstants.SVG_K_ATTRIBUTE == name) {
            checkWriteLoading(name);
            setK(parseFloatTrait(name, value));
        } else {
            super.setTraitImpl(name, value);
        }
    
public voidsetU1(int[][] u1)
Sets this kerning entry's first match

param
u1 the new matching unicode ranges.
throws
IllegalArgumentException if the input array has an entry which is not of length 2.

        if (u1 != null) {
            for (int i = 0; i < u1.length; i++) {
                if (u1[i] == null || u1[i].length != 2) {
                    throw new IllegalArgumentException();
                }
            }
        }

        if (equal(u1, this.u1)) {
            return;
        }
        modifyingNode();
        this.u1 = u1;
        modifiedNode();
    
public voidsetU2(int[][] u2)
Sets this kerning entry's second match

param
u2 the new matching unicode ranges.
throws
IllegalArgumentException if the input array has an entry which is not of length 2.

        if (u2 != null) {
            for (int i = 0; i < u2.length; i++) {
                if (u2[i] == null || u2[i].length != 2) {
                    throw new IllegalArgumentException();
                }
            }
        }

        if (equal(u2, this.u2)) {
            return;
        }
        modifyingNode();
        this.u2 = u2;
        modifiedNode();
    
booleansupportsTrait(java.lang.String traitName)
HKern handles the u1, u2, g1, g2 and k traits.

param
traitName the name of the trait which the element may support.
return
true if this element supports the given trait in one of the trait accessor methods.

        if (SVGConstants.SVG_U1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_U2_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_G1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_G2_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_K_ATTRIBUTE == traitName) {
            return true;
        }
        
        return super.supportsTrait(traitName);