{
    "mode": "perldoc",
    "parameter": "Font::TTF::Font",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Font%3A%3ATTF%3A%3AFont/json",
    "generated": "2026-06-13T07:01:42Z",
    "synopsis": "Here is the regression test (you provide your own font). Run it once and then again on the\noutput of the first run. There should be no differences between the outputs of the two runs.\n$f = Font::TTF::Font->open($ARGV[0]);\n# force a read of all the tables\n$f->tablesdo(sub { $[0]->read; });\n# force read of all glyphs (use readdat to use lots of memory!)\n# $f->{'loca'}->glyphsdo(sub { $[0]->read; });\n$f->{'loca'}->glyphsdo(sub { $[0]->readdat; });\n# NB. no need to $g->update since $f->{'glyf'}->out will do it for us\n$f->out($ARGV[1]);\n$f->release;            # clear up memory forcefully!",
    "sections": {
        "NAME": {
            "content": "Font::TTF::Font - Memory representation of a font\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "Here is the regression test (you provide your own font). Run it once and then again on the\noutput of the first run. There should be no differences between the outputs of the two runs.\n\n$f = Font::TTF::Font->open($ARGV[0]);\n\n# force a read of all the tables\n$f->tablesdo(sub { $[0]->read; });\n\n# force read of all glyphs (use readdat to use lots of memory!)\n# $f->{'loca'}->glyphsdo(sub { $[0]->read; });\n$f->{'loca'}->glyphsdo(sub { $[0]->readdat; });\n# NB. no need to $g->update since $f->{'glyf'}->out will do it for us\n\n$f->out($ARGV[1]);\n$f->release;            # clear up memory forcefully!\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "A Truetype font consists of a header containing a directory of tables which constitute the rest\nof the file. This class holds that header and directory and also creates objects of the\nappropriate type for each table within the font. Note that it does not read each table into\nmemory, but creates a short reference which can be read using the form:\n\n$f->{$tablename}->read;\n\nClasses are included that support many of the different TrueType tables. For those for which no\nspecial code exists, the table type \"table\" is used, which defaults to Font::TTF::Table. The\ncurrent tables which are supported are:\n\ntable       Font::TTF::Table      - for unknown tables\nEBDT        Font::TTF::EBDT\nEBLC        Font::TTF::EBLC\nFeat        Font::TTF::GrFeat\nGDEF        Font::TTF::GDEF\nGPOS        Font::TTF::GPOS\nGSUB        Font::TTF::GSUB\nGlat        Font::TTF::Glat\nGloc        Font::TTF::Gloc\nLTSH        Font::TTF::LTSH\nOS/2        Font::TTF::OS2\nPCLT        Font::TTF::PCLT\nSill        Font::TTF::Sill\nSilf        Font::TTF::Silf\nbsln        Font::TTF::Bsln\ncmap        Font::TTF::Cmap       - see also Font::TTF::OldCmap\ncvt         Font::TTF::Cvt\nfdsc        Font::TTF::Fdsc\nfeat        Font::TTF::Feat\nfmtx        Font::TTF::Fmtx\nfpgm        Font::TTF::Fpgm\nglyf        Font::TTF::Glyf       - see also Font::TTF::Glyph\nhdmx        Font::TTF::Hdmx\nhead        Font::TTF::Head\nhhea        Font::TTF::Hhea\nhmtx        Font::TTF::Hmtx\nkern        Font::TTF::Kern       - see alternative Font::TTF::AATKern\nloca        Font::TTF::Loca\nmaxp        Font::TTF::Maxp\nmort        Font::TTF::Mort       - see also Font::TTF::OldMort\nname        Font::TTF::Name\npost        Font::TTF::Post\nprep        Font::TTF::Prep\nprop        Font::TTF::Prop\nvhea        Font::TTF::Vhea\nvmtx        Font::TTF::Vmtx\nDSIG        FONT::TTF::DSIG\n\nLinks are:\n\nFont::TTF::Table Font::TTF::EBDT Font::TTF::EBLC Font::TTF::GrFeat Font::TTF::GDEF\nFont::TTF::GPOS Font::TTF::GSUB Font::TTF::Glat Font::TTF::Gloc Font::TTF::LTSH Font::TTF::OS2\nFont::TTF::PCLT Font::TTF::Sill Font::TTF::Silf Font::TTF::Bsln Font::TTF::Cmap Font::TTF::Cvt\nFont::TTF::Fdsc Font::TTF::Feat Font::TTF::Fmtx Font::TTF::Fpgm Font::TTF::Glyf Font::TTF::Hdmx\nFont::TTF::Head Font::TTF::Hhea Font::TTF::Hmtx Font::TTF::Kern Font::TTF::Loca Font::TTF::Maxp\nFont::TTF::Mort Font::TTF::Name Font::TTF::Post Font::TTF::Prep Font::TTF::Prop Font::TTF::Vhea\nFont::TTF::Vmtx Font::TTF::OldCmap Font::TTF::Glyph Font::TTF::AATKern Font::TTF::OldMort\nFont::TTF::DSIG\n",
            "subsections": []
        },
        "INSTANCE VARIABLES": {
            "content": "Instance variables begin with a space (and have lengths greater than the 4 characters which make\nup table names).\n\nnocsum\nThis is used during output to disable the creation of the file checksum in the head table.\nFor example, during DSIG table creation, this flag will be set to ensure that the file\nchecksum is left at zero.\n\nnoharmony\nIf set, do not harmonize the script and lang trees of GPOS and GSUB tables. See\nFont::TTF::Ttopen for more info.\n\nnocompress\nIs the default value controlling WOFF output table compression. If undef, all tables will be\ncompressed if there is a size benefit in doing so. It may be set to an array of tagnames\nnaming tables that should not be compressed, or to a scalar integer specifying a table size\nthreshold below which tables will not be compressed. Note that individual Font::TTF::Table\nobjects may override this default. See Font::TTF::Table for more info.\n\nfname (R)\nContains the filename of the font which this object was read from.\n\nINFILE (P)\nThe file handle which reflects the source file for this font.\n\nOFFSET (P)\nContains the offset from the beginning of the read file of this particular font directory,\nthus providing support for TrueType Collections.\n\nWOFF\nContains a reference to a \"Font::TTF::Woff\" object.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "Font::TTF::Font->AddTable($tablename, $class)\nAdds the given class to be used when representing the given table name. It also 'requires' the\nclass for you.\n\nFont::TTF::Font->Init\nFor those people who like making fonts without reading them. This subroutine will require all\nthe table code for the various table types for you. Not needed if using Font::TTF::Font::read\nbefore using a table.\n\nFont::TTF::Font->new(%props)\nCreates a new font object and initialises with the given properties. This is primarily for use\nwhen a TTF is embedded somewhere. Notice that the properties are automatically preceded by a\nspace when inserted into the object. This is in order that fields do not clash with tables.\n\nFont::TTF::Font->open($fname)\nReads the header and directory for the given font file and creates appropriate objects for each\ntable in the font.\n\n$f->read\nReads a Truetype font directory starting from location \"$self-\"{' OFFSET'}> in the file. This\nhas been separated from the \"open\" function to allow support for embedded TTFs for example in\nTTCs. Also reads the \"head\" and \"maxp\" tables immediately.\n\n$f->out($fname [, @tablelist])\nWrites a TTF file consisting of the tables in tablelist. The list is checked to ensure that only\ntables that exist are output. (This means that you cannot have non table information stored in\nthe font object with key length of exactly 4)\n\nIn many cases the user simply wants to output all the tables in alphabetical order. This can be\ndone by not including a @tablelist, in which case the subroutine will output all the defined\ntables in the font in alphabetical order.\n\nReturns $f on success and undef on failure, including warnings.\n\nAll output files must include the \"head\" table.\n\n$f->outxml($filename [, @tables])\nOutputs the font in XML format\n\n$f->XMLstart($context, $tag, %attrs)\nHandles start messages from the XML parser. Of particular interest to us are <font> and <table>.\n\n$f->update\nSends update to all the tables in the font and then resets all the isDirty flags on each table.\nThe data structure in now consistent as a font (we hope).\n\n$f->dirty\nDirties all the tables in the font\n\n$f->tablesdo(&func [, tables])\nCalls &func for each table in the font. Calls the table in alphabetical sort order as per the\norder in the directory:\n\n&func($table, $name);\n\nMay optionally take a list of table names in which case func is called for each of them in the\ngiven order.\n\n$f->release\nReleases ALL of the memory used by the TTF font and all of its component objects. After calling\nthis method, do NOT expect to have anything left in the \"Font::TTF::Font\" object.\n\nNOTE, that it is important that you call this method on any \"Font::TTF::Font\" object when you\nwish to destruct it and free up its memory. Internally, we track things in a structure that can\nresult in circular references, and without calling '\"release()\"' these will not properly get\ncleaned up by Perl. Once you've called this method, though, don't expect to be able to do\nanything else with the \"Font::TTF::Font\" object; it'll have no internal state whatsoever.\n\nDeveloper note: As part of the brute-force cleanup done here, this method will throw a warning\nmessage whenever unexpected key values are found within the \"Font::TTF::Font\" object. This is\ndone to help ensure that any unexpected and unfreed values are brought to your attention so that\nyou can bug us to keep the module updated properly; otherwise the potential for memory leaks due\nto dangling circular references will exist.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Bugs abound aplenty I am sure. There is a lot of code here and plenty of scope. The parts of the\ncode which haven't been implemented yet are:\n\nPost\nVersion 4 format types are not supported yet.\n\nCmap\nFormat type 2 (MBCS) has not been implemented yet and therefore may cause somewhat spurious\nresults for this table type.\n\nKern\nOnly type 0 & type 2 tables are supported (type 1 & type 3 yet to come).\n\nTTC and WOFF\nThe current Font::TTF::Font::out method does not support the writing of TrueType Collections\nor WOFF files.\n\nDSIG\nHaven't figured out how to correctly calculate and output digital signature (DSIG) table\n\nIn addition there are weaknesses or features of this module library\n\n*   There is very little (or no) error reporting. This means that if you have garbled data or\ngarbled data structures, then you are liable to generate duff fonts.\n\n*   The exposing of the internal data structures everywhere means that doing radical\nre-structuring is almost impossible. But it stop the code from becoming ridiculously large.\n\nApart from these, I try to keep the code in a state of \"no known bugs\", which given the amount\nof testing this code has had, is not a guarantee of high quality, yet.\n\nFor more details see the appropriate class files.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Martin Hosken <http://scripts.sil.org/FontUtils>.\n",
            "subsections": []
        },
        "LICENSING": {
            "content": "Copyright (c) 1998-2016, SIL International (http://www.sil.org)\n\nThis module is released under the terms of the Artistic License 2.0. For details, see the full\ntext of the license in the file LICENSE.\n",
            "subsections": []
        }
    },
    "summary": "Font::TTF::Font - Memory representation of a font",
    "flags": [],
    "examples": [],
    "see_also": []
}