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
GIL
>> now and are sharing info.

http://opensource.adobe.com/gil/

>> Will the upcoming SOC project on Visualization of STL containers be able
to
>> use your wrapper to add labels to graphs ?
>>http://code.google.com/soc/boost/about.html#

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
it.
If "cleartype" is disabled than "freetype" just renders the glyph as a
normal
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
to
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
available
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
since
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.

Example:

//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(),
    std::back_inserter(glyphs),
    boost::freetype::make_glyph<gil::rgba8_pixel_t>(face,black));

//Step 2: Create metrics vector
std::vector<FT_Glyph_Metrics> metrics;
std::transform(glyphs.begin(),glyphs.end(),
    std::back_inserter(metrics), boost::freetype::make_metric());

//Step 3: Create kerning vector
std::vector<int> kerning;
std::transform(glyphs.begin(),glyphs.end(),
    std::back_inserter(kerning), boost::freetype::make_kerning());

//Step 4: Find last fitted glyph
std::vector<FT_Glyph_Metrics>::iterator it =
    std::find_if(metrics.begin(),metrics.end(),kerning.begin(),
        boost::freetype::find_last_fitted_glyph(view.width()));

//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,
kerning.begin(),
    boost::freetype::make_width());
int height = std::for_each(metrics.begin(), metrics.end()-distance,
    boost::freetype::make_height());
int gheight = std::for_each(metrics.begin(),metrics.end(),
    boost::freetype::make_glyph_height());

//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(),
    boost::freetype::draw_glyphs<>(boost::gil::subimage_view(view,x,y,
view.width(),height-gheight)));

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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk