GlyphRun 简介
Windows Presentation Foundation (WPF) 提供高级的文本支持包括直接访问的标志符号级标记Glyphs的用户想要截获并保存在格式化后的文本。 这些功能为以下每种方案中不同的文本呈现要求提供关键支持。
-
固定格式文档的屏幕显示。
-
打印方案。
-
可扩展应用程序标记语言 (XAML) 作为设备打印机语言。
-
Microsoft XPS 文档编写器。
-
以前的打印机驱动程序,从 Win32 应用程序输出为固定格式。
-
打印后台处理格式。
-
-
固定格式的文档演示,包括以前版本的 Windows 客户端和其他计算设备。
备注
Glyphs 和GlyphRun旨在固定格式的文档演示文稿和打印方案。 Windows Presentation Foundation (WPF) 为常规布局提供了多个元素和用户界面 (UI)如方案Label和TextBlock。 有关布局和 UI 方案的详细信息,请参阅 WPF 中的版式。
GlyphRun 对象
GlyphRun对象表示的标志符号的序列中的一种字体在单个大小,并且一种呈现样式的单个字形。
GlyphRun 包括这两种字体详细信息,例如标志符号Indices和单个标志符号位置。 它还包括原始Unicode点从字符标志符号缓冲区偏移量的映射信息,以及每个字符和每个标志符号的标志生成运行的代码。
GlyphRun 有一个相应的高级FrameworkElement, Glyphs。 Glyphs 元素树中并在可以使用XAML标记来表示GlyphRun输出。
Glyphs 元素
Glyphs元素表示的输出GlyphRun中XAML。 以下的标记语法用于描述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。 以下图形定义两种不同字形字符的各种排版品质。
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>