Boost logo

Boost :

From: Tom Brinkman (reportbase_at_[hidden])
Date: 2007-04-13 22:02:49

>> Is there a GIL-specific mailing list ? I imagine more people are using
>> now and are sharing info.

>> Will the upcoming SOC project on Visualization of STL containers be able
>> use your wrapper to add labels to graphs ?

As far as I understand it, thats an "svg" project, so "no".

>> Will it be possible to disable Cleartype? I have an application where
>> such a wrapper would be very useful, but Cleartype would give little
>> or no benefit because of the application type.

Its a build parameter of the freetype libraray. Disable it if you dont want
If "cleartype" is disabled than "freetype" just renders the glyph as a
anti-aliased glyph.

>> Can it render text rotated by 90, 180, 270 degrees?

I've also played around with this, but
have never had a need for it. All you have to do is rotate the glyph
image buffer that is returned by freetype. You can use the freetype api's
do this or calculate it yourself. boost::gil might even have a way to
rotate the image buffer, but I've not run across it.

>> I hope that by "clipping" you mean that I can say "render this
>> ten-thousand-pixel-high glypth at (0,-9900) so only the last hundred
>> pixels are visible", and have it do so efficiently. If so, great!

Kind of. It just takes care of handeling strings that are longer than the
space and optionally adds "..." at the end; or, for numeric values,

>> It looks rather low-level, presumably close to the native FreeType
>> API. I'd prefer something a little more compact, e.g.
>> image i;
>> Font f("times",35);
>> draw_text(i,0,0,f,"Hello World");

Its been tried many times by many developers, and it never works. I've long
given up trying to write simple wrapper classes like these for "C" api's.
The best we can do is make "freetype" more "stl/boost" friendly. I've
done this by converting charactar string into to a freetype glyph vector.
Once this is done, the vast array of stl algorithms and
iterators are available to operate on it.


//Step 1: Create glyphs vector
gil::rgba8_pixel_t black(0,0,0,255);
std::string str = "abcdef";
std::vector<boost::freetype::glyph> glyphs;
std::transform(str.begin(), str.end(),

//Step 2: Create metrics vector
std::vector<FT_Glyph_Metrics> metrics;
    std::back_inserter(metrics), boost::freetype::make_metric());

//Step 3: Create kerning vector
std::vector<int> kerning;
    std::back_inserter(kerning), boost::freetype::make_kerning());

//Step 4: Find last fitted glyph
std::vector<FT_Glyph_Metrics>::iterator it =

//Step 5: Get the Width, Height, and Glyph Height of the string
int distance = (int)std::distance(it,metrics.end());
int width = std::for_each(metrics.begin(), metrics.end()-distance,
int height = std::for_each(metrics.begin(), metrics.end()-distance,
int gheight = std::for_each(metrics.begin(),metrics.end(),

//Step 6: calculate the x and y position
int x = 0;
int y = -gheight;
if (align & Middle)
    y = (view.height()-height-gheight)/2;
else if (align & FMiddle)
    y = (view.height()-height)/2;
else if (align & Bottom)
    y = view.height()-height;
else if (align & FBottom)
    y = view.height()-height+gheight;

//Step 7: draw the glyphs onto the boost::gil image
std::for_each(glyphs.begin(), glyphs.end()-distance, kerning.begin(),

Of course, this example could be wrapped into a helper function such as:
boost::freetype::draw_text("abcdefg", view, face, Left|Center);

Boost list run by bdawes at, gregod at, cpdaniel at, john at