parent
6795f1e2b3
commit
a4540bb98a
24 changed files with 3309 additions and 2992 deletions
@ -0,0 +1,53 @@ |
||||
/* bdftypes.h
|
||||
|
||||
FreeType font driver for bdf fonts |
||||
|
||||
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. |
||||
*/ |
||||
|
||||
#ifndef __BDFTYPES_H__ |
||||
#define __BDFTYPES_H__ |
||||
|
||||
#include <ft2build.h> |
||||
#include FT_FREETYPE_H |
||||
|
||||
|
||||
FT_BEGIN_HEADER |
||||
|
||||
|
||||
typedef struct BDF_Public_FaceRec_ |
||||
{ |
||||
FT_FaceRec root; |
||||
|
||||
char* charset_encoding; |
||||
char* charset_registry; |
||||
|
||||
} BDF_Public_FaceRec, *BDF_Public_Face; |
||||
|
||||
|
||||
FT_END_HEADER |
||||
|
||||
|
||||
#endif /* __BDFTYPES_H__ */ |
||||
|
||||
|
||||
/* END */ |
@ -0,0 +1,85 @@ |
||||
/***************************************************************************/ |
||||
/* */ |
||||
/* t42types.h */ |
||||
/* */ |
||||
/* Type 42 font data types (specification only). */ |
||||
/* */ |
||||
/* Copyright 2002 by Roberto Alameda. */ |
||||
/* */ |
||||
/* 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 __T42TYPES_H__ |
||||
#define __T42TYPES_H__ |
||||
|
||||
|
||||
#include <ft2build.h> |
||||
#include FT_FREETYPE_H |
||||
#include FT_TYPE1_TABLES_H |
||||
#include FT_INTERNAL_TYPE1_TYPES_H |
||||
#include FT_INTERNAL_POSTSCRIPT_NAMES_H |
||||
#include FT_INTERNAL_POSTSCRIPT_HINTS_H |
||||
|
||||
|
||||
FT_BEGIN_HEADER |
||||
|
||||
|
||||
typedef struct T42_FontRec_
|
||||
{ |
||||
/* font info dictionary */ |
||||
PS_FontInfoRec font_info;
|
||||
|
||||
/* top-level dictionary */ |
||||
FT_String* font_name; |
||||
|
||||
T1_EncodingType encoding_type;
|
||||
T1_EncodingRec encoding; |
||||
|
||||
FT_Byte* charstrings_block; |
||||
FT_Byte* glyph_names_block; |
||||
|
||||
FT_Int num_glyphs; |
||||
FT_String** glyph_names; /* array of glyph names */ |
||||
FT_Byte** charstrings; /* array of glyph charstrings */ |
||||
FT_Int* charstrings_len; |
||||
|
||||
FT_Byte paint_type; |
||||
FT_Byte font_type; |
||||
FT_Matrix font_matrix; /* From FontMatrix field: a, b, c, d */ |
||||
FT_Vector font_offset; /* From FontMatrix field: tx, ty */ |
||||
FT_BBox font_bbox; |
||||
|
||||
FT_Int stroke_width;
|
||||
|
||||
} T42_FontRec, *T42_Font; |
||||
|
||||
|
||||
typedef struct T42_FaceRec_ |
||||
{ |
||||
FT_FaceRec root; |
||||
T42_FontRec type42; |
||||
const void* psnames; |
||||
const void* psaux; |
||||
const void* afm_data; |
||||
FT_Byte* ttf_data; |
||||
FT_ULong ttf_size; |
||||
FT_Face ttf_face; |
||||
FT_CharMapRec charmaprecs[2]; |
||||
FT_CharMap charmaps[2]; |
||||
PS_Unicodes unicode_map; |
||||
|
||||
} T42_FaceRec, *T42_Face; |
||||
|
||||
|
||||
FT_END_HEADER |
||||
|
||||
#endif /* __T1TYPES_H__ */ |
||||
|
||||
|
||||
/* END */ |
@ -0,0 +1,23 @@ |
||||
# FreeType 2 src/bdf Jamfile (c) 2002 David Turner |
||||
# |
||||
|
||||
SubDir FT2_TOP src bdf ; |
||||
|
||||
SubDirHdrs [ FT2_SubDir src bdf ] ; |
||||
|
||||
{ |
||||
local _sources ; |
||||
|
||||
if $(FT2_MULTI) |
||||
{ |
||||
_sources = bdfdrivr bdflib ; |
||||
} |
||||
else |
||||
{ |
||||
_sources = bdf ; |
||||
} |
||||
|
||||
Library $(FT2_LIB) : $(_sources).c ; |
||||
} |
||||
|
||||
# end of src/bdf Jamfile |
@ -0,0 +1,146 @@ |
||||
FreeType font driver for BDF fonts |
||||
|
||||
Francesco Zappa Nardelli |
||||
<francesco.zappa.nardelli@ens.fr> |
||||
|
||||
|
||||
Introduction |
||||
************ |
||||
|
||||
BDF (Bitmap Distribution Format) is a bitmap font format defined by Adobe, |
||||
which is intended to be easily understood by both humans and computers. |
||||
This code implements a BDF driver for the FreeType library, following the |
||||
Adobe Specification V 2.2. The specification of the BDF font format is |
||||
available from Adobe's web site: |
||||
|
||||
http://partners.adobe.com/asn/developer/PDFS/TN/5005.BDF_Spec.pdf |
||||
|
||||
Many good bitmap fonts in bdf format come with XFree86 (www.XFree86.org). |
||||
They do not define vertical metrics, because the X Consortium BDF |
||||
specification has removed them. |
||||
|
||||
|
||||
Encodings |
||||
********* |
||||
|
||||
The variety of encodings that accompanies bdf fonts appears to encompass the |
||||
small set defined in freetype.h. On the other hand, two properties that |
||||
specify encoding and registry are usually defined in bdf fonts. |
||||
|
||||
I decided to make these two properties directly accessible, leaving to the |
||||
client application the work of interpreting them. For instance: |
||||
|
||||
|
||||
#include FT_INTERNAL_BDF_TYPES_H |
||||
|
||||
FT_Face face; |
||||
BDF_Public_Face bdfface; |
||||
|
||||
|
||||
FT_New_Face( library, ..., &face ); |
||||
|
||||
bdfface = (BDF_Public_Face)face; |
||||
|
||||
if ( ( bdfface->charset_registry == "ISO10646" ) && |
||||
( bdfface->charset_encoding == "1" ) ) |
||||
[..] |
||||
|
||||
|
||||
Thus the driver always exports `ft_encoding_none' as face->charmap.encoding. |
||||
FT_Get_Char_Index's behavior is unmodified, that is, it converts the ULong |
||||
value given as argument into the corresponding glyph number. |
||||
|
||||
If the two properties are not available, Adobe Standard Encoding should be |
||||
assumed. |
||||
|
||||
|
||||
Anti-Aliased Bitmaps |
||||
******************** |
||||
|
||||
The driver supports an extension to the BDF format as used in Mark Leisher's |
||||
xmbdfed bitmap font editor. It introduces a fourth field to the `SIZE' |
||||
keyword which gives the bpp value (bits per pixel) of the glyph data in the |
||||
font. Possible values are 1 (the default), 2 (four gray levels), and 4 (16 |
||||
gray levels). The driver returns either a bitmap with 1 bit per pixel or a |
||||
pixmap with 8bits per pixel (using 4 and 16 gray levels, respectively). |
||||
|
||||
|
||||
Known problems |
||||
************** |
||||
|
||||
- A font is entirely loaded into memory. Obviously, this is not the Right |
||||
Thing(TM). If you have big fonts I suggest you convert them into PCF |
||||
format (using the bdftopcf utility): the PCF font drive of FreeType can |
||||
perform incremental glyph loading. |
||||
|
||||
When I have some time, I will implement on-demand glyph parsing. |
||||
|
||||
- Except for encodings properties, client applications have no visibility of |
||||
the PCF_Face object. This means that applications cannot directly access |
||||
font tables and must trust FreeType. |
||||
|
||||
- Currently, glyph names are ignored. |
||||
|
||||
I plan to give full visibility of the BDF_Face object in an upcoming |
||||
revision of the driver, thus implementing also glyph names. |
||||
|
||||
- As I have never seen a BDF font that defines vertical metrics, vertical |
||||
metrics are (parsed and) discarded. If you own a BDF font that defines |
||||
vertical metrics, please let me know (I will implement them in 5-10 |
||||
minutes). |
||||
|
||||
|
||||
License |
||||
******* |
||||
|
||||
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. |
||||
|
||||
*** Portions of the driver (that is, bdflib.c and bdf.h): |
||||
|
||||
Copyright 2000 Computing Research Labs, New Mexico State University |
||||
Copyright 2001-2002 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. |
||||
|
||||
|
||||
Credits |
||||
******* |
||||
|
||||
This driver is based on excellent Mark Leisher's bdf library. If you |
||||
find something good in this driver you should probably thank him, not |
||||
me. |
@ -1,463 +0,0 @@ |
||||
/* 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 */ |
@ -0,0 +1,564 @@ |
||||
/* bdfdrivr.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 "bdfdrivr.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_bdfdriver |
||||
|
||||
|
||||
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_Face_Done: done face\n" )); |
||||
|
||||
return BDF_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 = BDF_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 ); |
||||
|
||||
|
||||
if ( FT_STREAM_SEEK( 0 ) ) |
||||
goto Exit; |
||||
|
||||
options.correct_metrics = 1; /* FZ XXX: options semantics */ |
||||
options.keep_unencoded = 1; |
||||
options.keep_comments = 0; |
||||
options.font_spacing = BDF_PROPORTIONAL; |
||||
|
||||
error = bdf_load_font( stream, memory, &options, &font ); |
||||
if ( error == BDF_Err_Missing_Startfont_Field ) |
||||
{ |
||||
FT_TRACE2(( "[not a valid BDF file]\n" )); |
||||
goto Fail; |
||||
} |
||||
else if ( error ) |
||||
goto Exit; |
||||
|
||||
/* 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(( "number of glyphs: %d (%d)\n", |
||||
font->glyphs_size, |
||||
font->glyphs_used )); |
||||
FT_TRACE4(( "number of unencoded glyphs: %d (%d)\n", |
||||
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, (char *)"SPACING" ); |
||||
if ( prop != NULL ) |
||||
if ( 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, (char *)"SLANT" ); |
||||
if ( prop != NULL ) |
||||
if ( 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, (char *)"WEIGHT_NAME" ); |
||||
if ( prop != NULL ) |
||||
if ( prop->format == BDF_ATOM ) |
||||
if ( *(prop->value.atom) == 'B' ) |
||||
root->style_flags |= FT_STYLE_FLAG_BOLD; |
||||
|
||||
prop = bdf_get_font_property( font, (char *)"FAMILY_NAME" ); |
||||
if ( prop != NULL ) |
||||
{ |
||||
int l = ft_strlen( prop->value.atom ) + 1; |
||||
|
||||
|
||||
if ( FT_NEW_ARRAY( root->family_name, l ) ) |
||||
goto Exit; |
||||
ft_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_NEW_ARRAY( root->available_sizes, 1 ) ) |
||||
goto Exit; |
||||
|
||||
prop = bdf_get_font_property( font, (char *)"PIXEL_SIZE" ); |
||||
if ( prop != NULL ) |
||||
{ |
||||
bdf_property_t *xres = 0, *yres = 0; |
||||
|
||||
|
||||
xres = bdf_get_font_property( font, (char *)"RESOLUTION_X" ); |
||||
yres = bdf_get_font_property( font, (char *)"RESOLUTION_Y" ); |
||||
if ( ( xres != NULL ) && ( yres != NULL ) ) |
||||
{ |
||||
FT_TRACE4(( "PIXEL_SIZE: %d RESOLUTION_X: %d RESOLUTION_Y: %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_Face_Init: 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; |
||||
unsigned long n; |
||||
|
||||
|
||||
if ( FT_NEW_ARRAY( face->en_table, font->glyphs_size ) ) |
||||
goto Exit; |
||||
|
||||
for ( n = 0; n < font->glyphs_size; n++ ) |
||||
{ |
||||
(face->en_table[n]).enc = cur[n].encoding; |
||||
FT_TRACE4(( "idx %d, val 0x%lX\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, (char *)"CHARSET_REGISTRY" ); |
||||
charset_encoding = |
||||
bdf_get_font_property( font, (char *)"CHARSET_ENCODING" ); |
||||
if ( ( charset_registry != NULL ) && ( charset_encoding != NULL ) ) |
||||
{ |
||||
if ( ( charset_registry->format == BDF_ATOM ) && |
||||
( charset_encoding->format == BDF_ATOM ) ) |
||||
{ |
||||
if ( FT_NEW_ARRAY( face->charset_encoding, |
||||
strlen( charset_encoding->value.atom ) + 1 ) ) |
||||
goto Exit; |
||||
if (FT_NEW_ARRAY( face->charset_registry, |
||||
strlen( charset_registry->value.atom ) + 1 ) ) |
||||
goto Exit; |
||||
ft_strcpy( face->charset_registry, charset_registry->value.atom ); |
||||
ft_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 error; |
||||
|
||||
Fail: |
||||
BDF_Face_Done( face ); |
||||
return BDF_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 BDF_Err_Ok; |
||||
} |
||||
else |
||||
return BDF_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 = BDF_Err_Ok; |
||||
FT_Bitmap* bitmap = &slot->bitmap; |
||||
bdf_glyph_t glyph; |
||||
int bpp = face->bdffont->bpp; |
||||
int i, j, count; |
||||
unsigned char *p, *pp; |
||||
|
||||
FT_Memory memory = face->bdffont->memory; |
||||
|
||||
FT_UNUSED( load_flags ); |
||||
|
||||
|
||||
if ( !face ) |
||||
{ |
||||
error = BDF_Err_Invalid_Argument; |
||||
goto Exit; |
||||
} |
||||
|
||||
/* slot, bitmap => freetype, glyph => bdflib */ |
||||
glyph = face->bdffont->glyphs[glyph_index]; |
||||
|
||||
bitmap->rows = glyph.bbx.height; |
||||
bitmap->width = glyph.bbx.width; |
||||
|
||||
if ( bpp == 1 ) |
||||
{ |
||||
bitmap->pixel_mode = ft_pixel_mode_mono; |
||||
bitmap->pitch = glyph.bpr; |
||||
|
||||
if ( FT_NEW_ARRAY( bitmap->buffer, glyph.bytes ) ) |
||||
goto Exit; |
||||
FT_MEM_COPY( bitmap->buffer, glyph.bitmap, glyph.bytes ); |
||||
} |
||||
else |
||||
{ |
||||
/* blow up pixmap to have 8 bits per pixel */ |
||||
bitmap->pixel_mode = ft_pixel_mode_grays; |
||||
bitmap->pitch = bitmap->width; |
||||
|
||||
if ( FT_NEW_ARRAY( bitmap->buffer, bitmap->rows * bitmap->pitch ) ) |
||||
goto Exit; |
||||
|
||||
switch ( bpp ) |
||||
{ |
||||
case 2: |
||||
bitmap->num_grays = 4; |
||||
|
||||
count = 0; |
||||
p = glyph.bitmap; |
||||
|
||||
for ( i = 0; i < bitmap->rows; i++ ) |
||||
{ |
||||
pp = p; |
||||
|
||||
/* get the full bytes */ |
||||
for ( j = 0; j < ( bitmap->width >> 2 ); j++ ) |
||||
{ |
||||
bitmap->buffer[count++] = ( *pp & 0xC0 ) >> 6; |
||||
bitmap->buffer[count++] = ( *pp & 0x30 ) >> 4; |
||||
bitmap->buffer[count++] = ( *pp & 0x0C ) >> 2; |
||||
bitmap->buffer[count++] = *pp & 0x03; |
||||
|
||||
pp++; |
||||
} |
||||
|
||||
/* get remaining pixels (if any) */ |
||||
switch ( bitmap->width & 3 ) |
||||
{ |
||||
case 3: |
||||
bitmap->buffer[count++] = ( *pp & 0xC0 ) >> 6; |
||||
/* fall through */ |
||||
case 2: |
||||
bitmap->buffer[count++] = ( *pp & 0x30 ) >> 4; |
||||
/* fall through */ |
||||
case 1: |
||||
bitmap->buffer[count++] = ( *pp & 0x0C ) >> 2; |
||||
/* fall through */ |
||||
case 0: |
||||
break; |
||||
} |
||||
|
||||
p += glyph.bpr; |
||||
} |
||||
break; |
||||
|
||||
case 4: |
||||
bitmap->num_grays = 16; |
||||
|
||||
count = 0; |
||||
p = glyph.bitmap; |
||||
|
||||
for ( i = 0; i < bitmap->rows; i++ ) |
||||
{ |
||||
pp = p; |
||||
|
||||
/* get the full bytes */ |
||||
for ( j = 0; j < ( bitmap->width >> 1 ); j++ ) |
||||
{ |
||||
bitmap->buffer[count++] = ( *pp & 0xF0 ) >> 4; |
||||
bitmap->buffer[count++] = *pp & 0x0F; |
||||
|
||||
pp++; |
||||
} |
||||
|
||||
/* get remaining pixel (if any) */ |
||||
switch ( bitmap->width & 1 ) |
||||
{ |
||||
case 1: |
||||
bitmap->buffer[count++] = ( *pp & 0xF0 ) >> 4; |
||||
/* fall through */ |
||||
case 0: |
||||
break; |
||||
} |
||||
|
||||
p += glyph.bpr; |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
slot->bitmap_left = 0; |
||||
slot->bitmap_top = glyph.bbx.ascent; |
||||
|
||||
/* FZ XXX: TODO: 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(( "BDF_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)BDF_Get_Char_Index, |
||||
#endif |
||||
|
||||
(FT_Face_GetKerningFunc) 0, |
||||
(FT_Face_AttachFunc) 0, |
||||
(FT_Face_GetAdvancesFunc) 0, |
||||
|
||||
#ifndef FT_CONFIG_OPTION_USE_CMAPS |
||||
(FT_CharMap_CharNextFunc) 0, /* BDF_Char_Get_Next,*/ |
||||
#else |
||||
(FT_CharMap_CharNextFunc) 0 |
||||
#endif |
||||
}; |
||||
|
||||
|
||||
#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 */ |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue