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

PropertyTypeDefaultDescription
FontNamestr | NoneNoneFont family name (e.g. "Calibri", "Arial"). None means the parent style is inherited.
FontSizefloat | NoneNoneFont size in points. None means inherited.
FontColorint | NoneNoneFont colour as a packed ARGB integer. None means inherited.
HighlightColorint | NoneNoneBackground highlight colour as a packed ARGB integer. None means no highlight.

Style Flags

PropertyTypeDefaultDescription
BoldboolFalseBold weight
ItalicboolFalseItalic
UnderlineboolFalseUnderline
StrikethroughboolFalseStrikethrough
SuperscriptboolFalseSuperscript baseline
SubscriptboolFalseSubscript baseline

Language

PropertyTypeDefaultDescription
LanguageIdint | NoneNoneWindows LCID for the run’s language (e.g. 1033 = en-US). None means unspecified.

Hyperlink

PropertyTypeDefaultDescription
IsHyperlinkboolFalseTrue when this run is a clickable hyperlink.
HyperlinkAddressstr | NoneNoneTarget 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