<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#------------------------------------------------------------------------------
# File:         Font.pm
#
# Description:  Read meta information from font files
#
# Revisions:    2010/01/15 - P. Harvey Created
#
# References:   1) http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6.html
#               2) http://www.microsoft.com/typography/otspec/otff.htm
#               3) http://partners.adobe.com/public/developer/opentype/index_font_file.html
#               4) http://partners.adobe.com/public/developer/en/font/5178.PFM.pdf
#               5) http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/util/MimeMappings.java
#               6) http://www.adobe.com/devnet/font/pdfs/5004.AFM_Spec.pdf
#------------------------------------------------------------------------------

package Image::ExifTool::Font;

use strict;
use vars qw($VERSION %ttLang);
use Image::ExifTool qw(:DataAccess :Utils);

$VERSION = '1.07';

sub ProcessOTF($$);

# TrueType 'name' platform codes
my %ttPlatform = (
    0 =&gt; 'Unicode',
    1 =&gt; 'Macintosh',
    2 =&gt; 'ISO',
    3 =&gt; 'Windows',
    4 =&gt; 'Custom',
);

# convert TrueType 'name' character encoding to ExifTool Charset (ref 1/2)
my %ttCharset = (
  Macintosh =&gt; {
    0 =&gt; 'MacRoman',      17 =&gt; 'MacMalayalam',
    1 =&gt; 'MacJapanese',   18 =&gt; 'MacSinhalese',
    2 =&gt; 'MacChineseTW',  19 =&gt; 'MacBurmese',
    3 =&gt; 'MacKorean',     20 =&gt; 'MacKhmer',
    4 =&gt; 'MacArabic',     21 =&gt; 'MacThai',
    5 =&gt; 'MacHebrew',     22 =&gt; 'MacLaotian',
    6 =&gt; 'MacGreek',      23 =&gt; 'MacGeorgian',
    7 =&gt; 'MacCyrillic',   24 =&gt; 'MacArmenian', # 7=Russian
    8 =&gt; 'MacRSymbol',    25 =&gt; 'MacChineseCN',
    9 =&gt; 'MacDevanagari', 26 =&gt; 'MacTibetan',
   10 =&gt; 'MacGurmukhi',   27 =&gt; 'MacMongolian',
   11 =&gt; 'MacGujarati',   28 =&gt; 'MacGeez',
   12 =&gt; 'MacOriya',      29 =&gt; 'MacCyrillic', # 29=Slavic
   13 =&gt; 'MacBengali',    30 =&gt; 'MacVietnam',
   14 =&gt; 'MacTamil',      31 =&gt; 'MacSindhi',
   15 =&gt; 'MacTelugu',     32 =&gt; '', # 32=uninterpreted
   16 =&gt; 'MacKannada',
  },
  Windows =&gt; {
    0 =&gt; 'Symbol',         4 =&gt; 'Big5',
    1 =&gt; 'UCS2',           5 =&gt; 'Wansung',
    2 =&gt; 'ShiftJIS',       6 =&gt; 'Johab',
    3 =&gt; 'PRC',           10 =&gt; 'UCS4',
  },
  Unicode =&gt; {
    # (we don't currently handle the various Unicode flavours)
    0 =&gt; 'UCS2', # Unicode 1.0 semantics
    1 =&gt; 'UCS2', # Unicode 1.1 semantics
    2 =&gt; 'UCS2', # ISO 10646 semantics
    3 =&gt; 'UCS2', # Unicode 2.0 and onwards semantics, Unicode BMP only.
    4 =&gt; 'UCS2', # Unicode 2.0 and onwards semantics, Unicode full repertoire.
    # 5 =&gt; Unicode Variation Sequences (not used in Naming table)
  },
  ISO =&gt; { # (deprecated)
    0 =&gt; 'UTF8',  # (7-bit ASCII)
    1 =&gt; 'UCS2',  # ISO 10646
    2 =&gt; 'Latin', # ISO 8859-1
  },
  Custom =&gt; { },
);

# convert TrueType 'name' language code to ExifTool language code
%ttLang = (
  # Macintosh language codes (also used by QuickTime.pm)
  # oddities:
  #   49 - Cyrllic version    83 - Roman
  #   50 - Arabic version     84 - Arabic
  #  146 - with dot above
  Macintosh =&gt; {
    0 =&gt; 'en',     24 =&gt; 'lt',    48 =&gt; 'kk',    72 =&gt; 'ml',    129 =&gt; 'eu',
    1 =&gt; 'fr',     25 =&gt; 'pl',    49 =&gt; 'az',    73 =&gt; 'kn',    130 =&gt; 'ca',
    2 =&gt; 'de',     26 =&gt; 'hu',    50 =&gt; 'az',    74 =&gt; 'ta',    131 =&gt; 'la',
    3 =&gt; 'it',     27 =&gt; 'et',    51 =&gt; 'hy',    75 =&gt; 'te',    132 =&gt; 'qu',
    4 =&gt; 'nl',     28 =&gt; 'lv',    52 =&gt; 'ka',    76 =&gt; 'si',    133 =&gt; 'gn',
    5 =&gt; 'sv',     29 =&gt; 'smi',   53 =&gt; 'ro',    77 =&gt; 'my',    134 =&gt; 'ay',
    6 =&gt; 'es',     30 =&gt; 'fo',    54 =&gt; 'ky',    78 =&gt; 'km',    135 =&gt; 'tt',
    7 =&gt; 'da',     31 =&gt; 'fa',    55 =&gt; 'tg',    79 =&gt; 'lo',    136 =&gt; 'ug',
    8 =&gt; 'pt',     32 =&gt; 'ru',    56 =&gt; 'tk',    80 =&gt; 'vi',    137 =&gt; 'dz',
    9 =&gt; 'no',     33 =&gt; 'zh-CN', 57 =&gt; 'mn-MN', 81 =&gt; 'id',    138 =&gt; 'jv',
    10 =&gt; 'he',    34 =&gt; 'nl',    58 =&gt; 'mn-CN', 82 =&gt; 'tl',    139 =&gt; 'su',
    11 =&gt; 'ja',    35 =&gt; 'ga',    59 =&gt; 'ps',    83 =&gt; 'ms-MY', 140 =&gt; 'gl',
    12 =&gt; 'ar',    36 =&gt; 'sq',    60 =&gt; 'ku',    84 =&gt; 'ms-BN', 141 =&gt; 'af',
    13 =&gt; 'fi',    37 =&gt; 'ro',    61 =&gt; 'ks',    85 =&gt; 'am',    142 =&gt; 'br',
    14 =&gt; 'iu',    38 =&gt; 'cs',    62 =&gt; 'sd',    86 =&gt; 'ti',    144 =&gt; 'gd',
    15 =&gt; 'is',    39 =&gt; 'sk',    63 =&gt; 'bo',    87 =&gt; 'om',    145 =&gt; 'vg',
    16 =&gt; 'mt',    40 =&gt; 'sl',    64 =&gt; 'ne',    88 =&gt; 'so',    146 =&gt; 'ga',
    17 =&gt; 'tr',    41 =&gt; 'yi',    65 =&gt; 'sa',    89 =&gt; 'sw',    147 =&gt; 'rar',
    18 =&gt; 'hr',    42 =&gt; 'sr',    66 =&gt; 'mr',    90 =&gt; 'rw',    148 =&gt; 'el',
    19 =&gt; 'zh-TW', 43 =&gt; 'mk',    67 =&gt; 'bn',    91 =&gt; 'rn',    149 =&gt; 'kl',
    20 =&gt; 'ur',    44 =&gt; 'bg',    68 =&gt; 'as',    92 =&gt; 'ny',    150 =&gt; 'az',
    21 =&gt; 'hi',    45 =&gt; 'uk',    69 =&gt; 'gu',    93 =&gt; 'mg',
    22 =&gt; 'th',    46 =&gt; 'be',    70 =&gt; 'pa',    94 =&gt; 'eo',
    23 =&gt; 'ko',    47 =&gt; 'uz',    71 =&gt; 'or',   128 =&gt; 'cy',
  },
  # Windows language codes (http://msdn.microsoft.com/en-us/library/0h88fahh(VS.85).aspx)
  # Notes: This isn't an exact science.  The reference above gives language codes
  # which are different from some ISO 639-1 numbers.  Also, some Windows language
  # codes don't appear to have ISO 639-1 equivalents.
  #  0x0428 - fa by ref above
  #  0x048c - no ISO equivalent
  #  0x081a/0x83c - sr-SP
  #  0x0c0a - modern?
  #  0x2409 - Carribean country code not found in ISO 3166-1
  Windows =&gt; {
    0x0401 =&gt; 'ar-SA', 0x0438 =&gt; 'fo',    0x0481 =&gt; 'mi',    0x1409 =&gt; 'en-NZ',
    0x0402 =&gt; 'bg',    0x0439 =&gt; 'hi',    0x0482 =&gt; 'oc',    0x140a =&gt; 'es-CR',
    0x0403 =&gt; 'ca',    0x043a =&gt; 'mt',    0x0483 =&gt; 'co',    0x140c =&gt; 'fr-LU',
    0x0404 =&gt; 'zh-TW', 0x043b =&gt; 'se-NO', 0x0484 =&gt; 'gsw',   0x141a =&gt; 'bs-BA',
    0x0405 =&gt; 'cs',    0x043c =&gt; 'gd',    0x0485 =&gt; 'sah',   0x143b =&gt; 'smj-SE',
    0x0406 =&gt; 'da',    0x043d =&gt; 'yi',    0x0486 =&gt; 'ny',    0x1801 =&gt; 'ar-MA',
    0x0407 =&gt; 'de-DE', 0x043e =&gt; 'ms-MY', 0x0487 =&gt; 'rw',    0x1809 =&gt; 'en-IE',
    0x0408 =&gt; 'el',    0x043f =&gt; 'kk',    0x048c =&gt; 'Dari',  0x180a =&gt; 'es-PA',
    0x0409 =&gt; 'en-US', 0x0440 =&gt; 'ky',    0x0801 =&gt; 'ar-IQ', 0x180c =&gt; 'fr-MC',
    0x040a =&gt; 'es-ES', 0x0441 =&gt; 'sw',    0x0804 =&gt; 'zh-CN', 0x181a =&gt; 'sr-BA',
    0x040b =&gt; 'fi',    0x0442 =&gt; 'tk',    0x0807 =&gt; 'de-CH', 0x183b =&gt; 'sma-NO',
    0x040c =&gt; 'fr-FR', 0x0443 =&gt; 'uz-UZ', 0x0809 =&gt; 'en-GB', 0x1c01 =&gt; 'ar-TN',
    0x040d =&gt; 'he',    0x0444 =&gt; 'tt',    0x080a =&gt; 'es-MX', 0x1c09 =&gt; 'en-ZA',
    0x040e =&gt; 'hu',    0x0445 =&gt; 'bn-IN', 0x080c =&gt; 'fr-BE', 0x1c0a =&gt; 'es-DO',
    0x040f =&gt; 'is',    0x0446 =&gt; 'pa',    0x0810 =&gt; 'it-CH', 0x1c1a =&gt; 'sr-BA',
    0x0410 =&gt; 'it-IT', 0x0447 =&gt; 'gu',    0x0813 =&gt; 'nl-BE', 0x1c3b =&gt; 'sma-SE',
    0x0411 =&gt; 'ja',    0x0448 =&gt; 'wo',    0x0814 =&gt; 'nn',    0x2001 =&gt; 'ar-OM',
    0x0412 =&gt; 'ko',    0x0449 =&gt; 'ta',    0x0816 =&gt; 'pt-PT', 0x2009 =&gt; 'en-JM',
    0x0413 =&gt; 'nl-NL', 0x044a =&gt; 'te',    0x0818 =&gt; 'ro-MO', 0x200a =&gt; 'es-VE',
    0x0414 =&gt; 'no-NO', 0x044b =&gt; 'kn',    0x0819 =&gt; 'ru-MO', 0x201a =&gt; 'bs-BA',
    0x0415 =&gt; 'pl',    0x044c =&gt; 'ml',    0x081a =&gt; 'sr-RS', 0x203b =&gt; 'sms',
    0x0416 =&gt; 'pt-BR', 0x044d =&gt; 'as',    0x081d =&gt; 'sv-FI', 0x2401 =&gt; 'ar-YE',
    0x0417 =&gt; 'rm',    0x044e =&gt; 'mr',    0x082c =&gt; 'az-AZ', 0x2409 =&gt; 'en-CB',
    0x0418 =&gt; 'ro',    0x044f =&gt; 'sa',    0x082e =&gt; 'dsb',   0x240a =&gt; 'es-CO',
    0x0419 =&gt; 'ru',    0x0450 =&gt; 'mn-MN', 0x083b =&gt; 'se-SE', 0x243b =&gt; 'smn',
    0x041a =&gt; 'hr',    0x0451 =&gt; 'bo',    0x083c =&gt; 'ga',    0x2801 =&gt; 'ar-SY',
    0x041b =&gt; 'sk',    0x0452 =&gt; 'cy',    0x083e =&gt; 'ms-BN', 0x2809 =&gt; 'en-BZ',
    0x041c =&gt; 'sq',    0x0453 =&gt; 'km',    0x0843 =&gt; 'uz-UZ', 0x280a =&gt; 'es-PE',
    0x041d =&gt; 'sv-SE', 0x0454 =&gt; 'lo',    0x0845 =&gt; 'bn-BD', 0x2c01 =&gt; 'ar-JO',
    0x041e =&gt; 'th',    0x0456 =&gt; 'gl',    0x0850 =&gt; 'mn-CN', 0x2c09 =&gt; 'en-TT',
    0x041f =&gt; 'tr',    0x0457 =&gt; 'kok',   0x085d =&gt; 'iu-CA', 0x2c0a =&gt; 'es-AR',
    0x0420 =&gt; 'ur',    0x045a =&gt; 'syr',   0x085f =&gt; 'tmh',   0x3001 =&gt; 'ar-LB',
    0x0421 =&gt; 'id',    0x045b =&gt; 'si',    0x086b =&gt; 'qu-EC', 0x3009 =&gt; 'en-ZW',
    0x0422 =&gt; 'uk',    0x045d =&gt; 'iu-CA', 0x0c01 =&gt; 'ar-EG', 0x300a =&gt; 'es-EC',
    0x0423 =&gt; 'be',    0x045e =&gt; 'am',    0x0c04 =&gt; 'zh-HK', 0x3401 =&gt; 'ar-KW',
    0x0424 =&gt; 'sl',    0x0461 =&gt; 'ne',    0x0c07 =&gt; 'de-AT', 0x3409 =&gt; 'en-PH',
    0x0425 =&gt; 'et',    0x0462 =&gt; 'fy',    0x0c09 =&gt; 'en-AU', 0x340a =&gt; 'es-CL',
    0x0426 =&gt; 'lv',    0x0463 =&gt; 'ps',    0x0c0a =&gt; 'es-ES', 0x3801 =&gt; 'ar-AE',
    0x0427 =&gt; 'lt',    0x0464 =&gt; 'fil',   0x0c0c =&gt; 'fr-CA', 0x380a =&gt; 'es-UY',
    0x0428 =&gt; 'tg',    0x0465 =&gt; 'dv',    0x0c1a =&gt; 'sr-RS', 0x3c01 =&gt; 'ar-BH',
    0x042a =&gt; 'vi',    0x0468 =&gt; 'ha',    0x0c3b =&gt; 'se-FI', 0x3c0a =&gt; 'es-PY',
    0x042b =&gt; 'hy',    0x046a =&gt; 'yo',    0x0c6b =&gt; 'qu-PE', 0x4001 =&gt; 'ar-QA',
    0x042c =&gt; 'az-AZ', 0x046b =&gt; 'qu-BO', 0x1001 =&gt; 'ar-LY', 0x4009 =&gt; 'en-IN',
    0x042d =&gt; 'eu',    0x046c =&gt; 'st',    0x1004 =&gt; 'zh-SG', 0x400a =&gt; 'es-BO',
    0x042e =&gt; 'hsb',   0x046d =&gt; 'ba',    0x1007 =&gt; 'de-LU', 0x4409 =&gt; 'en-MY',
    0x042f =&gt; 'mk',    0x046e =&gt; 'lb',    0x1009 =&gt; 'en-CA', 0x440a =&gt; 'es-SV',
    0x0430 =&gt; 'st',    0x046f =&gt; 'kl',    0x100a =&gt; 'es-GT', 0x4809 =&gt; 'en-SG',
    0x0431 =&gt; 'ts',    0x0470 =&gt; 'ig',    0x100c =&gt; 'fr-CH', 0x480a =&gt; 'es-HN',
    0x0432 =&gt; 'tn',    0x0478 =&gt; 'yi',    0x101a =&gt; 'hr-BA', 0x4c0a =&gt; 'es-NI',
    0x0434 =&gt; 'xh',    0x047a =&gt; 'arn',   0x103b =&gt; 'smj-NO',0x500a =&gt; 'es-PR',
    0x0435 =&gt; 'zu',    0x047c =&gt; 'moh',   0x1401 =&gt; 'ar-DZ', 0x540a =&gt; 'es-US',
    0x0436 =&gt; 'af',    0x047e =&gt; 'br',    0x1404 =&gt; 'zh-MO',
    0x0437 =&gt; 'ka',    0x0480 =&gt; 'ug',    0x1407 =&gt; 'de-LI',
  },
  Unicode =&gt; { },
  ISO     =&gt; { },
  Custom  =&gt; { },
);

# eclectic table of tags for various format font files
%Image::ExifTool::Font::Main = (
    GROUPS =&gt; { 2 =&gt; 'Document' },
    NOTES =&gt; q{
        This table contains a collection of tags found in font files of various
        formats.  ExifTool current recognizes OTF, TTF, TTC, DFONT, PFA, PFB, PFM,
        AFM, ACFM and AMFM font files.
    },
    name =&gt; {
        SubDirectory =&gt; { TagTable =&gt; 'Image::ExifTool::Font::Name' },
    },
    PFM  =&gt; {
        Name =&gt; 'PFMHeader',
        SubDirectory =&gt; { TagTable =&gt; 'Image::ExifTool::Font::PFM' },
    },
    PSInfo =&gt; {
        Name =&gt; 'PSFontInfo',
        SubDirectory =&gt; { TagTable =&gt; 'Image::ExifTool::Font::PSInfo' },
    },
    AFM =&gt; {
        Name =&gt; 'AFM',
        SubDirectory =&gt; { TagTable =&gt; 'Image::ExifTool::Font::AFM' },
    },
    numfonts =&gt; 'NumFonts',
    fontname =&gt; 'FontName',
    postfont =&gt; {
        Name =&gt; 'PostScriptFontName',
        Description =&gt; 'PostScript Font Name',
    },
);

# TrueType name tags (ref 1/2)
%Image::ExifTool::Font::Name = (
    GROUPS =&gt; { 2 =&gt; 'Document' },
    NOTES =&gt; q{
        The following tags are extracted from the TrueType font "name" table found
        in OTF, TTF, TTC and DFONT files.  These tags support localized languages by
        adding a hyphen followed by a language code to the end of the tag name (eg.
        "Copyright-fr" or "License-en-US").  Tags with no language code use the
        default language of "en".
    },
    0 =&gt; { Name =&gt; 'Copyright', Groups =&gt; { 2 =&gt; 'Author' } },
    1 =&gt; 'FontFamily',
    2 =&gt; 'FontSubfamily',
    3 =&gt; 'FontSubfamilyID',
    4 =&gt; 'FontName', # full name
    5 =&gt; 'NameTableVersion',
    6 =&gt; { Name =&gt; 'PostScriptFontName', Description =&gt; 'PostScript Font Name' },
    7 =&gt; 'Trademark',
    8 =&gt; 'Manufacturer',
    9 =&gt; 'Designer',
    10 =&gt; 'Description',
    11 =&gt; 'VendorURL',
    12 =&gt; 'DesignerURL',
    13 =&gt; 'License',
    14 =&gt; 'LicenseInfoURL',
    16 =&gt; 'PreferredFamily',
    17 =&gt; 'PreferredSubfamily',
    18 =&gt; 'CompatibleFontName',
    19 =&gt; 'SampleText',
    20 =&gt; {
        Name =&gt; 'PostScriptFontName',
        Description =&gt; 'PostScript Font Name',
    },
    21 =&gt; 'WWSFamilyName',
    22 =&gt; 'WWSSubfamilyName',
);

# PostScript Font Metric file header (ref 4)
%Image::ExifTool::Font::PFM = (
    GROUPS =&gt; { 2 =&gt; 'Document' },
    PROCESS_PROC =&gt; \&amp;Image::ExifTool::ProcessBinaryData,
    NOTES =&gt; 'Tags extracted from the PFM file header.',
    0 =&gt; {
        Name =&gt; 'PFMVersion',
        Format =&gt; 'int16u',
        PrintConv =&gt; 'sprintf("%x.%.2x",$val&gt;&gt;8,$val&amp;0xff)',
    },
    6  =&gt; { Name =&gt; 'Copyright',       Format =&gt; 'string[60]', Groups =&gt; { 2 =&gt; 'Author' } },
    66 =&gt; { Name =&gt; 'FontType',        Format =&gt; 'int16u' },
    68 =&gt; { Name =&gt; 'PointSize',       Format =&gt; 'int16u' },
    70 =&gt; { Name =&gt; 'YResolution',     Format =&gt; 'int16u' },
    72 =&gt; { Name =&gt; 'XResolution',     Format =&gt; 'int16u' },
    74 =&gt; { Name =&gt; 'Ascent',          Format =&gt; 'int16u' },
    76 =&gt; { Name =&gt; 'InternalLeading', Format =&gt; 'int16u' },
    78 =&gt; { Name =&gt; 'ExternalLeading', Format =&gt; 'int16u' },
    80 =&gt; { Name =&gt; 'Italic' },
    81 =&gt; { Name =&gt; 'Underline' },
    82 =&gt; { Name =&gt; 'Strikeout' },
    83 =&gt; { Name =&gt; 'Weight',          Format =&gt; 'int16u' },
    85 =&gt; { Name =&gt; 'CharacterSet' },
    86 =&gt; { Name =&gt; 'PixWidth',        Format =&gt; 'int16u' },
    88 =&gt; { Name =&gt; 'PixHeight',       Format =&gt; 'int16u' },
    90 =&gt; { Name =&gt; 'PitchAndFamily' },
    91 =&gt; { Name =&gt; 'AvgWidth',        Format =&gt; 'int16u' },
    93 =&gt; { Name =&gt; 'MaxWidth',        Format =&gt; 'int16u' },
    95 =&gt; { Name =&gt; 'FirstChar' },
    96 =&gt; { Name =&gt; 'LastChar' },
    97 =&gt; { Name =&gt; 'DefaultChar' },
    98 =&gt; { Name =&gt; 'BreakChar' },
    99 =&gt; { Name =&gt; 'WidthBytes',      Format =&gt; 'int16u' },
   # 101 =&gt; { Name =&gt; 'DeviceTypeOffset', Format =&gt; 'int32u' },
   # 105 =&gt; { Name =&gt; 'FontNameOffset',   Format =&gt; 'int32u' },
   # 109 =&gt; { Name =&gt; 'BitsPointer',      Format =&gt; 'int32u' },
   # 113 =&gt; { Name =&gt; 'BitsOffset',       Format =&gt; 'int32u' },
);

# PostScript FontInfo attributes (PFA, PFB) (ref PH)
%Image::ExifTool::Font::PSInfo = (
    GROUPS =&gt; { 2 =&gt; 'Document' },
    NOTES =&gt; 'Tags extracted from PostScript font files (PFA and PFB).',
    FullName    =&gt; { },
    FamilyName  =&gt; { Name =&gt; 'FontFamily' },
    Weight      =&gt; { },
    ItalicAngle =&gt; { },
    isFixedPitch=&gt; { },
    UnderlinePosition  =&gt; { },
    UnderlineThickness =&gt; { },
    Copyright   =&gt; { Groups =&gt; { 2 =&gt; 'Author' } },
    Notice      =&gt; { Groups =&gt; { 2 =&gt; 'Author' } },
    version     =&gt; { },
    FontName    =&gt; { },
    FontType    =&gt; { },
    FSType      =&gt; { },
);

# Adobe Font Metrics tags (AFM) (ref 6)
%Image::ExifTool::Font::AFM = (
    GROUPS =&gt; { 2 =&gt; 'Document' },
    NOTES =&gt; 'Tags extracted from Adobe Font Metrics files (AFM, ACFM and AMFM).',
   'Creation Date' =&gt; { Name =&gt; 'CreateDate', Groups =&gt; { 2 =&gt; 'Time' } },
    FontName    =&gt; { },
    FullName    =&gt; { },
    FamilyName =&gt; { Name =&gt; 'FontFamily' },
    Weight      =&gt; { },
    Version     =&gt; { },
    Notice      =&gt; { Groups =&gt; { 2 =&gt; 'Author' } },
    EncodingScheme =&gt; { },
    MappingScheme  =&gt; { },
    EscChar     =&gt; { },
    CharacterSet=&gt; { },
    Characters  =&gt; { },
    IsBaseFont  =&gt; { },
   # VVector     =&gt; { },
    IsFixedV    =&gt; { },
    CapHeight   =&gt; { },
    XHeight     =&gt; { },
    Ascender    =&gt; { },
    Descender   =&gt; { },
);

#------------------------------------------------------------------------------
# Read information from a TrueType font collection (TTC) (refs 2,3)
# Inputs: 0) ExifTool ref, 1) dirInfo ref
# Returns: 1 on success, 0 if this wasn't a valid TrueType font collection
sub ProcessTTC($$)
{
    my ($et, $dirInfo) = @_;
    my $raf = $$dirInfo{RAF};
    my ($buff, $i);

    return 0 unless $raf-&gt;Read($buff, 12) == 12;
    return 0 unless $buff =~ /^ttcf\0[\x01\x02]\0\0/;
    SetByteOrder('MM');
    my $num = Get32u(\$buff, 8);
    # might as well put a limit on the number of fonts we will parse (&lt; 256)
    return 0 unless $num &lt; 0x100 and $raf-&gt;Read($buff, $num * 4) == $num * 4;
    $et-&gt;SetFileType('TTC');
    my $tagTablePtr = GetTagTable('Image::ExifTool::Font::Main');
    $et-&gt;HandleTag($tagTablePtr, 'numfonts', $num);
    # loop through all fonts in the collection
    for ($i=0; $i&lt;$num; ++$i) {
        my $n = $i + 1;
        $et-&gt;VPrint(0, "Font $n:\n");
        $$et{SET_GROUP1} = "+$n";
        my $offset = Get32u(\$buff, $i * 4);
        $raf-&gt;Seek($offset, 0) or last;
        ProcessOTF($et, $dirInfo) or last;
    }
    delete $$et{SET_GROUP1};
    return 1;
}

#------------------------------------------------------------------------------
# Read information from a TrueType font file (OTF or TTF) (refs 1,2)
# Inputs: 0) ExifTool ref, 1) dirInfo ref
# Returns: 1 on success, 0 if this wasn't a valid TrueType font file
sub ProcessOTF($$)
{
    my ($et, $dirInfo) = @_;
    my $raf = $$dirInfo{RAF};
    my ($tbl, $buff, $pos, $i);
    my $base = $$dirInfo{Base} || 0;

    return 0 unless $raf-&gt;Read($buff, 12) == 12;
    return 0 unless $buff =~ /^(\0\x01\0\0|OTTO|true|typ1|\xa5(kbd|lst))[\0\x01]/;

    $et-&gt;SetFileType($1 eq 'OTTO' ? 'OTF' : 'TTF');
    SetByteOrder('MM');
    my $numTables = Get16u(\$buff, 4);
    return 0 unless $numTables &gt; 0 and $numTables &lt; 0x200;
    my $len = $numTables * 16;
    return 0 unless $raf-&gt;Read($tbl, $len) == $len;

    my $verbose = $et-&gt;Options('Verbose');
    my $oldIndent = $$et{INDENT};
    $$et{INDENT} .= '| ';
    $et-&gt;VerboseDir('TrueType', $numTables) if $verbose;

    for ($pos=0; $pos&lt;$len; $pos+=16) {
        # look for 'name' table
        my $tag = substr($tbl, $pos, 4);
        next unless $tag eq 'name' or $verbose;
        my $offset = Get32u(\$tbl, $pos + 8);
        my $size   = Get32u(\$tbl, $pos + 12);
        unless ($raf-&gt;Seek($offset+$base, 0) and $raf-&gt;Read($buff, $size) == $size) {
            $et-&gt;Warn("Error reading '$tag' data");
            next;
        }
        if ($verbose) {
            $tag =~ s/([\0-\x1f\x80-\xff])/sprintf('\x%.2x',ord $1)/ge;
            my $str = sprintf("%s%d) Tag '%s' (offset 0x%.4x, %d bytes)\n",
                              $$et{INDENT}, $pos/16, $tag, $offset, $size);
            $et-&gt;VPrint(0, $str);
            $et-&gt;VerboseDump(\$buff, Addr =&gt; $offset) if $verbose &gt; 2;
            next unless $tag eq 'name';
        }
        next unless $size &gt;= 8;
        my $entries = Get16u(\$buff, 2);
        my $recEnd = 6 + $entries * 12;
        if ($recEnd &gt; $size) {
            $et-&gt;Warn('Truncated name record');
            last;
        }
        my $strStart = Get16u(\$buff, 4);
        if ($strStart &lt; $recEnd or $strStart &gt; $size) {
            $et-&gt;Warn('Invalid string offset');
            last;
        }
        # parse language-tag record (in format 1 Naming table only) (ref 2)
        my %langTag;
        if (Get16u(\$buff, 0) == 1 and $recEnd + 2 &lt;= $size) {
            my $langTags = Get16u(\$buff, $recEnd);
            if ($langTags and $recEnd + 2 + $langTags * 4 &lt; $size) {
                for ($i=0; $i&lt;$langTags; ++$i) {
                    my $pt = $recEnd + 2 + $i * 4;
                    my $langLen = Get16u(\$buff, $pt);
                    # make sure the language string length is reasonable (UTF-16BE)
                    last if $langLen == 0 or $langLen &amp; 0x01 or $langLen &gt; 40;
                    my $langPt = Get16u(\$buff, $pt + 2) + $strStart;
                    last if $langPt + $langLen &gt; $size;
                    my $lang = substr($buff, $langPt, $langLen);
                    $lang = $et-&gt;Decode($lang,'UCS2','MM','UTF8');
                    $lang =~ tr/-_a-zA-Z0-9//dc;    # remove naughty characters
                    $langTag{$i + 0x8000} = $lang;
                }
            }
        }
        my $tagTablePtr = GetTagTable('Image::ExifTool::Font::Name');
        $$et{INDENT} .= '| ';
        $et-&gt;VerboseDir('Name', $entries) if $verbose;
        for ($i=0; $i&lt;$entries; ++$i) {
            my $pt = 6 + $i * 12;
            my $platform = Get16u(\$buff, $pt);
            my $encoding = Get16u(\$buff, $pt + 2);
            my $langID   = Get16u(\$buff, $pt + 4);
            my $nameID   = Get16u(\$buff, $pt + 6);
            my $strLen   = Get16u(\$buff, $pt + 8);
            my $strPt    = Get16u(\$buff, $pt + 10) + $strStart;
            if ($strPt + $strLen &lt;= $size) {
                my $val = substr($buff, $strPt, $strLen);
                my ($lang, $charset, $extra);
                my $sys = $ttPlatform{$platform};
                # translate from specified encoding
                if ($sys) {
                    $lang = $ttLang{$sys}{$langID} || $langTag{$langID};
                    $charset = $ttCharset{$sys}{$encoding};
                    if (not $charset) {
                        if (not defined $charset and not $$et{FontWarn}) {
                            $et-&gt;Warn("Unknown $sys character set ($encoding)");
                            $$et{FontWarn} = 1;
                        }
                    } else {
                        # translate to ExifTool character set
                        $val = $et-&gt;Decode($val, $charset);
                    }
                } else {
                    $et-&gt;Warn("Unknown platform ($platform) for name $nameID");
                }
                # get the tagInfo for our specific language (use 'en' for default)
                my $tagInfo = $et-&gt;GetTagInfo($tagTablePtr, $nameID);
                if ($tagInfo and $lang and $lang ne 'en') {
                    my $langInfo = Image::ExifTool::GetLangInfo($tagInfo, $lang);
                    $tagInfo = $langInfo if $langInfo;
                }
                if ($verbose) {
                    $langID &gt; 0x400 and $langID = sprintf('0x%x', $langID);
                    $extra = ", Plat=$platform/" . ($sys || 'Unknown') . ', ' .
                               "Enc=$encoding/" . ($charset || 'Unknown') . ', ' .
                               "Lang=$langID/" . ($lang || 'Unknown');
                }
                $et-&gt;HandleTag($tagTablePtr, $nameID, $val,
                    TagInfo =&gt; $tagInfo,
                    DataPt  =&gt; \$buff,
                    DataPos =&gt; $offset,
                    Start   =&gt; $strPt,
                    Size    =&gt; $strLen,
                    Index   =&gt; $i,
                    Extra   =&gt; $extra,
                );
            }
        }
        $$et{INDENT} = $oldIndent . '| ';
        last unless $verbose;
    }
    $$et{INDENT} = $oldIndent;
    return 1;
}

#------------------------------------------------------------------------------
# Read information from an Adobe Font Metrics file (AFM, ACFM, AMFM) (ref 6)
# Inputs: 0) ExifTool ref, 1) dirInfo ref
# Returns: 1 on success, 0 if this wasn't a recognized AFM-type file
sub ProcessAFM($$)
{
    my ($et, $dirInfo) = @_;
    my $raf = $$dirInfo{RAF};
    my ($buff, $comment);

    require Image::ExifTool::PostScript;
    local $/ = Image::ExifTool::PostScript::GetInputRecordSeparator($raf);
    $raf-&gt;ReadLine($buff);
    return 0 unless $buff =~ /^Start(Comp|Master)?FontMetrics\s+\d+/;
    my $ftyp = $1 ? ($1 eq 'Comp' ? 'ACFM' : 'AMFM') : 'AFM';
    $et-&gt;SetFileType($ftyp, 'application/x-font-afm');
    my $tagTablePtr = GetTagTable('Image::ExifTool::Font::AFM');

    for (;;) {
        $raf-&gt;ReadLine($buff) or last;
        if (defined $comment and $buff !~ /^Comment\s/) {
            $et-&gt;FoundTag('Comment', $comment);
            undef $comment;
        }
        $buff =~ /^(\w+)\s+(.*?)[\x0d\x0a]/ or next;
        my ($tag, $val) = ($1, $2);
        if ($tag eq 'Comment' and $val =~ /^(Creation Date):\s+(.*)/) {
            ($tag, $val) = ($1, $2);
        }
        $val =~ s/^\((.*)\)$/$1/;   # (some values may be in brackets)
        if ($tag eq 'Comment') {
            # concatinate all comments into a single value
            $comment = defined($comment) ? "$comment\n$val" : $val;
            next;
        }
        unless ($et-&gt;HandleTag($tagTablePtr, $tag, $val)) {
            # end parsing if we start any subsection
            last if $tag =~ /^Start/ and $tag ne 'StartDirection';
        }
    }
    return 1;
}

#------------------------------------------------------------------------------
# Read information from various format font files
# Inputs: 0) ExifTool ref, 1) dirInfo ref
# Returns: 1 on success, 0 if this wasn't a recognized Font file
sub ProcessFont($$)
{
    my ($et, $dirInfo) = @_;
    my $raf = $$dirInfo{RAF};
    my ($buff, $buf2, $rtnVal);
    return 0 unless $raf-&gt;Read($buff, 24) and $raf-&gt;Seek(0,0);
    if ($buff =~ /^(\0\x01\0\0|OTTO|true|typ1)[\0\x01]/) {        # OTF, TTF
        $rtnVal = ProcessOTF($et, $dirInfo);
    } elsif ($buff =~ /^ttcf\0[\x01\x02]\0\0/) {                  # TTC
        $rtnVal = ProcessTTC($et, $dirInfo);
    } elsif ($buff =~ /^Start(Comp|Master)?FontMetrics\s+\d+/s) { # AFM
        $rtnVal = ProcessAFM($et, $dirInfo);
    } elsif ($buff =~ /^(.{6})?%!(PS-(AdobeFont-|Bitstream )|FontType1-)/s) {# PFA, PFB
        $raf-&gt;Seek(6,0) and $et-&gt;SetFileType('PFB') if $1;
        require Image::ExifTool::PostScript;
        $rtnVal = Image::ExifTool::PostScript::ProcessPS($et, $dirInfo);
    } elsif ($buff =~ /^\0[\x01\x02]/ and $raf-&gt;Seek(0, 2) and    # PFM
             # validate file size
             $raf-&gt;Tell() &gt; 117 and $raf-&gt;Tell() == unpack('x2V',$buff) and
             # read PFM header
             $raf-&gt;Seek(0,0) and $raf-&gt;Read($buff,117) == 117 and
             # validate "DeviceType" string (must be "PostScript\0")
             SetByteOrder('II') and $raf-&gt;Seek(Get32u(\$buff, 101), 0) and
             # the DeviceType should be "PostScript\0", but FontForge
             # incorrectly writes "Postscript\0", so ignore case
             $raf-&gt;Read($buf2, 11) == 11 and lc($buf2) eq "postscript\0")
    {
        $et-&gt;SetFileType('PFM');
        SetByteOrder('II');
        my $tagTablePtr = GetTagTable('Image::ExifTool::Font::Main');
        # process the PFM header
        $et-&gt;HandleTag($tagTablePtr, 'PFM', $buff);
        # extract the font names
        my $nameOff = Get32u(\$buff, 105);
        if ($raf-&gt;Seek($nameOff, 0) and $raf-&gt;Read($buff, 256) and
            $buff =~ /^([\x20-\xff]+)\0([\x20-\xff]+)\0/)
        {
            $et-&gt;HandleTag($tagTablePtr, 'fontname', $1);
            $et-&gt;HandleTag($tagTablePtr, 'postfont', $2);
        }
        $rtnVal = 1;
    } else {
        $rtnVal = 0;
    }
    return $rtnVal;
}

1;  # end

__END__

=head1 NAME

Image::ExifTool::Font - Read meta information from font files

=head1 SYNOPSIS

This module is used by Image::ExifTool

=head1 DESCRIPTION

This module contains the routines required by Image::ExifTool to read meta
information from various format font files.  Currently recognized font file
types are OTF, TTF, TTC, DFONT, PFA, PFB, PFM, AFM, ACFM and AMFM.

=head1 AUTHOR

Copyright 2003-2015, Phil Harvey (phil at owl.phy.queensu.ca)

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 REFERENCES

=over 4

=item L&lt;http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6.html&gt;

=item L&lt;http://www.microsoft.com/typography/otspec/otff.htm&gt;

=item L&lt;http://partners.adobe.com/public/developer/opentype/index_font_file.html&gt;

=item L&lt;http://partners.adobe.com/public/developer/en/font/5178.PFM.pdf&gt;

=item L&lt;http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/util/MimeMappings.java&gt;

=item L&lt;http://www.adobe.com/devnet/font/pdfs/5004.AFM_Spec.pdf&gt;

=back

=head1 SEE ALSO

L&lt;Image::ExifTool::TagNames/Font Tags&gt;,
L&lt;Image::ExifTool(3pm)|Image::ExifTool&gt;

=cut

</pre></body></html>