Mercurial > octave
comparison libinterp/corefcn/gl2ps-print.cc @ 21209:67d2965af0b5
revamp text rendering classes
* base-text-renderer.h: New file.
* ft-text-renderer.h, ft-text-renderer.cc: New files for freetype text
rendering classes, adapted from txt-eng-ft.h and txt-eng.cc.
* text-renderer.h, text-renderer.cc: New files. Public interface for
text rendering.
* gl-select.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
graphics.cc, graphics.in.h: Adapt to use new text rendering interface
that does not require checking HAVE_FREETYPE.
* libinterp/corefcn/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Feb 2016 08:15:53 -0500 |
parents | 945695cafd2b |
children | 721539013db4 |
comparison
equal
deleted
inserted
replaced
21208:f5e05c11c343 | 21209:67d2965af0b5 |
---|---|
39 #include "unwind-prot.h" | 39 #include "unwind-prot.h" |
40 | 40 |
41 #include "gl-render.h" | 41 #include "gl-render.h" |
42 #include "oct-opengl.h" | 42 #include "oct-opengl.h" |
43 #include "sysdep.h" | 43 #include "sysdep.h" |
44 #include "txt-eng-ft.h" | 44 #include "text-renderer.h" |
45 | 45 |
46 class | 46 class |
47 OCTINTERP_API | 47 OCTINTERP_API |
48 gl2ps_renderer : public opengl_renderer | 48 gl2ps_renderer : public opengl_renderer |
49 { | 49 { |
121 gl2psLineWidth (w); | 121 gl2psLineWidth (w); |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 | 125 |
126 // Use xform to compute the coordinates of the ft_string list | 126 // Use xform to compute the coordinates of the string list |
127 // that have been parsed by freetype | 127 // that have been parsed by freetype |
128 void fix_strlist_position (double x, double y, double z, | 128 void fix_strlist_position (double x, double y, double z, |
129 Matrix box, double rotation, | 129 Matrix box, double rotation, |
130 std::list<ft_render::ft_string>& lst); | 130 std::list<text_renderer::string>& lst); |
131 | 131 |
132 int alignment_to_mode (int ha, int va) const; | 132 int alignment_to_mode (int ha, int va) const; |
133 FILE *fp; | 133 FILE *fp; |
134 caseless_str term; | 134 caseless_str term; |
135 double fontsize; | 135 double fontsize; |
300 } | 300 } |
301 | 301 |
302 void | 302 void |
303 gl2ps_renderer::fix_strlist_position (double x, double y, double z, | 303 gl2ps_renderer::fix_strlist_position (double x, double y, double z, |
304 Matrix box, double rotation, | 304 Matrix box, double rotation, |
305 std::list<ft_render::ft_string>& lst) | 305 std::list<text_renderer::string>& lst) |
306 { | 306 { |
307 for (std::list<ft_render::ft_string>::iterator p = lst.begin (); | 307 for (std::list<text_renderer::string>::iterator p = lst.begin (); |
308 p != lst.end (); p++) | 308 p != lst.end (); p++) |
309 { | 309 { |
310 // Get pixel coordinates | 310 // Get pixel coordinates |
311 ColumnVector coord_pix = get_transform ().transform (x, y, z, false); | 311 ColumnVector coord_pix = get_transform ().transform (x, y, z, false); |
312 | 312 |
550 | 550 |
551 // We have no way to get a bounding box from gl2ps, so we parse the raw | 551 // We have no way to get a bounding box from gl2ps, so we parse the raw |
552 // string using freetype | 552 // string using freetype |
553 Matrix bbox; | 553 Matrix bbox; |
554 std::string str = txt; | 554 std::string str = txt; |
555 std::list<ft_render::ft_string> lst; | 555 std::list<text_renderer::string> lst; |
556 | 556 |
557 text_to_strlist (str, lst, bbox, ha, va, rotation); | 557 text_to_strlist (str, lst, bbox, ha, va, rotation); |
558 | 558 |
559 // When using "tex" or when the string has only one line and no | 559 // When using "tex" or when the string has only one line and no |
560 // special characters, use gl2ps for alignment | 560 // special characters, use gl2ps for alignment |
563 { | 563 { |
564 std::string name = fontname; | 564 std::string name = fontname; |
565 int sz = fontsize; | 565 int sz = fontsize; |
566 if (! lst.empty () && term.find ("tex") == std::string::npos) | 566 if (! lst.empty () && term.find ("tex") == std::string::npos) |
567 { | 567 { |
568 ft_render::ft_string s = lst.front (); | 568 text_renderer::string s = lst.front (); |
569 name = select_font (s.get_name (), s.get_weight () == "bold", | 569 name = select_font (s.get_name (), s.get_weight () == "bold", |
570 s.get_angle () == "italic"); | 570 s.get_angle () == "italic"); |
571 set_color (s.get_color ()); | 571 set_color (s.get_color ()); |
572 str = s.get_string (); | 572 str = s.get_string (); |
573 sz = s.get_size (); | 573 sz = s.get_size (); |
589 } | 589 } |
590 | 590 |
591 // Translate and rotate coordinates in order to use bottom-left alignment | 591 // Translate and rotate coordinates in order to use bottom-left alignment |
592 fix_strlist_position (x, y, z, bbox, rotation, lst); | 592 fix_strlist_position (x, y, z, bbox, rotation, lst); |
593 | 593 |
594 for (std::list<ft_render::ft_string>::iterator p = lst.begin (); | 594 for (std::list<text_renderer::string>::iterator p = lst.begin (); |
595 p != lst.end (); p++) | 595 p != lst.end (); p++) |
596 { | 596 { |
597 fontname = select_font ((*p).get_name (), | 597 fontname = select_font ((*p).get_name (), |
598 (*p).get_weight () == "bold", | 598 (*p).get_weight () == "bold", |
599 (*p).get_angle () == "italic"); | 599 (*p).get_angle () == "italic"); |