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 ถูกจัดเก็บเป็นจำนวนเต็ม ARGB 32‑บิตแบบบรรจุ (packed) ซึ่งตรงกับรูปแบบไบนารีของ 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})")ตัวอย่างการใช้งาน
พิมพ์คุณลักษณะการจัดรูปแบบสำหรับแต่ละรัน
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: ชุดที่เป็นเจ้าของ
TextStyle - RichText: บล็อกข้อความแม่
- Properties: คลาสฐาน
- คู่มือผู้พัฒนา