Compare commits

...

81 Commits

Author SHA1 Message Date
Parth Wazurkar 1a9a851672 [gf] Some more fixes. 2018-09-08 21:27:32 +05:30
Parth Wazurkar 38f652dbd6 [gf] Formatting fixes. 2018-09-08 21:15:45 +05:30
Parth Wazurkar 52fc5d1819 [tfm] Fix typo. 2018-08-15 11:41:45 +05:30
Parth Wazurkar 08a8e43fb4 [gf] Resolve failing of `GF_CMap'.
* src/gf/gfdrivr.c(gf_cmap_char_{index, next}): Use `linear search'
instead of `binary search' in the encoding table as it will always
be unsorted.
2018-08-15 02:01:12 +05:30
Parth Wazurkar 96db629b8e [pk] Resolve failing of `PK_CMap'.
* src/pk/pkdrivr.c(pk_cmap_char_{index, next}): Use `linear search'
instead of `binary search' in the encoding table as it will always
be unsorted.

* src/pk/pklib.c: Resolve issues occurred in the previous commit
which caused errors in glyph loading on `ft2-demos'.
2018-08-15 02:00:17 +05:30
Parth Wazurkar 401ce90bdf [pk] Fixes.
* src/pk/pkdrivr.c(PK_Glyph_Load):
  - Remove unnecessary test for code_{min, max} values.
  - Use pointer to get metric values.

* src/pk/pklib.c(pk_load_font):
  - Improve tracing.
  - Remove unnecessary variables and parameters.
2018-08-13 10:11:31 +05:30
Parth Wazurkar df8cb68d11 [gf] Fixes in `GF_Glyph_Load' function.
* src/gf/gfdrivr.c(GF_Glyph_Load):
  - Use pointer to extract metric values from `bm_table'.
  - Remove unnecessary test for `glyph_index'.
2018-08-12 23:30:04 +05:30
Parth Wazurkar e3a53c1a14 [pk] Change `cmap' encoding scheme.
* src/pk/pkdrivr.c(PK_Face_Init):
  - Change `pk_cmap_class' functions to use new encoding
    scheme.
  - Set charmap to `0: synthetic, platform 0, encoding  0
    language 0' values.
2018-08-12 23:17:03 +05:30
Parth Wazurkar 2097c52603 [gf] Fix invalid free operation.
* src/gf/gfdrivr.c(GF_Face_Done): Fix the free operation
which caused seg fault after `gf driver' returned `not a gf file'.
2018-08-12 22:46:38 +05:30
Parth Wazurkar 9c3ffded1b [gf] Important Fixes.
* As suggested here:

    http://lists.gnu.org/archive/html/freetype-devel/2018-08/msg00030.html
2018-08-12 15:58:49 +05:30
Parth Wazurkar 743b415ca9 [gf] Change `cmap' encoding scheme.
* src/gf/gfdrivr.c(GF_Face_Init):
  - Change `gf_cmap_class' functions to use new encoding
    scheme.
  - Set charmap to `0: synthetic, platform 0, encoding  0
    language 0' values.

* src/gf/gflib.c(gf_set_encodings, gf_load_font): Modify
  to set encoding so as to load glyphs in the order they appear
  in the font file.
2018-08-12 11:36:33 +05:30
Parth Wazurkar eba29d801e [gf] Fixes. 2018-08-11 02:15:59 +05:30
Parth Wazurkar 32028ffb55 [pk] Fix oversight.
* src/pk/pkdrivr.c(TFM_Read_Metrics): Fix oversight, to
resolve the memory leakage errors which occured while
attaching a `tfm' file.
2018-08-10 18:58:41 +05:30
Parth Wazurkar 540b1aca44 [gf] Fix typo. 2018-08-10 18:18:07 +05:30
Parth Wazurkar fd2b16f01f [tfm] Resolve memory leak errors.
* src/tfm/tfmobjs.c(tfm_close): Remove double freeing
of `stream' object.

* src/gf/gfdrivr.c(TFM_Read_Metrics): Fix oversight
errors.
2018-08-10 18:11:10 +05:30
Parth Wazurkar b76b34ef5d [gf, pk] Modify `attach_file' function.
* src/gf/gfdrivr.c(TFM_Read_Metrics): Modify to accomodate changes
in the `tfm' module.

* src/pk/pkdrivr.c(TFM_Read_Metrics): Ditto.
2018-08-08 10:34:38 +05:30
Parth Wazurkar b583b42c85 [tfm] Modify module functions as per `tftopl'.
* src/tfm/tfmobjs.c(tfm_parse_metrics):
  - Modify the metric extraction functions.
  - Add checking for `tfm' file so that an error will be
    returned if the font file is found *malformed*.
2018-08-08 10:17:06 +05:30
Parth Wazurkar 903a066214 [tfm] Modify `tfm_interface' definition.
* src/tfm/tfmmod.c: Add `TFM_Parser_FuncsRec' implementation
in `tfm_interface'.
2018-08-08 09:54:58 +05:30
Parth Wazurkar 8d32347f78 [tfm] Modify `TFM_ServiceRec' and `TFM_FontInfoRec' definitions.
* include/freetype/internal/tfm.h(TFM_FontInfoRec): Change data types
to accomodate changes.

* include/freetype/internal/tfm.h(TFM_ServiceRec): Create `TFM_Parse_FuncsRec'
to hold the `tfm' module functions.
2018-08-08 09:41:52 +05:30
Parth Wazurkar 2f59a4c8a9 [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-08 09:22:04 +05:30
Parth Wazurkar a6bb748265 [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-08 09:21:38 +05:30
Parth Wazurkar 859d6c6dc3 [pk] Modify `pk' files' header. 2018-08-04 16:22:47 +05:30
Parth Wazurkar fbaaeb812b [pk] Cleanup commit.
* Remove all the unnecessary typedefs and comments.
* Rename `pk' files' headers.
2018-08-04 13:48:59 +05:30
Parth Wazurkar 5e0acc45bf [pk] Fix metric extraction functions.
* src/pk/pklib.c(pk_load_font): Change `READ_UINT4' function
to `READ_INT4' to *correctly* extract information in font
file's header.

* Now pk driver displays glyphs in ftview.
2018-08-02 01:04:26 +05:30
Parth Wazurkar 383752cd98 [tfm] Fixes. 2018-08-02 00:55:08 +05:30
Parth Wazurkar 3d5f300f0c [pk] Improve error handling.
* src/pk/pklib.c(pk_load_font): Do it.
2018-08-01 00:28:10 +05:30
Parth Wazurkar 1931328a34 [pk] Define `attach_file' function in `pk_driver_class'.
* src/pk/pkdrivr.c: Define `attach_file' function, `TFM_Read_Metrics'
in `pk_driver_class' to extract font metric information from `tfm'
file.

* src/pk/pkdrivr.c(PK_Face_Init): Initialise `TFM_Service' by calling
`FT_Get_Module_Interface'.
2018-08-01 00:25:34 +05:30
Parth Wazurkar 883e6af448 [pk] Add `tfm' element in `PK_FaceRec'.
* src/pk/pkdrivr.h: Add `tfm' element in the `PK_FaceRec'
structure to accomodate the tfm metric values.
2018-08-01 00:04:25 +05:30
Parth Wazurkar 3511c3c3c3 [gf, pk] Minor Fixes for some compilation errors. 2018-07-31 01:28:02 +05:30
Parth Wazurkar aa77f5af45 [pk] Remove indentation errors. 2018-07-31 00:03:10 +05:30
Parth Wazurkar f909b86c84 [pk] Add pk services. 2018-07-31 00:00:28 +05:30
Parth Wazurkar e4ec41fc02 [pk] Improve error checking in font file.
* src/pk/pklib.c (pk_load_font): Add check for
`PK_ID' and `PK_PRE' command in the font file.
2018-07-30 23:57:57 +05:30
Parth Wazurkar ab75cfedd0 [pk] Fixes. 2018-07-30 23:57:00 +05:30
Parth Wazurkar 460fe90b59 [pk] Define `pk_driver_class' functions.
* src/pk/pkdrivr.c: Define all the `pk_driver_class'
functions.
2018-07-30 23:53:37 +05:30
Parth Wazurkar 20230216aa [pk] Define `pk_cmap_class' functions. 2018-07-30 23:53:23 +05:30
Parth Wazurkar 0d109109df [pk] Define `pk' font loader functions.
* src/pk/pk.h: Add `pk' format specific opcodes.

* src/pk/pklib.c: Define `pk_font_load', `pk_free_font'
and other format specific utility functions.
2018-07-30 23:53:07 +05:30
Parth Wazurkar 24f39cba3d [pk] Define PK_FaceRec and other format specific structures.
* src/pk/pkdrivr.h: Define PK_Bitmap and PK_Glyph
structures to hold `pk' format specific values and
define PK_FaceRec to accomodate them.
2018-07-30 23:52:53 +05:30
Parth Wazurkar 1316b813fd [pk] Initialise pk driver files and Makefiles. 2018-07-30 23:52:39 +05:30
Parth Wazurkar 3959431aab [pk,vf] Initialise pk and vf driver repositories. 2018-07-30 23:52:23 +05:30
Parth Wazurkar d3a78786b5 [tfm] Fixes. 2018-07-30 23:47:51 +05:30
Parth Wazurkar 8302c96c83 [gf] Improve data types of some variables. 2018-07-30 23:47:51 +05:30
Parth Wazurkar 73338b9c10 [gf] Initialise `TFM Service' and add tracing.
* src/gf/gfdrivr.c (GF_Face_Init): Call `FT_Get_Module_Interface'
to initialise `tfm' module.

* src/gf/gfdrivr.c (TFM_Read_Metrics): Add tracing messages.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 7939499452 [tfm] Define the `tfm_interface' functions.
* src/tfm/tfmobjs.c: Do it.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 4b9c1b2b1b [tfm] Initialise makefiles. 2018-07-30 23:47:51 +05:30
Parth Wazurkar 2d693b5a2c [tfm] Define `tfm_module_class' and `tfm_interface'.
* src/tfm/tfmmod.c: Do it.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 146b7febbd [tfm] Add new `tfm' auxiliary module.
* include/freetype/internal/tfm.h:
  - Add TFM_FontInfoRec to accomodate TFM metric data.
  - Define TFM_ParserRec to parse the metric data from
    input `tfm' file.
  - Define TFM_ServiceRec to provide functions to do it.
2018-07-30 23:47:51 +05:30
Parth Wazurkar b36649fd86 [gf] Define `attach_file' function in `gf_driver_class'.
* src/gf/gfdrivr.c: Define `attach_file' function, `TFM_Read_Metrics'
in `gf_driver_class' to extract font metric information from `tfm'
file using a new `TFM' auxiliary module.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 0f41489a09 [gf] Add `tfm' element in `GF_FaceRec'.
* src/gf/gfdrivr.h: Add `tfm' element in the `GF_FaceRec'
structure to accomodate the tfm metric values.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 5b32e1a9d9 [gf] Cleanup commit.
* Rename `gf' files' header.
* Remove all the unnecessary typedefs and
switch to FT specific ones.
* Remove unnecessary comments.
2018-07-30 23:47:51 +05:30
Parth Wazurkar fcef64dde7 [gf] Register gf services. 2018-07-30 23:47:51 +05:30
Parth Wazurkar 9da5d09e26 [gf] Create gf services.
* src/gf/gfdrivr.c: Define gf services descriptor
table and `gf_driver_requestor' function.
2018-07-30 23:47:51 +05:30
Parth Wazurkar d9d157e556 [gf] Fixes. 2018-07-30 23:47:51 +05:30
Parth Wazurkar 69124b5979 [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-30 23:47:51 +05:30
Parth Wazurkar d9cdc15d80 [gf] Minor Fixes. 2018-07-30 23:47:51 +05:30
Parth Wazurkar b619592a8f [gf] Add support for parsing `xxx' and `yyy' commands.
* Now gf driver supports all the `gf' 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-30 23:47:51 +05:30
Parth Wazurkar 256c625c6e [gf] Modify Glyph slot metric values. 2018-07-30 23:47:51 +05:30
Parth Wazurkar 10775a138e [gf] Fix memory leak errors.
* src/gf/gfdrivr.c: Improve GF_Face_Done and
GF_Face_Init functions to fix memory leak errors.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 2c3b6390a5 [gf] Fix gf_free_font function errors.
* src/gf/gflib.c (gf_free_font): Fix errors in gf_free_font
function.

* src/gf/gfdrir.c (GF_Glyph_Load): Improve slot metric
values.
2018-07-30 23:47:51 +05:30
Parth Wazurkar f7f18d792e [gf] Minor Fixes. 2018-07-30 23:47:51 +05:30
Parth Wazurkar 98b83f08aa [gf] Improve error handling and minor fixes.
* src/gf/gflib.c : Use `Unknown_File_Format' instead
of `Invalid_File_Format'.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 9efa36c8b0 [gf] Use Unicode charmap and modify slot metric values.
* src/gf/gfdrivr.c(GF_Face_Init): Use Unicode charmap and
modify FT_Bitmap_Size values.

* src/gf/gfdrivr.c(GF_Glyph_Load): Modify FT_GlyphSlot and
FT_Bitmap values.
2018-07-30 23:47:51 +05:30
Parth Wazurkar d0c08730c7 [gf] Add tracing and error handling.
* src/gf/gfdrivr.c, src/gf/gflib.c: Add FT_TRACEX and
FT_ERROR messages for debugging.

* src/gf/module.mk: Fixes to make output of first `make'
call prettier.
2018-07-30 23:47:51 +05:30
Parth Wazurkar f2c92f1173 [gf] Add gf components to FT trace definitions.
* include/freetype/internal/fttrace.h: Add gf driver
components, gfdriver and gflib to FT trace definitions.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 34d588002c [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-30 23:47:51 +05:30
Parth Wazurkar 2439cfb7e9 [gf] Minor fixes. 2018-07-30 23:47:51 +05:30
Parth Wazurkar f7f6a981c4 [gf] FT stream support for gf driver.
* src/gf/gflib.c : Convert all the file functions to
FT stream functions.
2018-07-30 23:47:51 +05:30
Parth Wazurkar c80039d715 [gf] Define FT driver variables with gftype values.
* src/gf/gfdrivr.c : Define the FT driver variables
in all the functions with gftype values from the font file.
2018-07-30 23:47:51 +05:30
Parth Wazurkar 522853e565 [gf] Removed VFlib specific code and refactored to FT. 2018-07-30 23:47:50 +05:30
Parth Wazurkar ea69f5127c [gf] Convert block comments to `light' style in gf files. 2018-07-30 23:47:50 +05:30
Parth Wazurkar a11d8d05d5 [gf] * src/gf/gfdrivr.c: Added GF_Face_Init, GF_Face_Done and GF_Glyph_Load functions. 2018-07-30 23:47:50 +05:30
Parth Wazurkar 8ce66d72c8 [gf] Added GF_Size_Request and GF_Size_Select functions. 2018-07-30 23:47:50 +05:30
Parth Wazurkar 2cbff6f458 [gf] Minor changes to Makefiles to accomodate GF Driver.
* modules.cfg: Added gf font driver module.
* src/gf/module.mk: Minor changes.
2018-07-30 23:47:50 +05:30
Parth Wazurkar 9e030fff8f [gf] * src/gf/gf.c: Added source files for single build 2018-07-30 23:47:50 +05:30
Parth Wazurkar 161035d66b [gf] Removed indentation errors. 2018-07-30 23:47:50 +05:30
Parth Wazurkar fdcaaa84fa [gf] Added Makefiles.
-Initialised module.mk and rules.mk.
2018-07-30 23:47:50 +05:30
Parth Wazurkar 10c4f0bd4e [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-30 23:47:50 +05:30
Parth Wazurkar 9a53ba425e [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-30 23:47:50 +05:30
Parth Wazurkar 3e006d31fd [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-30 23:47:50 +05:30
Parth Wazurkar b1aef3269f [gf] Added gf.c 2018-07-30 23:47:50 +05:30
Parth Wazurkar edfccbd6e3 [gf] Initialised gf driver files
gf driver files are initialised. Macros required for gf font files are determined in gf.h file.
2018-07-30 23:47:50 +05:30
Parth Wazurkar 13338ef516 *src added gf driver repository
This repository contains the driver for gf font format.
2018-07-30 23:47:50 +05:30
38 changed files with 4146 additions and 2 deletions

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

@ -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

@ -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,145 @@
/****************************************************************************
*
* 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

@ -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

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 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.
*
*/
#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 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 */

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

@ -0,0 +1,634 @@
/****************************************************************************
*
* 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_UInt max, code, result = 0, i;
max = cmap->num_encodings;
for( i = 0; i < max; i++ )
{
code = (FT_ULong) encodings[i].enc;
if ( charcode == code )
{
result = encodings[i].glyph;
goto Exit;
}
}
Exit:
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_UInt result = 0, i, code, max;
FT_ULong charcode = *acharcode + 1;
max = cmap->num_encodings;
for( i = 0; i < max; i++ )
{
code = (FT_ULong) encodings[i].enc;
if ( charcode == code )
{
result = encodings[i].glyph + 1;
goto Exit;
}
}
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 );
if( face->gf_glyph )
FT_FREE( face->gf_glyph->encodings );
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->bm_table )
{
FT_TRACE2(( "glyph bitmaps not allocated\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) go->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;
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_Error error = FT_Err_Ok;
FT_Bitmap* bitmap = &slot->bitmap;
GF_Bitmap bm;
GF_Glyph go;
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 charcode is %d\n",
glyph_index, go->bm_table[glyph_index].code ));
if ( !go->bm_table )
{
FT_TRACE2(( "invalid bitmap table\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* slot, bitmap => freetype, bm => gflib */
bm = &gf->gf_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 = (FT_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_TRACE2(( "Glyph metric values are: bm->bbx_height is %ld\n"
" bm->bbx_width is %ld\n"
" bm->off_x is %ld\n"
" bm->off_y is %ld\n"
" bm->mv_x is %ld\n"
" bm->mv_y is %ld\n", bm->bbx_height, bm->bbx_width,
bm->off_x, bm->off_y,
bm->mv_x, bm->mv_y ));
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 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 */

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

@ -0,0 +1,88 @@
/****************************************************************************
*
* 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_BitmapRec_
{
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_UShort code;
} GF_BitmapRec, *GF_Bitmap;
typedef struct GF_GlyphRec_
{
FT_UInt code_min, code_max;
GF_Bitmap bm_table;
FT_Int ds, hppp, vppp;
FT_Int font_bbx_w, font_bbx_h;
FT_Int font_bbx_xoff, font_bbx_yoff;
FT_ULong nencodings;
GF_Encoding encodings;
FT_ULong nglyphs;
} 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 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.
*
*/
/**************************************************************************
*
* 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 */

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

@ -0,0 +1,728 @@
/****************************************************************************
*
* 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 };
typedef struct GF_CharOffsetRec_
{
FT_Long char_offset;
FT_UShort code;
FT_Short gid;
} GF_CharOffsetRec, *GF_CharOffset;
/**************************************************************************
*
* 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_CharOffset of,
FT_Int ngphs,
GF_Glyph go,
FT_Memory memory )
{
FT_Error error;
FT_ULong nencoding;
FT_Int i, j;
FT_ULong k;
GF_Encoding encoding = NULL;
FT_Long *tosort;
nencoding = ngphs;
if ( FT_NEW_ARRAY( encoding, nencoding ) )
return error;
if ( FT_NEW_ARRAY( tosort, nencoding ) )
return error;
for ( i = 0 ; i < ngphs ; i++ )
{
if ( of[i].char_offset >= 0 )
tosort[i] = of[i].char_offset;
}
ft_qsort( (void*)tosort, ngphs, sizeof(FT_Long),
(int(*)(const void*, const void*))compare );
k = 0;
for ( i = 0; i < ngphs; i++ )
{
for ( j = 0; j < ngphs; j++ )
{
if ( of[j].char_offset == tosort[i] )
break;
}
encoding[k].enc = of[j].code;
encoding[k].glyph = k;
of[j].gid = k;
k++;
}
FT_FREE(tosort);
go->nencodings = k;
go->encodings = encoding;
return error;
}
FT_LOCAL_DEF( FT_Error )
gf_read_glyph( FT_Stream stream,
GF_Bitmap bm,
FT_Memory memory )
{
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 m_b, k;
FT_Byte *ptr;
FT_Error error = FT_Err_Ok;
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 -1;
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 -1;
}
/* allocate and build bitmap */
if ( (bm->bitmap = (FT_Byte*)malloc(h*((w+7)/8))) == NULL )
{
error = FT_THROW( Invalid_File_Format );
return -1;
}
memset(bm->bitmap, 0, h*((w+7)/8));
bm->raster = (FT_UInt)(w+7)/8;
bm->bbx_width = w;
bm->bbx_height = h;
bm->off_x = -min_m;
bm->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:
FT_FREE( bm->bitmap );
bm->bitmap = NULL;
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;
GF_Bitmap bm;
GF_CharOffset of;
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, optr, rptr;
FT_Int bc, ec, nchars, i, ngphs, idx;
FT_Error error = FT_Err_Ok;
FT_Memory memory = extmemory; /* needed for FT_NEW */
go = NULL;
nchars = -1;
idx = 0;
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 ) /* Defined to use ptr_p */
{
FT_ERROR(( "gf_load_font: invalid pointer in postamble\n" ));
goto Exit;
}
if ( check_sum < 0 ) /* Defined to use check_sum */
{
FT_ERROR(( "gf_load_font: invalid check sum value\n" ));
goto Exit;
}
#if 0
gptr = ftell(fp);
#endif
#if 0
/* read min & max char code */
bc = 256;
ec = -1;
for ( ; ; )
{
instr = READ_UINT1(fp);
if ( instr == GF_POST_POST )
{
break;
}
else if ( instr == GF_CHAR_LOC )
{
code = READ_UINT1(fp);
(void)SKIP_N(fp, 16);
}
else if ( instr == GF_CHAR_LOC0 )
{
code = READ_UINT1(fp);
(void)SKIP_N(fp, 9);
}
else
{
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
if ( code < bc )
bc = code;
if ( code > ec )
ec = code;
}
#else
bc = 0;
ec = 255;
#endif
nchars = ec - bc + 1;
if( FT_ALLOC( go, sizeof(GF_GlyphRec) ) )
goto Exit;
FT_TRACE2(( "gf_load_font: Allocated bitmap table\n" ));
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_ALLOC_MULT( of, sizeof(GF_CharOffsetRec), nchars ) )
goto Exit;
rptr = stream->pos;
i =0;
ngphs=0;
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;
}
of[i].char_offset = (FT_ULong) ptr;
of[i].code = (FT_UShort) code;
of[i].gid = -1;
ngphs += 1;
i++;
}
if( FT_ALLOC_MULT( go->bm_table, sizeof(GF_BitmapRec), ngphs ) )
goto Exit;
error = gf_set_encodings( of, ngphs, go, memory );
if( error )
goto Exit;
if( FT_STREAM_SEEK( rptr ) )
goto Exit;
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;
}
optr = stream->pos;
if ( FT_STREAM_SEEK( ptr ) )
goto Exit;
for ( i = 0; i < 256; i++ )
{
if( of[i].code == code && of[i].char_offset == ptr )
{
idx = of[i].gid;
break;
}
}
bm = &go->bm_table[idx];
bm->mv_x = dx;
bm->mv_y = dy;
bm->code = code;
go->nglyphs += 1;
if ( gf_read_glyph( stream, bm, memory ) < 0 )
goto Exit;
if ( FT_STREAM_SEEK( optr ) )
goto Exit;
}
FT_FREE(of);
*goptr = go;
return error;
Exit:
if ( go != NULL )
{
if ( go->bm_table )
{
for ( i = 0; i < nchars; i++ )
FT_FREE(go->bm_table[i].bitmap);
}
FT_FREE( go->bm_table );
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;
FT_UInt nchars = FT_FACE( face )->num_glyphs,i;
if ( !go )
return;
if( go->bm_table )
{
for ( i = 0; i < nchars; i++ )
FT_FREE(go->bm_table[i].bitmap);
}
FT_FREE( go->bm_table );
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 */

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

@ -0,0 +1,50 @@
/****************************************************************************
*
* 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 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))
FT_END_HEADER
#endif /* PK_H_ */
/* END */

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

@ -0,0 +1,624 @@
/****************************************************************************
*
* 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_ULong num_encodings;
PK_Encoding encodings;
} 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->num_encodings = face->pk_glyph->nencodings;
cmap->encodings = face->pk_glyph->encodings;
return FT_Err_Ok;
}
FT_CALLBACK_DEF( void )
pk_cmap_done( FT_CMap pkcmap )
{
PK_CMap cmap = (PK_CMap)pkcmap;
cmap->encodings = NULL;
cmap->num_encodings = 0;
}
FT_CALLBACK_DEF( FT_UInt )
pk_cmap_char_index( FT_CMap pkcmap,
FT_UInt32 charcode )
{
PK_CMap cmap = (PK_CMap)pkcmap;
PK_Encoding encodings = cmap->encodings;
FT_UInt max, code, result = 0, i;
max = cmap->num_encodings;
for( i = 0; i < max; i++ )
{
code = (FT_ULong)encodings[i].enc;
if ( charcode == code )
{
result = encodings[i].glyph;
goto Exit;
}
}
Exit:
return result;
}
FT_CALLBACK_DEF( FT_UInt )
pk_cmap_char_next( FT_CMap pkcmap,
FT_UInt32 *acharcode )
{
PK_CMap cmap = (PK_CMap)pkcmap;
PK_Encoding encodings = cmap->encodings;
FT_UInt result = 0, i, code, max;
FT_ULong charcode = *acharcode + 1;
max = cmap->num_encodings;
for( i = 0; i < max; i++ )
{
code = (FT_ULong)encodings[i].enc;
if ( charcode == code )
{
result = encodings[i].glyph + 1;
goto Exit;
}
}
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 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 );
}
/* 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( &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_Bitmap 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 ( !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 */

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

@ -0,0 +1,83 @@
/****************************************************************************
*
* 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_EncodingRec_
{
FT_Long enc;
FT_UShort glyph;
} PK_EncodingRec, *PK_Encoding;
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;
FT_UShort code;
} 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;
FT_ULong nencodings;
PK_Encoding encodings;
FT_ULong nglyphs;
} 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 */

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

@ -0,0 +1,597 @@
/****************************************************************************
*
* 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
FT_Byte bits_table[] = {
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
/**************************************************************************
*
* PK font utility functions.
*
*/
FT_Long pk_read_intn( FT_Stream, FT_Int );
FT_ULong pk_read_uintn( FT_Stream, FT_Int );
#define READ_UINT1( stream ) (FT_Byte)pk_read_uintn( stream, 1)
#define READ_UINT2( stream ) (FT_Byte)pk_read_uintn( stream, 2)
#define READ_UINT3( stream ) (FT_Byte)pk_read_uintn( stream, 3)
#define READ_UINT4( stream ) (FT_Byte)pk_read_uintn( stream, 4)
#define READ_UINTN( stream,n) (FT_ULong)pk_read_uintn( stream, n)
#define READ_INT1( stream ) (FT_String)pk_read_intn( stream, 1)
#define READ_INT2( stream ) (FT_String)pk_read_intn( stream, 2)
#define READ_INT4( stream ) (FT_Long)pk_read_intn( stream, 4)
/*
* Reading a Number from file
*/
FT_ULong
pk_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
pk_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;
}
FT_Int pk_read_nyble_rest_cnt;
FT_Int pk_read_nyble_max_bytes;
void
pk_read_nyble_init( FT_Int max )
{
pk_read_nyble_rest_cnt = 0;
pk_read_nyble_max_bytes = max;
}
FT_Int
pk_read_nyble(FT_Stream stream)
{
static FT_Byte d;
FT_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;
}
FT_Long
pk_read_packed_number(FT_Long* repeat, FT_Stream stream, int dyn_f)
{
FT_Int d, n;
FT_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;
}
FT_Int
pk_read_14( FT_Stream stream,
FT_ULong rs,
PK_Bitmap bm )
{
FT_Long x, y, x8, xm;
FT_Byte *bm_ptr;
FT_ULong bit16_buff;
FT_Int rest_bit16_buff;
static FT_UInt 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;
}
FT_Int
pk_read_n14( FT_Stream stream,
FT_Int dyn_f,
FT_Int bw,
FT_ULong rs,
PK_Bitmap bm )
{
FT_Long x, y, xx, yy, repeat;
FT_Int bits, b_p;
FT_Byte *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;
FT_Byte instr, pre, id;
FT_ULong ds, check_sum, hppp, vppp, k;
FT_UInt flag, dny_f, bw, ess, size;
FT_ULong cc, tfm, dx, dy, dm, w, h, rs;
FT_Long hoff, voff, mv_x, mv_y, gptr;
FT_Int bc, ec, nchars, index, i;
FT_Error error = FT_Err_Ok;
FT_Memory memory = extmemory; /* needed for FT_NEW */
PK_Encoding encoding = NULL;
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 );
FT_TRACE2(( "pk_load_font: checksum is %ld\n",check_sum ));
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 = (FT_ULong)READ_UINT1( stream ); if ( FT_STREAM_SKIP( k ) ) goto Exit; break;
case PK_XXX2: k = (FT_ULong)READ_UINT2( stream ); if ( FT_STREAM_SKIP( k ) ) goto Exit; break;
case PK_XXX3: k = (FT_ULong)READ_UINT3( stream ); if ( FT_STREAM_SKIP( k ) ) goto Exit; break;
case PK_XXX4: k = (FT_ULong)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 = (FT_ULong)(size*256) + (FT_ULong)READ_UINT1( stream );
cc = (FT_ULong)READ_UINT1( stream );
}
else if ((ess == 1) && (size != 3))
{ /* extended short */
rs = (FT_ULong)(size*65536) + (FT_ULong)READ_UINT2( stream );
cc = (FT_ULong)READ_UINT1( stream );
}
else
{ /* standard */
rs = READ_UINT4( stream );
cc = (FT_ULong)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;
if ( FT_NEW_ARRAY( encoding, nchars ) )
return error;
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 */
if( FT_STREAM_SEEK( gptr ) )
goto Exit;
index = 0;
go->nglyphs = 0;
for (;;)
{
if ((instr = READ_UINT1( stream )) == PK_POST)
break;
switch ((FT_Int)instr)
{
case PK_XXX1:
k = (FT_ULong)READ_UINT1( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
break;
case PK_XXX2:
k = (FT_ULong)READ_UINT2( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
break;
case PK_XXX3:
k = (FT_ULong)READ_UINT3( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
break;
case PK_XXX4:
k = (FT_ULong)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 = (FT_ULong)(size*256) + (FT_ULong)READ_UINT1( stream ) - (FT_ULong)8;
cc = (FT_ULong)READ_UINT1( stream );
tfm = (FT_ULong)READ_UINT3( stream );
dm = (FT_ULong)READ_UINT1( stream );
w = (FT_ULong)READ_UINT1( stream );
h = (FT_ULong)READ_UINT1( stream );
hoff = (FT_Long)READ_INT1( stream );
voff = (FT_Long)READ_INT1( stream );
mv_x = dm;
mv_y = 0;
}
else if ((ess == 1) && (size != 3))
{ /* extended short */
rs = (FT_ULong)(size*65536) + (FT_ULong)READ_UINT2( stream ) - (FT_ULong)13;
cc = (FT_ULong)READ_UINT1( stream );
tfm = (FT_ULong)READ_UINT3( stream );
dm = (FT_ULong)READ_UINT2( stream );
w = (FT_ULong)READ_UINT2( stream );
h = (FT_ULong)READ_UINT2( stream );
hoff = (FT_Long)READ_INT2( stream );
voff = (FT_Long)READ_INT2( stream );
mv_x = dm;
mv_y = 0;
}
else
{ /* standard */
rs = READ_UINT4( stream ) - (FT_ULong)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;
}
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));
go->bm_table[index].code = cc ; /* For backward compatibility */
go->nglyphs += 1;
encoding[index].enc = cc ;
encoding[index].glyph = index;
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, rs, &(go->bm_table[index]) ) < 0)
{
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]) ) < 0)
{
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);
index++;
}
}
go->nencodings = go->nglyphs;
go->encodings = encoding;
*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 */

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

@ -0,0 +1,55 @@
/****************************************************************************
*
* 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 */

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

@ -0,0 +1,356 @@
/****************************************************************************
*
* 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));
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 */

0
src/vf/README Normal file
View File