9 of NLP learning-built-in gsv_text object raster draw character

Source: Internet
Author: User

There are many ways to draw characters using the delimiter:

  1. Use the gsv_text object that comes with the delimiter;
  2. Use the WinAPI font engine;
  3. Use FreeType font engine;
  4. 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:

  1. The coordinate of the Red Cross center is (100,100), which is the starting coordinate for drawing characters.
  2. 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.
  3. 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.
  4. Gsv_text object that automatically processes line breaks.
  5. 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.
  6. Gsv_text can only process Spanish characters and cannot process Chinese characters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.