天天看點

GlyphRun 對象和 Glyphs 元素簡介

原文 GlyphRun 對象和 Glyphs 元素簡介

GlyphRun 簡介

Windows Presentation Foundation (WPF) 提供進階的文本支援包括直接通路的标志符号級标記

Glyphs

的使用者想要截獲并儲存在格式化後的文本。 這些功能為以下每種方案中不同的文本呈現要求提供關鍵支援。

  1. 固定格式文檔的螢幕顯示。
  2. 列印方案。
    • 可擴充應用程式标記語言 (XAML) 作為裝置列印機語言。
    • Microsoft XPS 文檔編寫器。
    • 以前的列印機驅動程式,從 Win32 應用程式輸出為固定格式。
    • 列印背景處理格式。
  3. 固定格式的文檔示範,包括以前版本的 Windows 用戶端和其他計算裝置。

備注

 和

GlyphRun

旨在固定格式的文檔示範文稿和列印方案。 Windows Presentation Foundation (WPF) 為正常布局提供了多個元素和使用者界面 (UI)如方案

Label

TextBlock

。 有關布局和 UI 方案的詳細資訊,請參閱 

WPF 中的版式

GlyphRun 對象

對象表示的标志符号的序列中的一種字型在單個大小,并且一種呈現樣式的單個字形。

 包括這兩種字型詳細資訊,例如标志符号

Indices

和單個标志符号位置。 它還包括原始Unicode點從字元标志符号緩沖區偏移量的映射資訊,以及每個字元和每個标志符号的标志生成運作的代碼。

 有一個相應的進階

FrameworkElement

, 

。 

 元素樹中并在可以使用XAML标記來表示

輸出。

Glyphs 元素

元素表示的輸出

中XAML。 以下的标記文法用于描述

元素。

XAML複制

<!-- 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 屬性

屬性是一個字元串的标志符号規範。 在一系列字形形成單個群集的情況下,群集中第一個字形的規範之前會跟有一個規範,說明組合了多少個字形和多少個代碼點來形成群集。 

屬性收集在一個字元串中的以下屬性。

  • 字形索引
  • 字形步進寬度
  • 組合字形附加矢量
  • 從代碼點映射到字形的群集
  • 字形标志

每個字形規範具有以下形式。

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

字形路徑成本

每個字形定義路徑成本,指定與其他的對齊方式

。 以下圖形定義兩種不同字形字元的各種排版品質。

GlyphRun 對象和 Glyphs 元素簡介

Glyphs 标記

下面的代碼示例示範如何使用各種屬性

中的元素XAML。

<!-- 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>           

繼續閱讀