GlyphRun 对象和 Glyphs 元素简介

本主题介绍 GlyphRun 对象和 Glyphs 元素。

本主题包括下列各节。

  • GlyphRun 简介
  • GlyphRun 对象
  • Glyphs 元素
  • 标志符号规格
  • 标志符号标记
  • 相关主题

GlyphRun 简介

Windows Presentation Foundation (WPF) 为想要在设置文本格式之后截取和保存文本的客户提供了高级文本支持,包括可直接访问 Glyphs 的标志符号级别标记。 这些功能为下列每一种方案中的不同文本呈现要求提供了关键支持。

  1. 固定格式文档的屏幕显示。

  2. 打印方案。

    • 将Extensible Application Markup Language (XAML) 作为设备打印机语言。

    • Microsoft XPS Document Writer.

    • 以前的打印机驱动程序,从 Win32 应用程序输出为固定格式。

    • 打印后台格式。

  3. 固定格式的文档表示,包括以前版本 Windows 的客户端和其他计算设备。

注意注意

GlyphsGlyphRun 设计用于固定格式的文档表示和打印方案。Windows Presentation Foundation (WPF) 为常规布局和 user interface (UI) 方案(例如 LabelTextBlock)提供了若干元素。有关布局和 UI 方案的更多信息,请参见 WPF 中的版式

GlyphRun 对象

GlyphRun 对象表示只具有一种大小和一种呈现样式的一种字体中的标志符号序列。

GlyphRun 包含诸如标志符号 Indices 之类的字体详细信息和各个标志符号位置。 它还包括从中生成运行的原始 Unicode 码位、字符到标志符号缓冲区偏移量的映射信息以及每个字符和每个标志符号的标志。

GlyphRun 具有一个对应的高级别 FrameworkElement,即 GlyphsGlyphs 可以用在元素树和 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

说明

FontUri

指定资源标识符:文件名、Web uniform resource identifier (URI) 或者应用程序 .exe 或容器中的资源引用。

FontRenderingEmSize

指定以绘图图面单位计量的字号(默认为 .96 英寸)。

StyleSimulations

为粗体和斜体样式指定标志。

BidiLevel

指定双向布局级别。 偶数或零值表示从左到右的布局,奇数值表示从右到左的布局。

Indices 属性

Indices 属性是标志符号规范字符串。 当标志符号序列形成了一个簇时,簇中第一个标志符号的规范前面会有这样一个规范:指定多少个标志符号和多少个码位组成了这个簇。 Indices 属性将以下属性收集在一个字符串中。

  • 标志符号索引

  • 标志符号前进宽度

  • 组合标志符号附加向量

  • 从码位到标志符号的簇映射

  • 标志符号标志

每个标志符号规范都有以下形式。

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

标志符号规格

每个标志符号都定义了规格,指定它与其他 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>

请参见

概念

WPF 中的版式

WPF 中的文档

优化性能:文本