TextFormatter TextFormatter TextFormatter TextFormatter Class

定義

使用自訂文字配置用戶端提供格式化文字和分隔文字行的服務。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
繼承
TextFormatterTextFormatterTextFormatterTextFormatter
實作

範例

下列範例示範如何使用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.

不同於傳統的文字APIAPI,則TextFormatter互動文字配置用戶端透過一組回呼方法。Unlike a traditional text APIAPI, 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 Brush所用的背景色彩。The 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 Brush所用的前景色彩。The 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 決定字樣,以及,粗細、 樣式和 stretch。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() TextFormatter() TextFormatter()

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

方法

Create() Create() Create() Create()

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

Create(TextFormattingMode) Create(TextFormattingMode) Create(TextFormattingMode) Create(TextFormattingMode)

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

Dispose() Dispose() Dispose() Dispose()

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
FormatLine(TextSource, Int32, Double, TextParagraphProperties, TextLineBreak) FormatLine(TextSource, Int32, Double, TextParagraphProperties, TextLineBreak) FormatLine(TextSource, Int32, Double, TextParagraphProperties, TextLineBreak) 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) FormatLine(TextSource, Int32, Double, TextParagraphProperties, TextLineBreak, TextRunCache) FormatLine(TextSource, Int32, Double, TextParagraphProperties, TextLineBreak, TextRunCache) FormatLine(TextSource, Int32, Double, TextParagraphProperties, TextLineBreak, TextRunCache)

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

FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties) FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties) FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties) 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) FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties, TextRunCache) FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties, TextRunCache) 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() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)

適用於

另請參閱