Compare commits

...

28 Commits

Author SHA1 Message Date
Parth Wazurkar d64bad545a [tfm] Fixes. 2018-12-20 23:36:05 +05:30
Parth Wazurkar 75fd199d70 [tfm] Fixes.
Conflicts:
	include/freetype/internal/tfm.h
2018-12-20 23:29:42 +05:30
Parth Wazurkar 46ab8e2f4c [tfm] Fixes. 2018-12-20 23:27:13 +05:30
Parth Wazurkar 4c8db5478b [tfm] Define the `tfm_interface' functions.
* src/tfm/tfmobjs.c: Do it.
2018-12-20 23:26:42 +05:30
Parth Wazurkar 72035f0025 [tfm] Initialise makefiles. 2018-12-20 23:26:21 +05:30
Parth Wazurkar 46d2e1bd65 [tfm] Define `tfm_module_class' and `tfm_interface'.
* src/tfm/tfmmod.c: Do it.
2018-12-20 23:26:00 +05:30
Parth Wazurkar 6ae549152a [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-12-20 23:25:37 +05:30
Parth Wazurkar b490cfd5fd [vf] Register `vf' services. 2018-12-19 17:53:32 +05:30
Parth Wazurkar 18a923c039 [vf] Add `vf_driver_class' functions.
Note: Does not compile.
2018-12-19 17:52:05 +05:30
Parth Wazurkar 30679ffae9 [vf] Add DVI interpreter functions. 2018-12-18 16:28:35 +05:30
Parth Wazurkar 7305227c8c [vf] Add `vf' utility and `dvi' stack functions.
* src/vf/vflib.c: Add `vf_dv_stack' utility
functions and `vf_read_info' function.
2018-12-07 00:47:28 +05:30
Parth Wazurkar b9b1f22afe [vf] Minor. 2018-12-06 00:20:28 +05:30
Parth Wazurkar 51e77c8217 [vf] Modify makefiles. 2018-12-06 00:19:11 +05:30
Parth Wazurkar 35c6834a06 [vf] Add utility functions.
* src/vf/vflib.c: Do it.
2018-12-06 00:17:27 +05:30
Parth Wazurkar 6939265f77 [vf] Define `vf_cmap_class' functions.
* src/vf/vfdrivr.c: Do it.
2018-08-05 19:34:06 +05:30
Parth Wazurkar 540347496a [vf] Define VF_FaceRec and other format specific structures.
* src/vf/vfdrivr.h: Define VF_Bitmap, VF, and TFM
and other structures to hold `vf' format specific
values and define VF_FaceRec to accomodate them.
2018-07-25 13:47:13 +05:30
Parth Wazurkar 1cffbb92e5 [vf] Add vf format opcodes.
* src/vf/vf.h: Add opcodes used for vf driver.
2018-07-25 12:49:48 +05:30
Parth Wazurkar 9fac20632d [pk] Minor Fixes. 2018-07-19 13:43:20 +05:30
Parth Wazurkar 8bacbfc33e [pk] Add pk services. 2018-07-19 12:58:44 +05:30
Parth Wazurkar 5f57c6a8e8 [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-13 21:36:01 +05:30
Parth Wazurkar 9678e0c902 [pk] Fixes. 2018-07-13 01:14:58 +05:30
Parth Wazurkar 86a901d198 [pk] Define `pk_driver_class' functions.
* src/pk/pkdrivr.c: Define all the `pk_driver_class'
functions.
2018-07-13 01:13:11 +05:30
Parth Wazurkar ab86ec699d [pk] Define `pk_cmap_class' functions. 2018-07-12 23:26:48 +05:30
Parth Wazurkar 21d3754b29 [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-12 22:33:12 +05:30
Parth Wazurkar d934e03cdd [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-12 22:28:58 +05:30
Parth Wazurkar f9d1ea429b [vf] Initialise vf driver files and Makefiles. 2018-07-10 15:18:45 +05:30
Parth Wazurkar e67b502c14 [pk] Initialise pk driver files and Makefiles. 2018-07-10 15:08:47 +05:30
Parth Wazurkar 7399a4c280 [pk,vf] Initialise pk and vf driver repositories. 2018-07-10 14:27:17 +05:30
35 changed files with 3824 additions and 2 deletions

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_PK_H <freetype/internal/services/svpk.h>
#define FT_SERVICE_VF_H <freetype/internal/services/svvf.h>
/* */

View File

@ -116,6 +116,13 @@ FT_TRACE_DEF( pcfread )
FT_TRACE_DEF( bdfdriver )
FT_TRACE_DEF( bdflib )
/* PK font components */
FT_TRACE_DEF( pkdriver )
FT_TRACE_DEF( pklib )
/* TFM helper module components */
FT_TRACE_DEF( tfmobjs )
/* 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_PK "PK"
#define FT_FONT_FORMAT_VF "VF"
/* */

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,9 @@ FONT_MODULES += pcf
# BDF font driver. See optional extension ftbdf.c below also.
FONT_MODULES += bdf
# PK font driver.
FONT_MODULES += vf
# SFNT files support. If used without `truetype' or `cff', it supports
# bitmap-only fonts within an SFNT wrapper.
#
@ -137,6 +140,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/pk/README Normal file
View File

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

@ -0,0 +1,22 @@
#
# FreeType 2 PK Font module definition
#
# Copyright 1996-2018 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
# and distributed under the terms of the FreeType project license,
# LICENSE.TXT. By continuing to use, modify, or distribute this file you
# indicate that you have read the license and understand and accept it
# fully.
FTMODULE_H_COMMANDS += PK_DRIVER
define PK_DRIVER
$(OPEN_DRIVER) FT_Driver_ClassRec, pk_driver_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)pk $(ECHO_DRIVER_DESC)METAFONT bitmap fonts$(ECHO_DRIVER_DONE)
endef
# EOF

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

@ -0,0 +1,27 @@
/****************************************************************************
*
* pk.c
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used,
* modified, and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*/
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "pklib.c"
#include "pkdrivr.c"
/* END */

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

@ -0,0 +1,62 @@
/****************************************************************************
*
* pk.h
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used,
* modified, and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*/
#ifndef PK_H_
#define PK_H_
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_STREAM_H
#include FT_SYSTEM_H
FT_BEGIN_HEADER
#define FONT_DRIVER_PK 1
#define PK_PRE 247
#define PK_ID 89
#define PK_XXX1 240
#define PK_XXX2 241
#define PK_XXX3 242
#define PK_XXX4 243
#define PK_YYY 244
#define PK_POST 245
#define PK_NO_OP 246
#define toint(x) (int)(((x)>0)?(x+0.5):(x-0.5))
/* Temporary TO BE REMOVED */
typedef char INT1;
typedef unsigned char UINT1;
typedef int INT2;
typedef unsigned int UINT2;
typedef long INT3;
typedef unsigned long UINT3;
typedef long INT4;
typedef unsigned long UINT4;
FT_END_HEADER
#endif /* PK_H_ */
/* END */

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

@ -0,0 +1,497 @@
/****************************************************************************
*
* 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_SERVICE_PK_H
#include FT_SERVICE_FONT_FORMAT_H
#include "pk.h"
#include "pkdrivr.h"
#include "pkerror.h"
/**************************************************************************
*
* The macro FT_COMPONENT is used in trace mode. It is an implicit
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
* messages during execution.
*/
#undef FT_COMPONENT
#define FT_COMPONENT trace_pkdriver
typedef struct PK_CMapRec_
{
FT_CMapRec cmap;
FT_UInt32 bc; /* Beginning Character */
FT_UInt32 ec; /* End Character */
} PK_CMapRec, *PK_CMap;
FT_CALLBACK_DEF( FT_Error )
pk_cmap_init( FT_CMap pkcmap,
FT_Pointer init_data )
{
PK_CMap cmap = (PK_CMap)pkcmap;
PK_Face face = (PK_Face)FT_CMAP_FACE( cmap );
FT_UNUSED( init_data );
cmap->bc = face->pk_glyph->code_min;
cmap->ec = face->pk_glyph->code_max;
return FT_Err_Ok;
}
FT_CALLBACK_DEF( void )
pk_cmap_done( FT_CMap pkcmap )
{
PK_CMap cmap = (PK_CMap)pkcmap;
cmap->bc = 0;
cmap->ec = -1;
}
FT_CALLBACK_DEF( FT_UInt )
pk_cmap_char_index( FT_CMap pkcmap,
FT_UInt32 char_code )
{
FT_UInt gindex = 0;
PK_CMap cmap = (PK_CMap)pkcmap;
char_code -= cmap->bc;
if ( char_code < cmap->ec - cmap->bc + 1 )
gindex = (FT_UInt)( char_code );
return gindex;
}
FT_CALLBACK_DEF( FT_UInt )
pk_cmap_char_next( FT_CMap pkcmap,
FT_UInt32 *achar_code )
{
PK_CMap cmap = (PK_CMap)pkcmap;
FT_UInt gindex = 0;
FT_UInt32 result = 0;
FT_UInt32 char_code = *achar_code + 1;
if ( char_code <= cmap->bc )
{
result = cmap->bc;
gindex = 1;
}
else
{
char_code -= cmap->bc;
if ( char_code < cmap->ec - cmap->bc + 1 )
{
result = char_code;
gindex = (FT_UInt)( char_code );
}
}
*achar_code = result;
return gindex;
}
static
const FT_CMap_ClassRec pk_cmap_class =
{
sizeof ( PK_CMapRec ),
pk_cmap_init,
pk_cmap_done,
pk_cmap_char_index,
pk_cmap_char_next,
NULL, NULL, NULL, NULL, NULL
};
FT_CALLBACK_DEF( void )
PK_Face_Done( FT_Face pkface ) /* PK_Face */
{
PK_Face face = (PK_Face)pkface;
FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
pk_free_font( face );
FT_FREE( pkface->available_sizes );
}
FT_CALLBACK_DEF( FT_Error )
PK_Face_Init( FT_Stream stream,
FT_Face pkface, /* PK_Face */
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
PK_Face face = (PK_Face)pkface;
FT_Error error = FT_Err_Ok;
FT_Memory memory = FT_FACE_MEMORY( face );
PK_Glyph go=NULL;
FT_UInt16 i,count;
FT_UNUSED( num_params );
FT_UNUSED( params );
FT_TRACE2(( "PK driver\n" ));
/* load font */
error = pk_load_font( stream, memory, &go );
if ( FT_ERR_EQ( error, Unknown_File_Format ) )
{
FT_TRACE2(( " not a PK file\n" ));
goto Fail;
}
else if ( error )
goto Exit;
/* we have a pk font: let's construct the face object */
face->pk_glyph = go ;
/* sanity check */
if ( !face->pk_glyph->bm_table )
{
FT_TRACE2(( "glyph bitmaps not allocated\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* PK cannot have multiple faces in a single font file.
* XXX: non-zero face_index is already invalid argument, but
* Type1, Type42 driver has a convention to return
* an invalid argument error when the font could be
* opened by the specified driver.
*/
if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 )
{
FT_ERROR(( "PK_Face_Init: invalid face index\n" ));
PK_Face_Done( pkface );
return FT_THROW( Invalid_Argument );
}
/* we now need to fill the root FT_Face fields */
/* with relevant information */
pkface->num_faces = 1;
pkface->face_index = 0;
pkface->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
FT_FACE_FLAG_HORIZONTAL ;
/*
* XXX: TO-DO: pkface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
* XXX: I have to check for this.
*/
pkface->family_name = NULL;
count=0;
for (i = 0; i < 256; i++)
{
if(go->bm_table[i].bitmap != NULL)
count++;
}
pkface->num_glyphs = (FT_Long)count;
FT_TRACE4(( " number of glyphs: allocated %d\n",pkface->num_glyphs ));
if ( pkface->num_glyphs <= 0 )
{
FT_ERROR(( "PK_Face_Init: glyphs not allocated\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
pkface->num_fixed_sizes = 1;
if ( FT_NEW_ARRAY( pkface->available_sizes, 1 ) )
goto Exit;
{
FT_Bitmap_Size* bsize = pkface->available_sizes;
FT_UShort x_res, y_res;
bsize->height = (FT_Short) face->pk_glyph->font_bbx_h ;
bsize->width = (FT_Short) face->pk_glyph->font_bbx_w ;
bsize->size = (FT_Pos) FT_MulDiv( FT_ABS( face->pk_glyph->ds ),
64 * 7200,
72270L );
x_res = toint( face->pk_glyph->hppp * 72.27 );
y_res = toint( face->pk_glyph->vppp * 72.27 );
bsize->y_ppem = (FT_Pos) toint((face->pk_glyph->ds * y_res)/ 72.27) << 6 ;
bsize->x_ppem = (FT_Pos)FT_MulDiv( bsize->y_ppem,
x_res,
y_res ); ;
}
/* Charmaps */
{
FT_CharMapRec charmap;
/* Unicode Charmap */
charmap.encoding = FT_ENCODING_UNICODE;
charmap.platform_id = TT_PLATFORM_MICROSOFT;
charmap.encoding_id = TT_MS_ID_UNICODE_CS;
charmap.face = FT_FACE( face );
error = FT_CMap_New( &pk_cmap_class, NULL, &charmap, NULL );
if ( error )
goto Exit;
}
if ( go->code_max < go->code_min )
{
FT_TRACE2(( "invalid number of glyphs\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
Exit:
return error;
Fail:
PK_Face_Done( pkface );
return FT_THROW( Unknown_File_Format );
}
FT_CALLBACK_DEF( FT_Error )
PK_Size_Select( FT_Size size,
FT_ULong strike_index )
{
PK_Face face = (PK_Face)size->face;
PK_Glyph go = face->pk_glyph;
FT_UNUSED( strike_index );
FT_Select_Metrics( size->face, 0 );
size->metrics.ascender = (go->font_bbx_h - go->font_bbx_yoff) * 64;
size->metrics.descender = -go->font_bbx_yoff * 64;
size->metrics.max_advance = go->font_bbx_w * 64;
return FT_Err_Ok;
}
FT_CALLBACK_DEF( FT_Error )
PK_Size_Request( FT_Size size,
FT_Size_Request req )
{
PK_Face face = (PK_Face)size->face;
FT_Bitmap_Size* bsize = size->face->available_sizes;
FT_Error error = FT_ERR( Invalid_Pixel_Size );
FT_Long height;
height = FT_REQUEST_HEIGHT( req );
height = ( height + 32 ) >> 6;
switch ( req->type )
{
case FT_SIZE_REQUEST_TYPE_NOMINAL:
if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) )
error = FT_Err_Ok;
break;
case FT_SIZE_REQUEST_TYPE_REAL_DIM:
if ( height == face->pk_glyph->font_bbx_h )
error = FT_Err_Ok;
break;
default:
error = FT_THROW( Unimplemented_Feature );
break;
}
if ( error )
return error;
else
return PK_Size_Select( size, 0 );
}
FT_CALLBACK_DEF( FT_Error )
PK_Glyph_Load( FT_GlyphSlot slot,
FT_Size size,
FT_UInt glyph_index,
FT_Int32 load_flags )
{
PK_Face pk = (PK_Face)FT_SIZE_FACE( size );
FT_Face face = FT_FACE( pk );
FT_Error error = FT_Err_Ok;
FT_Bitmap* bitmap = &slot->bitmap;
PK_BitmapRec bm;
PK_Glyph go;
FT_Int ascent;
go = pk->pk_glyph;
FT_UNUSED( load_flags );
if ( !face )
{
error = FT_THROW( Invalid_Face_Handle );
goto Exit;
}
if ( !go ||
glyph_index >= (FT_UInt)( face->num_glyphs ) )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
FT_TRACE1(( "PK_Glyph_Load: glyph index %d\n", glyph_index ));
if ( glyph_index < 0 )
glyph_index = 0;
if ((glyph_index < go->code_min) || (go->code_max < glyph_index))
{
FT_TRACE2(( "invalid glyph index\n" ));
error = FT_THROW( Invalid_Argument );
goto Exit;
}
if ( !go->bm_table )
{
FT_TRACE2(( "invalid bitmap table\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* slot, bitmap => freetype, bm => pklib */
bm = pk->pk_glyph->bm_table[glyph_index];
bitmap->rows = bm.bbx_height;
bitmap->width = bm.bbx_width;
bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
if ( !bm.raster )
{
FT_TRACE2(( "invalid bitmap width\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
bitmap->pitch = (int)bm.raster ;
/* note: we don't allocate a new array to hold the bitmap; */
/* we can simply point to it */
ft_glyphslot_set_bitmap( slot, bm.bitmap );
ascent = (bm.bbx_height + bm.off_y);
slot->format = FT_GLYPH_FORMAT_BITMAP;
slot->bitmap_left = bm.off_x ;
slot->bitmap_top = ascent ;
slot->metrics.horiAdvance = (FT_Pos) (bm.mv_x ) * 64;
slot->metrics.horiBearingX = (FT_Pos) (bm.off_x ) * 64;
slot->metrics.horiBearingY = (FT_Pos) ascent * 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;
}
/*
*
* 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 */
NULL, /* 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 */

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

@ -0,0 +1,65 @@
/****************************************************************************
*
* pkdrivr.h
*
* FreeType font driver for TeX's PK FONT files.
*
* Copyright 1996-2018 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used,
* modified, and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*/
#ifndef PKDRIVR_H_
#define PKDRIVR_H_
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
#include "pk.h"
FT_BEGIN_HEADER
typedef struct PK_BitmapRec_
{
FT_UInt bbx_width, bbx_height;
FT_UInt off_x, off_y;
FT_UInt mv_x, mv_y;
FT_Byte *bitmap;
FT_UInt raster;
} PK_BitmapRec, *PK_Bitmap;
typedef struct PK_GlyphRec_
{
FT_UInt code_min, code_max;
PK_Bitmap bm_table;
FT_UInt ds, hppp, vppp;
FT_UInt font_bbx_w, font_bbx_h;
FT_UInt font_bbx_xoff, font_bbx_yoff;
} PK_GlyphRec, *PK_Glyph;
typedef struct PK_FaceRec_
{
FT_FaceRec root;
PK_Glyph pk_glyph;
} 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 */

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

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

22
src/vf/module.mk Normal file
View File

@ -0,0 +1,22 @@
#
# FreeType 2 VF 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 += VF_DRIVER
define VF_DRIVER
$(OPEN_DRIVER) FT_Driver_ClassRec, vf_driver_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)vf $(ECHO_DRIVER_DESC)METAFONT bitmap fonts$(ECHO_DRIVER_DONE)
endef
# EOF

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

@ -0,0 +1,70 @@
#
# FreeType 2 VF 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.
# vf driver directory
#
VF_DIR := $(SRC_DIR)/vf
VF_COMPILE := $(CC) $(ANSIFLAGS) \
$I$(subst /,$(COMPILER_SEP),$(VF_DIR)) \
$(INCLUDE_FLAGS) \
$(FT_CFLAGS)
# vf driver sources (i.e., C files)
#
VF_DRV_SRC := $(VF_DIR)/vflib.c \
$(VF_DIR)/vfdrivr.c
# vf driver headers
#
VF_DRV_H := $(VF_DIR)/vf.h \
$(VF_DIR)/vfdrivr.h \
$(VF_DIR)/vferror.h
# vf driver object(s)
#
# VF_DRV_OBJ_M is used during `multi' builds
# VF_DRV_OBJ_S is used during `single' builds
#
VF_DRV_OBJ_M := $(VF_DRV_SRC:$(VF_DIR)/%.c=$(OBJ_DIR)/%.$O)
VF_DRV_OBJ_S := $(OBJ_DIR)/vf.$O
# vf driver source file for single build
#
VF_DRV_SRC_S := $(VF_DIR)/vf.c
# vf driver - single object
#
$(VF_DRV_OBJ_S): $(VF_DRV_SRC_S) $(VF_DRV_SRC) $(FREETYPE_H) $(VF_DRV_H)
$(VF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(VF_DRV_SRC_S))
# vf driver - multiple objects
#
$(OBJ_DIR)/%.$O: $(VF_DIR)/%.c $(FREETYPE_H) $(VF_DRV_H)
$(VF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
# update main driver object lists
#
DRV_OBJS_S += $(VF_DRV_OBJ_S)
DRV_OBJS_M += $(VF_DRV_OBJ_M)
# EOF

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

@ -0,0 +1,27 @@
/****************************************************************************
*
* vf.c
*
* FreeType font driver for TeX's VF 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 "vflib.c" */
#include "vfdrivr.c"
/* END */

103
src/vf/vf.h Normal file
View File

@ -0,0 +1,103 @@
/****************************************************************************
*
* vf.h
*
* FreeType font driver for TeX's VF 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 VF_H_
#define VF_H_
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_STREAM_H
#include FT_SYSTEM_H
FT_BEGIN_HEADER
#define VFINST_ID_BYTE 202
#define VFINST_CP_SHORT_CHAR0 0
#define VFINST_CP_SHORT_CHAR241 241
#define VFINST_CP_LONG_CHAR 242
#define VFINST_SETCHAR0 0
#define VFINST_SETCHAR127 127
#define VFINST_SET1 128
#define VFINST_SET2 129
#define VFINST_SET3 130
#define VFINST_SET4 131
#define VFINST_SETRULE 132
#define VFINST_PUT1 133
#define VFINST_PUT2 134
#define VFINST_PUT3 135
#define VFINST_PUT4 136
#define VFINST_PUTRULE 137
#define VFINST_NOP 138
#define VFINST_PUSH 141
#define VFINST_POP 142
#define VFINST_RIGHT1 143
#define VFINST_RIGHT2 144
#define VFINST_RIGHT3 145
#define VFINST_RIGHT4 146
#define VFINST_W0 147
#define VFINST_W1 148
#define VFINST_W2 149
#define VFINST_W3 150
#define VFINST_W4 151
#define VFINST_X0 152
#define VFINST_X1 153
#define VFINST_X2 154
#define VFINST_X3 155
#define VFINST_X4 156
#define VFINST_DOWN1 157
#define VFINST_DOWN2 158
#define VFINST_DOWN3 159
#define VFINST_DOWN4 160
#define VFINST_Y0 161
#define VFINST_Y1 162
#define VFINST_Y2 163
#define VFINST_Y3 164
#define VFINST_Y4 165
#define VFINST_Z0 166
#define VFINST_Z1 167
#define VFINST_Z2 168
#define VFINST_Z3 169
#define VFINST_Z4 170
#define VFINST_FNTNUM0 171
#define VFINST_FNTNUM63 234
#define VFINST_FNT1 235
#define VFINST_FNT2 236
#define VFINST_FNT3 237
#define VFINST_FNT4 238
#define VFINST_XXX1 239
#define VFINST_XXX2 240
#define VFINST_XXX3 241
#define VFINST_XXX4 242
#define VFINST_FNTDEF1 243
#define VFINST_FNTDEF2 244
#define VFINST_FNTDEF3 245
#define VFINST_FNTDEF4 246
#define VFINST_PRE 247
#define VFINST_POST 248
FT_END_HEADER
#endif /* VF_H_ */
/* END */

456
src/vf/vfdrivr.c Normal file
View File

@ -0,0 +1,456 @@
/****************************************************************************
*
* vfdrivr.c
*
* FreeType font driver for TeX's VF 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_VF_H
#include FT_SERVICE_FONT_FORMAT_H
#include "vf.h"
#include "vfdrivr.h"
#include "vferror.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_vfdriver
typedef struct VF_CMapRec_
{
FT_CMapRec cmap;
FT_UInt32 bc; /* Beginning Character */
FT_UInt32 ec; /* End Character */
} VF_CMapRec, *VF_CMap;
FT_CALLBACK_DEF( FT_Error )
vf_cmap_init( FT_CMap vfcmap,
FT_Pointer init_data )
{
VF_CMap cmap = (VF_CMap)vfcmap;
VF_Face face = (VF_Face)FT_CMAP_FACE( cmap );
FT_UNUSED( init_data );
cmap->bc = 0;
cmap->ec = 255;/* TO-DO */
return FT_Err_Ok;
}
FT_CALLBACK_DEF( void )
vf_cmap_done( FT_CMap vfcmap )
{
VF_CMap cmap = (VF_CMap)vfcmap;
cmap->bc = 0;
cmap->ec = -1;
}
FT_CALLBACK_DEF( FT_UInt )
vf_cmap_char_index( FT_CMap vfcmap,
FT_UInt32 char_code )
{
FT_UInt gindex = 0;
VF_CMap cmap = (VF_CMap)vfcmap;
char_code -= cmap->bc;
if ( char_code < cmap->ec - cmap->bc + 1 )
gindex = (FT_UInt)( char_code );
return gindex;
}
FT_CALLBACK_DEF( FT_UInt )
vf_cmap_char_next( FT_CMap vfcmap,
FT_UInt32 *achar_code )
{
VF_CMap cmap = (VF_CMap)vfcmap;
FT_UInt gindex = 0;
FT_UInt32 result = 0;
FT_UInt32 char_code = *achar_code + 1;
if ( char_code <= cmap->bc )
{
result = cmap->bc;
gindex = 1;
}
else
{
char_code -= cmap->bc;
if ( char_code < cmap->ec - cmap->bc + 1 )
{
result = char_code;
gindex = (FT_UInt)( char_code );
}
}
*achar_code = result;
return gindex;
}
static
const FT_CMap_ClassRec vf_cmap_class =
{
sizeof ( VF_CMapRec ),
vf_cmap_init,
vf_cmap_done,
vf_cmap_char_index,
vf_cmap_char_next,
NULL, NULL, NULL, NULL, NULL
};
FT_CALLBACK_DEF( void )
VF_Face_Done( FT_Face vfface ) /* VF_Face */
{
VF_Face face = (VF_Face) vfface;
FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
FT_FREE( vfface->available_sizes );
vf_free_font( face );
}
FT_CALLBACK_DEF( FT_Error )
VF_Face_Init( FT_Stream stream,
FT_Face vfface, /* VF_Face */
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
VF_Face face = (VF_Face) vfface;
FT_Error error = FT_Err_Ok;
FT_Memory memory = FT_FACE_MEMORY( face );
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(( "vf_Face_Init: cannot access `tfm' module\n" ));
error = FT_THROW( Missing_Module );
goto Exit;
}
FT_TRACE2(( "VF driver\n" ));
/* load font */
error = vf_read_info( stream, memory, &go );
if ( FT_ERR_EQ( error, Unknown_File_Format ) )
{
FT_TRACE2(( " not a vf file\n" ));
goto Fail;
}
else if ( error )
goto Exit;
/* we have a vf font: let's construct the face object */
/* sanity check */
/* we now need to fill the root FT_Face fields */
/* with relevant information */
vfface->num_faces = 1;
vfface->face_index = 0;
vfface->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
FT_FACE_FLAG_HORIZONTAL ;
/*
* XXX: TO-DO: vfface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
*/
vfface->family_name = NULL;
vfface->num_glyphs = (FT_Long) 999; /* TO-DO*/
FT_TRACE4(( " number of glyphs: allocated %d\n", vfface->num_glyphs ));
if ( vfface->num_glyphs <= 0 )
{
FT_ERROR(( "vf_Face_Init: glyphs not allocated\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
vfface->num_fixed_sizes = 1;
if ( FT_NEW_ARRAY( vfface->available_sizes, 1 ) )
goto Exit;
{
FT_Bitmap_Size* bsize = vfface->available_sizes;
FT_UShort x_res, y_res;
/* Add Dummy values */
/* To be modified */
bsize->height = (FT_Short) 999 ;
bsize->width = (FT_Short) 999 ;
bsize->size = (FT_Pos) 999 ;
bsize->y_ppem = (FT_Pos) 999 ;
bsize->x_ppem = (FT_Pos) 999 ;
}
/* set up charmap */
{
/* FT_Bool unicode_charmap ; */
/*
* XXX: TO-DO
* Currently the unicode_charmap is set to `0'
* The functionality of extracting coding scheme
* will be added.
*/
}
/* 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( &vf_cmap_class, NULL, &charmap, NULL );
if ( error )
goto Exit;
}
Exit:
return error;
Fail:
vf_Face_Done( vfface );
return FT_THROW( Unknown_File_Format );
}
FT_CALLBACK_DEF( FT_Error )
VF_Size_Select( FT_Size size,
FT_ULong strike_index )
{
VF_Face face = (VF_Face)size->face;
FT_UNUSED( strike_index );
FT_Select_Metrics( size->face, 0 );
/* Add Dummy values */
/* To be modified */
size->metrics.ascender = 999 * 64;
size->metrics.descender = 999 * 64;
size->metrics.max_advance = 999 * 64;
return FT_Err_Ok;
}
FT_CALLBACK_DEF( FT_Error )
VF_Size_Request( FT_Size size,
FT_Size_Request req )
{
VF_Face face = (VF_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 == 999 ) /* TO-DO */
error = FT_Err_Ok;
break;
default:
error = FT_THROW( Unimplemented_Feature );
break;
}
if ( error )
return error;
else
return VF_Size_Select( size, 0 );
}
FT_CALLBACK_DEF( FT_Error )
VF_Glyph_Load( FT_GlyphSlot slot,
FT_Size size,
FT_UInt glyph_index,
FT_Int32 load_flags )
{
VF_Face vf = (VF_Face) FT_SIZE_FACE( size );
FT_Face face = FT_FACE ( vf );
FT_Error error = FT_Err_Ok;
FT_Bitmap* bitmap = &slot->bitmap;
FT_UNUSED( load_flags );
if ( !face )
{
error = FT_THROW( Invalid_Face_Handle );
goto Exit;
}
/* slot, bitmap => freetype, bm => gflib */
bitmap->rows = 999; /* TO-DO */
bitmap->width = 999; /* TO-DO */
bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
bitmap->pitch = (FT_Int) 999 ; /* TO-DO */
/* 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 ); */ /* TO-DO */
slot->format = FT_GLYPH_FORMAT_BITMAP;
slot->bitmap_left = 999 ; /* TO-DO */
slot->bitmap_top = 999 ; /* TO-DO */
slot->metrics.horiAdvance = (FT_Pos) 999 * 64; /* TO-DO */
slot->metrics.horiBearingX = (FT_Pos) 999 * 64; /* TO-DO */
slot->metrics.horiBearingY = (FT_Pos) 999 * 64; /* TO-DO */
slot->metrics.width = (FT_Pos) ( 999 * 64 ); /* TO-DO */
slot->metrics.height = (FT_Pos) ( 999 * 64 ); /* TO-DO */
ft_synthesize_vertical_metrics( &slot->metrics, 999 * 64 ); /* TO-DO */
Exit:
return error;
}
/*
*
* SERVICES LIST
*
*/
static const FT_ServiceDescRec vf_services[] =
{
{ FT_SERVICE_ID_VF, NULL },
{ FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_VF },
{ NULL, NULL }
};
FT_CALLBACK_DEF( FT_Module_Interface )
vf_driver_requester( FT_Module module,
const char* name )
{
FT_UNUSED( module );
return ft_service_list_lookup( vf_services, name );
}
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec vf_driver_class =
{
{
FT_MODULE_FONT_DRIVER |
FT_MODULE_DRIVER_NO_OUTLINES,
sizeof ( FT_DriverRec ),
"vf",
0x10000L,
0x20000L,
NULL, /* module-specific interface */
NULL, /* FT_Module_Constructor module_init */
NULL, /* FT_Module_Destructor module_done */
vf_driver_requester /* FT_Module_Requester get_interface */
},
sizeof ( VF_FaceRec ),
sizeof ( FT_SizeRec ),
sizeof ( FT_GlyphSlotRec ),
VF_Face_Init, /* FT_Face_InitFunc init_face */
VF_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 */
VF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */
NULL, /* FT_Face_GetKerningFunc get_kerning */
NULL, /* FT_Face_AttachFunc attach_file */
NULL, /* FT_Face_GetAdvancesFunc get_advances */
VF_Size_Request, /* FT_Size_RequestFunc request_size */
VF_Size_Select /* FT_Size_SelectFunc select_size */
};
/* END */

138
src/vf/vfdrivr.h Normal file
View File

@ -0,0 +1,138 @@
/****************************************************************************
*
* vfdrivr.h
*
* FreeType font driver for TeX's VF 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 VFDRIVR_H_
#define VFDRIVR_H_
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
#include "vf.h"
FT_BEGIN_HEADER
typedef struct VF_BitmapRec_
{
FT_UInt bbx_width, bbx_height;
FT_UInt off_x, off_y;
FT_UInt mv_x, mv_y;
FT_Byte *bitmap;
FT_UInt raster;
} VF_BitmapRec, *VF_Bitmap;
/* Bitmap list */
struct vf_s_bitmaplist {
FT_Long off_x, off_y;
VF_Bitmap bitmap;
struct vf_s_bitmaplist *next;
};
typedef struct vf_s_bitmaplist *VF_BITMAPLIST;
typedef struct TFM_Rec_
{
/* Font Info */
FT_ULong cs;
/* Metrics */
FT_ULong ds;
FT_ULong design_size;
FT_ULong slant;
unsigned int begin_char, end_char;
FT_Long *width, *height, *depth;
/* Font bounding box */
FT_ULong font_bbx_w, font_bbx_h;
FT_ULong font_bbx_xoff, font_bbx_yoff;
} TFM_Rec, *TFM;
typedef struct VF_Rec_
{
FT_Char *vf_path;
FT_ULong cs;
FT_ULong ds;
FT_ULong design_size;
FT_ULong point_size;
FT_ULong dpi_x, dpi_y;
FT_ULong mag_x, mag_y;
/* TFM */
FT_Char *tfm_path;
TFM tfm;
/* subfotns */
struct s_vf_subfont *subfonts;
FT_Int subfonts_opened;
FT_Int default_subfont;
/* file offset to character packets (offset in vf file) */
FT_Long offs_char_packet;
}VF_Rec, *VF;
typedef struct s_vf_char_packet
{
FT_ULong pl;
FT_ULong cc;
FT_ULong tfm;
FT_Byte *dvi;
}s_vf_char_packet, *VF_CHAR_PACKET;
typedef struct s_vf_char_packet_tbl
{
int npackets;
VF_CHAR_PACKET packets;
}s_vf_char_packet_tbl, *VF_CHAR_PACKET_TBL;
typedef struct s_vf_subfont
{
FT_ULong k;
FT_ULong s;
FT_ULong d;
FT_ULong a;
FT_ULong l;
char *n;
struct s_vf_subfont *next;
}s_vf_subfont, *VF_SUBFONT;
struct s_vf_dvi_stack
{
long h, v, w, x, y, z;
int f;
int font_id;
struct s_vf_dvi_stack *next;
};
typedef struct s_vf_dvi_stack *VF_DVI_STACK;
#define STACK(X) dvi_stack->next->X
typedef struct VF_FaceRec_
{
FT_FaceRec root;
VF vf;
} VF_FaceRec, *VF_Face;
FT_EXPORT_VAR( const FT_Driver_ClassRec ) vf_driver_class;
FT_END_HEADER
#endif /* VFDRIVR_H_ */
/* END */

40
src/vf/vferror.h Normal file
View File

@ -0,0 +1,40 @@
/****************************************************************************
*
* vferror.h
*
* FreeType font driver for TeX's VF 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 VF error enumeration constants.
*
*/
#ifndef VFERROR_H_
#define VFERROR_H_
#include FT_MODULE_ERRORS_H
#undef FTERRORS_H_
#undef FT_ERR_PREFIX
#define FT_ERR_PREFIX VF_Err_
#define FT_ERR_BASE FT_Mod_Err_VF
#include FT_ERRORS_H
#endif /* VFERROR_H_ */
/* END */

707
src/vf/vflib.c Normal file
View File

@ -0,0 +1,707 @@
/****************************************************************************
*
* vflib.c
*
* FreeType font driver for TeX's VF 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 "vf.h"
#include "vfdrivr.h"
#include "vferror.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_vflib
/**************************************************************************
*
* VF font utility functions.
*
*/
FT_Long vf_read_intn( FT_Stream, FT_Int );
FT_ULong vf_read_uintn( FT_Stream, FT_Int );
FT_Long vf_get_intn( FT_Byte*, FT_Int );
FT_ULong vf_get_uintn( FT_Byte*, FT_Int );
#define READ_UINT1( stream ) (FT_Byte)vf_read_uintn( stream, 1 )
#define READ_UINT2( stream ) (FT_Byte)vf_read_uintn( stream, 2 )
#define READ_UINT3( stream ) (FT_Byte)vf_read_uintn( stream, 3 )
#define READ_UINT4( stream ) (FT_Byte)vf_read_uintn( stream, 4 )
#define READ_UINTN( stream, n ) (FT_ULong)vf_read_uintn( stream, n )
#define READ_INT1( stream ) (FT_String)vf_read_intn( stream, 1 )
#define READ_INT4( stream ) (FT_Long)vf_read_intn( stream, 4 )
#define GET_INT1(p) (FT_Char)vf_get_intn((p), 1)
#define GET_UINT1(p) (FT_Byte)vf_get_uintn((p), 1)
#define GET_INT2(p) (FT_Int)vf_get_intn((p), 2)
#define GET_UINT2(p) (FT_UInt)vf_get_uintn((p), 2)
#define GET_INT3(p) (FT_Long)vf_get_intn((p), 3)
#define GET_UINT3(p) (FT_ULong)vf_get_uintn((p), 3)
#define GET_INT4(p) (FT_Long)vf_get_intn((p), 4)
#define GET_UINT4(p) (FT_ULong)vf_get_uintn((p), 4)
#define GET_INTN(p,n) (FT_Long)vf_get_intn((p), (n))
#define GET_UINTN(p,n) (FT_ULong)vf_get_uintn((p), (n))
/*
* Reading a Number from file
*/
FT_ULong
vf_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
vf_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_ULong
vf_get_uintn( FT_Byte *p,
FT_Int size )
{
FT_ULong v;
v = 0L;
while (size >= 1)
{
v = v*256L + (FT_ULong) *(p++);
--size;
}
return v;
}
FT_Long
vf_get_intn( FT_Byte *p,
FT_Int size )
{
FT_Long v;
v = (FT_Long)*(p++) & 0xffL;
if (v & 0x80L)
v = v - 256L;
--size;
while (size >= 1)
{
v = v*256L + (FT_ULong) *(p++);
--size;
}
return v;
}
/**************************************************************************
*
* API.
*
*/
FT_LOCAL_DEF( FT_Error )
vf_read_info( FT_Stream stream,
FT_Memory extmemory,
VF vf)
{
FT_Byte id, a, l;
FT_ULong k, c, s, d;
VF_SUBFONT sf, sf0, sf_next;
struct s_vf_subfont subfont;
FT_ULong scale;
FT_Int fid, name_len, i;
FT_Char subfont_name[1024];
FT_Error error = FT_Err_Ok;
if( READ_UINT1( stream ) != VFINST_PRE )
goto Exit;
id = READ_UINT1( stream );
switch (id)
{
case VFINST_ID_BYTE:
break;
default:
goto Exit;
}
k = READ_UINT1( stream );
if ( FT_STREAM_SKIP( k ) )
goto Exit;
vf->cs = READ_UINT4( stream );
vf->ds = READ_UINT4( stream );
if ((vf->cs != vf->tfm->cs) || (vf->ds != vf->tfm->ds))
{
error = FT_THROW( Unknown_File_Format );
goto Exit;
}
vf->design_size = (FT_ULong)(vf->ds)/(FT_ULong)(1<<20);
vf->subfonts_opened = 1;
vf->default_subfont = -1;
subfont.next = NULL;
for ( sf0 = &subfont ; ; sf0 = sf )
{
if( FT_ALLOC( sf, sizeof(struct s_vf_subfont) ) )
goto Exit;
sf0->next = sf;
switch ( READ_UINT1( stream ) )
{
default:
vf->offs_char_packet = stream->pos - 1;
sf0->next = NULL;
FT_FREE( sf );
goto end_fontdef;
case VFINST_FNTDEF1:
k = (FT_ULong)READ_UINT1( stream );
c = READ_UINT4( stream ); s = READ_UINT4( stream ); d = READ_UINT4( stream );
a = READ_UINT1( stream ); l = READ_UINT1( stream );
break;
case VFINST_FNTDEF2:
k = (FT_ULong)READ_UINT2( stream );
c = READ_UINT4( stream ); s = READ_UINT4( stream ); d = READ_UINT4( stream );
a = READ_UINT1( stream ); l = READ_UINT1( stream );
break;
case VFINST_FNTDEF3:
k = (FT_ULong)READ_UINT3( stream );
c = READ_UINT4( stream ); s = READ_UINT4( stream ); d = READ_UINT4( stream );
a = READ_UINT1( stream ); l = READ_UINT1( stream );
break;
case VFINST_FNTDEF4:
k = (FT_ULong)READ_UINT4( stream );
c = READ_UINT4( stream ); s = READ_UINT4( stream ); d = READ_UINT4( stream );
a = READ_UINT1( stream ); l = READ_UINT1( stream );
break;
}
name_len = a + l;
sf->k = k;
sf->s = s;
sf->d = d;
sf->a = a;
sf->l = l;
sf->next = NULL;
scale = (FT_ULong)sf->s/(FT_ULong)(1<<20);
if ((sf->n = (char*)malloc(name_len + 1)) == NULL)
{
goto Exit;
}
for (i = 0; i < name_len; i++)
sf->n[i] = (char)READ_UINT1( stream );
sf->n[i] = '\0';
/* sprintf(subfont_name, "%s", &sf->n[sf->a]);
if (vf_debug('s'))
{
printf("VFlib Virtual Font: subfont %d: %s, scaled %f\n",
(int)sf->k, subfont_name, scale);
}
*/ /* To add tracing*/
end_fontdef:
if (vf->subfonts_opened == 0)
{
/*
if (open_style == TEX_OPEN_STYLE_REQUIRE)
{
if (vf_debug('s'))
printf("VFlib Virtual Font: all subfonts are required but failed\n");
goto error_exit;
}
else
{
if (vf_debug('s'))
printf("VFlib Virtual Font: not all fonts are opened; continue.\n");
}
*/
}
vf->subfonts = subfont.next;
return 0;
Exit:
for (sf = subfont.next; sf != NULL; sf = sf_next)
{
sf_next = sf->next;
FT_FREE(sf->n);
FT_FREE(sf);
}
vf->subfonts = NULL;
return error;
}
/**************************************************************************
*
* DVI stack utility functions.
*
*/
FT_Int
vf_dvi_stack_init(VF vf, VF_DVI_STACK stack, FT_Memory memory)
{
VF_DVI_STACK top;
if( FT_ALLOC( top, sizeof(struct s_vf_dvi_stack) ) )
return 0;
top->h = top->v = top->w = top->x = top->y = top->z = 0;
top->f = vf->default_subfont;
top->font_id = vf->subfonts->font_id;
top->next = NULL;
stack->next = top;
return 0;
}
FT_Int
vf_dvi_stack_deinit(VF vf, VF_DVI_STACK stack, FT_Memory memory)
{
VF_DVI_STACK elem, elem_next;
elem = stack->next;
while (elem != NULL)
{
elem_next = elem->next;
FT_FREE(elem);
elem = elem_next;
}
return 0;
}
FT_Int
vf_dvi_stack_push(VF vf, VF_DVI_STACK stack)
{
VF_DVI_STACK new_elem, top;
if( FT_ALLOC( new_elem, sizeof(struct s_vf_dvi_stack) ) )
return 0;
top = stack->next;
new_elem->h = top->h;
new_elem->v = top->v;
new_elem->w = top->w;
new_elem->x = top->x;
new_elem->y = top->y;
new_elem->z = top->z;
new_elem->f = top->f;
new_elem->font_id = top->font_id;
new_elem->next = top;
stack->next = new_elem;
return 0;
}
FT_Int
vf_dvi_stack_pop(VF vf, VF_DVI_STACK stack, FT_Memory memory)
{
VF_DVI_STACK top;
top = stack->next;
if (top == NULL)
{
/*Add trace and error message here*/
/* fprintf(stderr, "VFlib warning: VF DVI stack under flow: %s\n",
vf->vf_path);*/
return 0;
}
stack->next = top->next;
FT_FREE(top);
return 0;
}
/* BMPLIST FUNCTIONS */
vf_bitmaplist_finish(VF_BITMAPLIST bmlist)
{
VF_BITMAPLIST elem, elem_next;
elem = bmlist->next;
while (elem != NULL)
{
elem_next = elem->next;
VF_FreeBitmap(elem->bitmap);/* To Define */
FT_FREE(elem);
elem = elem_next;
}
bmlist->next = NULL;
return 0;
}
int
vf_bitmaplist_init(VF_BITMAPLIST bmlist)
{
bmlist->next = NULL;
return 0;
}
int
vf_bitmaplist_finish(VF_BITMAPLIST bmlist)
{
VF_BITMAPLIST elem, elem_next;
elem = bmlist->next;
while (elem != NULL)
{
elem_next = elem->next;
VF_FreeBitmap(elem->bitmap);
vf_free(elem);
elem = elem_next;
}
bmlist->next = NULL;
return 0;
}
/**************************************************************************
*
* DVI interpreter.
*
*/
void
vf_dvi_interp_font_select(VF vf, VF_DVI_STACK dvi_stack, long f,
FT_ULong *fmag_p)
{
VF_SUBFONT sf;
STACK(f) = f;
STACK(font_id) = -1;
for (sf = vf->subfonts; sf != NULL; sf = sf->next)
{
if (sf->k == f)
{
STACK(font_id) = sf->font_id;
if (fmag_p != NULL)
*fmag_p = 1;
break;
}
}
}
void
vf_dvi_interp_put_rule(VF_BITMAPLIST bmlist, VF vf, VF_DVI_STACK dvi_stack,
long w, long h, double mag_x, double mag_y)
{
VF_Bitmap bm;
FT_ULong rx, ry, ds;
int bm_w, bm_h;
long off_x, off_y;
ds = vf->design_size / (FT_ULong)(1<<20);
rx = vf->mag_x * mag_x * vf->dpi_x/72.27 * ds;
ry = vf->mag_y * mag_y * vf->dpi_y/72.27 * ds;
bm_w = rx * w;
bm_h = ry * h;
if (bm_w <= 0)
bm_w = 1;
if (bm_h <= 0)
bm_h = 1;
bm = vf_alloc_bitmap(bm_w, bm_h);
if (bm == NULL)
return;
VF_FillBitmap(bm);
bm->off_x = 0;
bm->off_y = bm_h - 1;
off_x = rx * (double)STACK(h);
off_y = -ry * (double)STACK(v);
vf_bitmaplist_put(bmlist, bm, off_x, off_y);
}
void
vf_dvi_interp_put_char(VF_BITMAPLIST bmlist, VF vf, VF_DVI_STACK dvi_stack,
long code_point, int mode, double mag_x, double mag_y)
{
VF_BITMAP bm;
double rx, ry, ds;
long off_x, off_y;
if (STACK(font_id) < 0)
return;
if (mode == 1)
{
bm = VF_GetBitmap1(STACK(font_id), code_point, mag_x, mag_y);
}
else
{
bm = VF_GetBitmap2(STACK(font_id), code_point, mag_x, mag_y);
}
if (bm == NULL)
return;
ds = vf->design_size / (double)(1<<20);
#if 1 /*XXX*/
rx = vf->mag_x * mag_x * (vf->dpi_x/72.27) * ds;
ry = vf->mag_y * mag_y * (vf->dpi_y/72.27) * ds;
#else
rx = (vf->dpi_x/72.27) * ds;
ry = (vf->dpi_y/72.27) * ds;
#endif
off_x = rx * (double)STACK(h);
off_y = -ry * (double)STACK(v);
vf_bitmaplist_put(bmlist, bm, off_x, off_y);
}
int
vf_dvi_interp(VF_BITMAPLIST bmlist, VF vf,
int mode, double mag_x, double mag_y,
long cc, unsigned char *dvi_prog, int prog_len)
{
int pc, instr, n, ret;
long code_point, h, w, f, length;
double fmag;
double r_mv_x, r_mv_y;
struct vf_s_metric1 met, *m;
struct s_vf_dvi_stack the_dvi_stack, *dvi_stack;
fmag = 1.0;
dvi_stack = &the_dvi_stack;
vf_dvi_stack_init(vf, dvi_stack);
pc = 0;
ret = 0;
while (pc < prog_len)
{
if (vf_debug('d'))
{
printf("VFlib Virtual Font\n ");
printf("DVI CODE PC=0x%04x: INSTR=0x%02x (%d) H=0x%08x V=0x%08x\n",
pc, (int)dvi_prog[pc], (int)dvi_prog[pc],
(int)STACK(h), (int)STACK(v));
}
instr = (int)dvi_prog[pc++];
if (instr <= VFINST_SET4)
{ /* SETCHAR0 ... SETCHAR127, SET1, ... ,SET4 */
if ((code_point = instr) > VFINST_SETCHAR127)
{
n = instr - VFINST_SET1 + 1;
code_point = GET_UINTN(&dvi_prog[pc], n);
pc += n;
}
vf_dvi_interp_put_char(bmlist, vf, dvi_stack, code_point,
mode, fmag * mag_x, fmag * mag_y);
m = VF_GetMetric1(STACK(font_id), code_point, &met,
fmag * mag_x, fmag * mag_y);
if (m == NULL)
continue;
r_mv_x = (met.mv_x / vf->design_size) * (double)(1<<20);
r_mv_y = (met.mv_y / vf->design_size) * (double)(1<<20);
STACK(h) = STACK(h) + toint(r_mv_x);
STACK(v) = STACK(v) + toint(r_mv_y);
}
else if ((VFINST_FNTNUM0 <= instr) && (instr <= (VFINST_FNTNUM63)))
{
f = instr - VFINST_FNTNUM0;
vf_dvi_interp_font_select(vf, dvi_stack, f, &fmag);
}
else
{
switch (instr)
{
case VFINST_PUT1:
case VFINST_PUT2:
case VFINST_PUT3:
case VFINST_PUT4:
n = instr - VFINST_SET1 + 1;
code_point = (UINT4)GET_UINTN(&dvi_prog[pc], n); pc += n;
vf_dvi_interp_put_char(bmlist, vf, dvi_stack, code_point,
mode, fmag * mag_x, fmag * mag_y);
break;
case VFINST_SETRULE:
h = (long)GET_INT4(&dvi_prog[pc]); pc += 4;
w = (long)GET_INT4(&dvi_prog[pc]); pc += 4;
vf_dvi_interp_put_rule(bmlist, vf, dvi_stack, w, h, mag_x, mag_y);
STACK(h) += w;
break;
case VFINST_PUTRULE:
h = (long)GET_INT4(&dvi_prog[pc]); pc += 4;
w = (long)GET_INT4(&dvi_prog[pc]); pc += 4;
vf_dvi_interp_put_rule(bmlist, vf, dvi_stack, w, h, mag_x, mag_y);
break;
case VFINST_RIGHT1:
case VFINST_RIGHT2:
case VFINST_RIGHT3:
case VFINST_RIGHT4:
n = instr - VFINST_RIGHT1 + 1;
STACK(h) += (long)GET_INTN(&dvi_prog[pc], n); pc += n;
break;
case VFINST_X1:
case VFINST_X2:
case VFINST_X3:
case VFINST_X4:
n = instr - VFINST_X0;
STACK(x) = (long)GET_INTN(&dvi_prog[pc], n); pc += n;
case VFINST_X0:
STACK(h) += STACK(x);
break;
case VFINST_W1:
case VFINST_W2:
case VFINST_W3:
case VFINST_W4:
n = instr - VFINST_W0;
STACK(w) = (long)GET_INTN(&dvi_prog[pc], n); pc += n;
case VFINST_W0:
STACK(h) += STACK(w);
break;
case VFINST_Y1:
case VFINST_Y2:
case VFINST_Y3:
case VFINST_Y4:
n = instr - VFINST_Y0;
STACK(y) = (long)GET_INTN(&dvi_prog[pc], n); pc += n;
case VFINST_Y0:
STACK(v) += STACK(y);
break;
case VFINST_Z1:
case VFINST_Z2:
case VFINST_Z3:
case VFINST_Z4:
n = instr - VFINST_Z0;
STACK(z) = (long)GET_INTN(&dvi_prog[pc], n); pc += n;
case VFINST_Z0:
STACK(v) += STACK(z);
break;
case VFINST_DOWN1:
case VFINST_DOWN2:
case VFINST_DOWN3:
case VFINST_DOWN4:
n = instr - VFINST_DOWN1 + 1;
STACK(v) += (long)GET_INTN(&dvi_prog[pc], n);
break;
case VFINST_XXX1:
case VFINST_XXX2:
case VFINST_XXX3:
case VFINST_XXX4:
n = instr - VFINST_XXX1 + 1;
length = (long)GET_INTN(&dvi_prog[pc], n); pc += n;
pc += length;
break;
case VFINST_FNT1:
case VFINST_FNT2:
case VFINST_FNT3:
case VFINST_FNT4:
n = instr - VFINST_FNT1 + 1;
f = GET_UINTN(&dvi_prog[pc], n); pc += n;
vf_dvi_interp_font_select(vf, dvi_stack, f, &fmag);
break;
case VFINST_PUSH:
vf_dvi_stack_push(vf, dvi_stack);
break;
case VFINST_POP:
vf_dvi_stack_pop(vf, dvi_stack);
break;
case VFINST_NOP:
break;
default:
vf_error = VF_ERR_ILL_FONT_FILE;
ret = -1;
goto ExitInterp;
}
}
}
ExitInterp:
vf_dvi_stack_deinit(vf, dvi_stack);
return ret;
}
VF_Bitmap
vf_run_dvi_program(VF vf, VF_CHAR_PACKET packet,
int mode, double mag_x, double mag_y)
{
struct vf_s_bitmaplist the_bmlist;
VF_Bitmap bm;
vf_bitmaplist_init(&the_bmlist);
vf_dvi_interp(&the_bmlist, vf, mode, mag_x, mag_y,
packet->cc, packet->dvi, packet->pl);
bm = vf_bitmaplist_compose(&the_bmlist);
vf_bitmaplist_finish(&the_bmlist);
return bm;
}
/* END */