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
| Properties | Properties | Properties | Properties |
|---|---|---|---|
FontName | `str | None` | None |
FontSize | `float | None` | None |
FontColor | `int | None` | None |
Highlight | `int | None` | None |
样式标志
| Properties | Properties | Properties | Properties |
|---|---|---|---|
Bold | bool | False | 粗体权重 |
Italic | bool | False | Properties |
Underline | bool | False | Properties |
Strikethrough | bool | False | Properties |
Superscript | bool | False | 上标基线 |
Subscript | bool | False | 下标基线 |
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
Language | `int | None` | None |
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
IsHyperlink | bool | False | True 当此运行是可点击的超链接时。. |
HyperlinkAddress | `str | None` | None |
ARGB 颜色编码
FontColor 和 HighlightColor 以打包的 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: 在位移颜色值之前。.
另见
- TextRun: 拥有 a 的运行
TextStyle - RichText: 父文本块
- Properties: 基类
- 开发者指南