TextStyle

TextStyle — Aspose.Note FOSS for Python API Reference

类:TextStyle

Properties: aspose.note Properties: from aspose.note import TextStyle Properties: Node

TextStyle 携带单个字符的完整每字符格式属性集 TextRun.它通过 TextRun.Style.所有布尔标志默认为 False;;所有可选字段默认为 None.


Properties

所有属性均为读写。.

Properties

PropertiesPropertiesPropertiesProperties
FontName`strNone`None
FontSize`floatNone`None
FontColor`intNone`None
Highlight`intNone`None

样式标志

PropertiesPropertiesPropertiesProperties
BoldboolFalse粗体权重
ItalicboolFalseProperties
UnderlineboolFalseProperties
StrikethroughboolFalseProperties
SuperscriptboolFalse上标基线
SubscriptboolFalse下标基线

Properties

PropertiesPropertiesPropertiesProperties
Language`intNone`None

Properties

PropertiesPropertiesPropertiesProperties
IsHyperlinkboolFalseTrue 当此运行是可点击的超链接时。.
HyperlinkAddress`strNone`None

ARGB 颜色编码

FontColorHighlightColor 以打包的 32 位 ARGB 整数形式存储,匹配 MS-ONE 二进制格式。要解码它们::

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})")

使用示例

打印每个 run 的格式属性

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
    for run in rt.TextRuns:
        s = run.Style
        parts = []
        if s.IsBold:           parts.append("bold")
        if s.IsItalic:         parts.append("italic")
        if s.IsUnderline:      parts.append("underline")
        if s.IsStrikethrough:  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}")

收集所有唯一样式的片段

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
bold_runs = []
for rt in doc.GetChildNodes(RichText):
    for run in rt.TextRuns:
        if run.Style.IsBold and run.Text.strip():
            bold_runs.append(run.Text)

print(f"Bold segments ({len(bold_runs)}):", bold_runs)

None 安全性

Properties None-typed 属性可能是 None 当属性在源文件中缺失时。始终使用 if s.FontColor is not None: 在位移颜色值之前。.


另见

 中文