mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-08 16:06:07 +02:00
Links: .NET Desktop - framework\wpf (#109)
* Links: .NET Desktop - framework\wpf * Apply suggestions from code review Co-authored-by: Andy De George <[email protected]>
This commit is contained in:
co-authored by
Andy De George
parent
c1d6e1d23e
commit
674b773578
@@ -13,21 +13,26 @@ helpviewer_keywords:
|
||||
ms.assetid: db15ee48-4d24-49f5-8b9d-a64460865286
|
||||
---
|
||||
# Packaging Fonts with Applications
|
||||
|
||||
This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)] application.
|
||||
|
||||
> [!NOTE]
|
||||
> As with most types of software, font files are licensed, rather than sold. Licenses that govern the use of fonts vary from vendor to vendor but in general most licenses, including those covering the fonts Microsoft supplies with applications and Windows, do not allow the fonts to be embedded within applications or otherwise redistributed. Therefore, as a developer it is your responsibility to ensure that you have the required license rights for any font you embed within an application or otherwise redistribute.
|
||||
|
||||
<a name="introduction_to_packaging_fonts"></a>
|
||||
|
||||
## Introduction to Packaging Fonts
|
||||
|
||||
You can easily package fonts as resources within your [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications to display user interface text and other types of text based content. The fonts can be separate from or embedded within the application's assembly files. You can also create a resource-only font library, which your application can reference.
|
||||
|
||||
OpenType and TrueType® fonts contain a type flag, fsType, that indicates font embedding licensing rights for the font. However, this type flag only refers to embedded fonts stored in a document–it does not refer to fonts embedded in an application. You can retrieve the font embedding rights for a font by creating a <xref:System.Windows.Media.GlyphTypeface> object and referencing its <xref:System.Windows.Media.GlyphTypeface.EmbeddingRights%2A> property. Refer to the "OS/2 and Windows Metrics" section of the [OpenType Specification](https://www.microsoft.com/typography/otspec/os2.htm) for more information on the fsType flag.
|
||||
|
||||
The [Microsoft Typography](https://docs.microsoft.com/typography/) Web site includes contact information that can help you locate a particular font vendor or find a font vendor for custom work.
|
||||
The [Microsoft Typography](/typography/) Web site includes contact information that can help you locate a particular font vendor or find a font vendor for custom work.
|
||||
|
||||
<a name="adding_fonts_as_content_items"></a>
|
||||
|
||||
## Adding Fonts as Content Items
|
||||
|
||||
You can add fonts to your application as project content items that are separate from the application's assembly files. This means that content items are not embedded as resources within an assembly. The following project file example shows how to define content items.
|
||||
|
||||
```xml
|
||||
@@ -60,7 +65,9 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-xaml[FontSnippets#FontPackageSnippet8](~/samples/snippets/csharp/VS_Snippets_Wpf/FontSnippets/CSharp/FontPackageSnippets.xaml#fontpackagesnippet8)]
|
||||
|
||||
<a name="adding_fonts_as_resource_items"></a>
|
||||
|
||||
## Adding Fonts as Resource Items
|
||||
|
||||
You can add fonts to your application as project resource items that are embedded within the application's assembly files. Using a separate subdirectory for resources helps to organize the application's project files. The following project file example shows how to define fonts as resource items in a separate subdirectory.
|
||||
|
||||
```xml
|
||||
@@ -83,6 +90,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-xaml[FontSnippets#FontPackageSnippet1](~/samples/snippets/csharp/VS_Snippets_Wpf/FontSnippets/CSharp/FontPackageSnippets.xaml#fontpackagesnippet1)]
|
||||
|
||||
### Referencing Font Resource Items from Code
|
||||
|
||||
In order to reference font resource items from code, you must supply a two-part font resource reference: the base uniform resource identifier (URI); and the font location reference. These values are used as the parameters for the <xref:System.Windows.Media.FontFamily.%23ctor%2A> method. The following code example shows how to reference the application's font resources in the project subdirectory called `resources`.
|
||||
|
||||
[!code-csharp[FontSnippets#FontPackageSnippet2](~/samples/snippets/csharp/VS_Snippets_Wpf/FontSnippets/CSharp/FontPackageSnippets.xaml.cs#fontpackagesnippet2)]
|
||||
@@ -94,6 +102,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-vb[FontSnippets#FontPackageSnippet5](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FontSnippets/visualbasic/fontpackagesnippets.xaml.vb#fontpackagesnippet5)]
|
||||
|
||||
### Referencing Fonts from the Same Application Subdirectory
|
||||
|
||||
You can place both application content and resource files within the same user-defined subdirectory of your application project. The following project file example shows a content page and font resources defined in the same subdirectory.
|
||||
|
||||
```xml
|
||||
@@ -114,6 +123,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-vb[FontSnippets#FontPackageSnippet4](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FontSnippets/visualbasic/pages/homepage.xaml.vb#fontpackagesnippet4)]
|
||||
|
||||
### Enumerating Fonts in an Application
|
||||
|
||||
To enumerate fonts as resource items in your application, use either the <xref:System.Windows.Media.Fonts.GetFontFamilies%2A> or <xref:System.Windows.Media.Fonts.GetTypefaces%2A> method. The following example shows how to use the <xref:System.Windows.Media.Fonts.GetFontFamilies%2A> method to return the collection of <xref:System.Windows.Media.FontFamily> objects from the application font location. In this case, the application contains a subdirectory named "resources".
|
||||
|
||||
[!code-csharp[FontSnippets#FontsSnippet3](~/samples/snippets/csharp/VS_Snippets_Wpf/FontSnippets/CSharp/FontFamilySnippets.xaml.cs#fontssnippet3)]
|
||||
@@ -125,7 +135,9 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
[!code-vb[FontSnippets#FontsSnippet7](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FontSnippets/visualbasic/fontfamilysnippets.xaml.vb#fontssnippet7)]
|
||||
|
||||
<a name="creating_a_font_resource_library"></a>
|
||||
|
||||
## Creating a Font Resource Library
|
||||
|
||||
You can create a resource-only library that contains only fonts—no code is part of this type of library project. Creating a resource-only library is a common technique for decoupling resources from the application code that uses them. This also allows the library assembly to be included with multiple application projects. The following project file example shows the key portions of a resource-only library project.
|
||||
|
||||
```xml
|
||||
@@ -142,6 +154,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
```
|
||||
|
||||
### Referencing a Font in a Resource Library
|
||||
|
||||
To reference a font in a resource library from your application, you must prefix the font reference with the name of the library assembly. In this case, the font resource assembly is "FontLibrary". To separate the assembly name from the reference within the assembly, use a ';' character. Adding the "Component" keyword followed by the reference to the font name completes the full reference to the font library's resource. The following code example shows how to reference a font in a resource library assembly.
|
||||
|
||||
[!code-xaml[OpenTypeFontsSample#OpenTypeFontsSample1](~/samples/snippets/csharp/VS_Snippets_Wpf/OpenTypeFontsSample/CS/Kootenay.xaml#opentypefontssample1)]
|
||||
@@ -150,7 +163,9 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
> This SDK contains a set of sample OpenType fonts that you can use with [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications. The fonts are defined in a resource-only library. For more information, see [Sample OpenType Font Pack](sample-opentype-font-pack.md).
|
||||
|
||||
<a name="limitations_on_font_usage"></a>
|
||||
|
||||
## Limitations on Font Usage
|
||||
|
||||
The following list describes several limitations on the packaging and use of fonts in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications:
|
||||
|
||||
- **Font embedding permission bits:** [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] applications do not check or enforce any font embedding permission bits. See the [Introduction_to_Packing Fonts](#introduction_to_packaging_fonts) section for more information.
|
||||
@@ -169,7 +184,7 @@ This topic provides an overview of how to package fonts with your [!INCLUDE[TLA#
|
||||
|
||||
- <xref:System.Windows.Documents.Typography>
|
||||
- <xref:System.Windows.Media.FontFamily>
|
||||
- [Microsoft Typography: Links, News, and Contacts](https://docs.microsoft.com/typography/)
|
||||
- [Microsoft Typography: Links, News, and Contacts](/typography/)
|
||||
- [OpenType Specification](https://www.microsoft.com/typography/otspec/)
|
||||
- [OpenType Font Features](opentype-font-features.md)
|
||||
- [Sample OpenType Font Pack](sample-opentype-font-pack.md)
|
||||
|
||||
Reference in New Issue
Block a user