Formatting.
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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
diff --git a/ChangeLog b/ChangeLog
index 42dcd2e..551876b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,25 +1,48 @@
2005-03-15 David Turner <david@freetype.org>
- * src/bdf/bdflib.c: removing compiler warnings
-
- * docs/CHANGES: updating
-
- * src/type1/t1parse.c (T1_New_Parser), src/type42/t42parse.c
- (t42_parser_init): modifying functions to check the font header before
- allocating anything on the heap.
-
- * internal/freetype/ftmemory.h: introducing the new macros FT_ARRAY_MAX
- and FT_ARRAY_CHECK
-
- * src/pcf/pcfread.c, src/pcf/pcfutil.c: minor fixes and simplifications.
- try to protect the PCF driver from doing stupid things with broken fonts.
-
- * src/lzw/ftlzw.c (FT_Stream_OpenLZW): modified the function to check
- the LZW header before doing anything else. This helps avoid un-necessary
- heap allocations (400 Kb of heap memory for the LZW decoder ! Oh my !)
-
- * src/gzip/ftgzip.c (FT_Stream_OpenGZip): ditto for the .gz decoder,
- though the code savings is smaller.
+ * src/bdf/bdflib.c: Remove compiler warnings.
+ (hash_rehash, hash_init): Don't call FT_MEM_ZERO.
+ (_bdf_list_t): Add `memory' field.
+ (_bdf_list_init, _bdf_list_done, _bdf_list_ensure): New functions.
+ (_bdf_shift, _bdf_join): Rename to...
+ (_bdf_list_shift, _bdf_list_join): This.
+ (_bdf_split): Renamed to...
+ (_bdf_list_split): This. Use new functions.
+ (bdf_internal_readstream): Removed.
+ (NO_SKIP): New macro.
+ (_bdf_readstream): Rewritten.
+ (bdf_create_property, _bdf_add_comment): Improve allocation.
+ (_bdf_set_default_spacing, _bdf_parse_glyphs): Updated. Improve
+ allocation.
+ (_bdf_parse_properties, _bdf_parse_start): Updated.
+ (bdf_load_font): Updated to use new functions.
+
+ * src/type1/t1parse.c (check_type1_format): New function.
+ (T1_New_Parser): Use it to check font header before allocating
+ anything on the heap.
+
+ * src/type42/t42parse.c (t42_parser_init): Modify functions to check
+ the font header before allocating anything on the heap.
+
+ * include/freetype/internal/ftmemory.h (FT_ARRAY_MAX,
+ FT_ARRAY_CHECK): New macros.
+
+ * src/base/ftstream.c (FT_Stream_TryRead): New function.
+ * include/freetype/internal/ftstream.h: Updated.
+
+ * src/pcf/pcfread.c (pcf_read_TOC), src/pcf/pcfutil.c
+ (BitOrderInvert, TwoByteSwap, FourByteSwap): Minor fixes and
+ simplifications. Try to protect the PCF driver from doing stupid
+ things with broken fonts.
+
+ * src/lzw/ftlzw.c (FT_Stream_OpenLZW): Check the LZW header before
+ doing anything else. This avoids unnecessary heap allocations
+ (400KByte of heap memory for the LZW decoder).
+
+ * src/gzip/ftgzip.c (FT_Stream_OpenGZip): Ditto for the gzip
+ decoder, although the code savings are smaller.
+
+ * docs/CHANGES: Updated.
2005-03-10 David Turner <david@freetype.org>
diff --git a/docs/CHANGES b/docs/CHANGES
index 4ef3c24..cc19787 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -19,28 +19,28 @@ LATEST CHANGES BETWEEN 2.1.10 and 2.1.9
- FreeType didn't properly parse empty Type 1 glyphs.
- - An unbounded dynamic buffer growth was fixed in the PFR loader
+ - An unbound dynamic buffer growth was fixed in the PFR loader.
- - Several bugs were fixed in the cache sub-system.
+ - Several bugs have been fixed in the cache sub-system.
- - Fixed bug #12263: incorrect behaviour when resizing to distinct but
- very close character pixel sizes through FT_Set_Char_Size
+ - FreeType behaved incorrectly when resizing two distinct but very
+ close character pixel sizes through `FT_Set_Char_Size' (Savannah
+ bug #12263).
- - The auto-hinter didn't work when a font didn't have a Unicode charmap.
- it even refused to load the glyphs !
+ - The auto-hinter didn't work properly for fonts without a Unicode
+ charmap -- it even refused to load the glyphs.
II. IMPORTANT CHANGES
- - a LOT of work has been done in order to drastically reduce the
- amount of heap memory used by FreeType, especially when using
- memory-mapped font files (which is the default on Unix systems
- which support them). This should be good news for any Unix distribution
- upgrading to this release of the font engine.
+ - Many fixes have been applied to drastically reduce the amount of
+ heap memory used by FreeType, especially when using
+ memory-mapped font files (which is the default on Unix systems
+ which support them).
- - The auto-hinter has been completely rewritten as a new module,
- called the 'auto-fitter'. The latter is the new default auto-hinting
- module. It also consumes a lot less memory than its predecessor.
+ - The auto-hinter has been completely rewritten as a new module,
+ called the `auto-fitter', which is now the default auto-hinting
+ module. It consumes a lot less memory than its predecessor.
- George Williams contributed code to read kerning data from PFM
files.
@@ -63,6 +63,7 @@ LATEST CHANGES BETWEEN 2.1.10 and 2.1.9
an FT_Bitmap structure in 1bpp, 2bpp, 4bpp, or 8bpp format into
another 8bpp FT_Bitmap, probably using a different pitch.
+
III. MISCELLANEOUS
- The BDF driver no longer converts all returned bitmaps with a
@@ -87,6 +88,9 @@ LATEST CHANGES BETWEEN 2.1.10 and 2.1.9
the array in a novel compressed way that saves about 20 Kb of code
as well.
+
+======================================================================
+
LATEST CHANGES BETWEEN 2.1.9 and 2.1.8
I. IMPORTANT BUG FIXES
diff --git a/include/freetype/internal/ftmemory.h b/include/freetype/internal/ftmemory.h
index 70e3a3f..e255379 100644
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -270,13 +270,16 @@ FT_BEGIN_HEADER
#define FT_ARRAY_MOVE( dest, source, count ) \
FT_MEM_MOVE( dest, source, (count) * sizeof ( *(dest) ) )
-/* return the maximum number of adressable elements in an array
- * we limit ourselves to INT_MAX, rather than UINT_MAX, to avoid
- * any problems
- */
-#define FT_ARRAY_MAX( ptr ) (FT_INT_MAX/sizeof( *(ptr) ))
-#define FT_ARRAY_CHECK( ptr, count ) ( (count) <= FT_ARRAY_MAX(ptr) )
+ /*
+ * Return the maximum number of adressable elements in an array.
+ * We limit ourselves to INT_MAX, rather than UINT_MAX, to avoid
+ * any problems.
+ */
+#define FT_ARRAY_MAX( ptr ) ( FT_INT_MAX / sizeof ( *(ptr) ) )
+
+#define FT_ARRAY_CHECK( ptr, count ) ( (count) <= FT_ARRAY_MAX( ptr ) )
+
/*************************************************************************/
/* */
diff --git a/include/freetype/internal/ftstream.h b/include/freetype/internal/ftstream.h
index b5c7066..1fa9db4 100644
--- a/include/freetype/internal/ftstream.h
+++ b/include/freetype/internal/ftstream.h
@@ -4,7 +4,7 @@
/* */
/* Stream handling (specification). */
/* */
-/* Copyright 1996-2001, 2002, 2004 by */
+/* Copyright 1996-2001, 2002, 2004, 2005 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -385,9 +385,8 @@ FT_BEGIN_HEADER
FT_Byte* buffer,
FT_ULong count );
- /* try to read bytes at the end of a stream, return
- * the number of bytes really available
- */
+ /* try to read bytes at the end of a stream; return number of bytes */
+ /* really available */
FT_BASE( FT_ULong )
FT_Stream_TryRead( FT_Stream stream,
FT_Byte* buffer,
diff --git a/src/base/ftstream.c b/src/base/ftstream.c
index 2ff29cb..3b7b29f 100644
--- a/src/base/ftstream.c
+++ b/src/base/ftstream.c
@@ -4,7 +4,7 @@
/* */
/* I/O stream support (body). */
/* */
-/* Copyright 2000-2001, 2002, 2004 by */
+/* Copyright 2000-2001, 2002, 2004, 2005 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index e14fd65..c7064f2 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -1,6 +1,6 @@
/*
* Copyright 2000 Computing Research Labs, New Mexico State University
- * Copyright 2001, 2002, 2003, 2004 Francesco Zappa Nardelli
+ * Copyright 2001, 2002, 2003, 2004, 2005 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"),
@@ -392,19 +392,21 @@
_bdf_list_init( _bdf_list_t* list,
FT_Memory memory )
{
- FT_ZERO(list);
+ FT_ZERO( list );
list->memory = memory;
}
+
static void
_bdf_list_done( _bdf_list_t* list )
{
FT_Memory memory = list->memory;
+
if ( memory )
{
FT_FREE( list->field );
- FT_ZERO(list);
+ FT_ZERO( list );
}
}
@@ -413,18 +415,20 @@
_bdf_list_ensure( _bdf_list_t* list,
int num_items )
{
- FT_Error error = 0;
+ FT_Error error = BDF_Err_Ok;
+
if ( num_items > (int)list->size )
{
- int oldsize = list->size;
- int newsize = oldsize + (oldsize >> 1) + 4;
- int bigsize = FT_INT_MAX / sizeof(char*);
+ int oldsize = list->size;
+ int newsize = oldsize + ( oldsize >> 1 ) + 4;
+ int bigsize = FT_INT_MAX / sizeof ( char* );
FT_Memory memory = list->memory;
+
if ( oldsize == bigsize )
{
- error = FT_Err_Out_Of_Memory;
+ error = BDF_Err_Out_Of_Memory;
goto Exit;
}
else if ( newsize < oldsize || newsize > bigsize )
@@ -435,6 +439,7 @@
list->size = newsize;
}
+
Exit:
return error;
}
@@ -493,13 +498,11 @@
}
-
/* An empty string for empty fields. */
static const char empty[1] = { 0 }; /* XXX eliminate this */
-
static FT_Error
_bdf_list_split( _bdf_list_t* list,
char* separators,
@@ -553,7 +556,7 @@
/* Resize the list if necessary. */
if ( list->used == list->size )
{
- error = _bdf_list_ensure( list, list->used+1 );
+ error = _bdf_list_ensure( list, list->used + 1 );
if ( error )
goto Exit;
}
@@ -582,7 +585,7 @@
/* Finally, NULL-terminate the list. */
if ( list->used + final_empty >= list->size )
{
- error = _bdf_list_ensure( list, list->used+final_empty+1 );
+ error = _bdf_list_ensure( list, list->used + final_empty + 1 );
if ( error )
goto Exit;
}
@@ -597,9 +600,9 @@
}
-
#define NO_SKIP 256 /* this value cannot be stored in a 'char' */
+
static FT_Error
_bdf_readstream( FT_Stream stream,
_bdf_line_func_t callback,
@@ -621,29 +624,28 @@
goto Exit;
}
- /* initial size and allocation of the input buffer
- */
+ /* initial size and allocation of the input buffer */
buf_size = 1024;
if ( FT_NEW_ARRAY( buf, buf_size ) )
goto Exit;
- cb = callback;
- lineno = 1;
- buf[0] = 0;
- start = 0;
- end = 0;
- avail = 0;
- cursor = 0;
- refill = 1;
- to_skip = NO_SKIP;
- bytes = 0; /* make compiler happy */
+ cb = callback;
+ lineno = 1;
+ buf[0] = 0;
+ start = 0;
+ end = 0;
+ avail = 0;
+ cursor = 0;
+ refill = 1;
+ to_skip = NO_SKIP;
+ bytes = 0; /* make compiler happy */
for (;;)
{
if ( refill )
{
- bytes = (int) FT_Stream_TryRead( stream, (FT_Byte*)buf + cursor,
+ bytes = (int)FT_Stream_TryRead( stream, (FT_Byte*)buf + cursor,
(FT_ULong)(buf_size - cursor) );
avail = cursor + bytes;
cursor = 0;
@@ -652,7 +654,7 @@
end = start;
- /* should we skip an optional character like \n or \r ? */
+ /* should we skip an optional character like \n or \r? */
if ( start < avail && buf[start] == to_skip )
{
start += 1;
@@ -664,9 +666,8 @@
while ( end < avail && buf[end] != '\n' && buf[end] != '\r' )
end++;
- /* if we hit the end of the buffer, try shifting its content
- * or even resizing it
- */
+ /* if we hit the end of the buffer, try shifting its content */
+ /* or even resizing it */
if ( end >= avail )
{
if ( bytes == 0 ) /* last line in file doesn't end in \r or \n */
@@ -674,18 +675,18 @@
if ( start == 0 )
{
- /* this line is definitely too long, try resizing the input buffer
- * a bit to handle it.
- */
+ /* this line is definitely too long; try resizing the input */
+ /* buffer a bit to handle it. */
FT_ULong new_size;
- if ( buf_size >= 65536UL ) /* limit ourselves to 64 Kb */
+
+ if ( buf_size >= 65536UL ) /* limit ourselves to 64KByte */
{
error = BDF_Err_Invalid_Argument;
goto Exit;
}
- new_size = buf_size*2;
+ new_size = buf_size * 2;
if ( FT_RENEW_ARRAY( buf, buf_size, new_size ) )
goto Exit;
@@ -696,7 +697,7 @@
{
bytes = avail - start;
- FT_MEM_COPY( buf, buf+start, bytes );
+ FT_MEM_COPY( buf, buf + start, bytes );
cursor = bytes;
avail -= bytes;
@@ -713,14 +714,15 @@
/* XXX: Use encoding independent value for 0x1a */
if ( buf[start] != '#' && buf[start] != 0x1a && end > start )
{
- error = (*cb)( buf+start, end-start, lineno, (void*)&cb, client_data );
+ error = (*cb)( buf + start, end - start, lineno,
+ (void*)&cb, client_data );
if ( error )
break;
}
lineno += 1;
buf[end] = (char)hold;
- start = end+1;
+ start = end + 1;
if ( hold == '\n' )
to_skip = '\r';
diff --git a/src/gzip/ftgzip.c b/src/gzip/ftgzip.c
index c2ae1a0..67e7bb8 100644
--- a/src/gzip/ftgzip.c
+++ b/src/gzip/ftgzip.c
@@ -8,7 +8,7 @@
/* parse compressed PCF fonts, as found with many X11 server */
/* distributions. */
/* */
-/* Copyright 2002, 2003, 2004 by */
+/* Copyright 2002, 2003, 2004, 2005 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -561,9 +561,11 @@
FT_Memory memory = source->memory;
FT_GZipFile zip;
- /* check the header right now, this prevents allocating un-necessary
- * objects when we don't need them
- */
+
+ /*
+ * check the header right now; this prevents allocating un-necessary
+ * objects when we don't need them
+ */
error = ft_gzip_check_header( source );
if ( error )
goto Exit;
diff --git a/src/lzw/ftlzw.c b/src/lzw/ftlzw.c
index bf52b77..5d23cd2 100644
--- a/src/lzw/ftlzw.c
+++ b/src/lzw/ftlzw.c
@@ -8,7 +8,7 @@
/* be used to parse compressed PCF fonts, as found with many X11 server */
/* distributions. */
/* */
-/* Copyright 2004 by */
+/* Copyright 2004, 2005 by */
/* Albert Chin-A-Young. */
/* */
/* Based on code in src/gzip/ftgzip.c, Copyright 2004 by */
@@ -414,13 +414,14 @@
FT_Memory memory = source->memory;
FT_LZWFile zip;
- /* check the header right now, this will prevent us from
- * allocating a huge LZWFile object (400 Kb of heap memory !!)
- * when not necessary.
- *
- * Did I mention that you should never use .Z compressed font
- * file ?
- */
+
+ /*
+ * Check the header right now; this prevents allocation a huge
+ * LZWFile object (400 KByte of heap memory) if not necessary.
+ *
+ * Did I mention that you should never use .Z compressed font
+ * file?
+ */
error = ft_lzw_check_header( source );
if ( error )
goto Exit;
diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c
index 6596bbf..701f94d 100644
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -2,7 +2,7 @@
FreeType font driver for pcf fonts
- Copyright 2000, 2001, 2002, 2003, 2004 by
+ Copyright 2000, 2001, 2002, 2003, 2004, 2005 by
Francesco Zappa Nardelli
Permission is hereby granted, free of charge, to any person obtaining a copy
diff --git a/src/pcf/pcfutil.c b/src/pcf/pcfutil.c
index 547b786..67e6579 100644
--- a/src/pcf/pcfutil.c
+++ b/src/pcf/pcfutil.c
@@ -44,9 +44,10 @@ in this Software without prior written authorization from The Open Group.
{
unsigned int val = *buf;
- val = ((val >> 1) & 0x55) | ((val << 1) & 0xAA);
- val = ((val >> 2) & 0x33) | ((val << 2) & 0xCC);
- val = ((val >> 4) & 0x0F) | ((val << 4) & 0xF0);
+
+ val = ( ( val >> 1 ) & 0x55 ) | ( ( val << 1 ) & 0xAA );
+ val = ( ( val >> 2 ) & 0x33 ) | ( ( val << 2 ) & 0xCC );
+ val = ( ( val >> 4 ) & 0x0F ) | ( ( val << 4 ) & 0xF0 );
*buf = (unsigned char)val;
}
diff --git a/src/type1/t1parse.c b/src/type1/t1parse.c
index 0d9072a..222df9b 100644
--- a/src/type1/t1parse.c
+++ b/src/type1/t1parse.c
@@ -102,6 +102,7 @@
FT_UShort tag;
FT_Long size;
+
if ( FT_STREAM_SEEK( 0 ) )
goto Exit;
@@ -149,7 +150,7 @@
parser->in_memory = 0;
parser->single_block = 0;
- /* check the header format */
+ /* check the header format */
error = check_type1_format( stream, "%!PS-AdobeFont-1", 16 );
if ( error )
{
@@ -216,8 +217,8 @@
}
else
{
- /* read segment in memory - yeah that sucks, but so does the format */
- if ( FT_ALLOC( parser->base_dict, size ) ||
+ /* read segment in memory - this is clumsy, but so does the format */
+ if ( FT_ALLOC( parser->base_dict, size ) ||
FT_STREAM_READ( parser->base_dict, size ) )
goto Exit;
parser->base_len = size;