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

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: ก่อนทำการบิตชิฟท์ค่าของสี.


ดูเพิ่มเติม

 ภาษาไทย