GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ft-text-renderer.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2009-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "base-text-renderer.h"
31 #include "ft-text-renderer.h"
32 
33 #if defined (HAVE_FREETYPE)
34 
35 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
36 # pragma GCC diagnostic push
37 # pragma GCC diagnostic ignored "-Wold-style-cast"
38 #endif
39 
40 #include <ft2build.h>
41 #include FT_FREETYPE_H
42 #include FT_GLYPH_H
43 
44 #if defined (HAVE_FONTCONFIG)
45 # include <fontconfig/fontconfig.h>
46 #endif
47 
48 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
49 # pragma GCC diagnostic pop
50 #endif
51 
52 #include <clocale>
53 #include <cwchar>
54 #include <map>
55 #include <utility>
56 
57 #include "singleton-cleanup.h"
58 #include "unistr-wrappers.h"
59 
60 #include "defaults.h"
61 #include "error.h"
62 #include "file-ops.h"
63 #include "oct-env.h"
64 #include "pr-output.h"
65 #include "sysdep.h"
66 #include "text-renderer.h"
67 
69 
70 // FIXME: maybe issue at most one warning per glyph/font/size/weight
71 // combination.
72 
73 static void
74 warn_missing_glyph (FT_ULong c)
75 {
76  warning_with_id ("Octave:missing-glyph",
77  "text_renderer: skipping missing glyph for character '%lx'", c);
78 }
79 
80 static void
81 warn_glyph_render (FT_ULong c)
82 {
83  warning_with_id ("Octave:glyph-render",
84  "text_renderer: unable to render glyph for character '%lx'", c);
85 }
86 
87 #if defined (_MSC_VER)
88 // FIXME: is this really needed?
89 //
90 // This is just a trick to avoid multiple symbol definitions.
91 // PermMatrix.h contains a dllexport'ed Array<octave_idx_type>
92 // that will cause MSVC not to generate a new instantiation and
93 // use the imported one instead.
94 # include "PermMatrix.h"
95 #endif
96 
97 // Forward declaration
98 static void ft_face_destroyed (void *object);
99 
100 class
101 ft_manager
102 {
103 private:
104 
105  ft_manager ()
106  : m_library (), m_freetype_initialized (false),
107  m_fontconfig_initialized (false)
108  {
109  if (FT_Init_FreeType (&m_library))
110  error ("unable to initialize FreeType library");
111  else
112  m_freetype_initialized = true;
113 
114 #if defined (HAVE_FONTCONFIG)
115  if (! FcInit ())
116  error ("unable to initialize fontconfig library");
117  else
118  m_fontconfig_initialized = true;
119 #endif
120  }
121 
122 public:
123 
124  OCTAVE_DISABLE_COPY_MOVE (ft_manager)
125 
126 private:
127 
128  ~ft_manager ()
129  {
130  if (m_freetype_initialized)
131  FT_Done_FreeType (m_library);
132 
133 #if defined (HAVE_FONTCONFIG)
134  // FIXME: Skip the call to FcFini because it can trigger the assertion
135  //
136  // octave: fccache.c:507: FcCacheFini: Assertion 'fcCacheChains[i] == ((void *)0)' failed.
137  //
138  // if (m_fontconfig_initialized)
139  // FcFini ();
140 #endif
141  }
142 
143 public:
144 
145  static bool instance_ok ()
146  {
147  bool retval = true;
148 
149  if (! s_instance)
150  {
151  s_instance = new ft_manager ();
152  singleton_cleanup_list::add (cleanup_instance);
153  }
154 
155  return retval;
156  }
157 
158  static void cleanup_instance ()
159  { delete s_instance; s_instance = nullptr; }
160 
161  static FT_Face get_font (const std::string& name, const std::string& weight,
162  const std::string& angle, double size,
163  FT_ULong c = 0)
164  {
165  return (instance_ok ()
166  ? s_instance->do_get_font (name, weight, angle, size, c)
167  : nullptr);
168  }
169 
170  static octave_map get_system_fonts ()
171  {
172  return (instance_ok ()
173  ? s_instance->do_get_system_fonts ()
174  : octave_map ());
175  }
176 
177  static void font_destroyed (FT_Face face)
178  {
179  if (instance_ok ())
180  s_instance->do_font_destroyed (face);
181  }
182 
183 private:
184 
185  typedef std::pair<std::string, double> ft_key;
186  typedef std::map<ft_key, FT_Face> ft_cache;
187 
188  static octave_map do_get_system_fonts ()
189  {
190  static octave_map font_map;
191 
192  if (font_map.isempty ())
193  {
194 #if defined (HAVE_FONTCONFIG)
195  FcConfig *config = FcConfigGetCurrent();
196  FcPattern *pat = FcPatternCreate ();
197  FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_SLANT, FC_WEIGHT,
198  FC_CHARSET, nullptr);
199  FcFontSet *fs = FcFontList (config, pat, os);
200 
201  if (fs->nfont > 0)
202  {
203  // Mark fonts that have at least all printable ASCII chars
204  FcCharSet *minimal_charset = FcCharSetCreate ();
205  for (int i = 32; i < 127; i++)
206  FcCharSetAddChar (minimal_charset, static_cast<FcChar32> (i));
207 
208  string_vector fields (4);
209  fields(0) = "family";
210  fields(1) = "angle";
211  fields(2) = "weight";
212  fields(3) = "suitable";
213 
214  dim_vector dv (1, fs->nfont);
215  Cell families (dv);
216  Cell angles (dv);
217  Cell weights (dv);
218  Cell suitable (dv);
219 
220  unsigned char *family;
221  int val;
222  for (int i = 0; fs && i < fs->nfont; i++)
223  {
224  FcPattern *font = fs->fonts[i];
225  if (FcPatternGetString (font, FC_FAMILY, 0, &family)
226  == FcResultMatch)
227  families(i) = std::string (reinterpret_cast<char *> (family));
228  else
229  families(i) = "unknown";
230 
231  if (FcPatternGetInteger (font, FC_SLANT, 0, &val)
232  == FcResultMatch)
233  angles(i) = (val == FC_SLANT_ITALIC
234  || val == FC_SLANT_OBLIQUE)
235  ? "italic" : "normal";
236  else
237  angles(i) = "unknown";
238 
239  if (FcPatternGetInteger (font, FC_WEIGHT, 0, &val)
240  == FcResultMatch)
241  weights(i) = (val == FC_WEIGHT_BOLD
242  || val == FC_WEIGHT_DEMIBOLD)
243  ? "bold" : "normal";
244  else
245  weights(i) = "unknown";
246 
247  FcCharSet *cset;
248  if (FcPatternGetCharSet (font, FC_CHARSET, 0, &cset)
249  == FcResultMatch)
250  suitable(i) = (FcCharSetIsSubset (minimal_charset, cset)
251  ? true : false);
252  else
253  suitable(i) = false;
254  }
255 
256  font_map = octave_map (dv, fields);
257 
258  font_map.assign ("family", families);
259  font_map.assign ("angle", angles);
260  font_map.assign ("weight", weights);
261  font_map.assign ("suitable", suitable);
262 
263  // Free up memory within libfontconfig.
264  if (fs)
265  FcFontSetDestroy (fs);
266  if (pat) // Supposed to be freed by FcFontSetDestroy above, but isn't.
267  FcPatternDestroy (pat);
268  if (os)
269  FcObjectSetDestroy (os);
270  if (minimal_charset)
271  FcCharSetDestroy (minimal_charset);
272  }
273 #endif
274  }
275 
276  return font_map;
277  }
278 
279  FT_Face do_get_font (const std::string& name, const std::string& weight,
280  const std::string& angle, double size,
281  FT_ULong search_code_point)
282  {
283  FT_Face retval = nullptr;
284 
285 #if defined (HAVE_FT_REFERENCE_FACE)
286  // Look first into the font cache, then use fontconfig. If the font
287  // is present in the cache, simply add a reference and return it.
288 
289  ft_key key (name + ':' + weight + ':' + angle + ':'
290  + std::to_string (search_code_point), size);
291  ft_cache::const_iterator it = m_cache.find (key);
292 
293  if (it != m_cache.end ())
294  {
295  FT_Reference_Face (it->second);
296  return it->second;
297  }
298 #endif
299 
300  static std::string fonts_dir;
301 
302  if (fonts_dir.empty ())
303  {
304  fonts_dir = sys::env::getenv ("OCTAVE_FONTS_DIR");
305 
306  if (fonts_dir.empty ())
307 #if defined (SYSTEM_FREEFONT_DIR)
308  fonts_dir = SYSTEM_FREEFONT_DIR;
309 #else
310  fonts_dir = config::oct_fonts_dir ();
311 #endif
312  }
313 
314 
315  // Default font file
316  std::string file;
317 
318  if (! fonts_dir.empty ())
319  {
320  file = fonts_dir + sys::file_ops::dir_sep_str () + "FreeSans";
321 
322  if (weight == "bold")
323  file += "Bold";
324 
325  if (angle == "italic" || angle == "oblique")
326  file += "Oblique";
327 
328  file += ".otf";
329  }
330 
331 #if defined (HAVE_FONTCONFIG)
332  if ((search_code_point != 0 || name != "*") && m_fontconfig_initialized)
333  {
334  int fc_weight, fc_angle;
335 
336  if (weight == "bold")
337  fc_weight = FC_WEIGHT_BOLD;
338  else
339  fc_weight = FC_WEIGHT_NORMAL;
340 
341  if (angle == "italic")
342  fc_angle = FC_SLANT_ITALIC;
343  else if (angle == "oblique")
344  fc_angle = FC_SLANT_OBLIQUE;
345  else
346  fc_angle = FC_SLANT_ROMAN;
347 
348  FcPattern *pat = FcPatternCreate ();
349 
350  FcPatternAddString (pat, FC_FAMILY,
351  (reinterpret_cast<const FcChar8 *>
352  (name.c_str ())));
353 
354  FcPatternAddInteger (pat, FC_WEIGHT, fc_weight);
355  FcPatternAddInteger (pat, FC_SLANT, fc_angle);
356  FcPatternAddDouble (pat, FC_PIXEL_SIZE, size);
357 
358  if (search_code_point > 0)
359  {
360  FcCharSet *minimal_charset = FcCharSetCreate ();
361  FcCharSetAddChar (minimal_charset,
362  static_cast<FcChar32> (search_code_point));
363  FcPatternAddCharSet (pat, FC_CHARSET, minimal_charset);
364  }
365 
366  if (FcConfigSubstitute (nullptr, pat, FcMatchPattern))
367  {
368  FcResult res;
369  FcPattern *match;
370 
371  FcDefaultSubstitute (pat);
372 
373  match = FcFontMatch (nullptr, pat, &res);
374 
375  // FIXME: originally, this test also required that
376  // res != FcResultNoMatch. Is that really needed?
377  if (match)
378  {
379  unsigned char *tmp;
380 
381  FcPatternGetString (match, FC_FILE, 0, &tmp);
382  file = reinterpret_cast<char *> (tmp);
383  }
384  else
385  ::warning ("could not match any font: %s-%s-%s-%g, using default font",
386  name.c_str (), weight.c_str (), angle.c_str (),
387  size);
388 
389  if (match)
390  FcPatternDestroy (match);
391  }
392 
393  FcPatternDestroy (pat);
394  }
395 #endif
396 
397  if (file.empty ())
398  ::warning ("unable to find default font files");
399  else
400  {
401  std::string ascii_file = sys::get_ASCII_filename (file);
402 
403  if (FT_New_Face (m_library, ascii_file.c_str (), 0, &retval))
404  ::warning ("ft_manager: unable to load font: %s", file.c_str ());
405 #if defined (HAVE_FT_REFERENCE_FACE)
406  else
407  {
408  // Install a finalizer to notify ft_manager that the font is
409  // being destroyed. The class ft_manager only keeps weak
410  // references to font objects.
411 
412  retval->generic.data = new ft_key (key);
413  retval->generic.finalizer = ft_face_destroyed;
414 
415  // Insert loaded font into the cache.
416  if (FT_Reference_Face (retval) == 0)
417  m_cache[key] = retval;
418  }
419 #endif
420  }
421 
422  return retval;
423  }
424 
425  void do_font_destroyed (FT_Face face)
426  {
427  if (face->generic.data)
428  {
429  ft_key *pkey = reinterpret_cast<ft_key *> (face->generic.data);
430 
431  m_cache.erase (*pkey);
432  delete pkey;
433  face->generic.data = nullptr;
434  FT_Done_Face (face);
435  }
436  }
437 
438  //--------
439 
440  static ft_manager *s_instance;
441 
442  // Cache the fonts loaded by FreeType. This cache only contains
443  // weak references to the fonts, strong references are only present
444  // in class text_renderer.
445  ft_cache m_cache;
446 
447  FT_Library m_library;
448  bool m_freetype_initialized;
449  bool m_fontconfig_initialized;
450 };
451 
452 ft_manager *ft_manager::s_instance = nullptr;
453 
454 static void
455 ft_face_destroyed (void *object)
456 {
457  ft_manager::font_destroyed (reinterpret_cast<FT_Face> (object));
458 }
459 
460 class
461 OCTINTERP_API
462 ft_text_renderer : public base_text_renderer
463 {
464 public:
465 
466  enum
467  {
468  MODE_BBOX = 0,
469  MODE_RENDER = 1
470  };
471 
472 public:
473 
474  ft_text_renderer ()
475  : base_text_renderer (), m_font (), m_bbox (1, 4, 0.0), m_halign (0),
476  m_xoffset (0), m_line_yoffset (0), m_yoffset (0), m_mode (MODE_BBOX),
477  m_color (dim_vector (1, 3), 0), m_do_strlist (false), m_strlist (),
478  m_line_xoffset (0), m_ymin (0), m_ymax (0), m_deltax (0),
479  m_max_fontsize (0), m_antialias (true)
480  { }
481 
482  OCTAVE_DISABLE_COPY_MOVE (ft_text_renderer)
483 
484  ~ft_text_renderer () = default;
485 
486  void visit (text_element_string& e);
487 
488  void visit (text_element_list& e);
489 
490  void visit (text_element_subscript& e);
491 
492  void visit (text_element_superscript& e);
493 
494  void visit (text_element_color& e);
495 
496  void visit (text_element_fontsize& e);
497 
498  void visit (text_element_fontname& e);
499 
500  void visit (text_element_fontstyle& e);
501 
502  void visit (text_element_symbol& e);
503 
504  void visit (text_element_combined& e);
505 
506  void reset ();
507 
508  uint8NDArray get_pixels () const { return m_pixels; }
509 
510  Matrix get_boundingbox () const { return m_bbox; }
511 
512  uint8NDArray render (text_element *elt, Matrix& box,
513  int rotation = ROTATION_0);
514 
515  Matrix get_extent (text_element *elt, double rotation = 0.0);
516  Matrix get_extent (const std::string& txt, double rotation,
517  const caseless_str& interpreter);
518 
519  void set_anti_aliasing (bool val) { m_antialias = val; };
520 
521  void set_font (const std::string& name, const std::string& weight,
522  const std::string& angle, double size);
523 
524  octave_map get_system_fonts ();
525 
526  void set_color (const Matrix& c);
527 
528  void set_mode (int m);
529 
530  void text_to_pixels (const std::string& txt,
531  uint8NDArray& pxls, Matrix& bbox,
532  int halign, int valign, double rotation,
533  const caseless_str& interpreter,
534  bool handle_rotation);
535 
536 private:
537 
538  // Class to hold information about fonts and a strong
539  // reference to the font objects loaded by FreeType.
540 
541  class ft_font : public text_renderer::font
542  {
543  public:
544 
545  ft_font ()
546  : text_renderer::font (), m_face (nullptr) { }
547 
548  ft_font (const std::string& nm, const std::string& wt,
549  const std::string& ang, double sz, FT_Face f = nullptr)
550  : text_renderer::font (nm, wt, ang, sz), m_face (f)
551  { }
552 
553  ft_font (const ft_font& ft);
554 
555  ~ft_font ()
556  {
557  if (m_face)
558  FT_Done_Face (m_face);
559  }
560 
561  ft_font& operator = (const ft_font& ft);
562 
563  bool is_valid () const { return get_face (); }
564 
565  FT_Face get_face () const;
566 
567  private:
568 
569  mutable FT_Face m_face;
570  };
571 
572  void push_new_line ();
573 
574  void update_line_bbox ();
575 
576  void compute_bbox ();
577 
578  int compute_line_xoffset (const Matrix& lb) const;
579 
580  FT_UInt process_character (FT_ULong code, FT_UInt previous,
581  std::string& sub_font);
582 
583 public:
584 
585  void text_to_strlist (const std::string& txt,
586  std::list<text_renderer::string>& lst, Matrix& bbox,
587  int halign, int valign, double rotation,
588  const caseless_str& interp);
589 
590 private:
591 
592  // The current font used by the renderer.
593  ft_font m_font;
594 
595  // Used to stored the bounding box corresponding to the rendered text.
596  // The bounding box has the form [x, y, w, h] where x and y represent the
597  // coordinates of the bottom left corner relative to the anchor point of
598  // the text (== start of text on the baseline). Due to font descent or
599  // multiple lines, the value y is usually negative.
600  Matrix m_bbox;
601 
602  // Used to stored the rendered text. It's a 3D matrix with size MxNx4
603  // where M and N are the width and height of the bounding box.
604  uint8NDArray m_pixels;
605 
606  // Used to store the bounding box of each line. This is used to layout
607  // multiline text properly.
608  std::list<Matrix> m_line_bbox;
609 
610  // The current horizontal alignment. This is used to align multi-line text.
611  int m_halign;
612 
613  // The X offset for the next glyph.
614  int m_xoffset;
615 
616  // The Y offset of the baseline for the current line.
617  int m_line_yoffset;
618 
619  // The Y offset of the baseline for the next glyph. The offset is relative
620  // to line_yoffset. The total Y offset is computed with:
621  // line_yoffset + yoffset.
622  int m_yoffset;
623 
624  // The current mode of the rendering process (box computing or rendering).
625  int m_mode;
626 
627  // The base color of the rendered text.
628  uint8NDArray m_color;
629 
630  // A list of parsed strings to be used for printing.
631  bool m_do_strlist;
632  std::list<text_renderer::string> m_strlist;
633 
634  // The X offset of the baseline for the current line.
635  int m_line_xoffset;
636 
637  // Min and max y coordinates of all glyphs in a line.
638  FT_Pos m_ymin;
639  FT_Pos m_ymax;
640 
641  // Difference between the advance and the actual extent of the latest glyph
642  FT_Pos m_deltax;
643 
644  // Used for computing the distance between lines.
645  double m_max_fontsize;
646 
647  // Anti-aliasing.
648  bool m_antialias;
649 
650 };
651 
652 void
653 ft_text_renderer::set_font (const std::string& name,
654  const std::string& weight,
655  const std::string& angle, double size)
656 {
657  // FIXME: take "fontunits" into account
658  m_font = ft_font (name, weight, angle, size, nullptr);
659 }
660 
662 ft_text_renderer::get_system_fonts ()
663 {
664  return ft_manager::get_system_fonts ();
665 }
666 
667 void
668 ft_text_renderer::push_new_line ()
669 {
670  switch (m_mode)
671  {
672  case MODE_BBOX:
673  {
674  // Create a new bbox entry based on the current font.
675 
676  FT_Face face = m_font.get_face ();
677 
678  if (face)
679  {
680  Matrix bb (1, 5, 0.0);
681 
682  m_line_bbox.push_back (bb);
683 
684  m_xoffset = m_yoffset = 0;
685  m_ymin = m_ymax = m_deltax = 0;
686  }
687  }
688  break;
689 
690  case MODE_RENDER:
691  {
692  // Move to the next line bbox, adjust xoffset based on alignment
693  // and yoffset based on the old and new line bbox.
694 
695  Matrix old_bbox = m_line_bbox.front ();
696  m_line_bbox.pop_front ();
697  Matrix new_bbox = m_line_bbox.front ();
698 
699  m_xoffset = m_line_xoffset = compute_line_xoffset (new_bbox);
700  m_line_yoffset -= (-old_bbox(1) + math::round (0.4 * m_max_fontsize)
701  + (new_bbox(3) + new_bbox(1)));
702  m_yoffset = 0;
703  m_ymin = m_ymax = m_deltax = 0;
704  }
705  break;
706  }
707 }
708 
709 int
710 ft_text_renderer::compute_line_xoffset (const Matrix& lb) const
711 {
712  if (! m_bbox.isempty ())
713  {
714  switch (m_halign)
715  {
716  case 0:
717  return 0;
718  case 1:
719  return (m_bbox(2) - lb(2)) / 2;
720  case 2:
721  return (m_bbox(2) - lb(2));
722  }
723  }
724 
725  return 0;
726 }
727 
728 void
729 ft_text_renderer::compute_bbox ()
730 {
731  // Stack the various line bbox together and compute the final
732  // bounding box for the entire text string.
733 
734  m_bbox = Matrix ();
735 
736  switch (m_line_bbox.size ())
737  {
738  case 0:
739  break;
740 
741  case 1:
742  m_bbox = m_line_bbox.front ().extract (0, 0, 0, 3);
743  break;
744 
745  default:
746  for (const auto& lbox : m_line_bbox)
747  {
748  if (m_bbox.isempty ())
749  m_bbox = lbox.extract (0, 0, 0, 3);
750  else
751  {
752  double delta = math::round (0.4 * m_max_fontsize) + lbox(3);
753  m_bbox(1) -= delta;
754  m_bbox(3) += delta;
755  m_bbox(2) = math::max (m_bbox(2), lbox(2));
756  }
757  }
758  break;
759  }
760 }
761 
762 void
763 ft_text_renderer::update_line_bbox ()
764 {
765  // Called after a font change, when in MODE_BBOX mode, to update the
766  // current line bbox with the new font metrics. This also includes the
767  // current yoffset, that is the offset of the current glyph's baseline
768  // the line's baseline.
769 
770  if (m_mode == MODE_BBOX)
771  {
772  Matrix& bb = m_line_bbox.back ();
773  bb(1) = m_ymin;
774  // Add one pixel to the bbox height to avoid occasional text clipping.
775  // See bug #55328.
776  bb(3) = (m_ymax + 1) - m_ymin;
777  if (m_deltax > 0)
778  bb(2) += m_deltax;
779  }
780 }
781 
782 void
783 ft_text_renderer::set_mode (int m)
784 {
785  m_mode = m;
786 
787  switch (m_mode)
788  {
789  case MODE_BBOX:
790  m_xoffset = m_line_yoffset = m_yoffset = 0;
791  m_max_fontsize = 0.0;
792  m_bbox = Matrix (1, 4, 0.0);
793  m_line_bbox.clear ();
794  push_new_line ();
795  break;
796 
797  case MODE_RENDER:
798  if (m_bbox.numel () != 4)
799  {
800  ::error ("ft_text_renderer: invalid bounding box, cannot render");
801 
802  m_xoffset = m_line_yoffset = m_yoffset = 0;
803  m_pixels = uint8NDArray ();
804  }
805  else
806  {
807  dim_vector d (4, octave_idx_type (m_bbox(2)),
808  octave_idx_type (m_bbox(3)));
809  m_pixels = uint8NDArray (d, static_cast<uint8_t> (0));
810  m_xoffset = compute_line_xoffset (m_line_bbox.front ());
811  m_line_yoffset = -m_bbox(1);
812  m_yoffset = 0;
813  }
814  break;
815 
816  default:
817  error ("ft_text_renderer: invalid mode '%d'", m_mode);
818  break;
819  }
820 }
821 
822 bool
823 is_opaque (const FT_GlyphSlot& glyph, const int x, const int y)
824 {
825  // Borrowed from https://stackoverflow.com/questions/14800827/
826  // indexing-pixels-in-a-monochrome-freetype-glyph-buffer
827  int pitch = std::abs (glyph->bitmap.pitch);
828  unsigned char *row = &glyph->bitmap.buffer[pitch * y];
829  char cvalue = row[x >> 3];
830 
831  return ((cvalue & (128 >> (x & 7))) != 0);
832 }
833 
834 FT_UInt
835 ft_text_renderer::process_character (FT_ULong code, FT_UInt previous,
836  std::string& sub_name)
837 {
838  FT_Face face = m_font.get_face ();
839 
840  sub_name = face->family_name;
841 
842  FT_UInt glyph_index = 0;
843 
844  if (face)
845  {
846  glyph_index = FT_Get_Char_Index (face, code);
847 
848  if (code != '\n' && code != '\t'
849  && (! glyph_index
850  || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)))
851  {
852 #if defined (HAVE_FONTCONFIG)
853  // Try to substitue font
854  FT_Face sub_face = ft_manager::get_font (m_font.get_name (),
855  m_font.get_weight (),
856  m_font.get_angle (),
857  m_font.get_size (),
858  code);
859 
860  if (sub_face)
861  {
862  FT_Set_Char_Size (sub_face, 0, m_font.get_size ()*64, 0, 0);
863 
864  glyph_index = FT_Get_Char_Index (sub_face, code);
865 
866  if (glyph_index
867  && (FT_Load_Glyph (sub_face, glyph_index, FT_LOAD_DEFAULT)
868  == 0))
869  {
870  static std::string prev_sub_name;
871 
872  if (prev_sub_name.empty ()
873  || prev_sub_name != std::string (sub_face->family_name))
874  {
875  prev_sub_name = sub_face->family_name;
876  warning_with_id ("Octave:substituted-glyph",
877  "text_renderer: substituting font to '%s' for some characters",
878  sub_face->family_name);
879  }
880 
881  ft_font saved_font = m_font;
882 
883  m_font = ft_font (m_font.get_name (), m_font.get_weight (),
884  m_font.get_angle (), m_font.get_size (),
885  sub_face);
886 
887  process_character (code, previous, sub_name);
888 
889  m_font = saved_font;
890  }
891  else
892  {
893  glyph_index = 0;
894  warn_missing_glyph (code);
895  }
896  }
897  else
898  {
899  glyph_index = 0;
900  warn_missing_glyph (code);
901  }
902 #else
903  glyph_index = 0;
904  warn_missing_glyph (code);
905 #endif
906  }
907  else if ((code == '\n') || (code == '\t'))
908  {
909  glyph_index = FT_Get_Char_Index (face, ' ');
910  if (! glyph_index
911  || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
912  {
913  glyph_index = 0;
914  warn_missing_glyph (' ');
915  }
916  else if (code == '\n')
917  push_new_line ();
918  else
919  {
920  // Advance to next multiple of 4 times the width of the "space"
921  // character.
922  int x_tab = 4 * (face->glyph->advance.x >> 6);
923  m_xoffset = (1 + std::floor (1. * m_xoffset / x_tab)) * x_tab;
924  }
925  }
926  else
927  {
928  switch (m_mode)
929  {
930  case MODE_RENDER:
931  if (FT_Render_Glyph (face->glyph, (m_antialias
932  ? FT_RENDER_MODE_NORMAL
933  : FT_RENDER_MODE_MONO)))
934  {
935  glyph_index = 0;
936  warn_glyph_render (code);
937  }
938  else
939  {
940  FT_Bitmap& bitmap = face->glyph->bitmap;
941  int x0, y0;
942 
943  if (previous)
944  {
945  FT_Vector delta;
946 
947  FT_Get_Kerning (face, previous, glyph_index,
948  FT_KERNING_DEFAULT, &delta);
949 
950  m_xoffset += (delta.x >> 6);
951  }
952 
953  x0 = m_xoffset + face->glyph->bitmap_left;
954  y0 = m_line_yoffset + m_yoffset
955  + (face->glyph->bitmap_top - 1);
956 
957  // 'w' seems to have a negative -1
958  // face->glyph->bitmap_left, this is so we don't index out
959  // of bound, and assumes we've allocated the right amount of
960  // horizontal space in the bbox.
961  if (x0 < 0)
962  x0 = 0;
963 
964  for (int r = 0; static_cast<unsigned int> (r) < bitmap.rows; r++)
965  for (int c = 0; static_cast<unsigned int> (c) < bitmap.width; c++)
966  {
967  unsigned char pix
968  = (m_antialias
969  ? bitmap.buffer[r*bitmap.width+c]
970  : (is_opaque (face->glyph, c, r) ? 255 : 0));
971 
972  if (x0+c < 0 || x0+c >= m_pixels.dim2 ()
973  || y0-r < 0 || y0-r >= m_pixels.dim3 ())
974  {
975  // ::warning ("ft_text_renderer: x %d, y %d",
976  // x0+c, y0-r);
977  }
978  else if (m_pixels(3, x0+c, y0-r).value () == 0)
979  {
980  m_pixels(0, x0+c, y0-r) = m_color(0);
981  m_pixels(1, x0+c, y0-r) = m_color(1);
982  m_pixels(2, x0+c, y0-r) = m_color(2);
983  m_pixels(3, x0+c, y0-r) = pix;
984  }
985  }
986 
987  m_xoffset += (face->glyph->advance.x >> 6);
988  }
989  break;
990 
991  case MODE_BBOX:
992  Matrix& bb = m_line_bbox.back ();
993 
994  // If we have a previous glyph, use kerning information. This
995  // usually means moving a bit backward before adding the next
996  // glyph. That is, "delta.x" is usually < 0.
997  if (previous)
998  {
999  FT_Vector delta;
1000 
1001  FT_Get_Kerning (face, previous, glyph_index,
1002  FT_KERNING_DEFAULT, &delta);
1003 
1004  m_xoffset += (delta.x >> 6);
1005  }
1006 
1007  // Extend current X offset box by the width of the current
1008  // glyph. Then extend the line bounding box if necessary.
1009 
1010  m_xoffset += (face->glyph->advance.x >> 6);
1011  bb(2) = math::max (bb(2), m_xoffset);
1012 
1013  // Store the actual bbox vertical coordinates of this character
1014  FT_Glyph glyph;
1015  if (FT_Get_Glyph (face->glyph, &glyph))
1016  warn_glyph_render (code);
1017  else
1018  {
1019  FT_BBox glyph_bbox;
1020  FT_Glyph_Get_CBox (glyph, FT_GLYPH_BBOX_UNSCALED,
1021  &glyph_bbox);
1022  m_deltax = (glyph_bbox.xMax - face->glyph->advance.x) >> 6;
1023  m_ymin = math::min ((glyph_bbox.yMin >> 6) + m_yoffset,
1024  m_ymin);
1025  m_ymax = math::max ((glyph_bbox.yMax >> 6) + m_yoffset,
1026  m_ymax);
1027  FT_Done_Glyph (glyph);
1028  update_line_bbox ();
1029  }
1030  break;
1031  }
1032  }
1033  }
1034 
1035  return glyph_index;
1036 }
1037 
1038 void
1039 ft_text_renderer::text_to_strlist (const std::string& txt,
1040  std::list<text_renderer::string>& lst,
1041  Matrix& box,
1042  int ha, int va, double rot,
1043  const caseless_str& interp)
1044 {
1045  uint8NDArray pxls;
1046 
1047  // First run text_to_pixels which will also build the string list
1048 
1049  m_strlist = std::list<text_renderer::string> ();
1050 
1051  unwind_protect_var<bool> restore_var1 (m_do_strlist);
1053  restore_var2 (m_strlist);
1054 
1055  m_do_strlist = true;
1056 
1057  text_to_pixels (txt, pxls, box, ha, va, rot, interp, false);
1058 
1059  lst = m_strlist;
1060 }
1061 
1062 void
1063 ft_text_renderer::visit (text_element_string& e)
1064 {
1065  if (m_font.is_valid ())
1066  {
1067  m_max_fontsize = std::max (m_max_fontsize, m_font.get_size ());
1068  FT_UInt glyph_index, previous = 0;
1069 
1070  std::string str = e.string_value ();
1071  const uint8_t *c = reinterpret_cast<const uint8_t *> (str.c_str ());
1072  uint32_t u32_c;
1073 
1074  std::size_t n = str.size ();
1075  std::size_t icurr = 0;
1076  std::size_t ibegin = 0;
1077 
1078  // Initialize a new string
1079  text_renderer::string fs (str, m_font, m_xoffset, m_yoffset);
1080 
1081  std::string fname = m_font.get_face ()->family_name;
1082 
1083  if (fname.find (" ") != std::string::npos)
1084  fname = "'" + fname + "'";
1085 
1086  fs.set_family (fname);
1087 
1088  std::vector<double> xdata;
1089  std::string sub_name;
1090 
1091  while (n > 0)
1092  {
1093  // Retrieve the length and the u32 representation of the current
1094  // character
1095  int mblen = octave_u8_strmbtouc_wrapper (&u32_c, c + icurr);
1096  if (mblen < 1)
1097  {
1098  // This is not an UTF-8 character, use a replacement character
1099  mblen = 1;
1100  u32_c = 0xFFFD;
1101  }
1102 
1103  n -= mblen;
1104 
1105  if (m_do_strlist && m_mode == MODE_RENDER)
1106  {
1107  if (u32_c == 10)
1108  {
1109  // Finish previous string in m_strlist before processing
1110  // the newline character
1111  fs.set_y (m_line_yoffset + m_yoffset);
1112  fs.set_color (m_color);
1113 
1114  std::string s = str.substr (ibegin, icurr - ibegin);
1115  if (! s.empty ())
1116  {
1117  fs.set_string (s);
1118  fs.set_y (m_line_yoffset + m_yoffset);
1119  fs.set_xdata (xdata);
1120  fs.set_family (fname);
1121  m_strlist.push_back (fs);
1122  }
1123  }
1124  else
1125  xdata.push_back (m_xoffset);
1126  }
1127 
1128  glyph_index = process_character (u32_c, previous, sub_name);
1129 
1130  if (m_do_strlist && m_mode == MODE_RENDER && ! sub_name.empty ())
1131  {
1132  // Add substitution font to the family name stack
1133  std::string tmp_family = fs.get_family ();
1134 
1135  if (tmp_family.find (sub_name) == std::string::npos)
1136  {
1137  if (sub_name.find (" ") != std::string::npos)
1138  sub_name = "'" + sub_name + "'";
1139 
1140  fs.set_family (tmp_family + ", " + sub_name);
1141  }
1142  }
1143 
1144  if (u32_c == 10)
1145  {
1146  previous = 0;
1147 
1148  if (m_do_strlist && m_mode == MODE_RENDER)
1149  {
1150  // Start a new string in m_strlist
1151  ibegin = icurr+1;
1152  xdata.clear ();
1153  fs = text_renderer::string (str.substr (ibegin), m_font,
1154  m_line_xoffset, m_yoffset);
1155  }
1156  }
1157  else
1158  previous = glyph_index;
1159 
1160  icurr += mblen;
1161  }
1162 
1163  if (m_do_strlist && m_mode == MODE_RENDER
1164  && ! fs.get_string ().empty ())
1165  {
1166  fs.set_y (m_line_yoffset + m_yoffset);
1167  fs.set_color (m_color);
1168  fs.set_xdata (xdata);
1169  m_strlist.push_back (fs);
1170  }
1171  }
1172 }
1173 
1174 void
1175 ft_text_renderer::visit (text_element_list& e)
1176 {
1177  // Save and restore (after processing the list) the current font and color.
1178 
1179  ft_font saved_font (m_font);
1180  uint8NDArray saved_color (m_color);
1181 
1183 
1184  m_font = saved_font;
1185  m_color = saved_color;
1186 }
1187 
1188 void
1189 ft_text_renderer::visit (text_element_subscript& e)
1190 {
1191  ft_font saved_font (m_font);
1192  int saved_line_yoffset = m_line_yoffset;
1193  int saved_yoffset = m_yoffset;
1194 
1195  double sz = m_font.get_size ();
1196 
1197  // Reducing font size by 70% produces decent results.
1198  set_font (m_font.get_name (), m_font.get_weight (), m_font.get_angle (),
1199  std::max (5.0, sz * 0.7));
1200 
1201  if (m_font.is_valid ())
1202  {
1203  // Shifting the baseline by 15% of the font size gives decent results.
1204  m_yoffset -= std::ceil (sz * 0.15);
1205 
1206  if (m_mode == MODE_BBOX)
1207  update_line_bbox ();
1208  }
1209 
1211 
1212  m_font = saved_font;
1213  // If line_yoffset changed, this means we moved to a new line; hence yoffset
1214  // cannot be restored, because the saved value is not relevant anymore.
1215  if (m_line_yoffset == saved_line_yoffset)
1216  m_yoffset = saved_yoffset;
1217 }
1218 
1219 void
1220 ft_text_renderer::visit (text_element_superscript& e)
1221 {
1222  ft_font saved_font (m_font);
1223  int saved_line_yoffset = m_line_yoffset;
1224  int saved_yoffset = m_yoffset;
1225 
1226  double sz = m_font.get_size ();
1227 
1228  // Reducing font size by 70% produces decent results.
1229  set_font (m_font.get_name (), m_font.get_weight (), m_font.get_angle (),
1230  std::max (5.0, sz * 0.7));
1231 
1232  if (saved_font.is_valid ())
1233  {
1234  // Shifting the baseline by 40% of the font size gives decent results.
1235  m_yoffset += std::ceil (sz * 0.4);
1236 
1237  if (m_mode == MODE_BBOX)
1238  update_line_bbox ();
1239  }
1240 
1242 
1243  m_font = saved_font;
1244  // If line_yoffset changed, this means we moved to a new line; hence yoffset
1245  // cannot be restored, because the saved value is not relevant anymore.
1246  if (m_line_yoffset == saved_line_yoffset)
1247  m_yoffset = saved_yoffset;
1248 }
1249 
1250 void
1251 ft_text_renderer::visit (text_element_color& e)
1252 {
1253  if (m_mode == MODE_RENDER)
1254  set_color (e.get_color ());
1255 }
1256 
1257 void
1258 ft_text_renderer::visit (text_element_fontsize& e)
1259 {
1260  double sz = e.get_fontsize ();
1261 
1262  // FIXME: Matlab documentation says that the font size is expressed
1263  // in the text object FontUnit.
1264 
1265  set_font (m_font.get_name (), m_font.get_weight (),
1266  m_font.get_angle (), sz);
1267 
1268  if (m_mode == MODE_BBOX)
1269  update_line_bbox ();
1270 }
1271 
1272 void
1273 ft_text_renderer::visit (text_element_fontname& e)
1274 {
1275  set_font (e.get_fontname (), m_font.get_weight (), m_font.get_angle (),
1276  m_font.get_size ());
1277 
1278  if (m_mode == MODE_BBOX)
1279  update_line_bbox ();
1280 }
1281 
1282 void
1283 ft_text_renderer::visit (text_element_fontstyle& e)
1284 {
1285  switch (e.get_fontstyle ())
1286  {
1288  set_font (m_font.get_name (), "normal", "normal", m_font.get_size ());
1289  break;
1290 
1292  set_font (m_font.get_name (), "bold", "normal", m_font.get_size ());
1293  break;
1294 
1296  set_font (m_font.get_name (), "normal", "italic", m_font.get_size ());
1297  break;
1298 
1300  set_font (m_font.get_name (), "normal", "oblique", m_font.get_size ());
1301  break;
1302  }
1303 
1304  if (m_mode == MODE_BBOX)
1305  update_line_bbox ();
1306 }
1307 
1308 void
1309 ft_text_renderer::visit (text_element_symbol& e)
1310 {
1311  uint32_t code = e.get_symbol_code ();
1312 
1313  std::vector<double> xdata (1, m_xoffset);
1314  text_renderer::string fs ("-", m_font, m_xoffset, m_yoffset);
1315 
1316  if (code != text_element_symbol::invalid_code && m_font.is_valid ())
1317  {
1318  std::string sub_name;
1319 
1320  process_character (code, 0, sub_name);
1321 
1322  if (m_do_strlist && m_mode == MODE_RENDER)
1323  {
1324  if (! sub_name.empty ())
1325  {
1326  // Add substitution font to the family name
1327  std::string tmp_family = fs.get_family ();
1328 
1329  if (tmp_family.find (sub_name) == std::string::npos)
1330  {
1331  if (sub_name.find (" ") != std::string::npos)
1332  sub_name = "'" + sub_name + "'";
1333 
1334  fs.set_family (tmp_family + ", " + sub_name);
1335  }
1336  }
1337 
1338  fs.set_code (code);
1339  fs.set_xdata (xdata);
1340  }
1341  }
1342  else if (m_font.is_valid ())
1343  ::warning ("ignoring unknown symbol: %d", e.get_symbol ());
1344 
1345  if (m_do_strlist && m_mode == MODE_RENDER && fs.get_code ())
1346  {
1347  fs.set_y (m_line_yoffset + m_yoffset);
1348  fs.set_color (m_color);
1349  fs.set_family (m_font.get_face ()->family_name);
1350  m_strlist.push_back (fs);
1351  }
1352 }
1353 
1354 void
1355 ft_text_renderer::visit (text_element_combined& e)
1356 {
1357  int saved_xoffset = m_xoffset;
1358  int max_xoffset = m_xoffset;
1359 
1360  for (auto *txt_elt : e)
1361  {
1362  m_xoffset = saved_xoffset;
1363  txt_elt->accept (*this);
1364  max_xoffset = math::max (m_xoffset, max_xoffset);
1365  }
1366 
1367  m_xoffset = max_xoffset;
1368 }
1369 
1370 void
1371 ft_text_renderer::reset ()
1372 {
1373  set_mode (MODE_BBOX);
1374  set_color (Matrix (1, 3, 0.0));
1375  m_strlist = std::list<text_renderer::string> ();
1376 }
1377 
1378 void
1379 ft_text_renderer::set_color (const Matrix& c)
1380 {
1381  if (c.numel () == 3)
1382  {
1383  m_color(0) = static_cast<uint8_t> (c(0)*255);
1384  m_color(1) = static_cast<uint8_t> (c(1)*255);
1385  m_color(2) = static_cast<uint8_t> (c(2)*255);
1386  }
1387  else
1388  ::warning ("ft_text_renderer::set_color: invalid color");
1389 }
1390 
1392 ft_text_renderer::render (text_element *elt, Matrix& box, int rotation)
1393 {
1394  set_mode (MODE_BBOX);
1395  elt->accept (*this);
1396  compute_bbox ();
1397  box = m_bbox;
1398 
1399  set_mode (MODE_RENDER);
1400 
1401  if (m_pixels.numel () > 0)
1402  {
1403  elt->accept (*this);
1404 
1405  rotate_pixels (m_pixels, rotation);
1406  }
1407 
1408  return m_pixels;
1409 }
1410 
1411 // Note:
1412 // x-extent accurately measures width of glyphs.
1413 // y-extent is overly large because it is measured from baseline-to-baseline.
1414 // Calling routines, such as ylabel, may need to account for this mismatch.
1415 
1416 Matrix
1417 ft_text_renderer::get_extent (text_element *elt, double rotation)
1418 {
1419  set_mode (MODE_BBOX);
1420  elt->accept (*this);
1421  compute_bbox ();
1422 
1423  Matrix extent (1, 2, 0.0);
1424 
1425  switch (rotation_to_mode (rotation))
1426  {
1427  case ROTATION_0:
1428  case ROTATION_180:
1429  extent(0) = m_bbox(2);
1430  extent(1) = m_bbox(3);
1431  break;
1432 
1433  case ROTATION_90:
1434  case ROTATION_270:
1435  extent(0) = m_bbox(3);
1436  extent(1) = m_bbox(2);
1437  }
1438 
1439  return extent;
1440 }
1441 
1442 Matrix
1443 ft_text_renderer::get_extent (const std::string& txt, double rotation,
1444  const caseless_str& interpreter)
1445 {
1447  Matrix extent = get_extent (elt, rotation);
1448  delete elt;
1449 
1450  return extent;
1451 }
1452 
1453 void
1454 ft_text_renderer::text_to_pixels (const std::string& txt,
1455  uint8NDArray& pxls, Matrix& box,
1456  int _halign, int valign, double rotation,
1457  const caseless_str& interpreter,
1458  bool handle_rotation)
1459 {
1460  int rot_mode = rotation_to_mode (rotation);
1461 
1462  m_halign = _halign;
1463 
1465  pxls = render (elt, box, rot_mode);
1466  delete elt;
1467 
1468  if (pxls.isempty ())
1469  return; // nothing to render
1470 
1471  // Move X0 and Y0 depending on alignments and eventually swap all values
1472  // for text rotated 90° 180° or 270°
1473  fix_bbox_anchor (box, m_halign, valign, rot_mode, handle_rotation);
1474 }
1475 
1476 ft_text_renderer::ft_font::ft_font (const ft_font& ft)
1477  : text_renderer::font (ft), m_face (nullptr)
1478 {
1479 #if defined (HAVE_FT_REFERENCE_FACE)
1480  FT_Face ft_face = ft.get_face ();
1481 
1482  if (ft_face && FT_Reference_Face (ft_face) == 0)
1483  m_face = ft_face;
1484 #endif
1485 }
1486 
1487 ft_text_renderer::ft_font&
1488 ft_text_renderer::ft_font::operator = (const ft_font& ft)
1489 {
1490  if (&ft != this)
1491  {
1493 
1494  if (m_face)
1495  {
1496  FT_Done_Face (m_face);
1497  m_face = nullptr;
1498  }
1499 
1500 #if defined (HAVE_FT_REFERENCE_FACE)
1501  FT_Face ft_face = ft.get_face ();
1502 
1503  if (ft_face && FT_Reference_Face (ft_face) == 0)
1504  m_face = ft_face;
1505 #endif
1506  }
1507 
1508  return *this;
1509 }
1510 
1511 FT_Face
1512 ft_text_renderer::ft_font::get_face () const
1513 {
1514  if (! m_face && ! m_name.empty ())
1515  {
1516  m_face = ft_manager::get_font (m_name, m_weight, m_angle, m_size);
1517 
1518  if (m_face)
1519  {
1520  if (FT_Set_Char_Size (m_face, 0, m_size*64, 0, 0))
1521  ::warning ("ft_text_renderer: unable to set font size to %g", m_size);
1522  }
1523  else
1524  ::warning ("ft_text_renderer: unable to load appropriate font");
1525  }
1526 
1527  return m_face;
1528 }
1529 
1530 OCTAVE_END_NAMESPACE(octave)
1531 
1532 #endif
1533 
1535 
1538 {
1539 #if defined (HAVE_FREETYPE)
1540  return new ft_text_renderer ();
1541 #else
1542  return 0;
1543 #endif
1544 }
1545 
1546 OCTAVE_END_NAMESPACE(octave)
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:230
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:207
bool isempty() const
Size of the specified dimension.
Definition: Array.h:651
octave_idx_type numel() const
Number of elements in the array.
Definition: Array.h:414
Definition: Cell.h:43
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
void assign(const std::string &k, const Cell &val)
Definition: oct-map.h:344
bool isempty() const
Definition: oct-map.h:370
static void add(fptr f)
const std::string & get_fontname() const
Definition: text-engine.h:255
double get_fontsize() const
Definition: text-engine.h:277
fontstyle get_fontstyle() const
Definition: text-engine.h:233
std::string string_value() const
Definition: text-engine.h:78
uint32_t get_symbol_code() const
Definition: text-engine.cc:36
int get_symbol() const
Definition: text-engine.h:102
virtual void accept(text_processor &p)=0
virtual text_element * parse(const std::string &s)=0
virtual void visit(text_element_string &)
Definition: text-engine.h:337
font & operator=(const font &ft)
Definition: text-renderer.h:98
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string oct_fonts_dir()
void warning(const char *fmt,...)
Definition: error.cc:1063
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:1078
void() error(const char *fmt,...)
Definition: error.cc:988
std::string dir_sep_str()
base_text_renderer * make_ft_text_renderer()
double round(double x)
Definition: lo-mappers.h:136
std::complex< T > floor(const std::complex< T > &x)
Definition: lo-mappers.h:130
std::complex< T > ceil(const std::complex< T > &x)
Definition: lo-mappers.h:103
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
std::string get_ASCII_filename(const std::string &orig_file_name, const bool allow_locale)
Definition: lo-sysdep.cc:814
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761
T * r
Definition: mx-inlines.cc:781
bool is_opaque(const FT_GlyphSlot &glyph, const int x, const int y)
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:36
int octave_u8_strmbtouc_wrapper(uint32_t *puc, const uint8_t *src)