Fields Summary |
---|
static final String[] | REQUIRED_TRAITSOnly the horiz-adv-x trait is required on |
protected float | horizontalOriginXThe X-coordinate in the font coordinate system of the origin
of a glyph to be used when drawing horizontally oriented text.
(Note that the origin applies to all glyphs in the font.) |
protected float | horizontalAdvanceXThe default horizontal advance after rendering a glyph in
horizontal orientation. Glyph widths are required to be non-negative,
even if the glyph is typically rendered right-to-left, as in
Hebrew and Arabic scripts. |
protected FontFace | fontFaceThe current fontFace describing this font, if any |
protected Glyph | missingGlyphThe Font's missing glyph, used to render unknown characters |
protected HKern | firstHKernThe Font's first horizontal kerning pair. May be null. |
protected HKern | lastHKernThe Font's last horizontal kerning pair. May be null. |
Methods Summary |
---|
public void | add(ElementNode node)
super.add(node);
addSpecial(node);
|
protected void | addFontFace(FontFace newFontFace)
if (fontFace != null) {
// If there is already a FontFace child, we ignore the second
// one. Only the first child is accounted for.
return;
}
// A Font can only have a single font-face child. If there is alre
fontFace = newFontFace;
updateGlyphEmSquare();
|
protected void | addGlyph(Glyph gl)
updateGlyphEmSquare(gl);
|
protected void | addHKern(HKern hkern)Simply chain the kerning pairs so that they can be
looked up easily later.
if (firstHKern != null) {
lastHKern.nextHKern = hkern;
lastHKern = hkern;
} else {
firstHKern = hkern;
lastHKern = hkern;
hkern.nextHKern = null;
}
|
protected void | addMissingGlyph(Glyph gl)If there is already a missing glyph, any new call
to addMissingGlyph has no effect on the
missing glyph.
// Only use gl as a missing glyph if it is the
// first missing glyph
if (missingGlyph == null) {
missingGlyph = gl;
}
updateGlyphEmSquare(gl);
|
protected void | addSpecial(ModelNode node)Called in case special handling of children is required.
if (!(node instanceof Glyph)) {
if (!(node instanceof FontFace)) {
if (!(node instanceof HKern)) {
return;
} else {
addHKern((HKern) node);
}
} else {
addFontFace((FontFace) node);
}
} else {
Glyph gl = (Glyph) node;
if (gl.getUnicode() == null) {
addMissingGlyph(gl);
} else {
addGlyph(gl);
}
}
|
public Glyph | canDisplay(char[] s, int index)Returns a Glyph if the FontFace can display the
character at the requested index. Returns null
if no matching glyph can be found.
int max = s.length - index;
int glLength = 0;
int j = 0;
Glyph gl = null;
ModelNode c = firstChild;
while (c != null) {
if (c instanceof Glyph) {
gl = (Glyph) c;
glLength = gl.getLength();
if (gl.getUnicode() != null
&& glLength > 0
&& index + glLength <= s.length) {
for (j = 0; j < glLength; j++) {
if (s[index + j] != gl.getCharAt(j)) {
break;
}
}
if (j == glLength) {
return gl;
}
}
}
c = c.nextSibling;
}
// No matching glyph
return null;
|
float | getFloatTraitImpl(java.lang.String name)Font handles the horiz-adv-x and horiz-origin-x traits.
Other traits are handled by the super class.
if (SVGConstants.SVG_HORIZ_ADV_X_ATTRIBUTE == name) {
return getHorizontalAdvanceX();
} else if (SVGConstants.SVG_HORIZ_ORIGIN_X_ATTRIBUTE == name) {
return getHorizontalOriginX();
} else {
return super.getFloatTraitImpl(name);
}
|
float | getHKern(Glyph g1, Glyph g2)Used by the Text class: looks up kerning pairs to check if
there is any horizontal kerning for the input pair.
if (g2.parent != this) {
return 0;
}
HKern k = firstHKern;
while (k != null) {
if (k.matchesFirst(g1)) {
if (k.matchesSecond(g2)) {
break;
}
}
k = k.nextHKern;
}
if (k != null) {
if (fontFace != null) {
return k.k * fontFace.getEmSquareScale();
} else {
return k.k;
}
} else {
return 0;
}
|
public float | getHorizontalAdvanceX()
return horizontalAdvanceX;
|
public float | getHorizontalOriginX()
return horizontalOriginX;
|
public java.lang.String | getLocalName()
return SVGConstants.SVG_FONT_TAG;
|
public Glyph | getMissingGlyph()
return missingGlyph;
|
public java.lang.String[] | getRequiredTraits()
return REQUIRED_TRAITS;
|
public java.lang.String | getTraitImpl(java.lang.String name)Font handles the horiz-adv-x and horiz-origin-x traits.
Other traits are handled by the super class.
if (SVGConstants.SVG_HORIZ_ADV_X_ATTRIBUTE == name) {
return Float.toString(getHorizontalAdvanceX());
} else if (SVGConstants.SVG_HORIZ_ORIGIN_X_ATTRIBUTE == name) {
return Float.toString(getHorizontalOriginX());
} else {
return super.getTraitImpl(name);
}
|
public ElementNode | newInstance(DocumentNode doc)Used by DocumentNode to create a new instance from
a prototype Font .
return new Font(doc);
|
public void | setFloatTraitImpl(java.lang.String name, float value)Font handles the horiz-adv-x and horiz-origin-x traits.
Other traits are handled by the super class.
if (SVGConstants.SVG_HORIZ_ADV_X_ATTRIBUTE == name) {
setHorizontalAdvanceX(value);
} else if (SVGConstants.SVG_HORIZ_ORIGIN_X_ATTRIBUTE == name) {
setHorizontalOriginX(value);
} else {
super.setFloatTraitImpl(name, value);
}
|
public void | setHorizontalAdvanceX(float newHorizontalAdvanceX)
if (newHorizontalAdvanceX == horizontalAdvanceX) {
return;
}
modifyingNode();
horizontalAdvanceX = newHorizontalAdvanceX;
modifiedNode();
|
public void | setHorizontalOriginX(float newHorizontalOriginX)
if (newHorizontalOriginX == horizontalOriginX) {
return;
}
modifyingNode();
horizontalOriginX = newHorizontalOriginX;
modifiedNode();
|
public void | setTraitImpl(java.lang.String name, java.lang.String value)Font handles the horiz-adv-x and horiz-origin-x traits.
Other traits are handled by the super class.
if (SVGConstants.SVG_HORIZ_ADV_X_ATTRIBUTE == name) {
checkWriteLoading(name);
setHorizontalAdvanceX(parseFloatTrait(name, value));
} else if (SVGConstants.SVG_HORIZ_ORIGIN_X_ATTRIBUTE == name) {
checkWriteLoading(name);
setHorizontalOriginX(parseFloatTrait(name, value));
} else {
super.setTraitImpl(name, value);
}
|
boolean | supportsTrait(java.lang.String traitName)Font handlers the horiz-adv-x and horiz-origin-x traits.
if (SVGConstants.SVG_HORIZ_ORIGIN_X_ATTRIBUTE == traitName
||
SVGConstants.SVG_HORIZ_ADV_X_ATTRIBUTE == traitName) {
return true;
}
return super.supportsTrait(traitName);
|
protected void | updateGlyphEmSquare()Update the em square on all the Font's glyphs
float emSquareScale = 1;
if (fontFace != null) {
emSquareScale = fontFace.getEmSquareScale();
}
ElementNode c = firstChild;
while (c != null) {
if (c instanceof Glyph) {
((Glyph) c).setEmSquareScale(emSquareScale);
}
c = (ElementNode) c.nextSibling;
}
|
protected void | updateGlyphEmSquare(Glyph gl)
if (fontFace != null) {
gl.setEmSquareScale(fontFace.getEmSquareScale());
} else {
gl.setEmSquareScale(1);
}
|