Package org.apache.batik.bridge
Class GlyphLayout
- java.lang.Object
-
- org.apache.batik.bridge.GlyphLayout
-
- All Implemented Interfaces:
TextSpanLayout
- Direct Known Subclasses:
FlowExtGlyphLayout,FlowGlyphLayout
public class GlyphLayout extends java.lang.Object implements TextSpanLayout
Implementation of TextSpanLayout which uses java.awt.font.GlyphVector.- Version:
- $Id: GlyphLayout.java 1804130 2017-08-04 14:41:11Z ssteiner $
- See Also:
TextSpanLayout
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.AttributedCharacterIteratoraciprivate booleanadjSpacingprotected java.awt.geom.Point2Dadvanceprivate static java.text.AttributedCharacterIterator.AttributeBASELINE_SHIFTprivate int[]charMapprivate static java.text.AttributedCharacterIterator.AttributeDXprivate static java.text.AttributedCharacterIterator.AttributeDYstatic doubleepsstatic java.text.AttributedCharacterIterator.AttributeFLOW_EMPTY_PARAGRAPHstatic java.text.AttributedCharacterIterator.AttributeFLOW_LINE_BREAKstatic java.text.AttributedCharacterIterator.AttributeFLOW_PARAGRAPHprivate GVTFontfontprivate float[]glyphAdvancesprotected GVTGlyphVectorgvstatic java.text.AttributedCharacterIterator.AttributeGVT_FONTstatic java.text.AttributedCharacterIterator.AttributeHORIZONTAL_ORIENTATION_ANGLEprivate booleanisAltGlyphprotected booleanlayoutAppliedstatic java.text.AttributedCharacterIterator.AttributeLINE_HEIGHTprivate GVTLineMetricsmetricsprivate java.awt.geom.Point2Doffsetprivate static java.lang.IntegerORIENTATION_AUTOprivate booleanpathAppliedprivate static java.text.AttributedCharacterIterator.AttributeROTATIONprotected static java.util.SetrunAttsprivate booleanspacingAppliedprotected static java.util.SetszAttsprivate TextPathtextPathprivate java.awt.geom.Point2DtextPathAdvanceprivate booleanverticalstatic java.text.AttributedCharacterIterator.AttributeVERTICAL_ORIENTATIONstatic java.text.AttributedCharacterIterator.AttributeVERTICAL_ORIENTATION_ANGLEprivate static java.text.AttributedCharacterIterator.AttributeWRITING_MODEprivate static java.lang.IntegerWRITING_MODE_TTBprivate static java.text.AttributedCharacterIterator.AttributeXprivate floatxScaleprivate static java.text.AttributedCharacterIterator.AttributeYprivate floatyScale-
Fields inherited from interface org.apache.batik.bridge.TextSpanLayout
DECORATION_ALL, DECORATION_OVERLINE, DECORATION_STRIKETHROUGH, DECORATION_UNDERLINE
-
-
Constructor Summary
Constructors Constructor Description GlyphLayout(java.text.AttributedCharacterIterator aci, int[] charMap, java.awt.geom.Point2D offset, java.awt.font.FontRenderContext frc)Creates the specified text layout using the specified AttributedCharacterIterator and rendering context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddPtsToPath(java.awt.geom.GeneralPath shape, java.awt.geom.Point2D.Float[] topPts, java.awt.geom.Point2D.Float[] botPts, int numPts)protected voidadjustTextSpacing()Does any spacing adjustments that may have been specified.protected voidapplyStretchTransform(boolean stretchGlyphs)Stretches the text so that it becomes the specified length.protected voiddoExplicitGlyphLayout()Explicitly lays out each of the glyphs in the glyph vector.protected voiddoPathLayout()If this layout is on a text path, positions the characters along the path.protected java.awt.geom.Point2DdoSpacing(java.lang.Float kern, java.lang.Float letterSpacing, java.lang.Float wordSpacing)Performs any spacing adjustments required and returns the new advance value.voiddraw(java.awt.Graphics2D g2d)Paints the text layout using the specified Graphics2D and rendering context.static booleanepsEQ(double a, double b)java.awt.geom.Point2DgetAdvance2D()Returns the current text position at the completion of glyph layout.java.awt.geom.Rectangle2DgetBounds2D()Returns the rectangular bounds of the completed glyph layout.intgetCharacterCount(int startGlyphIndex, int endGlyphIndex)Returns the number of chars represented by the glyphs within the specified range.doublegetComputedOrientationAngle(int index)Return the angle value according to the orientation of the character.java.awt.ShapegetDecorationOutline(int decorationType)Returns the outline of the specified decorations on the glyphs,protected GVTFontgetFont()Returns the GVTFont to use when rendering the specified character iterator.java.awt.geom.Rectangle2DgetGeometricBounds()Returns the rectangular bounds of the completed glyph layout, inclusive of "decoration" (underline, overline, etc.)float[]getGlyphAdvances()Returns the advance between each glyph in text progression direction.intgetGlyphCount()Returns the number of glyphs in this layout.intgetGlyphIndex(int charIndex)Returns the index of the first glyph that has the specified char index.GVTGlyphMetricsgetGlyphMetrics(int glyphIndex)Returns the Metrics for a particular glyph.protected intgetGlyphOrientationAngle()Returns the value of the vertical glyph orientation angle.GVTGlyphVectorgetGlyphVector()Return the glyph vector asociated to this layout.java.awt.ShapegetHighlightShape(int beginCharIndex, int endCharIndex)Returns a Shape which encloses the currently selected glyphs as specified by the character indices.intgetLastGlyphIndex(int charIndex)Returns the index of the last glyph that has the specified char index.GVTLineMetricsgetLineMetrics()Returns the Line metrics for this text span.java.awt.geom.Point2DgetOffset()Returns the current text position at the beginning of glyph layout, before the application of explicit glyph positioning attributes.java.awt.ShapegetOutline()Returns the outline of the completed glyph layout.protected java.awt.ShapegetOverlineShape()Returns a shape describing the overline decoration for a given ACI.protected java.awt.ShapegetStrikethroughShape()Returns a shape describing the strikethrough line for a given ACI.java.awt.geom.Point2DgetTextPathAdvance()Returns the position to used when drawing a text run after this one.protected java.awt.ShapegetUnderlineShape()Returns a shape describing the undeline decoration for a given ACI.booleanhasCharacterIndex(int index)Return true is the character index is represented by glyphs in this layout.TextHithitTestChar(float x, float y)Perform hit testing for coordinate at x, y.booleanisAltGlyph()Return true if this text run represents an alt glyph.protected booleanisGlyphOrientationAuto()Returns whether or not the vertical glyph orientation value is "auto".protected booleanisLatinChar(char c)Returns true if the specified character is within one of the Latin unicode character blocks.booleanisLeftToRight()Returns true if the text direction in this layout is from left to right.booleanisOnATextPath()Returns true if this layout in on a text path.booleanisReversed()Return true if this text has been reversed.booleanisVertical()Returns true if the advance direction of this text is vertical.static intmakeConvexHull(java.awt.geom.Point2D.Float[] pts, int numPts)voidmaybeReverse(boolean mirror)Reverse (and optionally mirror) glyphs if not already reversed.static voidmergeAreas(java.awt.geom.GeneralPath shape, java.awt.geom.Area[] shapes, int nShapes)voidsetOffset(java.awt.geom.Point2D offset)Sets the text position used for the implicit origin of glyph layout.voidsetScale(float xScale, float yScale, boolean adjSpacing)Sets the scaling factor to use for string.private voidsyncLayout()This method makes certain that the layout has been completed at this point (much of the layout is done lazily).
-
-
-
Field Detail
-
gv
protected GVTGlyphVector gv
-
font
private GVTFont font
-
metrics
private GVTLineMetrics metrics
-
aci
private java.text.AttributedCharacterIterator aci
-
advance
protected java.awt.geom.Point2D advance
-
offset
private java.awt.geom.Point2D offset
-
xScale
private float xScale
-
yScale
private float yScale
-
textPath
private TextPath textPath
-
textPathAdvance
private java.awt.geom.Point2D textPathAdvance
-
charMap
private int[] charMap
-
vertical
private boolean vertical
-
adjSpacing
private boolean adjSpacing
-
glyphAdvances
private float[] glyphAdvances
-
isAltGlyph
private boolean isAltGlyph
-
layoutApplied
protected boolean layoutApplied
-
spacingApplied
private boolean spacingApplied
-
pathApplied
private boolean pathApplied
-
FLOW_LINE_BREAK
public static final java.text.AttributedCharacterIterator.Attribute FLOW_LINE_BREAK
-
FLOW_PARAGRAPH
public static final java.text.AttributedCharacterIterator.Attribute FLOW_PARAGRAPH
-
FLOW_EMPTY_PARAGRAPH
public static final java.text.AttributedCharacterIterator.Attribute FLOW_EMPTY_PARAGRAPH
-
LINE_HEIGHT
public static final java.text.AttributedCharacterIterator.Attribute LINE_HEIGHT
-
VERTICAL_ORIENTATION
public static final java.text.AttributedCharacterIterator.Attribute VERTICAL_ORIENTATION
-
VERTICAL_ORIENTATION_ANGLE
public static final java.text.AttributedCharacterIterator.Attribute VERTICAL_ORIENTATION_ANGLE
-
HORIZONTAL_ORIENTATION_ANGLE
public static final java.text.AttributedCharacterIterator.Attribute HORIZONTAL_ORIENTATION_ANGLE
-
X
private static final java.text.AttributedCharacterIterator.Attribute X
-
Y
private static final java.text.AttributedCharacterIterator.Attribute Y
-
DX
private static final java.text.AttributedCharacterIterator.Attribute DX
-
DY
private static final java.text.AttributedCharacterIterator.Attribute DY
-
ROTATION
private static final java.text.AttributedCharacterIterator.Attribute ROTATION
-
BASELINE_SHIFT
private static final java.text.AttributedCharacterIterator.Attribute BASELINE_SHIFT
-
WRITING_MODE
private static final java.text.AttributedCharacterIterator.Attribute WRITING_MODE
-
WRITING_MODE_TTB
private static final java.lang.Integer WRITING_MODE_TTB
-
ORIENTATION_AUTO
private static final java.lang.Integer ORIENTATION_AUTO
-
GVT_FONT
public static final java.text.AttributedCharacterIterator.Attribute GVT_FONT
-
runAtts
protected static java.util.Set runAtts
-
szAtts
protected static java.util.Set szAtts
-
eps
public static final double eps
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GlyphLayout
public GlyphLayout(java.text.AttributedCharacterIterator aci, int[] charMap, java.awt.geom.Point2D offset, java.awt.font.FontRenderContext frc)Creates the specified text layout using the specified AttributedCharacterIterator and rendering context.- Parameters:
aci- the AttributedCharacterIterator whose text is to be laid outcharMap- Indicates how chars in aci map to original text char array.offset- The offset position of this text layoutfrc- the FontRenderContext to use for generating glyphs.
-
-
Method Detail
-
getGlyphVector
public GVTGlyphVector getGlyphVector()
Description copied from interface:TextSpanLayoutReturn the glyph vector asociated to this layout.- Specified by:
getGlyphVectorin interfaceTextSpanLayout- Returns:
- glyph vector
-
getOffset
public java.awt.geom.Point2D getOffset()
Returns the current text position at the beginning of glyph layout, before the application of explicit glyph positioning attributes.- Specified by:
getOffsetin interfaceTextSpanLayout
-
setScale
public void setScale(float xScale, float yScale, boolean adjSpacing)Sets the scaling factor to use for string. if ajdSpacing is true then only the spacing between glyphs will be adjusted otherwise the glyphs and the spaces between them will be adjusted. Only the scale factor in the progression direction is used (x for horizontal text, y for vertical text ).- Specified by:
setScalein interfaceTextSpanLayout- Parameters:
xScale- Scale factor to apply in X direction.yScale- Scale factor to apply in Y direction.adjSpacing- True if only spaces should be adjusted.
-
setOffset
public void setOffset(java.awt.geom.Point2D offset)
Sets the text position used for the implicit origin of glyph layout. Ignored if multiple explicit glyph positioning attributes are present in ACI (e.g. if the aci has multiple X or Y values).- Specified by:
setOffsetin interfaceTextSpanLayout
-
getGlyphMetrics
public GVTGlyphMetrics getGlyphMetrics(int glyphIndex)
Description copied from interface:TextSpanLayoutReturns the Metrics for a particular glyph.- Specified by:
getGlyphMetricsin interfaceTextSpanLayout
-
getLineMetrics
public GVTLineMetrics getLineMetrics()
Description copied from interface:TextSpanLayoutReturns the Line metrics for this text span.- Specified by:
getLineMetricsin interfaceTextSpanLayout
-
isVertical
public boolean isVertical()
Returns true if the advance direction of this text is vertical.- Specified by:
isVerticalin interfaceTextSpanLayout
-
isOnATextPath
public boolean isOnATextPath()
Returns true if this layout in on a text path.- Specified by:
isOnATextPathin interfaceTextSpanLayout
-
getGlyphCount
public int getGlyphCount()
Returns the number of glyphs in this layout.- Specified by:
getGlyphCountin interfaceTextSpanLayout
-
getCharacterCount
public int getCharacterCount(int startGlyphIndex, int endGlyphIndex)Returns the number of chars represented by the glyphs within the specified range.- Specified by:
getCharacterCountin interfaceTextSpanLayout- Parameters:
startGlyphIndex- The index of the first glyph in the range.endGlyphIndex- The index of the last glyph in the range.- Returns:
- The number of chars.
-
isLeftToRight
public boolean isLeftToRight()
Returns true if the text direction in this layout is from left to right.- Specified by:
isLeftToRightin interfaceTextSpanLayout
-
syncLayout
private final void syncLayout()
This method makes certain that the layout has been completed at this point (much of the layout is done lazily).
-
draw
public void draw(java.awt.Graphics2D g2d)
Paints the text layout using the specified Graphics2D and rendering context.- Specified by:
drawin interfaceTextSpanLayout- Parameters:
g2d- the Graphics2D to use
-
getAdvance2D
public java.awt.geom.Point2D getAdvance2D()
Returns the current text position at the completion of glyph layout.- Specified by:
getAdvance2Din interfaceTextSpanLayout
-
getOutline
public java.awt.Shape getOutline()
Returns the outline of the completed glyph layout.- Specified by:
getOutlinein interfaceTextSpanLayout
-
getGlyphAdvances
public float[] getGlyphAdvances()
Description copied from interface:TextSpanLayoutReturns the advance between each glyph in text progression direction.- Specified by:
getGlyphAdvancesin interfaceTextSpanLayout
-
getDecorationOutline
public java.awt.Shape getDecorationOutline(int decorationType)
Returns the outline of the specified decorations on the glyphs,- Specified by:
getDecorationOutlinein interfaceTextSpanLayout- Parameters:
decorationType- an integer indicating the type(s) of decorations included in this shape. May be the result of "OR-ing" several values together: e.g.DECORATION_UNDERLINE | DECORATION_STRIKETHROUGH
-
getBounds2D
public java.awt.geom.Rectangle2D getBounds2D()
Returns the rectangular bounds of the completed glyph layout.- Specified by:
getBounds2Din interfaceTextSpanLayout
-
getGeometricBounds
public java.awt.geom.Rectangle2D getGeometricBounds()
Returns the rectangular bounds of the completed glyph layout, inclusive of "decoration" (underline, overline, etc.)- Specified by:
getGeometricBoundsin interfaceTextSpanLayout
-
getTextPathAdvance
public java.awt.geom.Point2D getTextPathAdvance()
Returns the position to used when drawing a text run after this one. It takes into account the text path layout if there is one.- Specified by:
getTextPathAdvancein interfaceTextSpanLayout
-
getGlyphIndex
public int getGlyphIndex(int charIndex)
Returns the index of the first glyph that has the specified char index.- Specified by:
getGlyphIndexin interfaceTextSpanLayout- Parameters:
charIndex- The original index of the character in the text node's text string.- Returns:
- The index of the matching glyph in this layout's glyph vector, or -1 if a matching glyph could not be found.
-
getLastGlyphIndex
public int getLastGlyphIndex(int charIndex)
Returns the index of the last glyph that has the specified char index.- Parameters:
charIndex- The original index of the character in the text node's text string.- Returns:
- The index of the matching glyph in this layout's glyph vector, or -1 if a matching glyph could not be found.
-
getComputedOrientationAngle
public double getComputedOrientationAngle(int index)
Return the angle value according to the orientation of the character.- Specified by:
getComputedOrientationAnglein interfaceTextSpanLayout- Parameters:
index- index of the character in the ACI- Returns:
- rotation angle
-
getHighlightShape
public java.awt.Shape getHighlightShape(int beginCharIndex, int endCharIndex)Returns a Shape which encloses the currently selected glyphs as specified by the character indices.- Specified by:
getHighlightShapein interfaceTextSpanLayout- Parameters:
beginCharIndex- the index of the first char in the contiguous selection.endCharIndex- the index of the last char in the contiguous selection.- Returns:
- The highlight shape or null if the spacified char range does not overlap with the chars in this layout.
-
epsEQ
public static boolean epsEQ(double a, double b)
-
makeConvexHull
public static int makeConvexHull(java.awt.geom.Point2D.Float[] pts, int numPts)
-
addPtsToPath
public static void addPtsToPath(java.awt.geom.GeneralPath shape, java.awt.geom.Point2D.Float[] topPts, java.awt.geom.Point2D.Float[] botPts, int numPts)
-
mergeAreas
public static void mergeAreas(java.awt.geom.GeneralPath shape, java.awt.geom.Area[] shapes, int nShapes)
-
hitTestChar
public TextHit hitTestChar(float x, float y)
Perform hit testing for coordinate at x, y.- Specified by:
hitTestCharin interfaceTextSpanLayout- Parameters:
x- the x coordinate of the point to be tested.y- the y coordinate of the point to be tested.- Returns:
- a TextHit object encapsulating the character index for successful hits and whether the hit is on the character leading edge.
-
getFont
protected GVTFont getFont()
Returns the GVTFont to use when rendering the specified character iterator. This should already be set as an attribute on the aci.- Returns:
- The GVTFont to use.
-
getOverlineShape
protected java.awt.Shape getOverlineShape()
Returns a shape describing the overline decoration for a given ACI.
-
getUnderlineShape
protected java.awt.Shape getUnderlineShape()
Returns a shape describing the undeline decoration for a given ACI.
-
getStrikethroughShape
protected java.awt.Shape getStrikethroughShape()
Returns a shape describing the strikethrough line for a given ACI.
-
doExplicitGlyphLayout
protected void doExplicitGlyphLayout()
Explicitly lays out each of the glyphs in the glyph vector. This will handle any glyph position adjustments such as dx, dy and baseline offsets. It will also handle vertical layouts.
-
adjustTextSpacing
protected void adjustTextSpacing()
Does any spacing adjustments that may have been specified.
-
doSpacing
protected java.awt.geom.Point2D doSpacing(java.lang.Float kern, java.lang.Float letterSpacing, java.lang.Float wordSpacing)Performs any spacing adjustments required and returns the new advance value.- Parameters:
kern- The kerning adjustment to apply to the space between each char.letterSpacing- The amount of spacing required between each char.wordSpacing- The amount of spacing required between each word.
-
applyStretchTransform
protected void applyStretchTransform(boolean stretchGlyphs)
Stretches the text so that it becomes the specified length.- Parameters:
stretchGlyphs- if true xScale, yScale will be applied to each glyphs transform.
-
doPathLayout
protected void doPathLayout()
If this layout is on a text path, positions the characters along the path.
-
isLatinChar
protected boolean isLatinChar(char c)
Returns true if the specified character is within one of the Latin unicode character blocks.- Parameters:
c- The char to test.- Returns:
- True if c is latin.
-
isGlyphOrientationAuto
protected boolean isGlyphOrientationAuto()
Returns whether or not the vertical glyph orientation value is "auto".
-
getGlyphOrientationAngle
protected int getGlyphOrientationAngle()
Returns the value of the vertical glyph orientation angle. This will be one of 0, 90, 180 or 270.
-
hasCharacterIndex
public boolean hasCharacterIndex(int index)
Return true is the character index is represented by glyphs in this layout.- Specified by:
hasCharacterIndexin interfaceTextSpanLayout- Parameters:
index- index of the character in the ACI.- Returns:
- true if the layout represents that character.
-
isAltGlyph
public boolean isAltGlyph()
Return true if this text run represents an alt glyph.- Specified by:
isAltGlyphin interfaceTextSpanLayout
-
isReversed
public boolean isReversed()
Description copied from interface:TextSpanLayoutReturn true if this text has been reversed.- Specified by:
isReversedin interfaceTextSpanLayout
-
maybeReverse
public void maybeReverse(boolean mirror)
Description copied from interface:TextSpanLayoutReverse (and optionally mirror) glyphs if not already reversed.- Specified by:
maybeReversein interfaceTextSpanLayout
-
-