Format ranges of text as subscript or superscript for prices, formulas, footnotes, and technical notation.
CE.SDK formats superscript and subscript synthetically: the affected range is scaled down to 58.3% of its font size and shifted up or down by 33.3% of the unscaled font size. These defaults match common design applications, so the feature works with every font, and block properties let you adjust the scale and shift. Lines grow automatically when a shifted range needs more room, and exports include the shifted glyphs. Superscript and subscript combine with text decorations, text on a path, and text animations.
Apply Superscript#
Raise a range above the baseline using engine.block.setTextScriptStyle() with ScriptStyle.SUPERSCRIPT and UTF-16 indices [from, to). Without a range, the whole text or the current selection is changed.
// Raise the cents of the price above the baseline.// Superscript text is scaled down and raised automatically.engine.block.setTextScriptStyle(text, scriptStyle = ScriptStyle.SUPERSCRIPT, from = 3, to = 5)
// Raise the exponent of the formulaengine.block.setTextScriptStyle(text, scriptStyle = ScriptStyle.SUPERSCRIPT, from = 14, to = 15)Apply Subscript#
Lower a range below the baseline with ScriptStyle.SUBSCRIPT.
// Lower the "2" of the water formula below the baselineengine.block.setTextScriptStyle(text, scriptStyle = ScriptStyle.SUBSCRIPT, from = 7, to = 8)Query Script Styles#
Query the script styles using engine.block.getTextScriptStyles(). It returns the ordered list of unique values in the range: NORMAL, SUPERSCRIPT, or SUBSCRIPT.
// Query the unique script styles in a range, in document orderval scriptStyles = engine.block.getTextScriptStyles(text)// e.g. [NORMAL, SUPERSCRIPT, SUBSCRIPT]
// Query a specific rangeval centsScriptStyle = engine.block.getTextScriptStyles(text, from = 3, to = 5)// [SUPERSCRIPT]Text Runs#
Each entry returned by engine.block.getTextRuns() reports the scriptStyle of that run alongside its other formatting properties.
// Each text run reports its script styleval runs = engine.block.getTextRuns(text)// e.g. runs[1].scriptStyle == ScriptStyle.SUPERSCRIPTAdjust Size and Position#
Four block properties control how superscript and subscript are rendered. The font scale is a factor of the font size, the vertical shift is a fraction of the unscaled font size. The properties apply to all shifted ranges in the block.
// Adjust the size and position of shifted text for the whole block.// The scale is a factor of the font size. The shift is a fraction of// the unscaled font size.engine.block.setFloat(text, property = "text/superscriptFontScale", value = 0.65F)engine.block.setFloat(text, property = "text/superscriptVerticalShift", value = 0.4F)engine.block.setFloat(text, property = "text/subscriptFontScale", value = 0.65F)engine.block.setFloat(text, property = "text/subscriptVerticalShift", value = 0.25F)Reset to Normal#
Reset a range back to the regular baseline with ScriptStyle.NORMAL.
// Reset a range back to the normal baselineengine.block.setTextScriptStyle(text, scriptStyle = ScriptStyle.NORMAL, from = 14, to = 15)API Reference#
| Method | Purpose |
|---|---|
engine.block.setTextScriptStyle() |
Set the script style for entire text or range |
engine.block.getTextScriptStyles() |
Get ordered list of unique script styles in range |
engine.block.getTextRuns() |
Read the scriptStyle of each text run |
text/superscriptFontScale |
Font scale of superscript text, default 0.583 |
text/superscriptVerticalShift |
Upward shift of superscript text, default 0.333 |
text/subscriptFontScale |
Font scale of subscript text, default 0.583 |
text/subscriptVerticalShift |
Downward shift of subscript text, default 0.333 |