ResolveFontEventArgs Class

The ResolveFont event data.
Inheritance Hierarchy

Namespace:  TallComponents.PDF.Rasterizer.Fonts
Assembly:  TallComponents.PDF.Rasterizer (in TallComponents.PDF.Rasterizer.dll) Version: 3.0.167.0
Syntax
public class ResolveFontEventArgs : EventArgs

The ResolveFontEventArgs type exposes the following members.

Properties
  NameDescription
Public propertyBold
Specifies a bold variant of a system font.
Public propertyEmbedded
Whether the font is embedded in the PDF document.
Public propertyFontLocation
Specifies whether a definition for the font has been found.
Public propertyFontPath
The Resolved font path. If the font could be resolved and the FontLocation is File, this value holds a path to the font.
Public propertyFontRenderMode
The mode that will be used to render the font.
Public propertyItalic
Specifies an italic variant of a system font.
Public propertyPdfFontName
The name of the font, as found in the PDF document.
Public propertyPredefinedEncoding
The predefined encoding.
Public propertySystemFontName
The system font name. If the font could be resolved and the FontLocation is System, this property contains the name of the system font.
Top
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)
Top
Remarks

This event is raised in order to resolve PDF fonts to device fonts. In contrast to the font substitution map, which only plays a role for non-embedded fonts, this event will be raised for all fonts.

The first time that a particular pdf font is encountered, the system will try to resolve the font, and then raise this event to inform the client which device font it has found. The FontLocation property specifies whether a font definition has been found, and if so where it has been found.

If the event handler does not change any properties of this event, the system will use the definition as indicated by the FontLocation propery. If the font has been resolved this is often the right thing to do. If the font is unresolved the system will use the default font as specified in the FontSubstitutionMap.

By changing one or more event properties, the event handler can change this behavior. Not only is it possible to map unresolved fonts to different fonts than the default, but it is also possible to map resolved fonts to different font definitions.

The latter may make sense for example, for fonts that have the FontRenderMode set to RenderAsCurves, as curve rendering increases the size of print jobs and the size of WPF output. Instead, one can have these fonts rendered by an appropriate system font. This is merely a matter of setting the SystemFontName of the event to the appropriate font name and setting the FontRenderMode to RenderAsFont

It is also possible to map a font to a font file that has not been installed on the system. In that case one should clear the SystemFontName and set the FontPath to refer to the appropriate file.

If the system is able to resolve the font, based on the information provided by the event handler, it will simply use that font. If for some reason the font cannot be resolved, or if it cannot be used as requested, a new ResolveFont event will be raised. At the moment there a two cases:

  • If the font cannot be resolved the FontLocation will be set to Unresolved. The SystemFontName and the FontPath properties will indicate which values were tried.
  • If the font specified an unsupported FontRenderMode, the event will change this property into a supported value. This allows one to either accept this different mode, or specify a different font.

Examples
The code below lists a ResolveFont event handler that maps all fonts to system fonts. The code below only does some special processing for Helvetica. All other fonts are mapped to "Arial Unicode MS".
void resolveFont(object sender, ResolveFontEventArgs args)
  {
    // We are going to map all non-system fonts a system font.

    if (args.FontLocation != FontLocation.System)
    {
      args.FontRenderMode = FontRenderMode.RenderAsFont;

      switch (args.PdfFontName)
      {
        case "Helvetica":
          args.SystemFontName = "Arial";
          break;
        case "Helvetica-Bold":
          args.SystemFontName = "Arial";
          args.Bold = true;
          break;
        case "Helvetica-Oblique":
          args.SystemFontName = "Arial";
          args.Italic = true;
          break;
        case "Helvetica-BoldOblique":
          args.SystemFontName = "Arial";
          args.Bold = true;
          args.Italic = true;
          break;
        default:
          args.SystemFontName = "Arial Unicode MS";
          break;
        }
        break;
     }
  }
See Also