freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Freetype] Anyone else using FreeType on MacOS? Found a bug...


From: Leonard Rosenthol
Subject: Re: [Freetype] Anyone else using FreeType on MacOS? Found a bug...
Date: Thu, 25 Oct 2001 11:04:20 -0400

At 9:47 AM -0500 10/25/01, Paul Miller wrote:
That only gets you half-way there, since it ONLY works with a
"family name" (ie. Times New Roman).

        Oh, didn't know that!


 If you pass it "Times New Roman Bold" it doesn't work. So you
actually have to iterate over all the families, and then all the
faces, building up a full face name from there, then compare it to
the face name you are interested in. Here is my code:

        Excellent, thanks!!


                FSSpec spec;
                ::FMGetFontContainer(the_font, &spec);

                short res_ref = ::FSpOpenResFile(&spec, fsRdPerm);
                if (ResError())
                        return false;

                short cur_res = ::CurResFile();
                ::UseResFile(res_ref);

                Handle fond = ::GetResource('FOND', family);
                if (!ResError())
                {
                        FT_Face face;

                        FT_Error error = FT_New_Face_From_FOND(library,
                                                fond,
                                                face_index,
                                                &face);

                        ::CloseResFile(res_ref);
                }
                ::UseResFile(cur_res);
        }

        That's only going to work for old-style Mac OS fonts - it
won't work for any of the new formats (.dfont, .ttf, .otf, etc.) that
are supported by Mac OS X (I don't know if that's an issue for you or
now).   As such, I've written the following code that deal with the
different types of fonts...

        Hope it helps!

Leonard
___________

/* now let's find that file on disk! */
error = FMGetFontContainer( hostFont, &hostContainerSpec );
if ( error == noErr ) {
        OSErr           err = noErr;
        short           res_ref, res_index = 1;
        Handle          fond, sfnt;
        char*           fontData = NULL;

        /* first we try to open it up as an old-style resource-based font */
        res_ref = FSpOpenResFile( &hostContainerSpec, fsRdPerm );
        err = ResError();
        if ( err != noErr ) {   /* if it fails, try it as a new
datafork-based resource font */
                FSRef   hostContainerRef;

                err = FSpMakeFSRef( &hostContainerSpec, &hostContainerRef );
                if ( err == noErr )
                        err = FSOpenResourceFile( &hostContainerRef,
0, NULL, fsRdPerm, &res_ref );
        }

        if ( err == noErr ) {
                UseResFile( res_ref );

                fond = Get1IndResource( 'FOND', res_index );
                if ( ResError() == noErr )
                {
                        // do something with the FOND!
                }

                CloseResFile( res_ref );

                return font->img != NULL ? pdf_true : pdf_false;
        } else {
                OSErr   err = noErr;
                short   data_ref;

                err = FSpOpenDF( &hostContainerSpec, fsRdPerm, &data_ref );
                if ( err == noErr ) {

                        // load the data and do something with it!
                        // err = GetEOF( data_ref, (long *)&font->filelen );
                        // err = FSRead( data_ref, (long
*)&font->filelen, font->img );

                        FSClose( data_ref );
                }
        }
}
--
----------------------------------------------------------------------------
                  You've got a SmartFriend in Pennsylvania
----------------------------------------------------------------------------
Leonard Rosenthol                       Internet:       address@hidden
Web Site: <http://www.lazerware.com/>
Coola Signature: <http://signature.coola.com/address@hidden>
PGP Fingerprint: C76E 0497 C459 182D 0C6B  AB6B CA10 B4DF 8067 5E65




reply via email to

[Prev in Thread] Current Thread [Next in Thread]