10 of NLP Learning -- draw characters in the FreeType library raster Mode

Source: Internet
Author: User
Reference of FreeType Library:
  1. Download FreeType source code, load address: http://www.freetype.org/index2.html, I use version 2.4.4.
  2. Compile it into a static library under VS2008
  3. Use FreeType Library
  • Set the FreeType header file directory // freetype // includes //
  • Reference Library # pragma comment (lib, "freetype. lib ")

Sample Code:
# Pragma comment (lib, "freetype. lib ") # include <strong> # include <agg_scanline_p.h> # include <strong> # include <agg_rendering_buffer.h> # include <agg_basics.h> # include <platform/agg_platform_support.h> # include <vector> using namespace std; typedef Syntax: font_engine_freetype_int32fe_type; typedef fe_type: path_adaptor_typevs_type; class the_appli Cation: public Syntax: platform_support {public: the_application (usage: pix_format_e format, bool flip_y): Platform: 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 (fingerprint: rgba (1, 1, 1, 0); // load the model and set the font parameter fe_type fe; if (! Fe. load_font (". /. ttf ", 0, struct: glyph_ren_outline) return; fe. height (25); fe. width (23); fe. flip_y (false); fe. hinting (true); fe. resolution (0); // string drawing wchar_t * s = L "test samples \ + FreeType \ 0"; vector <samples: int8u> data; vs_typevs; samples :: conv_curve <vs_type> ccvs (vs); int x = 50, y = 100; for (; * s; ++ s) {if (* s = '') {x + = fe. width (); continue;} if (! Fe. prepare_glyph (* s) continue; data. resize (fe. data_size (); fe. write_glyph_to (& data [0]);. init (& data [0], data. size (), x, y); x + = fe. advance_x (); y + = fe. advance_y (); ras. add_path (ccvs);} resolve: render_scanlines_aa_solid (ras, sl, renb, scheme: rgba (, 0); // draw double minx = ras in the string range border. min_x (); double miny = ras. min_y (); double maxx = ras. max_x (); double maxy = ras. max_y (); ras. reset (); ras. move_to_d (minx, miny); ras. line_to_d (minx, maxy); ras. line_to_d (maxx, maxy); ras. line_to_d (maxx, miny); Placement: render_scanlines_aa_solid (ras, sl, renb, placement: rgba (0.08, 1,); // Red Cross positioning, the Center Coordinate is (50, 50) renb. copy_hline (40,100, 60, rows: rgba (1, 0, 0, 0); renb. copy_vline (50, 90,110, rows: 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 ;}

Note:

1. The center of the Red Cross refers to the input start parameter for drawing text.

2. During painting, special processing of space characters is required; otherwise, the program crash

3. The "\" character is processed as an escape character, but the line break cannot be implemented.

4. The input draw start point is not the corner point of the draw string outsourcing.

5. FreeType does not have a weight parameter similar to Windows GDI, and cannot be set to bold

6. The width and height of the drawn characters can be set at will.

7. You can set resolution, but you have not yet understood the causal relationship that affects the rendering effect.

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.