FreeType 1.31.1

This commit is contained in:
2023-08-27 18:03:45 +02:00
commit 5edbb7a80a
454 changed files with 173977 additions and 0 deletions

347
lib/extend/ftxcmap.c Normal file
View File

@@ -0,0 +1,347 @@
/*******************************************************************
*
* ftxcmap.h 1.0
*
* API extension for iterating over Cmaps
*
* Copyright 1996-1999 by Juliusz Chroboczek,
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
******************************************************************/
#include "ftxcmap.h"
#include "tttypes.h"
#include "ttobjs.h"
#include "tttables.h"
static Long charmap_first4 ( PCMap4, UShort* );
static Long charmap_next4 ( PCMap4, UShort, UShort* );
static Long charmap_last4 ( PCMap4, UShort* );
static UShort charmap_find_id4( PCMap4, UShort, TCMap4Segment*, UShort );
/*******************************************************************
*
* Function : TT_CharMap_First
*
* Description : Returns the first valid character code in a
* given character map. Also returns the corresponding
* glyph index.
*
* Input : charMap handle to the target character map
* id address where the glyph index will be
* be returned in case of success
*
* Output : First valid character code. -1 in case of failure.
*
* Notes :
*
******************************************************************/
EXPORT_FUNC
TT_Long TT_CharMap_First( TT_CharMap charMap,
TT_UShort* id )
{
PCMapTable cmap;
UShort i, c;
if ( !( cmap = HANDLE_CharMap( charMap ) ) )
return -1;
switch ( cmap->format )
{
case 0:
if ( id )
*id = cmap->c.cmap0.glyphIdArray[0];
return 0;
case 4:
return charmap_first4( &cmap->c.cmap4, id );
case 6:
if ( cmap->c.cmap6.entryCount < 1 )
return -1;
if ( id )
*id = cmap->c.cmap6.glyphIdArray[0];
return cmap->c.cmap6.firstCode;
default:
/* Now loop from 0 to 65535. We can't use a simple "for' on */
/* 16-bits systems, hence the "strange" loop here.. */
i = 0;
do
{
c = TT_Char_Index( charMap, i );
if ( c > 0 )
{
if ( id )
*id = c;
return i;
}
i++;
} while ( i != 0 ); /* because i is UShort! */
return -1;
}
}
static Long charmap_first4( PCMap4 cmap4,
UShort* id )
{
UShort firstCode;
if ( cmap4->segCountX2 / 2 < 1 )
return -1;
firstCode = cmap4->segments[0].startCount;
if ( id )
*id = charmap_find_id4( cmap4, firstCode, &(cmap4->segments[0]), 0 );
return firstCode;
}
/*******************************************************************
*
* Function : TT_CharMap_Next
*
* Description : Returns the next valid character code in a given
* charMap.
*
* Input : charMap handle to the target char. map
* index starting character code
* id address where the glyph index of the next
* character will be returned
*
* Output : Next valid character code after 'index'. -1 in case
* of failure.
*
* Notes :
*
******************************************************************/
EXPORT_FUNC
TT_Long TT_CharMap_Next( TT_CharMap charMap,
TT_UShort index,
TT_UShort* id )
{
PCMapTable cmap;
UShort i, c;
cmap = HANDLE_CharMap( charMap );
if ( !cmap )
return -1;
switch ( cmap->format )
{
case 0:
if ( index < 255 )
{
if ( id )
*id = cmap->c.cmap0.glyphIdArray[index + 1];
return index + 1;
}
else
return -1;
case 4:
return charmap_next4( &cmap->c.cmap4, index, id );
case 6:
{
UShort firstCode = cmap->c.cmap6.firstCode;
if ( index + 1 < firstCode + cmap->c.cmap6.entryCount )
{
if ( id )
*id = cmap->c.cmap6.glyphIdArray[index + 1 - firstCode];
return index + 1;
}
else
return -1;
}
default:
/* Now loop from 0 to 65535. We can't use a simple "for" on */
/* 16-bits systems, hence the "strange" loop here.. */
i = 0;
do
{
c = TT_Char_Index( charMap, i );
if ( c > 0 )
{
if ( id )
*id = c;
return i;
}
i++;
} while ( i != 0 ); /* because i is UShort! */
return -1;
}
}
static Long charmap_next4( PCMap4 cmap4,
UShort charCode,
UShort* id)
{
UShort segCount, nextCode;
UShort i;
TCMap4Segment seg4;
if ( charCode == 0xFFFF )
return -1; /* get it out of the way now */
segCount = cmap4->segCountX2 / 2;
for ( i = 0; i < segCount; i++ )
if ( charCode < cmap4->segments[i].endCount )
break;
/* Safety check - even though the last endCount should be 0xFFFF */
if ( i >= segCount )
return -1;
seg4 = cmap4->segments[i];
if ( charCode < seg4.startCount )
nextCode = seg4.startCount;
else
nextCode = charCode + 1;
if ( id )
*id = charmap_find_id4( cmap4, nextCode, &seg4, i );
return nextCode;
}
static UShort
charmap_find_id4( PCMap4 cmap4,
UShort charCode,
TCMap4Segment* seg4,
UShort i )
{
UShort index1;
if ( seg4->idRangeOffset == 0 )
return (charCode + seg4->idDelta) & 0xFFFF;
else
{
index1 = seg4->idRangeOffset / 2 + charCode-seg4->startCount -
( cmap4->segCountX2 / 2 - i );
if ( index1 >= cmap4->numGlyphId || cmap4->glyphIdArray[index1] == 0 )
return 0;
else
return (cmap4->glyphIdArray[index1] + seg4->idDelta) & 0xFFFF;
}
}
/*******************************************************************
*
* Function : TT_CharMap_Last
*
* Description : Returns the last valid character code in a
* given character map. Also returns the corresponding
* glyph index.
*
* Input : charMap handle to the target character map
* id address where the glyph index will be
* be returned in case of success
*
* Output : Last valid character code. -1 in case of failure.
*
* Notes :
*
******************************************************************/
EXPORT_FUNC
TT_Long TT_CharMap_Last( TT_CharMap charMap,
TT_UShort* id )
{
PCMapTable cmap;
UShort i, c;
if ( !( cmap = HANDLE_CharMap( charMap ) ) )
return -1;
switch ( cmap->format )
{
case 0:
if ( id )
*id = cmap->c.cmap0.glyphIdArray[255];
return 255;
case 4:
return charmap_last4( &cmap->c.cmap4, id );
case 6:
if ( cmap->c.cmap6.entryCount < 1 )
return -1;
if ( id )
*id = cmap->c.cmap6.glyphIdArray[cmap->c.cmap6.entryCount - 1];
return cmap->c.cmap6.firstCode + cmap->c.cmap6.entryCount - 1;
default:
i = 65535;
do
{
c = TT_Char_Index( charMap, i );
if ( c > 0 )
{
if ( id )
*id = c;
return i;
}
i--;
} while ( i != 0 );
return -1;
}
}
static Long charmap_last4( PCMap4 cmap4,
UShort* id )
{
UShort lastCode;
if ( cmap4->segCountX2 / 2 < 1 )
return -1;
lastCode = cmap4->segments[cmap4->segCountX2 / 2 - 1].endCount;
if ( id )
*id = charmap_find_id4( cmap4,
lastCode,
&(cmap4->segments[cmap4->segCountX2 / 2 - 1]),
0 );
return lastCode;
}
/* END */

60
lib/extend/ftxcmap.h Normal file
View File

@@ -0,0 +1,60 @@
/*******************************************************************
*
* ftxcmap.h 1.0
*
* API extension for iterating over Cmaps
*
* Copyright 1996-1999 by Juliusz Chroboczek,
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
******************************************************************/
#ifndef FTXCMAP_H
#define FTXCMAP_H
#include "freetype.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Find the first entry of a Cmap. Its glyph index is returned */
/* in the "id" field, while the function returns the first valid */
/* character code in the Cmap. It returns -1 in case of failure. */
EXPORT_DEF
TT_Long TT_CharMap_First( TT_CharMap charMap,
TT_UShort* id );
/* Find the next entry of Cmap. Same return conventions. */
EXPORT_DEF
TT_Long TT_CharMap_Next( TT_CharMap charMap,
TT_UShort startId,
TT_UShort* id );
/* Find the last entry of a Cmap. Its glyph index is returned */
/* in the "id" field, while the function returns the last valid */
/* character code in the Cmap. It returns -1 in case of failure. */
EXPORT_DEF
TT_Long TT_CharMap_Last( TT_CharMap charMap,
TT_UShort* id );
#ifdef __cplusplus
}
#endif
#endif /* FTXCMAP_H */
/* END */

241
lib/extend/ftxerr18.c Normal file
View File

@@ -0,0 +1,241 @@
/****************************************************************************/
/* */
/* Erwin Dieterich, 15. 10. 1997 */
/* - 15. 08. 1999 */
/* */
/* TT_ErrToString: translate error codes to character strings */
/* */
/* This extension provides internationalized error strings from the */
/* various error messages. It uses the "gettext" package if available */
/* or returns English/American message strings if not. */
/* */
/* If you do not want to use it, or if you encounter some problems */
/* compiling this file, try to disable nls support when invoking */
/* ./configure (on Unix). */
/* */
/* */
/****************************************************************************/
#include "ttconfig.h"
#include "ftxerr18.h"
#include "ftxkern.h"
#include "ftxpost.h"
#include "ftxopen.h"
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef HAVE_LIBINTL_H
#include <libintl.h>
#undef _
#define _( String ) dgettext( "freetype", String )
#else
#define _( String ) ( String )
#endif
EXPORT_FUNC
TT_String* TT_ErrToString18( TT_Error error )
{
switch ( error )
{
/* ----- high-level API error codes ----- */
case TT_Err_Ok:
return _( "Successful function call, no error." );
case TT_Err_Invalid_Face_Handle:
return _( "Invalid face handle." );
case TT_Err_Invalid_Instance_Handle:
return _( "Invalid instance handle." );
case TT_Err_Invalid_Glyph_Handle:
return _( "Invalid glyph handle." );
case TT_Err_Invalid_CharMap_Handle:
return _( "Invalid charmap handle." );
case TT_Err_Invalid_Result_Address:
return _( "Invalid result address." );
case TT_Err_Invalid_Glyph_Index:
return _( "Invalid glyph index." );
case TT_Err_Invalid_Argument:
return _( "Invalid argument." );
case TT_Err_Could_Not_Open_File:
return _( "Could not open file." );
case TT_Err_File_Is_Not_Collection:
return _( "File is not a TrueType collection." );
case TT_Err_Table_Missing:
return _( "Mandatory table missing." );
case TT_Err_Invalid_Horiz_Metrics:
return _( "Invalid horizontal metrics (hmtx table broken)." );
case TT_Err_Invalid_CharMap_Format:
return _( "Invalid charmap format." );
case TT_Err_Invalid_PPem:
return _( "Invalid ppem value." );
case TT_Err_Invalid_Vert_Metrics:
return _( "Invalid vertical metrics (vmtx table broken)." );
case TT_Err_Invalid_File_Format:
return _( "Invalid file format." );
case TT_Err_Invalid_Engine:
return _( "Invalid engine." );
case TT_Err_Too_Many_Extensions:
return _( "Too many extensions." );
case TT_Err_Extensions_Unsupported:
return _( "Extensions unsupported." );
case TT_Err_Invalid_Extension_Id:
return _( "Invalid extension id." );
case TT_Err_No_Vertical_Data:
return _( "No vertical data in font." );
case TT_Err_Max_Profile_Missing:
return _( "Maximum Profile (maxp) table missing." );
case TT_Err_Header_Table_Missing:
return _( "Font Header (head) table missing." );
case TT_Err_Horiz_Header_Missing:
return _( "Horizontal Header (hhea) table missing." );
case TT_Err_Locations_Missing:
return _( "Index to Location (loca) table missing." );
case TT_Err_Name_Table_Missing:
return _( "Naming (name) table missing." );
case TT_Err_CMap_Table_Missing:
return _( "Character to Glyph Index Mapping (cmap) tables missing." );
case TT_Err_Hmtx_Table_Missing:
return _( "Horizontal Metrics (hmtx) table missing." );
case TT_Err_OS2_Table_Missing:
return _( "OS/2 table missing." );
case TT_Err_Post_Table_Missing:
return _( "PostScript (post) table missing." );
case TT_Err_Glyf_Table_Missing:
return _( "Glyph (glyf) table missing." );
/* ----- memory component error codes ----- */
case TT_Err_Out_Of_Memory:
return _( "Out of memory." );
/* ----- file component error codes ----- */
case TT_Err_Invalid_File_Offset:
return _( "Invalid file offset." );
case TT_Err_Invalid_File_Read:
return _( "Invalid file read." );
case TT_Err_Invalid_Frame_Access:
return _( "Invalid frame access." );
/* ----- glyph loader error codes ----- */
case TT_Err_Too_Many_Points:
return _( "Too many points." );
case TT_Err_Too_Many_Contours:
return _( "Too many contours." );
case TT_Err_Invalid_Composite:
return _( "Invalid composite glyph." );
case TT_Err_Too_Many_Ins:
return _( "Too many instructions." );
/* ----- byte-code interpreter error codes ----- */
case TT_Err_Invalid_Opcode:
return _( "Invalid opcode." );
case TT_Err_Too_Few_Arguments:
return _( "Too few arguments." );
case TT_Err_Stack_Overflow:
return _( "Stack overflow." );
case TT_Err_Code_Overflow:
return _( "Code overflow." );
case TT_Err_Bad_Argument:
return _( "Bad argument." );
case TT_Err_Divide_By_Zero:
return _( "Divide by zero." );
case TT_Err_Storage_Overflow:
return _( "Storage overflow." );
case TT_Err_Cvt_Overflow:
return _( "Control Value (cvt) table overflow." );
case TT_Err_Invalid_Reference:
return _( "Invalid reference." );
case TT_Err_Invalid_Distance:
return _( "Invalid distance." );
case TT_Err_Interpolate_Twilight:
return _( "Interpolate twilight points." );
case TT_Err_Debug_OpCode:
return _( "`DEBUG' opcode found." );
case TT_Err_ENDF_In_Exec_Stream:
return _( "`ENDF' in byte-code stream." );
case TT_Err_Out_Of_CodeRanges:
return _( "Out of code ranges." );
case TT_Err_Nested_DEFS:
return _( "Nested function definitions." );
case TT_Err_Invalid_CodeRange:
return _( "Invalid code range." );
case TT_Err_Invalid_Displacement:
return _( "Invalid displacement." );
case TT_Err_Execution_Too_Long:
return _( "Endless loop encountered while executing instructions." );
/* ----- internal failure error codes ----- */
case TT_Err_Nested_Frame_Access:
return _( "Nested frame access." );
case TT_Err_Invalid_Cache_List:
return _( "Invalid cache list." );
case TT_Err_Could_Not_Find_Context:
return _( "Could not find context." );
case TT_Err_Unlisted_Object:
return _( "Unlisted object." );
/* ----- scan-line converter error codes ----- */
case TT_Err_Raster_Pool_Overflow:
return _( "Raster pool overflow." );
case TT_Err_Raster_Negative_Height:
return _( "Raster: negative height encountered." );
case TT_Err_Raster_Invalid_Value:
return _( "Raster: invalid value." );
case TT_Err_Raster_Not_Initialized:
return _( "Raster not initialized." );
/* ----- engine extensions error codes ----- */
case TT_Err_Invalid_Kerning_Table_Format:
return _( "Invalid kerning (kern) table format." );
case TT_Err_Invalid_Kerning_Table:
return _( "Invalid kerning (kern) table." );
case TT_Err_Invalid_Post_Table_Format:
return _( "Invalid PostScript (post) table format." );
case TT_Err_Invalid_Post_Table:
return _( "Invalid PostScript (post) table." );
/* ----- TrueType Open extension error codes ----- */
case TTO_Err_Invalid_SubTable_Format:
return _( "Invalid TrueType Open subtable format." );
case TTO_Err_Invalid_SubTable:
return _( "Invalid TrueType Open subtable." );
case TTO_Err_Not_Covered:
return _( "Glyph(s) not covered by lookup." );
case TTO_Err_Too_Many_Nested_Contexts:
return _( "Too many nested context substitutions." );
case TTO_Err_Invalid_GSUB_SubTable_Format:
return _( "Invalid glyph substitution (GSUB) table format." );
case TTO_Err_Invalid_GSUB_SubTable:
return _( "Invalid glyph substitution (GSUB) table." );
case TTO_Err_Invalid_GPOS_SubTable_Format:
return _( "Invalid glyph positioning (GPOS) table format." );
case TTO_Err_Invalid_GPOS_SubTable:
return _( "Invalid glyph positioning (GPOS) table." );
default:
;
}
return _( "Invalid Error Number." );
}
/* END */

38
lib/extend/ftxerr18.h Normal file
View File

@@ -0,0 +1,38 @@
/****************************************************************************/
/* */
/* Erwin Dieterich, 15. 10. 1997 */
/* - 15. 08. 1999 */
/* */
/* TT_ErrToString: translate error codes to character strings */
/* */
/* This extension provides internationalized error strings from the */
/* various error messages. It uses the "gettext" package where available */
/* or returns english/american message strings if not. */
/* */
/* If you do not want to use it, or if you encounter some problems */
/* compiling this file, try to disable nls support by configuring */
/* FreeType with ./configure --disable-nls */
/* */
/* */
/****************************************************************************/
#ifndef FTXERR18_H
#define FTXERR18_H
#include "freetype.h"
#ifdef __cplusplus
extern "C" {
#endif
EXPORT_DEF
TT_String* TT_ErrToString18( TT_Error i );
#ifdef __cplusplus
}
#endif
#endif /* FTXERR18_H */
/* END */

69
lib/extend/ftxgasp.c Normal file
View File

@@ -0,0 +1,69 @@
/*******************************************************************
*
* ftxgasp.c 1.0
*
* Gasp table support API extension body
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* The gasp table is currently loaded by the core engine, but the
* standard API doesn't give access to it. This file is used to
* demonstrate the use of a simple API extension.
*
******************************************************************/
#include "ftxgasp.h"
#include "tttypes.h"
#include "ttobjs.h"
#include "tttables.h"
EXPORT_FUNC
TT_Error TT_Get_Face_Gasp_Flags( TT_Face face,
TT_UShort point_size,
TT_Bool* grid_fit,
TT_Bool* smooth_font )
{
PFace faze = HANDLE_Face( face );
UShort i, flag;
if ( !faze )
return TT_Err_Invalid_Face_Handle;
if ( faze->gasp.numRanges == 0 || !faze->gasp.gaspRanges )
return TT_Err_Table_Missing;
for ( i = 0; i < faze->gasp.numRanges; i++ )
{
if ( point_size <= faze->gasp.gaspRanges[i].maxPPEM )
{
flag = faze->gasp.gaspRanges[i].gaspFlag;
*grid_fit = ( (flag & GASP_GRIDFIT) != 0 );
*smooth_font = ( (flag & GASP_DOGRAY ) != 0 );
return TT_Err_Ok;
}
}
/* for very large fonts we enable font smoothing and discard */
/* grid fitting */
*grid_fit = 0;
*smooth_font = 1;
return TT_Err_Ok;
}
/* END */

53
lib/extend/ftxgasp.h Normal file
View File

@@ -0,0 +1,53 @@
/*******************************************************************
*
* ftxgasp.h 1.0
*
* Gasp table support API extension
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* The gasp table is currently loaded by the core engine, but the
* standard API doesn't give access to it. This file is used to
* demonstrate the use of a simple API extension.
*
******************************************************************/
#ifndef FTXGASP_H
#define FTXGASP_H
#include "freetype.h"
#ifdef __cplusplus
extern "C" {
#endif
/* This function returns for a given 'point_size' the values of the */
/* gasp flags 'grid_fit' and 'smooth_font'. The returned values */
/* are booleans (where 0 = NO, and 1 = YES). */
/* Note that this function will return TT_Err_Table_Missing if */
/* the font file doesn't contain any gasp table. */
EXPORT_DEF
TT_Error TT_Get_Face_Gasp_Flags( TT_Face face,
TT_UShort point_size,
TT_Bool* grid_fit,
TT_Bool* smooth_font );
#ifdef __cplusplus
}
#endif
#endif /* FTXGASP_H */
/* END */

1099
lib/extend/ftxgdef.c Normal file

File diff suppressed because it is too large Load Diff

216
lib/extend/ftxgdef.h Normal file
View File

@@ -0,0 +1,216 @@
/*******************************************************************
*
* ftxgdef.h
*
* TrueType Open GDEF table support
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
******************************************************************/
#ifndef FTXOPEN_H
#error "Don't include this file! Use ftxopen.h instead."
#endif
#ifndef FTXGDEF_H
#define FTXGDEF_H
#ifdef __cplusplus
extern "C" {
#endif
#define TTO_Err_Invalid_GDEF_SubTable_Format 0x1030
#define TTO_Err_Invalid_GDEF_SubTable 0x1031
/* GDEF glyph classes */
#define UNCLASSIFIED_GLYPH 0
#define SIMPLE_GLYPH 1
#define LIGATURE_GLYPH 2
#define MARK_GLYPH 3
#define COMPONENT_GLYPH 4
/* GDEF glyph properties, corresponding to class values 1-4. Note that
TTO_COMPONENT has no corresponding flag in the LookupFlag field. */
#define TTO_BASE_GLYPH 0x0002
#define TTO_LIGATURE 0x0004
#define TTO_MARK 0x0008
#define TTO_COMPONENT 0x0010
/* Attachment related structures */
struct TTO_AttachPoint_
{
TT_UShort PointCount; /* size of the PointIndex array */
TT_UShort* PointIndex; /* array of contour points */
};
typedef struct TTO_AttachPoint_ TTO_AttachPoint;
struct TTO_AttachList_
{
TT_Bool loaded;
TTO_Coverage Coverage; /* Coverage table */
TT_UShort GlyphCount; /* number of glyphs with
attachments */
TTO_AttachPoint* AttachPoint; /* array of AttachPoint tables */
};
typedef struct TTO_AttachList_ TTO_AttachList;
/* Ligature Caret related structures */
struct TTO_CaretValueFormat1_
{
TT_Short Coordinate; /* x or y value (in design units) */
};
typedef struct TTO_CaretValueFormat1_ TTO_CaretValueFormat1;
struct TTO_CaretValueFormat2_
{
TT_UShort CaretValuePoint; /* contour point index on glyph */
};
typedef struct TTO_CaretValueFormat2_ TTO_CaretValueFormat2;
struct TTO_CaretValueFormat3_
{
TT_Short Coordinate; /* x or y value (in design units) */
TTO_Device Device; /* Device table for x or y value */
};
typedef struct TTO_CaretValueFormat3_ TTO_CaretValueFormat3;
struct TTO_CaretValueFormat4_
{
TT_UShort IdCaretValue; /* metric ID */
};
typedef struct TTO_CaretValueFormat4_ TTO_CaretValueFormat4;
struct TTO_CaretValue_
{
TT_UShort CaretValueFormat; /* 1, 2, 3, or 4 */
union
{
TTO_CaretValueFormat1 cvf1;
TTO_CaretValueFormat2 cvf2;
TTO_CaretValueFormat3 cvf3;
TTO_CaretValueFormat4 cvf4;
} cvf;
};
typedef struct TTO_CaretValue_ TTO_CaretValue;
struct TTO_LigGlyph_
{
TT_Bool loaded;
TT_UShort CaretCount; /* number of caret values */
TTO_CaretValue* CaretValue; /* array of caret values */
};
typedef struct TTO_LigGlyph_ TTO_LigGlyph;
struct TTO_LigCaretList_
{
TT_Bool loaded;
TTO_Coverage Coverage; /* Coverage table */
TT_UShort LigGlyphCount; /* number of ligature glyphs */
TTO_LigGlyph* LigGlyph; /* array of LigGlyph tables */
};
typedef struct TTO_LigCaretList_ TTO_LigCaretList;
/* The `NewGlyphClasses' field is not defined in the TTO specification.
We use it for fonts with a constructed `GlyphClassDef' structure
(i.e., which don't have a GDEF table) to collect glyph classes
assigned during the lookup process. The number of arrays in this
pointer array is GlyphClassDef->cd.cd2.ClassRangeCount+1; the nth
array then contains the glyph class values of the glyphs not covered
by the ClassRangeRecords structures with index n-1 and n. We store
glyph class values for four glyphs in a single array element.
`LastGlyph' is identical to the number of glyphs minus one in the
font; we need it only if `NewGlyphClasses' is not NULL (to have an
upper bound for the last array).
Note that we first store the file offset to the `MarkAttachClassDef'
field (which has been introduced in OpenType 1.2) -- since the
`Version' field value hasn't been increased to indicate that we have
one more field for some obscure reason, we must parse the GSUB table
to find out whether class values refer to this table. Only then we
can finally load the MarkAttachClassDef structure if necessary. */
struct TTO_GDEFHeader_
{
TT_Bool loaded;
TT_ULong offset;
TT_Fixed Version;
TTO_ClassDefinition GlyphClassDef;
TTO_AttachList AttachList;
TTO_LigCaretList LigCaretList;
TT_ULong MarkAttachClassDef_offset;
TTO_ClassDefinition MarkAttachClassDef; /* new in OT 1.2 */
TT_UShort LastGlyph;
TT_UShort** NewGlyphClasses;
};
typedef struct TTO_GDEFHeader_ TTO_GDEFHeader;
/* finally, the GDEF API */
EXPORT_DEF
TT_Error TT_Init_GDEF_Extension( TT_Engine engine );
EXPORT_DEF
TT_Error TT_Load_GDEF_Table( TT_Face face,
TTO_GDEFHeader* gdef );
EXPORT_DEF
TT_Error TT_GDEF_Get_Glyph_Property( TTO_GDEFHeader* gdef,
TT_UShort glyphID,
TT_UShort* property );
EXPORT_DEF
TT_Error TT_GDEF_Build_ClassDefinition( TTO_GDEFHeader* gdef,
TT_UShort num_glyphs,
TT_UShort glyph_count,
TT_UShort* glyph_array,
TT_UShort* class_array );
#ifdef __cplusplus
}
#endif
#endif /* FTXGDEF_H */
/* END */

4045
lib/extend/ftxgpos.c Normal file

File diff suppressed because it is too large Load Diff

767
lib/extend/ftxgpos.h Normal file
View File

@@ -0,0 +1,767 @@
/*******************************************************************
*
* ftxgpos.h
*
* TrueType Open GPOS table support
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
******************************************************************/
#ifndef FTXOPEN_H
#error "Don't include this file! Use ftxopen.h instead."
#endif
#ifndef FTXGPOS_H
#define FTXGPOS_H
#ifdef __cplusplus
extern "C" {
#endif
#define TTO_Err_Invalid_GPOS_SubTable_Format 0x1020
#define TTO_Err_Invalid_GPOS_SubTable 0x1021
/* Lookup types for glyph positioning */
#define GPOS_LOOKUP_SINGLE 1
#define GPOS_LOOKUP_PAIR 2
#define GPOS_LOOKUP_CURSIVE 3
#define GPOS_LOOKUP_MARKBASE 4
#define GPOS_LOOKUP_MARKLIG 5
#define GPOS_LOOKUP_MARKMARK 6
#define GPOS_LOOKUP_CONTEXT 7
#define GPOS_LOOKUP_CHAIN 8
struct TTO_GPOSHeader_
{
TT_Bool loaded;
TT_ULong offset;
TT_Fixed Version;
TTO_ScriptList ScriptList;
TTO_FeatureList FeatureList;
TTO_LookupList LookupList;
TTO_GDEFHeader* gdef;
};
typedef struct TTO_GPOSHeader_ TTO_GPOSHeader;
/* shared tables */
struct TTO_ValueRecord_
{
TT_Short XPlacement; /* horizontal adjustment for
placement */
TT_Short YPlacement; /* vertical adjustment for
placement */
TT_Short XAdvance; /* horizontal adjustment for
advance */
TT_Short YAdvance; /* vertical adjustment for
advance */
TTO_Device XPlacementDevice; /* device table for horizontal
placement */
TTO_Device YPlacementDevice; /* device table for vertical
placement */
TTO_Device XAdvanceDevice; /* device table for horizontal
advance */
TTO_Device YAdvanceDevice; /* device table for vertical
advance */
TT_UShort XIdPlacement; /* horizontal placement metric ID */
TT_UShort YIdPlacement; /* vertical placement metric ID */
TT_UShort XIdAdvance; /* horizontal advance metric ID */
TT_UShort YIdAdvance; /* vertical advance metric ID */
};
typedef struct TTO_ValueRecord_ TTO_ValueRecord;
/* Mask values to scan the value format of the ValueRecord structure.
We always expand compressed ValueRecords of the font. */
#define HAVE_X_PLACEMENT 0x0001
#define HAVE_Y_PLACEMENT 0x0002
#define HAVE_X_ADVANCE 0x0004
#define HAVE_Y_ADVANCE 0x0008
#define HAVE_X_PLACEMENT_DEVICE 0x0010
#define HAVE_Y_PLACEMENT_DEVICE 0x0020
#define HAVE_X_ADVANCE_DEVICE 0x0040
#define HAVE_Y_ADVANCE_DEVICE 0x0080
#define HAVE_X_ID_PLACEMENT 0x0100
#define HAVE_Y_ID_PLACEMENT 0x0200
#define HAVE_X_ID_ADVANCE 0x0400
#define HAVE_Y_ID_ADVANCE 0x0800
struct TTO_AnchorFormat1_
{
TT_Short XCoordinate; /* horizontal value */
TT_Short YCoordinate; /* vertical value */
};
typedef struct TTO_AnchorFormat1_ TTO_AnchorFormat1;
struct TTO_AnchorFormat2_
{
TT_Short XCoordinate; /* horizontal value */
TT_Short YCoordinate; /* vertical value */
TT_UShort AnchorPoint; /* index to glyph contour point */
};
typedef struct TTO_AnchorFormat2_ TTO_AnchorFormat2;
struct TTO_AnchorFormat3_
{
TT_Short XCoordinate; /* horizontal value */
TT_Short YCoordinate; /* vertical value */
TTO_Device XDeviceTable; /* device table for X coordinate */
TTO_Device YDeviceTable; /* device table for Y coordinate */
};
typedef struct TTO_AnchorFormat3_ TTO_AnchorFormat3;
struct TTO_AnchorFormat4_
{
TT_UShort XIdAnchor; /* horizontal metric ID */
TT_UShort YIdAnchor; /* vertical metric ID */
};
typedef struct TTO_AnchorFormat4_ TTO_AnchorFormat4;
struct TTO_Anchor_
{
TT_UShort PosFormat; /* 1, 2, 3, or 4 -- 0 indicates
that there is no Anchor table */
union
{
TTO_AnchorFormat1 af1;
TTO_AnchorFormat2 af2;
TTO_AnchorFormat3 af3;
TTO_AnchorFormat4 af4;
} af;
};
typedef struct TTO_Anchor_ TTO_Anchor;
struct TTO_MarkRecord_
{
TT_UShort Class; /* mark class */
TTO_Anchor MarkAnchor; /* anchor table */
};
typedef struct TTO_MarkRecord_ TTO_MarkRecord;
struct TTO_MarkArray_
{
TT_UShort MarkCount; /* number of MarkRecord tables */
TTO_MarkRecord* MarkRecord; /* array of MarkRecord tables */
};
typedef struct TTO_MarkArray_ TTO_MarkArray;
/* LookupType 1 */
struct TTO_SinglePosFormat1_
{
TTO_ValueRecord Value; /* ValueRecord for all covered
glyphs */
};
typedef struct TTO_SinglePosFormat1_ TTO_SinglePosFormat1;
struct TTO_SinglePosFormat2_
{
TT_UShort ValueCount; /* number of ValueRecord tables */
TTO_ValueRecord* Value; /* array of ValueRecord tables */
};
typedef struct TTO_SinglePosFormat2_ TTO_SinglePosFormat2;
struct TTO_SinglePos_
{
TT_UShort PosFormat; /* 1 or 2 */
TTO_Coverage Coverage; /* Coverage table */
TT_UShort ValueFormat; /* format of ValueRecord table */
union
{
TTO_SinglePosFormat1 spf1;
TTO_SinglePosFormat2 spf2;
} spf;
};
typedef struct TTO_SinglePos_ TTO_SinglePos;
/* LookupType 2 */
struct TTO_PairValueRecord_
{
TT_UShort SecondGlyph; /* glyph ID for second glyph */
TTO_ValueRecord Value1; /* pos. data for first glyph */
TTO_ValueRecord Value2; /* pos. data for second glyph */
};
typedef struct TTO_PairValueRecord_ TTO_PairValueRecord;
struct TTO_PairSet_
{
TT_UShort PairValueCount;
/* number of PairValueRecord tables */
TTO_PairValueRecord* PairValueRecord;
/* array of PairValueRecord tables */
};
typedef struct TTO_PairSet_ TTO_PairSet;
struct TTO_PairPosFormat1_
{
TT_UShort PairSetCount; /* number of PairSet tables */
TTO_PairSet* PairSet; /* array of PairSet tables */
};
typedef struct TTO_PairPosFormat1_ TTO_PairPosFormat1;
struct TTO_Class2Record_
{
TTO_ValueRecord Value1; /* pos. data for first glyph */
TTO_ValueRecord Value2; /* pos. data for second glyph */
};
typedef struct TTO_Class2Record_ TTO_Class2Record;
struct TTO_Class1Record_
{
TTO_Class2Record* Class2Record; /* array of Class2Record tables */
};
typedef struct TTO_Class1Record_ TTO_Class1Record;
struct TTO_PairPosFormat2_
{
TTO_ClassDefinition ClassDef1; /* class def. for first glyph */
TTO_ClassDefinition ClassDef2; /* class def. for second glyph */
TT_UShort Class1Count; /* number of classes in ClassDef1
table */
TT_UShort Class2Count; /* number of classes in ClassDef2
table */
TTO_Class1Record* Class1Record; /* array of Class1Record tables */
};
typedef struct TTO_PairPosFormat2_ TTO_PairPosFormat2;
struct TTO_PairPos_
{
TT_UShort PosFormat; /* 1 or 2 */
TTO_Coverage Coverage; /* Coverage table */
TT_UShort ValueFormat1; /* format of ValueRecord table
for first glyph */
TT_UShort ValueFormat2; /* format of ValueRecord table
for second glyph */
union
{
TTO_PairPosFormat1 ppf1;
TTO_PairPosFormat2 ppf2;
} ppf;
};
typedef struct TTO_PairPos_ TTO_PairPos;
/* LookupType 3 */
struct TTO_EntryExitRecord_
{
TTO_Anchor EntryAnchor; /* entry Anchor table */
TTO_Anchor ExitAnchor; /* exit Anchor table */
};
typedef struct TTO_EntryExitRecord_ TTO_EntryExitRecord;
struct TTO_CursivePos_
{
TT_UShort PosFormat; /* always 1 */
TTO_Coverage Coverage; /* Coverage table */
TT_UShort EntryExitCount;
/* number of EntryExitRecord tables */
TTO_EntryExitRecord* EntryExitRecord;
/* array of EntryExitRecord tables */
};
typedef struct TTO_CursivePos_ TTO_CursivePos;
/* LookupType 4 */
struct TTO_BaseRecord_
{
TTO_Anchor* BaseAnchor; /* array of base glyph anchor
tables */
};
typedef struct TTO_BaseRecord_ TTO_BaseRecord;
struct TTO_BaseArray_
{
TT_UShort BaseCount; /* number of BaseRecord tables */
TTO_BaseRecord* BaseRecord; /* array of BaseRecord tables */
};
typedef struct TTO_BaseArray_ TTO_BaseArray;
struct TTO_MarkBasePos_
{
TT_UShort PosFormat; /* always 1 */
TTO_Coverage MarkCoverage; /* mark glyph coverage table */
TTO_Coverage BaseCoverage; /* base glyph coverage table */
TT_UShort ClassCount; /* number of mark classes */
TTO_MarkArray MarkArray; /* mark array table */
TTO_BaseArray BaseArray; /* base array table */
};
typedef struct TTO_MarkBasePos_ TTO_MarkBasePos;
/* LookupType 5 */
struct TTO_ComponentRecord_
{
TTO_Anchor* LigatureAnchor; /* array of ligature glyph anchor
tables */
};
typedef struct TTO_ComponentRecord_ TTO_ComponentRecord;
struct TTO_LigatureAttach_
{
TT_UShort ComponentCount;
/* number of ComponentRecord tables */
TTO_ComponentRecord* ComponentRecord;
/* array of ComponentRecord tables */
};
typedef struct TTO_LigatureAttach_ TTO_LigatureAttach;
struct TTO_LigatureArray_
{
TT_UShort LigatureCount; /* number of LigatureAttach tables */
TTO_LigatureAttach* LigatureAttach;
/* array of LigatureAttach tables */
};
typedef struct TTO_LigatureArray_ TTO_LigatureArray;
struct TTO_MarkLigPos_
{
TT_UShort PosFormat; /* always 1 */
TTO_Coverage MarkCoverage; /* mark glyph coverage table */
TTO_Coverage LigatureCoverage;
/* ligature glyph coverage table */
TT_UShort ClassCount; /* number of mark classes */
TTO_MarkArray MarkArray; /* mark array table */
TTO_LigatureArray LigatureArray; /* ligature array table */
};
typedef struct TTO_MarkLigPos_ TTO_MarkLigPos;
/* LookupType 6 */
struct TTO_Mark2Record_
{
TTO_Anchor* Mark2Anchor; /* array of mark glyph anchor
tables */
};
typedef struct TTO_Mark2Record_ TTO_Mark2Record;
struct TTO_Mark2Array_
{
TT_UShort Mark2Count; /* number of Mark2Record tables */
TTO_Mark2Record* Mark2Record; /* array of Mark2Record tables */
};
typedef struct TTO_Mark2Array_ TTO_Mark2Array;
struct TTO_MarkMarkPos_
{
TT_UShort PosFormat; /* always 1 */
TTO_Coverage Mark1Coverage; /* first mark glyph coverage table */
TTO_Coverage Mark2Coverage; /* second mark glyph coverave table */
TT_UShort ClassCount; /* number of combining mark classes */
TTO_MarkArray Mark1Array; /* MarkArray table for first mark */
TTO_Mark2Array Mark2Array; /* MarkArray table for second mark */
};
typedef struct TTO_MarkMarkPos_ TTO_MarkMarkPos;
/* needed by both lookup type 7 and 8 */
struct TTO_PosLookupRecord_
{
TT_UShort SequenceIndex; /* index into current
glyph sequence */
TT_UShort LookupListIndex; /* Lookup to apply to that pos. */
};
typedef struct TTO_PosLookupRecord_ TTO_PosLookupRecord;
/* LookupType 7 */
struct TTO_PosRule_
{
TT_UShort GlyphCount; /* total number of input glyphs */
TT_UShort PosCount; /* number of PosLookupRecord tables */
TT_UShort* Input; /* array of input glyph IDs */
TTO_PosLookupRecord* PosLookupRecord;
/* array of PosLookupRecord tables */
};
typedef struct TTO_PosRule_ TTO_PosRule;
struct TTO_PosRuleSet_
{
TT_UShort PosRuleCount; /* number of PosRule tables */
TTO_PosRule* PosRule; /* array of PosRule tables */
};
typedef struct TTO_PosRuleSet_ TTO_PosRuleSet;
struct TTO_ContextPosFormat1_
{
TTO_Coverage Coverage; /* Coverage table */
TT_UShort PosRuleSetCount; /* number of PosRuleSet tables */
TTO_PosRuleSet* PosRuleSet; /* array of PosRuleSet tables */
};
typedef struct TTO_ContextPosFormat1_ TTO_ContextPosFormat1;
struct TTO_PosClassRule_
{
TT_UShort GlyphCount; /* total number of context classes */
TT_UShort PosCount; /* number of PosLookupRecord tables */
TT_UShort* Class; /* array of classes */
TTO_PosLookupRecord* PosLookupRecord;
/* array of PosLookupRecord tables */
};
typedef struct TTO_PosClassRule_ TTO_PosClassRule;
struct TTO_PosClassSet_
{
TT_UShort PosClassRuleCount;
/* number of PosClassRule tables */
TTO_PosClassRule* PosClassRule; /* array of PosClassRule tables */
};
typedef struct TTO_PosClassSet_ TTO_PosClassSet;
/* The `MaxContextLength' field is not defined in the TTO specification
but simplifies the implementation of this format. It holds the
maximal context length used in the context rules. */
struct TTO_ContextPosFormat2_
{
TT_UShort MaxContextLength;
/* maximal context length */
TTO_Coverage Coverage; /* Coverage table */
TTO_ClassDefinition ClassDef; /* ClassDef table */
TT_UShort PosClassSetCount;
/* number of PosClassSet tables */
TTO_PosClassSet* PosClassSet; /* array of PosClassSet tables */
};
typedef struct TTO_ContextPosFormat2_ TTO_ContextPosFormat2;
struct TTO_ContextPosFormat3_
{
TT_UShort GlyphCount; /* number of input glyphs */
TT_UShort PosCount; /* number of PosLookupRecord tables */
TTO_Coverage* Coverage; /* array of Coverage tables */
TTO_PosLookupRecord* PosLookupRecord;
/* array of PosLookupRecord tables */
};
typedef struct TTO_ContextPosFormat3_ TTO_ContextPosFormat3;
struct TTO_ContextPos_
{
TT_UShort PosFormat; /* 1, 2, or 3 */
union
{
TTO_ContextPosFormat1 cpf1;
TTO_ContextPosFormat2 cpf2;
TTO_ContextPosFormat3 cpf3;
} cpf;
};
typedef struct TTO_ContextPos_ TTO_ContextPos;
/* LookupType 8 */
struct TTO_ChainPosRule_
{
TT_UShort BacktrackGlyphCount;
/* total number of backtrack glyphs */
TT_UShort* Backtrack; /* array of backtrack glyph IDs */
TT_UShort InputGlyphCount;
/* total number of input glyphs */
TT_UShort* Input; /* array of input glyph IDs */
TT_UShort LookaheadGlyphCount;
/* total number of lookahead glyphs */
TT_UShort* Lookahead; /* array of lookahead glyph IDs */
TT_UShort PosCount; /* number of PosLookupRecords */
TTO_PosLookupRecord* PosLookupRecord;
/* array of PosLookupRecords */
};
typedef struct TTO_ChainPosRule_ TTO_ChainPosRule;
struct TTO_ChainPosRuleSet_
{
TT_UShort ChainPosRuleCount;
/* number of ChainPosRule tables */
TTO_ChainPosRule* ChainPosRule; /* array of ChainPosRule tables */
};
typedef struct TTO_ChainPosRuleSet_ TTO_ChainPosRuleSet;
struct TTO_ChainContextPosFormat1_
{
TTO_Coverage Coverage; /* Coverage table */
TT_UShort ChainPosRuleSetCount;
/* number of ChainPosRuleSet tables */
TTO_ChainPosRuleSet* ChainPosRuleSet;
/* array of ChainPosRuleSet tables */
};
typedef struct TTO_ChainContextPosFormat1_ TTO_ChainContextPosFormat1;
struct TTO_ChainPosClassRule_
{
TT_UShort BacktrackGlyphCount;
/* total number of backtrack
classes */
TT_UShort* Backtrack; /* array of backtrack classes */
TT_UShort InputGlyphCount;
/* total number of context classes */
TT_UShort* Input; /* array of context classes */
TT_UShort LookaheadGlyphCount;
/* total number of lookahead
classes */
TT_UShort* Lookahead; /* array of lookahead classes */
TT_UShort PosCount; /* number of PosLookupRecords */
TTO_PosLookupRecord* PosLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ChainPosClassRule_ TTO_ChainPosClassRule;
struct TTO_ChainPosClassSet_
{
TT_UShort ChainPosClassRuleCount;
/* number of ChainPosClassRule
tables */
TTO_ChainPosClassRule* ChainPosClassRule;
/* array of ChainPosClassRule
tables */
};
typedef struct TTO_ChainPosClassSet_ TTO_ChainPosClassSet;
/* The `MaxXXXLength' fields are not defined in the TTO specification
but simplifies the implementation of this format. It holds the
maximal context length used in the specific context rules. */
struct TTO_ChainContextPosFormat2_
{
TTO_Coverage Coverage; /* Coverage table */
TT_UShort MaxBacktrackLength;
/* maximal backtrack length */
TTO_ClassDefinition BacktrackClassDef;
/* BacktrackClassDef table */
TT_UShort MaxInputLength;
/* maximal input length */
TTO_ClassDefinition InputClassDef;
/* InputClassDef table */
TT_UShort MaxLookaheadLength;
/* maximal lookahead length */
TTO_ClassDefinition LookaheadClassDef;
/* LookaheadClassDef table */
TT_UShort ChainPosClassSetCount;
/* number of ChainPosClassSet
tables */
TTO_ChainPosClassSet* ChainPosClassSet;
/* array of ChainPosClassSet
tables */
};
typedef struct TTO_ChainContextPosFormat2_ TTO_ChainContextPosFormat2;
struct TTO_ChainContextPosFormat3_
{
TT_UShort BacktrackGlyphCount;
/* number of backtrack glyphs */
TTO_Coverage* BacktrackCoverage;
/* array of backtrack Coverage
tables */
TT_UShort InputGlyphCount;
/* number of input glyphs */
TTO_Coverage* InputCoverage;
/* array of input coverage
tables */
TT_UShort LookaheadGlyphCount;
/* number of lookahead glyphs */
TTO_Coverage* LookaheadCoverage;
/* array of lookahead coverage
tables */
TT_UShort PosCount; /* number of PosLookupRecords */
TTO_PosLookupRecord* PosLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ChainContextPosFormat3_ TTO_ChainContextPosFormat3;
struct TTO_ChainContextPos_
{
TT_UShort PosFormat; /* 1, 2, or 3 */
union
{
TTO_ChainContextPosFormat1 ccpf1;
TTO_ChainContextPosFormat2 ccpf2;
TTO_ChainContextPosFormat3 ccpf3;
} ccpf;
};
typedef struct TTO_ChainContextPos_ TTO_ChainContextPos;
union TTO_GPOS_SubTable_
{
TTO_SinglePos single;
TTO_PairPos pair;
TTO_CursivePos cursive;
TTO_MarkBasePos markbase;
TTO_MarkLigPos marklig;
TTO_MarkMarkPos markmark;
TTO_ContextPos context;
TTO_ChainContextPos chain;
};
typedef union TTO_GPOS_SubTable_ TTO_GPOS_SubTable;
/* finally, the GPOS API */
EXPORT_DEF
TT_Error TT_Init_GPOS_Extension( TT_Engine engine );
EXPORT_DEF
TT_Error TT_Load_GPOS_Table( TT_Face face,
TTO_GPOSHeader* gpos,
TTO_GDEFHeader* gdef );
EXPORT_DEF
TT_Error TT_GPOS_Select_Script( TTO_GPOSHeader* gpos,
TT_ULong script_tag,
TT_UShort* script_index );
EXPORT_DEF
TT_Error TT_GPOS_Select_Language( TTO_GPOSHeader* gpos,
TT_ULong language_tag,
TT_UShort script_index,
TT_UShort* language_index,
TT_UShort* req_feature_index );
EXPORT_DEF
TT_Error TT_GPOS_Select_Feature( TTO_GPOSHeader* gpos,
TT_ULong feature_tag,
TT_UShort script_index,
TT_UShort language_index,
TT_UShort* feature_index );
EXPORT_DEF
TT_Error TT_GPOS_Query_Scripts( TTO_GPOSHeader* gpos,
TT_ULong** script_tag_list );
EXPORT_DEF
TT_Error TT_GPOS_Query_Languages( TTO_GPOSHeader* gpos,
TT_UShort script_index,
TT_ULong** language_tag_list );
EXPORT_DEF
TT_Error TT_GPOS_Query_Features( TTO_GPOSHeader* gpos,
TT_UShort script_index,
TT_UShort language_index,
TT_ULong** feature_tag_list );
EXPORT_DEF
TT_Error TT_GPOS_Add_Feature( TTO_GPOSHeader* gpos,
TT_UShort feature_index,
TT_UShort property );
EXPORT_DEF
TT_Error TT_GPOS_Clear_Features( TTO_GPOSHeader* gpos );
#ifdef __cplusplus
}
#endif
#endif /* FTXGPOS_H */
/* END */

4307
lib/extend/ftxgsub.c Normal file

File diff suppressed because it is too large Load Diff

581
lib/extend/ftxgsub.h Normal file
View File

@@ -0,0 +1,581 @@
/*******************************************************************
*
* ftxgsub.h
*
* TrueType Open GSUB table support
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
******************************************************************/
#ifndef FTXOPEN_H
#error "Don't include this file! Use ftxopen.h instead."
#endif
#ifndef FTXGSUB_H
#define FTXGSUB_H
#ifdef __cplusplus
extern "C" {
#endif
#define TTO_Err_Invalid_GSUB_SubTable_Format 0x1010
#define TTO_Err_Invalid_GSUB_SubTable 0x1011
/* Lookup types for glyph substitution */
#define GSUB_LOOKUP_SINGLE 1
#define GSUB_LOOKUP_MULTIPLE 2
#define GSUB_LOOKUP_ALTERNATE 3
#define GSUB_LOOKUP_LIGATURE 4
#define GSUB_LOOKUP_CONTEXT 5
#define GSUB_LOOKUP_CHAIN 6
/* Use this if a feature applies to all glyphs */
#define ALL_GLYPHS 0xFFFF
/* A pointer to a function which selects the alternate glyph. `pos' is
the position of the glyph with index `glyphID', `num_alternates'
gives the number of alternates in the `alternates' array. `data'
points to the user-defined structure specified during a call to
TT_GSUB_Register_Alternate_Function(). The function must return an
index into the `alternates' array. */
typedef TT_UShort (*TTO_AltFunction)(TT_ULong pos,
TT_UShort glyphID,
TT_UShort num_alternates,
TT_UShort* alternates,
void* data );
struct TTO_GSUBHeader_
{
TT_Bool loaded;
TT_ULong offset;
TT_Fixed Version;
TTO_ScriptList ScriptList;
TTO_FeatureList FeatureList;
TTO_LookupList LookupList;
TTO_GDEFHeader* gdef;
/* the next two fields are used for an alternate substitution callback
function to select the proper alternate glyph. */
TTO_AltFunction alt;
void* data;
};
typedef struct TTO_GSUBHeader_ TTO_GSUBHeader;
/* LookupType 1 */
struct TTO_SingleSubstFormat1_
{
TT_Short DeltaGlyphID; /* constant added to get
substitution glyph index */
};
typedef struct TTO_SingleSubstFormat1_ TTO_SingleSubstFormat1;
struct TTO_SingleSubstFormat2_
{
TT_UShort GlyphCount; /* number of glyph IDs in
Substitute array */
TT_UShort* Substitute; /* array of substitute glyph IDs */
};
typedef struct TTO_SingleSubstFormat2_ TTO_SingleSubstFormat2;
struct TTO_SingleSubst_
{
TT_UShort SubstFormat; /* 1 or 2 */
TTO_Coverage Coverage; /* Coverage table */
union
{
TTO_SingleSubstFormat1 ssf1;
TTO_SingleSubstFormat2 ssf2;
} ssf;
};
typedef struct TTO_SingleSubst_ TTO_SingleSubst;
/* LookupType 2 */
struct TTO_Sequence_
{
TT_UShort GlyphCount; /* number of glyph IDs in the
Substitute array */
TT_UShort* Substitute; /* string of glyph IDs to
substitute */
};
typedef struct TTO_Sequence_ TTO_Sequence;
struct TTO_MultipleSubst_
{
TT_UShort SubstFormat; /* always 1 */
TTO_Coverage Coverage; /* Coverage table */
TT_UShort SequenceCount; /* number of Sequence tables */
TTO_Sequence* Sequence; /* array of Sequence tables */
};
typedef struct TTO_MultipleSubst_ TTO_MultipleSubst;
/* LookupType 3 */
struct TTO_AlternateSet_
{
TT_UShort GlyphCount; /* number of glyph IDs in the
Alternate array */
TT_UShort* Alternate; /* array of alternate glyph IDs */
};
typedef struct TTO_AlternateSet_ TTO_AlternateSet;
struct TTO_AlternateSubst_
{
TT_UShort SubstFormat; /* always 1 */
TTO_Coverage Coverage; /* Coverage table */
TT_UShort AlternateSetCount;
/* number of AlternateSet tables */
TTO_AlternateSet* AlternateSet; /* array of AlternateSet tables */
};
typedef struct TTO_AlternateSubst_ TTO_AlternateSubst;
/* LookupType 4 */
struct TTO_Ligature_
{
TT_UShort LigGlyph; /* glyphID of ligature
to substitute */
TT_UShort ComponentCount; /* number of components in ligature */
TT_UShort* Component; /* array of component glyph IDs */
};
typedef struct TTO_Ligature_ TTO_Ligature;
struct TTO_LigatureSet_
{
TT_UShort LigatureCount; /* number of Ligature tables */
TTO_Ligature* Ligature; /* array of Ligature tables */
};
typedef struct TTO_LigatureSet_ TTO_LigatureSet;
struct TTO_LigatureSubst_
{
TT_UShort SubstFormat; /* always 1 */
TTO_Coverage Coverage; /* Coverage table */
TT_UShort LigatureSetCount; /* number of LigatureSet tables */
TTO_LigatureSet* LigatureSet; /* array of LigatureSet tables */
};
typedef struct TTO_LigatureSubst_ TTO_LigatureSubst;
/* needed by both lookup type 5 and 6 */
struct TTO_SubstLookupRecord_
{
TT_UShort SequenceIndex; /* index into current
glyph sequence */
TT_UShort LookupListIndex; /* Lookup to apply to that pos. */
};
typedef struct TTO_SubstLookupRecord_ TTO_SubstLookupRecord;
/* LookupType 5 */
struct TTO_SubRule_
{
TT_UShort GlyphCount; /* total number of input glyphs */
TT_UShort SubstCount; /* number of SubstLookupRecord
tables */
TT_UShort* Input; /* array of input glyph IDs */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of SubstLookupRecord
tables */
};
typedef struct TTO_SubRule_ TTO_SubRule;
struct TTO_SubRuleSet_
{
TT_UShort SubRuleCount; /* number of SubRule tables */
TTO_SubRule* SubRule; /* array of SubRule tables */
};
typedef struct TTO_SubRuleSet_ TTO_SubRuleSet;
struct TTO_ContextSubstFormat1_
{
TTO_Coverage Coverage; /* Coverage table */
TT_UShort SubRuleSetCount; /* number of SubRuleSet tables */
TTO_SubRuleSet* SubRuleSet; /* array of SubRuleSet tables */
};
typedef struct TTO_ContextSubstFormat1_ TTO_ContextSubstFormat1;
struct TTO_SubClassRule_
{
TT_UShort GlyphCount; /* total number of context classes */
TT_UShort SubstCount; /* number of SubstLookupRecord
tables */
TT_UShort* Class; /* array of classes */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of SubstLookupRecord
tables */
};
typedef struct TTO_SubClassRule_ TTO_SubClassRule;
struct TTO_SubClassSet_
{
TT_UShort SubClassRuleCount;
/* number of SubClassRule tables */
TTO_SubClassRule* SubClassRule; /* array of SubClassRule tables */
};
typedef struct TTO_SubClassSet_ TTO_SubClassSet;
/* The `MaxContextLength' field is not defined in the TTO specification
but simplifies the implementation of this format. It holds the
maximal context length used in the context rules. */
struct TTO_ContextSubstFormat2_
{
TT_UShort MaxContextLength;
/* maximal context length */
TTO_Coverage Coverage; /* Coverage table */
TTO_ClassDefinition ClassDef; /* ClassDef table */
TT_UShort SubClassSetCount;
/* number of SubClassSet tables */
TTO_SubClassSet* SubClassSet; /* array of SubClassSet tables */
};
typedef struct TTO_ContextSubstFormat2_ TTO_ContextSubstFormat2;
struct TTO_ContextSubstFormat3_
{
TT_UShort GlyphCount; /* number of input glyphs */
TT_UShort SubstCount; /* number of SubstLookupRecords */
TTO_Coverage* Coverage; /* array of Coverage tables */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ContextSubstFormat3_ TTO_ContextSubstFormat3;
struct TTO_ContextSubst_
{
TT_UShort SubstFormat; /* 1, 2, or 3 */
union
{
TTO_ContextSubstFormat1 csf1;
TTO_ContextSubstFormat2 csf2;
TTO_ContextSubstFormat3 csf3;
} csf;
};
typedef struct TTO_ContextSubst_ TTO_ContextSubst;
/* LookupType 6 */
struct TTO_ChainSubRule_
{
TT_UShort BacktrackGlyphCount;
/* total number of backtrack glyphs */
TT_UShort* Backtrack; /* array of backtrack glyph IDs */
TT_UShort InputGlyphCount;
/* total number of input glyphs */
TT_UShort* Input; /* array of input glyph IDs */
TT_UShort LookaheadGlyphCount;
/* total number of lookahead glyphs */
TT_UShort* Lookahead; /* array of lookahead glyph IDs */
TT_UShort SubstCount; /* number of SubstLookupRecords */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of SubstLookupRecords */
};
typedef struct TTO_ChainSubRule_ TTO_ChainSubRule;
struct TTO_ChainSubRuleSet_
{
TT_UShort ChainSubRuleCount;
/* number of ChainSubRule tables */
TTO_ChainSubRule* ChainSubRule; /* array of ChainSubRule tables */
};
typedef struct TTO_ChainSubRuleSet_ TTO_ChainSubRuleSet;
struct TTO_ChainContextSubstFormat1_
{
TTO_Coverage Coverage; /* Coverage table */
TT_UShort ChainSubRuleSetCount;
/* number of ChainSubRuleSet tables */
TTO_ChainSubRuleSet* ChainSubRuleSet;
/* array of ChainSubRuleSet tables */
};
typedef struct TTO_ChainContextSubstFormat1_ TTO_ChainContextSubstFormat1;
struct TTO_ChainSubClassRule_
{
TT_UShort BacktrackGlyphCount;
/* total number of backtrack
classes */
TT_UShort* Backtrack; /* array of backtrack classes */
TT_UShort InputGlyphCount;
/* total number of context classes */
TT_UShort* Input; /* array of context classes */
TT_UShort LookaheadGlyphCount;
/* total number of lookahead
classes */
TT_UShort* Lookahead; /* array of lookahead classes */
TT_UShort SubstCount; /* number of SubstLookupRecords */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ChainSubClassRule_ TTO_ChainSubClassRule;
struct TTO_ChainSubClassSet_
{
TT_UShort ChainSubClassRuleCount;
/* number of ChainSubClassRule
tables */
TTO_ChainSubClassRule* ChainSubClassRule;
/* array of ChainSubClassRule
tables */
};
typedef struct TTO_ChainSubClassSet_ TTO_ChainSubClassSet;
/* The `MaxXXXLength' fields are not defined in the TTO specification
but simplifies the implementation of this format. It holds the
maximal context length used in the specific context rules. */
struct TTO_ChainContextSubstFormat2_
{
TTO_Coverage Coverage; /* Coverage table */
TT_UShort MaxBacktrackLength;
/* maximal backtrack length */
TTO_ClassDefinition BacktrackClassDef;
/* BacktrackClassDef table */
TT_UShort MaxInputLength;
/* maximal input length */
TTO_ClassDefinition InputClassDef;
/* InputClassDef table */
TT_UShort MaxLookaheadLength;
/* maximal lookahead length */
TTO_ClassDefinition LookaheadClassDef;
/* LookaheadClassDef table */
TT_UShort ChainSubClassSetCount;
/* number of ChainSubClassSet
tables */
TTO_ChainSubClassSet* ChainSubClassSet;
/* array of ChainSubClassSet
tables */
};
typedef struct TTO_ChainContextSubstFormat2_ TTO_ChainContextSubstFormat2;
struct TTO_ChainContextSubstFormat3_
{
TT_UShort BacktrackGlyphCount;
/* number of backtrack glyphs */
TTO_Coverage* BacktrackCoverage;
/* array of backtrack Coverage
tables */
TT_UShort InputGlyphCount;
/* number of input glyphs */
TTO_Coverage* InputCoverage;
/* array of input coverage
tables */
TT_UShort LookaheadGlyphCount;
/* number of lookahead glyphs */
TTO_Coverage* LookaheadCoverage;
/* array of lookahead coverage
tables */
TT_UShort SubstCount; /* number of SubstLookupRecords */
TTO_SubstLookupRecord* SubstLookupRecord;
/* array of substitution lookups */
};
typedef struct TTO_ChainContextSubstFormat3_ TTO_ChainContextSubstFormat3;
struct TTO_ChainContextSubst_
{
TT_UShort SubstFormat; /* 1, 2, or 3 */
union
{
TTO_ChainContextSubstFormat1 ccsf1;
TTO_ChainContextSubstFormat2 ccsf2;
TTO_ChainContextSubstFormat3 ccsf3;
} ccsf;
};
typedef struct TTO_ChainContextSubst_ TTO_ChainContextSubst;
union TTO_GSUB_SubTable_
{
TTO_SingleSubst single;
TTO_MultipleSubst multiple;
TTO_AlternateSubst alternate;
TTO_LigatureSubst ligature;
TTO_ContextSubst context;
TTO_ChainContextSubst chain;
};
typedef union TTO_GSUB_SubTable_ TTO_GSUB_SubTable;
/* A simple string object. It can both `send' and `receive' data.
In case of sending, `length' and `pos' will be used. In case of
receiving, `pos' points to the first free slot, and `allocated'
specifies the amount of allocated memory (and the `length' field
will be ignored). The routine TT_Add_String() will increase the
amount of memory if necessary. After end of receive, `length'
should be set to the value of `pos', and `pos' will be set to zero.
`properties' (which is treated as a bit field) gives the glyph's
properties: If a certain bit is set for a glyph, the feature which
has the same bit set in its property value is applied.
NEVER modify any elements of the structure! You should rather copy
its contents if necessary.
TT_Add_String() will also handle allocation; you should use
free() in case you want to destroy the arrays in the object. */
struct TTO_GSUB_String_
{
TT_ULong length;
TT_ULong pos;
TT_ULong allocated;
TT_UShort* string;
TT_UShort* properties;
};
typedef struct TTO_GSUB_String_ TTO_GSUB_String;
/* finally, the GSUB API */
EXPORT_DEF
TT_Error TT_Init_GSUB_Extension( TT_Engine engine );
EXPORT_DEF
TT_Error TT_Load_GSUB_Table( TT_Face face,
TTO_GSUBHeader* gsub,
TTO_GDEFHeader* gdef );
EXPORT_DEF
TT_Error TT_GSUB_Select_Script( TTO_GSUBHeader* gsub,
TT_ULong script_tag,
TT_UShort* script_index );
EXPORT_DEF
TT_Error TT_GSUB_Select_Language( TTO_GSUBHeader* gsub,
TT_ULong language_tag,
TT_UShort script_index,
TT_UShort* language_index,
TT_UShort* req_feature_index );
EXPORT_DEF
TT_Error TT_GSUB_Select_Feature( TTO_GSUBHeader* gsub,
TT_ULong feature_tag,
TT_UShort script_index,
TT_UShort language_index,
TT_UShort* feature_index );
EXPORT_DEF
TT_Error TT_GSUB_Query_Scripts( TTO_GSUBHeader* gsub,
TT_ULong** script_tag_list );
EXPORT_DEF
TT_Error TT_GSUB_Query_Languages( TTO_GSUBHeader* gsub,
TT_UShort script_index,
TT_ULong** language_tag_list );
EXPORT_DEF
TT_Error TT_GSUB_Query_Features( TTO_GSUBHeader* gsub,
TT_UShort script_index,
TT_UShort language_index,
TT_ULong** feature_tag_list );
EXPORT_DEF
TT_Error TT_GSUB_Add_Feature( TTO_GSUBHeader* gsub,
TT_UShort feature_index,
TT_UShort property );
EXPORT_DEF
TT_Error TT_GSUB_Clear_Features( TTO_GSUBHeader* gsub );
EXPORT_DEF
TT_Error TT_GSUB_Register_Alternate_Function( TTO_GSUBHeader* gsub,
TTO_AltFunction alt,
void* data );
EXPORT_DEF
TT_Error TT_GSUB_Apply_String( TTO_GSUBHeader* gsub,
TTO_GSUB_String* in,
TTO_GSUB_String* out );
EXPORT_DEF
TT_Error TT_GSUB_Add_String( TTO_GSUB_String* in,
TT_UShort num_in,
TTO_GSUB_String* out,
TT_UShort num_out,
TT_UShort* data );
#ifdef __cplusplus
}
#endif
#endif /* FTXGSUB_H */
/* END */

564
lib/extend/ftxkern.c Normal file
View File

@@ -0,0 +1,564 @@
/*******************************************************************
*
* ftxkern.c 1.0
*
* Kerning support extension.
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* The kerning support is currently part of the engine extensions.
*
******************************************************************/
#include "ftxkern.h"
#include "ttextend.h"
#include "tttypes.h"
#include "ttdebug.h"
#include "ttmemory.h"
#include "ttfile.h"
#include "ttobjs.h"
#include "ttload.h" /* For the macros */
#include "tttags.h"
/* Required by the tracing mode */
#undef TT_COMPONENT
#define TT_COMPONENT trace_any
#define KERNING_ID Build_Extension_ID( 'k', 'e', 'r', 'n' )
/*******************************************************************
*
* Function : SubTable_Load_0
*
* Description : Loads a format 0 kerning subtable data.
*
* Input : kern0 pointer to the kerning subtable
*
* Output : error code
*
* Notes : - Assumes that the stream is already `used'
*
* - the file cursor must be set by the caller
*
* - in case of error, the function _must_ destroy
* the data it allocates!
*
******************************************************************/
static TT_Error Subtable_Load_0( TT_Kern_0* kern0,
PFace input )
{
DEFINE_LOAD_LOCALS( input->stream );
UShort num_pairs, n;
if ( ACCESS_Frame( 8L ) )
return error;
num_pairs = GET_UShort();
kern0->nPairs = 0;
kern0->searchRange = GET_UShort();
kern0->entrySelector = GET_UShort();
kern0->rangeShift = GET_UShort();
/* we only set kern0->nPairs if the subtable has been loaded */
FORGET_Frame();
if ( ALLOC_ARRAY( kern0->pairs, num_pairs, TT_Kern_0_Pair ) )
return error;
if ( ACCESS_Frame( num_pairs * 6L ) )
goto Fail;
for ( n = 0; n < num_pairs; n++ )
{
kern0->pairs[n].left = GET_UShort();
kern0->pairs[n].right = GET_UShort();
kern0->pairs[n].value = GET_UShort();
if ( kern0->pairs[n].left >= input->numGlyphs ||
kern0->pairs[n].right >= input->numGlyphs )
{
FORGET_Frame();
error = TT_Err_Invalid_Kerning_Table;
goto Fail;
}
}
FORGET_Frame();
/* we're ok, set the pairs count */
kern0->nPairs = num_pairs;
return TT_Err_Ok;
Fail:
FREE( kern0->pairs );
return error;
}
/*******************************************************************
*
* Function : SubTable_Load_2
*
* Description : Loads a format 2 kerning subtable data.
*
* Input : kern2 pointer to the kerning subtable
* length subtable length. This is required as
* the subheader doesn't give any indication
* of the size of the `array' table.
*
* Output : error code
*
* Notes : - Assumes that the stream is already `used'
*
* - the file cursor must be set by the caller
*
* - in case of error, the function _must_ destroy
* the data it allocates!
*
******************************************************************/
static TT_Error Subtable_Load_2( TT_Kern_2* kern2,
PFace input )
{
DEFINE_LOAD_LOCALS( input->stream );
Long table_base;
UShort left_offset, right_offset, array_offset;
ULong array_size;
UShort left_max, right_max, n;
/* record the table offset */
table_base = FILE_Pos();
if ( ACCESS_Frame( 8L ) )
return error;
kern2->rowWidth = GET_UShort();
left_offset = GET_UShort();
right_offset = GET_UShort();
array_offset = GET_UShort();
FORGET_Frame();
/* first load left and right glyph classes */
if ( FILE_Seek( table_base + left_offset ) ||
ACCESS_Frame( 4L ) )
return error;
kern2->leftClass.firstGlyph = GET_UShort();
kern2->leftClass.nGlyphs = GET_UShort();
FORGET_Frame();
if ( ALLOC_ARRAY( kern2->leftClass.classes,
kern2->leftClass.nGlyphs,
UShort ) )
return error;
/* load left offsets */
if ( ACCESS_Frame( kern2->leftClass.nGlyphs * 2L ) )
goto Fail_Left;
for ( n = 0; n < kern2->leftClass.nGlyphs; n++ )
kern2->leftClass.classes[n] = GET_UShort();
FORGET_Frame();
/* right class */
if ( FILE_Seek( table_base + right_offset ) ||
ACCESS_Frame( 4L ) )
goto Fail_Left;
kern2->rightClass.firstGlyph = GET_UShort();
kern2->rightClass.nGlyphs = GET_UShort();
FORGET_Frame();
if ( ALLOC_ARRAY( kern2->rightClass.classes,
kern2->rightClass.nGlyphs,
UShort ) )
goto Fail_Left;
/* load right offsets */
if ( ACCESS_Frame( kern2->rightClass.nGlyphs * 2L ) )
goto Fail_Right;
for ( n = 0; n < kern2->rightClass.nGlyphs; n++ )
kern2->rightClass.classes[n] = GET_UShort();
FORGET_Frame();
/* Now load the kerning array. We don't have its size, we */
/* must compute it from what we know. */
/* We thus compute the maximum left and right offsets and */
/* add them to get the array size. */
left_max = right_max = 0;
for ( n = 0; n < kern2->leftClass.nGlyphs; n++ )
left_max = MAX( left_max, kern2->leftClass.classes[n] );
for ( n = 0; n < kern2->rightClass.nGlyphs; n++ )
right_max = MAX( right_max, kern2->leftClass.classes[n] );
array_size = left_max + right_max + 2;
if ( ALLOC( kern2->array, array_size ) )
goto Fail_Right;
if ( ACCESS_Frame( array_size ) )
goto Fail_Array;
for ( n = 0; n < array_size/2; n++ )
kern2->array[n] = GET_Short();
FORGET_Frame();
/* we're good now */
return TT_Err_Ok;
Fail_Array:
FREE( kern2->array );
Fail_Right:
FREE( kern2->rightClass.classes );
kern2->rightClass.nGlyphs = 0;
Fail_Left:
FREE( kern2->leftClass.classes );
kern2->leftClass.nGlyphs = 0;
return error;
}
/*******************************************************************
*
* Function : Kerning_Create
*
* Description : Creates the kerning directory if a face is
* loaded. The tables however are loaded on
* demand to save space.
*
* Input : face pointer to the parent face object
* kern pointer to the extension's kerning field
*
* Output : error code
*
* Notes : as in all constructors, the memory allocated isn't
* released in case of failure. Rather, the task is left
* to the destructor (which is called if an error
* occurs during the loading of a face).
*
******************************************************************/
static TT_Error Kerning_Create( void* ext,
PFace face )
{
DEFINE_LOAD_LOCALS( face->stream );
TT_Kerning* kern = (TT_Kerning*)ext;
UShort num_tables;
Long table;
TT_Kern_Subtable* sub;
/* by convention */
if ( !kern )
return TT_Err_Ok;
/* Now load the kerning directory. We're called from the face */
/* constructor. We thus need not use the stream. */
kern->version = 0;
kern->nTables = 0;
kern->tables = NULL;
table = TT_LookUp_Table( face, TTAG_kern );
if ( table < 0 )
return TT_Err_Ok; /* The table is optional */
if ( FILE_Seek( face->dirTables[table].Offset ) ||
ACCESS_Frame( 4L ) )
return error;
kern->version = GET_UShort();
num_tables = GET_UShort();
FORGET_Frame();
/* we don't set kern->nTables until we have allocated the array */
if ( ALLOC_ARRAY( kern->tables, num_tables, TT_Kern_Subtable ) )
return error;
kern->nTables = num_tables;
/* now load the directory entries, but do _not_ load the tables ! */
sub = kern->tables;
for ( table = 0; table < num_tables; table++ )
{
if ( ACCESS_Frame( 6L ) )
return error;
sub->loaded = FALSE; /* redundant, but good to see */
sub->version = GET_UShort();
sub->length = GET_UShort() - 6; /* substract header length */
sub->format = GET_Byte();
sub->coverage = GET_Byte();
FORGET_Frame();
sub->offset = FILE_Pos();
/* now skip to the next table */
if ( FILE_Skip( sub->length ) )
return error;
sub++;
}
/* that's fine, leave now */
return TT_Err_Ok;
}
/*******************************************************************
*
* Function : Kerning_Destroy
*
* Description : Destroys all kerning information.
*
* Input : kern pointer to the extension's kerning field
*
* Output : error code
*
* Notes : This function is a destructor; it must be able
* to destroy partially built tables.
*
******************************************************************/
static TT_Error Kerning_Destroy( void* ext,
PFace face )
{
TT_Kerning* kern = (TT_Kerning*)ext;
TT_Kern_Subtable* sub;
UShort n;
/* by convention */
if ( !kern )
return TT_Err_Ok;
if ( kern->nTables == 0 )
return TT_Err_Ok; /* no tables to release */
/* scan the table directory and release loaded entries */
sub = kern->tables;
for ( n = 0; n < kern->nTables; n++ )
{
if ( sub->loaded )
{
switch ( sub->format )
{
case 0:
FREE( sub->t.kern0.pairs );
sub->t.kern0.nPairs = 0;
sub->t.kern0.searchRange = 0;
sub->t.kern0.entrySelector = 0;
sub->t.kern0.rangeShift = 0;
break;
case 2:
FREE( sub->t.kern2.leftClass.classes );
sub->t.kern2.leftClass.firstGlyph = 0;
sub->t.kern2.leftClass.nGlyphs = 0;
FREE( sub->t.kern2.rightClass.classes );
sub->t.kern2.rightClass.firstGlyph = 0;
sub->t.kern2.rightClass.nGlyphs = 0;
FREE( sub->t.kern2.array );
sub->t.kern2.rowWidth = 0;
break;
default:
; /* invalid subtable format - do nothing */
}
sub->loaded = FALSE;
sub->version = 0;
sub->offset = 0;
sub->length = 0;
sub->coverage = 0;
sub->format = 0;
}
sub++;
}
FREE( kern->tables );
kern->nTables = 0;
return TT_Err_Ok;
}
/*******************************************************************
*
* Function : TT_Get_Kerning_Directory
*
* Description : Returns a given face's kerning directory.
*
* Input : face handle to the face object
* directory pointer to client's target directory
*
* Output : error code
*
* Notes : The kerning table directory is loaded with the face
* through the extension constructor. However, the kerning
* tables themselves are only loaded on demand, as they
* may represent a lot of data, unneeded by most uses of
* the engine.
*
******************************************************************/
EXPORT_FUNC
TT_Error TT_Get_Kerning_Directory( TT_Face face,
TT_Kerning* directory )
{
PFace faze = HANDLE_Face( face );
TT_Error error;
TT_Kerning* kerning;
if ( !faze )
return TT_Err_Invalid_Face_Handle;
/* copy directory header */
error = TT_Extension_Get( faze, KERNING_ID, (void**)&kerning );
if ( !error )
*directory = *kerning;
return error;
}
/*******************************************************************
*
* Function : TT_Load_Kerning_Table
*
* Description : Loads a kerning table intro memory.
*
* Input : face face handle
* kern_index index in the face's kerning directory
*
* Output : error code
*
* Notes :
*
******************************************************************/
EXPORT_FUNC
TT_Error TT_Load_Kerning_Table( TT_Face face,
TT_UShort kern_index )
{
TT_Error error;
TT_Stream stream;
TT_Kerning* kern;
TT_Kern_Subtable* sub;
PFace faze = HANDLE_Face( face );
if ( !faze )
return TT_Err_Invalid_Face_Handle;
error = TT_Extension_Get( faze, KERNING_ID, (void**)&kern );
if ( error )
return error;
if ( kern->nTables == 0 )
return TT_Err_Table_Missing;
if ( kern_index >= kern->nTables )
return TT_Err_Invalid_Argument;
sub = kern->tables + kern_index;
if ( sub->format != 0 && sub->format != 2 )
return TT_Err_Invalid_Kerning_Table_Format;
/* now access stream */
if ( USE_Stream( faze->stream, stream ) )
return error;
if ( FILE_Seek( sub->offset ) )
goto Fail;
if ( sub->format == 0 )
error = Subtable_Load_0( &sub->t.kern0, faze );
else if ( sub->format == 2 )
error = Subtable_Load_2( &sub->t.kern2, faze );
if ( !error )
sub->loaded = TRUE;
Fail:
/* release stream */
DONE_Stream( stream );
return error;
}
EXPORT_FUNC
TT_Error TT_Init_Kerning_Extension( TT_Engine engine )
{
PEngine_Instance _engine = HANDLE_Engine( engine );
TT_Error error;
if ( !_engine )
return TT_Err_Invalid_Engine;
error = TT_Register_Extension( _engine,
KERNING_ID,
sizeof ( TT_Kerning ),
Kerning_Create,
Kerning_Destroy );
return error;
}
/* END */

181
lib/extend/ftxkern.h Normal file
View File

@@ -0,0 +1,181 @@
/*******************************************************************
*
* ftxkern.h 1.0
*
* High-Level API Kerning extension
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* The kerning support is currently part of the engine extensions.
*
* This file should _not_ depend on engine internal types.
*
******************************************************************/
#ifndef FTXKERN_H
#define FTXKERN_H
#include "freetype.h"
#ifdef __cplusplus
extern "C" {
#endif
/* The kerning support in FreeType is minimal. This means that */
/* we do not try to interpret the kerning data in any way to */
/* `cook' it for a user application. This API lets you access */
/* directly the kerning tables found in the TrueType file; it's */
/* up to the client application to apply its own processing on */
/* these. */
/* The reason for this is that we generally do not encourage */
/* feature-bloat of the core engine. Moreover, not all */
/* libraries or font servers really need kerning data, or all */
/* formats of this data. */
/************** kerning error codes *****************************/
/* we choose the class 0x0A for our errors, this should not */
/* match with any error code class used in any other extension */
#define TT_Err_Invalid_Kerning_Table_Format 0x0A00
#define TT_Err_Invalid_Kerning_Table 0x0A01
/********** structures definitions ******************************/
/* Remember that all types and function are accessible by client */
/* applications in this section, and thus should have the `TT_' */
/* prefix. */
/* format 0 kerning pair */
struct TT_Kern_0_Pair_
{
TT_UShort left; /* index of left glyph in pair */
TT_UShort right; /* index of right glyph in pair */
TT_FWord value; /* kerning value */
};
typedef struct TT_Kern_0_Pair_ TT_Kern_0_Pair;
/* format 0 kerning subtable */
struct TT_Kern_0_
{
TT_UShort nPairs; /* number of kerning pairs */
TT_UShort searchRange; /* these values are defined by the TT spec */
TT_UShort entrySelector; /* for table searchs. */
TT_UShort rangeShift;
TT_Kern_0_Pair* pairs; /* a table of nPairs `pairs' */
};
typedef struct TT_Kern_0_ TT_Kern_0;
/* format 2 kerning glyph class */
struct TT_Kern_2_Class_
{
TT_UShort firstGlyph; /* first glyph in range */
TT_UShort nGlyphs; /* number of glyphs in range */
TT_UShort* classes; /* a table giving for each ranged glyph */
/* its class offset in the subtable pairs */
/* two-dimensional array */
};
typedef struct TT_Kern_2_Class_ TT_Kern_2_Class;
/* format 2 kerning subtable */
struct TT_Kern_2_
{
TT_UShort rowWidth; /* length of one row in bytes */
TT_Kern_2_Class leftClass; /* left class table */
TT_Kern_2_Class rightClass; /* right class table */
TT_FWord* array; /* 2-dimensional kerning values array */
};
typedef struct TT_Kern_2_ TT_Kern_2;
/* kerning subtable */
struct TT_Kern_Subtable_
{
TT_Bool loaded; /* boolean; indicates whether the table is */
/* loaded */
TT_UShort version; /* table version number */
TT_Long offset; /* file offset of table */
TT_UShort length; /* length of table, _excluding_ header */
TT_Byte coverage; /* lower 8 bit of the coverage table entry */
TT_Byte format; /* the subtable format, as found in the */
/* higher 8 bits of the coverage table entry */
union
{
TT_Kern_0 kern0;
TT_Kern_2 kern2;
} t;
};
typedef struct TT_Kern_Subtable_ TT_Kern_Subtable;
struct TT_Kerning_
{
TT_UShort version; /* kern table version number. starts at 0 */
TT_UShort nTables; /* number of tables */
TT_Kern_Subtable* tables; /* the kerning sub-tables */
};
typedef struct TT_Kerning_ TT_Kerning;
/***************** high-level API extension **************************/
/* Initialize Kerning extension, must be called after */
/* TT_Init_FreeType(). There is no need for a finalizer */
EXPORT_DEF
TT_Error TT_Init_Kerning_Extension( TT_Engine engine );
/* Note on the implemented mechanism: */
/* The kerning table directory is loaded with the face through the */
/* extension constructor. However, the tables will only be loaded */
/* on demand, as they may represent a lot of data, unnecessary to */
/* most applications. */
/* Queries a pointer to the kerning directory for the face object */
EXPORT_DEF
TT_Error TT_Get_Kerning_Directory( TT_Face face,
TT_Kerning* directory );
/* Load the kerning table number `kern_index' in the kerning */
/* directory. The table will stay in memory until the `face' */
/* face is destroyed. */
EXPORT_DEF
TT_Error TT_Load_Kerning_Table( TT_Face face,
TT_UShort kern_index );
#ifdef __cplusplus
}
#endif
#endif /* FTXKERN_H */
/* END */

1439
lib/extend/ftxopen.c Normal file

File diff suppressed because it is too large Load Diff

304
lib/extend/ftxopen.h Normal file
View File

@@ -0,0 +1,304 @@
/*******************************************************************
*
* ftxopen.h
*
* TrueType Open support.
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
* This file should be included by the application. Nevertheless,
* the table specific APIs (and structures) are located in files like
* ftxgsub.h or ftxgpos.h; these header files are read by ftxopen.h .
*
******************************************************************/
#ifndef FTXOPEN_H
#define FTXOPEN_H
#include "freetype.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TTO_MAX_NESTING_LEVEL 100
#define TTO_Err_Invalid_SubTable_Format 0x1000
#define TTO_Err_Invalid_SubTable 0x1001
#define TTO_Err_Not_Covered 0x1002
#define TTO_Err_Too_Many_Nested_Contexts 0x1003
/* Script list related structures */
struct TTO_LangSys_
{
TT_UShort LookupOrderOffset; /* always 0 for TT Open 1.0 */
TT_UShort ReqFeatureIndex; /* required FeatureIndex */
TT_UShort FeatureCount; /* number of Feature indices */
TT_UShort* FeatureIndex; /* array of Feature indices */
};
typedef struct TTO_LangSys_ TTO_LangSys;
struct TTO_LangSysRecord_
{
TT_ULong LangSysTag; /* LangSysTag identifier */
TTO_LangSys LangSys; /* LangSys table */
};
typedef struct TTO_LangSysRecord_ TTO_LangSysRecord;
struct TTO_Script_
{
TTO_LangSys DefaultLangSys; /* DefaultLangSys table */
TT_UShort LangSysCount; /* number of LangSysRecords */
TTO_LangSysRecord* LangSysRecord; /* array of LangSysRecords */
};
typedef struct TTO_Script_ TTO_Script;
struct TTO_ScriptRecord_
{
TT_ULong ScriptTag; /* ScriptTag identifier */
TTO_Script Script; /* Script table */
};
typedef struct TTO_ScriptRecord_ TTO_ScriptRecord;
struct TTO_ScriptList_
{
TT_UShort ScriptCount; /* number of ScriptRecords */
TTO_ScriptRecord* ScriptRecord; /* array of ScriptRecords */
};
typedef struct TTO_ScriptList_ TTO_ScriptList;
/* Feature list related structures */
struct TTO_Feature_
{
TT_UShort FeatureParams; /* always 0 for TT Open 1.0 */
TT_UShort LookupListCount; /* number of LookupList indices */
TT_UShort* LookupListIndex; /* array of LookupList indices */
};
typedef struct TTO_Feature_ TTO_Feature;
struct TTO_FeatureRecord_
{
TT_ULong FeatureTag; /* FeatureTag identifier */
TTO_Feature Feature; /* Feature table */
};
typedef struct TTO_FeatureRecord_ TTO_FeatureRecord;
struct TTO_FeatureList_
{
TT_UShort FeatureCount; /* number of FeatureRecords */
TTO_FeatureRecord* FeatureRecord; /* array of FeatureRecords */
};
typedef struct TTO_FeatureList_ TTO_FeatureList;
/* Lookup list related structures */
struct TTO_SubTable_; /* defined below after inclusion
of ftxgsub.h and ftxgpos.h */
typedef struct TTO_SubTable_ TTO_SubTable;
struct TTO_Lookup_
{
TT_UShort LookupType; /* Lookup type */
TT_UShort LookupFlag; /* Lookup qualifiers */
TT_UShort SubTableCount; /* number of SubTables */
TTO_SubTable* SubTable; /* array of SubTables */
};
typedef struct TTO_Lookup_ TTO_Lookup;
/* The `Properties' field is not defined in the TTO specification but
is needed for processing lookups. If properties[n] is > 0, the
function TT_GSUB_Apply() will process Lookup[n] for glyphs which
have the specific bit not set in the `properties' field of the
input string object. */
struct TTO_LookupList_
{
TT_UShort LookupCount; /* number of Lookups */
TTO_Lookup* Lookup; /* array of Lookup records */
TT_UShort* Properties; /* array of flags */
};
typedef struct TTO_LookupList_ TTO_LookupList;
/* Possible LookupFlag bit masks. `IGNORE_SPECIAL_MARKS' comes from the
OpenType 1.2 specification. */
#define IGNORE_BASE_GLYPHS 0x0002
#define IGNORE_LIGATURES 0x0004
#define IGNORE_MARKS 0x0008
#define IGNORE_SPECIAL_MARKS 0xFF00
struct TTO_CoverageFormat1_
{
TT_UShort GlyphCount; /* number of glyphs in GlyphArray */
TT_UShort* GlyphArray; /* array of glyph IDs */
};
typedef struct TTO_CoverageFormat1_ TTO_CoverageFormat1;
struct TTO_RangeRecord_
{
TT_UShort Start; /* first glyph ID in the range */
TT_UShort End; /* last glyph ID in the range */
TT_UShort StartCoverageIndex; /* coverage index of first
glyph ID in the range */
};
typedef struct TTO_RangeRecord_ TTO_RangeRecord;
struct TTO_CoverageFormat2_
{
TT_UShort RangeCount; /* number of RangeRecords */
TTO_RangeRecord* RangeRecord; /* array of RangeRecords */
};
typedef struct TTO_CoverageFormat2_ TTO_CoverageFormat2;
struct TTO_Coverage_
{
TT_UShort CoverageFormat; /* 1 or 2 */
union
{
TTO_CoverageFormat1 cf1;
TTO_CoverageFormat2 cf2;
} cf;
};
typedef struct TTO_Coverage_ TTO_Coverage;
struct TTO_ClassDefFormat1_
{
TT_UShort StartGlyph; /* first glyph ID of the
ClassValueArray */
TT_UShort GlyphCount; /* size of the ClassValueArray */
TT_UShort* ClassValueArray; /* array of class values */
};
typedef struct TTO_ClassDefFormat1_ TTO_ClassDefFormat1;
struct TTO_ClassRangeRecord_
{
TT_UShort Start; /* first glyph ID in the range */
TT_UShort End; /* last glyph ID in the range */
TT_UShort Class; /* applied to all glyphs in range */
};
typedef struct TTO_ClassRangeRecord_ TTO_ClassRangeRecord;
struct TTO_ClassDefFormat2_
{
TT_UShort ClassRangeCount;
/* number of ClassRangeRecords */
TTO_ClassRangeRecord* ClassRangeRecord;
/* array of ClassRangeRecords */
};
typedef struct TTO_ClassDefFormat2_ TTO_ClassDefFormat2;
/* The `Defined' field is not defined in the TTO specification but
apparently needed for processing fonts like trado.ttf: This font
refers to a class which contains not a single element. We map such
classes to class 0. */
struct TTO_ClassDefinition_
{
TT_Bool loaded;
TT_Bool* Defined; /* array of Booleans.
If Defined[n] is FALSE,
class n contains no glyphs. */
TT_UShort ClassFormat; /* 1 or 2 */
union
{
TTO_ClassDefFormat1 cd1;
TTO_ClassDefFormat2 cd2;
} cd;
};
typedef struct TTO_ClassDefinition_ TTO_ClassDefinition;
struct TTO_Device_
{
TT_UShort StartSize; /* smallest size to correct */
TT_UShort EndSize; /* largest size to correct */
TT_UShort DeltaFormat; /* DeltaValue array data format:
1, 2, or 3 */
TT_UShort* DeltaValue; /* array of compressed data */
};
typedef struct TTO_Device_ TTO_Device;
#include "ftxgdef.h"
#include "ftxgsub.h"
#include "ftxgpos.h"
struct TTO_SubTable_
{
union
{
TTO_GSUB_SubTable gsub;
TTO_GPOS_SubTable gpos;
} st;
};
enum TTO_Type_
{
GSUB,
GPOS
};
typedef enum TTO_Type_ TTO_Type;
#ifdef __cplusplus
}
#endif
#endif /* FTXOPEN_H */
/* END */

135
lib/extend/ftxopenf.h Normal file
View File

@@ -0,0 +1,135 @@
/*******************************************************************
*
* ftxopenf.h
*
* internal TrueType Open functions
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
******************************************************************/
#ifndef FTXOPENF_H
#define FTXOPENF_H
#include "ftxopen.h"
#ifdef __cplusplus
extern "C" {
#endif
/* functions from ftxopen.c */
TT_Error Load_ScriptList( TTO_ScriptList* sl,
PFace input );
TT_Error Load_FeatureList( TTO_FeatureList* fl,
PFace input );
TT_Error Load_LookupList( TTO_LookupList* ll,
PFace input,
TTO_Type type );
TT_Error Load_Coverage( TTO_Coverage* c,
PFace input );
TT_Error Load_ClassDefinition( TTO_ClassDefinition* cd,
UShort limit,
PFace input );
TT_Error Load_Device( TTO_Device* d,
PFace input );
void Free_ScriptList( TTO_ScriptList* sl );
void Free_FeatureList( TTO_FeatureList* fl );
void Free_LookupList( TTO_LookupList* ll,
TTO_Type type );
void Free_Coverage( TTO_Coverage* c );
void Free_ClassDefinition( TTO_ClassDefinition* cd );
void Free_Device( TTO_Device* d );
/* functions from ftxgsub.c */
TT_Error Load_SingleSubst( TTO_SingleSubst* ss,
PFace input );
TT_Error Load_MultipleSubst( TTO_MultipleSubst* ms,
PFace input );
TT_Error Load_AlternateSubst( TTO_AlternateSubst* as,
PFace input );
TT_Error Load_LigatureSubst( TTO_LigatureSubst* ls,
PFace input );
TT_Error Load_ContextSubst( TTO_ContextSubst* cs,
PFace input );
TT_Error Load_ChainContextSubst( TTO_ChainContextSubst* ccs,
PFace input );
void Free_SingleSubst( TTO_SingleSubst* ss );
void Free_MultipleSubst( TTO_MultipleSubst* ms );
void Free_AlternateSubst( TTO_AlternateSubst* as );
void Free_LigatureSubst( TTO_LigatureSubst* ls );
void Free_ContextSubst( TTO_ContextSubst* cs );
void Free_ChainContextSubst( TTO_ChainContextSubst* ccs );
/* functions from ftxgpos.c */
TT_Error Load_SinglePos( TTO_SinglePos* sp,
PFace input );
TT_Error Load_PairPos( TTO_PairPos* pp,
PFace input );
TT_Error Load_CursivePos( TTO_CursivePos* cp,
PFace input );
TT_Error Load_MarkBasePos( TTO_MarkBasePos* mbp,
PFace input );
TT_Error Load_MarkLigPos( TTO_MarkLigPos* mlp,
PFace input );
TT_Error Load_MarkMarkPos( TTO_MarkMarkPos* mmp,
PFace input );
TT_Error Load_ContextPos( TTO_ContextPos* cp,
PFace input );
TT_Error Load_ChainContextPos( TTO_ChainContextPos* ccp,
PFace input );
void Free_SinglePos( TTO_SinglePos* sp );
void Free_PairPos( TTO_PairPos* pp );
void Free_CursivePos( TTO_CursivePos* cp );
void Free_MarkBasePos( TTO_MarkBasePos* mbp );
void Free_MarkLigPos( TTO_MarkLigPos* mlp );
void Free_MarkMarkPos( TTO_MarkMarkPos* mmp );
void Free_ContextPos( TTO_ContextPos* cp );
void Free_ChainContextPos( TTO_ChainContextPos* ccp );
/* query functions */
TT_Error Coverage_Index( TTO_Coverage* c,
UShort glyphID,
UShort* index );
TT_Error Get_Class( TTO_ClassDefinition* cd,
UShort glyphID,
UShort* class,
UShort* index );
TT_Error Get_Device( TTO_Device* d,
UShort size,
Short* value );
/* functions from ftxgdef.c */
TT_Error Add_Glyph_Property( TTO_GDEFHeader* gdef,
UShort glyphID,
UShort property );
#ifdef __cplusplus
}
#endif
#endif /* FTXOPENF_H */
/* END */

522
lib/extend/ftxpost.c Normal file
View File

@@ -0,0 +1,522 @@
/*******************************************************************
*
* ftxpost.c
*
* post table support API extension body
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* The post table is not completely loaded by the core engine. This
* file loads the missing PS glyph names and implements an API to
* access them.
*
******************************************************************/
#include "ftxpost.h"
#include "tttypes.h"
#include "ttobjs.h"
#include "tttables.h"
#include "ttload.h" /* for the macros */
#include "ttfile.h"
#include "tttags.h"
#include "ttmemory.h"
#include "ttextend.h"
#define POST_ID Build_Extension_ID( 'p', 'o', 's', 't' )
/* the 258 default Mac PS glyph names */
String* TT_Post_Default_Names[258] =
{
/* 0 */
".notdef", ".null", "CR", "space", "exclam",
"quotedbl", "numbersign", "dollar", "percent", "ampersand",
/* 10 */
"quotesingle", "parenleft", "parenright", "asterisk", "plus",
"comma", "hyphen", "period", "slash", "zero",
/* 20 */
"one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "colon",
/* 30 */
"semicolon", "less", "equal", "greater", "question",
"at", "A", "B", "C", "D",
/* 40 */
"E", "F", "G", "H", "I",
"J", "K", "L", "M", "N",
/* 50 */
"O", "P", "Q", "R", "S",
"T", "U", "V", "W", "X",
/* 60 */
"Y", "Z", "bracketleft", "backslash", "bracketright",
"asciicircum", "underscore", "grave", "a", "b",
/* 70 */
"c", "d", "e", "f", "g",
"h", "i", "j", "k", "l",
/* 80 */
"m", "n", "o", "p", "q",
"r", "s", "t", "u", "v",
/* 90 */
"w", "x", "y", "z", "braceleft",
"bar", "braceright", "asciitilde", "Adieresis", "Aring",
/* 100 */
"Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis",
"aacute", "agrave", "acircumflex", "adieresis", "atilde",
/* 110 */
"aring", "ccedilla", "eacute", "egrave", "ecircumflex",
"edieresis", "iacute", "igrave", "icircumflex", "idieresis",
/* 120 */
"ntilde", "oacute", "ograve", "ocircumflex", "odieresis",
"otilde", "uacute", "ugrave", "ucircumflex", "udieresis",
/* 130 */
"dagger", "degree", "cent", "sterling", "section",
"bullet", "paragraph", "germandbls", "registered", "copyright",
/* 140 */
"trademark", "acute", "dieresis", "notequal", "AE",
"Oslash", "infinity", "plusminus", "lessequal", "greaterequal",
/* 150 */
"yen", "mu", "partialdiff", "summation", "product",
"pi", "integral", "ordfeminine", "ordmasculine", "Omega",
/* 160 */
"ae", "oslash", "questiondown", "exclamdown", "logicalnot",
"radical", "florin", "approxequal", "Delta", "guillemotleft",
/* 170 */
"guillemotright", "ellipsis", "nbspace", "Agrave", "Atilde",
"Otilde", "OE", "oe", "endash", "emdash",
/* 180 */
"quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide",
"lozenge", "ydieresis", "Ydieresis", "fraction", "currency",
/* 190 */
"guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl",
"periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex",
/* 200 */
"Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute",
"Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
/* 210 */
"apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave",
"dotlessi", "circumflex", "tilde", "macron", "breve",
/* 220 */
"dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek",
"caron", "Lslash", "lslash", "Scaron", "scaron",
/* 230 */
"Zcaron", "zcaron", "brokenbar", "Eth", "eth",
"Yacute", "yacute", "Thorn", "thorn", "minus",
/* 240 */
"multiply", "onesuperior", "twosuperior", "threesuperior", "onehalf",
"onequarter", "threequarters", "franc", "Gbreve", "gbreve",
/* 250 */
"Idot", "Scedilla", "scedilla", "Cacute", "cacute",
"Ccaron", "ccaron", "dmacron",
};
static TT_Error Load_Format_20( TT_Post_20* post20,
PFace input )
{
DEFINE_LOAD_LOCALS( input->stream );
UShort nameindex, n, num;
Byte len;
if ( ACCESS_Frame( 2L ) )
return error;
num = GET_UShort();
FORGET_Frame();
/* UNDOCUMENTED! The number of glyphs in this table can be smaller */
/* than the value in the maxp table (cf. cyberbit.ttf). */
/* There already exist fonts which have more than 32768 glyph names */
/* in this table, so the test for this threshold has been dropped. */
if ( num > input->numGlyphs )
return TT_Err_Invalid_Post_Table;
post20->numGlyphs = num;
if ( ALLOC_ARRAY( post20->glyphNameIndex, num, TT_UShort ) )
return error;
if ( ACCESS_Frame( num * 2L ) )
goto Fail;
for ( n = 0; n < num; n++ )
{
post20->glyphNameIndex[n] = GET_UShort();
if ( post20->glyphNameIndex[n] > 258 + num )
{
FORGET_Frame();
error = TT_Err_Invalid_Post_Table;
goto Fail;
}
}
FORGET_Frame();
if ( ALLOC_ARRAY( post20->glyphNames, num, Char* ) )
goto Fail;
/* We must initialize the glyphNames array for proper */
/* deallocation. */
for ( n = 0; n < num; n++ )
post20->glyphNames[n] = NULL;
/* Now we can read the glyph names which are stored in */
/* Pascal string format. */
for ( n = 0; n < num; n++ )
{
nameindex = post20->glyphNameIndex[n];
if ( nameindex < 258 )
; /* default Mac glyph, do nothing */
else
{
if ( ACCESS_Frame( 1L ) )
goto Fail1;
len = GET_Byte();
FORGET_Frame();
if ( ALLOC_ARRAY( post20->glyphNames[nameindex - 258],
len + 1, Char ) ||
FILE_Read( post20->glyphNames[nameindex - 258], len ) )
goto Fail1;
/* we make a C string */
post20->glyphNames[nameindex - 258][len] = '\0';
}
}
return TT_Err_Ok;
Fail1:
for ( n = 0; n < num; n++ )
if ( post20->glyphNames[n] )
FREE( post20->glyphNames[n] );
FREE( post20->glyphNames );
Fail:
FREE( post20->glyphNameIndex );
return error;
}
static TT_Error Load_Format_25( TT_Post_25* post25,
PFace input )
{
DEFINE_LOAD_LOCALS( input->stream );
UShort n, num;
if ( ACCESS_Frame( 2L ) )
return error;
/* UNDOCUMENTED! This value appears only in the Apple TT specs. */
num = GET_UShort();
FORGET_Frame();
if ( num > input->numGlyphs || num > 258 )
return TT_Err_Invalid_Post_Table;
post25->numGlyphs = num;
if ( ALLOC_ARRAY( post25->offset, num, Char ) )
return error;
if ( ACCESS_Frame( num ) )
goto Fail;
for ( n = 0; n < num; n++ )
{
post25->offset[n] = GET_Char();
/* We add 128 to the tests to avoid problems with negative */
/* values for comparison. */
if ( n + ( post25->offset[n] + 128 ) > num + 128 ||
n + ( post25->offset[n] + 128 ) < 128 )
{
FORGET_Frame();
error = TT_Err_Invalid_Post_Table;
goto Fail;
}
}
FORGET_Frame();
return TT_Err_Ok;
Fail:
FREE( post25->offset );
return error;
}
static TT_Error Post_Create( void* ext,
PFace face )
{
TT_Post* post = (TT_Post*)ext;
Long table;
/* by convention */
if ( !post )
return TT_Err_Ok;
/* we store the start offset and the size of the subtable */
table = TT_LookUp_Table( face, TTAG_post );
post->offset = face->dirTables[table].Offset + 32L;
post->length = face->dirTables[table].Length - 32L;
post->loaded = FALSE;
return TT_Err_Ok;
}
static TT_Error Post_Destroy( void* ext,
PFace face )
{
TT_Post* post = (TT_Post*)ext;
UShort n;
/* by convention */
if ( !post )
return TT_Err_Ok;
if ( post->loaded )
{
switch ( face->postscript.FormatType )
{
case 0x00010000: /* nothing to do */
break;
case 0x00020000:
for ( n = 0; n < post->p.post20.numGlyphs; n++ )
if ( post->p.post20.glyphNames[n] )
FREE( post->p.post20.glyphNames[n] );
FREE( post->p.post20.glyphNames );
FREE( post->p.post20.glyphNameIndex );
break;
case 0x00028000:
FREE( post->p.post25.offset );
break;
case 0x00030000: /* nothing to do */
break;
#if 0
case 0x00040000:
break;
#endif
default:
; /* invalid format, do nothing */
}
}
return TT_Err_Ok;
}
EXPORT_FUNC
TT_Error TT_Init_Post_Extension( TT_Engine engine )
{
PEngine_Instance _engine = HANDLE_Engine( engine );
TT_Error error;
if ( !_engine )
return TT_Err_Invalid_Engine;
error = TT_Register_Extension( _engine,
POST_ID,
sizeof ( TT_Post ),
Post_Create,
Post_Destroy );
return error;
}
/*******************************************************************
*
* Function : TT_Load_PS_Names
*
* Description : Loads the PostScript Glyph Name subtable (if any).
*
* Output : error code
*
******************************************************************/
EXPORT_FUNC
TT_Error TT_Load_PS_Names( TT_Face face,
TT_Post* ppost )
{
PFace faze = HANDLE_Face( face );
TT_Error error;
TT_Stream stream;
TT_Post* post;
if ( !faze )
return TT_Err_Invalid_Face_Handle;
error = TT_Extension_Get( faze, POST_ID, (void**)&post );
if ( error )
return error;
if ( USE_Stream( faze->stream, stream ) )
return error;
switch ( faze->postscript.FormatType )
{
case 0x00010000:
error = TT_Err_Ok; /* nothing to do */
break;
case 0x00020000:
if ( FILE_Seek( post->offset ) )
goto Fail;
error = Load_Format_20( &post->p.post20, faze );
break;
case 0x00028000: /* 2.5 in 16.16 format */
if ( FILE_Seek( post->offset ) )
goto Fail;
error = Load_Format_25( &post->p.post25, faze );
break;
case 0x00030000:
error = TT_Err_Ok; /* nothing to do */
break;
#if 0
case 0x00040000:
break;
#endif
default:
error = TT_Err_Invalid_Post_Table_Format;
break;
}
if ( !error )
{
post->loaded = TRUE;
*ppost = *post;
}
Fail:
DONE_Stream( stream );
return error;
}
/*******************************************************************
*
* Function : TT_Get_PS_Name
*
* Description : Gets the PostScript Glyph Name of a glyph.
*
* Input : index glyph index
* PSname address of a string pointer.
* Will be NULL in case of error; otherwise it
* contains a pointer to the glyph name.
*
* You must not modify the returned string!
*
* Output : error code
*
******************************************************************/
EXPORT_FUNC
TT_Error TT_Get_PS_Name( TT_Face face,
TT_UShort index,
TT_String** PSname )
{
PFace faze = HANDLE_Face( face );
TT_Error error;
TT_Post* post;
UShort nameindex;
if ( !faze )
return TT_Err_Invalid_Face_Handle;
if ( index >= faze->numGlyphs )
return TT_Err_Invalid_Glyph_Index;
error = TT_Extension_Get( faze, POST_ID, (void**)&post );
if ( error )
return error;
*PSname = TT_Post_Default_Names[0]; /* default value */
switch ( faze->postscript.FormatType )
{
case 0x00010000:
if ( index < 258 ) /* paranoid checking */
*PSname = TT_Post_Default_Names[index];
break;
case 0x00020000:
if ( index < post->p.post20.numGlyphs )
nameindex = post->p.post20.glyphNameIndex[index];
else
break;
if ( nameindex < 258 )
*PSname = TT_Post_Default_Names[nameindex];
else
*PSname = (String*)post->p.post20.glyphNames[nameindex - 258];
break;
case 0x00028000:
if ( index < post->p.post25.numGlyphs ) /* paranoid checking */
*PSname = TT_Post_Default_Names[index + post->p.post25.offset[index]];
break;
case 0x00030000:
break; /* nothing to do */
#if 0
case 0x00040000:
break;
#endif
default:
; /* should never happen */
}
return TT_Err_Ok;
}
/* END */

107
lib/extend/ftxpost.h Normal file
View File

@@ -0,0 +1,107 @@
/*******************************************************************
*
* ftxpost.h
*
* post table support API extension
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* The post table is not completely loaded by the core engine. This
* file loads the missing PS glyph names and implements an API to
* access them.
*
******************************************************************/
#ifndef FTXPOST_H
#define FTXPOST_H
#include "freetype.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TT_Err_Invalid_Post_Table_Format 0x0B00
#define TT_Err_Invalid_Post_Table 0x0B01
/* the 258 standard Mac glyph names, used for format 1.0 and 2.5 */
extern TT_String* TT_Post_Default_Names[];
/* format 2.0 table */
struct TT_Post_20_
{
TT_UShort numGlyphs;
TT_UShort* glyphNameIndex;
TT_Char** glyphNames;
};
typedef struct TT_Post_20_ TT_Post_20;
struct TT_Post_25_
{
TT_UShort numGlyphs;
TT_Char* offset;
};
typedef struct TT_Post_25_ TT_Post_25;
#if 0
/* format 4.0 table -- not implemented yet */
struct TT_Post_40_
{
};
typedef struct TT_Post_40_ TT_Post_40;
#endif
struct TT_Post_
{
TT_Long offset;
TT_Long length;
TT_Bool loaded;
union
{
TT_Post_20 post20;
TT_Post_25 post25;
#if 0
TT_Post_40 post40;
#endif
} p;
};
typedef struct TT_Post_ TT_Post;
EXPORT_DEF
TT_Error TT_Init_Post_Extension( TT_Engine engine );
EXPORT_DEF
TT_Error TT_Load_PS_Names( TT_Face face,
TT_Post* post );
EXPORT_DEF
TT_Error TT_Get_PS_Name( TT_Face face,
TT_UShort index,
TT_String** PSname );
#ifdef __cplusplus
}
#endif
#endif /* FTXPOST_H */
/* END */

1391
lib/extend/ftxsbit.c Normal file

File diff suppressed because it is too large Load Diff

490
lib/extend/ftxsbit.h Normal file
View File

@@ -0,0 +1,490 @@
/*******************************************************************
*
* ftxsbit.h
*
* embedded bitmap support API extension
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* This extension is used to load the embedded bitmaps present
* in certain TrueType files.
*
******************************************************************/
#ifndef FTXSBIT_H
#define FTXSBIT_H
#include "freetype.h"
#ifdef __cplusplus
extern "C" {
#endif
/*************************************************************/
/* */
/* <Struct> TT_SBit_Metrics */
/* */
/* <Description> */
/* A structure used to hold the big metrics of a given */
/* glyph bitmap in a TrueType or OpenType font. These */
/* are usually found in the `EBDT' table. */
/* */
/* <Fields> */
/* height :: glyph height in pixels */
/* width :: glyph width in pixels */
/* */
/* horiBearingX :: horizontal left bearing */
/* horiBearingY :: horizontal top bearing */
/* horiAdvance :: horizontal advance */
/* */
/* vertBearingX :: vertical left bearing */
/* vertBearingY :: vertical top bearing */
/* vertAdvance :: vertical advance */
/* */
typedef struct TT_SBit_Metrics_
{
TT_Byte height;
TT_Byte width;
TT_Char horiBearingX;
TT_Char horiBearingY;
TT_Byte horiAdvance;
TT_Char vertBearingX;
TT_Char vertBearingY;
TT_Byte vertAdvance;
} TT_SBit_Metrics;
/*************************************************************/
/* */
/* <Struct> TT_SBit_Small_Metrics */
/* */
/* <Description> */
/* A structure used to hold the small metrics of a given */
/* glyph bitmap in a TrueType or OpenType font. These */
/* are usually found in the `EBDT' table. */
/* */
/* <Fields> */
/* height :: glyph height in pixels */
/* width :: glyph width in pixels */
/* */
/* bearingX :: left-side bearing */
/* bearingY :: top-side bearing */
/* advance :: advance width or height */
/* */
typedef struct TT_SBit_Small_Metrics_
{
TT_Byte height;
TT_Byte width;
TT_Char bearingX;
TT_Char bearingY;
TT_Byte advance;
} TT_SBit_Small_Metrics;
/*************************************************************/
/* */
/* <Struct> TT_SBit_Line_Metrics */
/* */
/* <Description> */
/* A structure used to describe the text line metrics of */
/* a given bitmap strike, for either horizontal or */
/* vertical layout. */
/* */
/* <Fields> */
/* ascender :: ascender in pixels */
/* descender :: descender in pixels */
/* max_width :: maximum glyph width in pixels */
/* */
/* caret_slope_enumerator :: Rise of the caret slope, */
/* typically set to 1 for non-italic fonts. */
/* caret_slope_denominator :: Rise of the caret slope, */
/* typically set to 0 for non-italic fonts. */
/* caret_offset :: Offset in pixels */
/* to move the caret for proper positioning. */
/* */
/* min_origin_SB :: Minimum of horiBearingX */
/* (resp. vertBearingY) */
/* min_advance_SB :: Minimum of */
/* (hori. advance - ( horiBearingX + width )) */
/* (resp. vert. advance - ( vertBearingY + height )) */
/* max_before_BL :: Maximum of horiBearingY */
/* (resp. Maximum of vertBearingY) */
/* min_after_BL :: Minimum of ( horiBearingY - height ) */
/* (resp. vertBearingX - width ) */
/* */
typedef struct TT_SBit_Line_Metrics_
{
TT_Char ascender;
TT_Char descender;
TT_Byte max_width;
TT_Char caret_slope_numerator;
TT_Char caret_slope_denominator;
TT_Char caret_offset;
TT_Char min_origin_SB;
TT_Char min_advance_SB;
TT_Char max_before_BL;
TT_Char min_after_BL;
TT_Char pads[2];
} TT_SBit_Line_Metrics;
/*************************************************************/
/* */
/* <Struct> TT_SBit_Range */
/* */
/* <Description> */
/* A TrueType/OpenType subIndexTable as defined in the */
/* `EBLC' or `bloc' tables. */
/* */
/* <Fields> */
/* */
/* first_glyph :: first glyph index in range */
/* last_glyph :: last glyph index in range */
/* */
/* index_format :: format of index table. valid */
/* values are 1 to 5. */
/* */
/* image_format :: format of `EBDT' image data */
/* image_offset :: offset to image data in `EBDT' */
/* */
/* image_size :: for index formats 2 and 5. This is */
/* the size in bytes of each glyph bitmap */
/* glyph bitmap */
/* */
/* big_metrics :: for index formats 2 and 5. This is */
/* the big metrics for each glyph bitmap */
/* */
/* num_glyphs :: for index formats 4 and 5. This is */
/* the number of glyphs in the code */
/* array. */
/* */
/* glyph_offsets :: for index formats 1 and 3. */
/* glyph_codes :: for index formats 4 and 5. */
/* */
/* table_offset :: offset of index table in `EBLC' table */
/* -- only used during strike loading. */
/* */
typedef struct TT_SBit_Range
{
TT_UShort first_glyph;
TT_UShort last_glyph;
TT_UShort index_format;
TT_UShort image_format;
TT_ULong image_offset;
TT_ULong image_size;
TT_SBit_Metrics metrics;
TT_ULong num_glyphs;
TT_ULong* glyph_offsets;
TT_UShort* glyph_codes;
TT_ULong table_offset;
} TT_SBit_Range;
/*************************************************************/
/* */
/* <Struct> TT_SBit_Strike */
/* */
/* <Description> */
/* A structure used describe a given bitmap strike in the */
/* `EBLC' or `bloc' tables. */
/* */
/* <Fields> */
/* */
/* num_index_ranges :: number of index ranges */
/* index_ranges :: array of glyph index ranges */
/* */
/* color_ref :: unused. color reference? */
/* hori :: line metrics for horizontal layouts. */
/* vert :: line metrics for vertical layouts. */
/* */
/* start_glyph :: lowest glyph index for this strike. */
/* end_glyph :: higher glyph index for this strike. */
/* */
/* x_ppem :: horizontal pixels per EM */
/* y_ppem :: vertical pixels per EM */
/* bit_depth :: bit depth. valid values are 1, 2, 4 & 8 */
/* flags :: vertical or horizontal? */
/* */
typedef struct TT_SBit_Strike_
{
TT_Int num_ranges;
TT_SBit_Range* sbit_ranges;
TT_ULong ranges_offset;
TT_ULong color_ref;
TT_SBit_Line_Metrics hori;
TT_SBit_Line_Metrics vert;
TT_UShort start_glyph;
TT_UShort end_glyph;
TT_Byte x_ppem;
TT_Byte y_ppem;
TT_Byte bit_depth;
TT_Char flags;
} TT_SBit_Strike;
/*************************************************************/
/* */
/* <Struct> TT_SBit_Component */
/* */
/* <Description> */
/* A simple structure to describe a compound sbit element */
/* */
/* <Fields> */
/* glyph_code :: element's glyph index */
/* x_offset :: element's left bearing */
/* y_offset :: element's top bearing */
/* */
typedef struct TT_SBit_Component_
{
TT_UShort glyph_code;
TT_Char x_offset;
TT_Char y_offset;
} TT_SBit_Component;
/*************************************************************/
/* */
/* <Struct> TT_SBit_Scale */
/* */
/* <Description> */
/* A structure used describe a given bitmap scaling */
/* table, as defined for the `EBSC' table. */
/* */
/* <Fields> */
/* hori :: horizontal line metrics */
/* vert :: vertical line metrics */
/* */
/* x_ppem :: horizontal pixels per EM */
/* y_ppem :: vertical pixels per EM */
/* */
/* x_ppem_substitute :: substitution x_ppem */
/* y_ppem_substitute :: substitution y_ppem */
/* */
typedef struct TT_SBit_Scale_
{
TT_SBit_Line_Metrics hori;
TT_SBit_Line_Metrics vert;
TT_Byte x_ppem;
TT_Byte y_ppem;
TT_Byte x_ppem_substitute;
TT_Byte y_ppem_substitute;
} TT_SBit_Scale;
/*************************************************************/
/* */
/* <Struct> TT_SBit_Image */
/* */
/* <Description> */
/* A structure used to describe a given embedded bitmap */
/* image. */
/* */
/* <Fields> */
/* map :: bitmap descriptor */
/* bit_depth :: pixel bit depth */
/* metrics :: glyph metrics for the bitmap */
/* */
typedef struct TT_SBit_Image_
{
TT_Raster_Map map;
int bit_depth;
TT_Big_Glyph_Metrics metrics;
} TT_SBit_Image;
/*************************************************************/
/* */
/* <Struct> TT_EBLC */
/* */
/* <Description> */
/* A structure used to describe the `EBLC' table from */
/* a TrueType font. */
/* */
/* <Fields> */
/* version :: version number of the EBLC table */
/* */
/* num_strikes :: the number of strikes, i.e. bitmap */
/* sizes, present in this font */
/* */
/* strikes :: array of strikes */
/* */
typedef struct TT_EBLC_
{
TT_ULong version;
TT_ULong num_strikes;
TT_SBit_Strike* strikes;
} TT_EBLC;
/*************************************************************/
/* */
/* <Function> */
/* TT_Init_SBit_Extension */
/* */
/* <Description> */
/* Initializes the embedded bitmap extension for the */
/* FreeType engine. */
/* */
/* <Input> */
/* engine :: handle to current FreeType library instance */
/* */
/* <Return> */
/* Error code. 0 means success. */
/* */
EXPORT_DEF
TT_Error TT_Init_SBit_Extension( TT_Engine engine );
/*************************************************************/
/* */
/* <Function> */
/* TT_Get_Face_Bitmaps */
/* */
/* <Description> */
/* Loads the `EBLC' table from a font file, if any. */
/* */
/* <Input> */
/* face :: handle to the source TrueType font/face */
/* */
/* <Output> */
/* eblc_table :: a descriptor for the EBLC table */
/* */
/* <Return> */
/* Error code. 0 means success. */
/* */
/* <Note> */
/* This function returns TT_Err_Table_Missing if the */
/* font contains no embedded bitmaps. All fields in */
/* `eblc_table' will then be set to 0. */
/* */
EXPORT_DEF
TT_Error TT_Get_Face_Bitmaps( TT_Face face,
TT_EBLC* eblc_table );
/*************************************************************/
/* */
/* <Function> */
/* TT_New_SBit_Image */
/* */
/* <Description> */
/* Allocates a new embedded bitmap container. */
/* */
/* <Output> */
/* image :: sbit image */
/* */
/* <Return> */
/* Error code. 0 means success. */
/* */
EXPORT_DEF
TT_Error TT_New_SBit_Image( TT_SBit_Image** image );
/*************************************************************/
/* */
/* <Function> */
/* TT_Done_SBit_Image */
/* */
/* <Description> */
/* Releases an embedded bitmap container. */
/* */
/* <Input> */
/* image :: sbit image */
/* */
EXPORT_DEF
void TT_Done_SBit_Image( TT_SBit_Image* image );
/*************************************************************/
/* */
/* <Function> TT_Get_SBit_Strike */
/* */
/* <Description> */
/* Loads a suitable strike (bitmap sizetable) for the */
/* given instance. This strike includes */
/* sbitLineMetrics. */
/* */
/* <Input> */
/* face :: the source face */
/* instance :: the current size instance */
/* */
/* <Output> */
/* strike :: the bitmap strike descriptor */
/* */
/* <Return> */
/* Error code. 0 means success. */
/* */
EXPORT_DEF
TT_Error TT_Get_SBit_Strike( TT_Face face,
TT_Instance instance,
TT_SBit_Strike* strike );
/*************************************************************/
/* */
/* <Function> */
/* TT_Load_Glyph_Bitmap */
/* */
/* <Description> */
/* Loads a given glyph embedded bitmap. */
/* */
/* <Input> */
/* face :: handle to the source TrueType font/face */
/* instance :: current size/transform instance */
/* glyph_index :: index of source glyph */
/* bitmap :: target embedded bitmap descriptor */
/* */
/* <Return> */
/* Error code. 0 means success. */
/* */
/* <Note> */
/* This function returns an error if there is no */
/* embedded bitmap for the glyph at the given */
/* instance. */
/* */
EXPORT_DEF
TT_Error TT_Load_Glyph_Bitmap( TT_Face face,
TT_Instance instance,
TT_UShort glyph_index,
TT_SBit_Image* bitmap );
#ifdef __cplusplus
}
#endif
#endif /* FTXSBIT_H */
/* END */

185
lib/extend/ftxwidth.c Normal file
View File

@@ -0,0 +1,185 @@
/*******************************************************************
*
* ftxwidth.c 1.0
*
* Glyph Widths (and Heights) fast retrieval extension
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* This extension is used to parse the "glyf" table of a TrueType
* file in order to extract the bbox of a given range of glyphs.
*
* The bbox is then used to build font unit widths and height
* that are returned in two parallel arrays.
*
* This extension is needed by the FreeType/2 OS/2 Font Driver.
*
******************************************************************/
#include "ftxwidth.h"
#include "ttdebug.h"
#include "ttobjs.h"
#include "ttfile.h"
#include "tttags.h"
#include "ttload.h"
/* Required by the tracing mode */
#undef TT_COMPONENT
#define TT_COMPONENT trace_any
/******************************************************************/
/* */
/* Function: TT_Get_Face_Widths */
/* */
/* Description: Returns the widths and/or heights of a given */
/* range of glyphs for a face. */
/* */
/* Input: */
/* face :: face handle */
/* */
/* first_glyph :: first glyph in range */
/* */
/* last_glyph :: last glyph in range */
/* */
/* widths :: address of table receiving the widths */
/* expressed in font units (ushorts). Set */
/* this parameter to NULL if you're not */
/* interested by these values. */
/* */
/* heights :: address of table receiving the heights */
/* expressed in font units (ushorts). Set */
/* this parameter to NULL if you're not */
/* interested by these values. */
/* */
/* Returns: */
/* Error code */
/* */
/* */
/******************************************************************/
EXPORT_FUNC
TT_Error TT_Get_Face_Widths( TT_Face face,
TT_UShort first_glyph,
TT_UShort last_glyph,
TT_UShort* widths,
TT_UShort* heights )
{
DEFINE_ALL_LOCALS;
PFace faze = HANDLE_Face(face);
UShort n;
Long table;
ULong glyf_offset; /* offset of glyph table in file */
UShort zero_width = 0; /* width of glyph 0 */
UShort zero_height = 0; /* height of glyph 0 */
Bool zero_loaded = 0;
#ifndef TT_HUGE_PTR
PStorage locations;
#else
Storage TT_HUGE_PTR * locations;
#endif
TT_BBox bbox;
if ( !faze )
return TT_Err_Invalid_Face_Handle;
if ( last_glyph >= faze->numGlyphs ||
first_glyph > last_glyph )
return TT_Err_Invalid_Argument;
/* find "glyf" table */
table = TT_LookUp_Table( faze, TTAG_glyf );
if ( table < 0 )
{
PERROR(( "ERROR: there is no glyph table in this font file!\n" ));
return TT_Err_Glyf_Table_Missing;
}
glyf_offset = faze->dirTables[table].Offset;
/* now access stream */
if ( USE_Stream( faze->stream, stream ) )
return error;
locations = faze->glyphLocations + first_glyph;
/* loop to load each glyph in the range */
for ( n = first_glyph; n <= last_glyph; n++ )
{
if ( n + 1 < faze->numGlyphs &&
locations[0] == locations[1] )
{
/* Note : Glyph 0 is always used to indicate a missing glyph */
/* in a range. We must thus return its width and height */
/* where appropriate when we find an undefined glyph. */
if ( zero_loaded == 0 )
{
if ( FILE_Seek( glyf_offset + faze->glyphLocations[0] ) ||
ACCESS_Frame( 10L ) )
goto Fail;
(void)GET_Short(); /* skip number of contours */
bbox.xMin = GET_Short();
bbox.yMin = GET_Short();
bbox.xMax = GET_Short();
bbox.yMax = GET_Short();
FORGET_Frame();
zero_width = (UShort)(bbox.xMax - bbox.xMin);
zero_height = (UShort)(bbox.yMax - bbox.yMin);
zero_loaded = 1;
}
if ( widths )
*widths++ = zero_width;
if ( heights )
*heights++ = zero_height;
}
else
{
/* normal glyph, read header */
if ( FILE_Seek( glyf_offset + locations[0] ) ||
ACCESS_Frame( 10L ) )
goto Fail;
(void)GET_Short(); /* skip number of contours */
bbox.xMin = GET_Short();
bbox.yMin = GET_Short();
bbox.xMax = GET_Short();
bbox.yMax = GET_Short();
FORGET_Frame();
if ( widths )
*widths++ = (UShort)(bbox.xMax - bbox.xMin);
if ( heights )
*heights++ = (UShort)(bbox.yMax - bbox.yMin);
}
}
Fail:
DONE_Stream( stream );
return error;
}
/* END */

80
lib/extend/ftxwidth.h Normal file
View File

@@ -0,0 +1,80 @@
/*******************************************************************
*
* ftxwidth.h
*
* Glyph Widths (and Heights) fast retrieval extension.
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* This extension is used to parse the `glyf' table of a TrueType
* file in order to extract the bounding box of a given range of glyphs.
*
* The bounding box is then used to build font unit widths and heights
* that are returned in two parallel arrays.
*
* This extension is needed by the FreeType/2 OS/2 Font Driver.
*
******************************************************************/
#ifndef FTXWIDTH_H
#define FTXWIDTH_H
#include "freetype.h"
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************/
/* */
/* Function: TT_Get_Face_Widths */
/* */
/* Description: Returns the widths and/or heights of a given */
/* range of glyphs for a face. */
/* */
/* Input: */
/* face :: face handle */
/* */
/* first_glyph :: first glyph in range */
/* */
/* last_glyph :: last glyph in range */
/* */
/* widths :: address of table receiving the widths */
/* expressed in font units (ushorts). Set */
/* this parameter to NULL if you're not */
/* interested by these values. */
/* */
/* heights :: address of table receiving the heights */
/* expressed in font units (ushorts). Set */
/* this parameter to NULL if you're not */
/* interested by these values */
/* */
/* Returns: */
/* Error code */
/* */
/* */
/******************************************************************/
EXPORT_DEF
TT_Error TT_Get_Face_Widths( TT_Face face,
TT_UShort first_glyph,
TT_UShort last_glyph,
TT_UShort* widths,
TT_UShort* heights );
#ifdef __cplusplus
}
#endif
#endif /* FTXWIDTH_H */
/* END */

61
lib/extend/readme.1st Normal file
View File

@@ -0,0 +1,61 @@
This directory contains several extensions to the core engine.
An extension is a separately compilable unit which can be linked by
a client application to add new functionalities to the engine.
There are two kinds of extensions: an `API extension' provides
clients with new APIs to access internal engine structures or data,
while an `engine extension' implements new TrueType data or table
management.
This directory contains the following:
ftxcmap: An API extension to iterate over cmaps.
ftxgasp: A simple API extension which returns the TrueType `gasp'
table to client applications, when found in a font file.
Though this table is always loaded by the engine, there
is no function in the core API to access it. The reason
is simple: to demonstrate a simple API extension with
`ftxgasp'!
ftxkern: This engine extension is used to access kerning data,
when available in a font file. Note that it implements
on-the-fly loading and retrieving of kerning tables.
However, it doesn't interpret or process the data, and
client applications should use it according to the
TrueType specification.
ftxpost: An engine extension to load the PostScript glyph names
of the `post' table. See the `ftzoom' program for an
example how to use it.
ftxwidth: A simple extension used to load the widths and heights
of a given range of glyphs in a face. Results are
expressed in unscaled font units. This is required by
the latest version of the FreeType/2 DLL to speed up
font loading in the GRE (the OS/2 GRaphics Engine). It
can be used by other applications though...
ftxerr18: This extension simply converts a TrueType engine error
code into a corresponding string describing the error.
It is useful if you intend to write a package for end
users and want to give them not `Error code 135' but
`OS/2 table missing'. See docs/errstr.txt for a
description how to use it (really simple!). ftxerr18
supports localization of error strings (that is: error
strings are automatically translated into supported
languages) using gettext(). See docs/i18n.txt about
using gettext.
ftxsbit: Embedded bitmap support. This is an engine extension.
See e.g. the `ftstrtto' program for its usage.
ftxopen,
ftxgsub,
ftxgpos,
ftxgdef: This is experimental stuff for TrueType Open support!
Please ignore it or help debugging :-)
--- END ---