GlyphLayoutpublic class GlyphLayout extends Object GlyphLayout is used to represent successing text 'chunks' in
a Text layout of glyphs. The notion of 'chunk' is that of the
SVG specification. |
Fields Summary |
---|
protected float | advanceThe overally layout's advance | protected float | xThe chunk's x-axis position | protected float | yThe chunk's y-axis position | protected GlyphProxy | firstChildThe first child | protected GlyphProxy | lastChildThe last child | protected GlyphLayout | prevSiblingPrevious sibling. | protected GlyphLayout | nextSiblingNext sibling | protected DocumentNode | ownerDocumentOwner Document, to get cache objects. | protected float[] | helperDashArrayUsed to scale dash array values. |
Constructors Summary |
---|
GlyphLayout(DocumentNode doc)
this.ownerDocument = doc;
|
Methods Summary |
---|
public void | add(GlyphProxy proxy)Appends an element at the end of the list
if (proxy == null) {
throw new NullPointerException();
}
if (firstChild == null) {
firstChild = proxy;
lastChild = proxy;
proxy.nextSibling = null;
proxy.prevSibling = null;
} else {
lastChild.nextSibling = proxy;
proxy.nextSibling = null;
proxy.prevSibling = lastChild;
lastChild = proxy;
}
| com.sun.perseus.j2d.Box | addBBox(com.sun.perseus.j2d.Box bbox, com.sun.perseus.j2d.Transform t)
GlyphProxy gp = firstChild;
while (gp != null) {
ownerDocument.bboxGlyphTxf.setTransform(t);
gp.applyTransform(ownerDocument.bboxGlyphTxf);
bbox = gp.addNodeBBox(bbox, ownerDocument.bboxGlyphTxf);
gp = gp.nextSibling;
}
return bbox;
| protected final com.sun.perseus.j2d.Tile | addRenderingTile(com.sun.perseus.j2d.Tile tile, com.sun.perseus.j2d.TextRenderingProperties trp, com.sun.perseus.j2d.Transform t)Add this GlyphLayout rendering tile to the input Tile.
if (trp.getStroke() != null) {
GlyphProxy gp = firstChild;
while (gp != null) {
ownerDocument.bboxGlyphTxf.setTransform(t);
gp.applyTransform(ownerDocument.bboxGlyphTxf);
tile = gp.addRenderingTile(tile, trp, t);
gp = (GlyphProxy) gp.nextSibling;
}
} else {
GlyphProxy gp = firstChild;
float strokeWidth = trp.getStrokeWidth();
while (gp != null) {
ownerDocument.bboxGlyphTxf.setTransform(t);
gp.applyTransform(ownerDocument.bboxGlyphTxf);
trp.setStrokeWidth(strokeWidth / gp.proxied.emSquareScale);
tile = gp.addRenderingTile(tile, trp, t);
gp = (GlyphProxy) gp.nextSibling;
}
}
return tile;
| protected void | applyInverseTransform(com.sun.perseus.j2d.TextRenderingProperties trp, com.sun.perseus.j2d.Transform tx)Applies the inverse of the chunk's position adjustment due to the
text anchor's value.
// Account for the text-anchor translation
switch (trp.getTextAnchor()) {
default:
break;
case TextNode.TEXT_ANCHOR_MIDDLE:
tx.mTranslate(advance / 2f, 0);
break;
case TextNode.TEXT_ANCHOR_END:
tx.mTranslate(advance, 0);
break;
}
// Scale according to the fontSize
float fontSize = trp.getFontSize();
if (fontSize > 0) {
tx.mScale(1 / fontSize);
}
// Position the text chunk on the current
// text position.
tx.mTranslate(-x, -y);
| protected void | applyTransform(com.sun.perseus.j2d.TextRenderingProperties trp, com.sun.perseus.j2d.Transform tx)Applies the chunk's position adjustment due to the text anchor's
value.
// Position the text chunk on the current
// text position.
tx.mTranslate(x, y);
// Scale according to the fontSize
float fontSize = trp.getFontSize();
if (fontSize > 0) {
tx.mScale(fontSize);
}
// Account for the text-anchor translation
switch (trp.getTextAnchor()) {
default:
break;
case TextNode.TEXT_ANCHOR_MIDDLE:
tx.mTranslate(-advance / 2f, 0);
break;
case TextNode.TEXT_ANCHOR_END:
tx.mTranslate(-advance, 0);
break;
}
| void | drawText(com.sun.perseus.j2d.RenderGraphics rg, com.sun.perseus.j2d.Transform tx)Draws text.
GlyphProxy c = firstChild;
float strokeWidth = rg.getStrokeWidth();
float dashOffset = rg.getStrokeDashOffset();
float[] dashArray = rg.getStrokeDashArray();
if ((dashArray != null) &&
((helperDashArray == null) ||
(helperDashArray.length != dashArray.length))) {
helperDashArray = new float[dashArray.length];
}
float lastEMSquareScale = 0;
while (c != null) {
ownerDocument.paintGlyphTxf.setTransform(tx);
c.applyTransform(ownerDocument.paintGlyphTxf);
rg.setTransform(ownerDocument.paintGlyphTxf);
if (lastEMSquareScale != c.proxied.emSquareScale) {
rg.setStrokeWidth(strokeWidth / c.proxied.emSquareScale);
if (dashArray != null) {
float emSquareScale = c.proxied.emSquareScale;
float lengthSum = 0;
for (int i = 0; i < dashArray.length; ++i) {
helperDashArray[i] = dashArray[i] / emSquareScale;
lengthSum += dashArray[i];
}
float reducedDashOffset = dashOffset;
if (lengthSum > 0) {
int r = (int)(dashOffset / lengthSum);
reducedDashOffset -= r * lengthSum;
}
rg.setStrokeDashArray(helperDashArray);
rg.setStrokeDashOffset(reducedDashOffset / emSquareScale);
}
lastEMSquareScale = c.proxied.emSquareScale;
}
if (c.proxied.d != null) {
rg.draw(c.proxied.d);
}
c = c.nextSibling;
}
// Restore stroke-width property.
rg.setStrokeWidth(strokeWidth);
if (dashArray != null) {
// Restore dash array & offset
rg.setStrokeDashArray(dashArray);
rg.setStrokeDashOffset(dashOffset);
}
| void | fillText(com.sun.perseus.j2d.RenderGraphics rg, com.sun.perseus.j2d.Transform tx)Fills text.
GlyphProxy c = firstChild;
while (c != null) {
ownerDocument.paintGlyphTxf.setTransform(tx);
c.applyTransform(ownerDocument.paintGlyphTxf);
rg.setTransform(ownerDocument.paintGlyphTxf);
if (c.proxied.d != null) {
rg.fill(c.proxied.d);
}
c = c.nextSibling;
}
| protected boolean | isHitVP(float[] pt, com.sun.perseus.j2d.TextRenderingProperties trp, com.sun.perseus.j2d.Transform chunkTxf)Returns true if this node is hit by the input point. The input point
is in viewport space. By default, a node is not hit, not
matter what the input coordinate is.
GlyphProxy c = lastChild;
while (c != null) {
ownerDocument.hitGlyphTxf.setTransform(1, 0, 0, 1, 0, 0);
c.applyInverseTransform(ownerDocument.hitGlyphTxf);
ownerDocument.hitGlyphTxf.mMultiply(chunkTxf);
ownerDocument.hitGlyphTxf.transformPoint(pt, ownerDocument.upt);
if (c.isHit(ownerDocument.upt, trp)) {
return true;
}
c = c.prevSibling;
}
return false;
| public java.lang.String | toString()
return "GlyphLayout[x=" + x + ", y=" + y
+ " advance=" + advance + "]";
|
|