Mercurial > octave
comparison libinterp/corefcn/graphics.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 | 7be1f58f9dd7 |
comparison
equal
deleted
inserted
replaced
21208:f5e05c11c343 | 21209:67d2965af0b5 |
---|---|
52 #include "ovl.h" | 52 #include "ovl.h" |
53 #include "oct-map.h" | 53 #include "oct-map.h" |
54 #include "ov-fcn-handle.h" | 54 #include "ov-fcn-handle.h" |
55 #include "pager.h" | 55 #include "pager.h" |
56 #include "parse.h" | 56 #include "parse.h" |
57 #include "text-renderer.h" | |
57 #include "toplev.h" | 58 #include "toplev.h" |
58 #include "txt-eng-ft.h" | |
59 #include "unwind-prot.h" | 59 #include "unwind-prot.h" |
60 #include "utils.h" | 60 #include "utils.h" |
61 #include "octave-default-image.h" | 61 #include "octave-default-image.h" |
62 | 62 |
63 // forward declarations | 63 // forward declarations |
6165 } | 6165 } |
6166 | 6166 |
6167 void | 6167 void |
6168 axes::properties::update_font (void) | 6168 axes::properties::update_font (void) |
6169 { | 6169 { |
6170 #ifdef HAVE_FREETYPE | 6170 txt_renderer.set_font (get ("fontname").string_value (), |
6171 # ifdef HAVE_FONTCONFIG | 6171 get ("fontweight").string_value (), |
6172 text_renderer.set_font (get ("fontname").string_value (), | 6172 get ("fontangle").string_value (), |
6173 get ("fontweight").string_value (), | 6173 get ("fontsize_points").double_value ()); |
6174 get ("fontangle").string_value (), | |
6175 get ("fontsize_points").double_value ()); | |
6176 #endif | |
6177 #endif | |
6178 } | 6174 } |
6179 | 6175 |
6180 // The INTERNAL flag defines whether position or outerposition is used. | 6176 // The INTERNAL flag defines whether position or outerposition is used. |
6181 | 6177 |
6182 Matrix | 6178 Matrix |
6973 if (limits(0) <= val && val <= limits(1)) | 6969 if (limits(0) <= val && val <= limits(1)) |
6974 { | 6970 { |
6975 std::string label (ticklabels(i)); | 6971 std::string label (ticklabels(i)); |
6976 label.erase (0, label.find_first_not_of (" ")); | 6972 label.erase (0, label.find_first_not_of (" ")); |
6977 label = label.substr (0, label.find_last_not_of (" ")+1); | 6973 label = label.substr (0, label.find_last_not_of (" ")+1); |
6978 #ifdef HAVE_FREETYPE | 6974 |
6979 ext = text_renderer.get_extent (label, 0.0, | 6975 if (txt_renderer.ok ()) |
6980 get_ticklabelinterpreter ()); | 6976 { |
6981 wmax = std::max (wmax, ext(0)); | 6977 ext = txt_renderer.get_extent (label, 0.0, |
6982 hmax = std::max (hmax, ext(1)); | 6978 get_ticklabelinterpreter ()); |
6983 #else | 6979 |
6984 // FIXME: find a better approximation | 6980 wmax = std::max (wmax, ext(0)); |
6985 double fsize = get ("fontsize").double_value (); | 6981 hmax = std::max (hmax, ext(1)); |
6986 int len = label.length (); | 6982 } |
6987 wmax = std::max (wmax, 0.5*fsize*len); | 6983 else |
6988 hmax = fsize; | 6984 { |
6989 #endif | 6985 // FIXME: find a better approximation |
6986 double fsize = get ("fontsize").double_value (); | |
6987 int len = label.length (); | |
6988 | |
6989 wmax = std::max (wmax, 0.5*fsize*len); | |
6990 hmax = fsize; | |
6991 } | |
6990 } | 6992 } |
6991 } | 6993 } |
6992 | 6994 |
6993 ext(0) = wmax; | 6995 ext(0) = wmax; |
6994 ext(1) = hmax; | 6996 ext(1) = hmax; |
7938 } | 7940 } |
7939 | 7941 |
7940 void | 7942 void |
7941 text::properties::update_font (void) | 7943 text::properties::update_font (void) |
7942 { | 7944 { |
7943 #ifdef HAVE_FREETYPE | 7945 txt_renderer.set_font (get ("fontname").string_value (), |
7944 # ifdef HAVE_FONTCONFIG | 7946 get ("fontweight").string_value (), |
7945 renderer.set_font (get ("fontname").string_value (), | 7947 get ("fontangle").string_value (), |
7946 get ("fontweight").string_value (), | 7948 get ("fontsize_points").double_value ()); |
7947 get ("fontangle").string_value (), | 7949 |
7948 get ("fontsize_points").double_value ()); | 7950 txt_renderer.set_color (get_color_rgb ()); |
7949 #endif | |
7950 renderer.set_color (get_color_rgb ()); | |
7951 #endif | |
7952 } | 7951 } |
7953 | 7952 |
7954 void | 7953 void |
7955 text::properties::update_text_extent (void) | 7954 text::properties::update_text_extent (void) |
7956 { | 7955 { |
7957 #ifdef HAVE_FREETYPE | |
7958 | |
7959 int halign = 0; | 7956 int halign = 0; |
7960 int valign = 0; | 7957 int valign = 0; |
7961 | 7958 |
7962 if (horizontalalignment_is ("center")) | 7959 if (horizontalalignment_is ("center")) |
7963 halign = 1; | 7960 halign = 1; |
7979 | 7976 |
7980 octave_value string_prop = get_string (); | 7977 octave_value string_prop = get_string (); |
7981 | 7978 |
7982 string_vector sv = string_prop.string_vector_value (); | 7979 string_vector sv = string_prop.string_vector_value (); |
7983 | 7980 |
7984 renderer.text_to_pixels (sv.join ("\n"), pixels, bbox, | 7981 txt_renderer.text_to_pixels (sv.join ("\n"), pixels, bbox, |
7985 halign, valign, get_rotation (), | 7982 halign, valign, get_rotation (), |
7986 get_interpreter ()); | 7983 get_interpreter ()); |
7987 // The bbox is relative to the text's position. We'll leave it that | 7984 // The bbox is relative to the text's position. We'll leave it that |
7988 // way, because get_position does not return valid results when the | 7985 // way, because get_position does not return valid results when the |
7989 // text is first constructed. Conversion to proper coordinates is | 7986 // text is first constructed. Conversion to proper coordinates is |
7990 // performed in get_extent. | 7987 // performed in get_extent. |
7991 set_extent (bbox); | 7988 set_extent (bbox); |
7992 | |
7993 #endif | |
7994 | 7989 |
7995 if (autopos_tag_is ("xlabel") || autopos_tag_is ("ylabel") | 7990 if (autopos_tag_is ("xlabel") || autopos_tag_is ("ylabel") |
7996 || autopos_tag_is ("zlabel") || autopos_tag_is ("title")) | 7991 || autopos_tag_is ("zlabel") || autopos_tag_is ("title")) |
7997 update_autopos ("sync"); | 7992 update_autopos ("sync"); |
7998 } | 7993 } |
8671 } | 8666 } |
8672 | 8667 |
8673 void | 8668 void |
8674 uicontrol::properties::update_text_extent (void) | 8669 uicontrol::properties::update_text_extent (void) |
8675 { | 8670 { |
8676 #ifdef HAVE_FREETYPE | |
8677 | |
8678 text_element *elt; | 8671 text_element *elt; |
8679 ft_render text_renderer; | 8672 text_renderer txt_renderer; |
8680 Matrix box; | 8673 Matrix box; |
8681 | 8674 |
8682 // FIXME: parsed content should be cached for efficiency | 8675 // FIXME: parsed content should be cached for efficiency |
8683 // FIXME: support multiline text | 8676 // FIXME: support multiline text |
8684 | 8677 |
8685 elt = text_parser::parse (get_string_string (), "none"); | 8678 elt = text_parser::parse (get_string_string (), "none"); |
8686 #ifdef HAVE_FONTCONFIG | 8679 |
8687 text_renderer.set_font (get_fontname (), | 8680 txt_renderer.set_font (get_fontname (), get_fontweight (), |
8688 get_fontweight (), | 8681 get_fontangle (), get_fontsize ()); |
8689 get_fontangle (), | 8682 |
8690 get_fontsize ()); | 8683 box = txt_renderer.get_extent (elt, 0); |
8691 #endif | 8684 |
8692 box = text_renderer.get_extent (elt, 0); | |
8693 delete elt; | 8685 delete elt; |
8694 | 8686 |
8695 Matrix ext (1, 4); | 8687 Matrix ext (1, 4); |
8696 | 8688 |
8697 // FIXME: also handle left and bottom components | 8689 // FIXME: also handle left and bottom components |
8699 ext(0) = ext(1) = 1; | 8691 ext(0) = ext(1) = 1; |
8700 ext(2) = box(0); | 8692 ext(2) = box(0); |
8701 ext(3) = box(1); | 8693 ext(3) = box(1); |
8702 | 8694 |
8703 set_extent (ext); | 8695 set_extent (ext); |
8704 | |
8705 #endif | |
8706 } | 8696 } |
8707 | 8697 |
8708 void | 8698 void |
8709 uicontrol::properties::update_units (void) | 8699 uicontrol::properties::update_units (void) |
8710 { | 8700 { |