There are many ways to draw characters using the delimiter:
- Use the gsv_text object that comes with the delimiter;
- Use the WinAPI font engine;
- Use FreeType font engine;
- Use the font cache manager.
First, we use the built-in gsv_text object to draw characters in the rastser mode. The sample code is as follows:
# Include <strong> # include <agg_scanline_p.h> # include <agg_gsv_text.h> # include <strong >#include <agg_basics.h> # include <platform/agg_platform_support.h> class the_application: public role: platform_support {public: the_application (Role: pix_format_e format, bool flip_y): Role: platform_support (format, flip_y) {} virtual ~ The_application () {} virtual void on_init () {} virtual void on_draw () {region: rasterizer_scanline_aa <> ras; region: scanline_p8 sl; region :: rendering_buffer rbuf = this-> rbuf_window (); vertex: pixfmt_rgba32 pixf (rbuf); vertex: renderer_base <vertex: pixfmt_rgba32> renb (pixf ); // The screen is cleared to white renb. clear (sequence: rgba (1, 1, 1, 0); // gsv_text class sequence: gsv_text txt; sequence: conv_stroke <sequence :: gsv_text> cstxt (txt); txt. flip (false); // sets whether to reverse the txt. size (30); // the height and width of txt. line_space (10); // line spacing txt. space (5); // Character Spacing // set the location and text txt. start_point (100,100); txt. text ("program \ nC ++"); cstxt. width (3); // cstxt. line_cap (plaintext: butt_cap); // line style // output red green text ras. add_path (cstxt); region: render_scanlines_aa_solid (ras, sl, renb, Region: rgba (100,100, 0); // The Center coordinate of the Red Cross is) renb. copy_hline (90,100,110, rows: rgba (1, 0, 0, 0); renb. copy_vline (100, 90,110, encoding: rgba (1, 0, 0, 0) ;}}; int agg_main (int argc, char * argv []) {the_application app (usage: pix_format_rgba32, true); app. caption ("My role Demo"); if (app. init (320,200, restart: window_resize) {app. run () ;}return 1 ;}
Display Effect:
Note:
- The coordinate of the Red Cross center is (100,100), which is the starting coordinate for drawing characters.
- The START coordinate point of the input drawing is not the point in the upper left or lower left corner of the outer frame actually drawn by the character.
- Therefore, if you need to draw characters at a specified position, you need to accurately calculate the actual position of the painting and import the difference between the drawn coordinates.
- Gsv_text object that automatically processes line breaks.
- Although the row spacing can be set for the gsv_text object, the width of the line spacing is not removed from the character edge, so developers need to pay attention to the calculation.
- Gsv_text can only process Spanish characters and cannot process Chinese characters.