diff libinterp/corefcn/gl-render.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 fcac5dbbf9ed
children 40de9f8f23a6
line wrap: on
line diff
--- a/libinterp/corefcn/gl-render.cc	Fri Feb 05 14:53:10 2016 -0500
+++ b/libinterp/corefcn/gl-render.cc	Sat Feb 06 08:15:53 2016 -0500
@@ -40,8 +40,7 @@
 #include "errwarn.h"
 #include "gl-render.h"
 #include "oct-opengl.h"
-#include "txt-eng.h"
-#include "txt-eng-ft.h"
+#include "text-renderer.h"
 
 #define LIGHT_MODE GL_FRONT_AND_BACK
 
@@ -2897,20 +2896,17 @@
 opengl_renderer::set_color (const Matrix& c)
 {
   glColor3dv (c.data ());
-#if HAVE_FREETYPE
-  text_renderer.set_color (c);
-#endif
+
+  txt_renderer.set_color (c);
 }
 
 void
 opengl_renderer::set_font (const base_properties& props)
 {
-#if HAVE_FREETYPE
-  text_renderer.set_font (props.get ("fontname").string_value (),
-                          props.get ("fontweight").string_value (),
-                          props.get ("fontangle").string_value (),
-                          props.get ("fontsize_points").double_value ());
-#endif
+  txt_renderer.set_font (props.get ("fontname").string_value (),
+                         props.get ("fontweight").string_value (),
+                         props.get ("fontangle").string_value (),
+                         props.get ("fontsize_points").double_value ());
 }
 
 void
@@ -3238,22 +3234,18 @@
                                  Matrix& bbox,
                                  int halign, int valign, double rotation)
 {
-#if HAVE_FREETYPE
-  text_renderer.text_to_pixels (txt, pixels, bbox,
-                                halign, valign, rotation, interpreter);
-#endif
+  txt_renderer.text_to_pixels (txt, pixels, bbox, halign, valign,
+                               rotation, interpreter);
 }
 
 void
 opengl_renderer::text_to_strlist (const std::string& txt,
-                                  std::list<ft_render::ft_string>& lst,
+                                  std::list<text_renderer::string>& lst,
                                   Matrix& bbox,
                                   int halign, int valign, double rotation)
 {
-#if HAVE_FREETYPE
-  text_renderer.text_to_strlist (txt, lst, bbox,
-                                 halign, valign, rotation, interpreter);
-#endif
+  txt_renderer.text_to_strlist (txt, lst, bbox, halign, valign,
+                                rotation, interpreter);
 }
 
 Matrix
@@ -3261,32 +3253,31 @@
                               double x, double y, double z,
                               int halign, int valign, double rotation)
 {
-#if HAVE_FREETYPE
+  Matrix bbox (1, 4, 0.0);
+
   if (txt.empty ())
-    return Matrix (1, 4, 0.0);
-
-  uint8NDArray pixels;
-  Matrix bbox;
-  text_to_pixels (txt, pixels, bbox, halign, valign, rotation);
-
-  bool blend = glIsEnabled (GL_BLEND);
-
-  glEnable (GL_BLEND);
-  glEnable (GL_ALPHA_TEST);
-  glRasterPos3d (x, y, z);
-  glBitmap(0, 0, 0, 0, bbox(0), bbox(1), 0);
-  glDrawPixels (bbox(2), bbox(3),
-                GL_RGBA, GL_UNSIGNED_BYTE, pixels.data ());
-  glDisable (GL_ALPHA_TEST);
-  if (! blend)
-    glDisable (GL_BLEND);
+    return bbox;
+
+  if (txt_renderer.ok ())
+    {
+      uint8NDArray pixels;
+      text_to_pixels (txt, pixels, bbox, halign, valign, rotation);
+
+      bool blend = glIsEnabled (GL_BLEND);
+
+      glEnable (GL_BLEND);
+      glEnable (GL_ALPHA_TEST);
+      glRasterPos3d (x, y, z);
+      glBitmap(0, 0, 0, 0, bbox(0), bbox(1), 0);
+      glDrawPixels (bbox(2), bbox(3),
+                    GL_RGBA, GL_UNSIGNED_BYTE, pixels.data ());
+      glDisable (GL_ALPHA_TEST);
+
+      if (! blend)
+        glDisable (GL_BLEND);
+    }
 
   return bbox;
-#else
-  warn_disabled_feature ("opengl_renderer::render_text",
-                         "rendering text (FreeType)");
-  return Matrix (1, 4, 0.0);
-#endif
 }
 
 #endif