共用方式為


GlyphRun 物件和 Glyphs 項目簡介

更新:2007 年 11 月

本主題說明 GlyphRun 物件和 Glyphs 項目。

這個主題包含下列章節。

  • GlyphRun 簡介
  • GlyphRun 物件
  • Glyphs 項目
  • 圖像度量資訊
  • Glyphs 標記
  • 相關主題

GlyphRun 簡介

Windows Presentation Foundation (WPF) 針對想要攔截文字並在格式化之後保留文字的客戶,提供進階的文字支援,包含可以直接存取 Glyphs 的圖像 (Glyph) 層次標記。這些功能提供下列每個案例中之不同文字呈現需求的重要支援。

  1. 固定格式文件的螢幕顯示。

  2. 列印案例。

    • 可延伸標記語言 (XAML) 做為裝置印表機語言。

    • Microsoft XPS 文件寫作程式.

    • 先前的印表機驅動程式 (從 Win32 應用程式輸出至固定格式)。

    • 列印多工緩衝處理格式。

  3. 固定格式文件呈現 (包含舊版 Windows 和其他運算裝置的用戶端)。

注意事項:

GlyphsGlyphRun 是針對固定格式文件呈現和列印案例所設計。Windows Presentation Foundation (WPF) 提供數個項目可用於一般配置和使用者介面 (UI) 案例 (如 LabelTextBlock)。如需配置和 UI 案例的詳細資訊,請參閱 Windows Presentation Foundation 中的印刷樣式

GlyphRun 物件

GlyphRun 物件會使用單一呈現樣式,以單一大小之單一字型的單一字體呈現一系列圖像。

GlyphRun 同時包含字型詳細資料 (例如圖像 Indices) 和個別的圖像位置。它也包含產生此圖像的原始 Unicode 字碼指標、字元對圖像緩衝區位移 (Offset) 對應資訊,以及個別字元和個別圖像旗標。

GlyphRun 具有對應的高階 FrameworkElementGlyphsGlyphs 可在項目樹狀結構和 XAML 標記中,用來代表 GlyphRun 輸出。

Glyphs 項目

Glyphs 項目代表 XAML 格式的 GlyphRun 輸出。下列標記語法是用來描述 Glyphs 項目。

<!-- The example shows how to use a Glyphs object. -->
<Page
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  >

   <StackPanel Background="PowderBlue">

      <Glyphs
         FontUri             = "C:\WINDOWS\Fonts\TIMES.TTF"
         FontRenderingEmSize = "100"
         StyleSimulations    = "BoldSimulation"
         UnicodeString       = "Hello World!"
         Fill                = "Black"
         OriginX             = "100"
         OriginY             = "200"
      />

   </StackPanel>
</Page>

下列屬性 (Property) 定義對應於範例標記中的前四個屬性 (Attribute)。

屬性

描述

FontUri

指定資源識別項 (Resource Identifier):檔名、Web 統一資源識別元 (URI),或是應用程式 .exe 或容器 (Container) 中的資源參考。

FontRenderingEmSize

以繪圖平面單位指定字元大小 (預設為 .96 英吋)。

StyleSimulations

指定粗體和斜體樣式的旗標。

BidiLevel

指定雙向版面配置層級。偶數值和零代表由左到右的版面配置,而奇數值則代表由右到左的版面配置。

Indices 屬性

Indices 屬性是圖像規格的字串。當一系列圖像形成單一叢集時,叢集中第一個圖像的規格前面會加上形成該叢集之圖像數目和字碼指標數目。Indices 屬性會在單一字串中收集下列屬性:

  • 圖像索引

  • 圖像前進距離寬度

  • 合併圖像附加向量

  • 由字碼指標至圖像的叢集對應

  • 圖像旗標

每個圖像規格都採用下列格式:

[GlyphIndex][,[Advance][,[uOffset][,[vOffset][,[Flags]]]]]

圖像度量資訊

每個圖像都會定義度量資訊,用以指定圖像與其他 Glyphs 的對齊方式。下圖定義兩個不同圖像字元的各種印刷樣式品質。

圖像量測的繪圖器

Glyphs 標記

下列程式碼範例示範如何在 XAML 中使用 Glyphs 項目的各種屬性。

<!-- The example shows how to use different property settings of Glyphs objects. -->
<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  Background="PowderBlue"
  >

<Glyphs 
   FontUri             = "C:\WINDOWS\Fonts\ARIAL.TTF"
   FontRenderingEmSize = "36"
   StyleSimulations    = "ItalicSimulation"
   UnicodeString       = "Hello World!"
   Fill                = "SteelBlue"
   OriginX             = "50"
   OriginY             = "75"
/>

<!-- "Hello World!" with default kerning -->
<Glyphs 
   FontUri             = "C:\WINDOWS\Fonts\ARIAL.TTF"
   FontRenderingEmSize = "36"
   UnicodeString       = "Hello World!"
   Fill                = "Maroon"
   OriginX             = "50"
   OriginY             = "150"
/>

<!-- "Hello World!" with explicit character widths for proportional font -->
<Glyphs 
   FontUri             = "C:\WINDOWS\Fonts\ARIAL.TTF"
   FontRenderingEmSize = "36"
   UnicodeString       = "Hello World!"
   Indices             = ",80;,80;,80;,80;,80;,80;,80;,80;,80;,80;,80"
   Fill                = "Maroon"
   OriginX             = "50"
   OriginY             = "225"
/>

<!-- "Hello World!" with fixed-width font -->
<Glyphs 
     FontUri             = "C:\WINDOWS\Fonts\COUR.TTF"
     FontRenderingEmSize = "36"
     StyleSimulations    = "BoldSimulation"
     UnicodeString       = "Hello World!"
     Fill                = "Maroon"
     OriginX             = "50"
     OriginY             = "300"
/>

<!-- "Open file" without "fi" ligature -->
<Glyphs
   FontUri             = "C:\WINDOWS\Fonts\TIMES.TTF"
   FontRenderingEmSize = "36"
   StyleSimulations    = "BoldSimulation"
   UnicodeString       = "Open file"
   Fill                = "SlateGray"
   OriginX             = "400"
   OriginY             = "75"
/>

<!-- "Open file" with "fi" ligature -->
<Glyphs
   FontUri             = "C:\WINDOWS\Fonts\TIMES.TTF"
   FontRenderingEmSize = "36"
   StyleSimulations    = "BoldSimulation"
   UnicodeString       = "Open file"
   Indices             = ";;;;;(2:1)191"
   Fill                = "SlateGray"
   OriginX             = "400"
   OriginY             = "150"
/>

</Canvas>

請參閱

概念

Windows Presentation Foundation 中的印刷樣式

Windows Presentation Foundation 中的文件

最佳化效能:文字