Add support for the hexadicimal representation of binary data started with `StartData' in CID-keyed Type 1 fonts. * include/freetype/internal/t1types.h (CID_FaceRec): Add new members `binary_data' and `cid_stream'. * src/cid/cidload.c (cid_read_subrs): Use `face->cid_stream'. (cid_hex_to_binary): New auxiliary function. (cid_face_open): Add new argument `face_index' to return quickly if less than zero. Updated all callers. Call `cid_hex_to_binary', then open and assign memory stream to `face->cid_stream' if `parser->binary_length' is non-zero. * src/cid/cidload.h: Updated. * src/cid/cidobjs.c (cid_face_done): Free `binary_data' and `cid_stream'. * src/cid/cidparse.c (cid_parser_new): Check arguments to `StartData' and set parser->binary_length accordingly. * src/cid/cidparse.h (CID_Parser): New member `binary_length'. * src/cid/cidgload.c (cid_load_glyph): Use `face->cid_stream'. * docs/CHANGES: Updated. include/freetype/config/ftstdlib.h (ft_atoi): Replaced with... (ft_atol): This. * src/base/ftdbgmem.c: s/atol/ft_atol/. * src/type42/t42drivr.c: s/ft_atoi/ft_atol/.
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
diff --git a/ChangeLog b/ChangeLog
index 67a5808..d533e4a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2004-01-22 Werner Lemberg <wl@gnu.org>
+
+ Add support for the hexadicimal representation of binary data
+ started with `StartData' in CID-keyed Type 1 fonts.
+
+ * include/freetype/internal/t1types.h (CID_FaceRec): Add new
+ members `binary_data' and `cid_stream'.
+
+ * src/cid/cidload.c (cid_read_subrs): Use `face->cid_stream'.
+ (cid_hex_to_binary): New auxiliary function.
+ (cid_face_open): Add new argument `face_index' to return quickly
+ if less than zero. Updated all callers.
+ Call `cid_hex_to_binary', then open and assign memory stream to
+ `face->cid_stream' if `parser->binary_length' is non-zero.
+ * src/cid/cidload.h: Updated.
+
+ * src/cid/cidobjs.c (cid_face_done): Free `binary_data' and
+ `cid_stream'.
+
+ * src/cid/cidparse.c (cid_parser_new): Check arguments to
+ `StartData' and set parser->binary_length accordingly.
+ * src/cid/cidparse.h (CID_Parser): New member `binary_length'.
+
+ * src/cid/cidgload.c (cid_load_glyph): Use `face->cid_stream'.
+
+ * docs/CHANGES: Updated.
+
+2004-01-21 Werner Lemberg <wl@gnu.org>
+
+ include/freetype/config/ftstdlib.h (ft_atoi): Replaced with...
+ (ft_atol): This.
+ * src/base/ftdbgmem.c: s/atol/ft_atol/.
+ * src/type42/t42drivr.c: s/ft_atoi/ft_atol/.
+
2004-01-20 Masatake YAMATO <jet@gyve.org>
* include/freetype/ftcache.h: Delete duplicated definition of
diff --git a/docs/CHANGES b/docs/CHANGES
index eaa3d1a..00f64bd 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -38,6 +38,11 @@ LATEST CHANGES BETWEEN 2.1.8 and 2.1.7
`tttables.h') is available to get the language ID of a
TrueType/SFNT cmap.
+ - The hexadecimal format of data after the `StartData' command in
+ CID-keyed Type 1 fonts is now supported. While this can't occur
+ in file-based fonts, it can happen in document-embedded
+ resources of PostScript documents.
+
- The cache sub-system has been rewritten.
- There is now support for deinstallation of faces.
diff --git a/include/freetype/config/ftstdlib.h b/include/freetype/config/ftstdlib.h
index f160ad2..871590f 100644
--- a/include/freetype/config/ftstdlib.h
+++ b/include/freetype/config/ftstdlib.h
@@ -5,7 +5,7 @@
/* ANSI-specific library and header configuration file (specification */
/* only). */
/* */
-/* Copyright 2002, 2003 by */
+/* Copyright 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -110,7 +110,7 @@
#define ft_qsort qsort
#define ft_exit exit /* only used to exit from unhandled exceptions */
-#define ft_atoi atoi
+#define ft_atol atol
/**********************************************************************/
diff --git a/include/freetype/internal/t1types.h b/include/freetype/internal/t1types.h
index 95e3057..702bb1e 100644
--- a/include/freetype/internal/t1types.h
+++ b/include/freetype/internal/t1types.h
@@ -5,7 +5,7 @@
/* Basic Type1/Type2 type definitions and interface (specification */
/* only). */
/* */
-/* Copyright 1996-2001, 2002, 2003 by */
+/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -173,6 +173,8 @@ FT_BEGIN_HEADER
void* psaux;
CID_FaceInfoRec cid;
void* afm_data;
+ FT_Byte* binary_data; /* used if hex data has been converted */
+ FT_Stream cid_stream;
CID_Subrs subrs;
/* since FT 2.1 - interface to PostScript hinter */
diff --git a/src/base/ftdbgmem.c b/src/base/ftdbgmem.c
index dc4a1bb..152220c 100644
--- a/src/base/ftdbgmem.c
+++ b/src/base/ftdbgmem.c
@@ -4,7 +4,7 @@
/* */
/* Memory debugger (body). */
/* */
-/* Copyright 2001, 2002, 2003 by */
+/* Copyright 2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -604,7 +604,7 @@
p = getenv( "FT2_ALLOC_TOTAL_MAX" );
if ( p != NULL )
{
- FT_Long total_max = atol(p);
+ FT_Long total_max = ft_atol(p);
if ( total_max > 0 )
{
@@ -616,7 +616,7 @@
p = getenv( "FT2_ALLOC_COUNT_MAX" );
if ( p != NULL )
{
- FT_Long total_count = atol(p);
+ FT_Long total_count = ft_atol(p);
if ( total_count > 0 )
{
diff --git a/src/cid/cidgload.c b/src/cid/cidgload.c
index f038ae5..4c21097 100644
--- a/src/cid/cidgload.c
+++ b/src/cid/cidgload.c
@@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 Glyph Loader (body). */
/* */
-/* Copyright 1996-2001, 2002, 2003 by */
+/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -44,7 +44,7 @@
CID_FaceInfo cid = &face->cid;
FT_Byte* p;
FT_UInt fd_select;
- FT_Stream stream = face->root.stream;
+ FT_Stream stream = face->cid_stream;
FT_Error error = 0;
FT_Byte* charstring = 0;
FT_Memory memory = face->root.memory;
diff --git a/src/cid/cidload.c b/src/cid/cidload.c
index 9d20559..5b69ba5 100644
--- a/src/cid/cidload.c
+++ b/src/cid/cidload.c
@@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 font loader (body). */
/* */
-/* Copyright 1996-2001, 2002, 2003 by */
+/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -363,7 +363,7 @@
{
CID_FaceInfo cid = &face->cid;
FT_Memory memory = face->root.memory;
- FT_Stream stream = face->root.stream;
+ FT_Stream stream = face->cid_stream;
FT_Error error;
FT_Int n;
CID_Subrs subr;
@@ -399,7 +399,7 @@
/* read the subrmap's offsets */
if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) ||
- FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) )
+ FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) )
goto Fail;
p = (FT_Byte*)stream->cursor;
@@ -487,11 +487,111 @@
}
+ static FT_Error
+ cid_hex_to_binary( FT_Byte* data,
+ FT_Long data_len,
+ FT_ULong offset,
+ CID_Face face )
+ {
+ FT_Stream stream = face->root.stream;
+ FT_Error error;
+
+ FT_Byte buffer[256];
+ FT_Byte *p, *plimit;
+ FT_Byte *d, *dlimit;
+ FT_Byte val;
+
+ FT_Bool upper_nibble, done;
+
+
+ if ( FT_STREAM_SEEK( offset ) )
+ goto Exit;
+
+ d = data;
+ dlimit = d + data_len;
+ p = buffer;
+ plimit = p;
+
+ upper_nibble = 1;
+ done = 0;
+
+ while ( d < dlimit )
+ {
+ if ( p >= plimit )
+ {
+ FT_ULong oldpos = FT_STREAM_POS();
+ FT_ULong size = stream->size - oldpos;
+
+
+ if ( size == 0 )
+ {
+ error = CID_Err_Syntax_Error;
+ goto Exit;
+ }
+
+ if ( FT_STREAM_READ( buffer, 256 > size ? size : 256 ) )
+ goto Exit;
+ p = buffer;
+ plimit = p + FT_STREAM_POS() - oldpos;
+ }
+
+ if ( ft_isdigit( *p ) )
+ val = *p - '0';
+ else if ( *p >= 'a' && *p <= 'f' )
+ val = *p - 'a';
+ else if ( *p >= 'A' && *p <= 'F' )
+ val = *p - 'A' + 10;
+ else if ( *p == ' ' ||
+ *p == '\t' ||
+ *p == '\r' ||
+ *p == '\n' ||
+ *p == '\f' ||
+ *p == '\0' )
+ {
+ p++;
+ continue;
+ }
+ else if ( *p == '>' )
+ {
+ val = 0;
+ done = 1;
+ }
+ else
+ {
+ error = CID_Err_Syntax_Error;
+ goto Exit;
+ }
+
+ if ( upper_nibble )
+ *d = val << 4;
+ else
+ {
+ *d += val;
+ d++;
+ }
+
+ upper_nibble = 1 - upper_nibble;
+
+ if ( done )
+ break;
+
+ p++;
+ }
+
+ error = CID_Err_Ok;
+
+ Exit:
+ return error;
+ }
+
+
FT_LOCAL_DEF( FT_Error )
- cid_face_open( CID_Face face )
+ cid_face_open( CID_Face face,
+ FT_Int face_index )
{
CID_Loader loader;
CID_Parser* parser;
+ FT_Memory memory = face->root.memory;
FT_Error error;
@@ -509,7 +609,30 @@
if ( error )
goto Exit;
- face->cid.data_offset = loader.parser.data_offset;
+ if ( face_index < 0 )
+ goto Exit;
+
+ if ( parser->binary_length )
+ {
+ /* we must convert the data section from hexadecimal to binary */
+ if ( FT_ALLOC( face->binary_data, parser->binary_length ) ||
+ cid_hex_to_binary( face->binary_data, parser->binary_length,
+ parser->data_offset, face ) )
+ goto Exit;
+
+ if ( FT_NEW( face->cid_stream ) )
+ goto Exit;
+
+ FT_Stream_OpenMemory( face->cid_stream,
+ face->binary_data, parser->binary_length );
+ face->cid.data_offset = 0;
+ }
+ else
+ {
+ face->cid_stream = face->root.stream;
+ face->cid.data_offset = loader.parser.data_offset;
+ }
+
error = cid_read_subrs( face );
Exit:
diff --git a/src/cid/cidload.h b/src/cid/cidload.h
index a7f4bce..8c172ff 100644
--- a/src/cid/cidload.h
+++ b/src/cid/cidload.h
@@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 font loader (specification). */
/* */
-/* Copyright 1996-2001, 2002, 2003 by */
+/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -41,7 +41,8 @@ FT_BEGIN_HEADER
FT_Byte offsize );
FT_LOCAL( FT_Error )
- cid_face_open( CID_Face face );
+ cid_face_open( CID_Face face,
+ FT_Int face_index );
FT_END_HEADER
diff --git a/src/cid/cidobjs.c b/src/cid/cidobjs.c
index ebf45e8..6999217 100644
--- a/src/cid/cidobjs.c
+++ b/src/cid/cidobjs.c
@@ -4,7 +4,7 @@
/* */
/* CID objects manager (body). */
/* */
-/* Copyright 1996-2001, 2002, 2003 by */
+/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -234,6 +234,9 @@
face->root.family_name = 0;
face->root.style_name = 0;
+
+ FT_FREE( face->binary_data );
+ FT_FREE( face->cid_stream );
}
}
@@ -275,7 +278,6 @@
FT_UNUSED( num_params );
FT_UNUSED( params );
- FT_UNUSED( face_index );
FT_UNUSED( stream );
@@ -305,7 +307,7 @@
if ( FT_STREAM_SEEK( 0 ) )
goto Exit;
- error = cid_face_open( face );
+ error = cid_face_open( face, face_index );
if ( error )
goto Exit;
diff --git a/src/cid/cidparse.c b/src/cid/cidparse.c
index 8cf20bd..3f18749 100644
--- a/src/cid/cidparse.c
+++ b/src/cid/cidparse.c
@@ -140,22 +140,23 @@
/* in a comment or string. We also get its arguments to find out */
/* whether the data is represented in binary or hex format. */
- limit = parser->root.limit;
- cur = parser->root.cursor;
-
- arg1 = cur;
+ arg1 = parser->root.cursor;
cid_parser_skip_PS_token( parser );
cid_parser_skip_spaces ( parser );
- arg2 = cur;
+ arg2 = parser->root.cursor;
cid_parser_skip_PS_token( parser );
cid_parser_skip_spaces ( parser );
+ limit = parser->root.limit;
+ cur = parser->root.cursor;
+
while ( cur < limit )
{
if ( *cur == 'S' && ft_strncmp( (char*)cur, "StartData", 9 ) == 0 )
{
if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 )
- parser->data_type = 1;
+ parser->binary_length = ft_atol( (const char *)arg2 );
+
limit = parser->root.limit;
cur = parser->root.cursor;
goto Exit;
diff --git a/src/cid/cidparse.h b/src/cid/cidparse.h
index ecc8b7b..ca37dea 100644
--- a/src/cid/cidparse.h
+++ b/src/cid/cidparse.h
@@ -50,8 +50,8 @@ FT_BEGIN_HEADER
/* data_offset :: The start position of the binary data (i.e., the */
/* end of the data to be parsed. */
/* */
- /* data_type :: If true, the binary data is represented in */
- /* hexadecimal format. */
+ /* binary_length :: The length of the data after the `StartData' */
+ /* command if the data format is hexadecimal. */
/* */
/* cid :: A structure which holds the information about */
/* the current font. */
@@ -67,7 +67,8 @@ FT_BEGIN_HEADER
FT_Long postscript_len;
FT_ULong data_offset;
- FT_Bool data_type;
+
+ FT_Long binary_length;
CID_FaceInfo cid;
FT_Int num_dict;
diff --git a/src/type42/t42drivr.c b/src/type42/t42drivr.c
index 8af1621..f4a7bec 100644
--- a/src/type42/t42drivr.c
+++ b/src/type42/t42drivr.c
@@ -4,7 +4,7 @@
/* */
/* High-level Type 42 driver interface (body). */
/* */
-/* Copyright 2002, 2003 by Roberto Alameda. */
+/* Copyright 2002, 2003, 2004 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 */
@@ -95,7 +95,7 @@
gname = face->type1.glyph_names[i];
if ( !ft_strcmp( glyph_name, gname ) )
- return ft_atoi( (const char *)face->type1.charstrings[i] );
+ return (FT_UInt)ft_atol( (const char *)face->type1.charstrings[i] );
}
return 0;