GlyphRun 物件和 Glyphs 元素簡介

本主題描述 GlyphRun 物件和 Glyphs 專案。

GlyphRun 簡介

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

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

  2. 列印案例。

    • 可延伸的應用程式標記語言 (XAML) 作為裝置印表機語言。

    • Microsoft XPS 檔寫入器。

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

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

  3. 固定格式的檔標記法,包括舊版 Windows 和其他計算裝置的用戶端。

注意

GlyphsGlyphRun 是針對固定格式的檔簡報和列印案例所設計。 WPF 提供一般配置和使用者介面 (UI) 案例的數個元素,例如 LabelTextBlock 。 如需版面配置和 UI 案例的詳細資訊,請參閱 WPF 中的印刷樣式。

GlyphRun 物件

物件 GlyphRun 代表單一字型單一字型的單一字型字元序列,以及單一轉譯樣式。

GlyphRun 包含字型詳細資料,例如圖像 Indices 和個別圖像位置。 它也包含執行所產生的原始 Unicode 字碼點、字元到字元緩衝區位移對應資訊,以及每個字元和每字元旗標。

GlyphRun 具有對應的高階 FrameworkElementGlyphsGlyphs 可用於專案樹狀結構及 XAML 標記中來表示 GlyphRun 輸出。

Glyphs 項目

元素 Glyphs 代表 XAML 中的 輸出 GlyphRun 。 下列標記語法可用來描述 Glyphs 專案。

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

下列屬性定義對應至範例標記中的前四個屬性。

屬性 說明
FontUri 指定資源識別碼:檔案名、Web 統一資源識別項(URI),或應用程式 .exe 或容器中的資源參考。
FontRenderingEmSize 指定字型大小 (以繪圖介面單位為單位) (預設值為 .96 英吋)。
StyleSimulations 指定粗體和斜體樣式的旗標。
BidiLevel 指定雙向配置層級。 偶數值和零值表示由左至右的版面配置,奇數值則表示由右至左的版面配置。

Indices 屬性

屬性 Indices 是字元規格的字串。 如果由一系列字符形成單一叢集,則會先指定叢集中的第一個字符,再指定合併多少字符和多少字碼指標來形成叢集。 屬性 Indices 會在下列屬性的一個字串中收集。

  • 字符索引

  • 字符遞增寬度

  • 合併字符附加向量

  • 從字碼指標到字符的叢集對應

  • 字符旗標

每個字符規格的形式如下。

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

字符度量

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

Diagraph of glyph measurements

字符標記

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

<!-- The example shows how to use different property settings of Glyphs objects. -->
<Canvas
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://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>

另請參閱