System windows media fontfamily

FontFamily Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents a family of related fonts.

Inheritance Hierarchy

System.Object
В В System.Windows.Media.FontFamily

Namespace: В System.Windows.Media
Assembly: В System.Windows (in System.Windows.dll)

Syntax

XAML Values

fontFamilyName
A string that names the primary font.

fallbackFontFamilyName
Following the fontFamilyName and a comma, a string that names an optional fallback font. More than one fallback can be specified, each fallback separated by more commas. See Remarks.

uri
A URI that is evaluated either as a relative path in the assembly, or as a component; qualified assembly reference that starts the path from a specified assembly’s root. See Remarks.

The FontFamily type exposes the following members.

Constructors

В Name Description
FontFamily Initializes a new instance of the FontFamily class from the specified font family string.

Properties

В Name Description
Source Gets the font family name that is used to construct the FontFamily object.

Methods

В Name Description
Equals Gets a value that indicates whether the current font family object and the specified font family object are the same. (Overrides Object.Equals(Object).)
Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode Serves as a hash function for FontFamily. (Overrides Object.GetHashCode().)
GetType Gets the Type of the current instance. (Inherited from Object.)
MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
ToString Returns a string representation of this FontFamily. (Overrides Object.ToString().)

Remarks

A font family is a set of typefaces that share the same family name, such as «Times New Roman», but that differ in features. These font family feature differences typically include font style, such as italic, and font weight, such as bold.

Default Font Set

Silverlight supports a list of font family values that are supported in the initial, default Silverlight font set for non-East Asian cultures. This list is documented in the topic Text and Fonts.В

For a list of the East Asian fonts, see Text and Fonts.

Portable User Interface

The default value for a referenced FontFamily is initialized with the value Portable User Interface. For non-East Asian cultures, this value is an alias for the font family value (shown here as a string) of «Lucida Sans Unicode, Lucida Grande». Lucida Grande and Lucida Sans Unicode in turn are aliases for the same font and are specified as a pair for compatibility reasons.

Note that the Portable User Interface value is not always the apparent default value when a given object is referenced at run time, even if your user code made no changes to the value. Controls, even the default Silverlight controls, will generally apply a template that defines their appearance. These templates frequently change the values of properties such as Control.FontFamily to be different than the pure code default value. The templates also might be written differently for different locales. Also, your own application might apply different templates or styles to a control.

If you specify a FontFamily that does not exist, even if it is the only font family value available, Silverlight will still provide fallback to the Portable User Interface value for rendering purposes.

Commas in Font Family Names

You can specify a font family either as a single font family name, or as a series of font family names that describe a fallback sequence. The separator between fallbacks (both for XAML, and for the string used to construct a FontFamily in code) is a comma. To avoid ambiguity, if a supplied font family name contains a comma in its internal value, then each single comma in the supplied font family name must be replaced with a double comma (,,).

Using Other Font Families

If you specify a font family that is not typically present on a user’s system, you may have to redistribute the font. Restrictions apply when specifying a font file or a zip containing font files.

As with most types of software, font files are licensed, rather than sold, and licenses that govern the use of fonts vary from vendor to vendor. As a developer it is your responsibility to ensure that you have the required license rights for any font you embed within a document or application, or otherwise redistribute.

Non-System Font Files Must Come From Assembly Resources

In general. Silverlight processes XAML values that are actual URIs (or resemble a URI) through a fallback sequence of resource lookup. FontFamily values that have a URI portion are an important exception. The only places where a font file resource can be resolved is as a resource target within the current assembly.

For system fonts, you provide only the font family name, not the name of a font file. For instance, to specify a font family value of Verdana with an Arial fallback, you would specify this XAML:

For non system fonts, a FontFamily will include a URI portion. The value of the URI portion for a FontFamily value depends on the relationship between the assumed base URI of the calling XAML file and the resource location of the font file in the assembly.

For example, if you are calling from a XAML file at the assembly and project root, and have included a font file as a same-assembly resource also at the project root, the URI portion is simply the font file name with no path. The specific font family within the font file is appended, with the URI portion and font family portion separated by a hash sign (#). For example:

You can also use folders within your resource structure in the main assembly. For instance if your build structure contains a folder Fonts, your XAML is at the assembly root, and Contoso.ttf is a resource within that folder, you would use this XAML:

Another level of complexity emerges if the referencing XAML is in one structured folder of the assembly and resources are in another folder. For example, your project and assembly might be composed with the following structure:

SilverlightApplication1 (project root for creating assembly SilverlightApplication1)

Page1.xaml (a XAML Page)

contoso.ttf (a Resource)

You could reference contoso.ttf from Page1.xaml using a relative URI that traverses upwards one level:

However, relative URI traversals can be fragile if you do any refactoring of content. To avoid this, another option is to use the component; qualifier along with a named assembly reference. In this case you are self-referencing the same assembly. The component; qualifier is a case-insensitive qualifier that is supported for any Silverlight URI usage, which informs the client that the path should be evaluated from the assembly root of the specified assembly. Using this technique, you can unambiguously refer to an assembly resource from an assembly no matter how the referencing XAML page and the referenced font resource are relatively pathed within the assembly. For example, the following is a usage that could find the Contoso font file from any frame of reference within the SilverlightApplication1 assembly:

A component; reference may also be useful if you are applying a root FontFamily value to a custom UserControl that is defined in another assembly, because the templated XAML for the UserControl when applied uses its own defining assembly for URI scope.

XAML Syntax Notes

The [] and * characters in the XAML syntax are not literals. They are a convention to indicate that zero or more fallback font families can be specified in the syntax. The [] characters enclose the repeatable atom of the syntax, and the * character indicates the one-or-more convention if fallbacks are specified.

If you use the object element syntax, which is useful for declaring a FontFamily value within a ResourceDictionary, you must specify initialization text that names the font family name and possible fallbacks. Failing to specify initialization text results in a parsing error, because the underlying FontFamily constructor in the backing code requires a string.

FontSource

Rather than specify a FontFamily as a URI in XAML, you can also specify a FontSource in code. This gives you more options for packaging or obtaining a font file. Basically you obtain a stream of either a font file or a zip of font files, and set FontSource using that stream. This is equivalent to specifying a URI portion of a FontFamily value, and makes that font file available to the object. All you need to do now is specify a fontFamilyName to reference one of the specific families in the current FontSource value. See FontSource.

Fonts. Get Font Families Метод

Определение

Возвращает коллекцию объектов FontFamily из указанного расположения шрифтов. Returns the collection of FontFamily objects from a specified font location.

Перегрузки

Возвращает коллекцию объектов FontFamily из строкового значения, представляющего расположение шрифтов. Returns the collection of FontFamily objects from a string value that represents the location of the fonts.

Возвращает коллекцию объектов FontFamily по значению универсального кода ресурса (URI), представляющему расположение шрифтов. Returns a collection of FontFamily objects from a uniform resource identifier (URI) value that represents the location of the fonts.

Возвращает коллекцию объектов FontFamily, используя значение базового универсального кода ресурса (URI) для разрешения расположения шрифтов. Returns a collection of FontFamily objects using a base uniform resource identifier (URI) value to resolve the font location.

GetFontFamilies(String)

Возвращает коллекцию объектов FontFamily из строкового значения, представляющего расположение шрифтов. Returns the collection of FontFamily objects from a string value that represents the location of the fonts.

Параметры

Расположение, в котором находятся шрифты. The location that contains the fonts.

Возвращаемое значение

Коллекция ICollection объектов FontFamily, представляющих шрифты в location . An ICollection of FontFamily objects that represent the fonts in location .

Исключения

Значение параметра location — null . The location is null . Значение null передавать нельзя, поскольку этот параметр интерпретируется как путь или URI. You cannot pass null , because this parameter is treated as a path or URI.

Примеры

В следующем примере показано, как использовать этот метод для возврата коллекции FontFamily объектов из расположения шрифта. The following example shows how to use this method to return the collection of FontFamily objects from a font location.

Применяется к

GetFontFamilies(Uri)

Возвращает коллекцию объектов FontFamily по значению универсального кода ресурса (URI), представляющему расположение шрифтов. Returns a collection of FontFamily objects from a uniform resource identifier (URI) value that represents the location of the fonts.

Параметры

Значение базового URI расположения шрифтов. The base URI value of the location of the fonts.

Возвращаемое значение

Коллекция ICollection объектов FontFamily, представляющих шрифты в baseUri . An ICollection of FontFamily objects that represent the fonts in baseUri .

Примеры

В следующем примере показано, как использовать этот метод для возврата коллекции FontFamily объектов из базового расположения URI. The following example shows how to use this method to return the collection of FontFamily objects from a base URI location.

Чтобы получить коллекцию FontFamily объектов в ресурсах приложения, используйте нотацию URI «Pack://Application», как показано в следующем примере. To return the collection of FontFamily objects in an application’s resources, use the «pack://application» URI notation shown in the following example.

Применяется к

GetFontFamilies(Uri, String)

Возвращает коллекцию объектов FontFamily, используя значение базового универсального кода ресурса (URI) для разрешения расположения шрифтов. Returns a collection of FontFamily objects using a base uniform resource identifier (URI) value to resolve the font location.

Параметры

Значение базового URI расположения шрифтов. The base URI value of the location of the fonts.

Расположение, в котором находятся шрифты. The location that contains the fonts.

Возвращаемое значение

Коллекция ICollection объектов FontFamily, представляющих шрифты в разрешенном расположении шрифтов. An ICollection of FontFamily objects that represent the fonts in the resolved font location.

Примеры

В следующем примере показано, как использовать этот метод для возврата коллекции FontFamily объектов из разрешенного расположения шрифта. The following example shows how to use this method to return the collection of FontFamily objects from the resolved font location. В данном случае приложение содержит подкаталог с именем resources. In this case, the application contains a subdirectory named «resources».

Читайте также:  Writing script in linux
Оцените статью
Note: