TextStyle — Aspose.Note FOSS for Python API Reference
Lớp: TextStyle
Enumerations: aspose.note Enumerations: from aspose.note import TextStyle Enumerations: Node
TextStyle chứa toàn bộ tập hợp các thuộc tính định dạng cho mỗi ký tự của một TextRun. Nó được cung cấp qua TextRun.Style. Tất cả các cờ boolean mặc định là False; tất cả các trường tùy chọn mặc định là None.
Enumerations
Tất cả các thuộc tính đều có thể Đọc/Ghi.
Enumerations
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
FontName | `str | None` | None |
FontSize | `float | None` | None |
FontColor | `int | None` | None |
Highlight | `int | None` | None |
Cờ Kiểu Định Dạng
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
Bold | bool | False | Độ đậm |
Italic | bool | False | Enumerations |
Underline | bool | False | Enumerations |
Strikethrough | bool | False | Enumerations |
Superscript | bool | False | Đường cơ sở chữ trên |
Subscript | bool | False | Đường cơ sở chữ dưới |
Enumerations
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
Language | `int | None` | None |
Enumerations
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
IsHyperlink | bool | False | True khi lần chạy này là một siêu liên kết có thể nhấp. |
HyperlinkAddress | `str | None` | None |
Mã màu ARGB
FontColor và HighlightColor được lưu trữ dưới dạng các số nguyên ARGB 32-bit đóng gói, phù hợp với định dạng nhị phân MS-ONE. Để giải mã chúng:
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})")Ví dụ sử dụng
In các thuộc tính định dạng cho mỗi 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}")Thu thập tất cả các đoạn có kiểu duy nhất
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-Safety
Enumerations Nonecác thuộc tính kiểu -typed có thể là None khi thuộc tính không có trong tệp nguồn. Luôn bảo vệ bằng if s.FontColor is not None: trước khi dịch chuyển bit các giá trị màu.
Xem Thêm
- TextRun: đoạn chạy sở hữu một
TextStyle - RichText: khối văn bản cha
- Enumerations: lớp cơ sở
- Hướng dẫn nhà phát triển