* Merge the duplicated functions in ftmac.c with ftobjs.c
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
diff --git a/ChangeLog b/ChangeLog
index 1662536..63be2c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2008-10-02 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
+
+ * src/base/ftbase.h: New file to declare the private utility
+ functions shared by the sources of base modules. Currently,
+ `ft_lookup_PS_in_sfnt' and `open_face_from_buffer' are declared
+ to share between ftobjs.c and ftmac.c.
+ * src/base/rule.mk: Add ftbase.h.
+ * src/base/ftobjs.c: Include ftbase.h.
+ (memory_stream_close): Build on any platform when old MacOS
+ font support is enabled.
+ (new_memory_stream): Ditto.
+ (open_face_from_buffer): Build on any platform when old MacOS
+ font support is enabled. The counting of the face in a font
+ file is slightly different between Carbon-dependent parser and
+ Carbon-free parser. They are merged with the platform-specific
+ conditional.
+ (ft_lookup_PS_in_sfnt): Ditto.
+ * src/base/ftmac.c: Include ftbase.h.
+ (memory_stream_close): Removed.
+ (new_memory_stream): Ditto.
+ (open_face_from_buffer): Removed. Use the implementation in
+ ftobjs.c.
+ (ft_lookup_PS_in_sfnt): Ditto.
+
2008-10-02 Werner Lemberg <wl@gnu.org>
* src/sfnt/sfobjs.c (sfnt_load_face): `psnames_error' is only needed
diff --git a/src/base/ftbase.h b/src/base/ftbase.h
new file mode 100644
index 0000000..2a124eb
--- /dev/null
+++ b/src/base/ftbase.h
@@ -0,0 +1,54 @@
+/***************************************************************************/
+/* */
+/* ftbase.h */
+/* */
+/* The FreeType private functions used in base module (specification). */
+/* */
+/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 by */
+/* David Turner, Robert Wilhelm, Werner Lemberg, and suzuki toshiya. */
+/* */
+/* 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 __FTBASE_H__
+#define __FTBASE_H__
+
+
+#include <ft2build.h>
+#include FT_INTERNAL_OBJECTS_H
+
+
+FT_BEGIN_HEADER
+
+
+ /* Check whether the sfnt image in the buffer is sfnt-wrapped PS Type1 */
+ /* or sfnt-wrapped CID-keyed font. */
+ FT_LOCAL_DEF( FT_Error )
+ ft_lookup_PS_in_sfnt( FT_Byte* sfnt,
+ FT_ULong* offset,
+ FT_ULong* length,
+ FT_Bool* is_sfnt_cid );
+
+ /* Create a new FT_Face given a buffer and a driver name. */
+ /* from ftmac.c */
+ FT_LOCAL_DEF( FT_Error )
+ open_face_from_buffer( FT_Library library,
+ FT_Byte* base,
+ FT_ULong size,
+ FT_Long face_index,
+ const char* driver_name,
+ FT_Face *aface );
+
+
+FT_END_HEADER
+
+#endif /* __TTDRIVER_H__ */
+
+
+/* END */
diff --git a/src/base/ftmac.c b/src/base/ftmac.c
index 257bf9b..4c47138 100644
--- a/src/base/ftmac.c
+++ b/src/base/ftmac.c
@@ -68,6 +68,7 @@
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_STREAM_H
+#include "ftbase.h"
/* This is for Mac OS X. Without redefinition, OS_INLINE */
/* expands to `static inline' which doesn't survive the */
@@ -694,109 +695,6 @@
}
- /* Finalizer for a memory stream; gets called by FT_Done_Face().
- It frees the memory it uses. */
- static void
- memory_stream_close( FT_Stream stream )
- {
- FT_Memory memory = stream->memory;
-
-
- FT_FREE( stream->base );
-
- stream->size = 0;
- stream->base = 0;
- stream->close = 0;
- }
-
-
- /* Create a new memory stream from a buffer and a size. */
- static FT_Error
- new_memory_stream( FT_Library library,
- FT_Byte* base,
- FT_ULong size,
- FT_Stream_CloseFunc close,
- FT_Stream* astream )
- {
- FT_Error error;
- FT_Memory memory;
- FT_Stream stream;
-
-
- if ( !library )
- return FT_Err_Invalid_Library_Handle;
-
- if ( !base )
- return FT_Err_Invalid_Argument;
-
- *astream = 0;
- memory = library->memory;
- if ( FT_NEW( stream ) )
- goto Exit;
-
- FT_Stream_OpenMemory( stream, base, size );
-
- stream->close = close;
-
- *astream = stream;
-
- Exit:
- return error;
- }
-
-
- /* Create a new FT_Face given a buffer and a driver name. */
- static FT_Error
- open_face_from_buffer( FT_Library library,
- FT_Byte* base,
- FT_ULong size,
- FT_Long face_index,
- const char* driver_name,
- FT_Face* aface )
- {
- FT_Open_Args args;
- FT_Error error;
- FT_Stream stream;
- FT_Memory memory = library->memory;
-
-
- error = new_memory_stream( library,
- base,
- size,
- memory_stream_close,
- &stream );
- if ( error )
- {
- FT_FREE( base );
- return error;
- }
-
- args.flags = FT_OPEN_STREAM;
- args.stream = stream;
- if ( driver_name )
- {
- args.flags = args.flags | FT_OPEN_DRIVER;
- args.driver = FT_Get_Module( library, driver_name );
- }
-
- /* At this point, face_index has served its purpose; */
- /* whoever calls this function has already used it to */
- /* locate the correct font data. We should not propagate */
- /* this index to FT_Open_Face() (unless it is negative). */
-
- if ( face_index > 0 )
- face_index = 0;
-
- error = FT_Open_Face( library, &args, face_index, aface );
- if ( error )
- FT_Stream_Free( stream, 0 );
- else
- (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
-
- return error;
- }
-
-
/* Create a new FT_Face from a file spec to an LWFN file. */
static FT_Error
FT_New_Face_From_LWFN( FT_Library library,
@@ -829,61 +727,6 @@
}
- /* Look up `TYP1' or `CID ' table from sfnt table directory. */
- /* `offset' and `length' must exclude the binary header in tables. */
-
- /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
- /* format too. Here, since we can't expect that the TrueType font */
- /* driver is loaded unconditially, we must parse the font by */
- /* ourselves. We are only interested in the name of the table and */
- /* the offset. */
-
- static FT_Error
- ft_lookup_PS_in_sfnt( FT_Byte* sfnt,
- FT_ULong* offset,
- FT_ULong* length,
- FT_Bool* is_sfnt_cid )
- {
- FT_Byte* p = sfnt + 4; /* skip version `typ1' */
- FT_UShort numTables = FT_NEXT_USHORT( p );
-
-
- p += 2 * 3; /* skip binary search header */
-
- for ( ; numTables > 0 ; numTables -- )
- {
- FT_ULong tag = FT_NEXT_ULONG( p );
-
-
- p += 4; /* skip checkSum */
- *offset = FT_NEXT_ULONG( p );
- *length = FT_NEXT_ULONG( p );
-
- /* see Adobe TN# 5180 for binary header in CID table */
- if ( tag == FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) )
- {
- *offset += 22;
- *length -= 22;
- *is_sfnt_cid = TRUE;
- return FT_Err_Ok;
- }
-
- /* see Apple's `The Type 1 GX Font Format' */
- if ( tag == FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) )
- {
- *offset += 24;
- *length -= 24;
- *is_sfnt_cid = FALSE;
- return FT_Err_Ok;
- }
- }
-
- *offset = 0;
- *length = 0;
- return FT_Err_Invalid_Table;
- }
-
-
/* Create a new FT_Face from an SFNT resource, specified by res ID. */
static FT_Error
FT_New_Face_From_SFNT( FT_Library library,
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 2b49b2f..2e5534d 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -36,6 +36,8 @@
#include FT_SERVICE_KERNING_H
#include FT_SERVICE_TRUETYPE_ENGINE_H
+#include "ftbase.h"
+
#define GRID_FIT_METRICS
FT_BASE_DEF( FT_Pointer )
@@ -1167,7 +1169,7 @@
}
-#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS )
+#if defined( FT_CONFIG_OPTION_MAC_FONTS )
/* The behavior here is very similar to that in base/ftmac.c, but it */
/* is designed to work on non-mac systems, so no mac specific calls. */
@@ -1251,7 +1253,7 @@
/* Create a new FT_Face given a buffer and a driver name. */
/* from ftmac.c */
- static FT_Error
+ FT_LOCAL_DEF( FT_Error )
open_face_from_buffer( FT_Library library,
FT_Byte* base,
FT_ULong size,
@@ -1284,20 +1286,90 @@
args.driver = FT_Get_Module( library, driver_name );
}
+#if defined( FT_MACINTOSH )
+ /* At this point, face_index has served its purpose; */
+ /* whoever calls this function has already used it to */
+ /* locate the correct font data. We should not propagate */
+ /* this index to FT_Open_Face() (unless it is negative). */
+
+ if ( face_index > 0 )
+ face_index = 0;
+#endif
+
error = FT_Open_Face( library, &args, face_index, aface );
- if ( error )
+ if ( error == FT_Err_Ok )
+ (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
+ else
+#if defined( FT_MACINTOSH )
+ FT_Stream_Free( stream, 0 );
+#else
{
FT_Stream_Close( stream );
FT_FREE( stream );
}
- else
- (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
+#endif
return error;
}
+ /* Look up `TYP1' or `CID ' table from sfnt table directory. */
+ /* `offset' and `length' must exclude the binary header in tables. */
+
+ /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
+ /* format too. Here, since we can't expect that the TrueType font */
+ /* driver is loaded unconditially, we must parse the font by */
+ /* ourselves. We are only interested in the name of the table and */
+ /* the offset. */
+
+ FT_LOCAL_DEF( FT_Error )
+ ft_lookup_PS_in_sfnt( FT_Byte* sfnt,
+ FT_ULong* offset,
+ FT_ULong* length,
+ FT_Bool* is_sfnt_cid )
+ {
+ FT_Byte* p = sfnt + 4; /* skip version `typ1' */
+ FT_UShort numTables = FT_NEXT_USHORT( p );
+
+
+ p += 2 * 3; /* skip binary search header */
+
+ for ( ; numTables > 0 ; numTables -- )
+ {
+ FT_ULong tag = FT_NEXT_ULONG( p );
+
+
+ p += 4; /* skip checkSum */
+ *offset = FT_NEXT_ULONG( p );
+ *length = FT_NEXT_ULONG( p );
+
+ /* see Adobe TN# 5180 for binary header in CID table */
+ if ( tag == FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) )
+ {
+ *offset += 22;
+ *length -= 22;
+ *is_sfnt_cid = TRUE;
+ return FT_Err_Ok;
+ }
+
+ /* see Apple's `The Type 1 GX Font Format' */
+ if ( tag == FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) )
+ {
+ *offset += 24;
+ *length -= 24;
+ *is_sfnt_cid = FALSE;
+ return FT_Err_Ok;
+ }
+ }
+
+ *offset = 0;
+ *length = 0;
+ return FT_Err_Invalid_Table;
+ }
+
+
+#if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON )
/* The resource header says we've got resource_cnt `POST' (type1) */
/* resources in this file. They all need to be coalesced into */
/* one lump which gets passed on to the type1 driver. */
@@ -1415,61 +1487,6 @@
}
- /* Look up `TYP1' or `CID ' table from sfnt table directory. */
- /* `offset' and `length' must exclude the binary header in tables. */
-
- /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
- /* format too. Here, since we can't expect that the TrueType font */
- /* driver is loaded unconditially, we must parse the font by */
- /* ourselves. We are only interested in the name of the table and */
- /* the offset. */
-
- static FT_Error
- ft_lookup_PS_in_sfnt( FT_Byte* sfnt,
- FT_ULong* offset,
- FT_ULong* length,
- FT_Bool* is_sfnt_cid )
- {
- FT_Byte* p = sfnt + 4; /* skip version `typ1' */
- FT_UShort numTables = FT_NEXT_USHORT( p );
-
-
- p += 2 * 3; /* skip binary search header */
-
- for ( ; numTables > 0 ; numTables -- )
- {
- FT_ULong tag = FT_NEXT_ULONG( p );
-
-
- p += 4; /* skip checkSum */
- *offset = FT_NEXT_ULONG( p );
- *length = FT_NEXT_ULONG( p );
-
- /* see Adobe TN# 5180 for binary header in CID table */
- if ( tag == FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) )
- {
- *offset += 22;
- *length -= 22;
- *is_sfnt_cid = TRUE;
- return FT_Err_Ok;
- }
-
- /* see Apple's `The Type 1 GX Font Format' */
- if ( tag == FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) )
- {
- *offset += 24;
- *length -= 24;
- *is_sfnt_cid = FALSE;
- return FT_Err_Ok;
- }
- }
-
- *offset = 0;
- *length = 0;
- return FT_Err_Invalid_Table;
- }
-
-
/* The resource header says we've got resource_cnt `sfnt' */
/* (TrueType/OpenType) resources in this file. Look through */
/* them for the one indicated by face_index, load it into mem, */
@@ -1749,7 +1766,7 @@
}
- /* Check for some macintosh formats. */
+ /* Check for some macintosh formats without Carbon framework. */
/* Is this a macbinary file? If so look at the resource fork. */
/* Is this a mac dfont file? */
/* Is this an old style resource fork? (in data) */
@@ -1792,6 +1809,7 @@
face_index, aface, args );
return error;
}
+#endif
#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
diff --git a/src/base/rules.mk b/src/base/rules.mk
index 5a89b45..bf81666 100644
--- a/src/base/rules.mk
+++ b/src/base/rules.mk
@@ -51,6 +51,8 @@ ifneq ($(ftmac_c),)
BASE_SRC += $(BASE_DIR)/$(ftmac_c)
endif
+BASE_H := $(BASE_DIR)/ftbase.h
+
# Base layer `extensions' sources
#
# An extension is added to the library file as a separate object. It is