adding BDF driver

This commit is contained in:
David Turner 2002-05-18 12:03:43 +00:00
parent b89a42c6c5
commit 993a8d0445
10 changed files with 3555 additions and 0 deletions

View File

@ -92,6 +92,9 @@ FT_TRACE_DEF( winfnt )
FT_TRACE_DEF( pcfdriver )
FT_TRACE_DEF( pcfread )
/* BDF fonts component */
FT_TRACE_DEF( bdf )
/* PFR fonts component */
FT_TRACE_DEF( pfr )

View File

@ -17,6 +17,7 @@ HDRMACRO [ FT2_SubDir include internal internal.h ] ;
SubInclude FT2_TOP src pshinter ;
SubInclude FT2_TOP src autohint ;
SubInclude FT2_TOP src base ;
SubInclude FT2_TOP src bdf ;
SubInclude FT2_TOP src cache ;
SubInclude FT2_TOP src cff ;
SubInclude FT2_TOP src cid ;

33
src/bdf/bdf.c Normal file
View File

@ -0,0 +1,33 @@
/* bdf.c
FreeType font driver for bdf files
Copyright (C) 2001 by
Francesco Zappa Nardelli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "bdflib.c"
#include "bdfdriver.c"
/* END */

367
src/bdf/bdf.h Normal file
View File

@ -0,0 +1,367 @@
/*
* Copyright 2000 Computing Research Labs, New Mexico State University
* Copyright 2001 Francesco Zappa Nardelli
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __BDF_H__
#define __BDF_H__
/*
* $Id$
*/
#include <string.h>
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_STREAM_H
FT_BEGIN_HEADER
/* Imported from bdfP.h */
#ifndef MYABS
#define MYABS(xx) ((xx) < 0 ? -(xx) : (xx))
#endif
#define _bdf_glyph_modified(map, e) ((map)[(e) >> 5] & (1 << ((e) & 31)))
#define _bdf_set_glyph_modified(map, e) (map)[(e) >> 5] |= (1 << ((e) & 31))
#define _bdf_clear_glyph_modified(map, e) (map)[(e) >> 5] &= ~(1 << ((e) & 31))
/* end of bdfP.h */
/**************************************************************************
*
* BDF font options macros and types.
*
**************************************************************************/
#define BDF_UNIX_EOL 1 /* Save fonts with Unix LF. */
#define BDF_DOS_EOL 2 /* Save fonts with DOS CRLF. */
#define BDF_MAC_EOL 3 /* Save fonts with Mac CR. */
#define BDF_CORRECT_METRICS 0x01 /* Correct invalid metrics when loading. */
#define BDF_KEEP_COMMENTS 0x02 /* Preserve the font comments. */
#define BDF_KEEP_UNENCODED 0x04 /* Keep the unencoded glyphs. */
#define BDF_PROPORTIONAL 0x08 /* Font has proportional spacing. */
#define BDF_MONOWIDTH 0x10 /* Font has mono width. */
#define BDF_CHARCELL 0x20 /* Font has charcell spacing. */
#define BDF_ALL_SPACING (BDF_PROPORTIONAL|BDF_MONOWIDTH|BDF_CHARCELL)
#define BDF_DEFAULT_LOAD_OPTIONS \
(BDF_CORRECT_METRICS|BDF_KEEP_COMMENTS|BDF_KEEP_UNENCODED|BDF_PROPORTIONAL)
typedef struct {
int ttf_hint;
int correct_metrics;
int keep_unencoded;
int keep_comments;
int pad_cells;
int font_spacing;
long point_size;
unsigned long resolution_x;
unsigned long resolution_y;
int bits_per_pixel;
int eol;
} bdf_options_t;
/*
* Callback function type for unknown configuration options.
*/
typedef int (*bdf_options_callback_t) (bdf_options_t *opts,
char **params,
unsigned long nparams,
void *client_data);
/**************************************************************************
*
* BDF font property macros and types.
*
**************************************************************************/
#define BDF_ATOM 1
#define BDF_INTEGER 2
#define BDF_CARDINAL 3
/*
* This structure represents a particular property of a font.
* There are a set of defaults and each font has their own.
*/
typedef struct {
char *name; /* Name of the property. */
int format; /* Format of the property. */
int builtin; /* A builtin property. */
union {
char *atom;
long int32;
unsigned long card32;
} value; /* Value of the property. */
} bdf_property_t;
/**************************************************************************
*
* BDF font metric and glyph types.
*
**************************************************************************/
/*
* A general bitmap type, mostly used when the glyph bitmap is being edited.
*/
typedef struct {
short x;
short y;
unsigned short width;
unsigned short height;
unsigned short bpp;
unsigned short pad;
unsigned char *bitmap;
unsigned long bytes;
} bdf_bitmap_t;
typedef struct {
int font_spacing;
unsigned short swidth;
unsigned short dwidth;
unsigned short width;
unsigned short height;
short x_offset;
short y_offset;
short ascent;
short descent;
} bdf_metrics_t;
typedef struct {
unsigned short width;
unsigned short height;
short x_offset;
short y_offset;
short ascent;
short descent;
} bdf_bbx_t;
typedef struct {
char *name; /* Glyph name. */
long encoding; /* Glyph encoding. */
unsigned short swidth; /* Scalable width. */
unsigned short dwidth; /* Device width. */
bdf_bbx_t bbx; /* Glyph bounding box. */
unsigned char *bitmap; /* Glyph bitmap. */
unsigned short bytes; /* Number of bytes used for the bitmap. */
} bdf_glyph_t;
typedef struct {
char *key;
void *data;
} _hashnode, *hashnode;
typedef struct {
int limit;
int size;
int used;
hashnode *table;
} hashtable;
typedef struct {
unsigned short pad; /* Pad to 4-byte boundary. */
unsigned short bpp; /* Bits per pixel. */
long start; /* Beginning encoding value of glyphs. */
long end; /* Ending encoding value of glyphs. */
bdf_glyph_t *glyphs; /* Glyphs themselves. */
unsigned long glyphs_size; /* Glyph structures allocated. */
unsigned long glyphs_used; /* Glyph structures used. */
bdf_bbx_t bbx; /* Overall bounding box of glyphs. */
} bdf_glyphlist_t;
typedef struct {
char *name; /* Name of the font. */
bdf_bbx_t bbx; /* Font bounding box. */
long point_size; /* Point size of the font. */
unsigned long resolution_x; /* Font horizontal resolution. */
unsigned long resolution_y; /* Font vertical resolution. */
int hbf; /* Font came from an HBF font. */
int spacing; /* Font spacing value. */
unsigned short monowidth; /* Logical width for monowidth font. */
long default_glyph; /* Encoding of the default glyph. */
long font_ascent; /* Font ascent. */
long font_descent; /* Font descent. */
long glyphs_size; /* Glyph structures allocated. */
long glyphs_used; /* Glyph structures used. */
bdf_glyph_t *glyphs; /* Glyphs themselves. */
long unencoded_size; /* Unencoded glyph structures allocated. */
long unencoded_used; /* Unencoded glyph structures used. */
bdf_glyph_t *unencoded; /* Unencoded glyphs themselves. */
unsigned long props_size; /* Font properties allocated. */
unsigned long props_used; /* Font properties used. */
bdf_property_t *props; /* Font properties themselves. */
char *comments; /* Font comments. */
unsigned long comments_len; /* Length of comment string. */
char *acmsgs; /* Auto-correction messages. */
unsigned long acmsgs_len; /* Length of auto-correction messages. */
bdf_glyphlist_t overflow; /* Storage used for glyph insertion. */
void *internal; /* Internal data for the font. */
unsigned long nmod[2048]; /* Bitmap indicating modified glyphs. */
unsigned long umod[2048]; /* Bitmap indicating modified unencoded. */
unsigned short modified; /* Boolean indicating font modified. */
unsigned short bpp; /* Bits per pixel. */
FT_Memory memory;
bdf_property_t *user_props;
unsigned long nuser_props;
hashtable proptbl;
} bdf_font_t;
/**************************************************************************
*
* Types for load/save callbacks.
*
**************************************************************************/
/*
* Callback reasons.
*/
#define BDF_LOAD_START 1
#define BDF_LOADING 2
#define BDF_SAVE_START 3
#define BDF_SAVING 4
#define BDF_TRANSLATE_START 5
#define BDF_TRANSLATING 6
#define BDF_ROTATE_START 7
#define BDF_ROTATING 8
#define BDF_SHEAR_START 9
#define BDF_SHEARING 10
#define BDF_GLYPH_NAME_START 11
#define BDF_GLYPH_NAME 12
#define BDF_EXPORT_START 13
#define BDF_EXPORTING 14
#define BDF_EMBOLDEN_START 15
#define BDF_EMBOLDENING 16
#define BDF_WARNING 20
#define BDF_ERROR 21
/*
* Error codes.
*/
#define BDF_OK 0
#define BDF_MISSING_START -1
#define BDF_MISSING_FONTNAME -2
#define BDF_MISSING_SIZE -3
#define BDF_MISSING_FONTBBX -4
#define BDF_MISSING_CHARS -5
#define BDF_MISSING_STARTCHAR -6
#define BDF_MISSING_ENCODING -7
#define BDF_MISSING_BBX -8
#define BDF_NOT_CONSOLE_FONT -10
#define BDF_NOT_MF_FONT -11
#define BDF_NOT_PSF_FONT -12
#define BDF_OUT_OF_MEMORY -20
#define BDF_EMPTY_FONT -99
#define BDF_INVALID_LINE -100
typedef struct {
unsigned long reason;
unsigned long current;
unsigned long total;
unsigned long errlineno;
} bdf_callback_struct_t;
typedef void (*bdf_callback_t) (bdf_callback_struct_t *call_data,
void *client_data);
/**************************************************************************
*
* BDF font API.
*
**************************************************************************/
/*
* Startup and shutdown functions are no more needed
*/
/*
* Font options functions.
*/
/*extern void bdf_default_options (bdf_options_t *opts);*/
/*
* Font load, create, save and free functions.
*/
FT_LOCAL( bdf_font_t* ) bdf_load_font (FT_Stream stream, FT_Memory memory,
bdf_options_t *opts,
bdf_callback_t callback, void *data);
FT_LOCAL( void ) bdf_free_font (bdf_font_t *font);
/*
* Font property functions.
*/
/* extern void bdf_create_property (char *name, int type, bdf_font_t *font); */
FT_LOCAL( bdf_property_t* ) bdf_get_property (char *name, bdf_font_t *font);
FT_LOCAL( unsigned long ) bdf_property_list (bdf_property_t **props);
FT_LOCAL( void ) bdf_add_font_property (bdf_font_t *font,
bdf_property_t *property);
FT_LOCAL( void ) bdf_delete_font_property (bdf_font_t *font, char *name);
FT_LOCAL( bdf_property_t* ) bdf_get_font_property (bdf_font_t *font,
char *name);
FT_LOCAL( unsigned long ) bdf_font_property_list (bdf_font_t *font,
bdf_property_t **props);
/*
* Font comment functions.
*/
FT_LOCAL( int ) bdf_replace_comments (bdf_font_t *font, char *comments,
unsigned long comments_len);
/*
* Other miscellaneous functions.
*/
FT_LOCAL( void ) bdf_set_default_metrics (bdf_font_t *font);
/* */
FT_END_HEADER
#endif /* _h_bdf */

463
src/bdf/bdfdriver.c Normal file
View File

@ -0,0 +1,463 @@
/* bdfdriver.c
FreeType font driver for bdf files
Copyright (C) 2001-2002 by
Francesco Zappa Nardelli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
#include "bdf.h"
#include "bdfdriver.h"
#include "bdferror.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_bdf
FT_CALLBACK_DEF( FT_Error )
BDF_Face_Done( BDF_Face face )
{
FT_Memory memory = FT_FACE_MEMORY( face );
bdf_free_font(face->bdffont);
FT_FREE( face->en_table );
FT_FREE( face->charset_encoding);
FT_FREE( face->charset_registry);
FT_FREE( face->root.family_name );
FT_FREE( face->root.available_sizes );
FT_FREE( face->bdffont );
FT_TRACE4(("bdf: done face\n"));
return FT_Err_Ok;
}
FT_CALLBACK_DEF( FT_Error )
BDF_Face_Init( FT_Stream stream,
BDF_Face face,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
FT_Error error = FT_Err_Ok;
FT_Memory memory = FT_FACE_MEMORY( face );
bdf_font_t* font;
bdf_options_t options;
FT_UNUSED( num_params );
FT_UNUSED( params );
FT_UNUSED( face_index );
(void) FT_STREAM_SEEK( 0 );
options.correct_metrics = 1; /* FZ XXX : options semantics */
options.keep_unencoded = 1;
options.pad_cells = 1;
font = bdf_load_font( stream, memory, &options, 0, 0 );
if ( font == NULL )
{
FT_TRACE2(("[not a valid BDF file]\n"));
goto Fail;
}
/* we have a bdf font: let's construct the face object */
face->bdffont = font;
{
FT_Face root = FT_FACE( face );
bdf_property_t* prop = NULL;
FT_TRACE4(("glyph %d - %d, unencoded %d %d\n",font->glyphs_size,
font->glyphs_used, font->unencoded_size, font->unencoded_used));
root->num_faces = 1;
root->face_index = 0;
root->face_flags = FT_FACE_FLAG_FIXED_SIZES |
FT_FACE_FLAG_HORIZONTAL |
FT_FACE_FLAG_FAST_GLYPHS ;
prop = bdf_get_font_property (font,"SPACING");
if ( prop && prop->format == BDF_ATOM )
{
if ( (*(prop->value.atom) == 'M') ||
(*(prop->value.atom) == 'C') )
{
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
}
}
}
/* FZ XXX : TO DO : FT_FACE_FLAGS_VERTICAL */
/* FZ XXX : I need a font to implement this */
root->style_flags = 0;
prop = bdf_get_font_property (font,"SLANT");
if ( prop && prop->format == BDF_ATOM )
{
if ( (*(prop->value.atom) == 'O' ) ||
(*(prop->value.atom) == 'I' ) )
{
root->style_flags |= FT_STYLE_FLAG_ITALIC;
}
}
prop = bdf_get_font_property (font,"WEIGHT_NAME");
if ( prop && prop->format == BDF_ATOM )
{
if ( *(prop->value.atom) == 'B' )
root->style_flags |= FT_STYLE_FLAG_BOLD;
}
prop = bdf_get_font_property (font,"FAMILY_NAME");
if (prop != NULL) {
int l = strlen(prop->value.atom) + 1;
if ( FT_ALLOC( root->family_name, l * sizeof(char)) )
goto Fail;
strcpy(root->family_name, prop->value.atom);
} else root->family_name = 0;
root->style_name = (char *)"Regular";
if ( root->style_flags & FT_STYLE_FLAG_BOLD )
{
if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
root->style_name = (char *)"Bold Italic";
else
root->style_name = (char *)"Bold";
}
else if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
root->style_name = (char *)"Italic";
root->num_glyphs = font->glyphs_size ; /* unencoded included */
root->num_fixed_sizes = 1;
if ( FT_ALLOC_ARRAY( root->available_sizes, 1,
FT_Bitmap_Size ) )
goto Fail;
prop = bdf_get_font_property(font,"PIXEL_SIZE");
if (prop != NULL) {
bdf_property_t *xres = 0, *yres = 0;
xres = bdf_get_font_property(font,"RESOLUTION_X");
yres = bdf_get_font_property(font,"RESOLUTION_Y");
if ((xres != NULL) && (yres != NULL)) {
FT_TRACE4(("prop %d %d %d\n",prop->value.int32, xres->value.int32,
yres->value.int32));
root->available_sizes->width =
prop->value.int32 * 75 / xres->value.int32;
root->available_sizes->height =
prop->value.int32 * 75 / yres->value.int32;
}
} else {
/* some fonts have broken SIZE declaration (jiskan24.bdf) */
FT_ERROR(("BDF Warning: reading size\n"));
root->available_sizes->width = font->point_size ;
root->available_sizes->height = font->point_size ;
}
/* encoding table */
{
bdf_glyph_t *cur = font->glyphs;
int n;
if ( FT_ALLOC ( face->en_table ,
font->glyphs_size * sizeof(BDF_encoding_el ) ) )
goto Fail;
for (n = 0; n<font->glyphs_size ; n++) {
(face->en_table[n]).enc = cur[n].encoding ;
FT_TRACE4(("enc n: %d, val %ld\n",n,cur[n].encoding));
(face->en_table[n]).glyph = n;
}
}
/* charmaps */
{
bdf_property_t *charset_registry = 0, *charset_encoding = 0;
charset_registry = bdf_get_font_property(font,"CHARSET_REGISTRY");
charset_encoding = bdf_get_font_property(font,"CHARSET_ENCODING");
if ((charset_registry != NULL) && (charset_encoding != NULL)) {
if ((charset_registry->format == BDF_ATOM) &&
(charset_encoding->format == BDF_ATOM)) {
if (FT_ALLOC(face->charset_encoding,
(strlen(charset_encoding->value.atom)+1) * sizeof(char)))
goto Exit;
if (FT_ALLOC(face->charset_registry,
(strlen(charset_registry->value.atom)+1) * sizeof(char)))
goto Exit;
strcpy(face->charset_registry,charset_registry->value.atom);
strcpy(face->charset_encoding,charset_encoding->value.atom);
face->charmap.encoding = ft_encoding_none;
face->charmap.platform_id = 0;
face->charmap.encoding_id = 0;
face->charmap.face = root;
face->charmap_handle = &face->charmap;
root->charmap = face->charmap_handle;
goto Exit;
}
}
/* otherwise assume adobe standard encoding */
face->charmap.encoding = ft_encoding_adobe_standard;
face->charmap.platform_id = 7; /* taken from t1objs.c */
face->charmap.encoding_id = 0;
face->charmap.face = root;
face->charmap_handle = &face->charmap;
root->charmap = face->charmap_handle;
}
}
Exit:
return FT_Err_Ok;
Fail:
BDF_Face_Done( face );
return FT_Err_Unknown_File_Format;
}
static
FT_Error BDF_Set_Pixel_Size( FT_Size size )
{
BDF_Face face = (BDF_Face)FT_SIZE_FACE( size );
FT_Face root = FT_FACE( face );
FT_TRACE4(("rec %d - pres %d\n",size->metrics.y_ppem,
root->available_sizes->height));
if (size->metrics.y_ppem == root->available_sizes->height) {
size->metrics.ascender = face->bdffont->bbx.ascent << 6;
size->metrics.descender = face->bdffont->bbx.descent * (-64);
size->metrics.height = face->bdffont->bbx.height <<6;
return FT_Err_Ok;
}
else {
return FT_Err_Invalid_Pixel_Size;
}
}
static
FT_Error BDF_Glyph_Load( FT_GlyphSlot slot,
FT_Size size,
FT_UInt glyph_index,
FT_Int load_flags )
{
BDF_Face face = (BDF_Face)FT_SIZE_FACE( size );
FT_Error error = FT_Err_Ok;
FT_Bitmap *bitmap = &slot->bitmap;
bdf_glyph_t glyph;
int i;
FT_Memory memory = face->bdffont->memory;
if (!face) {
error = FT_Err_Invalid_Argument;
goto Exit;
}
/* slot, bitmap => freetype, glyph => bdflib */
glyph = face->bdffont->glyphs[glyph_index];
bitmap->pitch = (glyph.bbx.width + 7) >> 3;
bitmap->rows = glyph.bbx.height;
bitmap->width = glyph.bbx.width;
bitmap->num_grays = 1; /* unused */
bitmap->pixel_mode = ft_pixel_mode_mono;
if ( FT_ALLOC ( bitmap->buffer , glyph.bytes) )
return FT_Err_Out_Of_Memory;
FT_MEM_SET( bitmap->buffer , 0 , glyph.bytes );
for (i=0 ; i<glyph.bytes ; i++) {
bitmap->buffer[i] = glyph.bitmap[i];
}
slot->bitmap_left = 0;
slot->bitmap_top = glyph.bbx.ascent ;
/* FZ TO DO : vertical metrics */
slot->metrics.horiAdvance = glyph.dwidth << 6;
slot->metrics.horiBearingX = glyph.bbx.x_offset << 6 ;
slot->metrics.horiBearingY = glyph.bbx.y_offset << 6 ;
slot->metrics.width = bitmap->width << 6 ;
slot->metrics.height = bitmap->rows << 6;
slot->linearHoriAdvance = (FT_Fixed)glyph.dwidth << 16;
slot->format = ft_glyph_format_bitmap;
slot->flags = FT_GLYPH_OWN_BITMAP;
Exit:
return error;
}
static
FT_UInt BDF_Get_Char_Index( FT_CharMap charmap,
FT_ULong char_code )
{
BDF_Face face = ((BDF_Face)charmap->face);
BDF_encoding_el *en_table = face->en_table;
int low, high, mid;
FT_TRACE4(("get_char_index %ld\n", char_code));
low = 0;
high = face->bdffont->glyphs_used - 1;
while (low <= high) {
mid = (low+high) / 2;
if (char_code < en_table[mid].enc)
high = mid - 1;
else if (char_code > en_table[mid].enc)
low = mid + 1;
else return en_table[mid].glyph;
}
return face->bdffont->default_glyph;
}
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec bdf_driver_class =
{
{
ft_module_font_driver,
sizeof ( FT_DriverRec ),
"bdf",
0x10000L,
0x20000L,
0,
(FT_Module_Constructor)0,
(FT_Module_Destructor) 0,
(FT_Module_Requester) 0
},
sizeof( BDF_FaceRec ),
sizeof( FT_SizeRec ),
sizeof( FT_GlyphSlotRec ),
(FT_Face_InitFunc) BDF_Face_Init,
(FT_Face_DoneFunc) BDF_Face_Done,
(FT_Size_InitFunc) 0,
(FT_Size_DoneFunc) 0,
(FT_Slot_InitFunc) 0,
(FT_Slot_DoneFunc) 0,
(FT_Size_ResetPointsFunc) BDF_Set_Pixel_Size,
(FT_Size_ResetPixelsFunc) BDF_Set_Pixel_Size,
(FT_Slot_LoadFunc) BDF_Glyph_Load,
#ifndef FT_CONFIG_OPTION_USE_CMAPS
(FT_CharMap_CharIndexFunc)0,
#else
(FT_CharMap_CharIndexFunc)0,
#endif
(FT_Face_GetKerningFunc) 0,
(FT_Face_AttachFunc) 0,
(FT_Face_GetAdvancesFunc) 0,
#ifndef FT_CONFIG_OPTION_USE_CMAPS
(FT_CharMap_CharNextFunc) 0, /*PCF_Char_Get_Next,*/
#else
(FT_CharMap_CharNextFunc) 0
#endif
};
/*
(FTDriver_initFace) BDF_Init_Face,
(FTDriver_doneFace) BDF_Done_Face,
(FTDriver_initSize) 0,
(FTDriver_doneSize) 0,
(FTDriver_initGlyphSlot)0,
(FTDriver_doneGlyphSlot)0,
(FTDriver_setCharSizes) BDF_Set_Pixel_Size,
(FTDriver_setPixelSizes)BDF_Set_Pixel_Size,
(FTDriver_loadGlyph) BDF_Load_Glyph,
(FTDriver_getCharIndex) BDF_Get_Char_Index,
(FTDriver_getKerning) 0,
(FTDriver_attachFile) 0,
(FTDriver_getAdvances) 0
*/
#ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
/*************************************************************************/
/* */
/* <Function> */
/* getDriverClass */
/* */
/* <Description> */
/* This function is used when compiling the TrueType driver as a */
/* shared library (`.DLL' or `.so'). It will be used by the */
/* high-level library of FreeType to retrieve the address of the */
/* driver's generic interface. */
/* */
/* It shouldn't be implemented in a static build, as each driver must */
/* have the same function as an exported entry point. */
/* */
/* <Return> */
/* The address of the TrueType's driver generic interface. The */
/* format-specific interface can then be retrieved through the method */
/* interface->get_format_interface. */
/* */
FT_EXPORT_DEF( const FT_Driver_Class* )
getDriverClass( void )
{
return &bdf_driver_class;
}
#endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */
/* END */

68
src/bdf/bdfdriver.h Normal file
View File

@ -0,0 +1,68 @@
/* bdfdriver.h
FreeType font driver for bdf fonts
Copyright (C) 2001 by
Francesco Zappa Nardelli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef __BDF_DRIVER_H__
#define __BDF_DRIVER_H__
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
#include "bdf.h"
FT_BEGIN_HEADER
typedef struct {
FT_Long enc;
FT_Short glyph;
} BDF_encoding_el;
typedef struct BDF_FaceRec_
{
FT_FaceRec root;
char *charset_encoding;
char *charset_registry;
bdf_font_t *bdffont;
BDF_encoding_el *en_table;
FT_CharMap charmap_handle;
FT_CharMapRec charmap; /* a single charmap per face */
} BDF_FaceRec, *BDF_Face;
FT_EXPORT_VAR( const FT_Driver_ClassRec ) bdf_driver_class;
FT_END_HEADER
#endif /* __BDF_DRIVER_H__ */
/* END */

44
src/bdf/bdferror.h Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright 2001 Francesco Zappa Nardelli
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*************************************************************************/
/* */
/* This file is used to define the PCF error enumeration constants. */
/* */
/*************************************************************************/
#ifndef __BDFERROR_H__
#define __BDFERROR_H__
#include FT_MODULE_ERRORS_H
#undef __FTERRORS_H__
#define FT_ERR_PREFIX BDF_Err_
#define FT_ERR_BASE FT_Mod_Err_BDF
#include FT_ERRORS_H
#endif /* __PCFERROR_H__ */
/* END */

2465
src/bdf/bdflib.c Normal file

File diff suppressed because it is too large Load Diff

31
src/bdf/module.mk Normal file
View File

@ -0,0 +1,31 @@
#
# FreeType 2 BDF module definition
#
# Copyright 2001 by
# Francesco Zappa Nardelli
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
make_module_list: add_bdf_driver
add_bdf_driver:
$(OPEN_DRIVER)bdf_driver_class$(CLOSE_DRIVER)
$(ECHO_DRIVER)bdf $(ECHO_DRIVER_DESC)bdf bitmap fonts$(ECHO_DRIVER_DONE)

80
src/bdf/rules.mk Normal file
View File

@ -0,0 +1,80 @@
#
# FreeType 2 bdf driver configuration rules
#
# Copyright (C) 2001 by
# Francesco Zappa Nardelli
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# bdf driver directory
#
BDF_DIR := $(SRC_)bdf
BDF_DIR_ := $(BDF_DIR)$(SEP)
BDF_COMPILE := $(FT_COMPILE) $I$(BDF_DIR)
# bdf driver sources (i.e., C files)
#
BDF_DRV_SRC := $(BDF_DIR_)bdflib.c $(BDF_DIR_)bdfdriver.c
# bdf driver headers
#
#BDF_DRV_H := $(BDF_DRV_SRC:%.c=%.h)
BDF_DRV_H := $(BDF_DIR_)bdf.h \
$(BDF_DIR_)bdfdriver.h
# bdf driver object(s)
#
# BDF_DRV_OBJ_M is used during `multi' builds
# BDF_DRV_OBJ_S is used during `single' builds
#
BDF_DRV_OBJ_M := $(BDF_DRV_SRC:$(BDF_DIR_)%.c=$(OBJ_)%.$O)
BDF_DRV_OBJ_S := $(OBJ_)bdf.$O
# bdf driver source file for single build
#
BDF_DRV_SRC_S := $(BDF_DIR_)bdf.c
# bdf driver - single object
#
$(BDF_DRV_OBJ_S): $(BDF_DRV_SRC_S) $(BDF_DRV_SRC) $(FREETYPE_H) $(BDF_DRV_H)
$(BDF_COMPILE) $T$@ $(BDF_DRV_SRC_S)
# bdf driver - multiple objects
#
$(OBJ_)%.$O: $(BDF_DIR_)%.c $(FREETYPE_H) $(BDF_DRV_H)
$(BDF_COMPILE) $T$@ $<
# update main driver object lists
#
DRV_OBJS_S += $(BDF_DRV_OBJ_S)
DRV_OBJS_M += $(BDF_DRV_OBJ_M)
# EOF