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: Paul Miller
Subject: Re: [Freetype] Anyone else using FreeType on MacOS? Found a bug...
Date: Thu, 25 Oct 2001 09:47:48 -0500

I also have some code that goes from a font name (like "Times New Roman Bold Italic") to the appropriate FOND and face_index, if you are interested.

        That would be great, thanks!

I'm actually going to replace the current lookup code with the new Font Manager routines that do some of this for you (FMGetFontFamilyFromName()) and it will be interesting to compare the results ;).

That only gets you half-way there, since it ONLY works with a "family name" (ie. Times New Roman). 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:


        static inline void p2string(const Str255 str, std::string &out)
        {
                out.resize(str[0]);
                ::memcpy(&out[0], str + 1, str[0]);
        }


        std::string name = "Times New Roman Bold";

        OptionBits options = kFMUseGlobalScopeOption;
        FMFontFamilyIterator famIter;
OSStatus status = ::FMCreateFontFamilyIterator(NULL, NULL, options, &famIter);
        FMFont the_font = NULL;
        FMFontFamily family = NULL;
        int face_index = 0;
        while (status == 0 && !the_font)
        {
                status = ::FMGetNextFontFamily(&famIter, &family);
                if (status == 0)
                {
                        // get the family name
                        Str255 famNameStr;
                        ::FMGetFontFamilyName(family, famNameStr);

                        std::string famName;
                        p2string(famNameStr, famName);

                        // iterate through the styles
                        FMFontFamilyInstanceIterator instIter;
::FMCreateFontFamilyInstanceIterator(family, &instIter);
                        face_index = 0;
                        int stat2 = 0;
                        while (stat2 == 0 && !the_font)
                        {
                                FMFontStyle style;
                                FMFontSize size;
                                FMFont font;
stat2 = ::FMGetNextFontFamilyInstance(&instIter, &font, &style, &size);
                                if (stat2 == 0 && size == 0)
                                {
                                        // build up a complete face name
                                        std::string fullName = famName;
                                        if (style & bold)
fullName += " Bold";
                                        if (style & italic)
                                                fullName += " Italic";

// compare with the name we are looking for
                                        if (fullName == name)
                                        {
                                                // found it!
                                                the_font = font;
                                        }
                                        else
                                                ++face_index;
                                }
                        }
                        ::FMDisposeFontFamilyInstanceIterator(&instIter);
                }
        }
        ::FMDisposeFontFamilyIterator(&famIter);

// this is ripped out of ftmac.c (used to be FT_New_Face_From_Suitcase - which is kind of wrong)
        if (the_font)
        {
                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);
        }



--
Paul T. Miller | VP of Engineering, Profound Effects, Inc. | http://www.profoundeffects.com




reply via email to

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