Class ShapingEngine
- All Implemented Interfaces:
Disposable
ShapingEngine
class represents text shaping engine.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Releases the native memory of this object.static ShapingEngine
finalizable
(ShapingEngine shapingEngine) Wraps a shaping engine object into a finalizable instance which is guaranteed to be disposed automatically by the GC when no longer in use.int
Returns the language tag which this shaping engine will use for shaping text.Returns the user-specified open type feature settings.static WritingDirection
getScriptDirection
(int scriptTag) Returns the default writing direction of a script.int
Returns the script tag which this shaping engine will use for shaping text.Returns the order in which this shaping engine will process the text.Returns the typeface which this shaping engine will use for shaping text.float
Returns the type size which this shaping engine will use for shaping text.Returns the direction in which this shaping engine will place the resultant glyphs.static boolean
isFinalizable
(ShapingEngine shapingEngine) Checks whether a shaping engine object is finalizable or not.void
setLanguageTag
(int languageTag) Sets the language tag which this shaping engine will use for shaping text.void
setOpenTypeFeatures
(Set<OpenTypeFeature> features) Sets the user-specified open type feature settings.void
setScriptTag
(int scriptTag) Sets the script tag which this shaping engine will use for shaping text.void
setShapingOrder
(ShapingOrder shapingOrder) Sets the order in which this shaping engine will process the text.void
setTypeface
(Typeface typeface) Sets the typeface which this shaping engine will use for shaping text.void
setTypeSize
(float typeSize) Sets the type size which this shaping engine will use for shaping text.void
setWritingDirection
(WritingDirection writingDirection) Sets the direction in which this shaping engine will place the resultant glyphs.Shapes the specified range of text into glyphs.toString()
-
Constructor Details
-
ShapingEngine
public ShapingEngine()Constructs a shaping engine object.
-
-
Method Details
-
finalizable
Wraps a shaping engine object into a finalizable instance which is guaranteed to be disposed automatically by the GC when no longer in use. After calling this method,dispose()
should not be called on either original object or returned object. Callingdispose()
on returned object will throw anUnsupportedOperationException
.Note: The behavior is undefined if the passed-in object is already disposed or wrapped into another finalizable instance.
- Parameters:
shapingEngine
- The shaping engine object to wrap into a finalizable instance.- Returns:
- The finalizable instance of the passed-in shaping engine object.
-
isFinalizable
Checks whether a shaping engine object is finalizable or not.- Parameters:
shapingEngine
- The shaping engine object to check.- Returns:
true
if the passed-in shaping engine object is finalizable,false
otherwise.
-
getScriptDirection
Returns the default writing direction of a script.- Parameters:
scriptTag
- The tag of the script whose default direction is returned.- Returns:
- The default writing direction of the script identified by
scriptTag
.
-
getTypeface
Returns the typeface which this shaping engine will use for shaping text.- Returns:
- This current typeface.
-
setTypeface
Sets the typeface which this shaping engine will use for shaping text.- Parameters:
typeface
- The new typeface.
-
getTypeSize
public float getTypeSize()Returns the type size which this shaping engine will use for shaping text.- Returns:
- This current type size.
-
setTypeSize
public void setTypeSize(float typeSize) Sets the type size which this shaping engine will use for shaping text.- Parameters:
typeSize
- The new type size.
-
getScriptTag
public int getScriptTag()Returns the script tag which this shaping engine will use for shaping text. The default value is'DFLT'
.- Returns:
- The current script tag.
-
setScriptTag
public void setScriptTag(int scriptTag) Sets the script tag which this shaping engine will use for shaping text. The default value is'DFLT'
.A tag can be created from string by using
SfntTag.make(String)
method.- Parameters:
scriptTag
- The new script tag.
-
getLanguageTag
public int getLanguageTag()Returns the language tag which this shaping engine will use for shaping text. The default value is'dflt'
.- Returns:
- The current language tag.
-
setLanguageTag
public void setLanguageTag(int languageTag) Sets the language tag which this shaping engine will use for shaping text. The default value is'dflt'
.A tag can be created from string by using
SfntTag.make(String)
method.- Parameters:
languageTag
- The new language tag.
-
getOpenTypeFeatures
Returns the user-specified open type feature settings.- Returns:
- A set of open type features.
-
setOpenTypeFeatures
Sets the user-specified open type feature settings. If the value of a feature is set to zero, it would be disabled provided that it is not a required feature of the chosen script. If the value of a feature is greater than zero, it would be enabled. In case of an alternate feature, this value would be used to pick the alternate glyph at this position.- Parameters:
features
- A set of open type features.
-
getWritingDirection
Returns the direction in which this shaping engine will place the resultant glyphs. The default value isWritingDirection.LEFT_TO_RIGHT
.- Returns:
- The current writing direction.
-
setWritingDirection
Sets the direction in which this shaping engine will place the resultant glyphs. The default value isWritingDirection.LEFT_TO_RIGHT
.The value of
writingDirection
must reflect the rendering direction of source script so that cursive and mark glyphs are placed at appropriate locations. It should not be confused with the direction of a bidirectional run as that may not reflect the script direction if overridden explicitly.- Parameters:
writingDirection
- The new writing direction.
-
getShapingOrder
Returns the order in which this shaping engine will process the text. The default value isShapingOrder.FORWARD
.- Returns:
- The current shaping order.
-
setShapingOrder
Sets the order in which this shaping engine will process the text. The default value isShapingOrder.FORWARD
.This method provides a convenient way to shape a bidirectional run whose direction is opposite to that of script. For example, if the direction of a run, 'car' is explicitly set as right-to-left, backward order will automatically read it as 'rac' without reordering the original text.
- Parameters:
shapingOrder
- The new shaping order.
-
shapeText
Shapes the specified range of text into glyphs.The output glyphs in the
ShapingResult
object flow visually in writing direction. For left-to-right direction, the position of pen is incremented with glyph's advance after rendering it. Similarly, for right-to-left direction, the position of pen is decremented with glyph's advance after rendering it.- Parameters:
text
- The text to shape into glyphs.fromIndex
- The index of the first character (inclusive) to be shaped.toIndex
- The index of the last character (exclusive) to be shaped.- Returns:
- A non-finalizable instance of a
ShapingResult
object. - Throws:
IllegalStateException
- if current typeface isnull
.NullPointerException
- iftext
isnull
.IllegalArgumentException
- iffromIndex
is negative, ortoIndex
is greater thantext.length()
, orfromIndex
is greater thantoIndex
-
dispose
public void dispose()Description copied from interface:Disposable
Releases the native memory of this object. Failing to call this method will cause memory leaks.Note: The behavior is undefined if this method is called more than once on the same object.
- Specified by:
dispose
in interfaceDisposable
-
toString
-