TextStyle

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

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

Cờ Kiểu Định Dạng

EnumerationsEnumerationsEnumerationsEnumerations
BoldboolFalseĐộ đậm
ItalicboolFalseEnumerations
UnderlineboolFalseEnumerations
StrikethroughboolFalseEnumerations
SuperscriptboolFalseĐường cơ sở chữ trên
SubscriptboolFalseĐường cơ sở chữ dưới

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
Language`intNone`None

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
IsHyperlinkboolFalseTrue khi lần chạy này là một siêu liên kết có thể nhấp.
HyperlinkAddress`strNone`None

Mã màu ARGB

FontColorHighlightColor đượ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

 Tiếng Việt