Page 1 of 1

MagickSetFont silently failing?

Posted: 2010-10-09T23:00:08-07:00
by rarrum
I've got IM working for rendering some text using the C api. However setting the font appears to be failing even though it returns true.

Code: Select all

            std::string sample="abcdefghijklmnopqrstuvwxyz";

            //pick the appropriate font
            std::string fontName;
#ifdef _WIN32
            if (Type==VARIABLE_SERIF)
                fontName="Times New Roman";
            else if (Type==VARIABLE_SANSERIF)
                fontName="Arial";
            else if (Type==FIXED_SERIF)
                fontName="Courier New";
#else
            if (Type==VARIABLE_SERIF)
                fontName="Serif";
            else if (Type==VARIABLE_SANSERIF)
                fontName="Sans Serif";
            else if (Type==FIXED_SERIF)
                fontName="Monospace";
#endif
            else
                MPMA::ErrorReport()<<"Unhandled font type in FontCacheEntry::Build: "<<Type<<"\n";

            //render the string
            MagickCore::MagickWand *wand=MagickCore::NewMagickWand();
            if (!MagickCore::MagickSetFont(wand, fontName.c_str()))
                MPMA::ErrorReport()<<"In FontCacheEntry::Build, MagickSetFont failed for "<<fontName<<"\n";
            MagickCore::MagickSetSize(wand, 100, 0);
            MagickCore::MagickSetPointsize(wand, Size);
            MagickCore::MagickSetOption(wand, "fill", "black");
            MagickCore::MagickSetOption(wand, "background", "transparent");
            MagickCore::MagickSetGravity(wand, MagickCore::NorthGravity);
            MagickCore::MagickReadImage(wand, (std::string("caption:")+sample).c_str());
In this case, MagickCore::MagickSetFont returns true as if it succeeded, but has no effect at all. Everything else (SetPointSize, etc) is working fine.

This is happening on both Windows XP (ImageMagick 6.6.0) and Kubuntu Linux (ImageMagick 6.5.7).

Re: MagickSetFont silently failing?

Posted: 2010-10-10T06:00:48-07:00
by magick
MagickSetFont() assigns the font as a string to an internal structure and returns MagickTrue. MagickFalse is returned only if the font is null or empty.

Re: MagickSetFont silently failing?

Posted: 2010-10-10T12:52:47-07:00
by rarrum
I see. The documentation at http://www.imagemagick.org/api/magick-p ... ickSetFont is misleading then: "MagickSetFont() sets the font associated with the MagickWand.". It's worded the same way as the others which actually have an effect: "MagickSetPointsize() sets the font pointsize associated with the MagickWand.".

What's the correct method to use to set the font then?

Re: MagickSetFont silently failing?

Posted: 2010-10-12T21:00:45-07:00
by rarrum
From looking through RenderType in annotate.c, it looks like it calls GetTypeInfo on draw_info->font (which fails when font is a name like "Times New Roman") and GetTypeInfoByFamily on draw_info->family. I see in there that it tries to load (using GetTypeInfoByFamily) strings "arial" and "helvetica"... it looks like there just needs to be an accessor to set draw_info->family... does that sound right?

Re: MagickSetFont silently failing?

Posted: 2017-06-29T04:38:48-07:00
by him21sri
Is this fixed in IM 6.8.9-10 because I also can see there is no effect of MagickSetFont in my case. I am doing MagickReadImage(wand, "pango:some text") before this I am setting some font, which is not taking any effect, even if I set some random string in the place of font name then also nothing happens, I mean it returns true. One strange thing I noticed is if you don't set the font then text shrinks to smaller font size automatically and when you set the font it comes back to your set point size. How can we set font in this case. Please help