pdfFontFactory.cs :  » PDF » SharpPDF » sharpPDF » Fonts » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » PDF » SharpPDF 
SharpPDF » sharpPDF » Fonts » pdfFontFactory.cs
using System;

using sharpPDF;
using sharpPDF.Enumerators;
using sharpPDF.Exceptions;
using sharpPDF.Fonts.AFM;
using sharpPDF.Fonts.TTF;

namespace sharpPDF.Fonts{
  /// <summary>
  /// Class that represents a Font Factory
  /// </summary>
  internal abstract class pdfFontFactory
  {

    private readonly static string[] predefinedFontName = {"None","Helvetica","Helvetica-Bold","Helvetica-Oblique","Helvetica-BoldOblique","Courier","Courier-Bold","Courier-Oblique","Courier-BoldOblique","Times-Roman","Times-Bold","Times-Italic","Times-BoldItalic"};
    
    /// <summary>
    /// Method that returns an abstract font object[pdfAbstractFont Factory]
    /// </summary>
    /// <param name="fontReference">Font Name(for predefined fonts) or Font File</param>
    /// <param name="fontNumber">Number of the font inside the PDF</param>
    /// <param name="fontType">Type of the font</param>
    /// <returns>Abstract Font Object</returns>
    public static pdfAbstractFont getFontObject(string fontReference, int fontNumber, documentFontType fontType )
    {
      pdfAbstractFont fontObject = null;      
      FontReader fontReader = getFontReader(fontReference, fontType);  
      switch (fontType) {
        case documentFontType.csPredefinedfont:
        default:
          fontObject = new pdfPredefinedFont(fontReader.getFontDefinition(), fontNumber, documentFontEncoding.csWinAnsiEncoding);
          break;
        case documentFontType.csTrueTypeFont:
          fontObject = new pdfTrueTypeFont(fontReader.getFontDefinition(), fontNumber, documentFontEncoding.csIdentityH, fontReference);
          break;
      }
      fontReader = null;      
      return fontObject;
    }    

    /// <summary>
    /// Method that returns a generic font reader[FontReader Factory]
    /// </summary>
    /// <param name="fontReference">Font Name(for predefined fonts) or Font File</param>
    /// <param name="fontType">Type of the font</param>
    /// <returns>Generic Font Reader Object</returns>
    private static FontReader getFontReader(string fontReference, documentFontType fontType)
    {      
      FontReader fontReader;
      switch (fontType) {
        case documentFontType.csPredefinedfont:
        default:
          fontReader = new afmFontReader(fontReference);        
          break;
        case documentFontType.csTrueTypeFont:
          fontReader = new ttfFontReader(fontReference);
          break;
      }
      return fontReader;
    }

    /// <summary>
    /// Method that returns that font name for a predefined font
    /// </summary>
    /// <param name="fontStyle">Font style</param>
    /// <returns>Predefined font name</returns>
    public static string getPredefinedFontName(predefinedFont fontStyle)
    {
      return pdfFontFactory.predefinedFontName[Convert.ToInt32(fontStyle)];
    }

    /// <summary>
    /// Method that returns if the font reference is a predefined font
    /// </summary>
    /// <param name="fontReference">Font Reference</param>
    /// <returns>Boolean value that shows if the font reference is a predefined font</returns>
    public static bool isPredefinedFont(string fontReference)
    {      
      return ((fontReference == "Helvetica") ||
          (fontReference == "Helvetica-Bold") ||
          (fontReference == "Helvetica-Oblique") ||
          (fontReference == "Helvetica-BoldOblique") ||
          (fontReference == "Courier") ||
          (fontReference == "Courier-Bold") ||
          (fontReference == "Courier-Oblique") ||
          (fontReference == "Courier-BoldOblique") ||
          (fontReference == "Times-Roman") ||
          (fontReference == "Times-Bold") ||
          (fontReference == "Times-Italic") ||
          (fontReference =="Times-BoldItalic"));
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.