16 #include <agg_conv_curve.h> 17 #include <agg_pixfmt_rgba.h> 18 #include <agg_rasterizer_scanline_aa.h> 19 #include <agg_renderer_base.h> 20 #include <agg_renderer_scanline.h> 21 #include <agg_scanline_p.h> 22 #include <agg_font_freetype.h> 31 drawText (
const char* str,
47 for (; *str != 0; ++str)
61 fontCache.add_kerning(&x, &y);
64 fontCache.init_embedded_adaptors(glyph, x, y);
65 switch (glyph->data_type)
67 case agg::glyph_data_mono:
69 agg::render_scanlines_bin_solid(fontCache.mono_adaptor(), fontCache.mono_scanline(), rBase, color);
72 case agg::glyph_data_gray8:
74 agg::render_scanlines_aa_solid(fontCache.gray8_adaptor(), fontCache.gray8_scanline(), rBase, color);
77 case agg::glyph_data_outline:
81 agg::render_scanlines_aa_solid(ras, scanline, rBase, color);
89 x += glyph->advance_x;
90 y += glyph->advance_y;
96 main (
int argc,
const char* argv[])
100 const int imageWidth = 550;
101 const int imageHeight = 300;
103 const int pixelSize = PixelFormat::pix_width;
110 unsigned char *imageBuffer =
new unsigned char[imageWidth * imageHeight * pixelSize];
113 renderBuffer.attach (imageBuffer, imageWidth, imageHeight, imageWidth * pixelSize);
114 pixFmt.attach(renderBuffer);
115 rBase.attach(pixFmt);
117 const agg::rgba8 transparentwhiteColor (0xff, 0xff, 0xff, 0);
118 const agg::rgba8 blueColor (0, 0, 0xff, 0xff);
121 rBase.clear(transparentwhiteColor);
126 ras.auto_close(
false);
131 char text[] =
"Hello World!";
134 char fontPath[] =
"../fonts/DejaVuSerif.ttf";
135 double fontSize = 80;
136 bool fontHint =
true;
137 bool fontKerning =
true;
141 if (!fontEngine.load_font(fontPath, 0, agg::glyph_ren_agg_mono))
147 fontEngine.hinting(fontHint);
150 fontEngine.flip_y(
true);
152 fontEngine.height(fontSize);
164 if (!fontEngine.load_font(fontPath, 0, agg::glyph_ren_agg_gray8))
170 fontEngine.hinting(fontHint);
173 fontEngine.flip_y(
true);
175 fontEngine.height(fontSize);
187 if (!fontEngine.load_font(fontPath, 0, agg::glyph_ren_outline))
193 fontEngine.hinting(fontHint);
196 fontEngine.flip_y(
true);
198 fontEngine.height(fontSize);
209 char fileName[1000] = { 0 };
212 sprintf (fileName,
"%s/", argv[1]);
214 strcat(fileName,
"tutorial_font_1.png");
215 writePng<RendererBaseType> (fileName, rBase);
221 printf (
"%s\n", ex.getMessage());
226 printf (
"Unknown exception detected.\n");