TextFormatter 類別

定義

使用自訂文字配置用戶端提供格式化文字和分隔文字行的服務。Provides services for formatting text and breaking text lines using a custom text layout client.

public ref class TextFormatter abstract : IDisposable
public abstract class TextFormatter : IDisposable
type TextFormatter = class
    interface IDisposable
Public MustInherit Class TextFormatter
Implements IDisposable
繼承
TextFormatter
實作

範例

下列範例會示範如何使用 TextFormatter 物件來產生格式化的文字行,以顯示為繪圖物件。The following example shows how to use a TextFormatter object to generate formatted lines of text that can be displayed as drawing objects.

// Create a TextFormatter object.
TextFormatter formatter = TextFormatter.Create();

// Create common paragraph property settings.
CustomTextParagraphProperties customTextParagraphProperties
    = new CustomTextParagraphProperties();

// Format each line of text from the text store and draw it.
while (textStorePosition < customTextSource.Text.Length)
{
    // Create a textline from the text store using the TextFormatter object.
    using (TextLine myTextLine = formatter.FormatLine(
        customTextSource,
        textStorePosition,
        96 * 6,
        customTextParagraphProperties,
        null))
    {
        // Draw the formatted text into the drawing context.
        myTextLine.Draw(drawingContext, linePosition, InvertAxes.None);

        // Update the index position in the text store.
        textStorePosition += myTextLine.Length;

        // Update the line position coordinate for the displayed line.
        linePosition.Y += myTextLine.Height;
    }
}
' Create a TextFormatter object.
Dim formatter As TextFormatter = TextFormatter.Create()

' Create common paragraph property settings.
Dim customTextParagraphProperties As New CustomTextParagraphProperties()

' Format each line of text from the text store and draw it.
Do While textStorePosition < customTextSource.Text.Length
    ' Create a textline from the text store using the TextFormatter object.
    Using myTextLine As TextLine = formatter.FormatLine(customTextSource, textStorePosition, 96 * 6, customTextParagraphProperties, Nothing)
        ' Draw the formatted text into the drawing context.
        myTextLine.Draw(drawingContext, linePosition, InvertAxes.None)

        ' Update the index position in the text store.
        textStorePosition += myTextLine.Length

        ' Update the line position coordinate for the displayed line.
        linePosition.Y += myTextLine.Height
    End Using
Loop

備註

TextFormatterWPFWPF 的文字引擎,可提供用來格式化文字和斷線文字的服務。TextFormatter is the WPFWPF text engine that provides services for formatting text and breaking text lines. TextFormatter 可以處理不同的文字字元格式和段落樣式,且包含國際文字版面配置的支援。TextFormatter can handle different text character formats and paragraph styles, and includes support for international text layout.

不同于傳統文字 API,TextFormatter 會透過一組回呼方法與文字佈局用戶端互動。Unlike a traditional text API, the TextFormatter interacts with a text layout client through a set of callback methods. 它要求用戶端在 TextSource 類別的執行中提供這些方法。It requires the client to provide these methods in an implementation of the TextSource class. 下圖解說文字格式子客戶端和文字版面配置用戶端的互動。The following diagram illustrates the interaction of the text formatter client and the text layout client.

文字版面配置用戶端和 TextFormatter 的圖表Diagram of text layout client and TextFormatter
文字佈局用戶端與 TextFormatter 物件之間的互動Interaction between the text layout client and the TextFormatter object

文字格式服務Text Formatting Services

TextFormatter 提供文字功能的支援,例如 OpenType 印刷樣式,以及文字執行、線條和段落層級功能的支援。TextFormatter provides support for text features, such as OpenType typography, as well as support for text run, line, and paragraph level features.

下表是 TextFormatter 支援的文字功能服務的索引鍵清單。The following table is a list of the key TextFormatter supported services for text features.

功能Feature 說明Description
背景筆刷Background brush 用於背景色彩的 BrushThe Brush that is used for the background color. 請參閱 BackgroundBrush 屬性。See the BackgroundBrush property.
基準對齊Baseline alignment 決定線條的基準距離。Determines the baseline distance of the line. 請參閱 BaselineAlignment 屬性。See the BaselineAlignment property.
字型連結Font linking 透過使用複合字型來提供字型連結。Provides font linking through the use of composite fonts.
前景筆刷Foreground brush 用於前景色彩的 BrushThe Brush that is used for the foreground color. 請參閱 ForegroundBrush 屬性。See the ForegroundBrush property.
OpenTypeOpenType 先進的 OpenType 印刷樣式功能,這類內容相關的替代和標準的連字。Advanced OpenType typographic features, such contextual alternates and standard ligatures. 請參閱 TextRunTypographyProperties 類別屬性。See the TextRunTypographyProperties class properties.
字體Typeface 決定字型,以及權數、樣式和延展。Determines the typeface, as well as, weight, style, and stretch. 請參閱 Typeface 屬性。See the Typeface property.
文字裝飾Text decoration 提供 TextDecoration 物件(例如底線或刪除線)的支援。Provides support for TextDecoration objects, such as underline or strikethrough. 請參閱 TextDecorations 屬性。See the TextDecorations property.
文字效果Text effects 提供 TextEffect 物件的支援。Provides support for TextEffect objects. 請參閱 TextEffects 屬性。See the TextEffects property.

下表是段落層級功能的 TextFormatter 支援服務的索引鍵清單。The following table is a list of the key TextFormatter supported services for paragraph-level features.

功能Feature 說明Description
流程方向Flow direction 段落由左至右或由右至左的流程方向。Flow direction of the paragraph - left-to-right, or right-to-left. 請參閱 FlowDirection 屬性。See the FlowDirection property.
行縮排Line indentation 段落中每一行的縮排。Indentation for each line in the paragraph. 請參閱 Indent 屬性。See the Indent property.
標記Marker 段落中第一行的標記特性。Marker characteristics of the first line in the paragraph. 請參閱 TextMarkerProperties 屬性。See the TextMarkerProperties property.
段落縮排Paragraph indentation 段落中第一行的縮排。Indentation for the first line in the paragraph. 請參閱 ParagraphIndent 屬性。See the ParagraphIndent property.
定位點Tabs 包含定位鍵對齊和索引標籤前置字元的支援。Includes support for tab alignment and tab leader.
寬度Width 決定段落寬度的最小和最大值。Determine minimum and maximum paragraph width. 請參閱 FormatMinMaxParagraphWidth 方法。See the FormatMinMaxParagraphWidth methods.
自動換行Word wrap 決定文字到達流程邊緣時的換行方式。Determine how text wraps when it reaches the flow edge. 請參閱 TextWrapping 屬性。See the TextWrapping property.

下表是行層級功能的 TextFormatter 支援服務的索引鍵清單。The following table is a list of the key TextFormatter supported services for line-level features.

功能Feature 說明Description
對齊Alignment 文字對齊-靠左、靠右、置中或對齊。Text alignment - left, right, centered, or justified. 請參閱 TextAlignment 屬性。See the TextAlignment property.
行高Line height 線條的高度。Height of the line. 請參閱 Height 屬性。See the Height property.
行折迭Line collapsing 行折迭支援。Line collapsing support. 請參閱 Collapse 方法。See the Collapse method.
黑色方塊測量Black box measurement 表示用於配置裝置字型字元的度量。Represents the metrics used to lay out a character in a device font. 請參閱 CharacterMetrics 類別。See the CharacterMetrics class.
插入號支援Caret support 插入號流覽和編輯支援。Caret navigation and editing support. 請參閱 TextLine 字元點擊屬性,例如 GetNextCaretCharacterHitGetPreviousCaretCharacterHitSee the TextLine character hit properties, such as GetNextCaretCharacterHit and GetPreviousCaretCharacterHit.

下表是文字執行層級功能的 TextFormatter 支援服務的索引鍵清單。The following table is a list of the key TextFormatter supported services for text run-level features.

功能Feature 說明Description
隱藏執行Hidden run 不可見的字元範圍。Range of characters that are not visible. 請參閱 TextHidden 物件。See the TextHidden object.
中斷Breaking 線條和段落斷詞。Line and paragraph breaking.

建構函式

TextFormatter()

初始化 TextFormatter 類別的新執行個體。Initializes a new instance of the TextFormatter class.

方法

Create()

建立 TextFormatter 類別的新執行個體。Creates a new instance of the TextFormatter class. 這是靜態方法。This is a static method.

Create(TextFormattingMode)

使用指定的格式化模式,建立 TextFormatter 類別的新執行個體。Creates a new instance of the TextFormatter class with the specified formatting mode. 這是靜態方法。This is a static method.

Dispose()

釋放 TextFormatter 物件使用的所有 Managed 和 Unmanaged 資源。Releases all managed and unmanaged resources used by the TextFormatter object.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
FormatLine(TextSource, Int32, Double, TextParagraphProperties, TextLineBreak)

建立用於格式化和顯示文件內容的 TextLineCreates a TextLine that is used for formatting and displaying document content.

FormatLine(TextSource, Int32, Double, TextParagraphProperties, TextLineBreak, TextRunCache)

建立用於格式化和顯示文件內容的 TextLineCreates a TextLine that is used for formatting and displaying document content.

FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties)

傳回值,代表可完整內含指定之文字內容的最小及最大可能段落的寬度。Returns a value that represents the smallest and largest possible paragraph width that can fully contain the specified text content.

FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties, TextRunCache)

傳回值,代表可完整內含指定之文字內容的最小及最大可能段落的寬度。Returns a value that represents the smallest and largest possible paragraph width that can fully contain the specified text content.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱