Hash :
e49ab25c
Author :
Date :
2000-05-16T23:44:38
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
/****************************************************************************/
/* */
/* The FreeType project -- a free and portable quality TrueType renderer. */
/* */
/* Copyright 1996-1998 by */
/* D. Turner, R.Wilhelm, and W. Lemberg */
/* */
/* ftsbit: a _very_ simple embedded bitmap dumper for FreeType 1.x. */
/* */
/* NOTE: This is just a test program that is used to show off and */
/* debug the current engine. */
/* */
/****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freetype.h"
#ifdef HAVE_LIBINTL_H
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#include <libintl.h>
#include "ftxerr18.h"
#else /* !HAVE_LIBINTL */
#define gettext( x ) ( x )
/* We ignore error message strings with this function */
static char* TT_ErrToString18( FT_Error error )
{
static char temp[32];
sprintf( temp, "0x%04lx", error );
return temp;
}
#endif /* !HAVE_LIBINTL */
FT_Error error;
FT_Library engine;
FT_Resource resource;
FT_Face face;
FT_Size instance;
FT_GlyphSlot glyph;
unsigned int num_glyphs;
int ptsize;
int Fail;
int Num;
static void Usage( char* name )
{
printf( gettext( "ftsbit: simple TrueType 'sbit' dumper -- part of the FreeType project\n" ) );
printf( "---------------------------------------------------------------------\n" );
printf( "\n" );
printf( gettext( "Usage: %s ppem fontname (index)* (index1-index2)*\n\n" ), name );
printf( gettext( " or %s -a ppem fontname (dumps all glyphs)\n" ), name );
printf( "\n" );
exit( EXIT_FAILURE );
}
static
void dump_bitmap( FT_GlyphSlot glyph, int glyph_index )
{
/* Dump the resulting bitmap */
{
int y;
unsigned char* line = (unsigned char*)glyph->bitmap.buffer;
printf( "glyph index %d = %dx%d pixels, ",
glyph_index, glyph->bitmap.rows, glyph->bitmap.width );
printf( "advance = %d, minBearing = [%d,%d]\n",
glyph->metrics.horiAdvance >> 6,
glyph->metrics.horiBearingX >> 6,
glyph->metrics.horiBearingY >> 6 );
for ( y = 0; y < glyph->bitmap.rows; y++, line += glyph->bitmap.cols )
{
unsigned char* ptr = line;
int x;
unsigned char mask = 0x80;
for ( x = 0; x < glyph->bitmap.width; x++ )
{
printf( "%c", (ptr[0] & mask) ? '*' : '.' );
mask >>= 1;
if (mask == 0)
{
mask = 0x80;
ptr++;
}
}
printf( "\n" );
}
}
}
static
void dump_range( FT_GlyphSlot glyph,
int first_glyph,
int last_glyph )
{
int i;
for ( i = first_glyph; i <= last_glyph; i++ )
{
error = FT_Load_Glyph( glyph,
instance,
(unsigned short)i,
FT_LOAD_NO_OUTLINE,
0 );
if (error)
{
printf( " no bitmap for glyph %d\n", i );
printf( gettext( "FreeType error message: %s\n" ),
TT_ErrToString18( error ) );
continue;
}
dump_bitmap(glyph,i);
}
}
int main( int argc, char** argv )
{
int i;
char filename[128 + 4];
char alt_filename[128 + 4];
char* execname;
char* fname;
int dump_all = 0;
#ifdef HAVE_LIBINTL_H
setlocale( LC_ALL, "" );
bindtextdomain( "freetype", LOCALEDIR );
textdomain( "freetype" );
#endif
execname = argv[0];
if ( argc < 3 )
Usage( execname );
if ( argv[1][0] == '-' &&
argv[1][1] == 'a' )
{
argv++;
argc--;
dump_all = 1;
}
if ( sscanf( argv[1], "%d", &ptsize ) != 1 )
Usage( execname );
/* Initialize engine */
if ( (error = FT_Init_FreeType( &engine )) )
{
fprintf( stderr, gettext( "Error while initializing engine\n" ) );
goto Failure;
}
/* Now check all files */
fname = argv[2];
i = strlen( fname );
while ( i > 0 && fname[i] != '\\' && fname[i] != '/' )
{
if ( fname[i] == '.' )
i = 0;
i--;
}
filename[128] = '\0';
alt_filename[128] = '\0';
strncpy( filename, fname, 128 );
strncpy( alt_filename, fname, 128 );
if ( i >= 0 )
{
strncpy( filename + strlen( filename ), ".ttf", 4 );
strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 );
}
/* Load face */
error = FT_New_Resource( engine, filename, &resource );
if (error)
{
strcpy( filename, alt_filename );
error = FT_New_Resource( engine, alt_filename, &resource );
}
i = strlen( filename );
fname = filename;
while ( i >= 0 )
if ( filename[i] == '/' || filename[i] == '\\' )
{
fname = filename + i + 1;
i = -1;
}
else
i--;
if ( error )
{
printf( gettext( "Could not find or open file.\n" ) );
goto Failure;
}
error = FT_New_Face( resource, 0, &face );
if (error)
{
printf( gettext( "Could not create face object.\n " ) );
goto Failure;
}
/* get face properties */
num_glyphs = face->num_glyphs;
/* create instance */
error = FT_New_Size( face, &instance );
if ( error )
{
printf( gettext( "Could not create instance.\n" ) );
goto Failure;
}
error = FT_Set_Pixel_Sizes( instance, ptsize, ptsize );
if (error)
{
printf( gettext( "Could not set character size.\n" ) );
goto Failure;
}
glyph = face->slot;
if (dump_all)
dump_range( glyph, 0, num_glyphs-1 );
else
{
for ( i = 3; i < argc; i++ )
{
/* check for range in argument string */
int range_check = 0;
char* base = argv[i];
char* cur = base;
int first, last;
while (*cur)
{
if (*cur == '-')
{
range_check = 1;
break;
}
cur++;
}
if (range_check)
{
if ( sscanf( argv[i], "%d-%d", &first, &last ) != 2 )
Usage( execname );
dump_range( glyph, first, last );
}
else
{
if ( sscanf( argv[i], "%d", &first ) != 1 )
Usage( execname );
dump_range( glyph, first, first );
}
}
}
FT_Done_FreeType( engine );
exit( EXIT_SUCCESS ); /* for safety reasons */
return 0; /* never reached */
Failure:
printf( gettext( "FreeType error message: %s\n" ),
TT_ErrToString18( error ) );
exit( EXIT_FAILURE );
}
/* End */