Compare commits

...

57 Commits

Author SHA1 Message Date
Parth Wazurkar b064189c94 [gf] Improve tracing. 2018-08-11 02:22:23 +05:30
Parth Wazurkar b54503a256 [gf] Allocate bitmap in `GF_Glyph_Load' itself. 2018-08-10 20:23:28 +05:30
Parth Wazurkar 7ea68ac9f3 [gf] Change logic to load bitmap on demand.
Also load glyphs in the order they appear in the font
file by changing the cmap scheme and implementing a
proper `gf cmap'.
2018-08-10 00:54:24 +05:30
Parth Wazurkar 44d9f10ac8 [gf, pk] Change some data types to `signed' type.
* src/gf/gfdrivr.h(GF_GlyphRec): Do it.
* src/pk/pkdrivr.h(PK_GlyphRec): Ditto.
2018-08-07 19:44:01 +05:30
Parth Wazurkar 5485407707 [gf, pk] Resolve *glyph jumping* error.
* src/gf/gfdrivr.c(GF_Load_Glyph): Modify glyph metric values
to resolve the *glyph jumping* error and make the glyphs to
properly sit on baseline.

* src/pk/pkdrivr.c(PK_Glyph_Load): Ditto.
2018-08-07 19:38:26 +05:30
Parth Wazurkar ad0453fd39 [gf, pk] Improve `attach_file' functions. 2018-08-05 17:02:09 +05:30
Parth Wazurkar d93d4f6b34 [tfm] Improve error checking for `tfm' files. 2018-08-05 17:00:01 +05:30
Parth Wazurkar 82571dc2c7 [tfm] Improve `tfm_interface' definitions. 2018-08-05 16:57:35 +05:30
Parth Wazurkar ca9e387ccb [tfm] Improve data types of variables in `TFM_FontInfoRec' 2018-08-05 16:54:50 +05:30
Parth Wazurkar dddc46b0b8 [pk] Fixes.
* Now pk driver loads bitmaps properly and ftview
displays proper glyphs from pk driver.
2018-08-02 00:48:05 +05:30
Parth Wazurkar 1b16b2267e Fix `printf' statements. 2018-08-02 00:47:30 +05:30
Parth Wazurkar 7236cde177 Make branch even for testing.
* For testing modifications to gf, pk and tfm modules.
2018-08-01 01:30:06 +05:30
Parth Wazurkar 62a92ff723 [gf] Cleanup commit.
* Rename `gf' files' header.
* Remove all the unnecessary typedefs and
switch to FT specific ones.
* Remove unnecessary comments.
2018-07-20 16:49:55 +05:30
Parth Wazurkar cde0317724 [gf] Register gf services. 2018-07-20 16:49:45 +05:30
Parth Wazurkar 88ca39830e [gf] Create gf services.
* src/gf/gfdrivr.c: Define gf services descriptor
table and `gf_driver_requestor' function.
2018-07-20 16:49:37 +05:30
Parth Wazurkar eaa830405e [gf] Robustify.
* src/gf/gflib.c (gf_load_font): Add check
for GF_ID and GF_PRE commands to improve
test for `gf' files.
2018-07-20 16:49:24 +05:30
Parth Wazurkar ed698a3b3b [gf] Minor Fixes. 2018-07-20 16:49:13 +05:30
Parth Wazurkar 7635ca9624 [tfm] Fixes. 2018-07-17 21:01:53 +05:30
Parth Wazurkar a5e988fe32 [gf] Add support for parsing `xxx' and `yyy' commands.
* Now gf driver supports all the font files.
* Currently `xxx'and `yyy' commands if found after the
postamble are skipped over.
* Mechanism for extracting information from these commands
is to be added.
2018-07-12 20:13:22 +05:30
Parth Wazurkar 6cfd41681f [gf] Fixes.
* Make even with `parthw-cleaned' branch.
2018-07-12 17:00:18 +05:30
Parth Wazurkar f2120af34b [tfm] Add tfm_driver_class functions.
Note: Does not compile.
* src/tfm/tfmdrivr.c: Add TFM_Face_Done, TFM_Face_Init,
TFM_Glyph_Load, TFM_Size_Request and TFM_Size_Select
functions.
2018-07-12 16:50:07 +05:30
Parth Wazurkar 5b74836c7a [tfm] Fixes. 2018-07-10 16:36:30 +05:30
Parth Wazurkar 11f4cadddd [gf] Preliminary tracing and error handling support and minor fixes. 2018-07-04 15:33:57 +05:30
Parth Wazurkar 20c2358230 minor. 2018-07-03 01:57:10 +05:30
Parth Wazurkar 472155eac2 [gf] Fixes. 2018-07-03 01:57:10 +05:30
Parth Wazurkar a57dda6564 [gf] Resolve compiler flag errors.
* src/gf/gflib.c: Remove all the unused variables,
add error checking for all the stream functions which
were raising compiler flag warnings.

* src/gf/gfdrivr.c: Remove unused variables.
2018-07-03 01:57:10 +05:30
Parth Wazurkar 7870984ea1 [tfm] Minor. 2018-07-03 01:57:10 +05:30
Parth Wazurkar 3c555bf991 [tfm] Define TFM_FaceRec and other format specific structures.
* src/tfm/tfmdrivr.h: Define TFM_FaceRec also define
TFM_GlyphRec structure to properly distinguish format
specific values.
2018-07-03 01:57:10 +05:30
Parth Wazurkar a16b3b2199 [tfm] FT stream support for tfm driver.
* src/tfm/tfmlib.c : Convert all the file functions to
FT stream functions.
2018-07-03 01:57:10 +05:30
Parth Wazurkar 4c1f8627bf [tfm] Remove VFlib specific code and refactor to FT. 2018-07-03 01:57:10 +05:30
Parth Wazurkar 67d3c53dcd [tfm] Archive code for other font metric formats.
* src/tfm/tfmlib.c: Archive code for Omega Font metric(OFM),
Japanese Font Metric(JFM), font formats.
2018-07-03 01:57:10 +05:30
Parth Wazurkar 39375424d9 [tfm] Define tfm_cmap_class functions.
* Define structure TFM_CMapRec for TeX tfm font format.
* src/tfm/tfmdrivr.c: Define tfm_cmap_init, tfm_cmap_done,
tfm_cmap_char_index, tfm_cmap_char_next.
2018-07-03 01:57:10 +05:30
Parth Wazurkar 90624af017 [gf] Add printf flags for debugging. 2018-07-03 01:57:10 +05:30
Parth Wazurkar 86cc6cbd40 [gf] Changes. 2018-07-03 01:57:10 +05:30
Parth Wazurkar 5585c5f365 [gf] Minor changes. 2018-07-03 01:57:10 +05:30
Parth Wazurkar 0532670c02 [gf] Complete stream support and some minor changes for testing. 2018-07-03 01:57:10 +05:30
Parth Wazurkar 2bea8dbd49 Minor changes for testing. 2018-07-03 01:57:10 +05:30
Parth Wazurkar e69e7e492a [tfm] Add preliminary functions and structures.
* Added tfm specific functions and structures for the driver
(To be modified).
2018-07-03 01:57:10 +05:30
Parth Wazurkar e7c95039f5 [gf] COnverted file functions to FT stream functions.
* src/gf/gflib.c : Converted all the file functions like getc,
fseek,etc. to FT specific stream functions.
2018-07-03 01:57:09 +05:30
Parth Wazurkar 1338d517c4 [tfm] Initialised TFM driver files.
* src/tfm : Added all the driver source files and makefiles.
2018-07-03 01:57:09 +05:30
Parth Wazurkar 5147064e1b [gf] Temporary changes for compiling gf driver. 2018-07-03 01:57:09 +05:30
Parth Wazurkar 3ff144c5d9 [gf] Convert block comments to `light' style in gf files. 2018-07-03 01:57:09 +05:30
Parth Wazurkar 781a67cb82 [gf] Changes. 2018-07-03 01:57:09 +05:30
Parth Wazurkar 59f6af025d [gf] Changed to FT data types in structures.
* src/gf/gfdrivr.h: Changed data types in GF_FaceRec, Gf_GlyphRec and GF_BitmapRec to FT data types.
2018-07-03 01:57:09 +05:30
Parth Wazurkar 56b81c93f0 [gf] * src/gf/gfdrivr.c: Added GF_Face_Init, GF_Face_Done and GF_Glyph_Load functions. 2018-07-03 01:57:09 +05:30
Parth Wazurkar f920b5f345 [gf] Removed VFlib specific code and refactored to FT. 2018-07-03 01:57:09 +05:30
Parth Wazurkar 265cc448fd [gf] Added GF_Size_Request and GF_Size_Select functions. 2018-07-03 01:57:09 +05:30
Parth Wazurkar 577efd8f17 [gf] Minor changes to Makefiles to accomodate GF Driver.
* modules.cfg: Added gf font driver module.
* src/gf/module.mk: Minor changes.
2018-07-03 01:57:09 +05:30
Parth Wazurkar 48e21b7681 [gf] * src/gf/gf.c: Added source files for single build 2018-07-03 01:57:09 +05:30
Parth Wazurkar 846f20ac9d [gf] Removed indentation errors. 2018-07-03 01:57:09 +05:30
Parth Wazurkar ba5757b415 [gf] Added Makefiles.
-Initialised module.mk and rules.mk.
2018-07-03 01:57:09 +05:30
Parth Wazurkar 126c1e58e9 [gf] Initialised internal utility functions specific to GF format.
* src/gf/gf.h Added some required definitions.
* src/gf/gflib.c Added gf_font_load, gf_read_glyph, gf_font_done functions.
2018-07-03 01:57:09 +05:30
Parth Wazurkar 9de5de08ab [gf] *src/gf/gfdrivr.h Defined GF_FaceRec and other format specific structures.
- Defined GF_FaceRec.
- Defined GF_BitmapRec and GF_Glyph structures to properly distinguish format specific values.
2018-07-03 01:57:09 +05:30
Parth Wazurkar d40152c275 [gf] *src/gf/gfdrivr.c defined gf_cmap_class functions
- Defined structure GF_CMapRec for gf font format.
- Implemented gf_cmap_init, gf_cmap_done, gf_cmap_char_index, gf_cmap_char_next.
2018-07-03 01:57:09 +05:30
Parth Wazurkar af1a80cdd3 [gf] Added gf.c 2018-07-03 01:57:09 +05:30
Parth Wazurkar 43b840d6c2 [gf] Initialised gf driver files
gf driver files are initialised. Macros required for gf font files are determined in gf.h file.
2018-07-03 01:57:09 +05:30
Parth Wazurkar dfe1bdc246 *src added gf driver repository
This repository contains the driver for gf font format.
2018-07-03 01:57:09 +05:30
46 changed files with 4097 additions and 25 deletions

View File

@ -457,7 +457,7 @@ FT_BEGIN_HEADER
#ifdef FT2_BUILD_LIBRARY
#if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) )
#if defined( _WIN32 ) && defined( DLL_EXPORT )
#define FT_EXPORT( x ) __declspec( dllexport ) x
#elif defined( __GNUC__ ) && __GNUC__ >= 4
#define FT_EXPORT( x ) __attribute__(( visibility( "default" ) )) x
@ -471,7 +471,7 @@ FT_BEGIN_HEADER
#else
#if defined( FT2_DLLIMPORT )
#if defined( _WIN32 ) && defined( DLL_IMPORT )
#define FT_EXPORT( x ) __declspec( dllimport ) x
#elif defined( __cplusplus )
#define FT_EXPORT( x ) extern "C" x

View File

@ -28,5 +28,6 @@ FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class )
FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class )
FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class )
FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class )
FT_USE_MODULE( FT_Driver_ClassRec, gf_driver_class )
/* EOF */

View File

@ -413,8 +413,8 @@ FT_BEGIN_HEADER
* Do not #undef these macros here since the build system might define
* them for certain configurations only.
*/
/* #define FT_DEBUG_LEVEL_ERROR */
/* #define FT_DEBUG_LEVEL_TRACE */
#define FT_DEBUG_LEVEL_ERROR
#define FT_DEBUG_LEVEL_TRACE
/**************************************************************************

View File

@ -642,7 +642,8 @@ FT_BEGIN_HEADER
*
* @values:
* FT_ENCODING_NONE ::
* The encoding value~0 is reserved.
* The encoding value~0 is reserved for all formats except BDF, PCF,
* and Windows FNT; see below for more information.
*
* FT_ENCODING_UNICODE ::
* The Unicode character set. This value covers all versions of

View File

@ -195,27 +195,31 @@ FT_BEGIN_HEADER
* FT_Module_Class
*
* @description:
* The module class descriptor.
* The module class descriptor. While being a public structure
* necessary for FreeType's module bookkeeping, most of the fields are
* essentially internal, not to be used directly by an application.
*
* @fields:
* module_flags ::
* Bit flags describing the module.
*
* module_size ::
* The size of one module object/instance in
* bytes.
* The size of one module object/instance in bytes.
*
* module_name ::
* The name of the module.
*
* module_version ::
* The version, as a 16.16 fixed number
* (major.minor).
* The version, as a 16.16 fixed number (major.minor).
*
* module_requires ::
* The version of FreeType this module requires,
* as a 16.16 fixed number (major.minor). Starts
* at version 2.0, i.e., 0x20000.
* The version of FreeType this module requires, as a 16.16 fixed
* number (major.minor). Starts at version 2.0, i.e., 0x20000.
*
* module_interface ::
* A typeless pointer to a structure (which varies between different
* modules) that holds the module's interface functions. This is
* essentially what `get_interface' returns.
*
* module_init ::
* The initializing function.

View File

@ -320,7 +320,8 @@ FT_BEGIN_HEADER
*
* cursor ::
* This field is set and used internally by FreeType when parsing
* frames.
* frames. In particular, the `FT_GET_XXX' macros use this instead
* of the `pos' field.
*
* limit ::
* This field is set and used internally by FreeType when parsing

View File

@ -95,7 +95,7 @@ FT_BEGIN_HEADER
* second default codepage that most international versions of
* Windows have. It is one of the OEM codepages from
*
* https://msdn.microsoft.com/en-us/goglobal/bb964655,
* https://docs.microsoft.com/en-us/windows/desktop/intl/code-page-identifiers ,
*
* and is used for the `DOS boxes', to support legacy applications.
* A German Windows version for example usually uses ANSI codepage

View File

@ -462,6 +462,15 @@ FT_BEGIN_HEADER
*
* Use with care!
*/
#define ADD_INT( a, b ) \
(FT_Int)( (FT_UInt)(a) + (FT_UInt)(b) )
#define SUB_INT( a, b ) \
(FT_Int)( (FT_UInt)(a) - (FT_UInt)(b) )
#define MUL_INT( a, b ) \
(FT_Int)( (FT_UInt)(a) * (FT_UInt)(b) )
#define NEG_INT( a ) \
(FT_Int)( (FT_UInt)0 - (FT_UInt)(a) )
#define ADD_LONG( a, b ) \
(FT_Long)( (FT_ULong)(a) + (FT_ULong)(b) )
#define SUB_LONG( a, b ) \

View File

@ -510,6 +510,8 @@ FT_BEGIN_HEADER
#define FT_SERVICE_TRUETYPE_GLYF_H <freetype/internal/services/svttglyf.h>
#define FT_SERVICE_TT_CMAP_H <freetype/internal/services/svttcmap.h>
#define FT_SERVICE_WINFNT_H <freetype/internal/services/svwinfnt.h>
#define FT_SERVICE_GF_H <freetype/internal/services/svgf.h>
#define FT_SERVICE_PK_H <freetype/internal/services/svpk.h>
/* */

View File

@ -165,6 +165,10 @@ FT_BEGIN_HEADER
#define FT_BYTE_U32( p, i, s ) ( FT_UINT32( FT_BYTE_( p, i ) ) << (s) )
/*
* `FT_PEEK_XXX' are generic macros to get data from a buffer position.
* No safety checks are performed.
*/
#define FT_PEEK_SHORT( p ) FT_INT16( FT_BYTE_U16( p, 0, 8 ) | \
FT_BYTE_U16( p, 1, 0 ) )
@ -213,7 +217,10 @@ FT_BEGIN_HEADER
FT_BYTE_U32( p, 1, 8 ) | \
FT_BYTE_U32( p, 0, 0 ) )
/*
* `FT_NEXT_XXX' are generic macros to get data from a buffer position
* which is then increased appropriately. No safety checks are performed.
*/
#define FT_NEXT_CHAR( buffer ) \
( (signed char)*buffer++ )
@ -260,7 +267,11 @@ FT_BEGIN_HEADER
/**************************************************************************
*
* Each GET_xxxx() macro uses an implicit `stream' variable.
* The `FT_GET_XXX' macros use an implicit `stream' variable.
*
* Note that a call to `FT_STREAM_SEEK' or `FT_STREAM_POS' has *no* effect
* on `FT_GET_XXX'! They operate on `stream->pos', while `FT_GET_XXX' use
* `stream->cursor'.
*/
#if 0
#define FT_GET_MACRO( type ) FT_NEXT_ ## type ( stream->cursor )
@ -299,10 +310,18 @@ FT_BEGIN_HEADER
#define FT_GET_ULONG_LE() FT_GET_MACRO( FT_Stream_GetULongLE, FT_ULong )
#endif
#define FT_READ_MACRO( func, type, var ) \
( var = (type)func( stream, &error ), \
error != FT_Err_Ok )
/*
* The `FT_READ_XXX' macros use implicit `stream' and `error' variables.
*
* `FT_READ_XXX' can be controlled with `FT_STREAM_SEEK' and
* `FT_STREAM_POS'. They use the full machinery to check whether a read
* is valid.
*/
#define FT_READ_BYTE( var ) FT_READ_MACRO( FT_Stream_ReadChar, FT_Byte, var )
#define FT_READ_CHAR( var ) FT_READ_MACRO( FT_Stream_ReadChar, FT_Char, var )
#define FT_READ_SHORT( var ) FT_READ_MACRO( FT_Stream_ReadUShort, FT_Short, var )
@ -387,10 +406,10 @@ FT_BEGIN_HEADER
/* Enter a frame of `count' consecutive bytes in a stream. Returns an */
/* error if the frame could not be read/accessed. The caller can use */
/* the FT_Stream_Get_XXX functions to retrieve frame data without */
/* the `FT_Stream_Get_XXX' functions to retrieve frame data without */
/* error checks. */
/* */
/* You must _always_ call FT_Stream_ExitFrame() once you have entered */
/* You must _always_ call `FT_Stream_ExitFrame' once you have entered */
/* a stream frame! */
/* */
FT_BASE( FT_Error )
@ -415,7 +434,7 @@ FT_BEGIN_HEADER
FT_ULong count,
FT_Byte** pbytes );
/* release an extract frame (see FT_Stream_ExtractFrame) */
/* release an extract frame (see `FT_Stream_ExtractFrame') */
FT_BASE( void )
FT_Stream_ReleaseFrame( FT_Stream stream,
FT_Byte** pbytes );

View File

@ -116,6 +116,17 @@ FT_TRACE_DEF( pcfread )
FT_TRACE_DEF( bdfdriver )
FT_TRACE_DEF( bdflib )
/* GF font components */
FT_TRACE_DEF( gfdriver )
FT_TRACE_DEF( gflib )
/* TFM helper module components */
FT_TRACE_DEF( tfmobjs )
/* PK font components */
FT_TRACE_DEF( pkdriver )
FT_TRACE_DEF( pklib )
/* PFR font component */
FT_TRACE_DEF( pfr )

View File

@ -50,6 +50,8 @@
#define FT_INTERNAL_CFF_TYPES_H <freetype/internal/cfftypes.h>
#define FT_INTERNAL_CFF_OBJECTS_TYPES_H <freetype/internal/cffotypes.h>
#define FT_INTERNAL_TFM_H <freetype/internal/tfm.h>
#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */

View File

@ -42,6 +42,8 @@ FT_BEGIN_HEADER
#define FT_FONT_FORMAT_CFF "CFF"
#define FT_FONT_FORMAT_PFR "PFR"
#define FT_FONT_FORMAT_WINFNT "Windows FNT"
#define FT_FONT_FORMAT_GF "GF"
#define FT_FONT_FORMAT_PK "PK"
/* */

View File

@ -0,0 +1,40 @@
/****************************************************************************
*
* svgf.h
*
* The FreeType GF services (specification).
*
* Copyright 2003-2018 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 SVGF_H_
#define SVGF_H_
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_GF "gf"
/* */
FT_END_HEADER
#endif /* SVBDF_H_ */
/* END */

View File

@ -0,0 +1,40 @@
/****************************************************************************
*
* svpk.h
*
* The FreeType PK services (specification).
*
* Copyright 2003-2018 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 SVPK_H_
#define SVPK_H_
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_PK "pk"
/* */
FT_END_HEADER
#endif /* SVPK_H_ */
/* END */

View File

@ -0,0 +1,144 @@
/****************************************************************************
*
* tfm.h
*
* Auxiliary functions and data structures related to TFM metric files
* (specification).
*
* Copyright 1996-2018 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 TFM_H_
#define TFM_H_
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_HASH_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** TFM FONT INFORMATION STRUCTURES ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
typedef struct TFM_FontInfoRec_
{
/* Font Info */
FT_Long cs; /* Check Sum */
/* Metrics */
FT_ULong ds, fs; /* Design Size */
FT_UInt design_size;
FT_ULong slant;
FT_UInt begin_char, end_char;
FT_Long *width, *height, *depth;
/* Font bounding box */
FT_Long font_bbx_w, font_bbx_h;
FT_Long font_bbx_xoff, font_bbx_yoff;
} TFM_FontInfoRec, *TFM_FontInfo;
#define RDS2PT(rds) (tfm->design_size * ((FT_Long)(rds)/(FT_Long)(1<<20)))
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** TFM PARSER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct TFM_ParserRec_* TFM_Parser;
typedef struct TFM_Parser_FuncsRec_
{
FT_Error
(*init)( TFM_Parser parser,
FT_Memory memory,
FT_Stream stream );
FT_Error
(*parse_metrics)( TFM_Parser parser );
void
(*done)( TFM_Parser parser );
} TFM_Parser_FuncsRec;
/**************************************************************************
*
* @struct:
* TFM_ParserRec
*
* @description:
* An TFM_Parser is a parser for the TFM files.
*
* @fields:
* memory ::
* The object used for memory operations (alloc and
* realloc).
*
* stream ::
* This is an FT_Stream object.
*
* FontInfo ::
* The result will be stored here.
*/
typedef struct TFM_ParserRec_
{
FT_Memory memory;
FT_Stream stream;
TFM_FontInfo FontInfo;
void* user_data; /* To be checked for compatibility */
} TFM_ParserRec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** TFM Module Interface *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct TFM_ServiceRec_
{
const TFM_Parser_FuncsRec* tfm_parser_funcs;
} TFM_ServiceRec, *TFM_Service;
/* backward compatible type definition */
typedef TFM_ServiceRec TFM_Interface;
FT_END_HEADER
#endif /* PSAUX_H_ */
/* END */

View File

@ -437,7 +437,7 @@ FT_BEGIN_HEADER
*
* The canonical source for Microsoft's IDs is
*
* https://www.microsoft.com/globaldev/reference/lcid-all.mspx ,
* https://docs.microsoft.com/en-us/windows/desktop/Intl/language-identifier-constants-and-strings ,
*
* however, we only provide macros for language identifiers present in
* the OpenType specification: Microsoft has abandoned the concept of

View File

@ -67,6 +67,12 @@ FONT_MODULES += pcf
# BDF font driver. See optional extension ftbdf.c below also.
FONT_MODULES += bdf
# GF font driver.
FONT_MODULES += gf
# PK font driver.
FONT_MODULES += pk
# SFNT files support. If used without `truetype' or `cff', it supports
# bitmap-only fonts within an SFNT wrapper.
#
@ -137,6 +143,11 @@ AUX_MODULES += bzip2
# This module depends on `psnames'.
AUX_MODULES += psaux
# Auxiliary METAFONT driver component to share common code.
#
# TFM Module.
AUX_MODULES += tfm
# Support for PostScript glyph names.
#
# This module can be controlled in ftconfig.h

View File

@ -40,7 +40,6 @@
FT_Size size = NULL;
FT_Error error;
error = FTC_Manager_LookupFace( manager, scaler->face_id, &face );
if ( error )
goto Exit;
@ -123,7 +122,6 @@
FTC_Scaler scaler = (FTC_Scaler)ftcscaler;
FTC_Manager manager = (FTC_Manager)ftcmanager;
node->scaler = scaler[0];
return ftc_scaler_lookup_size( manager, scaler, &node->size );
@ -321,14 +319,12 @@
/* we break encapsulation for the sake of speed */
#ifdef FTC_INLINE
FTC_MRULIST_LOOKUP_CMP( &manager->faces, face_id, ftc_face_node_compare,
mrunode, error );
#else
error = FTC_MruList_Lookup( &manager->faces, face_id, &mrunode );
#endif
if ( !error )
*aface = FTC_FACE_NODE( mrunode )->face;

0
src/gf/README Normal file
View File

27
src/gf/gf.c Normal file
View File

@ -0,0 +1,27 @@
/****************************************************************************
*
* gf.c
*
* FreeType font driver for TeX's GF FONT files
*
* Copyright 1996-2018 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.
*
*/
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "gflib.c"
#include "gfdrivr.c"
/* END */

70
src/gf/gf.h Normal file
View File

@ -0,0 +1,70 @@
/****************************************************************************
*
* gf.h
*
* FreeType font driver for METAFONT GF FONT files
*
* Copyright 1996-2018 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 GF_H_
#define GF_H_
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_STREAM_H
#include FT_SYSTEM_H
FT_BEGIN_HEADER
#define FONT_DRIVER_GF 1
#define GF_PRE 247
#define GF_ID 131
#define GF_POST 248
#define GF_CHAR_LOC 245
#define GF_CHAR_LOC0 246
#define GF_POST_POST 249
#define GF_PAINT_0 0
#define GF_PAINT_1 1
#define GF_PAINT_63 63
#define GF_PAINT1 64
#define GF_PAINT2 65
#define GF_PAINT3 66
#define GF_BOC 67
#define GF_BOC1 68
#define GF_EOC 69
#define GF_SKIP0 70
#define GF_SKIP1 71
#define GF_SKIP2 72
#define GF_SKIP3 73
#define GF_NEW_ROW_0 74
#define GF_NEW_ROW_164 238
#define GF_XXX1 239
#define GF_XXX2 240
#define GF_XXX3 241
#define GF_XXX4 242
#define GF_YYY 243
#define GF_NO_OP 244
#define toint(x) (int)(((x)>0)?(x+0.5):(x-0.5))
FT_END_HEADER
#endif /* GF_H_ */
/* END */

659
src/gf/gfdrivr.c Normal file
View File

@ -0,0 +1,659 @@
/****************************************************************************
*
* gfdrivr.c
*
* FreeType font driver for METAFONT GF FONT files
*
* Copyright 1996-2018 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.
*
*/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
#include FT_TRUETYPE_IDS_H
#include FT_INTERNAL_TFM_H
#include FT_SERVICE_GF_H
#include FT_SERVICE_FONT_FORMAT_H
#include "gf.h"
#include "gfdrivr.h"
#include "gferror.h"
/**************************************************************************
*
* The macro FT_COMPONENT is used in trace mode. It is an implicit
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
* messages during execution.
*/
#undef FT_COMPONENT
#define FT_COMPONENT trace_gfdriver
typedef struct GF_CMapRec_
{
FT_CMapRec cmap;
FT_ULong num_encodings;
GF_Encoding encodings;
} GF_CMapRec, *GF_CMap;
FT_CALLBACK_DEF( FT_Error )
gf_cmap_init( FT_CMap gfcmap,
FT_Pointer init_data )
{
GF_CMap cmap = (GF_CMap)gfcmap;
GF_Face face = (GF_Face)FT_CMAP_FACE( cmap );
FT_UNUSED( init_data );
cmap->num_encodings = face->gf_glyph->nencodings;
cmap->encodings = face->gf_glyph->encodings;
return FT_Err_Ok;
}
FT_CALLBACK_DEF( void )
gf_cmap_done( FT_CMap gfcmap )
{
GF_CMap cmap = (GF_CMap)gfcmap;
cmap->encodings = NULL;
cmap->num_encodings = 0;
}
FT_CALLBACK_DEF( FT_UInt )
gf_cmap_char_index( FT_CMap gfcmap,
FT_UInt32 charcode )
{
GF_CMap cmap = (GF_CMap)gfcmap;
GF_Encoding encodings = cmap->encodings;
FT_ULong min, max, mid;
FT_UInt result = 0;
min = 0;
max = cmap->num_encodings;
while ( min < max )
{
FT_ULong code;
mid = ( min + max ) >> 1;
code = (FT_ULong)encodings[mid].enc;
if ( charcode == code )
{
result = encodings[mid].glyph;
break;
}
if ( charcode < code )
max = mid;
else
min = mid + 1;
}
return result;
}
FT_CALLBACK_DEF( FT_UInt )
gf_cmap_char_next( FT_CMap gfcmap,
FT_UInt32 *acharcode )
{
GF_CMap cmap = (GF_CMap)gfcmap;
GF_Encoding encodings = cmap->encodings;
FT_ULong min, max, mid;
FT_ULong charcode = *acharcode + 1;
FT_UInt result = 0;
min = 0;
max = cmap->num_encodings;
while ( min < max )
{
FT_ULong code;
mid = ( min + max ) >> 1;
code = (FT_ULong)encodings[mid].enc;
if ( charcode == code )
{
result = encodings[mid].glyph + 1;
goto Exit;
}
if ( charcode < code )
max = mid;
else
min = mid + 1;
}
charcode = 0;
if ( min < cmap->num_encodings )
{
charcode = (FT_ULong)encodings[min].enc;
result = encodings[min].glyph ;
}
Exit:
if ( charcode > 0xFFFFFFFFUL )
{
FT_TRACE1(( "gf_cmap_char_next: charcode 0x%x > 32bit API" ));
*acharcode = 0;
/* XXX: result should be changed to indicate an overflow error */
}
else
*acharcode = (FT_UInt32)charcode;
return result;
}
static
const FT_CMap_ClassRec gf_cmap_class =
{
sizeof ( GF_CMapRec ),
gf_cmap_init,
gf_cmap_done,
gf_cmap_char_index,
gf_cmap_char_next,
NULL, NULL, NULL, NULL, NULL
};
FT_CALLBACK_DEF( void )
GF_Face_Done( FT_Face gfface ) /* GF_Face */
{
GF_Face face = (GF_Face)gfface;
FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
FT_FREE( gfface->available_sizes );
FT_FREE( face->gf_glyph->encodings );
FT_FREE( face->gf_glyph->metrics );
gf_free_font( face );
}
FT_CALLBACK_DEF( FT_Error )
GF_Face_Init( FT_Stream stream,
FT_Face gfface, /* GF_Face */
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
GF_Face face = (GF_Face)gfface;
FT_Error error = FT_Err_Ok;
FT_Memory memory = FT_FACE_MEMORY( face );
GF_Glyph go=NULL;
TFM_Service tfm;
FT_UNUSED( num_params );
FT_UNUSED( params );
face->tfm = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
"tfm" );
tfm = (TFM_Service)face->tfm;
if ( !tfm )
{
FT_ERROR(( "GF_Face_Init: cannot access `tfm' module\n" ));
error = FT_THROW( Missing_Module );
goto Exit;
}
FT_TRACE2(( "GF driver\n" ));
/* load font */
error = gf_load_font( stream, memory, &go );
if ( FT_ERR_EQ( error, Unknown_File_Format ) )
{
FT_TRACE2(( " not a GF file\n" ));
goto Fail;
}
else if ( error )
goto Exit;
/* we have a gf font: let's construct the face object */
face->gf_glyph = go ;
/* sanity check */
if ( !face->gf_glyph->metrics )
{
FT_TRACE2(( "glyph metrics missing\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* GF cannot have multiple faces in a single font file.
* XXX: non-zero face_index is already invalid argument, but
* Type1, Type42 driver has a convention to return
* an invalid argument error when the font could be
* opened by the specified driver.
*/
if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 )
{
FT_ERROR(( "GF_Face_Init: invalid face index\n" ));
GF_Face_Done( gfface );
return FT_THROW( Invalid_Argument );
}
/* we now need to fill the root FT_Face fields */
/* with relevant information */
gfface->num_faces = 1;
gfface->face_index = 0;
gfface->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
FT_FACE_FLAG_HORIZONTAL ;
/*
* XXX: TO-DO: gfface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
* XXX: I have to check for this.
*/
gfface->family_name = NULL;
gfface->num_glyphs = (FT_Long)face->gf_glyph->nglyphs;
FT_TRACE4(( " number of glyphs: allocated %d\n",gfface->num_glyphs ));
if ( gfface->num_glyphs <= 0 )
{
FT_ERROR(( "GF_Face_Init: glyphs not allocated\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
gfface->num_fixed_sizes = 1;
if ( FT_NEW_ARRAY( gfface->available_sizes, 1 ) )
goto Exit;
{
FT_Bitmap_Size* bsize = gfface->available_sizes;
FT_UShort x_res, y_res;
bsize->height = (FT_Short) face->gf_glyph->font_bbx_h ;
bsize->width = (FT_Short) face->gf_glyph->font_bbx_w ;
bsize->size = (FT_Pos) FT_MulDiv( FT_ABS( face->gf_glyph->ds ),
64 * 7200,
72270L );
x_res = toint( go->hppp * 72.27 );
y_res = toint( go->vppp * 72.27 );
bsize->y_ppem = (FT_Pos) toint((face->gf_glyph->ds * y_res)/ 72.27) << 6 ;
bsize->x_ppem = (FT_Pos)FT_MulDiv( bsize->y_ppem,
x_res,
y_res ); ;
}
/* set up charmap */
{
/* FT_Bool unicode_charmap ; */
/* XXX: TO-DO
Currently the unicode_charmap is set to `0'
The functionality of extracting coding scheme
from `xxx' and `yyy' commands will be used to
set the unicode_charmap.
*/
}
/* Charmaps */
{
FT_CharMapRec charmap;
FT_Bool unicode_charmap = 0;
charmap.face = FT_FACE( face );
charmap.encoding = FT_ENCODING_NONE;
/* initial platform/encoding should indicate unset status? */
charmap.platform_id = TT_PLATFORM_APPLE_UNICODE;
charmap.encoding_id = TT_APPLE_ID_DEFAULT;
if( unicode_charmap )
{
/* Unicode Charmap */
charmap.encoding = FT_ENCODING_UNICODE;
charmap.platform_id = TT_PLATFORM_MICROSOFT;
charmap.encoding_id = TT_MS_ID_UNICODE_CS;
}
error = FT_CMap_New( &gf_cmap_class, NULL, &charmap, NULL );
if ( error )
goto Exit;
}
if ( go->code_max < go->code_min )
{
FT_TRACE2(( "invalid number of glyphs\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
Exit:
return error;
Fail:
GF_Face_Done( gfface );
return FT_THROW( Unknown_File_Format );
}
FT_CALLBACK_DEF( FT_Error )
GF_Size_Select( FT_Size size,
FT_ULong strike_index )
{
GF_Face face = (GF_Face)size->face;
GF_Glyph go = face->gf_glyph;
FT_UNUSED( strike_index );
FT_Select_Metrics( size->face, 0 );
size->metrics.ascender = (go->font_bbx_h - go->font_bbx_yoff) * 64;
size->metrics.descender = -go->font_bbx_yoff * 64;
size->metrics.max_advance = go->font_bbx_w * 64;
return FT_Err_Ok;
}
FT_CALLBACK_DEF( FT_Error )
GF_Size_Request( FT_Size size,
FT_Size_Request req )
{
GF_Face face = (GF_Face)size->face;
FT_Bitmap_Size* bsize = size->face->available_sizes;
FT_Error error = FT_ERR( Invalid_Pixel_Size );
FT_Long height;
height = FT_REQUEST_HEIGHT( req );
height = ( height + 32 ) >> 6;
switch ( req->type )
{
case FT_SIZE_REQUEST_TYPE_NOMINAL:
if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) )
error = FT_Err_Ok;
break;
case FT_SIZE_REQUEST_TYPE_REAL_DIM:
if ( height == face->gf_glyph->font_bbx_h )
error = FT_Err_Ok;
break;
default:
error = FT_THROW( Unimplemented_Feature );
break;
}
if ( error )
return error;
else
return GF_Size_Select( size, 0 );
}
FT_CALLBACK_DEF( FT_Error )
GF_Glyph_Load( FT_GlyphSlot slot,
FT_Size size,
FT_UInt glyph_index,
FT_Int32 load_flags )
{
GF_Face gf = (GF_Face)FT_SIZE_FACE( size );
FT_Face face = FT_FACE( gf );
FT_Stream stream;
FT_Error error = FT_Err_Ok;
FT_Bitmap* bitmap = &slot->bitmap;
GF_MetricRec metric;
GF_Glyph go;
FT_ULong bytes;
go = gf->gf_glyph;
FT_UNUSED( load_flags );
if ( !face )
{
error = FT_THROW( Invalid_Face_Handle );
goto Exit;
}
if ( !go ||
glyph_index >= (FT_UInt)( face->num_glyphs ) )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
FT_TRACE1(( "GF_Glyph_Load: glyph index %d and charcode is %d\n", glyph_index, go->metrics[glyph_index].code ));
if ( (FT_Int)glyph_index < 0 )
glyph_index = 0;
if ((glyph_index < go->code_min) || (go->code_max < glyph_index))
{
FT_TRACE2(( "invalid glyph index\n" ));
error = FT_THROW( Invalid_Argument );
goto Exit;
}
stream = gf->root.stream;
metric = gf->gf_glyph->metrics[glyph_index];
error = gf_read_glyph( stream,
&metric );
bitmap->rows = metric.bbx_height;
bitmap->width = metric.bbx_width;
bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
bitmap->pitch = (int)( ( bitmap->width + 7 ) >> 3 );
slot->format = FT_GLYPH_FORMAT_BITMAP;
slot->bitmap_left = metric.off_x ;
slot->bitmap_top = metric.off_y ;
slot->metrics.horiAdvance = (FT_Pos) ( metric.mv_x ) * 64;
slot->metrics.horiBearingX = (FT_Pos) ( metric.off_x ) * 64;
slot->metrics.horiBearingY = (FT_Pos) ( metric.bbx_height) * 64;
slot->metrics.width = (FT_Pos) ( bitmap->width * 64 );
slot->metrics.height = (FT_Pos) ( bitmap->rows * 64 );
FT_TRACE2(( "Glyph metric values are: metric.bbx_height is %ld\n"
" metric.bbx_width is %ld\n"
" metric.off_x is %ld\n"
" metric.off_y is %ld\n"
" metric.mv_x is %ld\n"
" metric.mv_y is %ld\n", metric.bbx_height, metric.bbx_width,
metric.off_x, metric.off_y, metric.mv_x,
metric.mv_y ));
ft_synthesize_vertical_metrics( &slot->metrics, metric.bbx_height * 64 );
if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY )
goto Exit;
bytes = (FT_ULong)bitmap->pitch * bitmap->rows;
error = ft_glyphslot_alloc_bitmap( slot, (FT_ULong)bytes );
memset( slot->bitmap.buffer, 0, bytes );
Exit:
return error;
}
FT_LOCAL_DEF( void )
TFM_Done_Metrics( FT_Memory memory,
TFM_FontInfo fi )
{
FT_FREE(fi->width);
FT_FREE(fi->height);
FT_FREE(fi->depth);
FT_FREE( fi );
}
/* parse a TFM metrics file */
FT_LOCAL_DEF( FT_Error )
TFM_Read_Metrics( FT_Face gf_face,
FT_Stream stream )
{
TFM_Service tfm;
FT_Memory memory = stream->memory;
TFM_ParserRec parser;
TFM_FontInfo fi = NULL;
FT_Error error = FT_ERR( Unknown_File_Format );
GF_Face face = (GF_Face)gf_face;
GF_Glyph gf_glyph= face->gf_glyph;
if ( face->tfm_data )
{
FT_TRACE1(( "TFM_Read_Metrics:"
" Freeing previously attached metrics data.\n" ));
TFM_Done_Metrics( memory, (TFM_FontInfo)face->tfm_data );
face->tfm_data = NULL;
}
if ( FT_NEW( fi ) )
goto Exit;
FT_TRACE4(( "TFM_Read_Metrics: Invoking TFM_Service.\n" ));
tfm = (TFM_Service)face->tfm;
if ( tfm->tfm_parser_funcs )
{
/* Initialise TFM Service */
error = tfm->tfm_parser_funcs->init( &parser,
memory,
stream );
if ( !error )
{
FT_TRACE4(( "TFM_Read_Metrics: Initialised tfm metric data.\n" ));
parser.FontInfo = fi;
parser.user_data = gf_glyph;
error = tfm->tfm_parser_funcs->parse_metrics( &parser );
if( !error )
FT_TRACE4(( "TFM_Read_Metrics: parsing TFM metric information done.\n" ));
FT_TRACE6(( "TFM_Read_Metrics: TFM Metric Information:\n"
" Check Sum : %ld\n"
" Design Size: %ld\n"
" Begin Char : %d\n"
" End Char : %d\n"
" font_bbx_w : %d\n"
" font_bbx_h : %d\n"
" slant : %d\n", parser.FontInfo->cs, parser.FontInfo->design_size, parser.FontInfo->begin_char,
parser.FontInfo->end_char, parser.FontInfo->font_bbx_w,
parser.FontInfo->font_bbx_h, parser.FontInfo->slant ));
tfm->tfm_parser_funcs->done( &parser );
}
}
if ( !error )
{
/* Modify GF_Glyph data according to TFM metric values */
/*face->gf_glyph->font_bbx_w = fi->font_bbx_w;
face->gf_glyph->font_bbx_h = fi->font_bbx_h;
*/
face->tfm_data = fi;
}
Exit:
if ( fi )
TFM_Done_Metrics( memory, fi );
return error;
}
/*
*
* SERVICES LIST
*
*/
static const FT_ServiceDescRec gf_services[] =
{
{ FT_SERVICE_ID_GF, NULL },
{ FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_GF },
{ NULL, NULL }
};
FT_CALLBACK_DEF( FT_Module_Interface )
gf_driver_requester( FT_Module module,
const char* name )
{
FT_UNUSED( module );
return ft_service_list_lookup( gf_services, name );
}
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec gf_driver_class =
{
{
FT_MODULE_FONT_DRIVER |
FT_MODULE_DRIVER_NO_OUTLINES,
sizeof ( FT_DriverRec ),
"gf",
0x10000L,
0x20000L,
NULL, /* module-specific interface */
NULL, /* FT_Module_Constructor module_init */
NULL, /* FT_Module_Destructor module_done */
gf_driver_requester /* FT_Module_Requester get_interface */
},
sizeof ( GF_FaceRec ),
sizeof ( FT_SizeRec ),
sizeof ( FT_GlyphSlotRec ),
GF_Face_Init, /* FT_Face_InitFunc init_face */
GF_Face_Done, /* FT_Face_DoneFunc done_face */
NULL, /* FT_Size_InitFunc init_size */
NULL, /* FT_Size_DoneFunc done_size */
NULL, /* FT_Slot_InitFunc init_slot */
NULL, /* FT_Slot_DoneFunc done_slot */
GF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */
NULL, /* FT_Face_GetKerningFunc get_kerning */
TFM_Read_Metrics, /* FT_Face_AttachFunc attach_file */
NULL, /* FT_Face_GetAdvancesFunc get_advances */
GF_Size_Request, /* FT_Size_RequestFunc request_size */
GF_Size_Select /* FT_Size_SelectFunc select_size */
};
/* END */

91
src/gf/gfdrivr.h Normal file
View File

@ -0,0 +1,91 @@
/****************************************************************************
*
* gfdrivr.h
*
* FreeType font driver for METAFONT GF FONT files
*
* Copyright 1996-2018 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 GFDRIVR_H_
#define GFDRIVR_H_
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
#include "gf.h"
FT_BEGIN_HEADER
typedef struct GF_EncodingRec_
{
FT_Long enc;
FT_UShort glyph;
} GF_EncodingRec, *GF_Encoding;
/* BitmapRec for GF format specific glyphs */
typedef struct GF_MetricRec_
{
FT_Long bbx_width, bbx_height;
FT_Long off_x, off_y;
FT_Long mv_x, mv_y;
FT_Byte *bitmap;
FT_UInt raster;
FT_Long char_offset;
FT_UShort code;
} GF_MetricRec, *GF_Metric;
typedef struct GF_GlyphRec_
{
FT_UInt code_min, code_max;
FT_ULong nmetrics;
GF_Metric metrics;
FT_ULong nglyphs;
FT_ULong nencodings;
GF_Encoding encodings;
FT_Short defaultChar; /* To be checked */
FT_Int ds, hppp, vppp;
FT_Int font_bbx_w, font_bbx_h;
FT_Int font_bbx_xoff, font_bbx_yoff;
FT_Int check_sum;
} GF_GlyphRec, *GF_Glyph;
typedef struct GF_FaceRec_
{
FT_FaceRec root;
GF_Glyph gf_glyph;
const void* tfm;
const void* tfm_data;
} GF_FaceRec, *GF_Face;
FT_EXPORT_VAR( const FT_Driver_ClassRec ) gf_driver_class;
FT_END_HEADER
#endif /* GFDRIVR_H_ */
/* END */

40
src/gf/gferror.h Normal file
View File

@ -0,0 +1,40 @@
/****************************************************************************
*
* gferror.h
*
* FreeType font driver for TeX's GF FONT files
*
* Copyright 1996-2018 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 is used to define the GF error enumeration constants.
*
*/
#ifndef GFERROR_H_
#define GFERROR_H_
#include FT_MODULE_ERRORS_H
#undef FTERRORS_H_
#undef FT_ERR_PREFIX
#define FT_ERR_PREFIX GF_Err_
#define FT_ERR_BASE FT_Mod_Err_GF
#include FT_ERRORS_H
#endif /* GFERROR_H_ */
/* END */

649
src/gf/gflib.c Normal file
View File

@ -0,0 +1,649 @@
/****************************************************************************
*
* gflib.c
*
* FreeType font driver for METAFONT GF FONT files
*
* Copyright 1996-2018 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.
*
*/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SYSTEM_H
#include FT_CONFIG_CONFIG_H
#include FT_ERRORS_H
#include FT_TYPES_H
#include "gf.h"
#include "gfdrivr.h"
#include "gferror.h"
/**************************************************************************
*
* The macro FT_COMPONENT is used in trace mode. It is an implicit
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
* messages during execution.
*/
#undef FT_COMPONENT
#define FT_COMPONENT trace_gflib
FT_Byte bit_table[] = {
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
/**************************************************************************
*
* GF font utility functions.
*
*/
FT_Long gf_read_intn(FT_Stream, FT_Int);
FT_ULong gf_read_uintn(FT_Stream, FT_Int);
#define READ_UINT1( stream ) (FT_Byte)gf_read_uintn( stream, 1)
#define READ_UINT2( stream ) (FT_Byte)gf_read_uintn( stream, 2)
#define READ_UINT3( stream ) (FT_Byte)gf_read_uintn( stream, 3)
#define READ_UINT4( stream ) (FT_Byte)gf_read_uintn( stream, 4)
#define READ_UINTN( stream,n) (FT_ULong)gf_read_uintn( stream, n)
#define READ_INT1( stream ) (FT_String)gf_read_intn( stream, 1)
#define READ_INT4( stream ) (FT_Long)gf_read_intn( stream, 4)
/*
* Reading a Number from file
*/
FT_ULong
gf_read_uintn(FT_Stream stream, FT_Int size)
{
FT_ULong v,k;
FT_Error error;
FT_Byte tp;
v = 0L;
while (size >= 1)
{
if ( FT_READ_BYTE(tp) )
return 0;
k = (FT_ULong)tp;
v = v*256L + k;
--size;
}
return v;
}
FT_Long
gf_read_intn(FT_Stream stream, FT_Int size)
{
FT_Long v;
FT_Byte tp;
FT_Error error;
FT_ULong z;
if ( FT_READ_BYTE(tp) )
return 0;
z = (FT_ULong)tp;
v = (FT_Long)z & 0xffL;
if (v & 0x80L)
v = v - 256L;
--size;
while (size >= 1)
{
if ( FT_READ_BYTE(tp) )
return 0;
z = (FT_ULong)tp;
v = v*256L + z;
--size;
}
return v;
}
static int
compare( FT_Long* a,
FT_Long* b )
{
if ( *a < *b )
return -1;
else if ( *a > *b )
return 1;
else
return 0;
}
/**************************************************************************
*
* API.
*
*/
static FT_Error
gf_set_encodings( GF_Glyph go,
FT_Memory memory )
{
FT_Error error;
FT_ULong nencoding;
FT_UInt i, j;
FT_ULong k;
GF_Encoding encoding = NULL;
GF_Metric metric;
FT_Long *tosort;
nencoding = go->nglyphs;
FT_TRACE2(( "gf_set_encodings: Reached here.\n" ));
if ( FT_NEW_ARRAY( metric, go->code_max - go->code_min + 1 ) )
return error;
if ( FT_NEW_ARRAY( encoding, nencoding ) )
return error;
if ( FT_NEW_ARRAY( tosort, nencoding ) )
return error;
FT_TRACE2(( "gf_set_encodings: Allocated sufficient memory.\n" ));
for( i = 0 ; i < 256 ; i++ )
{
if( go->metrics[i].char_offset >= 0 )
tosort[i] = go->metrics[i].char_offset;
}
ft_qsort( (void*)tosort, go->nglyphs, sizeof(FT_Long),
(int(*)(const void*, const void*) )compare );
for( i = 0 ; i < go->nglyphs ; i++ )
{
/* FT_TRACE2(( "tosort[%d]is %ld\n",i,tosort[i] )); */
}
k = 0;
for ( i = 0; i < go->nglyphs; i++ )
{
for ( j = 0; j < 256; j++ )
{
if( go->metrics[j].char_offset == tosort[i] )
break;
}
metric[k].char_offset = go->metrics[j].char_offset;
metric[k].code = go->metrics[j].code;
/* FT_TRACE2(( "metric[%d].char_offset is %ld %ld% ld\n",k,metric[k].char_offset,metric[k].code,k )); */
encoding[k].enc = go->metrics[j].code;
encoding[k].glyph = k;
k++;
}
for( i = 0 ; i < go->nglyphs ; i++ )
{
go->metrics[i].char_offset = metric[i].char_offset;
go->metrics[i].code = metric[i].code;
/* FT_TRACE2(( "Hi I am here go->metrics[%d].char_offset is %ld %ld% ld\n",i,
go->metrics[i].char_offset,go->metrics[i].code,i )); */
}
FT_FREE(metric);
FT_FREE(tosort);
go->nencodings = k;
go->encodings = encoding;
return error;
}
FT_LOCAL_DEF( FT_Error )
gf_read_glyph( FT_Stream stream,
GF_MetricRec *metrics )
{
FT_Long m, n;
FT_Int paint_sw;
FT_Int instr,inst;
FT_Long min_m, max_m, min_n, max_n, del_m, del_n;
FT_Long w, h, d;
FT_Int k;
/* FT_Int m_b;
FT_Byte *ptr; */
FT_Error error = FT_Err_Ok;
if( FT_STREAM_SEEK( metrics->char_offset ) )
return 0;
FT_TRACE2(( "In gf_read_glyph\n" ));
for ( ; ; )
{
inst = READ_UINT1( stream );
switch ((FT_Int)inst)
{
case GF_BOC:
if ( FT_STREAM_SKIP( 4 ) )
return -1;
if ( FT_STREAM_SKIP( 4 ) )
return -1;
min_m = READ_INT4( stream );
max_m = READ_INT4( stream );
min_n = READ_INT4( stream );
max_n = READ_INT4( stream );
goto BOC;
break;
case GF_BOC1:
if ( FT_STREAM_SKIP( 1 ) )
return -1;
del_m = (FT_Long)READ_UINT1( stream );
max_m = (FT_Long)READ_UINT1( stream );
del_n = (FT_Long)READ_UINT1( stream );
max_n = (FT_Long)READ_UINT1( stream );
min_m = max_m - del_m;
min_n = max_n - del_n;
goto BOC;
break;
case GF_XXX1:
k = (FT_ULong)READ_UINT1( stream );
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
case GF_XXX2:
k = (FT_ULong)READ_UINT2( stream );
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
case GF_XXX3:
k = (FT_ULong)READ_UINT3( stream );
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
case GF_XXX4:
k = (FT_ULong)READ_UINT4( stream );
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
case GF_YYY :
if ( FT_STREAM_SKIP( 4 ) )
return -1;
break;
case GF_NO_OP:
break;
default:
return -1;
}
}
return 0;
BOC:
if(error != FT_Err_Ok)
return error;
w = max_m - min_m + 1;
h = max_n - min_n + 1;
if ((w < 0) || (h < 0))
{
FT_ERROR(( "gf_read_glyph: invalid w and h values\n" ));
error = FT_THROW( Invalid_File_Format );
return error;
}
/* FT_TRACE2(( "w is %ld\n"
"h is %ld\n"
"-min_m is %ld\n"
"max_n is %ld\n\n", w, h, -min_m, max_n ));
*/
/* allocate and build bitmap */
/*
if ((metrics->bitmap = (FT_Byte*)malloc(h*((w+7)/8))) == NULL)
{
error = FT_THROW( Invalid_File_Format );
return error;
}
*/
/* if( FT_ALLOC( metrics->bitmap, (h*((w+7)/8)) ) )
return error;
*/
/*
memset(metrics->bitmap, 0, h*((w+7)/8));
metrics->raster = (FT_UInt)(w+7)/8;
*/
metrics->bbx_width = w;
metrics->bbx_height = h;
metrics->off_x = -min_m;
metrics->off_y = max_n;
#if 0
bm->mv_x = -min_m;
bm->mv_y = max_n;
#endif
m = min_m;
n = max_n;
paint_sw = 0;
while ((instr = (FT_Int)READ_UINT1( stream )) != GF_EOC)
{
if (instr == GF_PAINT_0)
{
paint_sw = 1 - paint_sw;
}
else if ((GF_NEW_ROW_0 <= instr) && (instr <= GF_NEW_ROW_164))
{
m = min_m + (instr - GF_NEW_ROW_0);
n = n - 1;
paint_sw = 1;
}
else if ((GF_PAINT_1 <= instr) && (instr <= GF_PAINT_63))
{
d = (instr - GF_PAINT_1 + 1);
goto Paint;
}
else
{
switch ((FT_Int)instr)
{
case GF_PAINT1:
case GF_PAINT2:
case GF_PAINT3:
d = (FT_ULong)READ_UINTN( stream, (instr - GF_PAINT1 + 1));
Paint:
if (paint_sw == 0)
{
m = m + d;
}
else
{
/*
ptr = &bm->bitmap[(max_n - n) * bm->raster + (m - min_m)/8];
m_b = (m - min_m) % 8;
while (d > 0)
{
*ptr |= bit_table[m_b];
m++;
if (++m_b >= 8)
{
m_b = 0;
++ptr;
}
d--;
}
*/
}
paint_sw = 1 - paint_sw;
break;
case GF_SKIP0:
m = min_m;
n = n - 1;
paint_sw = 0;
break;
case GF_SKIP1:
case GF_SKIP2:
case GF_SKIP3:
m = min_m;
n = n - (FT_ULong)READ_UINTN( stream, (instr - GF_SKIP1 + 1)) - 1;
paint_sw = 0;
break;
case GF_XXX1:
case GF_XXX2:
case GF_XXX3:
case GF_XXX4:
k = READ_UINTN( stream, instr - GF_XXX1 + 1);
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
case GF_YYY:
if ( FT_STREAM_SKIP( 4 ) )
return -1;
break;
case GF_NO_OP:
break;
default:
error = FT_THROW( Invalid_File_Format );
return -1;
}
}
}
return 0;
}
FT_LOCAL_DEF( FT_Error )
gf_load_font( FT_Stream stream,
FT_Memory extmemory,
GF_Glyph *goptr )
{
GF_Glyph go;
FT_Byte instr, d, pre, id, k, code;
FT_Long ds, check_sum, hppp, vppp;
FT_Long min_m, max_m, min_n, max_n, w;
FT_UInt dx, dy;
FT_Long ptr_post, ptr_p, ptr;
FT_Int bc, ec, nchars, i;
FT_Error error = FT_Err_Ok;
FT_Memory memory = extmemory; /* needed for FT_NEW */
go = NULL;
nchars = -1;
if( FT_STREAM_SEEK( 0 ) )
goto Exit;
pre = READ_UINT1( stream );
if (pre != GF_PRE)
{
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
id = READ_UINT1( stream );
if (id != GF_ID)
{
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
k = READ_UINT1( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
/* seek to post_post instr. */
if( FT_STREAM_SEEK( stream->size - 1 ) )
goto Exit;
if( FT_STREAM_SEEK( stream->size - 1 ) )
goto Exit;
while ( READ_UINT1( stream ) == 223)
{
if( FT_STREAM_SEEK( stream->pos -2 ) )
goto Exit;
}
if( FT_STREAM_SEEK( stream->pos -1 ) )
goto Exit;
d= READ_UINT1( stream );
if (d != GF_ID)
{
FT_ERROR(( "gf_load_font: missing GF_ID(131) field\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
FT_TRACE2(( "gf_load_font: GF_ID(131) found\n" ));
if(FT_STREAM_SEEK( stream->pos -6 ))
goto Exit;
/* check if the code is post_post */
if (READ_UINT1( stream ) != GF_POST_POST)
{
FT_ERROR(( "gf_load_font: missing GF_POST_POST(249) field\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
FT_TRACE2(( "gf_load_font: GF_POST_POST(249) found\n" ));
/* read pointer to post instr. */
if(FT_READ_ULONG( ptr_post ))
goto Exit;
if (ptr_post == -1)
{
FT_ERROR(( "gf_load_font: invalid postamble pointer\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
/* goto post instr. and read it */
if(FT_STREAM_SEEK( ptr_post ))
goto Exit;
if (READ_UINT1( stream ) != GF_POST)
{
FT_ERROR(( "gf_load_font: missing GF_POST(248) field\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
FT_TRACE2(( "gf_load_font: GF Postamble found\n" ));
if(FT_READ_ULONG( ptr_p ))
goto Exit;
if(FT_READ_ULONG( ds ))
goto Exit;
if(FT_READ_ULONG( check_sum ))
goto Exit;
if(FT_READ_ULONG( hppp ))
goto Exit;
if(FT_READ_ULONG( vppp ))
goto Exit;
min_m = READ_INT4( stream );
max_m = READ_INT4( stream );
min_n = READ_INT4( stream );
max_n = READ_INT4( stream );
FT_TRACE5(( "gf_load_font: checksum is %ld\n",check_sum ));
if( ptr_p < 0 )
{
FT_ERROR(( "gf_load_font: invalid pointer in postamble\n" ));
goto Exit;
}
if( check_sum < 0 )
{
FT_ERROR(( "gf_load_font: invalid check sum value\n" ));
goto Exit;
}
bc = 0;
ec = 255;
nchars = ec - bc + 1;
if( FT_ALLOC(go, sizeof(GF_GlyphRec)) )
goto Exit;
FT_TRACE5(( "gf_load_font: Allocated GF_GlyphRec\n" ));
go->check_sum = check_sum;
go->ds = (FT_UInt)ds/(1<<20);
go->hppp = (FT_UInt)hppp/(1<<16);
go->vppp = (FT_UInt)vppp/(1<<16);
go->font_bbx_w = max_m - min_m;
go->font_bbx_h = max_n - min_n;
go->font_bbx_xoff = min_m;
go->font_bbx_yoff = min_n;
go->code_min = bc;
go->code_max = ec;
go->nglyphs = 0;
if ( FT_NEW_ARRAY( go->metrics, nchars ) )
goto Exit;
FT_TRACE5(( "gf_load_font: Allocated go->metrics array\n" ));
for( i = 0; i < 256 ; i++)
go->metrics[i].char_offset = -1;
for ( ; ; )
{
if ((instr = READ_UINT1( stream )) == GF_POST_POST)
break;
switch ((FT_Int)instr)
{
case GF_CHAR_LOC:
code = READ_UINT1( stream );
dx = (FT_UInt)READ_INT4( stream )/(FT_UInt)(1<<16);
dy = (FT_UInt)READ_INT4( stream )/(FT_UInt)(1<<16);
w = READ_INT4( stream );
ptr = READ_INT4( stream );
break;
case GF_CHAR_LOC0:
code = READ_UINT1( stream );
dx = (FT_UInt)READ_INT1( stream );
dy = (FT_UInt)0;
w = READ_INT4( stream );
ptr = READ_INT4( stream );
break;
default:
FT_ERROR(( "gf_load_font: missing character locators in postamble\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
go->metrics[code - bc].mv_x = dx;
go->metrics[code - bc].mv_y = dy;
go->metrics[code - bc].char_offset = (FT_ULong)ptr;
go->metrics[code - bc].code = (FT_UShort)code;
go->metrics[code - bc].bbx_width = 0; /* Initialize other metrics here */
go->metrics[code - bc].bbx_height = 0;
go->metrics[code - bc].off_x = 0;
go->metrics[code - bc].off_y = 0;
go->metrics[code - bc].raster = 0;
go->metrics[code - bc].bitmap = NULL;
go->nglyphs += 1;
}
error = gf_set_encodings( go, memory );
if( error )
goto Exit;
*goptr = go;
return error;
Exit:
if (go != NULL)
{
if(go->metrics != NULL)
{
FT_FREE(go->metrics);
}
FT_FREE(go);
}
return error;
}
FT_LOCAL_DEF( void )
gf_free_font( GF_Face face )
{
FT_Memory memory = FT_FACE( face )->memory;
GF_Glyph go = face->gf_glyph;
if ( !go )
return;
FT_FREE(go);
}
/* END */

23
src/gf/module.mk Normal file
View File

@ -0,0 +1,23 @@
#
# FreeType 2 GF Font module definition
#
# Copyright 1996-2018 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.
FTMODULE_H_COMMANDS += GF_DRIVER
define GF_DRIVER
$(OPEN_DRIVER) FT_Driver_ClassRec, gf_driver_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)gf $(ECHO_DRIVER_DESC)METAFONT bitmap fonts$(ECHO_DRIVER_DONE)
endef
# EOF

70
src/gf/rules.mk Normal file
View File

@ -0,0 +1,70 @@
#
# FreeType 2 GF driver configuration rules
#
# Copyright 1996-2018 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.
# gf driver directory
#
GF_DIR := $(SRC_DIR)/gf
GF_COMPILE := $(CC) $(ANSIFLAGS) \
$I$(subst /,$(COMPILER_SEP),$(GF_DIR)) \
$(INCLUDE_FLAGS) \
$(FT_CFLAGS)
# gf driver sources (i.e., C files)
#
GF_DRV_SRC := $(GF_DIR)/gflib.c \
$(GF_DIR)/gfdrivr.c
# gf driver headers
#
GF_DRV_H := $(GF_DIR)/gf.h \
$(GF_DIR)/gfdrivr.h \
$(GF_DIR)/gferror.h
# gf driver object(s)
#
# GF_DRV_OBJ_M is used during `multi' builds
# GF_DRV_OBJ_S is used during `single' builds
#
GF_DRV_OBJ_M := $(GF_DRV_SRC:$(GF_DIR)/%.c=$(OBJ_DIR)/%.$O)
GF_DRV_OBJ_S := $(OBJ_DIR)/gf.$O
# gf driver source file for single build
#
GF_DRV_SRC_S := $(GF_DIR)/gf.c
# gf driver - single object
#
$(GF_DRV_OBJ_S): $(GF_DRV_SRC_S) $(GF_DRV_SRC) $(FREETYPE_H) $(GF_DRV_H)
$(GF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(GF_DRV_SRC_S))
# gf driver - multiple objects
#
$(OBJ_DIR)/%.$O: $(GF_DIR)/%.c $(FREETYPE_H) $(GF_DRV_H)
$(GF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
# update main driver object lists
#
DRV_OBJS_S += $(GF_DRV_OBJ_S)
DRV_OBJS_M += $(GF_DRV_OBJ_M)
# EOF

0
src/pk/README Normal file
View File

23
src/pk/module.mk Normal file
View File

@ -0,0 +1,23 @@
#
# FreeType 2 PK Font module definition
#
# Copyright 1996-2018 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.
FTMODULE_H_COMMANDS += PK_DRIVER
define PK_DRIVER
$(OPEN_DRIVER) FT_Driver_ClassRec, pk_driver_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)pk $(ECHO_DRIVER_DESC)METAFONT bitmap fonts$(ECHO_DRIVER_DONE)
endef
# EOF

27
src/pk/pk.c Normal file
View File

@ -0,0 +1,27 @@
/****************************************************************************
*
* pk.c
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 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.
*
*/
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "pklib.c"
#include "pkdrivr.c"
/* END */

62
src/pk/pk.h Normal file
View File

@ -0,0 +1,62 @@
/****************************************************************************
*
* pk.h
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 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 PK_H_
#define PK_H_
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_STREAM_H
#include FT_SYSTEM_H
FT_BEGIN_HEADER
#define FONT_DRIVER_PK 1
#define PK_PRE 247
#define PK_ID 89
#define PK_XXX1 240
#define PK_XXX2 241
#define PK_XXX3 242
#define PK_XXX4 243
#define PK_YYY 244
#define PK_POST 245
#define PK_NO_OP 246
#define toint(x) (int)(((x)>0)?(x+0.5):(x-0.5))
/* Temporary TO BE REMOVED */
typedef char INT1;
typedef unsigned char UINT1;
typedef int INT2;
typedef unsigned int UINT2;
typedef long INT3;
typedef unsigned long UINT3;
typedef long INT4;
typedef unsigned long UINT4;
FT_END_HEADER
#endif /* PK_H_ */
/* END */

594
src/pk/pkdrivr.c Normal file
View File

@ -0,0 +1,594 @@
/****************************************************************************
*
* pkdrivr.c
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 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.
*
*/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
#include FT_TRUETYPE_IDS_H
#include FT_INTERNAL_TFM_H
#include FT_SERVICE_PK_H
#include FT_SERVICE_FONT_FORMAT_H
#include "pk.h"
#include "pkdrivr.h"
#include "pkerror.h"
/**************************************************************************
*
* The macro FT_COMPONENT is used in trace mode. It is an implicit
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
* messages during execution.
*/
#undef FT_COMPONENT
#define FT_COMPONENT trace_pkdriver
typedef struct PK_CMapRec_
{
FT_CMapRec cmap;
FT_UInt32 bc; /* Beginning Character */
FT_UInt32 ec; /* End Character */
} PK_CMapRec, *PK_CMap;
FT_CALLBACK_DEF( FT_Error )
pk_cmap_init( FT_CMap pkcmap,
FT_Pointer init_data )
{
PK_CMap cmap = (PK_CMap)pkcmap;
PK_Face face = (PK_Face)FT_CMAP_FACE( cmap );
FT_UNUSED( init_data );
cmap->bc = face->pk_glyph->code_min;
cmap->ec = face->pk_glyph->code_max;
return FT_Err_Ok;
}
FT_CALLBACK_DEF( void )
pk_cmap_done( FT_CMap pkcmap )
{
PK_CMap cmap = (PK_CMap)pkcmap;
cmap->bc = 0;
cmap->ec = -1;
}
FT_CALLBACK_DEF( FT_UInt )
pk_cmap_char_index( FT_CMap pkcmap,
FT_UInt32 char_code )
{
FT_UInt gindex = 0;
PK_CMap cmap = (PK_CMap)pkcmap;
char_code -= cmap->bc;
if ( char_code < cmap->ec - cmap->bc + 1 )
gindex = (FT_UInt)( char_code );
return gindex;
}
FT_CALLBACK_DEF( FT_UInt )
pk_cmap_char_next( FT_CMap pkcmap,
FT_UInt32 *achar_code )
{
PK_CMap cmap = (PK_CMap)pkcmap;
FT_UInt gindex = 0;
FT_UInt32 result = 0;
FT_UInt32 char_code = *achar_code + 1;
if ( char_code <= cmap->bc )
{
result = cmap->bc;
gindex = 1;
}
else
{
char_code -= cmap->bc;
if ( char_code < cmap->ec - cmap->bc + 1 )
{
result = char_code;
gindex = (FT_UInt)( char_code );
}
}
*achar_code = result;
return gindex;
}
static
const FT_CMap_ClassRec pk_cmap_class =
{
sizeof ( PK_CMapRec ),
pk_cmap_init,
pk_cmap_done,
pk_cmap_char_index,
pk_cmap_char_next,
NULL, NULL, NULL, NULL, NULL
};
FT_CALLBACK_DEF( void )
PK_Face_Done( FT_Face pkface ) /* PK_Face */
{
PK_Face face = (PK_Face)pkface;
FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
pk_free_font( face );
FT_FREE( pkface->available_sizes );
}
FT_CALLBACK_DEF( FT_Error )
PK_Face_Init( FT_Stream stream,
FT_Face pkface, /* PK_Face */
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
PK_Face face = (PK_Face)pkface;
FT_Error error = FT_Err_Ok;
FT_Memory memory = FT_FACE_MEMORY( face );
PK_Glyph go=NULL;
FT_UInt16 i,count;
TFM_Service tfm;
FT_UNUSED( num_params );
FT_UNUSED( params );
face->tfm = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
"tfm" );
tfm = (TFM_Service)face->tfm;
if ( !tfm )
{
FT_ERROR(( "GF_Face_Init: cannot access `tfm' module\n" ));
error = FT_THROW( Missing_Module );
goto Exit;
}
FT_TRACE2(( "PK driver\n" ));
/* load font */
error = pk_load_font( stream, memory, &go );
if ( FT_ERR_EQ( error, Unknown_File_Format ) )
{
FT_TRACE2(( " not a PK file\n" ));
goto Fail;
}
else if ( error )
goto Exit;
/* we have a pk font: let's construct the face object */
face->pk_glyph = go ;
/* sanity check */
if ( !face->pk_glyph->bm_table )
{
FT_TRACE2(( "glyph bitmaps not allocated\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* PK cannot have multiple faces in a single font file.
* XXX: non-zero face_index is already invalid argument, but
* Type1, Type42 driver has a convention to return
* an invalid argument error when the font could be
* opened by the specified driver.
*/
if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 )
{
FT_ERROR(( "PK_Face_Init: invalid face index\n" ));
PK_Face_Done( pkface );
return FT_THROW( Invalid_Argument );
}
/* we now need to fill the root FT_Face fields */
/* with relevant information */
pkface->num_faces = 1;
pkface->face_index = 0;
pkface->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
FT_FACE_FLAG_HORIZONTAL ;
/*
* XXX: TO-DO: pkface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
* XXX: I have to check for this.
*/
pkface->family_name = NULL;
count=0;
for (i = 0; i < 256; i++)
{
if(go->bm_table[i].bitmap != NULL)
count++;
}
pkface->num_glyphs = (FT_Long)count;
FT_TRACE4(( " number of glyphs: allocated %d\n",pkface->num_glyphs ));
if ( pkface->num_glyphs <= 0 )
{
FT_ERROR(( "PK_Face_Init: glyphs not allocated\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
pkface->num_fixed_sizes = 1;
if ( FT_NEW_ARRAY( pkface->available_sizes, 1 ) )
goto Exit;
{
FT_Bitmap_Size* bsize = pkface->available_sizes;
FT_UShort x_res, y_res;
bsize->height = (FT_Short) face->pk_glyph->font_bbx_h ;
bsize->width = (FT_Short) face->pk_glyph->font_bbx_w ;
bsize->size = (FT_Pos) FT_MulDiv( FT_ABS( face->pk_glyph->ds ),
64 * 7200,
72270L );
x_res = toint( face->pk_glyph->hppp * 72.27 );
y_res = toint( face->pk_glyph->vppp * 72.27 );
bsize->y_ppem = (FT_Pos) toint((face->pk_glyph->ds * y_res)/ 72.27) << 6 ;
bsize->x_ppem = (FT_Pos)FT_MulDiv( bsize->y_ppem,
x_res,
y_res ); ;
}
/* Charmaps */
{
FT_CharMapRec charmap;
/* Unicode Charmap */
charmap.encoding = FT_ENCODING_UNICODE;
charmap.platform_id = TT_PLATFORM_MICROSOFT;
charmap.encoding_id = TT_MS_ID_UNICODE_CS;
charmap.face = FT_FACE( face );
error = FT_CMap_New( &pk_cmap_class, NULL, &charmap, NULL );
if ( error )
goto Exit;
}
if ( go->code_max < go->code_min )
{
FT_TRACE2(( "invalid number of glyphs\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
Exit:
return error;
Fail:
PK_Face_Done( pkface );
return FT_THROW( Unknown_File_Format );
}
FT_CALLBACK_DEF( FT_Error )
PK_Size_Select( FT_Size size,
FT_ULong strike_index )
{
PK_Face face = (PK_Face)size->face;
PK_Glyph go = face->pk_glyph;
FT_UNUSED( strike_index );
FT_Select_Metrics( size->face, 0 );
size->metrics.ascender = (go->font_bbx_h - go->font_bbx_yoff) * 64;
size->metrics.descender = -go->font_bbx_yoff * 64;
size->metrics.max_advance = go->font_bbx_w * 64;
return FT_Err_Ok;
}
FT_CALLBACK_DEF( FT_Error )
PK_Size_Request( FT_Size size,
FT_Size_Request req )
{
PK_Face face = (PK_Face)size->face;
FT_Bitmap_Size* bsize = size->face->available_sizes;
FT_Error error = FT_ERR( Invalid_Pixel_Size );
FT_Long height;
height = FT_REQUEST_HEIGHT( req );
height = ( height + 32 ) >> 6;
switch ( req->type )
{
case FT_SIZE_REQUEST_TYPE_NOMINAL:
if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) )
error = FT_Err_Ok;
break;
case FT_SIZE_REQUEST_TYPE_REAL_DIM:
if ( height == face->pk_glyph->font_bbx_h )
error = FT_Err_Ok;
break;
default:
error = FT_THROW( Unimplemented_Feature );
break;
}
if ( error )
return error;
else
return PK_Size_Select( size, 0 );
}
FT_CALLBACK_DEF( FT_Error )
PK_Glyph_Load( FT_GlyphSlot slot,
FT_Size size,
FT_UInt glyph_index,
FT_Int32 load_flags )
{
PK_Face pk = (PK_Face)FT_SIZE_FACE( size );
FT_Face face = FT_FACE( pk );
FT_Error error = FT_Err_Ok;
FT_Bitmap* bitmap = &slot->bitmap;
PK_BitmapRec bm;
PK_Glyph go;
go = pk->pk_glyph;
FT_UNUSED( load_flags );
if ( !face )
{
error = FT_THROW( Invalid_Face_Handle );
goto Exit;
}
if ( !go ||
glyph_index >= (FT_UInt)( face->num_glyphs ) )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
FT_TRACE1(( "PK_Glyph_Load: glyph index %d\n", glyph_index ));
if ( glyph_index < 0 )
glyph_index = 0;
if ((glyph_index < go->code_min) || (go->code_max < glyph_index))
{
FT_TRACE2(( "invalid glyph index\n" ));
error = FT_THROW( Invalid_Argument );
goto Exit;
}
if ( !go->bm_table )
{
FT_TRACE2(( "invalid bitmap table\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* slot, bitmap => freetype, bm => pklib */
bm = pk->pk_glyph->bm_table[glyph_index];
bitmap->rows = bm.bbx_height;
bitmap->width = bm.bbx_width;
bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
if ( !bm.raster )
{
FT_TRACE2(( "invalid bitmap width\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
bitmap->pitch = (int)bm.raster ;
/* note: we don't allocate a new array to hold the bitmap; */
/* we can simply point to it */
ft_glyphslot_set_bitmap( slot, bm.bitmap );
slot->format = FT_GLYPH_FORMAT_BITMAP;
slot->bitmap_left = bm.off_x ;
slot->bitmap_top = bm.off_y ;
slot->metrics.horiAdvance = (FT_Pos) (bm.mv_x ) * 64;
slot->metrics.horiBearingX = (FT_Pos) (bm.off_x ) * 64;
slot->metrics.horiBearingY = (FT_Pos) (bm.bbx_height) * 64;
slot->metrics.width = (FT_Pos) ( bitmap->width * 64 );
slot->metrics.height = (FT_Pos) ( bitmap->rows * 64 );
ft_synthesize_vertical_metrics( &slot->metrics, bm.bbx_height * 64 );
Exit:
return error;
}
FT_LOCAL_DEF( void )
TFM_Done_Metrics( FT_Memory memory,
TFM_FontInfo fi )
{
FT_FREE(fi->width);
FT_FREE(fi->height);
FT_FREE(fi->depth);
FT_FREE( fi );
}
/* parse a TFM metrics file */
FT_LOCAL_DEF( FT_Error )
TFM_Read_Metrics( FT_Face pk_face,
FT_Stream stream )
{
TFM_Service tfm;
FT_Memory memory = stream->memory;
TFM_ParserRec parser;
TFM_FontInfo fi = NULL;
FT_Error error = FT_ERR( Unknown_File_Format );
PK_Face face = (PK_Face)pk_face;
PK_Glyph pk_glyph= face->pk_glyph;
if ( face->tfm_data )
{
FT_TRACE1(( "TFM_Read_Metrics:"
" Freeing previously attached metrics data.\n" ));
TFM_Done_Metrics( memory, (TFM_FontInfo)face->tfm_data );
face->tfm_data = NULL;
}
if ( FT_NEW( fi ) )
goto Exit;
FT_TRACE4(( "TFM_Read_Metrics: Invoking TFM_Service.\n" ));
tfm = (TFM_Service)face->tfm;
if ( tfm->tfm_parser_funcs )
{
/* Initialise TFM Service */
error = tfm->tfm_parser_funcs->init( &parser,
memory,
stream );
if ( !error )
{
FT_TRACE4(( "TFM_Read_Metrics: Initialised tfm metric data.\n" ));
parser.FontInfo = fi;
parser.user_data = pk_glyph;
error = tfm->tfm_parser_funcs->parse_metrics( &parser );
if( !error )
FT_TRACE4(( "TFM_Read_Metrics: parsing TFM metric information done.\n" ));
FT_TRACE6(( "TFM_Read_Metrics: TFM Metric Information:\n"
" Check Sum : %ld\n"
" Design Size: %ld\n"
" Begin Char : %d\n"
" End Char : %d\n"
" font_bbx_w : %d\n"
" font_bbx_h : %d\n"
" slant : %d\n", parser.FontInfo->cs, parser.FontInfo->design_size, parser.FontInfo->begin_char,
parser.FontInfo->end_char, parser.FontInfo->font_bbx_w,
parser.FontInfo->font_bbx_h, parser.FontInfo->slant ));
tfm->tfm_parser_funcs->done( &parser );
}
}
if ( !error )
{
/* Modify PK_Glyph data according to TFM metric values */
/*face->pk_glyph->font_bbx_w = fi->font_bbx_w;
face->pk_glyph->font_bbx_h = fi->font_bbx_h;
*/
face->tfm_data = fi;
}
Exit:
if ( fi )
TFM_Done_Metrics( memory, fi );
return error;
}
/*
*
* SERVICES LIST
*
*/
static const FT_ServiceDescRec pk_services[] =
{
{ FT_SERVICE_ID_PK, NULL },
{ FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_PK },
{ NULL, NULL }
};
FT_CALLBACK_DEF( FT_Module_Interface )
pk_driver_requester( FT_Module module,
const char* name )
{
FT_UNUSED( module );
return ft_service_list_lookup( pk_services, name );
}
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec pk_driver_class =
{
{
FT_MODULE_FONT_DRIVER |
FT_MODULE_DRIVER_NO_OUTLINES,
sizeof ( FT_DriverRec ),
"pk",
0x10000L,
0x20000L,
NULL, /* module-specific interface */
NULL, /* FT_Module_Constructor module_init */
NULL, /* FT_Module_Destructor module_done */
pk_driver_requester /* FT_Module_Requester get_interface */
},
sizeof ( PK_FaceRec ),
sizeof ( FT_SizeRec ),
sizeof ( FT_GlyphSlotRec ),
PK_Face_Init, /* FT_Face_InitFunc init_face */
PK_Face_Done, /* FT_Face_DoneFunc done_face */
NULL, /* FT_Size_InitFunc init_size */
NULL, /* FT_Size_DoneFunc done_size */
NULL, /* FT_Slot_InitFunc init_slot */
NULL, /* FT_Slot_DoneFunc done_slot */
PK_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */
NULL, /* FT_Face_GetKerningFunc get_kerning */
TFM_Read_Metrics, /* FT_Face_AttachFunc attach_file */
NULL, /* FT_Face_GetAdvancesFunc get_advances */
PK_Size_Request, /* FT_Size_RequestFunc request_size */
PK_Size_Select /* FT_Size_SelectFunc select_size */
};
/* END */

69
src/pk/pkdrivr.h Normal file
View File

@ -0,0 +1,69 @@
/****************************************************************************
*
* pkdrivr.h
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 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 PKDRIVR_H_
#define PKDRIVR_H_
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
#include "pk.h"
FT_BEGIN_HEADER
typedef struct PK_BitmapRec_
{
FT_Int bbx_width, bbx_height;
FT_Int off_x, off_y;
FT_Int mv_x, mv_y;
FT_Byte *bitmap;
FT_UInt raster;
} PK_BitmapRec, *PK_Bitmap;
typedef struct PK_GlyphRec_
{
FT_UInt code_min, code_max;
PK_Bitmap bm_table;
FT_Int ds, hppp, vppp;
FT_UInt font_bbx_w, font_bbx_h;
FT_UInt font_bbx_xoff, font_bbx_yoff;
} PK_GlyphRec, *PK_Glyph;
typedef struct PK_FaceRec_
{
FT_FaceRec root;
PK_Glyph pk_glyph;
const void* tfm;
const void* tfm_data;
} PK_FaceRec, *PK_Face;
FT_EXPORT_VAR( const FT_Driver_ClassRec ) pk_driver_class;
FT_END_HEADER
#endif /* PKDRIVR_H_ */
/* END */

40
src/pk/pkerror.h Normal file
View File

@ -0,0 +1,40 @@
/****************************************************************************
*
* pkerror.h
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 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 is used to define the PK error enumeration constants.
*
*/
#ifndef PKERROR_H_
#define PKERROR_H_
#include FT_MODULE_ERRORS_H
#undef FTERRORS_H_
#undef FT_ERR_PREFIX
#define FT_ERR_PREFIX PK_Err_
#define FT_ERR_BASE FT_Mod_Err_PK
#include FT_ERRORS_H
#endif /* PKERROR_H_ */
/* END */

577
src/pk/pklib.c Normal file
View File

@ -0,0 +1,577 @@
/****************************************************************************
*
* pklib.c
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 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.
*
*/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SYSTEM_H
#include FT_CONFIG_CONFIG_H
#include FT_ERRORS_H
#include FT_TYPES_H
#include "pk.h"
#include "pkdrivr.h"
#include "pkerror.h"
/**************************************************************************
*
* The macro FT_COMPONENT is used in trace mode. It is an implicit
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
* messages during execution.
*/
#undef FT_COMPONENT
#define FT_COMPONENT trace_pklib
unsigned char bits_table[] = {
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
/**************************************************************************
*
* PK font utility functions.
*
*/
long pk_read_intn(FT_Stream,int);
unsigned long pk_read_uintn(FT_Stream,int);
#define READ_UINT1( stream ) (UINT1)pk_read_uintn( stream, 1)
#define READ_UINT2( stream ) (UINT1)pk_read_uintn( stream, 2)
#define READ_UINT3( stream ) (UINT1)pk_read_uintn( stream, 3)
#define READ_UINT4( stream ) (UINT1)pk_read_uintn( stream, 4)
#define READ_UINTN( stream,n) (UINT4)pk_read_uintn( stream, n)
#define READ_INT1( stream ) (INT1)pk_read_intn( stream, 1)
#define READ_INT2( stream ) (INT1)pk_read_intn( stream, 2)
#define READ_INT4( stream ) (INT4)pk_read_intn( stream, 4)
/*
* Reading a Number from file
*/
unsigned long
pk_read_uintn(FT_Stream stream, int size)
{
unsigned long v,k;
FT_Error error;
FT_Byte tp;
v = 0L;
while (size >= 1)
{
if ( FT_READ_BYTE(tp) )
return 0; /* To be changed */
k =(unsigned long)tp;
v = v*256L + k;
--size;
}
return v;
}
long
pk_read_intn(FT_Stream stream, int size)
{
long v;
FT_Byte tp;
FT_Error error;
unsigned long z ;
if ( FT_READ_BYTE(tp) )
return 0;/* To be changed */
z= (unsigned long)tp;
v = (long)z & 0xffL;
if (v & 0x80L)
v = v - 256L;
--size;
while (size >= 1)
{
if ( FT_READ_BYTE(tp) )
return 0;/* To be changed */
z= (unsigned long)tp;
v = v*256L + z;
--size;
}
return v;
}
int pk_read_nyble_rest_cnt;
int pk_read_nyble_max_bytes;
void
pk_read_nyble_init(int max)
{
pk_read_nyble_rest_cnt = 0;
pk_read_nyble_max_bytes = max;
}
int
pk_read_nyble(FT_Stream stream)
{
static UINT1 d;
int v;
switch (pk_read_nyble_rest_cnt)
{
case 0:
d = READ_UINT1( stream );
if (--pk_read_nyble_max_bytes < 0)
return -1L;
v = d / 0x10;
d = d % 0x10;
pk_read_nyble_rest_cnt = 1;
break;
case 1:
default:
v = d;
pk_read_nyble_rest_cnt = 0;
break;
}
return v;
}
long
pk_read_packed_number(long* repeat, FT_Stream stream, int dyn_f)
{
int d, n;
long di;
entry:
d = pk_read_nyble( stream );
if (d == 0)
{
n = 0;
do
{
di = pk_read_nyble( stream );
n++;
}
while (di == 0);
for ( ; n > 0; n--)
di = di*16 + pk_read_nyble( stream );
return di - 15 + (13 - dyn_f)*16 + dyn_f;
}
if (d <= dyn_f)
return d;
if (d <= 13)
return (d - dyn_f - 1)*16 + pk_read_nyble( stream ) + dyn_f + 1;
*repeat = 1;
if (d == 14)
*repeat = pk_read_packed_number(repeat, stream, dyn_f);
goto entry;
}
int
pk_read_14(FT_Stream stream, int dyn_f, int bw, UINT4 rs, PK_Bitmap bm, long cc)
{
long x, y, x8, xm;
unsigned char *bm_ptr;
unsigned long bit16_buff;
int rest_bit16_buff;
static unsigned int mask_table[] =
{ 0xdead, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xdead };
if (rs == 0)
return 0;
x8 = bm->bbx_width / 8;
xm = bm->bbx_width % 8;
bm_ptr = bm->bitmap;
bit16_buff = READ_UINT1( stream ) << 8;
rest_bit16_buff = 8;
--rs;
for(y = 0; y < bm->bbx_height; y++)
{
for(x = 0; x < x8; x++)
{
*(bm_ptr++) = bit16_buff >> 8;
rest_bit16_buff -= 8;
bit16_buff = (bit16_buff << 8) & 0xffff;
if (rs > 0)
{
bit16_buff |= (READ_UINT1( stream ) << (8 - rest_bit16_buff));
rest_bit16_buff += 8;
--rs;
}
}
if (xm != 0)
{
*(bm_ptr++) = (bit16_buff >> 8) & mask_table[xm];
rest_bit16_buff -= xm;
bit16_buff = (bit16_buff << xm) & 0xffff;
if (rest_bit16_buff < 8)
{
if (rs > 0)
{
bit16_buff |= (READ_UINT1( stream ) << (8 - rest_bit16_buff));
rest_bit16_buff += 8;
--rs;
}
}
}
}
return 0;
}
int
pk_read_n14(FT_Stream stream, int dyn_f, int bw, UINT4 rs, PK_Bitmap bm, long cc)
{
long x, y, xx, yy, repeat;
int bits, b_p;
unsigned char *p, *p0, *p1;
pk_read_nyble_init(rs);
p = bm->bitmap;
bw = 1-bw;
bits = 0;
for (y = 0; y < bm->bbx_height; )
{
b_p = 0;
repeat = 0;
p0 = p;
for (x = 0; x < bm->bbx_width; x++)
{
if (bits == 0)
{
bw = 1-bw;
if ((bits = pk_read_packed_number(&repeat, stream, dyn_f)) < 0)
return -1;
}
if (bw == 1)
*p = *p | bits_table[b_p];
--bits;
if (++b_p >= 8)
{
b_p = 0;
p++;
}
}
if (b_p != 0)
p++;
y++;
for (yy = 0; yy < repeat; yy++)
{
p1 = p0;
for (xx = 0; xx < bm->raster; xx++)
*(p++) = *(p1++);
y++;
}
}
return 0;
}
/**************************************************************************
*
* API.
*
*/
FT_LOCAL_DEF( FT_Error )
pk_load_font(FT_Stream stream,
FT_Memory extmemory,
PK_Glyph *goptr )
{
PK_Glyph go;
UINT1 instr, pre, id;;
unsigned long ds, check_sum, hppp, vppp, k;
unsigned int flag, dny_f, bw, ess, size;
UINT4 cc, tfm, dx, dy, dm, w, h, rs;
INT4 hoff, voff, mv_x, mv_y;
long gptr;
int bc, ec, nchars, index, i;
FT_Error error = FT_Err_Ok;
FT_Memory memory = extmemory; /* needed for FT_NEW */
go = NULL;
nchars = -1;
if( FT_STREAM_SEEK( 0 ) )
goto Exit;
pre = READ_UINT1( stream );
if (pre != PK_PRE)
{
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
id = READ_UINT1( stream );
if (id != PK_ID)
{
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
k = READ_UINT1( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
ds = READ_INT4( stream );
check_sum = READ_INT4( stream );
hppp = READ_INT4( stream );
vppp = READ_INT4( stream );
/* gptr = ftell(fp); */
gptr = stream->pos;
#if 0
/* read min & max char code */
bc = 256;
ec = -1;
for (;;)
{
instr = READ_UINT1( stream );
if (instr == PK_POST)
break;
switch ((int) instr)
{
case PK_XXX1: k = (UINT4)READ_UINT1( stream ); if ( FT_STREAM_SKIP( k ) ) goto Exit; break;
case PK_XXX2: k = (UINT4)READ_UINT2( stream ); if ( FT_STREAM_SKIP( k ) ) goto Exit; break;
case PK_XXX3: k = (UINT4)READ_UINT3( stream ); if ( FT_STREAM_SKIP( k ) ) goto Exit; break;
case PK_XXX4: k = (UINT4)READ_UINT4( stream ); if ( FT_STREAM_SKIP( k ) ) goto Exit; break;
case PK_YYY: if ( FT_STREAM_SKIP( 4 ) ) goto Exit; break;
case PK_NO_OP: break;
default:
size = instr & 0x3; instr >>= 2;
ess = instr & 0x1;
if (ess == 0)
{ /* short */
rs = (UINT4)(size*256) + (UINT4)READ_UINT1( stream );
cc = (UINT4)READ_UINT1( stream );
}
else if ((ess == 1) && (size != 3))
{ /* extended short */
rs = (UINT4)(size*65536) + (UINT4)READ_UINT2( stream );
cc = (UINT4)READ_UINT1( stream );
}
else
{ /* standard */
rs = READ_UINT4( stream );
cc = (UINT4)READ_UINT4( stream );
}
if ( FT_STREAM_SKIP( rs ) )
goto Exit;
if (cc < bc)
bc = cc;
if (cc > ec)
ec = cc;
break;
}
}
#else
bc = 0;
ec = 255;
#endif
nchars = ec - bc + 1;
if( FT_ALLOC(go, sizeof(PK_GlyphRec)) )
goto Exit;
if( FT_ALLOC_MULT(go->bm_table, sizeof(PK_BitmapRec), nchars) )
goto Exit;
for (i = 0; i < nchars; i++)
go->bm_table[i].bitmap = NULL;
go->ds = (FT_UInt)ds/(1<<20);
go->hppp = (FT_UInt)hppp/(1<<16);
go->vppp = (FT_UInt)vppp/(1<<16);
go->font_bbx_w = 0;
go->font_bbx_h = 0;
go->font_bbx_xoff = 0;
go->font_bbx_yoff = 0;
go->code_min = bc;
go->code_max = ec;
/* read glyphs */
/* fseek(fp, gptr, SEEK_SET); */
if( FT_STREAM_SEEK( gptr ) )
goto Exit;
for (;;)
{
if ((instr = READ_UINT1( stream )) == PK_POST)
break;
switch ((int)instr)
{
case PK_XXX1:
k = (UINT4)READ_UINT1( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
break;
case PK_XXX2:
k = (UINT4)READ_UINT2( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
break;
case PK_XXX3:
k = (UINT4)READ_UINT3( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
break;
case PK_XXX4:
k = (UINT4)READ_UINT4( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
break;
case PK_YYY:
if ( FT_STREAM_SKIP( 4 ) )
goto Exit;
break;
case PK_NO_OP:
break;
default:
flag = instr;
size = flag % 0x04; flag = flag >> 2;
ess = flag % 0x02; flag = flag >> 1;
bw = flag % 0x02; flag = flag >> 1;
dny_f = flag % 0x10;
if (ess == 0)
{ /* short */
rs = (UINT4)(size*256) + (UINT4)READ_UINT1( stream ) - (UINT4)8;
cc = (UINT4)READ_UINT1( stream );
tfm = (UINT4)READ_UINT3( stream );
dm = (UINT4)READ_UINT1( stream );
w = (UINT4)READ_UINT1( stream );
h = (UINT4)READ_UINT1( stream );
hoff = (INT4)READ_INT1( stream );
voff = (INT4)READ_INT1( stream );
mv_x = dm;
mv_y = 0;
}
else if ((ess == 1) && (size != 3))
{ /* extended short */
rs = (UINT4)(size*65536) + (UINT4)READ_UINT2( stream ) - (UINT4)13;
cc = (UINT4)READ_UINT1( stream );
tfm = (UINT4)READ_UINT3( stream );
dm = (UINT4)READ_UINT2( stream );
w = (UINT4)READ_UINT2( stream );
h = (UINT4)READ_UINT2( stream );
hoff = (INT4)READ_INT2( stream );
voff = (INT4)READ_INT2( stream );
mv_x = dm;
mv_y = 0;
}
else
{ /* standard */
rs = READ_UINT4( stream ) - (UINT4)28;
cc = READ_UINT4( stream );
tfm = READ_UINT4( stream );
dx = READ_UINT4( stream );
dy = READ_UINT4( stream );
w = READ_UINT4( stream );
h = READ_UINT4( stream );
hoff = READ_INT4( stream );
voff = READ_INT4( stream );
mv_x = (FT_UInt)dx/(FT_UInt)(1<<16);
mv_y = (FT_UInt)dy/(FT_UInt)(1<<16);
}
if ((cc < go->code_min) || (go->code_max < cc))
{
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
index = cc - go->code_min;
go->bm_table[index].bbx_width = w;
go->bm_table[index].bbx_height = h;
go->bm_table[index].raster = (w+7)/8;
go->bm_table[index].off_x = -hoff;
go->bm_table[index].off_y = voff;
go->bm_table[index].mv_x = mv_x;
go->bm_table[index].mv_y = mv_y;
go->bm_table[index].bitmap = (unsigned char*)malloc(h*((w+7)/8));
if (go->bm_table[index].bitmap == NULL)
{
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
memset(go->bm_table[index].bitmap, 0, h*((w+7)/8));
if (dny_f == 14)
{
if (pk_read_14(stream, dny_f, bw, rs, &(go->bm_table[index]), cc) < 0)
{
/* vf_error = VF_ERR_ILL_FONT_FILE; (FOR TRACING) */
FT_ERROR(( "pk_load_font: error in `pk_read_14'\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
}
else
{
if (pk_read_n14(stream, dny_f, bw, rs, &(go->bm_table[index]), cc) < 0)
{
/* vf_error = VF_ERR_ILL_FONT_FILE; (FOR TRACING) */
FT_ERROR(( "pk_load_font: error in `pk_read_n14'\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
}
if (go->font_bbx_w < w)
go->font_bbx_w = w;
if (go->font_bbx_h < h)
go->font_bbx_h = h;
if (go->font_bbx_xoff > -hoff)
go->font_bbx_xoff = -hoff;
if (go->font_bbx_yoff > (voff - h))
go->font_bbx_yoff = (voff - h);
}
}
*goptr = go;
return error;
Exit:
if (go != NULL)
{
for (i = 0; i < nchars; i++)
{
if (go->bm_table[i].bitmap != NULL)
FT_FREE(go->bm_table[i].bitmap);
}
FT_FREE(go->bm_table);
FT_FREE(go);
}
return error;
}
FT_LOCAL_DEF( void )
pk_free_font( PK_Face face )
{
FT_Memory memory = FT_FACE( face )->memory;
PK_Glyph go = face->pk_glyph;
FT_UInt nchars = FT_FACE( face )->num_glyphs,i;
if ( !go )
return;
if( go->bm_table )
{
for (i = 0; i < nchars; i++)
{
if (go->bm_table[i].bitmap != NULL)
FT_FREE(go->bm_table[i].bitmap);
}
}
FT_FREE(go->bm_table);
FT_FREE(go);
}
/* END */

70
src/pk/rules.mk Normal file
View File

@ -0,0 +1,70 @@
#
# FreeType 2 PK driver configuration rules
#
# Copyright 1996-2018 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.
# pk driver directory
#
PK_DIR := $(SRC_DIR)/pk
PK_COMPILE := $(CC) $(ANSIFLAGS) \
$I$(subst /,$(COMPILER_SEP),$(PK_DIR)) \
$(INCLUDE_FLAGS) \
$(FT_CFLAGS)
# pk driver sources (i.e., C files)
#
PK_DRV_SRC := $(PK_DIR)/pklib.c \
$(PK_DIR)/pkdrivr.c
# pk driver headers
#
PK_DRV_H := $(PK_DIR)/pk.h \
$(PK_DIR)/pkdrivr.h \
$(PK_DIR)/pkerror.h
# pk driver object(s)
#
# PK_DRV_OBJ_M is used during `multi' builds
# PK_DRV_OBJ_S is used during `single' builds
#
PK_DRV_OBJ_M := $(PK_DRV_SRC:$(PK_DIR)/%.c=$(OBJ_DIR)/%.$O)
PK_DRV_OBJ_S := $(OBJ_DIR)/pk.$O
# pk driver source file for single build
#
PK_DRV_SRC_S := $(PK_DIR)/pk.c
# pk driver - single object
#
$(PK_DRV_OBJ_S): $(PK_DRV_SRC_S) $(PK_DRV_SRC) $(FREETYPE_H) $(PK_DRV_H)
$(PK_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(PK_DRV_SRC_S))
# pk driver - multiple objects
#
$(OBJ_DIR)/%.$O: $(PK_DIR)/%.c $(FREETYPE_H) $(PK_DRV_H)
$(PK_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
# update main driver object lists
#
DRV_OBJS_S += $(PK_DRV_OBJ_S)
DRV_OBJS_M += $(PK_DRV_OBJ_M)
# EOF

30
src/tfm/Jamfile Normal file
View File

@ -0,0 +1,30 @@
# FreeType 2 src/tfm Jamfile
#
# Copyright 2001-2018 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.
SubDir FT2_TOP $(FT2_SRC_DIR) tfm ;
{
local _sources ;
if $(FT2_MULTI)
{
_sources = tfmmod
;
}
else
{
_sources = tfm ;
}
Library $(FT2_LIB) : $(_sources).c ;
}
# end of src/tfm Jamfile

23
src/tfm/module.mk Normal file
View File

@ -0,0 +1,23 @@
#
# FreeType 2 TFM module definition
#
# Copyright 1996-2018 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.
FTMODULE_H_COMMANDS += TFM_MODULE
define TFM_MODULE
$(OPEN_DRIVER) FT_Module_Class, tfm_module_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)tfm $(ECHO_DRIVER_DESC)TFM helper module$(ECHO_DRIVER_DONE)
endef
# EOF

72
src/tfm/rules.mk Normal file
View File

@ -0,0 +1,72 @@
#
# FreeType 2 TFM driver configuration rules
#
# Copyright 1996-2018 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.
# TFM driver directory
#
TFM_DIR := $(SRC_DIR)/tfm
# compilation flags for the driver
#
TFM_COMPILE := $(CC) $(ANSIFLAGS) \
$I$(subst /,$(COMPILER_SEP),$(TFM_DIR)) \
$(INCLUDE_FLAGS) \
$(FT_CFLAGS)
# TFM driver sources (i.e., C files)
#
TFM_DRV_SRC := $(TFM_DIR)/tfmmod.c \
$(TFM_DIR)/tfmobjs.c \
# TFM driver headers
#
TFM_DRV_H := $(TFM_DRV_SRC:%c=%h) \
$(TFM_DIR)/tfmerr.h \
# TFM driver object(s)
#
# TFM_DRV_OBJ_M is used during `multi' builds.
# TFM_DRV_OBJ_S is used during `single' builds.
#
TFM_DRV_OBJ_M := $(TFM_DRV_SRC:$(TFM_DIR)/%.c=$(OBJ_DIR)/%.$O)
TFM_DRV_OBJ_S := $(OBJ_DIR)/tfm.$O
# TFM driver source file for single build
#
TFM_DRV_SRC_S := $(TFM_DIR)/tfm.c
# TFM driver - single object
#
$(TFM_DRV_OBJ_S): $(TFM_DRV_SRC_S) $(TFM_DRV_SRC) \
$(FREETYPE_H) $(TFM_DRV_H)
$(TFM_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(TFM_DRV_SRC_S))
# TFM driver - multiple objects
#
$(OBJ_DIR)/%.$O: $(TFM_DIR)/%.c $(FREETYPE_H) $(TFM_DRV_H)
$(TFM_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
# update main driver object lists
#
DRV_OBJS_S += $(TFM_DRV_OBJ_S)
DRV_OBJS_M += $(TFM_DRV_OBJ_M)
# EOF

26
src/tfm/tfm.c Normal file
View File

@ -0,0 +1,26 @@
/****************************************************************************
*
* tfm.c
*
* FreeType auxiliary TFM module.
*
* Copyright 1996-2018 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.
*
*/
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "tfmmod.c"
#include "tfmobjs.c"
/* END */

42
src/tfm/tfmerr.h Normal file
View File

@ -0,0 +1,42 @@
/****************************************************************************
*
* tfmerr.h
*
* FreeType auxiliary TFM module error codes (specification only).
*
* Copyright 2001-2018 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 is used to define the TFM auxiliary module error enumeration
* constants.
*
*/
#ifndef TFMERR_H_
#define TFMERR_H_
#include FT_MODULE_ERRORS_H
#undef FTERRORS_H_
#undef FT_ERR_PREFIX
#define FT_ERR_PREFIX TFM_Err_
#define FT_ERR_BASE FT_Mod_Err_TFM
#include FT_ERRORS_H
#endif /* TFMERR_H_ */
/* END */

56
src/tfm/tfmmod.c Normal file
View File

@ -0,0 +1,56 @@
/****************************************************************************
*
* tfmmod.c
*
* FreeType auxiliary TFM module.
*
* Copyright 2000-2018 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.
*
*/
#include <ft2build.h>
#include "tfmmod.h"
#include "tfmobjs.h"
FT_CALLBACK_TABLE_DEF
const TFM_Parser_FuncsRec tfm_parser_funcs =
{
tfm_init, /* init */
tfm_parse_metrics, /* parse metrics */
tfm_close, /* done */
};
static
const TFM_Interface tfm_interface =
{
&tfm_parser_funcs,
};
FT_CALLBACK_TABLE_DEF
const FT_Module_Class tfm_module_class =
{
0,
sizeof ( FT_ModuleRec ),
"tfm",
0x20000L,
0x20000L,
&tfm_interface, /* module-specific interface */
(FT_Module_Constructor)NULL, /* module_init */
(FT_Module_Destructor) NULL, /* module_done */
(FT_Module_Requester) NULL /* get_interface */
};
/* END */

39
src/tfm/tfmmod.h Normal file
View File

@ -0,0 +1,39 @@
/****************************************************************************
*
* tfmmod.h
*
* FreeType auxiliary TFM module.
*
* Copyright 2000-2018 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 TFMMOD_H_
#define TFMMOD_H_
#include <ft2build.h>
#include FT_MODULE_H
#include FT_INTERNAL_TFM_H
FT_BEGIN_HEADER
FT_EXPORT_VAR( const FT_Module_Class ) tfm_driver_class;
FT_END_HEADER
#endif /* TFMMOD_H_ */
/* END */

357
src/tfm/tfmobjs.c Normal file
View File

@ -0,0 +1,357 @@
/****************************************************************************
*
* tfmobjs.c
*
* FreeType auxiliary TFM module.
*
* Copyright 1996-2018 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.
*
*/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_TFM_H
#include "tfmobjs.h"
#include "tfmmod.h"
#include "tfmerr.h"
/**************************************************************************
*
* The macro FT_COMPONENT is used in trace mode. It is an implicit
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
* messages during execution.
*/
#undef FT_COMPONENT
#define FT_COMPONENT trace_tfmobjs
/**************************************************************************
*
* Global TFM parameters.
*
*/
#define tfm_size 30000 /* maximum length of tfm data, in bytes */
#define lig_size 5000 /* maximum length of lig kern program, in words */
#define hash_size 5003
/**************************************************************************
*
* TFM font utility functions.
*
*/
long tfm_read_intn(FT_Stream,int);
unsigned long tfm_read_uintn(FT_Stream,int);
#define READ_UINT1( stream ) (FT_ULong)tfm_read_uintn( stream, 1)
#define READ_UINT2( stream ) (FT_ULong)tfm_read_uintn( stream, 2)
#define READ_UINT4( stream ) (FT_ULong)tfm_read_uintn( stream, 4)
#define READ_INT4( stream ) (FT_Long)tfm_read_intn( stream, 4)
/*
* Reading a Number from file
*/
unsigned long
tfm_read_uintn(FT_Stream stream, int size)
{
unsigned long v,k;
FT_Error error = FT_Err_Ok;
FT_Byte tp;
v = 0L;
while (size >= 1)
{
if ( FT_READ_BYTE(tp) )
return 0;
k =(unsigned long)tp;
v = v*256L + k;
--size;
}
return v;
}
long
tfm_read_intn(FT_Stream stream, int size)
{
long v;
FT_Byte tp;
FT_Error error= FT_Err_Ok;
unsigned long z ;
if ( FT_READ_BYTE(tp) )
return 0;
z= (unsigned long)tp;
v = (long)z & 0xffL;
if (v & 0x80L)
v = v - 256L;
--size;
while (size >= 1)
{
if ( FT_READ_BYTE(tp) )
return 0;
z= (unsigned long)tp;
v = v*256L + z;
--size;
}
return v;
}
/**************************************************************************
*
* API.
*
*/
FT_LOCAL_DEF( FT_Error )
tfm_init( TFM_Parser parser,
FT_Memory memory,
FT_Stream stream )
{
parser->memory = memory;
parser->stream = stream;
parser->FontInfo = NULL;
parser->user_data = NULL;
return FT_Err_Ok;
}
FT_LOCAL( void )
tfm_close( TFM_Parser parser )
{
FT_UNUSED( parser );
/* nothing */
}
FT_LOCAL_DEF( FT_Error )
tfm_parse_metrics( TFM_Parser parser )
{
FT_Memory memory = parser->memory;
TFM_FontInfo fi = parser->FontInfo;
FT_Stream stream = parser->stream;
FT_Error error = FT_ERR( Syntax_Error );
FT_ULong lf, lh, nc, nci;
FT_ULong offset_char_info, offset_param;
FT_ULong nw, nh, nd, ni, nl, nk, ne, np, bc, ec;
FT_Long *w, *h, *d;
FT_ULong *ci, v;
FT_ULong i;
FT_Long bbxw, bbxh, xoff, yoff;
if ( !fi )
return FT_THROW( Invalid_Argument );
fi->width = NULL;
fi->height = NULL;
fi->depth = NULL;
ci = NULL;
w = NULL;
h = NULL;
d = NULL;
fi->font_bbx_w = 0.0;
fi->font_bbx_h = 0.0;
fi->font_bbx_xoff = 0.0;
fi->font_bbx_yoff = 0.0;
if( FT_STREAM_SEEK( 0 ) )
return error;
/* Checking the correctness of the TFM file */
if( READ_UINT1( stream ) > 127 )
{
FT_ERROR(( "Malformed TFM file: The first byte of the input file exceeds 127!\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
if( FT_STREAM_SEEK( 0 ) )
return error;
lf = READ_UINT2( stream );
lh = READ_UINT2( stream );
bc = READ_UINT2( stream );
ec = READ_UINT2( stream );
nw = READ_UINT2( stream );
nh = READ_UINT2( stream );
nd = READ_UINT2( stream );
ni = READ_UINT2( stream );
nl = READ_UINT2( stream );
nk = READ_UINT2( stream );
ne = READ_UINT2( stream );
np = READ_UINT2( stream );
/* Uncomment this to check for the tfm file's header info if this program returns malformed tfm file */
/*
FT_TRACE6(( "tfm_parse_metrics: First 24 bytes in the tfm file:\n"
" lf : %ld\n"
" lh : %ld\n"
" bc : %d\n"
" ec : %d\n"
" nw : %d\n"
" nh : %d\n"
" nd : %d\n"
" ni : %d\n"
" nl : %d\n"
" nk : %d\n"
" ne : %d\n"
" np : %d\n", lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np ));
*/
if( lf == 0 || ((4*lf) - 1) > tfm_size)
{
FT_ERROR(( "Malformed TFM file: The file claims to have length zero, but that's impossible!\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
if(lh < 2)
{
FT_ERROR(( "Malformed TFM file: The header length is only %ld\n",lh ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
if( nl > lig_size )
{
FT_ERROR(( "Malformed TFM file: The lig/kern program is longer than I can handle!\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
if( ne > 256 )
{
FT_ERROR(( "Malformed TFM file: There are %ld extensible recipes!\n",ne ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
if ( ((signed)(fi->begin_char-1) > (signed)fi->end_char) ||
( fi->end_char > 255) ||
( ne > 256 ) )
{
FT_ERROR(( "tfm_parse_metrics: Incorrect header information in `tfm' file.\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
if ( lf != 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np )
{
FT_ERROR(( "tfm_parse_metrics: Incorrect header information in `tfm' file.\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
fi->begin_char = bc;
fi->end_char = ec;
fi->cs = READ_INT4( stream ); /* Check Sum */
fi->ds = READ_INT4( stream ); /* Design Size */
fi->design_size = (FT_ULong)((double)(fi->ds)/(double)(1<<20));
printf("fi->cs is %ld\n",fi->cs);
if( fi->cs <= 0 )
{
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
nc = fi->end_char - fi->begin_char + 1;
nci = nc;
ci = (FT_ULong*)calloc(nci, sizeof(FT_ULong));
w = (FT_Long*)calloc(nw, sizeof(FT_ULong));
h = (FT_Long*)calloc(nh, sizeof(FT_ULong));
d = (FT_Long*)calloc(nd, sizeof(FT_ULong));
if ((ci == NULL) || (w == NULL) || (h == NULL) || (d == NULL))
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
offset_char_info = 4*(6+lh);
if( FT_STREAM_SEEK( offset_char_info ) ) /* Skip over coding scheme and font family name */
goto Exit;
for (i = 0; i < nci; i++)
ci[i] = READ_UINT4( stream );
offset_param = stream->pos + 4*(nw + nh + nd + ni + nl + nk + ne);
for (i = 0; i < nw; i++)
w[i] = READ_INT4( stream );
for (i = 0; i < nh; i++)
h[i] = READ_INT4( stream );
for (i = 0; i < nd; i++)
d[i] = READ_INT4( stream );
fi->width = (FT_Long*)calloc(nc, sizeof(FT_Long));
fi->height = (FT_Long*)calloc(nc, sizeof(FT_Long));
fi->depth = (FT_Long*)calloc(nc, sizeof(FT_Long));
if ((fi->width == NULL) || (fi->height == NULL) || (fi->depth == NULL))
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
bbxw = 0;
bbxh = 0;
xoff = 0;
yoff = 0;
for (i = 0; i < nc; i++)
{
v = ci[i] / 0x10000L;
fi->depth[i] = d[v & 0xf]; v >>= 4;
fi->height[i] = h[v & 0xf]; v >>= 4;
fi->width[i] = w[v & 0xff];
if (bbxw < fi->width[i])
bbxw = fi->width[i];
if (bbxh < (fi->height[i] + fi->depth[i]))
bbxh = fi->height[i] + fi->depth[i];
if (yoff > -fi->depth[i])
yoff = -fi->depth[i];
}
fi->font_bbx_w = (FT_ULong)(fi->design_size * ((double)bbxw / (double)(1<<20)));
fi->font_bbx_h = (FT_ULong)(fi->design_size * ((FT_ULong)bbxh / (double)(1<<20)));
fi->font_bbx_xoff = (FT_ULong)(fi->design_size * ((double)xoff / (double)(1<<20)));
fi->font_bbx_yoff = (FT_ULong)(fi->design_size * ((double)yoff / (double)(1<<20)));
if( FT_STREAM_SEEK( offset_param ) )
return error;
if (FT_READ_ULONG(fi->slant) )
return error;
fi->slant = (FT_ULong)((double)fi->slant/(double)(1<<20));
Exit:
FT_FREE(ci);
FT_FREE(w);
FT_FREE(h);
FT_FREE(d);
return error;
}
/* END */

53
src/tfm/tfmobjs.h Normal file
View File

@ -0,0 +1,53 @@
/****************************************************************************
*
* tfmobjs.h
*
* FreeType auxiliary TFM module.
*
* Copyright 1996-2018 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 TFMOBJS_H_
#define TFMOBJS_H_
#include <ft2build.h>
#include "tfmmod.h"
FT_BEGIN_HEADER
#include <ft2build.h>
#include FT_INTERNAL_TFM_H
FT_BEGIN_HEADER
/* Initialise the TFM stream */
FT_LOCAL( FT_Error )
tfm_init( TFM_Parser parser,
FT_Memory memory,
FT_Stream stream );
/* Parse TFM metric data */
FT_LOCAL( FT_Error )
tfm_parse_metrics( TFM_Parser parser );
FT_LOCAL( void )
tfm_close( TFM_Parser parser );
FT_END_HEADER
#endif /* TFMOBJS_H_ */
/* END */