TextStyle — Aspose.Note FOSS for Python API Reference
Class: TextStyle
Package: aspose.note
Import: from aspose.note import TextStyle
Inherits: Node
TextStyle carries the complete set of per-character formatting attributes for a single TextRun. It is exposed via TextRun.Style. All boolean flags default to False; all optional fields default to None.
Properties
All properties are Read/Write.
Typography
| Property | Type | Default | Description |
|---|---|---|---|
FontName | str | None | None | Font family name (e.g. "Calibri", "Arial"). None means the parent style is inherited. |
FontSize | float | None | None | Font size in points. None means inherited. |
FontColor | int | None | None | Font colour as a packed ARGB integer. None means inherited. |
HighlightColor | int | None | None | Background highlight colour as a packed ARGB integer. None means no highlight. |
Style Flags
| Property | Type | Default | Description |
|---|---|---|---|
Bold | bool | False | Bold weight |
Italic | bool | False | Italic |
Underline | bool | False | Underline |
Strikethrough | bool | False | Strikethrough |
Superscript | bool | False | Superscript baseline |
Subscript | bool | False | Subscript baseline |
Language
| Property | Type | Default | Description |
|---|---|---|---|
LanguageId | int | None | None | Windows LCID for the run’s language (e.g. 1033 = en-US). None means unspecified. |
Hyperlink
| Property | Type | Default | Description |
|---|---|---|---|
IsHyperlink | bool | False | True when this run is a clickable hyperlink. |
HyperlinkAddress | str | None | None | Target URL when IsHyperlink is True. |
ARGB Colour Encoding
FontColor and HighlightColor are stored as packed 32-bit ARGB integers, matching the MS-ONE binary format. To decode them:
argb = run.Style.FontColor
if argb is not None:
a = (argb >> 24) & 0xFF
r = (argb >> 16) & 0xFF
g = (argb >> 8) & 0xFF
b = argb & 0xFF
print(f"RGBA({r}, {g}, {b}, {a})")Usage Example
Print formatting attributes for every run
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
for run in rt.Runs:
s = run.Style
parts = []
if s.Bold: parts.append("bold")
if s.Italic: parts.append("italic")
if s.Underline: parts.append("underline")
if s.Strikethrough: parts.append("strikethrough")
if s.FontName: parts.append(f"font={s.FontName!r}")
if s.FontSize: parts.append(f"size={s.FontSize}pt")
if s.IsHyperlink: parts.append(f"href={s.HyperlinkAddress!r}")
label = ", ".join(parts) or "plain"
print(f" [{label}] {run.Text!r}")Collect all uniquely-styled segments
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
bold_runs = []
for rt in doc.GetChildNodes(RichText):
for run in rt.Runs:
if run.Style.Bold and run.Text.strip():
bold_runs.append(run.Text)
print(f"Bold segments ({len(bold_runs)}):", bold_runs)None-Safety
All None-typed properties may be None when the attribute is absent from the source file. Always guard with if s.FontColor is not None: before bit-shifting colour values.
See Also
- TextRun: the run that owns a
TextStyle - RichText: parent text block
- Node: base class
- Developer Guide