16 #include <agg_conv_curve.h> 17 #include <agg_conv_stroke.h> 18 #include <agg_image_accessors.h> 19 #include <agg_path_storage.h> 20 #include <agg_pixfmt_rgba.h> 21 #include <agg_rasterizer_scanline_aa.h> 22 #include <agg_renderer_base.h> 23 #include <agg_renderer_scanline.h> 24 #include <agg_scanline_p.h> 25 #include <agg_font_freetype.h> 26 #include <agg_span_allocator.h> 27 #include <agg_span_image_filter_rgba.h> 28 #include <agg_span_interpolator_linear.h> 45 const agg::rgba8 transparentWhiteColor (0xff, 0xff, 0xff, 0);
47 double srcWidth = src.width();
48 double srcHeight = src.height();
53 invertMatrix.invert();
55 InterpolatorType interpolator (invertMatrix);
56 ImageAccessorType ia (src.ren(), transparentWhiteColor);
57 SpanGeneratorType sg (ia, interpolator);
64 ras.filling_rule(fillRule);
66 agg::render_scanlines_aa(ras, scanline, dst, sa, sg);
70 genTextPath (
const char* str,
84 for (; *str != 0; ++str)
98 fontCache.add_kerning(&x, &y);
101 fontCache.init_embedded_adaptors(glyph, x, y);
102 switch (glyph->data_type)
104 case agg::glyph_data_outline:
106 path.concat_path(curves, 0);
110 x += glyph->advance_x;
111 y += glyph->advance_y;
117 main (
int argc,
const char* argv[])
121 const int imageWidth = 550;
122 const int imageHeight = 300;
124 const int pixelSize = PixelFormat::pix_width;
130 unsigned char *imageBuffer =
new unsigned char[imageWidth * imageHeight * pixelSize];
133 renderBuffer.attach (imageBuffer, imageWidth, imageHeight, imageWidth * pixelSize);
134 pixFmt.attach(renderBuffer);
135 rBase.attach(pixFmt);
137 const agg::rgba8 transparentwhiteColor (0xff, 0xff, 0xff, 0);
138 const agg::rgba8 blueColor (0, 0, 0xff, 0xff);
141 rBase.clear(transparentwhiteColor);
146 ras.auto_close(
false);
152 char fontPath[] =
"../fonts/DejaVuSerif.ttf";
153 double fontSize = 80;
154 bool fontHint =
true;
155 bool fontKerning =
true;
157 if (!fontEngine.load_font(fontPath, 0, agg::glyph_ren_outline))
161 char text[] =
"Hello World!";
165 fontEngine.hinting(fontHint);
168 fontEngine.flip_y(
true);
170 fontEngine.height(fontSize);
174 for (
int y = 5; y < 100; y += 10)
178 (double)0, (
double)y,
179 (double)imageWidth, (
double)y
181 SimplePath path (line,
sizeof(line) /
sizeof(
double));
184 double strokeWidth = 5.0;
185 strokePath.width(strokeWidth);
186 strokePath.line_cap(agg::square_cap);
187 strokePath.line_join(agg::miter_join);
188 strokePath.miter_limit(strokeWidth);
191 ras.add_path(strokePath);
193 agg::render_scanlines_aa_solid(ras, scanline, rBase, blueColor);
207 matrix.translate(0, 100);
209 drawImage (rBase, rBase, matrix, path, agg::fill_non_zero);
217 path.move_to(0, 200);
218 path.line_to(imageWidth, 200);
219 path.line_to(imageWidth, 300);
220 path.line_to(0, 300);
221 path.line_to(0, 200);
231 matrix.translate(0, 200);
233 drawImage (rBase, rBase, matrix, path, agg::fill_even_odd);
237 char fileName[1000] = { 0 };
240 sprintf (fileName,
"%s/", argv[1]);
242 strcat(fileName,
"tutorial_font_2.png");
243 writePng<RendererBaseType> (fileName, rBase);
249 printf (
"%s\n", ex.getMessage());
254 printf (
"Unknown exception detected.\n");