2000-07-28 03:10:35 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftmac.c */
|
|
|
|
/* */
|
2000-07-29 22:38:19 +02:00
|
|
|
/* Mac FOND support. Written by just@letterror.com. */
|
2000-07-28 03:10:35 +02:00
|
|
|
/* */
|
2003-04-23 20:10:19 +02:00
|
|
|
/* Copyright 1996-2001, 2002, 2003 by */
|
2000-07-28 03:10:35 +02:00
|
|
|
/* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Notes
|
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
Mac suitcase files can (and often do!) contain multiple fonts. To
|
2000-07-28 03:10:35 +02:00
|
|
|
support this I use the face_index argument of FT_(Open|New)_Face()
|
|
|
|
functions, and pretend the suitcase file is a collection.
|
2002-04-30 16:26:49 +02:00
|
|
|
|
|
|
|
Warning: Although the FOND driver sets face->num_faces field to the
|
2000-07-28 03:10:35 +02:00
|
|
|
number of available fonts, but the Type 1 driver sets it to 1 anyway.
|
|
|
|
So this field is currently not reliable, and I don't see a clean way
|
2002-04-30 16:26:49 +02:00
|
|
|
to resolve that. The face_index argument translates to
|
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
Get1IndResource( 'FOND', face_index + 1 );
|
2002-04-30 16:26:49 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
so clients should figure out the resource index of the FOND.
|
|
|
|
(I'll try to provide some example code for this at some point.)
|
|
|
|
|
|
|
|
The Mac FOND support works roughly like this:
|
|
|
|
|
|
|
|
- Check whether the offered stream points to a Mac suitcase file.
|
|
|
|
This is done by checking the file type: it has to be 'FFIL' or 'tfil'.
|
|
|
|
The stream that gets passed to our init_face() routine is a stdio
|
|
|
|
stream, which isn't usable for us, since the FOND resources live
|
2002-04-30 16:26:49 +02:00
|
|
|
in the resource fork. So we just grab the stream->pathname field.
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
- Read the FOND resource into memory, then check whether there is
|
2002-04-30 16:26:49 +02:00
|
|
|
a TrueType font and/or(!) a Type 1 font available.
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
- If there is a Type 1 font available (as a separate 'LWFN' file),
|
|
|
|
read its data into memory, massage it slightly so it becomes
|
|
|
|
PFB data, wrap it into a memory stream, load the Type 1 driver
|
|
|
|
and delegate the rest of the work to it by calling FT_Open_Face().
|
|
|
|
(XXX TODO: after this has been done, the kerning data from the FOND
|
2002-04-30 16:26:49 +02:00
|
|
|
resource should be appended to the face: On the Mac there are usually
|
|
|
|
no AFM files available. However, this is tricky since we need to map
|
2000-07-28 03:10:35 +02:00
|
|
|
Mac char codes to ps glyph names to glyph ID's...)
|
|
|
|
|
|
|
|
- If there is a TrueType font (an 'sfnt' resource), read it into
|
|
|
|
memory, wrap it into a memory stream, load the TrueType driver
|
|
|
|
and delegate the rest of the work to it, by calling FT_Open_Face().
|
|
|
|
*/
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include FT_INTERNAL_STREAM_H
|
2003-05-11 09:12:26 +02:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#include "../truetype/ttobjs.h"
|
|
|
|
#include "../type1/t1objs.h"
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#else
|
2001-03-20 12:14:24 +01:00
|
|
|
#include "truetype/ttobjs.h"
|
|
|
|
#include "type1/t1objs.h"
|
2000-07-28 03:10:35 +02:00
|
|
|
#include <Resources.h>
|
|
|
|
#include <Fonts.h>
|
|
|
|
#include <Errors.h>
|
2001-12-06 18:52:06 +01:00
|
|
|
#include <Files.h>
|
|
|
|
#include <TextUtils.h>
|
2003-05-11 09:12:26 +02:00
|
|
|
#endif
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2000-12-08 03:42:29 +01:00
|
|
|
#include FT_MAC_H
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over
|
|
|
|
TrueType in case *both* are available (this is not common,
|
|
|
|
but it *is* possible). */
|
|
|
|
#ifndef PREFER_LWFN
|
|
|
|
#define PREFER_LWFN 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Given a pathname, fill in a file spec. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static int
|
|
|
|
file_spec_from_path( const char* pathname,
|
|
|
|
FSSpec* spec )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
2003-06-06 14:47:59 +02:00
|
|
|
#if defined( TARGET_API_MAC_CARBON ) && !defined( __MWERKS__ )
|
2002-04-30 16:26:49 +02:00
|
|
|
|
|
|
|
OSErr e;
|
|
|
|
FSRef ref;
|
|
|
|
|
|
|
|
|
|
|
|
e = FSPathMakeRef( (UInt8 *)pathname, &ref, false /* not a directory */ );
|
|
|
|
if ( e == noErr )
|
|
|
|
e = FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, spec, NULL );
|
|
|
|
|
|
|
|
return ( e == noErr ) ? 0 : (-1);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
Str255 p_path;
|
|
|
|
FT_ULong path_len;
|
|
|
|
|
|
|
|
|
|
|
|
/* convert path to a pascal string */
|
* README.UNX: updated the Unix-specific quick-compilation guide to
warn about the GNU Make requirement at compile time..
* include/freetype/config/ftstdlib.h,
include/freetype/config/ftconfig.h,
include/freetype/config/ftheader.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h,
src/autohint/ahoptim.c,
src/base/ftdbgmem.c, src/base/ftdebug.c,
src/base/ftmac.c, src/base/ftobjs.c,
src/base/ftsystem.c,
src/cache/ftcimage.c, src/cache/ftcsbits.c,
src/cff/cffdriver.c, src/cff/cffload.c, src/cff/cffobjs.c,
src/cid/cidload.c, src/cid/cidparse.c, src/cid/cidriver.c,
src/pcf/pcfdriver.c, src/pcf/pcfread.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c,
src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.c,
src/pshinter/pshrec.c,
src/psnames/psmodule.c,
src/raster/ftraster.c,
src/sfnt/sfdriver.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/smooth/ftgrays.c,
src/type1/t1afm.c, src/type1/t1driver.c, src/type1/t1gload.c,
src/type1/t1load.c, src/type1/t1objs.c, src/type1/t1parse.c:
added the new configuration file "ftstdlib.h" used to define
aliases for all ISO C library functions used by the engine
(e.g. strlen, qsort, setjmp, etc...)
this eases the porting of FreeType 2 to exotic environments like
XFree86 modules/extensions..
also removed many #include <string.h>, #include <stdlib.h>, etc...
from the engine's sources where they're not needed..
2002-04-12 11:31:48 +02:00
|
|
|
path_len = ft_strlen( pathname );
|
2000-07-28 03:10:35 +02:00
|
|
|
if ( path_len > 255 )
|
|
|
|
return -1;
|
|
|
|
p_path[0] = (unsigned char)path_len;
|
* README.UNX: updated the Unix-specific quick-compilation guide to
warn about the GNU Make requirement at compile time..
* include/freetype/config/ftstdlib.h,
include/freetype/config/ftconfig.h,
include/freetype/config/ftheader.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h,
src/autohint/ahoptim.c,
src/base/ftdbgmem.c, src/base/ftdebug.c,
src/base/ftmac.c, src/base/ftobjs.c,
src/base/ftsystem.c,
src/cache/ftcimage.c, src/cache/ftcsbits.c,
src/cff/cffdriver.c, src/cff/cffload.c, src/cff/cffobjs.c,
src/cid/cidload.c, src/cid/cidparse.c, src/cid/cidriver.c,
src/pcf/pcfdriver.c, src/pcf/pcfread.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c,
src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.c,
src/pshinter/pshrec.c,
src/psnames/psmodule.c,
src/raster/ftraster.c,
src/sfnt/sfdriver.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/smooth/ftgrays.c,
src/type1/t1afm.c, src/type1/t1driver.c, src/type1/t1gload.c,
src/type1/t1load.c, src/type1/t1objs.c, src/type1/t1parse.c:
added the new configuration file "ftstdlib.h" used to define
aliases for all ISO C library functions used by the engine
(e.g. strlen, qsort, setjmp, etc...)
this eases the porting of FreeType 2 to exotic environments like
XFree86 modules/extensions..
also removed many #include <string.h>, #include <stdlib.h>, etc...
from the engine's sources where they're not needed..
2002-04-12 11:31:48 +02:00
|
|
|
ft_strncpy( (char*)p_path + 1, pathname, path_len );
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
if ( FSMakeFSSpec( 0, 0, p_path, spec ) != noErr )
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
2002-04-30 16:26:49 +02:00
|
|
|
|
|
|
|
#endif
|
2000-07-28 03:10:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the file type of the file specified by spec. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static OSType
|
|
|
|
get_file_type( FSSpec* spec )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
2000-07-29 22:38:19 +02:00
|
|
|
FInfo finfo;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( FSpGetFInfo( spec, &finfo ) != noErr )
|
|
|
|
return 0; /* file might not exist */
|
2000-07-29 22:38:19 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
return finfo.fdType;
|
|
|
|
}
|
|
|
|
|
2001-12-07 22:56:32 +01:00
|
|
|
|
2003-06-06 14:47:59 +02:00
|
|
|
#ifdef TARGET_API_MAC_CARBON
|
2002-04-30 16:26:49 +02:00
|
|
|
|
2001-12-07 22:56:32 +01:00
|
|
|
/* is this a Mac OS X .dfont file */
|
|
|
|
static Boolean
|
|
|
|
is_dfont( FSSpec* spec )
|
|
|
|
{
|
2002-04-30 16:26:49 +02:00
|
|
|
int nameLen = spec->name[0];
|
2001-12-07 22:56:32 +01:00
|
|
|
|
|
|
|
|
2003-05-21 09:39:42 +02:00
|
|
|
return nameLen >= 6 &&
|
|
|
|
!ft_memcmp( spec->name + nameLen - 5, ".dfont", 6 );
|
2001-12-07 22:56:32 +01:00
|
|
|
}
|
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
#endif
|
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
/* Given a PostScript font name, create the Macintosh LWFN file name. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static void
|
|
|
|
create_lwfn_name( char* ps_name,
|
|
|
|
Str255 lwfn_file_name )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
int max = 5, count = 0;
|
|
|
|
FT_Byte* p = lwfn_file_name;
|
|
|
|
FT_Byte* q = (FT_Byte*)ps_name;
|
|
|
|
|
|
|
|
|
|
|
|
lwfn_file_name[0] = 0;
|
|
|
|
|
|
|
|
while ( *q )
|
|
|
|
{
|
2003-05-21 09:39:42 +02:00
|
|
|
if ( ft_isupper( *q ) )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
if ( count )
|
|
|
|
max = 3;
|
|
|
|
count = 0;
|
|
|
|
}
|
* README.UNX: updated the Unix-specific quick-compilation guide to
warn about the GNU Make requirement at compile time..
* include/freetype/config/ftstdlib.h,
include/freetype/config/ftconfig.h,
include/freetype/config/ftheader.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h,
src/autohint/ahoptim.c,
src/base/ftdbgmem.c, src/base/ftdebug.c,
src/base/ftmac.c, src/base/ftobjs.c,
src/base/ftsystem.c,
src/cache/ftcimage.c, src/cache/ftcsbits.c,
src/cff/cffdriver.c, src/cff/cffload.c, src/cff/cffobjs.c,
src/cid/cidload.c, src/cid/cidparse.c, src/cid/cidriver.c,
src/pcf/pcfdriver.c, src/pcf/pcfread.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c,
src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.c,
src/pshinter/pshrec.c,
src/psnames/psmodule.c,
src/raster/ftraster.c,
src/sfnt/sfdriver.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/smooth/ftgrays.c,
src/type1/t1afm.c, src/type1/t1driver.c, src/type1/t1gload.c,
src/type1/t1load.c, src/type1/t1objs.c, src/type1/t1parse.c:
added the new configuration file "ftstdlib.h" used to define
aliases for all ISO C library functions used by the engine
(e.g. strlen, qsort, setjmp, etc...)
this eases the porting of FreeType 2 to exotic environments like
XFree86 modules/extensions..
also removed many #include <string.h>, #include <stdlib.h>, etc...
from the engine's sources where they're not needed..
2002-04-12 11:31:48 +02:00
|
|
|
if ( count < max && ( ft_isalnum( *q ) || *q == '_' ) )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
*++p = *q;
|
|
|
|
lwfn_file_name[0]++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Given a file reference, answer its location as a vRefNum
|
|
|
|
and a dirID. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static FT_Error
|
|
|
|
get_file_location( short ref_num,
|
|
|
|
short* v_ref_num,
|
|
|
|
long* dir_id,
|
|
|
|
unsigned char* file_name )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
FCBPBRec pb;
|
|
|
|
OSErr error;
|
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
pb.ioNamePtr = file_name;
|
|
|
|
pb.ioVRefNum = 0;
|
|
|
|
pb.ioRefNum = ref_num;
|
|
|
|
pb.ioFCBIndx = 0;
|
|
|
|
|
|
|
|
error = PBGetFCBInfoSync( &pb );
|
|
|
|
if ( error == noErr )
|
|
|
|
{
|
|
|
|
*v_ref_num = pb.ioFCBVRefNum;
|
2000-07-29 22:38:19 +02:00
|
|
|
*dir_id = pb.ioFCBParID;
|
2000-07-28 03:10:35 +02:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Make a file spec for an LWFN file from a FOND resource and
|
|
|
|
a file name. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static FT_Error
|
|
|
|
make_lwfn_spec( Handle fond,
|
|
|
|
unsigned char* file_name,
|
|
|
|
FSSpec* spec )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
short ref_num, v_ref_num;
|
|
|
|
long dir_id;
|
|
|
|
Str255 fond_file_name;
|
|
|
|
|
|
|
|
|
|
|
|
ref_num = HomeResFile( fond );
|
2000-07-29 22:38:19 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
error = ResError();
|
|
|
|
if ( !error )
|
2000-07-29 22:38:19 +02:00
|
|
|
error = get_file_location( ref_num, &v_ref_num,
|
|
|
|
&dir_id, fond_file_name );
|
2000-07-28 03:10:35 +02:00
|
|
|
if ( !error )
|
|
|
|
error = FSMakeFSSpec( v_ref_num, dir_id, file_name, spec );
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Look inside the FOND data, answer whether there should be an SFNT
|
2001-12-07 22:56:32 +01:00
|
|
|
resource, and answer the name of a possible LWFN Type 1 file.
|
|
|
|
|
|
|
|
Thanks to Paul Miller (paulm@profoundeffects.com) for the fix
|
2001-10-26 15:24:39 +02:00
|
|
|
to load a face OTHER than the first one in the FOND!
|
|
|
|
*/
|
2001-06-27 18:18:10 +02:00
|
|
|
static void
|
|
|
|
parse_fond( char* fond_data,
|
|
|
|
short* have_sfnt,
|
|
|
|
short* sfnt_id,
|
2001-10-26 15:24:39 +02:00
|
|
|
Str255 lwfn_file_name,
|
|
|
|
short face_index )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
AsscEntry* assoc;
|
2001-10-26 15:24:39 +02:00
|
|
|
AsscEntry* base_assoc;
|
2000-07-28 03:10:35 +02:00
|
|
|
FamRec* fond;
|
|
|
|
|
|
|
|
|
|
|
|
*sfnt_id = 0;
|
|
|
|
*have_sfnt = 0;
|
|
|
|
lwfn_file_name[0] = 0;
|
|
|
|
|
2001-12-05 02:22:05 +01:00
|
|
|
fond = (FamRec*)fond_data;
|
|
|
|
assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 );
|
2001-10-26 15:24:39 +02:00
|
|
|
base_assoc = assoc;
|
2001-12-05 02:22:05 +01:00
|
|
|
assoc += face_index; /* add on the face_index! */
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2001-12-05 02:22:05 +01:00
|
|
|
/* if the face at this index is not scalable,
|
|
|
|
fall back to the first one (old behavior) */
|
2000-07-28 03:10:35 +02:00
|
|
|
if ( assoc->fontSize == 0 )
|
|
|
|
{
|
|
|
|
*have_sfnt = 1;
|
2001-12-05 02:22:05 +01:00
|
|
|
*sfnt_id = assoc->fontID;
|
2000-07-28 03:10:35 +02:00
|
|
|
}
|
2001-12-05 02:22:05 +01:00
|
|
|
else if ( base_assoc->fontSize == 0 )
|
2001-10-26 15:24:39 +02:00
|
|
|
{
|
|
|
|
*have_sfnt = 1;
|
2001-12-05 02:22:05 +01:00
|
|
|
*sfnt_id = base_assoc->fontID;
|
2001-10-26 15:24:39 +02:00
|
|
|
}
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
if ( fond->ffStylOff )
|
|
|
|
{
|
|
|
|
unsigned char* p = (unsigned char*)fond_data;
|
|
|
|
StyleTable* style;
|
|
|
|
unsigned short string_count;
|
|
|
|
char ps_name[256];
|
|
|
|
unsigned char* names[64];
|
|
|
|
int i;
|
|
|
|
|
2000-07-29 22:38:19 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
p += fond->ffStylOff;
|
|
|
|
style = (StyleTable*)p;
|
2000-07-29 22:38:19 +02:00
|
|
|
p += sizeof ( StyleTable );
|
2000-07-28 03:10:35 +02:00
|
|
|
string_count = *(unsigned short*)(p);
|
2000-07-29 22:38:19 +02:00
|
|
|
p += sizeof ( short );
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
for ( i = 0 ; i < string_count && i < 64; i++ )
|
|
|
|
{
|
|
|
|
names[i] = p;
|
|
|
|
p += names[i][0];
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2002-04-30 16:26:49 +02:00
|
|
|
size_t ps_name_len = (size_t)names[0][0];
|
|
|
|
|
|
|
|
|
|
|
|
if ( ps_name_len != 0 )
|
|
|
|
{
|
2003-05-21 09:39:42 +02:00
|
|
|
ft_memcpy(ps_name, names[0] + 1, ps_name_len);
|
2002-04-30 16:26:49 +02:00
|
|
|
ps_name[ps_name_len] = 0;
|
|
|
|
}
|
|
|
|
if ( style->indexes[0] > 1 )
|
|
|
|
{
|
|
|
|
unsigned char* suffixes = names[style->indexes[0] - 1];
|
|
|
|
|
|
|
|
|
2003-04-23 20:10:19 +02:00
|
|
|
for ( i = 1; i <= suffixes[0]; i++ )
|
2002-04-30 16:26:49 +02:00
|
|
|
{
|
|
|
|
unsigned char* s;
|
|
|
|
size_t j = suffixes[i] - 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ( j < string_count && ( s = names[j] ) != NULL )
|
|
|
|
{
|
|
|
|
size_t s_len = (size_t)s[0];
|
2000-07-29 22:38:19 +02:00
|
|
|
|
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
if ( s_len != 0 && ps_name_len + s_len < sizeof ( ps_name ) )
|
|
|
|
{
|
2003-05-21 09:39:42 +02:00
|
|
|
ft_memcpy( ps_name + ps_name_len, s + 1, s_len );
|
2002-04-30 16:26:49 +02:00
|
|
|
ps_name_len += s_len;
|
|
|
|
ps_name[ps_name_len] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-28 03:10:35 +02:00
|
|
|
}
|
2002-04-30 16:26:49 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
create_lwfn_name( ps_name, lwfn_file_name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read Type 1 data from the POST resources inside the LWFN file,
|
|
|
|
return a PFB buffer. This is somewhat convoluted because the FT2
|
|
|
|
PFB parser wants the ASCII header as one chunk, and the LWFN
|
|
|
|
chunks are often not organized that way, so we'll glue chunks
|
|
|
|
of the same type together. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static FT_Error
|
|
|
|
read_lwfn( FT_Memory memory,
|
|
|
|
FSSpec* lwfn_spec,
|
|
|
|
FT_Byte** pfb_data,
|
|
|
|
FT_ULong* size )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
short res_ref, res_id;
|
2002-04-30 16:26:49 +02:00
|
|
|
unsigned char *buffer, *p, *size_p = NULL;
|
2000-07-28 03:10:35 +02:00
|
|
|
FT_ULong total_size = 0;
|
|
|
|
FT_ULong post_size, pfb_chunk_size;
|
|
|
|
Handle post_data;
|
|
|
|
char code, last_code;
|
|
|
|
|
|
|
|
|
|
|
|
res_ref = FSpOpenResFile( lwfn_spec, fsRdPerm );
|
|
|
|
if ( ResError() )
|
|
|
|
return FT_Err_Out_Of_Memory;
|
|
|
|
UseResFile( res_ref );
|
|
|
|
|
|
|
|
/* First pass: load all POST resources, and determine the size of
|
|
|
|
the output buffer. */
|
2002-04-30 16:26:49 +02:00
|
|
|
res_id = 501;
|
2000-07-28 03:10:35 +02:00
|
|
|
last_code = -1;
|
2000-07-29 22:38:19 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
post_data = Get1Resource( 'POST', res_id++ );
|
|
|
|
if ( post_data == NULL )
|
|
|
|
break; /* we're done */
|
|
|
|
|
|
|
|
code = (*post_data)[0];
|
|
|
|
|
|
|
|
if ( code != last_code )
|
|
|
|
{
|
|
|
|
if ( code == 5 )
|
|
|
|
total_size += 2; /* just the end code */
|
|
|
|
else
|
|
|
|
total_size += 6; /* code + 4 bytes chunk length */
|
|
|
|
}
|
|
|
|
|
|
|
|
total_size += GetHandleSize( post_data ) - 2;
|
|
|
|
last_code = code;
|
|
|
|
}
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_ALLOC( buffer, (FT_Long)total_size ) )
|
2000-07-28 03:10:35 +02:00
|
|
|
goto Error;
|
|
|
|
|
|
|
|
/* Second pass: append all POST data to the buffer, add PFB fields.
|
2000-07-29 22:38:19 +02:00
|
|
|
Glue all consecutive chunks of the same type together. */
|
2002-04-30 16:26:49 +02:00
|
|
|
p = buffer;
|
|
|
|
res_id = 501;
|
|
|
|
last_code = -1;
|
2000-07-28 03:10:35 +02:00
|
|
|
pfb_chunk_size = 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
post_data = Get1Resource( 'POST', res_id++ );
|
|
|
|
if ( post_data == NULL )
|
|
|
|
break; /* we're done */
|
|
|
|
|
|
|
|
post_size = (FT_ULong)GetHandleSize( post_data ) - 2;
|
|
|
|
code = (*post_data)[0];
|
|
|
|
|
|
|
|
if ( code != last_code )
|
|
|
|
{
|
|
|
|
if ( last_code != -1 )
|
|
|
|
{
|
|
|
|
/* we're done adding a chunk, fill in the size field */
|
2002-04-30 16:26:49 +02:00
|
|
|
if ( size_p != NULL )
|
|
|
|
{
|
|
|
|
*size_p++ = (FT_Byte)( pfb_chunk_size & 0xFF );
|
|
|
|
*size_p++ = (FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF );
|
|
|
|
*size_p++ = (FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF );
|
|
|
|
*size_p++ = (FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF );
|
|
|
|
}
|
2000-07-28 03:10:35 +02:00
|
|
|
pfb_chunk_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p++ = 0x80;
|
|
|
|
if ( code == 5 )
|
|
|
|
*p++ = 0x03; /* the end */
|
|
|
|
else if ( code == 2 )
|
|
|
|
*p++ = 0x02; /* binary segment */
|
|
|
|
else
|
|
|
|
*p++ = 0x01; /* ASCII segment */
|
|
|
|
|
|
|
|
if ( code != 5 )
|
|
|
|
{
|
|
|
|
size_p = p; /* save for later */
|
|
|
|
p += 4; /* make space for size field */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* README.UNX: updated the Unix-specific quick-compilation guide to
warn about the GNU Make requirement at compile time..
* include/freetype/config/ftstdlib.h,
include/freetype/config/ftconfig.h,
include/freetype/config/ftheader.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h,
src/autohint/ahoptim.c,
src/base/ftdbgmem.c, src/base/ftdebug.c,
src/base/ftmac.c, src/base/ftobjs.c,
src/base/ftsystem.c,
src/cache/ftcimage.c, src/cache/ftcsbits.c,
src/cff/cffdriver.c, src/cff/cffload.c, src/cff/cffobjs.c,
src/cid/cidload.c, src/cid/cidparse.c, src/cid/cidriver.c,
src/pcf/pcfdriver.c, src/pcf/pcfread.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c,
src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.c,
src/pshinter/pshrec.c,
src/psnames/psmodule.c,
src/raster/ftraster.c,
src/sfnt/sfdriver.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/smooth/ftgrays.c,
src/type1/t1afm.c, src/type1/t1driver.c, src/type1/t1gload.c,
src/type1/t1load.c, src/type1/t1objs.c, src/type1/t1parse.c:
added the new configuration file "ftstdlib.h" used to define
aliases for all ISO C library functions used by the engine
(e.g. strlen, qsort, setjmp, etc...)
this eases the porting of FreeType 2 to exotic environments like
XFree86 modules/extensions..
also removed many #include <string.h>, #include <stdlib.h>, etc...
from the engine's sources where they're not needed..
2002-04-12 11:31:48 +02:00
|
|
|
ft_memcpy( p, *post_data + 2, post_size );
|
2000-07-28 03:10:35 +02:00
|
|
|
pfb_chunk_size += post_size;
|
|
|
|
p += post_size;
|
|
|
|
last_code = code;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pfb_data = buffer;
|
|
|
|
*size = total_size;
|
|
|
|
|
2000-07-29 22:38:19 +02:00
|
|
|
Error:
|
2000-07-28 03:10:35 +02:00
|
|
|
CloseResFile( res_ref );
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Finalizer for a memory stream; gets called by FT_Done_Face().
|
|
|
|
It frees the memory it uses. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static void
|
|
|
|
memory_stream_close( FT_Stream stream )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory = stream->memory;
|
|
|
|
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( stream->base );
|
2000-07-29 22:38:19 +02:00
|
|
|
|
|
|
|
stream->size = 0;
|
|
|
|
stream->base = 0;
|
|
|
|
stream->close = 0;
|
2000-07-28 03:10:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new memory stream from a buffer and a size. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static FT_Error
|
2002-04-30 16:26:49 +02:00
|
|
|
new_memory_stream( FT_Library library,
|
|
|
|
FT_Byte* base,
|
|
|
|
FT_ULong size,
|
|
|
|
FT_Stream_CloseFunc close,
|
|
|
|
FT_Stream *astream )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
2002-04-30 16:26:49 +02:00
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory;
|
|
|
|
FT_Stream stream;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
if ( !library )
|
|
|
|
return FT_Err_Invalid_Library_Handle;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
if ( !base )
|
|
|
|
return FT_Err_Invalid_Argument;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
*astream = 0;
|
|
|
|
memory = library->memory;
|
|
|
|
if ( FT_NEW( stream ) )
|
|
|
|
goto Exit;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
FT_Stream_OpenMemory( stream, base, size );
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
stream->close = close;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
*astream = stream;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
2000-07-28 03:10:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new FT_Face given a buffer and a driver name. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static FT_Error
|
|
|
|
open_face_from_buffer( FT_Library library,
|
|
|
|
FT_Byte* base,
|
|
|
|
FT_ULong size,
|
|
|
|
FT_Long face_index,
|
|
|
|
char* driver_name,
|
2002-04-30 16:26:49 +02:00
|
|
|
FT_Face *aface )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( base );
|
2000-07-28 03:10:35 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
args.flags = FT_OPEN_STREAM;
|
2000-07-28 03:10:35 +02:00
|
|
|
args.stream = stream;
|
|
|
|
if ( driver_name )
|
|
|
|
{
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
args.flags = args.flags | FT_OPEN_DRIVER;
|
2000-07-28 03:10:35 +02:00
|
|
|
args.driver = FT_Get_Module( library, driver_name );
|
|
|
|
}
|
2000-07-29 22:38:19 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
error = FT_Open_Face( library, &args, face_index, aface );
|
2000-07-28 04:25:23 +02:00
|
|
|
if ( error == FT_Err_Ok )
|
2000-07-28 03:10:35 +02:00
|
|
|
(*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
|
2002-04-30 16:26:49 +02:00
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new FT_Face from a file spec to an LWFN file. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static FT_Error
|
|
|
|
FT_New_Face_From_LWFN( FT_Library library,
|
|
|
|
FSSpec* spec,
|
|
|
|
FT_Long face_index,
|
2002-04-30 16:26:49 +02:00
|
|
|
FT_Face *aface )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
2002-04-30 16:26:49 +02:00
|
|
|
FT_Byte* pfb_data;
|
|
|
|
FT_ULong pfb_size;
|
|
|
|
FT_Error error;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
error = read_lwfn( library->memory, spec, &pfb_data, &pfb_size );
|
|
|
|
if ( error )
|
|
|
|
return error;
|
|
|
|
|
|
|
|
return open_face_from_buffer( library,
|
|
|
|
pfb_data,
|
|
|
|
pfb_size,
|
|
|
|
face_index,
|
|
|
|
"type1",
|
|
|
|
aface );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new FT_Face from an SFNT resource, specified by res ID. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static FT_Error
|
|
|
|
FT_New_Face_From_SFNT( FT_Library library,
|
|
|
|
short sfnt_id,
|
|
|
|
FT_Long face_index,
|
2002-04-30 16:26:49 +02:00
|
|
|
FT_Face *aface )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
2000-07-29 22:38:19 +02:00
|
|
|
Handle sfnt = NULL;
|
|
|
|
FT_Byte* sfnt_data;
|
|
|
|
size_t sfnt_size;
|
|
|
|
FT_Error error = 0;
|
|
|
|
FT_Memory memory = library->memory;
|
2003-05-15 08:44:09 +02:00
|
|
|
int is_cff;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
sfnt = GetResource( 'sfnt', sfnt_id );
|
|
|
|
if ( ResError() )
|
|
|
|
return FT_Err_Invalid_Handle;
|
|
|
|
|
|
|
|
sfnt_size = (FT_ULong)GetHandleSize( sfnt );
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_ALLOC( sfnt_data, (FT_Long)sfnt_size ) )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
ReleaseResource( sfnt );
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
HLock( sfnt );
|
* README.UNX: updated the Unix-specific quick-compilation guide to
warn about the GNU Make requirement at compile time..
* include/freetype/config/ftstdlib.h,
include/freetype/config/ftconfig.h,
include/freetype/config/ftheader.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h,
src/autohint/ahoptim.c,
src/base/ftdbgmem.c, src/base/ftdebug.c,
src/base/ftmac.c, src/base/ftobjs.c,
src/base/ftsystem.c,
src/cache/ftcimage.c, src/cache/ftcsbits.c,
src/cff/cffdriver.c, src/cff/cffload.c, src/cff/cffobjs.c,
src/cid/cidload.c, src/cid/cidparse.c, src/cid/cidriver.c,
src/pcf/pcfdriver.c, src/pcf/pcfread.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c,
src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.c,
src/pshinter/pshrec.c,
src/psnames/psmodule.c,
src/raster/ftraster.c,
src/sfnt/sfdriver.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/smooth/ftgrays.c,
src/type1/t1afm.c, src/type1/t1driver.c, src/type1/t1gload.c,
src/type1/t1load.c, src/type1/t1objs.c, src/type1/t1parse.c:
added the new configuration file "ftstdlib.h" used to define
aliases for all ISO C library functions used by the engine
(e.g. strlen, qsort, setjmp, etc...)
this eases the porting of FreeType 2 to exotic environments like
XFree86 modules/extensions..
also removed many #include <string.h>, #include <stdlib.h>, etc...
from the engine's sources where they're not needed..
2002-04-12 11:31:48 +02:00
|
|
|
ft_memcpy( sfnt_data, *sfnt, sfnt_size );
|
2000-07-28 03:10:35 +02:00
|
|
|
HUnlock( sfnt );
|
|
|
|
ReleaseResource( sfnt );
|
|
|
|
|
2003-05-15 08:44:09 +02:00
|
|
|
is_cff = rlen > 4 && sfnt_data[0] == 'O' &&
|
|
|
|
sfnt_data[1] == 'T' &&
|
|
|
|
sfnt_data[2] == 'T' &&
|
|
|
|
sfnt_data[3] == 'O';
|
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
return open_face_from_buffer( library,
|
|
|
|
sfnt_data,
|
|
|
|
sfnt_size,
|
|
|
|
face_index,
|
2003-05-15 08:44:09 +02:00
|
|
|
is_cff ? "cff" : "truetype",
|
2000-07-28 03:10:35 +02:00
|
|
|
aface );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new FT_Face from a file spec to a suitcase file. */
|
2001-06-27 18:18:10 +02:00
|
|
|
static FT_Error
|
|
|
|
FT_New_Face_From_Suitcase( FT_Library library,
|
|
|
|
FSSpec* spec,
|
|
|
|
FT_Long face_index,
|
2002-04-30 16:26:49 +02:00
|
|
|
FT_Face *aface )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
short res_ref, res_index;
|
|
|
|
Handle fond;
|
|
|
|
|
|
|
|
|
|
|
|
res_ref = FSpOpenResFile( spec, fsRdPerm );
|
|
|
|
if ( ResError() )
|
|
|
|
return FT_Err_Cannot_Open_Resource;
|
|
|
|
UseResFile( res_ref );
|
|
|
|
|
|
|
|
/* face_index may be -1, in which case we
|
|
|
|
just need to do a sanity check */
|
2000-07-29 22:38:19 +02:00
|
|
|
if ( face_index < 0 )
|
2000-07-28 03:10:35 +02:00
|
|
|
res_index = 1;
|
|
|
|
else
|
|
|
|
{
|
2000-07-29 22:38:19 +02:00
|
|
|
res_index = (short)( face_index + 1 );
|
2000-07-28 03:10:35 +02:00
|
|
|
face_index = 0;
|
|
|
|
}
|
|
|
|
fond = Get1IndResource( 'FOND', res_index );
|
|
|
|
if ( ResError() )
|
|
|
|
{
|
|
|
|
error = FT_Err_Cannot_Open_Resource;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = FT_New_Face_From_FOND( library, fond, face_index, aface );
|
|
|
|
|
2000-07-29 22:38:19 +02:00
|
|
|
Error:
|
2000-07-28 03:10:35 +02:00
|
|
|
CloseResFile( res_ref );
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2001-12-07 22:56:32 +01:00
|
|
|
|
2003-06-06 14:47:59 +02:00
|
|
|
#ifdef TARGET_API_MAC_CARBON
|
2002-04-30 16:26:49 +02:00
|
|
|
|
2001-12-06 18:52:06 +01:00
|
|
|
/* Create a new FT_Face from a file spec to a suitcase file. */
|
|
|
|
static FT_Error
|
|
|
|
FT_New_Face_From_dfont( FT_Library library,
|
2001-12-07 22:56:32 +01:00
|
|
|
FSSpec* spec,
|
|
|
|
FT_Long face_index,
|
|
|
|
FT_Face* aface )
|
2001-12-06 18:52:06 +01:00
|
|
|
{
|
2001-12-07 22:56:32 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
short res_ref, res_index;
|
|
|
|
Handle fond;
|
|
|
|
FSRef hostContainerRef;
|
|
|
|
|
|
|
|
|
|
|
|
error = FSpMakeFSRef( spec, &hostContainerRef );
|
|
|
|
if ( error == noErr )
|
|
|
|
error = FSOpenResourceFile( &hostContainerRef,
|
|
|
|
0, NULL, fsRdPerm, &res_ref );
|
|
|
|
|
|
|
|
if ( error != noErr )
|
|
|
|
return FT_Err_Cannot_Open_Resource;
|
|
|
|
|
|
|
|
UseResFile( res_ref );
|
|
|
|
|
|
|
|
/* face_index may be -1, in which case we
|
|
|
|
just need to do a sanity check */
|
|
|
|
if ( face_index < 0 )
|
|
|
|
res_index = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res_index = (short)( face_index + 1 );
|
|
|
|
face_index = 0;
|
|
|
|
}
|
|
|
|
fond = Get1IndResource( 'FOND', res_index );
|
|
|
|
if ( ResError() )
|
|
|
|
{
|
|
|
|
error = FT_Err_Cannot_Open_Resource;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = FT_New_Face_From_FOND( library, fond, face_index, aface );
|
|
|
|
|
|
|
|
Error:
|
|
|
|
CloseResFile( res_ref );
|
|
|
|
return error;
|
2001-12-06 18:52:06 +01:00
|
|
|
}
|
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
#endif
|
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
/* documentation is in ftmac.h */
|
2000-11-07 18:21:11 +01:00
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_New_Face_From_FOND( FT_Library library,
|
|
|
|
Handle fond,
|
|
|
|
FT_Long face_index,
|
|
|
|
FT_Face *aface )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
2002-04-30 16:26:49 +02:00
|
|
|
short sfnt_id, have_sfnt, have_lwfn = 0;
|
|
|
|
Str255 lwfn_file_name;
|
|
|
|
short fond_id;
|
|
|
|
OSType fond_type;
|
|
|
|
Str255 fond_name;
|
|
|
|
FSSpec lwfn_spec;
|
2000-07-28 03:10:35 +02:00
|
|
|
|
|
|
|
|
2001-12-05 02:22:05 +01:00
|
|
|
GetResInfo( fond, &fond_id, &fond_type, fond_name );
|
2000-07-28 03:10:35 +02:00
|
|
|
if ( ResError() != noErr || fond_type != 'FOND' )
|
|
|
|
return FT_Err_Invalid_File_Format;
|
|
|
|
|
|
|
|
HLock( fond );
|
2001-10-26 15:24:39 +02:00
|
|
|
parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index );
|
2000-07-28 03:10:35 +02:00
|
|
|
HUnlock( fond );
|
|
|
|
|
|
|
|
if ( lwfn_file_name[0] )
|
|
|
|
{
|
|
|
|
if ( make_lwfn_spec( fond, lwfn_file_name, &lwfn_spec ) == FT_Err_Ok )
|
|
|
|
have_lwfn = 1; /* yeah, we got one! */
|
|
|
|
else
|
|
|
|
have_lwfn = 0; /* no LWFN file found */
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) )
|
|
|
|
return FT_New_Face_From_LWFN( library,
|
|
|
|
&lwfn_spec,
|
|
|
|
face_index,
|
|
|
|
aface );
|
|
|
|
else if ( have_sfnt )
|
|
|
|
return FT_New_Face_From_SFNT( library,
|
|
|
|
sfnt_id,
|
|
|
|
face_index,
|
|
|
|
aface );
|
|
|
|
|
|
|
|
return FT_Err_Unknown_File_Format;
|
|
|
|
}
|
|
|
|
|
2001-12-07 22:56:32 +01:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
/* documentation is in ftmac.h */
|
2001-12-07 22:56:32 +01:00
|
|
|
|
2001-12-06 18:52:06 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
2001-12-07 22:56:32 +01:00
|
|
|
FT_GetFile_From_Mac_Name( char* fontName,
|
|
|
|
FSSpec* pathSpec,
|
|
|
|
FT_Long* face_index )
|
|
|
|
{
|
|
|
|
OptionBits options = kFMUseGlobalScopeOption;
|
|
|
|
|
|
|
|
FMFontFamilyIterator famIter;
|
|
|
|
OSStatus status = FMCreateFontFamilyIterator( NULL, NULL,
|
|
|
|
options,
|
|
|
|
&famIter );
|
|
|
|
FMFont the_font = NULL;
|
|
|
|
FMFontFamily family = NULL;
|
|
|
|
|
|
|
|
|
2001-12-06 18:52:06 +01:00
|
|
|
*face_index = 0;
|
2001-12-07 22:56:32 +01:00
|
|
|
while ( status == 0 && !the_font )
|
2001-12-06 18:52:06 +01:00
|
|
|
{
|
2001-12-07 22:56:32 +01:00
|
|
|
status = FMGetNextFontFamily( &famIter, &family );
|
|
|
|
if ( status == 0 )
|
|
|
|
{
|
|
|
|
int stat2;
|
|
|
|
FMFontFamilyInstanceIterator instIter;
|
|
|
|
Str255 famNameStr;
|
|
|
|
char famName[256];
|
|
|
|
|
|
|
|
|
|
|
|
/* get the family name */
|
|
|
|
FMGetFontFamilyName( family, famNameStr );
|
|
|
|
CopyPascalStringToC( famNameStr, famName );
|
|
|
|
|
|
|
|
/* iterate through the styles */
|
|
|
|
FMCreateFontFamilyInstanceIterator( family, &instIter );
|
|
|
|
|
|
|
|
*face_index = 0;
|
|
|
|
stat2 = 0;
|
|
|
|
while ( stat2 == 0 && !the_font )
|
|
|
|
{
|
|
|
|
FMFontStyle style;
|
|
|
|
FMFontSize size;
|
|
|
|
FMFont font;
|
|
|
|
|
|
|
|
|
|
|
|
stat2 = FMGetNextFontFamilyInstance( &instIter, &font,
|
|
|
|
&style, &size );
|
|
|
|
if ( stat2 == 0 && size == 0 )
|
|
|
|
{
|
2002-04-30 16:26:49 +02:00
|
|
|
char fullName[256];
|
2001-12-07 22:56:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* build up a complete face name */
|
* README.UNX: updated the Unix-specific quick-compilation guide to
warn about the GNU Make requirement at compile time..
* include/freetype/config/ftstdlib.h,
include/freetype/config/ftconfig.h,
include/freetype/config/ftheader.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h,
src/autohint/ahoptim.c,
src/base/ftdbgmem.c, src/base/ftdebug.c,
src/base/ftmac.c, src/base/ftobjs.c,
src/base/ftsystem.c,
src/cache/ftcimage.c, src/cache/ftcsbits.c,
src/cff/cffdriver.c, src/cff/cffload.c, src/cff/cffobjs.c,
src/cid/cidload.c, src/cid/cidparse.c, src/cid/cidriver.c,
src/pcf/pcfdriver.c, src/pcf/pcfread.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c,
src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.c,
src/pshinter/pshrec.c,
src/psnames/psmodule.c,
src/raster/ftraster.c,
src/sfnt/sfdriver.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/smooth/ftgrays.c,
src/type1/t1afm.c, src/type1/t1driver.c, src/type1/t1gload.c,
src/type1/t1load.c, src/type1/t1objs.c, src/type1/t1parse.c:
added the new configuration file "ftstdlib.h" used to define
aliases for all ISO C library functions used by the engine
(e.g. strlen, qsort, setjmp, etc...)
this eases the porting of FreeType 2 to exotic environments like
XFree86 modules/extensions..
also removed many #include <string.h>, #include <stdlib.h>, etc...
from the engine's sources where they're not needed..
2002-04-12 11:31:48 +02:00
|
|
|
ft_strcpy( fullName, famName );
|
2001-12-07 22:56:32 +01:00
|
|
|
if ( style & bold )
|
|
|
|
strcat( fullName, " Bold" );
|
|
|
|
if ( style & italic )
|
|
|
|
strcat( fullName, " Italic" );
|
|
|
|
|
|
|
|
/* compare with the name we are looking for */
|
* README.UNX: updated the Unix-specific quick-compilation guide to
warn about the GNU Make requirement at compile time..
* include/freetype/config/ftstdlib.h,
include/freetype/config/ftconfig.h,
include/freetype/config/ftheader.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h,
src/autohint/ahoptim.c,
src/base/ftdbgmem.c, src/base/ftdebug.c,
src/base/ftmac.c, src/base/ftobjs.c,
src/base/ftsystem.c,
src/cache/ftcimage.c, src/cache/ftcsbits.c,
src/cff/cffdriver.c, src/cff/cffload.c, src/cff/cffobjs.c,
src/cid/cidload.c, src/cid/cidparse.c, src/cid/cidriver.c,
src/pcf/pcfdriver.c, src/pcf/pcfread.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c,
src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.c,
src/pshinter/pshrec.c,
src/psnames/psmodule.c,
src/raster/ftraster.c,
src/sfnt/sfdriver.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/smooth/ftgrays.c,
src/type1/t1afm.c, src/type1/t1driver.c, src/type1/t1gload.c,
src/type1/t1load.c, src/type1/t1objs.c, src/type1/t1parse.c:
added the new configuration file "ftstdlib.h" used to define
aliases for all ISO C library functions used by the engine
(e.g. strlen, qsort, setjmp, etc...)
this eases the porting of FreeType 2 to exotic environments like
XFree86 modules/extensions..
also removed many #include <string.h>, #include <stdlib.h>, etc...
from the engine's sources where they're not needed..
2002-04-12 11:31:48 +02:00
|
|
|
if ( ft_strcmp( fullName, fontName ) == 0 )
|
2001-12-06 18:52:06 +01:00
|
|
|
{
|
2001-12-07 22:56:32 +01:00
|
|
|
/* found it! */
|
|
|
|
the_font = font;
|
2001-12-06 18:52:06 +01:00
|
|
|
}
|
2001-12-07 22:56:32 +01:00
|
|
|
else
|
|
|
|
++(*face_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FMDisposeFontFamilyInstanceIterator( &instIter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FMDisposeFontFamilyIterator( &famIter );
|
|
|
|
|
|
|
|
if ( the_font )
|
|
|
|
{
|
|
|
|
FMGetFontContainer( the_font, pathSpec );
|
|
|
|
return FT_Err_Ok;
|
2001-12-06 18:52:06 +01:00
|
|
|
}
|
2001-12-07 22:56:32 +01:00
|
|
|
else
|
|
|
|
return FT_Err_Unknown_File_Format;
|
|
|
|
}
|
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
static long
|
|
|
|
ResourceForkSize(FSSpec* spec)
|
|
|
|
{
|
|
|
|
long len;
|
|
|
|
short refNum;
|
|
|
|
OSErr e;
|
|
|
|
|
|
|
|
|
|
|
|
e = FSpOpenRF( spec, fsRdPerm, &refNum ); /* I.M. Files 2-155 */
|
|
|
|
if ( e == noErr )
|
|
|
|
{
|
|
|
|
e = GetEOF( refNum, &len );
|
|
|
|
FSClose( refNum );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( e == noErr ) ? len : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-28 03:10:35 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* FT_New_Face */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* This is the Mac-specific implementation of FT_New_Face. In */
|
2000-07-29 22:38:19 +02:00
|
|
|
/* addition to the standard FT_New_Face() functionality, it also */
|
2000-07-28 03:10:35 +02:00
|
|
|
/* accepts pathnames to Mac suitcase files. For further */
|
2000-11-07 18:21:11 +01:00
|
|
|
/* documentation see the original FT_New_Face() in freetype.h. */
|
2000-07-28 03:10:35 +02:00
|
|
|
/* */
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_New_Face( FT_Library library,
|
|
|
|
const char* pathname,
|
|
|
|
FT_Long face_index,
|
|
|
|
FT_Face *aface )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
|
|
|
FT_Open_Args args;
|
|
|
|
FSSpec spec;
|
|
|
|
OSType file_type;
|
|
|
|
|
|
|
|
|
|
|
|
/* test for valid `library' and `aface' delayed to FT_Open_Face() */
|
|
|
|
if ( !pathname )
|
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
|
|
|
if ( file_spec_from_path( pathname, &spec ) )
|
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
/* Regardless of type, don't try to use the resource fork if it is */
|
|
|
|
/* empty. Some TTF fonts have type `FFIL', for example, but they */
|
|
|
|
/* only have data forks. */
|
|
|
|
|
|
|
|
if ( ResourceForkSize( &spec ) != 0 )
|
2000-07-28 03:10:35 +02:00
|
|
|
{
|
2002-04-30 16:26:49 +02:00
|
|
|
file_type = get_file_type( &spec );
|
|
|
|
if ( file_type == 'FFIL' || file_type == 'tfil' )
|
|
|
|
return FT_New_Face_From_Suitcase( library, &spec, face_index, aface );
|
2000-07-28 03:10:35 +02:00
|
|
|
|
2002-04-30 16:26:49 +02:00
|
|
|
if ( file_type == 'LWFN' )
|
|
|
|
return FT_New_Face_From_LWFN( library, &spec, face_index, aface );
|
2000-07-28 03:10:35 +02:00
|
|
|
}
|
2002-04-30 16:26:49 +02:00
|
|
|
|
2003-06-06 14:47:59 +02:00
|
|
|
#ifdef TARGET_API_MAC_CARBON
|
2002-04-30 16:26:49 +02:00
|
|
|
|
|
|
|
if ( is_dfont( &spec ) )
|
|
|
|
return FT_New_Face_From_dfont( library, &spec, face_index, aface );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* let it fall through to normal loader (.ttf, .otf, etc.) */
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
args.flags = FT_OPEN_PATHNAME;
|
2002-04-30 16:26:49 +02:00
|
|
|
args.pathname = (char*)pathname;
|
|
|
|
return FT_Open_Face( library, &args, face_index, aface );
|
2000-07-28 03:10:35 +02:00
|
|
|
}
|
|
|
|
|
2000-07-29 22:38:19 +02:00
|
|
|
|
|
|
|
/* END */
|