misc/libfreetype/src/base/ftmac.c
author koda
Thu, 25 Jul 2013 23:16:06 +0200
changeset 9371 f3840de881bd
parent 5172 88f2e05288ba
permissions -rw-r--r--
strip out our copy of libtremor SDL2_mixer comes with a more updated, better integrated version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftmac.c                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    Mac FOND support.  Written by just@letterror.com.                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*  Heavily modified by mpsuzuki, George Williams, and Sean McBride.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  This file is for Mac OS X only; see builds/mac/ftoldmac.c for          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  classic platforms built by MPW.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*            2009 by                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
    Notes
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
    Mac suitcase files can (and often do!) contain multiple fonts.  To
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
    support this I use the face_index argument of FT_(Open|New)_Face()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
    functions, and pretend the suitcase file is a collection.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
    Warning: fbit and NFNT bitmap resources are not supported yet.  In old
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
    sfnt fonts, bitmap glyph data for each size is stored in each `NFNT'
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
    resources instead of the `bdat' table in the sfnt resource.  Therefore,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
    face->num_fixed_sizes is set to 0, because bitmap data in `NFNT'
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
    resource is unavailable at present.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    The Mac FOND support works roughly like this:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
    - Check whether the offered stream points to a Mac suitcase file.  This
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
      is done by checking the file type: it has to be 'FFIL' or 'tfil'.  The
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
      stream that gets passed to our init_face() routine is a stdio stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
      which isn't usable for us, since the FOND resources live in the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
      resource fork.  So we just grab the stream->pathname field.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
    - Read the FOND resource into memory, then check whether there is a
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
      TrueType font and/or(!) a Type 1 font available.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    - If there is a Type 1 font available (as a separate `LWFN' file), read
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
      its data into memory, massage it slightly so it becomes PFB data, wrap
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
      it into a memory stream, load the Type 1 driver and delegate the rest
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
      of the work to it by calling FT_Open_Face().  (XXX TODO: after this
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
      has been done, the kerning data from the FOND resource should be
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
      appended to the face: On the Mac there are usually no AFM files
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
      available.  However, this is tricky since we need to map Mac char
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
      codes to ps glyph names to glyph ID's...)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    - If there is a TrueType font (an `sfnt' resource), read it into memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
      wrap it into a memory stream, load the TrueType driver and delegate
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
      the rest of the work to it, by calling FT_Open_Face().
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    - Some suitcase fonts (notably Onyx) might point the `LWFN' file to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
      itself, even though it doesn't contains `POST' resources.  To handle
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
      this special case without opening the file an extra time, we just
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
      ignore errors from the `LWFN' and fallback to the `sfnt' if both are
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
      available.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
#include FT_FREETYPE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
#include "ftbase.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  /* This is for Mac OS X.  Without redefinition, OS_INLINE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  /* expands to `static inline' which doesn't survive the   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  /* -ansi compilation flag of GCC.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
#if !HAVE_ANSI_OS_INLINE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
#undef  OS_INLINE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
#define OS_INLINE  static __inline__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  /* `configure' checks the availability of `ResourceIndex' strictly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  /* and sets HAVE_TYPE_RESOURCE_INDEX 1 or 0 always.  If it is      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  /* not set (e.g., a build without `configure'), the availability   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  /* is guessed from the SDK version.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
#ifndef HAVE_TYPE_RESOURCE_INDEX
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
#if !defined( MAC_OS_X_VERSION_10_5 ) || \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    ( MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
#define HAVE_TYPE_RESOURCE_INDEX 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
#define HAVE_TYPE_RESOURCE_INDEX 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
#endif /* !HAVE_TYPE_RESOURCE_INDEX */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
#if ( HAVE_TYPE_RESOURCE_INDEX == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  typedef short  ResourceIndex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
#include <CoreServices/CoreServices.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
#include <ApplicationServices/ApplicationServices.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
#include <sys/syslimits.h> /* PATH_MAX */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
  /* Don't want warnings about our own use of deprecated functions. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
#define FT_DEPRECATED_ATTRIBUTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
#include FT_MAC_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
#ifndef kATSOptionFlagsUnRestrictedScope /* since Mac OS X 10.1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
#define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
  /* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
     TrueType in case *both* are available (this is not common,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
     but it *is* possible). */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
#ifndef PREFER_LWFN
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
#define PREFER_LWFN  1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
  /* This function is deprecated because FSSpec is deprecated in Mac OS X  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  FT_GetFile_From_Mac_Name( const char*  fontName,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
                            FSSpec*      pathSpec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
                            FT_Long*     face_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    FT_UNUSED( fontName );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    FT_UNUSED( pathSpec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    FT_UNUSED( face_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
  /* Private function.                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
  /* The FSSpec type has been discouraged for a long time,     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
  /* unfortunately an FSRef replacement API for                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
  /* ATSFontGetFileSpecification() is only available in        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
  /* Mac OS X 10.5 and later.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
  static OSStatus
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  FT_ATSFontGetFileReference( ATSFontRef  ats_font_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
                              FSRef*      ats_font_ref )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
#if defined( MAC_OS_X_VERSION_10_5 ) && \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    OSStatus  err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    err = ATSFontGetFileReference( ats_font_id, ats_font_ref );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    return err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
#elif __LP64__ /* No 64bit Carbon API on legacy platforms */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    FT_UNUSED( ats_font_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    FT_UNUSED( ats_font_ref );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    return fnfErr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
#else /* 32bit Carbon API on legacy platforms */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    OSStatus  err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    FSSpec    spec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
    err = ATSFontGetFileSpecification( ats_font_id, &spec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
    if ( noErr == err )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      err = FSpMakeFSRef( &spec, ats_font_ref );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
    return err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
  FT_GetFileRef_From_Mac_ATS_Name( const char*  fontName,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
                                   FSRef*       ats_font_ref,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
                                   FT_Long*     face_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    CFStringRef  cf_fontName;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    ATSFontRef   ats_font_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
    *face_index = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
    cf_fontName = CFStringCreateWithCString( NULL, fontName,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
                                             kCFStringEncodingMacRoman );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    ats_font_id = ATSFontFindFromName( cf_fontName,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
                                       kATSOptionFlagsUnRestrictedScope );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    CFRelease( cf_fontName );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
      return FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
    if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      return FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    /* face_index calculation by searching preceding fontIDs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    /* with same FSRef                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      ATSFontRef  id2 = ats_font_id - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      FSRef       ref2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      while ( id2 > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
        if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
        if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
        id2 --;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
      *face_index = ats_font_id - ( id2 + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
  FT_GetFilePath_From_Mac_ATS_Name( const char*  fontName,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
                                    UInt8*       path,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
                                    UInt32       maxPathSize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
                                    FT_Long*     face_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    FSRef     ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
    FT_Error  err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    if ( FT_Err_Ok != err )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      return err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
    if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
      return FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  /* This function is deprecated because FSSpec is deprecated in Mac OS X  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
  FT_GetFile_From_Mac_ATS_Name( const char*  fontName,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
                                FSSpec*      pathSpec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
                                FT_Long*     face_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
      ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    FT_UNUSED( fontName );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    FT_UNUSED( pathSpec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    FT_UNUSED( face_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    FSRef     ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
    FT_Error  err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
    err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    if ( FT_Err_Ok != err )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
      return err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
    if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
                                    pathSpec, NULL ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
      return FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
  static OSErr
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
  FT_FSPathMakeRes( const UInt8*    pathname,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
                    ResFileRefNum*  res )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    OSErr  err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
    FSRef  ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
    if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    /* at present, no support for dfont format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    err = FSOpenResourceFile( &ref, 0, NULL, fsRdPerm, res );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
    if ( noErr == err )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
      return err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    /* fallback to original resource-fork font */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    *res = FSOpenResFile( &ref, fsRdPerm );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    err  = ResError();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
    return err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
  /* Return the file type for given pathname */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
  static OSType
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
  get_file_type_from_path( const UInt8*  pathname )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    FSRef          ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    FSCatalogInfo  info;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
    if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
      return ( OSType ) 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
    if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
                                    NULL, NULL, NULL ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      return ( OSType ) 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    return ((FInfo *)(info.finderInfo))->fdType;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
  /* Given a PostScript font name, create the Macintosh LWFN file name. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
  create_lwfn_name( char*   ps_name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
                    Str255  lwfn_file_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    int       max = 5, count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
    FT_Byte*  p = lwfn_file_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    FT_Byte*  q = (FT_Byte*)ps_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    lwfn_file_name[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    while ( *q )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
      if ( ft_isupper( *q ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
        if ( count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
          max = 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
        count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
      if ( count < max && ( ft_isalnum( *q ) || *q == '_' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
        *++p = *q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
        lwfn_file_name[0]++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
        count++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
      q++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
  static short
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
  count_faces_sfnt( char*  fond_data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    /* The count is 1 greater than the value in the FOND.  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    /* Isn't that cute? :-)                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    return EndianS16_BtoN( *( (short*)( fond_data +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
                                        sizeof ( FamRec ) ) ) ) + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
  static short
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
  count_faces_scalable( char*  fond_data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    AsscEntry*  assoc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
    FamRec*     fond;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
    short       i, face, face_all;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    fond     = (FamRec*)fond_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    face_all = EndianS16_BtoN( *( (short *)( fond_data +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
                                             sizeof ( FamRec ) ) ) ) + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    assoc    = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    face     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    for ( i = 0; i < face_all; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
      if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
        face++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
    return face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
  /* Look inside the FOND data, answer whether there should be an SFNT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
     resource, and answer the name of a possible LWFN Type 1 file.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
     Thanks to Paul Miller (paulm@profoundeffects.com) for the fix
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
     to load a face OTHER than the first one in the FOND!
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
  parse_fond( char*   fond_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
              short*  have_sfnt,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
              ResID*  sfnt_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
              Str255  lwfn_file_name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
              short   face_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    AsscEntry*  assoc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
    AsscEntry*  base_assoc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    FamRec*     fond;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    *sfnt_id          = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
    *have_sfnt        = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    lwfn_file_name[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
    fond       = (FamRec*)fond_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    assoc      = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    base_assoc = assoc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
    /* the maximum faces in a FOND is 48, size of StyleTable.indexes[] */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
    if ( 47 < face_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
    /* Let's do a little range checking before we get too excited here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
    if ( face_index < count_faces_sfnt( fond_data ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
      assoc += face_index;        /* add on the face_index! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
      /* if the face at this index is not scalable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
         fall back to the first one (old behavior) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      if ( EndianS16_BtoN( assoc->fontSize ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
        *have_sfnt = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
        *sfnt_id   = EndianS16_BtoN( assoc->fontID );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
      else if ( base_assoc->fontSize == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
        *have_sfnt = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
        *sfnt_id   = EndianS16_BtoN( base_assoc->fontID );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    if ( EndianS32_BtoN( fond->ffStylOff ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
      unsigned char*  p = (unsigned char*)fond_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      StyleTable*     style;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
      unsigned short  string_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
      char            ps_name[256];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
      unsigned char*  names[64];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
      int             i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
      p += EndianS32_BtoN( fond->ffStylOff );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
      style = (StyleTable*)p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
      p += sizeof ( StyleTable );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
      string_count = EndianS16_BtoN( *(short*)(p) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
      p += sizeof ( short );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      for ( i = 0; i < string_count && i < 64; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
        names[i] = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
        p       += names[i][0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
        p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
        size_t  ps_name_len = (size_t)names[0][0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
        if ( ps_name_len != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
          ft_memcpy(ps_name, names[0] + 1, ps_name_len);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
          ps_name[ps_name_len] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
        if ( style->indexes[face_index] > 1 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
             style->indexes[face_index] <= FT_MIN( string_count, 64 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
          unsigned char*  suffixes = names[style->indexes[face_index] - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
          for ( i = 1; i <= suffixes[0]; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
            unsigned char*  s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
            size_t          j = suffixes[i] - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
            if ( j < string_count && ( s = names[j] ) != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
              size_t  s_len = (size_t)s[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
              if ( s_len != 0 && ps_name_len + s_len < sizeof ( ps_name ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
                ft_memcpy( ps_name + ps_name_len, s + 1, s_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
                ps_name_len += s_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
                ps_name[ps_name_len] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
      create_lwfn_name( ps_name, lwfn_file_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
  static  FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
  lookup_lwfn_by_fond( const UInt8*      path_fond,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
                       ConstStr255Param  base_lwfn,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
                       UInt8*            path_lwfn,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
                       size_t            path_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    FSRef   ref, par_ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    size_t  dirname_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    /* Pathname for FSRef can be in various formats: HFS, HFS+, and POSIX. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    /* We should not extract parent directory by string manipulation.      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    if ( noErr != FSPathMakeRef( path_fond, &ref, FALSE ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
    if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
                                    NULL, NULL, NULL, &par_ref ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    if ( ft_strlen( (char *)path_lwfn ) + 1 + base_lwfn[0] > path_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    /* now we have absolute dirname in path_lwfn */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
    ft_strcat( (char *)path_lwfn, "/" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
    dirname_len = ft_strlen( (char *)path_lwfn );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
    ft_strcat( (char *)path_lwfn, (char *)base_lwfn + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
    path_lwfn[dirname_len + base_lwfn[0]] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
    if ( noErr != FSPathMakeRef( path_lwfn, &ref, FALSE ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
                                    NULL, NULL, NULL, NULL ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
  static short
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
  count_faces( Handle        fond,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
               const UInt8*  pathname )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    ResID     sfnt_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    short     have_sfnt, have_lwfn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    Str255    lwfn_file_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    UInt8     buff[PATH_MAX];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    FT_Error  err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
    short     num_faces;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
    have_sfnt = have_lwfn = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
    parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
    if ( lwfn_file_name[0] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
      err = lookup_lwfn_by_fond( pathname, lwfn_file_name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
                                 buff, sizeof ( buff )  );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
      if ( FT_Err_Ok == err )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
        have_lwfn = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
    if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
      num_faces = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
      num_faces = count_faces_scalable( *fond );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
    return num_faces;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
  /* Read Type 1 data from the POST resources inside the LWFN file,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
     return a PFB buffer.  This is somewhat convoluted because the FT2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
     PFB parser wants the ASCII header as one chunk, and the LWFN
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
     chunks are often not organized that way, so we glue chunks
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
     of the same type together. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
  read_lwfn( FT_Memory      memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
             ResFileRefNum  res,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
             FT_Byte**      pfb_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
             FT_ULong*      size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
    FT_Error       error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
    ResID          res_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
    unsigned char  *buffer, *p, *size_p = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    FT_ULong       total_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
    FT_ULong       old_total_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    FT_ULong       post_size, pfb_chunk_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
    Handle         post_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    char           code, last_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
    UseResFile( res );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    /* First pass: load all POST resources, and determine the size of */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
    /* the output buffer.                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
    res_id    = 501;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
    last_code = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      post_data = Get1Resource( TTAG_POST, res_id++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
      if ( post_data == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
        break;  /* we are done */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
      code = (*post_data)[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
      if ( code != last_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
        if ( code == 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
          total_size += 2; /* just the end code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
          total_size += 6; /* code + 4 bytes chunk length */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
      total_size += GetHandleSize( post_data ) - 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
      last_code = code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
      /* detect integer overflows */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      if ( total_size < old_total_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
        error = FT_Err_Array_Too_Large;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
        goto Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
      old_total_size = total_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
    if ( FT_ALLOC( buffer, (FT_Long)total_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
      goto Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
    /* Second pass: append all POST data to the buffer, add PFB fields. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
    /* Glue all consecutive chunks of the same type together.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    p              = buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    res_id         = 501;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    last_code      = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
    pfb_chunk_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
      post_data = Get1Resource( TTAG_POST, res_id++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
      if ( post_data == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
        break;  /* we are done */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
      post_size = (FT_ULong)GetHandleSize( post_data ) - 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
      code = (*post_data)[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
      if ( code != last_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
        if ( last_code != -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
          /* we are done adding a chunk, fill in the size field */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
          if ( size_p != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
            *size_p++ = (FT_Byte)(   pfb_chunk_size         & 0xFF );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
            *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 8  ) & 0xFF );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
            *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
            *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
          pfb_chunk_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
        *p++ = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
        if ( code == 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
          *p++ = 0x03;  /* the end */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
        else if ( code == 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
          *p++ = 0x02;  /* binary segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
          *p++ = 0x01;  /* ASCII segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
        if ( code != 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
          size_p = p;   /* save for later */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
          p += 4;       /* make space for size field */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
      ft_memcpy( p, *post_data + 2, post_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
      pfb_chunk_size += post_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
      p += post_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
      last_code = code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    *pfb_data = buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
    *size = total_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
  Error:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
    CloseResFile( res );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
  /* Create a new FT_Face from a file path to an LWFN file. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
  FT_New_Face_From_LWFN( FT_Library    library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
                         const UInt8*  pathname,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
                         FT_Long       face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
                         FT_Face*      aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    FT_Byte*       pfb_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
    FT_ULong       pfb_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
    ResFileRefNum  res;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
    if ( noErr != FT_FSPathMakeRes( pathname, &res ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
    pfb_data = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    pfb_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
    error = read_lwfn( library->memory, res, &pfb_data, &pfb_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
    CloseResFile( res ); /* PFB is already loaded, useless anymore */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
    return open_face_from_buffer( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
                                  pfb_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
                                  pfb_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
                                  face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
                                  "type1",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
                                  aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
  /* Create a new FT_Face from an SFNT resource, specified by res ID. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
  FT_New_Face_From_SFNT( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
                         ResID       sfnt_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
                         FT_Long     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
                         FT_Face*    aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
    Handle     sfnt = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
    FT_Byte*   sfnt_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
    size_t     sfnt_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    FT_Error   error  = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
    FT_Memory  memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
    int        is_cff, is_sfnt_ps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
    sfnt = GetResource( TTAG_sfnt, sfnt_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
    if ( sfnt == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
      return FT_Err_Invalid_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
    sfnt_size = (FT_ULong)GetHandleSize( sfnt );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
    if ( FT_ALLOC( sfnt_data, (FT_Long)sfnt_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
      ReleaseResource( sfnt );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
    ft_memcpy( sfnt_data, *sfnt, sfnt_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
    ReleaseResource( sfnt );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
    is_cff     = sfnt_size > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
    is_sfnt_ps = sfnt_size > 4 && !ft_memcmp( sfnt_data, "typ1", 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
    if ( is_sfnt_ps )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
      FT_Stream  stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
      if ( FT_NEW( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
        goto Try_OpenType;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
      FT_Stream_OpenMemory( stream, sfnt_data, sfnt_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
      if ( !open_face_PS_from_sfnt_stream( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
                                           stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
                                           face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
                                           0, NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
                                           aface ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
        FT_Stream_Close( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
        FT_FREE( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
        FT_FREE( sfnt_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
      FT_FREE( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
  Try_OpenType:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
    error = open_face_from_buffer( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
                                   sfnt_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
                                   sfnt_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
                                   face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
                                   is_cff ? "cff" : "truetype",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
                                   aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
  /* Create a new FT_Face from a file path to a suitcase file. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
  FT_New_Face_From_Suitcase( FT_Library    library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
                             const UInt8*  pathname,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
                             FT_Long       face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
                             FT_Face*      aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
    FT_Error       error = FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
    ResFileRefNum  res_ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
    ResourceIndex  res_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
    Handle         fond;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    short          num_faces_in_res, num_faces_in_fond;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
    if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
    UseResFile( res_ref );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
    if ( ResError() )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
    num_faces_in_res = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
    for ( res_index = 1; ; ++res_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
      fond = Get1IndResource( TTAG_FOND, res_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
      if ( ResError() )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
      num_faces_in_fond  = count_faces( fond, pathname );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
      num_faces_in_res  += num_faces_in_fond;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
      if ( 0 <= face_index && face_index < num_faces_in_fond && error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
        error = FT_New_Face_From_FOND( library, fond, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
      face_index -= num_faces_in_fond;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
    CloseResFile( res_ref );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
    if ( FT_Err_Ok == error && NULL != aface && NULL != *aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
      (*aface)->num_faces = num_faces_in_res;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
  /* documentation is in ftmac.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
  FT_New_Face_From_FOND( FT_Library  library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
                         Handle      fond,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
                         FT_Long     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
                         FT_Face*    aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
    short     have_sfnt, have_lwfn = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
    ResID     sfnt_id, fond_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
    OSType    fond_type;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
    Str255    fond_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
    Str255    lwfn_file_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
    UInt8     path_lwfn[PATH_MAX];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
    OSErr     err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
    GetResInfo( fond, &fond_id, &fond_type, fond_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
    if ( ResError() != noErr || fond_type != TTAG_FOND )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
      return FT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
    if ( lwfn_file_name[0] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
      ResFileRefNum  res;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
      res = HomeResFile( fond );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
      if ( noErr != ResError() )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
        goto found_no_lwfn_file;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
        UInt8  path_fond[PATH_MAX];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
        FSRef  ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
        err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
                               NULL, NULL, NULL, &ref, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
        if ( noErr != err )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
          goto found_no_lwfn_file;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
        err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
        if ( noErr != err )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
          goto found_no_lwfn_file;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
        error = lookup_lwfn_by_fond( path_fond, lwfn_file_name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
                                     path_lwfn, sizeof ( path_lwfn ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
        if ( FT_Err_Ok == error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
          have_lwfn = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
    if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
      error = FT_New_Face_From_LWFN( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
                                     path_lwfn,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
                                     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
                                     aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
      error = FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
  found_no_lwfn_file:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
    if ( have_sfnt && FT_Err_Ok != error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
      error = FT_New_Face_From_SFNT( library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
                                     sfnt_id,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
                                     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
                                     aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
  /* Common function to load a new FT_Face from a resource file. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
  FT_New_Face_From_Resource( FT_Library    library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
                             const UInt8*  pathname,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
                             FT_Long       face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
                             FT_Face*      aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
    OSType    file_type;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
    /* LWFN is a (very) specific file format, check for it explicitly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
    file_type = get_file_type_from_path( pathname );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
    if ( file_type == TTAG_LWFN )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
      return FT_New_Face_From_LWFN( library, pathname, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
    /* Otherwise the file type doesn't matter (there are more than  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
    /* `FFIL' and `tfil').  Just try opening it as a font suitcase; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
    /* if it works, fine.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
    error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
    if ( error == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
    /* let it fall through to normal loader (.ttf, .otf, etc.); */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
    /* we signal this by returning no error and no FT_Face      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
    *aface = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
  /*    FT_New_Face                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
  /*    This is the Mac-specific implementation of FT_New_Face.  In        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
  /*    addition to the standard FT_New_Face() functionality, it also      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
  /*    accepts pathnames to Mac suitcase files.  For further              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
  /*    documentation see the original FT_New_Face() in freetype.h.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
  FT_New_Face( FT_Library   library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
               const char*  pathname,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
               FT_Long      face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
               FT_Face*     aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
    FT_Open_Args  args;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
    /* test for valid `library' and `aface' delayed to FT_Open_Face() */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
    if ( !pathname )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
    error  = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
    *aface = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
    /* try resourcefork based font: LWFN, FFIL */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
    error = FT_New_Face_From_Resource( library, (UInt8 *)pathname,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
                                       face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
    if ( error != 0 || *aface != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
    /* let it fall through to normal loader (.ttf, .otf, etc.) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
    args.flags    = FT_OPEN_PATHNAME;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
    args.pathname = (char*)pathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
    return FT_Open_Face( library, &args, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
  /*    FT_New_Face_From_FSRef                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
  /*    FT_New_Face_From_FSRef is identical to FT_New_Face except it       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
  /*    accepts an FSRef instead of a path.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
  /* This function is deprecated because Carbon data types (FSRef)         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
  /* are not cross-platform, and thus not suitable for the freetype API.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
  FT_New_Face_From_FSRef( FT_Library    library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
                          const FSRef*  ref,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
                          FT_Long       face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
                          FT_Face*      aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
    FT_Open_Args  args;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
    OSErr   err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
    UInt8   pathname[PATH_MAX];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
    if ( !ref )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
    err = FSRefMakePath( ref, pathname, sizeof ( pathname ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
    if ( err )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
      error = FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
    error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
    if ( error != 0 || *aface != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
    /* fallback to datafork font */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
    args.flags    = FT_OPEN_PATHNAME;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
    args.pathname = (char*)pathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
    return FT_Open_Face( library, &args, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
  /*    FT_New_Face_From_FSSpec                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
  /*    FT_New_Face_From_FSSpec is identical to FT_New_Face except it      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
  /*    accepts an FSSpec instead of a path.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
  /* This function is deprecated because FSSpec is deprecated in Mac OS X  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
  FT_New_Face_From_FSSpec( FT_Library     library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
                           const FSSpec*  spec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
                           FT_Long        face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
                           FT_Face*       aface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
      ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
    FT_UNUSED( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    FT_UNUSED( spec );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
    FT_UNUSED( face_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
    FT_UNUSED( aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
    return FT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
    FSRef  ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
    if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
      return FT_New_Face_From_FSRef( library, &ref, face_index, aface );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
/* END */