boost::freetype - extension for boost::gil

I've written a few freetype wrappers over the years. I've since converted it to use boost::gil and will be submiting it to GIL graphics library developers as an extension. The source code is now available for the asking. Yes, it supports "cleartype" and "kerning" so it will produce fonts are equivalent to Microsoft's and Apples. I've also added extras such as "word-wrapping" and "clipping". Heres a complete working example of its usage. It shows all the steps necessary, including initializing the "freetype" font engine, creating the boost::gil image and saving it as a "png" file. //Step 1. Initialize the freetype library FT_Library library; FT_Face face; FT_Init_FreeType(&library); FT_New_Face(library,"c:/fonts/mini/ARGOW___.TTF",0,&face); FT_Set_Pixel_Sizes(face,0,12); //Step 2. Create a gil image gil::rgba8_image_t img(200,30); gil::fill_pixels(gil::view(img),gil::rgba8_pixel_t(255,210,200,255)); //Step 3. Initialize Variables std::string str = "A1234567890"; boost::freetype::glyph glyphs; gil::rgba8_pixel_t black(0,0,0,255); typdef freetype::make_glyphs<gil::rgba8_pixel_t> make_glyphs_t; boost::gil::subimage_view view(view,0,0,width,height); //Step 4. Transform the string into a freetype::glyphs vector std::transform(str.begin(), str.end(), std::back_inserter(glyphs), make_glyphs_t(face,black)); //Step 5: Create kerning vector std::vector<int> kernings; std::transform(glyphs.begin(),glyphs.end(), std::back_inserter(kernings), make_kerning()); //Step 6. Draw the freetype::glyphs vector onto the gil image std::for_each(glyphs.begin(), units.end(), kernings.begin(), boost::freetype::draw_glyphs<>(view)); //Step 7. output the image png_write_view("c:/out/example_1.png", gil::view(img));

Hi Tom, This will be very useful ! Where can I download it ? Is there a GIL-specific mailing list ? I imagine more people are using GIL now and are sharing info. 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# Regards, jose On 4/13/07, Tom Brinkman <reportbase@gmail.com> wrote:
I've written a few freetype wrappers over the years. I've since converted it to use boost::gil and will be submiting it to GIL graphics library developers as an extension. The source code is now available for the asking.
Yes, it supports "cleartype" and "kerning" so it will produce fonts are equivalent to Microsoft's and Apples. I've also added extras such as "word-wrapping" and "clipping".
Heres a complete working example of its usage. It shows all the steps necessary, including initializing the "freetype" font engine, creating the boost::gil image and saving it as a "png" file.
//Step 1. Initialize the freetype library FT_Library library; FT_Face face; FT_Init_FreeType(&library); FT_New_Face(library,"c:/fonts/mini/ARGOW___.TTF",0,&face); FT_Set_Pixel_Sizes(face,0,12);
//Step 2. Create a gil image gil::rgba8_image_t img(200,30); gil::fill_pixels(gil::view(img),gil::rgba8_pixel_t(255,210,200,255));
//Step 3. Initialize Variables std::string str = "A1234567890"; boost::freetype::glyph glyphs; gil::rgba8_pixel_t black(0,0,0,255); typdef freetype::make_glyphs<gil::rgba8_pixel_t> make_glyphs_t; boost::gil::subimage_view view(view,0,0,width,height);
//Step 4. Transform the string into a freetype::glyphs vector std::transform(str.begin(), str.end(), std::back_inserter(glyphs), make_glyphs_t(face,black));
//Step 5: Create kerning vector std::vector<int> kernings; std::transform(glyphs.begin(),glyphs.end(), std::back_inserter(kernings), make_kerning());
//Step 6. Draw the freetype::glyphs vector onto the gil image std::for_each(glyphs.begin(), units.end(), kernings.begin(), boost::freetype::draw_glyphs<>(view));
//Step 7. output the image png_write_view("c:/out/example_1.png", gil::view(img)); _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

2007/4/13, Tom Brinkman <reportbase@gmail.com>:
Yes, it supports "cleartype" and "kerning" so it will produce fonts are equivalent to Microsoft's and Apples.
Is this possible without patent violations? see: http://www.linux-watch.com/news/NS6944795565.html /$

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. In case of patent concerns, it would be nice to be able to compile with no Cleartype support at all. Jeremy Pack On 4/13/07, Henrik Sundberg <storangen@gmail.com> wrote:
2007/4/13, Tom Brinkman <reportbase@gmail.com>:
Yes, it supports "cleartype" and "kerning" so it will produce fonts are equivalent to Microsoft's and Apples.
Is this possible without patent violations? see: http://www.linux-watch.com/news/NS6944795565.html
/$ _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 4/13/07, Tom Brinkman <reportbase@gmail.com> wrote:
I've written a few freetype wrappers over the years. I've since converted it to use boost::gil and will be submiting it to GIL graphics library developers as an extension.
My 2p: Rendering text is quite a hard problem. Correct me if I'm wrong, but I think the approach you sketch assumes that there is a one-to-one mapping of characters to glyphs. This is fairly restrictive for English (e.g. no ligatures are possible); it is remarkably ungeneralisable to other languages. Most languages, even if written in the Latin script, require more sophisticated processing. I imagine it may be a better approach to pass a string of (Unicode?) characters to a function that renders them all at once. Cheers, Rogier
participants (5)
-
Henrik Sundberg
-
Jeremy Pack
-
Jose
-
Rogier van Dalen
-
Tom Brinkman