ADi-FontEngine  1.0
PDF Optimized FontEngine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FontEngine::TFont Class Reference

The primary font class with short sample to open font and get glyph information: More...

#include <FontEngine.h>

Public Types

enum  EFType {
  eftUnknown, eftCFF, eftType1, eftTrueType,
  eftOpenTypeCFF, eftTTMacSFNT, eftOTMacSFNTCFF, eftTTCollection,
  eftOTCollectionCFF
}
 possible font types More...
 
enum  ESVGFlags {
  esfNoBkgd = 0x0001, esfNoBBox = 0x0002, esfNoFill = 0x0004, esfNoStroke = 0x0008,
  esfNoPoints = 0x0010, esfNoCross = 0x0020, esfFitToGlyph = 0x0040, esfHStem = 0x0080,
  esfVStem = 0x0100, esfHStemCross = 0x0200, esfVStemCross = 0x0400, esfPtTooltip = 0x0800
}
 parameter flags to control glyph dump svg More...
 
typedef unsigned int TSVGFlags
 
typedef FontEngine::TPath TPath
 
typedef std::pair< TPath, EFTypeTFontPath
 
typedef std::vector< TFontPathTFontPathVec
 
typedef unsigned int TGID
 glyph id, can be used only in CFF and TrueType fonts More...
 

Public Member Functions

 TFont (const TPathParamMap &ppm)
 default ctor More...
 
 TFont (const std::string &fontname, const TFontDictionary &fd, TEmbFontParameter &efp)
 ctor to create a new font More...
 
 TFont (const TFont &font)
 copy ctor More...
 
TFontoperator= (const TFont &font)
 assignment operator More...
 
 ~TFont ()
 dtor More...
 
void initPathParameter (const TPathParamMap &ppm)
 set new parameter map More...
 
EFType open (const TPath &fname, unsigned int findex, EFType favorit=eftUnknown)
 open a font file from file path More...
 
EFType openPDFstream (std::istream &fontstream, EFType favorit)
 open a font from pdf stream, this can be only one font, i.e. no font collection More...
 
EFType openOTBlocks (const TBlock &headBlock, const TBlock &cmapBlock, const TBlock &glyfBlock, const TBlock &hheaBlock, const TBlock &hmtxBlock, const TBlock &locaBlock, const TBlock &maxpBlock, const TBlock &cff_Block, const TBlock &os_2Block, const TBlock &postBlock, const TBlock &nameBlock)
 open a TrueType or OpenType font from seperate font data buffern More...
 
void getFontDump (TDumpParam &dumparam) const
 make a font dump, all data will be appear in dumparam._dumptext, see TDumpParam More...
 
void glyphSVG (std::ostream &svgFile, const TGOutline &gout, const TFPoint &orghtmlsize, const TFPoint &cursor, TSVGFlags flags) const
 render a glyph into a ostream in svg format More...
 
void subset (TEmbFontParameter &efp)
 make a subset from this font, if the font is a PostScript Type font it wil be converted into a CFF font More...
 
void setFontName (const std::string &fontname, const std::string &fontfamily)
 set the font name and family name in this font, if the font is a PostScript Type font it wil be converted into a CFF font More...
 
TGID appendGlyph (const TEmbFontData &efd, bool as_cid)
 append a new glyph at the end of glyph table, not possible if the font is a PostScript Type font More...
 
bool isWriteable () const
 get writable state More...
 
void write (std::ostream &fontstream)
 write the complete font into a ostream, if the font is a PostScript Type font it wil be converted into a CFF font More...
 
void setCurrentFontIndex (unsigned int curidx)
 set the current font index, use this function to select a cid font into an OpenType cid font More...
 
bool hasT1Font () const
 get open font state More...
 
bool hasCFFFont () const
 get open font state More...
 
bool hasTTFont () const
 get open font state More...
 
EFType getFontType () const
 get open font state More...
 
unsigned int getNumberOfFonts () const
 get number of different fonts in one file. TrueType collections, PostScript Type1 and OpenType-CFF fonts can contain more than one font More...
 
TFontDictionary getFontDict () const
 get all data to fill a Font or FontDecriptor dictionary needed by a pdf file More...
 
TAltNameSet getAltNames () const
 get a data set of alternate font names, these names are collected on any relevant point in the font More...
 
TBBox getFontBBox () const
 get the font bounding box More...
 
unsigned int getNumberOfGlyphs () const
 get the number of all glyphs in the font. TrueType return also all composite glyphs. CFF-CID return all glyphs from whole font file. More...
 
unsigned int getTTNumberOf_cmap () const
 (TrueType only) the number of 'cmap' tables More...
 
void getFontEncGlyphs (TEncGlyphVec &egv, bool forceCIDFont) const
 get glyph information to find and identify each glyph in libraries own data base More...
 
std::string getEncodingDump (const TEncInfo &encinfo) const
 get a human readable txt string to specific encoding More...
 
TWidth getGWidth (TGID gid) const
 get glyph width from gid, this can be used for TrueType and cff fonts More...
 
TWidth getGWidth (const std::string &gname) const
 get glyph width from glyph name, this can be used for PostScript Type1 and non cid cff fonts More...
 
TGlyphBox getGBox (TGID gid) const
 get glyph bounding box from gid, this can be used for TrueType and cff fonts More...
 
TGlyphBox getGBox (const std::string &gname) const
 get glyph bounding box from glyph name, this can be used for PostScript Type1 and non cid cff fonts More...
 
TGOutline getGCurves (TGID gid, bool hint_info=false, TGInfoVec *ginfo=NULL) const
 get glyph outline curves from gid, this can be used for TrueType and cff fonts More...
 
TGOutline getGCurves (const std::string &gname, bool hint_info=false, TGInfoVec *ginfo=NULL) const
 get glyph outline curves from glyph name, this can be used for PostScript Type1 and non cid cff fonts More...
 
void getGDump (TGID gid, TDumpParam &dumparam) const
 get glyph dump data from gid, this can be used for TrueType and cff fonts More...
 
void getGDump (const std::string &gname, TDumpParam &dumparam) const
 get glyph dump data from glyph name, this can be used for PostScript Type1 and non cid cff fonts More...
 
bool getCIDSystemInfo (std::string &registry, std::string &ordering, int &supplement) const
 get CIDSystemInfo from font, this can be used for PostScript Type1 and cid cff fonts More...
 
bool isCIDFont ()
 get information if the font is a cid font, this can be used for PostScript Type1 and cid cff fonts More...
 
bool hasTTPostScriptInfo () const
 (TrueType only) get information about the 'post' table More...
 
TPSName getTTGlyphPSName (TGID gid) const
 (TrueType only) get glyph PostScript name from gid More...
 
TUShortBoolRes getTTOS2TypeFlag () const
 (TrueType only) get the 'os_2' Type flags, this contain license information More...
 
bool cmapTTPresent (unsigned short platform, unsigned short encoding) const
 (TrueType only) determine whether a specific encoding is present in 'cmap' table More...
 
TEncInfoVec getTTcmapInfo () const
 (TrueType only) get all encoding information from 'cmap' tables More...
 
T1PiecesLength getT1PiecesLength () const
 (PostScript Type1 only) get byte lengths from the three PostScript Type1 font parts More...
 
int getT1NumberOfMMaster () const
 (PostScript Type1 only) get size of "WeightVector" vector from MultipleMaster font More...
 
void setT1MMasterIndex (unsigned int mmidx)
 (PostScript Type1 only) set the font master index in MultipleMaster font, must be in range of [0 getT1NumberOfMMaster()] More...
 

Static Public Member Functions

static EFType isFont (const TPath &fname)
 return true if font engine can identify the given file as font More...
 

Friends

struct TFontThreadData
 

Detailed Description

The primary font class with short sample to open font and get glyph information:

// ADiFEFontDemo.cpp
//
#include <stdio.h>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
typedef FontEngine::TEncGlyphVec::size_type TEncGlyphVecST;
//! \brief demo main function
int main( int argc, char* argv[])
{
//!< init parameter
ppm["etc"] = L"C:\\Program Files (x86)\\InsideFont\\etc"; //! the path to etc folder FontEngine can find the encoding information here.
//! FontEngine font instance
FontEngine::TFont font( ppm);
FontEngine::TFont::EFType fonttype( font.open( L"C:\\WINDOWS\\FONTS\\ARIAL.TTF", 0));
//! to open a font pdf stream you must use 'openPDFstream' function with unfiltered (decoded) stream data.
//! check font type first
if( FontEngine::TFont::eftTrueType == fonttype) {
FontEngine::TFontDictionary fdict( font.getFontDict()); //! get ordinary font information derived from what is needed in pdf files
font.getFontEncGlyphs( egv, false);
for( TEncGlyphVecST i = 0; i < egv.size(); ++i) {
const FontEngine::TEncGlyph & eg = egv[i];
for( size_t j = 0; j < eg._ccodeGIDVec.size(); ++j) {
const FontEngine::TGlyph & gt = eg._ccodeGIDVec[j];
// Get all information about single glyph in 'gt', such "glyp name", gid, "char code", Unicode and CID.
// Regard the gt._vmask to see what member are valid. Not all of these members are available in all fonts.
// You know that PostScript Type1 fonts use a glyph name to identify including glyphs. Also in non CID-CFF fonts
// (called simple CFF font) glyph names can be used to select glyps. In TrueType and CID-CFF fonts only Glyph ids (GID) can
// be used to select specific glyph.
//! sample to get width information from single glyph 'gt'
if( FontEngine::TFont::eftType1 == fonttype) {
FontEngine::TWidth gw( font.getGWidth( gt._psname));
} else {
FontEngine::TWidth gw( font.getGWidth( gt._gid));
}
//! sample to get bounding box information from single glyph 'gt'
if( FontEngine::TFont::eftType1 == fonttype) {
FontEngine::TGlyphBox gb( font.getGBox( gt._psname));
} else {
FontEngine::TGlyphBox gb( font.getGBox( gt._gid));
}
//! sample to get glyph conture (lines and curves) information from single glyph 'gt'
if( FontEngine::TFont::eftType1 == fonttype) {
FontEngine::TGOutline go( font.getGCurves( gt._psname));
} else {
FontEngine::TGOutline go( font.getGCurves( gt._gid));
}
}
}
}
return 0;
}

Member Typedef Documentation

typedef std::pair< TPath, EFType > FontEngine::TFont::TFontPath
typedef unsigned int FontEngine::TFont::TGID

glyph id, can be used only in CFF and TrueType fonts

typedef unsigned int FontEngine::TFont::TSVGFlags

Member Enumeration Documentation

possible font types

Enumerator
eftUnknown 

no font file or unknown font format

eftCFF 

cff font (such fonts don't exists as single file, but will be used in pdf files)

eftType1 

PostScript Type1 font.

eftTrueType 

TrueType font.

eftOpenTypeCFF 

OpenType font with 'cff ' table.

eftTTMacSFNT 

TrueType font encapsulated in Mac Resource 'sfnt' wrapper.

eftOTMacSFNTCFF 

OpenType font with 'cff ' table encapsulated in Mac Resource 'sfnt' wrapper (never seen such files!)

eftTTCollection 

TrueType fonts collection.

eftOTCollectionCFF 

OpenType font collection with 'cff ' table (never seen such files!)

parameter flags to control glyph dump svg

Enumerator
esfNoBkgd 

paint no background (scale paper and origin lines)

esfNoBBox 

paint no bounding box and width gray area

esfNoFill 

don't fill the glyph with blue

esfNoStroke 

don't stroke the glyph outline with black

esfNoPoints 

paint no line and curve points

esfNoCross 

paint no red hair cross on given cursor pos

esfFitToGlyph 

max scale glyph to visible area

esfHStem 

paint horizontal stem hints if available

esfVStem 

paint vertical stem hints if available

esfHStemCross 

the cross parameter is a horz stem hint

esfVStemCross 

the cross parameter is a vert stem hint

esfPtTooltip 

show a tooltip on each point

Constructor & Destructor Documentation

FontEngine::TFont::TFont ( const TPathParamMap ppm)
inline

default ctor

Parameters
ppmparameter map, see description at TPathParamMap
FontEngine::TFont::TFont ( const std::string &  fontname,
const TFontDictionary fd,
TEmbFontParameter efp 
)

ctor to create a new font

Parameters
fontnamethe font name
fdordinary font traits comparable with PDF FontDescriptor
efpmust contain glyph information and output format
FontEngine::TFont::TFont ( const TFont font)

copy ctor

Parameters
fontto copy from
FontEngine::TFont::~TFont ( )

dtor

Member Function Documentation

TGID FontEngine::TFont::appendGlyph ( const TEmbFontData efd,
bool  as_cid 
)

append a new glyph at the end of glyph table, not possible if the font is a PostScript Type font

Parameters
efdthe glyph data, see TEmbFontData
as_cidmust be true if the font is a cid font
Returns
the new glyph gid
bool FontEngine::TFont::cmapTTPresent ( unsigned short  platform,
unsigned short  encoding 
) const

(TrueType only) determine whether a specific encoding is present in 'cmap' table

Parameters
platformthe wishing platform
encodingthe wishing encoding
Returns
true if the specific encoding is present
TAltNameSet FontEngine::TFont::getAltNames ( ) const

get a data set of alternate font names, these names are collected on any relevant point in the font

Returns
alternate name set
bool FontEngine::TFont::getCIDSystemInfo ( std::string &  registry,
std::string &  ordering,
int &  supplement 
) const

get CIDSystemInfo from font, this can be used for PostScript Type1 and cid cff fonts

Parameters
registryname filled by function
orderingname filled by function
supplementinteger filled by function
Returns
true if such inforamtion is available
std::string FontEngine::TFont::getEncodingDump ( const TEncInfo encinfo) const

get a human readable txt string to specific encoding

Parameters
encinfothe encoding to get text
Returns
human readable txt string to specific encoding
TBBox FontEngine::TFont::getFontBBox ( ) const

get the font bounding box

Returns
font bounding box
TFontDictionary FontEngine::TFont::getFontDict ( ) const

get all data to fill a Font or FontDecriptor dictionary needed by a pdf file

Returns
the font data
void FontEngine::TFont::getFontDump ( TDumpParam dumparam) const

make a font dump, all data will be appear in dumparam._dumptext, see TDumpParam

Parameters
dumparamthe parameter to set how the dump should be performed, see TDumpParam
void FontEngine::TFont::getFontEncGlyphs ( TEncGlyphVec egv,
bool  forceCIDFont 
) const

get glyph information to find and identify each glyph in libraries own data base

Parameters
egvthe data base struct to receive glyph information, see TEncGlyphVec
forceCIDFonttry to identify the font as cid font
Returns
EFType FontEngine::TFont::getFontType ( ) const
inline

get open font state

Returns
return type from font is currently open
TGlyphBox FontEngine::TFont::getGBox ( TGID  gid) const

get glyph bounding box from gid, this can be used for TrueType and cff fonts

Parameters
gidthe glyph id to get bounding box
Returns
glyph bounding box
TGlyphBox FontEngine::TFont::getGBox ( const std::string &  gname) const

get glyph bounding box from glyph name, this can be used for PostScript Type1 and non cid cff fonts

Parameters
gnamethe glyph name to get bounding box
Returns
glyph bounding box
TGOutline FontEngine::TFont::getGCurves ( TGID  gid,
bool  hint_info = false,
TGInfoVec ginfo = NULL 
) const

get glyph outline curves from gid, this can be used for TrueType and cff fonts

Parameters
gidthe glyph id to get outline curves
hint_infoif true also stem hint info wil be appear into the outline data
ginfoif unequal to NULL this struct receive encoding info from this glyph
Returns
glyph outline data
TGOutline FontEngine::TFont::getGCurves ( const std::string &  gname,
bool  hint_info = false,
TGInfoVec ginfo = NULL 
) const

get glyph outline curves from glyph name, this can be used for PostScript Type1 and non cid cff fonts

Parameters
gnamethe glyph name to get outline curves
hint_infoif true also stem hint info wil be appear into the outline data
ginfoif unequal to NULL this struct receive encoding info from this glyph
Returns
glyph outline data
void FontEngine::TFont::getGDump ( TGID  gid,
TDumpParam dumparam 
) const

get glyph dump data from gid, this can be used for TrueType and cff fonts

Parameters
gidthe glyph id to get dump data
dumparamthe dump data filled by this function, see TDumpParam
void FontEngine::TFont::getGDump ( const std::string &  gname,
TDumpParam dumparam 
) const

get glyph dump data from glyph name, this can be used for PostScript Type1 and non cid cff fonts

Parameters
gnamethe glyph name to get dump data
dumparamthe dump data filled by this function, see TDumpParam
TWidth FontEngine::TFont::getGWidth ( TGID  gid) const

get glyph width from gid, this can be used for TrueType and cff fonts

Parameters
gidthe glyph id to get width
Returns
glyph width
TWidth FontEngine::TFont::getGWidth ( const std::string &  gname) const

get glyph width from glyph name, this can be used for PostScript Type1 and non cid cff fonts

Parameters
gnamethe glyph name to get width
Returns
glyph width
unsigned int FontEngine::TFont::getNumberOfFonts ( ) const
inline

get number of different fonts in one file. TrueType collections, PostScript Type1 and OpenType-CFF fonts can contain more than one font

Returns
number of different fonts
unsigned int FontEngine::TFont::getNumberOfGlyphs ( ) const

get the number of all glyphs in the font. TrueType return also all composite glyphs. CFF-CID return all glyphs from whole font file.

Returns
number of all glyphs
int FontEngine::TFont::getT1NumberOfMMaster ( ) const

(PostScript Type1 only) get size of "WeightVector" vector from MultipleMaster font

Returns
the size of "WeightVector" vector from MultipleMaster font
T1PiecesLength FontEngine::TFont::getT1PiecesLength ( ) const

(PostScript Type1 only) get byte lengths from the three PostScript Type1 font parts

Returns
byte lengths struct, see T1PiecesLength
TEncInfoVec FontEngine::TFont::getTTcmapInfo ( ) const

(TrueType only) get all encoding information from 'cmap' tables

Returns
encoding information from 'cmap' tables, see TEncInfoVec
TPSName FontEngine::TFont::getTTGlyphPSName ( TGID  gid) const

(TrueType only) get glyph PostScript name from gid

Parameters
gidthe glyph id to get PostScript name
Returns
the glyph PostScript name
unsigned int FontEngine::TFont::getTTNumberOf_cmap ( ) const

(TrueType only) the number of 'cmap' tables

Returns
number of 'cmap' tables
TUShortBoolRes FontEngine::TFont::getTTOS2TypeFlag ( ) const

(TrueType only) get the 'os_2' Type flags, this contain license information

Returns
the 'os_2' Type flags in first and present bool in second
void FontEngine::TFont::glyphSVG ( std::ostream &  svgFile,
const TGOutline gout,
const TFPoint orghtmlsize,
const TFPoint cursor,
TSVGFlags  flags 
) const

render a glyph into a ostream in svg format

Parameters
svgFilean ostream that will recive the svg code
goutthe glyph outline data, to get call getGCurves(..)
orghtmlsizethe width and heigth of the output svg, can be used to put it into a gui control e.g.
cursora cursor pos to draw a hair cross or stem hints, see enum ESVGFlags
flagsa bitmask flag to set output appearance, see enum ESVGFlags
bool FontEngine::TFont::hasCFFFont ( ) const
inline

get open font state

Returns
return true if cff font is currently open
bool FontEngine::TFont::hasT1Font ( ) const
inline

get open font state

Returns
return true if a PostScript Type1 font is currently open
bool FontEngine::TFont::hasTTFont ( ) const
inline

get open font state

Returns
return true if a TrueType font is currently open
bool FontEngine::TFont::hasTTPostScriptInfo ( ) const

(TrueType only) get information about the 'post' table

Returns
return true if a 'post' table is present and contain glyph PostScript names
void FontEngine::TFont::initPathParameter ( const TPathParamMap ppm)
inline

set new parameter map

Parameters
ppmthe new parameter map, see description at TPathParamMap
bool FontEngine::TFont::isCIDFont ( )
inline

get information if the font is a cid font, this can be used for PostScript Type1 and cid cff fonts

Returns
true if font is a cid font
static EFType FontEngine::TFont::isFont ( const TPath fname)
static

return true if font engine can identify the given file as font

Parameters
fnamethe font file path to check
Returns
the font type determined by font engine
bool FontEngine::TFont::isWriteable ( ) const

get writable state

Returns
true if the font is writable
EFType FontEngine::TFont::open ( const TPath fname,
unsigned int  findex,
EFType  favorit = eftUnknown 
)

open a font file from file path

Parameters
fnamethe font file path to check
findexthe font index if file is a font collection or cid font
favorityou should get a primary type if you know to open the file quicker
Returns
the font type determined by font engine
EFType FontEngine::TFont::openOTBlocks ( const TBlock headBlock,
const TBlock cmapBlock,
const TBlock glyfBlock,
const TBlock hheaBlock,
const TBlock hmtxBlock,
const TBlock locaBlock,
const TBlock maxpBlock,
const TBlock cff_Block,
const TBlock os_2Block,
const TBlock postBlock,
const TBlock nameBlock 
)

open a TrueType or OpenType font from seperate font data buffern

Parameters
headBlocka 'head' data block is required and must be not empty
cmapBlocka 'cmap' data block is required and must be not empty
glyfBlocka 'glyf' data block is required and must be not empty except if cff_Block is not empty
hheaBlocka 'hhea' data block is required and must be not empty
hmtxBlocka 'hmtx' data block is required and must be not empty
locaBlocka 'loca' data block is required and must be not empty
maxpBlocka 'maxp' data block is required and must be not empty
cff_Blocka 'cff_' data block is optional and can be empty
os_2Blocka 'os_2' data block is optional and can be empty
postBlocka 'post' data block is optional and can be empty
nameBlocka 'name' data block is optional and can be empty
Returns
the font type determined by font engine
EFType FontEngine::TFont::openPDFstream ( std::istream &  fontstream,
EFType  favorit 
)

open a font from pdf stream, this can be only one font, i.e. no font collection

Parameters
fontstreama font stream used by an pdf file in 'FontFile', 'FontFile2' or 'FontFile3'. the stream must be decoded.
favorityou should get a primary type if you know to open the file quicker
Returns
the font type determined by font engine
TFont& FontEngine::TFont::operator= ( const TFont font)

assignment operator

Parameters
fontto copy from
void FontEngine::TFont::setCurrentFontIndex ( unsigned int  curidx)
inline

set the current font index, use this function to select a cid font into an OpenType cid font

Parameters
curidxthe new font index
void FontEngine::TFont::setFontName ( const std::string &  fontname,
const std::string &  fontfamily 
)

set the font name and family name in this font, if the font is a PostScript Type font it wil be converted into a CFF font

Parameters
fontnamethe new font name, can be required if a font was subseted
fontfamilythe new font family name, can be empty to not change the family name
void FontEngine::TFont::setT1MMasterIndex ( unsigned int  mmidx)

(PostScript Type1 only) set the font master index in MultipleMaster font, must be in range of [0 getT1NumberOfMMaster()]

Parameters
mmidxthe master index
void FontEngine::TFont::subset ( TEmbFontParameter efp)

make a subset from this font, if the font is a PostScript Type font it wil be converted into a CFF font

Parameters
efpthe subset parameter, see TEmbFontParameter
void FontEngine::TFont::write ( std::ostream &  fontstream)

write the complete font into a ostream, if the font is a PostScript Type font it wil be converted into a CFF font

Friends And Related Function Documentation

friend struct TFontThreadData
friend

The documentation for this class was generated from the following file:
InsideFont and ADI-FontEngine : Andreas Dippe, © 2013
http://www.insidefont.de