annotate libinterp/corefcn/ft-text-renderer.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents 796f54d4ddbf
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30390
diff changeset
3 // Copyright (C) 2009-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21568
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21209
diff changeset
27 # include "config.h"
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
28 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
29
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
30 #include "base-text-renderer.h"
23462
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23457
diff changeset
31 #include "ft-text-renderer.h"
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
32
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
33 #if defined (HAVE_FREETYPE)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
34
21334
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
35 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
24444
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24126
diff changeset
36 # pragma GCC diagnostic push
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24126
diff changeset
37 # pragma GCC diagnostic ignored "-Wold-style-cast"
21334
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
38 #endif
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
39
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
40 #include <ft2build.h>
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
41 #include FT_FREETYPE_H
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
42 #include FT_GLYPH_H
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
43
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
44 #if defined (HAVE_FONTCONFIG)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21102
diff changeset
45 # include <fontconfig/fontconfig.h>
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
46 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
47
21334
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
48 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
24444
53ca76c5cc8d maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents: 24126
diff changeset
49 # pragma GCC diagnostic pop
21334
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
50 #endif
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
51
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
52 #include <clocale>
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
53 #include <cwchar>
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
54 #include <map>
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
55 #include <utility>
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
56
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
57 #include "singleton-cleanup.h"
25362
def1b446ba64 Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25336
diff changeset
58 #include "unistr-wrappers.h"
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
59
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
60 #include "defaults.h"
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
61 #include "error.h"
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
62 #include "file-ops.h"
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
63 #include "oct-env.h"
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
64 #include "pr-output.h"
29489
ee66869c30d6 Fix loading fonts from path with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29470
diff changeset
65 #include "sysdep.h"
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
66 #include "text-renderer.h"
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
67
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
68 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
69
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
70 // FIXME: maybe issue at most one warning per glyph/font/size/weight
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
71 // combination.
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
72
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
73 static void
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
74 warn_missing_glyph (FT_ULong c)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
75 {
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
76 warning_with_id ("Octave:missing-glyph",
26152
b68c41cb0f99 Silence compiler warning about incorrect format specifier (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25460
diff changeset
77 "text_renderer: skipping missing glyph for character '%lx'", c);
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
78 }
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
79
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
80 static void
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
81 warn_glyph_render (FT_ULong c)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
82 {
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
83 warning_with_id ("Octave:glyph-render",
26152
b68c41cb0f99 Silence compiler warning about incorrect format specifier (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25460
diff changeset
84 "text_renderer: unable to render glyph for character '%lx'", c);
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
85 }
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
86
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
87 #if defined (_MSC_VER)
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
88 // FIXME: is this really needed?
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
89 //
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
90 // This is just a trick to avoid multiple symbol definitions.
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
91 // PermMatrix.h contains a dllexport'ed Array<octave_idx_type>
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
92 // that will cause MSVC not to generate a new instantiation and
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
93 // use the imported one instead.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
94 # include "PermMatrix.h"
13730
a2c74b5c02de [MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13317
diff changeset
95 #endif
a2c74b5c02de [MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13317
diff changeset
96
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
97 // Forward declaration
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
98 static void ft_face_destroyed (void *object);
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
99
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
100 class
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
101 ft_manager
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
102 {
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
103 private:
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
104
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
105 ft_manager (void)
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
106 : m_library (), m_freetype_initialized (false),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
107 m_fontconfig_initialized (false)
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
108 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
109 if (FT_Init_FreeType (&m_library))
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
110 error ("unable to initialize FreeType library");
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
111 else
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
112 m_freetype_initialized = true;
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
113
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
114 #if defined (HAVE_FONTCONFIG)
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
115 if (! FcInit ())
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
116 error ("unable to initialize fontconfig library");
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
117 else
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
118 m_fontconfig_initialized = true;
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
119 #endif
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
120 }
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
121
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
122 public:
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
123
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
124 // No copying!
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
125
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
126 ft_manager (const ft_manager&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
127
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
128 ft_manager& operator = (const ft_manager&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
129
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
130 private:
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
131
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
132 ~ft_manager (void)
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
133 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
134 if (m_freetype_initialized)
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
135 FT_Done_FreeType (m_library);
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
136
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
137 #if defined (HAVE_FONTCONFIG)
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
138 // FIXME: Skip the call to FcFini because it can trigger the assertion
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
139 //
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
140 // octave: fccache.c:507: FcCacheFini: Assertion 'fcCacheChains[i] == ((void *)0)' failed.
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
141 //
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
142 // if (m_fontconfig_initialized)
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
143 // FcFini ();
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
144 #endif
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
145 }
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
146
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
147 public:
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
148
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
149 static bool instance_ok (void)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
150 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
151 bool retval = true;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
152
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
153 if (! m_instance)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
154 {
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
155 m_instance = new ft_manager ();
26369
0249ba4c9589 Fix static analyzer detected V668 issues (bug #55347).
Andreas Weber <octave@josoansi.de>
parents: 26340
diff changeset
156 singleton_cleanup_list::add (cleanup_instance);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
157 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
158
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
159 return retval;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
160 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
161
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
162 static void cleanup_instance (void)
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
163 { delete m_instance; m_instance = nullptr; }
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
164
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
165 static FT_Face get_font (const std::string& name, const std::string& weight,
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
166 const std::string& angle, double size,
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
167 FT_ULong c = 0)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
168 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
169 return (instance_ok ()
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
170 ? m_instance->do_get_font (name, weight, angle, size, c)
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
171 : nullptr);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
172 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
173
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
174 static octave_map get_system_fonts (void)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
175 {
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
176 return (instance_ok ()
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
177 ? m_instance->do_get_system_fonts ()
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
178 : octave_map ());
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
179 }
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
180
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
181 static void font_destroyed (FT_Face face)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
182 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
183 if (instance_ok ())
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
184 m_instance->do_font_destroyed (face);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
185 }
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
186
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
187 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
188
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
189 typedef std::pair<std::string, double> ft_key;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
190 typedef std::map<ft_key, FT_Face> ft_cache;
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
191
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
192 static octave_map do_get_system_fonts (void)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
193 {
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
194 static octave_map font_map;
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
195
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
196 if (font_map.isempty ())
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
197 {
28483
98889de398dd * ft-text-renderer.cc: Allow build to succeed if HAVE_FONTCONFIG is undefined.
John W. Eaton <jwe@octave.org>
parents: 28305
diff changeset
198 #if defined (HAVE_FONTCONFIG)
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
199 FcConfig *config = FcConfigGetCurrent();
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
200 FcPattern *pat = FcPatternCreate ();
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
201 FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_SLANT, FC_WEIGHT,
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
202 FC_CHARSET, nullptr);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
203 FcFontSet *fs = FcFontList (config, pat, os);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
204
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
205 if (fs->nfont > 0)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
206 {
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
207 // Mark fonts that have at least all printable ASCII chars
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
208 FcCharSet *minimal_charset = FcCharSetCreate ();
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
209 for (int i = 32; i < 127; i++)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
210 FcCharSetAddChar (minimal_charset, static_cast<FcChar32> (i));
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
211
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
212 string_vector fields (4);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
213 fields(0) = "family";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
214 fields(1) = "angle";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
215 fields(2) = "weight";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
216 fields(3) = "suitable";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
217
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
218 dim_vector dv (1, fs->nfont);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
219 Cell families (dv);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
220 Cell angles (dv);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
221 Cell weights (dv);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
222 Cell suitable (dv);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
223
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
224 unsigned char *family;
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
225 int val;
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
226 for (int i = 0; fs && i < fs->nfont; i++)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
227 {
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
228 FcPattern *font = fs->fonts[i];
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
229 if (FcPatternGetString (font, FC_FAMILY, 0, &family)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
230 == FcResultMatch)
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30119
diff changeset
231 families(i) = std::string (reinterpret_cast<char *> (family));
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
232 else
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
233 families(i) = "unknown";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
234
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
235 if (FcPatternGetInteger (font, FC_SLANT, 0, &val)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
236 == FcResultMatch)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
237 angles(i) = (val == FC_SLANT_ITALIC
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
238 || val == FC_SLANT_OBLIQUE)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
239 ? "italic" : "normal";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
240 else
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
241 angles(i) = "unknown";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
242
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
243 if (FcPatternGetInteger (font, FC_WEIGHT, 0, &val)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
244 == FcResultMatch)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
245 weights(i) = (val == FC_WEIGHT_BOLD
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
246 || val == FC_WEIGHT_DEMIBOLD)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
247 ? "bold" : "normal";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
248 else
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
249 weights(i) = "unknown";
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
250
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
251 FcCharSet *cset;
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
252 if (FcPatternGetCharSet (font, FC_CHARSET, 0, &cset)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
253 == FcResultMatch)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
254 suitable(i) = (FcCharSetIsSubset (minimal_charset, cset)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
255 ? true : false);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
256 else
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
257 suitable(i) = false;
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
258 }
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
259
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
260 font_map = octave_map (dv, fields);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
261
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
262 font_map.assign ("family", families);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
263 font_map.assign ("angle", angles);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
264 font_map.assign ("weight", weights);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
265 font_map.assign ("suitable", suitable);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
266
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
267 if (fs)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
268 FcFontSetDestroy (fs);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
269 }
28483
98889de398dd * ft-text-renderer.cc: Allow build to succeed if HAVE_FONTCONFIG is undefined.
John W. Eaton <jwe@octave.org>
parents: 28305
diff changeset
270 #endif
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
271 }
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
272
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
273 return font_map;
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
274 }
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
275
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
276 FT_Face do_get_font (const std::string& name, const std::string& weight,
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
277 const std::string& angle, double size,
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
278 FT_ULong search_code_point)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
279 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
280 FT_Face retval = nullptr;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
281
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
282 #if defined (HAVE_FT_REFERENCE_FACE)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
283 // Look first into the font cache, then use fontconfig. If the font
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
284 // is present in the cache, simply add a reference and return it.
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
285
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
286 ft_key key (name + ':' + weight + ':' + angle + ':'
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
287 + std::to_string (search_code_point), size);
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
288 ft_cache::const_iterator it = m_cache.find (key);
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
289
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
290 if (it != m_cache.end ())
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
291 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
292 FT_Reference_Face (it->second);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
293 return it->second;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
294 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
295 #endif
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
296
24899
1a46d174a483 include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents: 24722
diff changeset
297 static std::string fonts_dir;
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
298
24899
1a46d174a483 include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents: 24722
diff changeset
299 if (fonts_dir.empty ())
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
300 {
24899
1a46d174a483 include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents: 24722
diff changeset
301 fonts_dir = sys::env::getenv ("OCTAVE_FONTS_DIR");
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
302
24899
1a46d174a483 include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents: 24722
diff changeset
303 if (fonts_dir.empty ())
24900
00d42b86d0a5 configure: new option --with-system-freefont to use system fonts (bug #53348)
Mike Miller <mtmiller@octave.org>
parents: 24899
diff changeset
304 #if defined (SYSTEM_FREEFONT_DIR)
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
305 fonts_dir = SYSTEM_FREEFONT_DIR;
24900
00d42b86d0a5 configure: new option --with-system-freefont to use system fonts (bug #53348)
Mike Miller <mtmiller@octave.org>
parents: 24899
diff changeset
306 #else
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
307 fonts_dir = config::oct_fonts_dir ();
24900
00d42b86d0a5 configure: new option --with-system-freefont to use system fonts (bug #53348)
Mike Miller <mtmiller@octave.org>
parents: 24899
diff changeset
308 #endif
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
309 }
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
310
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
311
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
312 // Default font file
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
313 std::string file;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
314
24899
1a46d174a483 include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents: 24722
diff changeset
315 if (! fonts_dir.empty ())
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
316 {
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
317 file = fonts_dir + sys::file_ops::dir_sep_str () + "FreeSans";
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
318
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
319 if (weight == "bold")
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
320 file += "Bold";
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
321
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
322 if (angle == "italic" || angle == "oblique")
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
323 file += "Oblique";
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
324
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
325 file += ".otf";
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
326 }
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
327
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
328 #if defined (HAVE_FONTCONFIG)
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
329 if ((search_code_point != 0 || name != "*") && m_fontconfig_initialized)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
330 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
331 int fc_weight, fc_angle;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
332
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
333 if (weight == "bold")
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
334 fc_weight = FC_WEIGHT_BOLD;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
335 else
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
336 fc_weight = FC_WEIGHT_NORMAL;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
337
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
338 if (angle == "italic")
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
339 fc_angle = FC_SLANT_ITALIC;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
340 else if (angle == "oblique")
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
341 fc_angle = FC_SLANT_OBLIQUE;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
342 else
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
343 fc_angle = FC_SLANT_ROMAN;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
344
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
345 FcPattern *pat = FcPatternCreate ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
346
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
347 FcPatternAddString (pat, FC_FAMILY,
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
348 (reinterpret_cast<const FcChar8 *>
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
349 (name.c_str ())));
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
350
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
351 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
352 FcPatternAddInteger (pat, FC_SLANT, fc_angle);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
353 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
354
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
355 if (search_code_point > 0)
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
356 {
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
357 FcCharSet *minimal_charset = FcCharSetCreate ();
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
358 FcCharSetAddChar (minimal_charset,
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
359 static_cast<FcChar32> (search_code_point));
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
360 FcPatternAddCharSet (pat, FC_CHARSET, minimal_charset);
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
361 }
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
362
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
363 if (FcConfigSubstitute (nullptr, pat, FcMatchPattern))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
364 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
365 FcResult res;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
366 FcPattern *match;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
367
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
368 FcDefaultSubstitute (pat);
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
369
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
370 match = FcFontMatch (nullptr, pat, &res);
9833
637fa784d102 Allow more font matches
godfrey@isl.Stanford.EDU
parents: 9619
diff changeset
371
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
372 // FIXME: originally, this test also required that
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
373 // res != FcResultNoMatch. Is that really needed?
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
374 if (match)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
375 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
376 unsigned char *tmp;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
377
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
378 FcPatternGetString (match, FC_FILE, 0, &tmp);
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
379 file = reinterpret_cast<char *> (tmp);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
380 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
381 else
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
382 ::warning ("could not match any font: %s-%s-%s-%g, using default font",
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
383 name.c_str (), weight.c_str (), angle.c_str (),
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
384 size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
385
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
386 if (match)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
387 FcPatternDestroy (match);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
388 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
389
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
390 FcPatternDestroy (pat);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
391 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
392 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
393
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
394 if (file.empty ())
24126
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
395 ::warning ("unable to find default font files");
2390079a8aed Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24076
diff changeset
396 else
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
397 {
29489
ee66869c30d6 Fix loading fonts from path with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29470
diff changeset
398 std::string ascii_file = sys::get_ASCII_filename (file);
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
399
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
400 if (FT_New_Face (m_library, ascii_file.c_str (), 0, &retval))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
401 ::warning ("ft_manager: unable to load font: %s", file.c_str ());
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
402 #if defined (HAVE_FT_REFERENCE_FACE)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
403 else
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
404 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
405 // Install a finalizer to notify ft_manager that the font is
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
406 // being destroyed. The class ft_manager only keeps weak
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
407 // references to font objects.
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
408
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
409 retval->generic.data = new ft_key (key);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
410 retval->generic.finalizer = ft_face_destroyed;
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
411
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
412 // Insert loaded font into the cache.
28206
11d66485fc19 Correctly cache fonts in ft_manager (bug #58150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27923
diff changeset
413 if (FT_Reference_Face (retval) == 0)
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
414 m_cache[key] = retval;
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
415 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
416 #endif
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
417 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
418
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
419 return retval;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
420 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
421
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
422 void do_font_destroyed (FT_Face face)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
423 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
424 if (face->generic.data)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
425 {
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
426 ft_key *pkey = reinterpret_cast<ft_key *> (face->generic.data);
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
427
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
428 m_cache.erase (*pkey);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
429 delete pkey;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
430 face->generic.data = nullptr;
28206
11d66485fc19 Correctly cache fonts in ft_manager (bug #58150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27923
diff changeset
431 FT_Done_Face (face);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
432 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
433 }
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
434
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
435 //--------
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
436
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
437 static ft_manager *m_instance;
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
438
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
439 // Cache the fonts loaded by FreeType. This cache only contains
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
440 // weak references to the fonts, strong references are only present
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
441 // in class text_renderer.
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
442 ft_cache m_cache;
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
443
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
444 FT_Library m_library;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
445 bool m_freetype_initialized;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
446 bool m_fontconfig_initialized;
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
447 };
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
448
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
449 ft_manager *ft_manager::m_instance = nullptr;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
450
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
451 static void
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
452 ft_face_destroyed (void *object)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
453 {
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
454 ft_manager::font_destroyed (reinterpret_cast<FT_Face> (object));
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
455 }
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
456
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
457 class
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
458 OCTINTERP_API
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
459 ft_text_renderer : public base_text_renderer
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
460 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
461 public:
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
462
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
463 enum
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
464 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
465 MODE_BBOX = 0,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
466 MODE_RENDER = 1
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
467 };
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
468
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
469 public:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
470
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
471 ft_text_renderer (void)
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
472 : base_text_renderer (), m_font (), m_bbox (1, 4, 0.0), m_halign (0),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
473 m_xoffset (0), m_line_yoffset (0), m_yoffset (0), m_mode (MODE_BBOX),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
474 m_color (dim_vector (1, 3), 0), m_do_strlist (false), m_strlist (),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
475 m_line_xoffset (0), m_ymin (0), m_ymax (0), m_deltax (0),
26858
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
476 m_max_fontsize (0), m_antialias (true)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
477 { }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
478
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
479 // No copying!
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
480
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
481 ft_text_renderer (const ft_text_renderer&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
482
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
483 ft_text_renderer& operator = (const ft_text_renderer&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
484
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
485 ~ft_text_renderer (void) = default;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
486
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
487 void visit (text_element_string& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
488
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
489 void visit (text_element_list& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
490
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
491 void visit (text_element_subscript& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
492
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
493 void visit (text_element_superscript& e);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
494
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
495 void visit (text_element_color& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
496
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
497 void visit (text_element_fontsize& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
498
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
499 void visit (text_element_fontname& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
500
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
501 void visit (text_element_fontstyle& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
502
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
503 void visit (text_element_symbol& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
504
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
505 void visit (text_element_combined& e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
506
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
507 void reset (void);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
508
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
509 uint8NDArray get_pixels (void) const { return m_pixels; }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
510
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
511 Matrix get_boundingbox (void) const { return m_bbox; }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
512
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
513 uint8NDArray render (text_element *elt, Matrix& box,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
514 int rotation = ROTATION_0);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
515
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
516 Matrix get_extent (text_element *elt, double rotation = 0.0);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
517 Matrix get_extent (const std::string& txt, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
518 const caseless_str& interpreter);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
519
26858
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
520 void set_anti_aliasing (bool val) { m_antialias = val; };
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
521
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
522 void set_font (const std::string& name, const std::string& weight,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
523 const std::string& angle, double size);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
524
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
525 octave_map get_system_fonts (void);
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
526
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
527 void set_color (const Matrix& c);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
528
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
529 void set_mode (int m);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
530
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
531 void text_to_pixels (const std::string& txt,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
532 uint8NDArray& pxls, Matrix& bbox,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
533 int halign, int valign, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
534 const caseless_str& interpreter,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
535 bool handle_rotation);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
536
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
537 private:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
538
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
539 // Class to hold information about fonts and a strong
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
540 // reference to the font objects loaded by FreeType.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
541
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
542 class ft_font : public text_renderer::font
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
543 {
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
544 public:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
545
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
546 ft_font (void)
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
547 : text_renderer::font (), m_face (nullptr) { }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
548
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
549 ft_font (const std::string& nm, const std::string& wt,
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
550 const std::string& ang, double sz, FT_Face f = nullptr)
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
551 : text_renderer::font (nm, wt, ang, sz), m_face (f)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
552 { }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
553
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
554 ft_font (const ft_font& ft);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
555
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
556 ~ft_font (void)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
557 {
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
558 if (m_face)
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
559 FT_Done_Face (m_face);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
560 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
561
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
562 ft_font& operator = (const ft_font& ft);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
563
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
564 bool is_valid (void) const { return get_face (); }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
565
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
566 FT_Face get_face (void) const;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
567
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
568 private:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
569
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
570 mutable FT_Face m_face;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
571 };
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
572
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
573 void push_new_line (void);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
574
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
575 void update_line_bbox (void);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
576
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
577 void compute_bbox (void);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
578
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
579 int compute_line_xoffset (const Matrix& lb) const;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
580
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
581 FT_UInt process_character (FT_ULong code, FT_UInt previous,
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
582 std::string& sub_font);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
583
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
584 public:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
585
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
586 void text_to_strlist (const std::string& txt,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
587 std::list<text_renderer::string>& lst, Matrix& bbox,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
588 int halign, int valign, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
589 const caseless_str& interp);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
590
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
591 private:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
592
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
593 // The current font used by the renderer.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
594 ft_font m_font;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
595
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
596 // Used to stored the bounding box corresponding to the rendered text.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
597 // The bounding box has the form [x, y, w, h] where x and y represent the
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
598 // coordinates of the bottom left corner relative to the anchor point of
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
599 // the text (== start of text on the baseline). Due to font descent or
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
600 // multiple lines, the value y is usually negative.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
601 Matrix m_bbox;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
602
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
603 // Used to stored the rendered text. It's a 3D matrix with size MxNx4
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
604 // where M and N are the width and height of the bounding box.
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
605 uint8NDArray m_pixels;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
606
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
607 // Used to store the bounding box of each line. This is used to layout
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
608 // multiline text properly.
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
609 std::list<Matrix> m_line_bbox;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
610
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
611 // The current horizontal alignment. This is used to align multi-line text.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
612 int m_halign;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
613
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
614 // The X offset for the next glyph.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
615 int m_xoffset;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
616
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
617 // The Y offset of the baseline for the current line.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
618 int m_line_yoffset;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
619
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
620 // The Y offset of the baseline for the next glyph. The offset is relative
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
621 // to line_yoffset. The total Y offset is computed with:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
622 // line_yoffset + yoffset.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
623 int m_yoffset;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
624
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
625 // The current mode of the rendering process (box computing or rendering).
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
626 int m_mode;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
627
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
628 // The base color of the rendered text.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
629 uint8NDArray m_color;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
630
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
631 // A list of parsed strings to be used for printing.
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
632 bool m_do_strlist;
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
633 std::list<text_renderer::string> m_strlist;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
634
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
635 // The X offset of the baseline for the current line.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
636 int m_line_xoffset;
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26573
diff changeset
637
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
638 // Min and max y coordinates of all glyphs in a line.
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
639 FT_Pos m_ymin;
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
640 FT_Pos m_ymax;
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
641
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
642 // Difference between the advance and the actual extent of the latest glyph
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
643 FT_Pos m_deltax;
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
644
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
645 // Used for computing the distance between lines.
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
646 double m_max_fontsize;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
647
26858
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
648 // Anti-aliasing.
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
649 bool m_antialias;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
650
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
651 };
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
652
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
653 void
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
654 ft_text_renderer::set_font (const std::string& name,
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
655 const std::string& weight,
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
656 const std::string& angle, double size)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
657 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
658 // FIXME: take "fontunits" into account
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
659 m_font = ft_font (name, weight, angle, size, nullptr);
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
660 }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
661
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
662 octave_map
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
663 ft_text_renderer::get_system_fonts (void)
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
664 {
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
665 return ft_manager::get_system_fonts ();
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
666 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
667
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
668 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
669 ft_text_renderer::push_new_line (void)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
670 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
671 switch (m_mode)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
672 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
673 case MODE_BBOX:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
674 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
675 // Create a new bbox entry based on the current font.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
676
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
677 FT_Face face = m_font.get_face ();
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
678
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
679 if (face)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
680 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
681 Matrix bb (1, 5, 0.0);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
682
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
683 m_line_bbox.push_back (bb);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
684
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
685 m_xoffset = m_yoffset = 0;
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
686 m_ymin = m_ymax = m_deltax = 0;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
687 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
688 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
689 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
690
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
691 case MODE_RENDER:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
692 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
693 // Move to the next line bbox, adjust xoffset based on alignment
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
694 // and yoffset based on the old and new line bbox.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
695
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
696 Matrix old_bbox = m_line_bbox.front ();
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
697 m_line_bbox.pop_front ();
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
698 Matrix new_bbox = m_line_bbox.front ();
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
699
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
700 m_xoffset = m_line_xoffset = compute_line_xoffset (new_bbox);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
701 m_line_yoffset -= (-old_bbox(1) + math::round (0.4 * m_max_fontsize)
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
702 + (new_bbox(3) + new_bbox(1)));
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
703 m_yoffset = 0;
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
704 m_ymin = m_ymax = m_deltax = 0;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
705 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
706 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
707 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
708 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
709
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
710 int
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
711 ft_text_renderer::compute_line_xoffset (const Matrix& lb) const
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
712 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
713 if (! m_bbox.isempty ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
714 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
715 switch (m_halign)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
716 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
717 case 0:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
718 return 0;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
719 case 1:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
720 return (m_bbox(2) - lb(2)) / 2;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
721 case 2:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
722 return (m_bbox(2) - lb(2));
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
723 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
724 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
725
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
726 return 0;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
727 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
728
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
729 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
730 ft_text_renderer::compute_bbox (void)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
731 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
732 // Stack the various line bbox together and compute the final
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
733 // bounding box for the entire text string.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
734
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
735 m_bbox = Matrix ();
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
736
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
737 switch (m_line_bbox.size ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
738 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
739 case 0:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
740 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
741
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
742 case 1:
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
743 m_bbox = m_line_bbox.front ().extract (0, 0, 0, 3);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
744 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
745
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
746 default:
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
747 for (const auto& lbox : m_line_bbox)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
748 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
749 if (m_bbox.isempty ())
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
750 m_bbox = lbox.extract (0, 0, 0, 3);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
751 else
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
752 {
26221
76ac35f71573 Fix regression in multi-line text rendering (bug #55218)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26187
diff changeset
753 double delta = math::round (0.4 * m_max_fontsize) + lbox(3);
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
754 m_bbox(1) -= delta;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
755 m_bbox(3) += delta;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
756 m_bbox(2) = math::max (m_bbox(2), lbox(2));
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
757 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
758 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
759 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
760 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
761 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
762
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
763 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
764 ft_text_renderer::update_line_bbox (void)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
765 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
766 // Called after a font change, when in MODE_BBOX mode, to update the
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
767 // current line bbox with the new font metrics. This also includes the
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
768 // current yoffset, that is the offset of the current glyph's baseline
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
769 // the line's baseline.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
770
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
771 if (m_mode == MODE_BBOX)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
772 {
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
773 Matrix& bb = m_line_bbox.back ();
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
774 bb(1) = m_ymin;
26330
45cf2ada3e39 Make sure text bounding box is high enough (bug #55328).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26221
diff changeset
775 // Add one pixel to the bbox height to avoid occasional text clipping.
45cf2ada3e39 Make sure text bounding box is high enough (bug #55328).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26221
diff changeset
776 // See bug #55328.
45cf2ada3e39 Make sure text bounding box is high enough (bug #55328).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26221
diff changeset
777 bb(3) = (m_ymax + 1) - m_ymin;
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
778 if (m_deltax > 0)
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
779 bb(2) += m_deltax;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
780 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
781 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
782
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
783 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
784 ft_text_renderer::set_mode (int m)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
785 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
786 m_mode = m;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
787
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
788 switch (m_mode)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
789 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
790 case MODE_BBOX:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
791 m_xoffset = m_line_yoffset = m_yoffset = 0;
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
792 m_max_fontsize = 0.0;
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
793 m_bbox = Matrix (1, 4, 0.0);
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
794 m_line_bbox.clear ();
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
795 push_new_line ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
796 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
797
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
798 case MODE_RENDER:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
799 if (m_bbox.numel () != 4)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
800 {
22515
77b50a83ec11 Error out, rather than segfault, when fontname is "" (bug #49102).
Rik <rik@octave.org>
parents: 22407
diff changeset
801 ::error ("ft_text_renderer: invalid bounding box, cannot render");
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
802
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
803 m_xoffset = m_line_yoffset = m_yoffset = 0;
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
804 m_pixels = uint8NDArray ();
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
805 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
806 else
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
807 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
808 dim_vector d (4, octave_idx_type (m_bbox(2)),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
809 octave_idx_type (m_bbox(3)));
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
810 m_pixels = uint8NDArray (d, static_cast<uint8_t> (0));
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
811 m_xoffset = compute_line_xoffset (m_line_bbox.front ());
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
812 m_line_yoffset = -m_bbox(1);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
813 m_yoffset = 0;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
814 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
815 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
816
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
817 default:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
818 error ("ft_text_renderer: invalid mode '%d'", m_mode);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
819 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
820 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
821 }
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
822
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30119
diff changeset
823 bool is_opaque (const FT_GlyphSlot& glyph, const int x, const int y)
26858
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
824 {
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
825 // Borrowed from https://stackoverflow.com/questions/14800827/
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
826 // indexing-pixels-in-a-monochrome-freetype-glyph-buffer
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
827 int pitch = std::abs (glyph->bitmap.pitch);
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
828 unsigned char *row = &glyph->bitmap.buffer[pitch * y];
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
829 char cvalue = row[x >> 3];
26995
ab5bfee22d18 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26858
diff changeset
830
26858
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
831 return ((cvalue & (128 >> (x & 7))) != 0);
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
832 }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
833
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
834 FT_UInt
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
835 ft_text_renderer::process_character (FT_ULong code, FT_UInt previous,
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
836 std::string& sub_name)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
837 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
838 FT_Face face = m_font.get_face ();
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
839
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
840 sub_name = face->family_name;
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
841
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
842 FT_UInt glyph_index = 0;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
843
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
844 if (face)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
845 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
846 glyph_index = FT_Get_Char_Index (face, code);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
847
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
848 if (code != '\n' && code != '\t'
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
849 && (! glyph_index
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
850 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)))
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
851 {
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
852 #if defined (HAVE_FONTCONFIG)
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
853 // Try to substitue font
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
854 FT_Face sub_face = ft_manager::get_font (m_font.get_name (),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
855 m_font.get_weight (),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
856 m_font.get_angle (),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
857 m_font.get_size (),
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
858 code);
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
859
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
860 if (sub_face)
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
861 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
862 FT_Set_Char_Size (sub_face, 0, m_font.get_size ()*64, 0, 0);
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
863
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
864 glyph_index = FT_Get_Char_Index (sub_face, code);
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
865
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
866 if (glyph_index
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
867 && (FT_Load_Glyph (sub_face, glyph_index, FT_LOAD_DEFAULT)
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
868 == 0))
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
869 {
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
870 static std::string prev_sub_name;
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
871
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
872 if (prev_sub_name.empty ()
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
873 || prev_sub_name != std::string (sub_face->family_name))
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
874 {
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
875 prev_sub_name = sub_face->family_name;
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
876 warning_with_id ("Octave:substituted-glyph",
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
877 "text_renderer: substituting font to '%s' for some characters",
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
878 sub_face->family_name);
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
879 }
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
880
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
881 ft_font saved_font = m_font;
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
882
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
883 m_font = ft_font (m_font.get_name (), m_font.get_weight (),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
884 m_font.get_angle (), m_font.get_size (),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
885 sub_face);
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
886
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
887 process_character (code, previous, sub_name);
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
888
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
889 m_font = saved_font;
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
890 }
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
891 else
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
892 {
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
893 glyph_index = 0;
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
894 warn_missing_glyph (code);
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
895 }
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
896 }
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
897 else
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
898 {
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
899 glyph_index = 0;
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
900 warn_missing_glyph (code);
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
901 }
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
902 #else
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
903 glyph_index = 0;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
904 warn_missing_glyph (code);
29678
7511182e5e9b Allow for automatic font substitution in graphics text rendering
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29655
diff changeset
905 #endif
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
906 }
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
907 else if ((code == '\n') || (code == '\t'))
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
908 {
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
909 glyph_index = FT_Get_Char_Index (face, ' ');
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
910 if (! glyph_index
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
911 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
912 {
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
913 glyph_index = 0;
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
914 warn_missing_glyph (' ');
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
915 }
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
916 else if (code == '\n')
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
917 push_new_line ();
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
918 else
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
919 {
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
920 // Advance to next multiple of 4 times the width of the "space"
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
921 // character.
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
922 int x_tab = 4 * (face->glyph->advance.x >> 6);
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
923 m_xoffset = (1 + std::floor (1. * m_xoffset / x_tab)) * x_tab;
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
924 }
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
925 }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
926 else
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
927 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
928 switch (m_mode)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
929 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
930 case MODE_RENDER:
26858
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
931 if (FT_Render_Glyph (face->glyph, (m_antialias
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
932 ? FT_RENDER_MODE_NORMAL
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
933 : FT_RENDER_MODE_MONO)))
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
934 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
935 glyph_index = 0;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
936 warn_glyph_render (code);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
937 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
938 else
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
939 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
940 FT_Bitmap& bitmap = face->glyph->bitmap;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
941 int x0, y0;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
942
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
943 if (previous)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
944 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
945 FT_Vector delta;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
946
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
947 FT_Get_Kerning (face, previous, glyph_index,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
948 FT_KERNING_DEFAULT, &delta);
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
949
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
950 m_xoffset += (delta.x >> 6);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
951 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
952
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
953 x0 = m_xoffset + face->glyph->bitmap_left;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
954 y0 = m_line_yoffset + m_yoffset
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30119
diff changeset
955 + (face->glyph->bitmap_top - 1);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
956
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
957 // 'w' seems to have a negative -1
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
958 // face->glyph->bitmap_left, this is so we don't index out
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
959 // of bound, and assumes we've allocated the right amount of
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
960 // horizontal space in the bbox.
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
961 if (x0 < 0)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
962 x0 = 0;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
963
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
964 for (int r = 0; static_cast<unsigned int> (r) < bitmap.rows; r++)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
965 for (int c = 0; static_cast<unsigned int> (c) < bitmap.width; c++)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
966 {
26858
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
967 unsigned char pix
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
968 = (m_antialias
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
969 ? bitmap.buffer[r*bitmap.width+c]
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26619
diff changeset
970 : (is_opaque (face->glyph, c, r) ? 255 : 0));
26995
ab5bfee22d18 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26858
diff changeset
971
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
972 if (x0+c < 0 || x0+c >= m_pixels.dim2 ()
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
973 || y0-r < 0 || y0-r >= m_pixels.dim3 ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
974 {
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
975 // ::warning ("ft_text_renderer: x %d, y %d",
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
976 // x0+c, y0-r);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
977 }
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
978 else if (m_pixels(3, x0+c, y0-r).value () == 0)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
979 {
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
980 m_pixels(0, x0+c, y0-r) = m_color(0);
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
981 m_pixels(1, x0+c, y0-r) = m_color(1);
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
982 m_pixels(2, x0+c, y0-r) = m_color(2);
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
983 m_pixels(3, x0+c, y0-r) = pix;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
984 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
985 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
986
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
987 m_xoffset += (face->glyph->advance.x >> 6);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
988 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
989 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
990
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
991 case MODE_BBOX:
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
992 Matrix& bb = m_line_bbox.back ();
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
993
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
994 // If we have a previous glyph, use kerning information. This
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
995 // usually means moving a bit backward before adding the next
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
996 // glyph. That is, "delta.x" is usually < 0.
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
997 if (previous)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
998 {
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
999 FT_Vector delta;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1000
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
1001 FT_Get_Kerning (face, previous, glyph_index,
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
1002 FT_KERNING_DEFAULT, &delta);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1003
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1004 m_xoffset += (delta.x >> 6);
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
1005 }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1006
25421
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
1007 // Extend current X offset box by the width of the current
c335f94766a7 Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25420
diff changeset
1008 // glyph. Then extend the line bounding box if necessary.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1009
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1010 m_xoffset += (face->glyph->advance.x >> 6);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1011 bb(2) = math::max (bb(2), m_xoffset);
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1012
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1013 // Store the actual bbox vertical coordinates of this character
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1014 FT_Glyph glyph;
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1015 if (FT_Get_Glyph (face->glyph, &glyph))
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1016 warn_glyph_render (code);
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1017 else
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1018 {
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1019 FT_BBox glyph_bbox;
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1020 FT_Glyph_Get_CBox (glyph, FT_GLYPH_BBOX_UNSCALED,
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1021 &glyph_bbox);
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1022 m_deltax = (glyph_bbox.xMax - face->glyph->advance.x) >> 6;
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1023 m_ymin = math::min ((glyph_bbox.yMin >> 6) + m_yoffset,
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1024 m_ymin);
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1025 m_ymax = math::max ((glyph_bbox.yMax >> 6) + m_yoffset,
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1026 m_ymax);
26478
6f22d0c91beb Fix memory leak with FT_Glyph objects (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
1027 FT_Done_Glyph (glyph);
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1028 update_line_bbox ();
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1029 }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1030 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1031 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1032 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1033 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1034
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1035 return glyph_index;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1036 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1037
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1038 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1039 ft_text_renderer::text_to_strlist (const std::string& txt,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1040 std::list<text_renderer::string>& lst,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1041 Matrix& box,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1042 int ha, int va, double rot,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1043 const caseless_str& interp)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1044 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1045 uint8NDArray pxls;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1046
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1047 // First run text_to_pixels which will also build the string list
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1048
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1049 m_strlist = std::list<text_renderer::string> ();
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26573
diff changeset
1050
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28823
diff changeset
1051 unwind_protect_var<bool> restore_var1 (m_do_strlist);
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28823
diff changeset
1052 unwind_protect_var<std::list<text_renderer::string>>
28823
26cfccfee9a0 Replace unwind_protect with more efficient constructs (bug #59192).
Rik <rik@octave.org>
parents: 28483
diff changeset
1053 restore_var2 (m_strlist);
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28823
diff changeset
1054
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1055 m_do_strlist = true;
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26573
diff changeset
1056
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1057 text_to_pixels (txt, pxls, box, ha, va, rot, interp, false);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1058
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1059 lst = m_strlist;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1060 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1061
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1062 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1063 ft_text_renderer::visit (text_element_string& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1064 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1065 if (m_font.is_valid ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1066 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1067 m_max_fontsize = std::max (m_max_fontsize, m_font.get_size ());
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1068 FT_UInt glyph_index, previous = 0;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1069
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1070 std::string str = e.string_value ();
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1071 const uint8_t *c = reinterpret_cast<const uint8_t *> (str.c_str ());
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1072 uint32_t u32_c;
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26573
diff changeset
1073
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1074 std::size_t n = str.size ();
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1075 std::size_t icurr = 0;
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1076 std::size_t ibegin = 0;
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1077
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1078 // Initialize a new string
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1079 text_renderer::string fs (str, m_font, m_xoffset, m_yoffset);
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1080
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1081 std::string fname = m_font.get_face ()->family_name;
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1082
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1083 if (fname.find (" ") != std::string::npos)
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1084 fname = "'" + fname + "'";
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1085
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1086 fs.set_family (fname);
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1087
24076
1b7e49a72c62 improve text rendering in svg printout (bug #48567)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23807
diff changeset
1088 std::vector<double> xdata;
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1089 std::string sub_name;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1090
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1091 while (n > 0)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1092 {
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1093 // Retrieve the length and the u32 representation of the current
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1094 // character
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1095 int mblen = octave_u8_strmbtouc_wrapper (&u32_c, c + icurr);
27142
8a07083c8cfc Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
1096 if (mblen < 1)
8a07083c8cfc Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
1097 {
8a07083c8cfc Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
1098 // This is not an UTF-8 character, use a replacement character
8a07083c8cfc Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
1099 mblen = 1;
8a07083c8cfc Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
1100 u32_c = 0xFFFD;
8a07083c8cfc Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
1101 }
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27150
diff changeset
1102
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1103 n -= mblen;
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1104
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1105 if (m_do_strlist && m_mode == MODE_RENDER)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1106 {
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1107 if (u32_c == 10)
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1108 {
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1109 // Finish previous string in m_strlist before processing
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1110 // the newline character
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1111 fs.set_y (m_line_yoffset + m_yoffset);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1112 fs.set_color (m_color);
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26573
diff changeset
1113
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1114 std::string s = str.substr (ibegin, icurr - ibegin);
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1115 if (! s.empty ())
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1116 {
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1117 fs.set_string (s);
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1118 fs.set_y (m_line_yoffset + m_yoffset);
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1119 fs.set_xdata (xdata);
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1120 fs.set_family (fname);
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1121 m_strlist.push_back (fs);
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1122 }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1123 }
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1124 else
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1125 xdata.push_back (m_xoffset);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1126 }
25362
def1b446ba64 Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25336
diff changeset
1127
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1128 glyph_index = process_character (u32_c, previous, sub_name);
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1129
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1130 if (m_do_strlist && m_mode == MODE_RENDER && ! sub_name.empty ())
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1131 {
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1132 // Add substitution font to the family name stack
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1133 std::string tmp_family = fs.get_family ();
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1134
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1135 if (tmp_family.find (sub_name) == std::string::npos)
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1136 {
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1137 if (sub_name.find (" ") != std::string::npos)
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1138 sub_name = "'" + sub_name + "'";
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1139
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1140 fs.set_family (tmp_family + ", " + sub_name);
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1141 }
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1142 }
25362
def1b446ba64 Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25336
diff changeset
1143
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1144 if (u32_c == 10)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1145 {
25362
def1b446ba64 Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25336
diff changeset
1146 previous = 0;
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26573
diff changeset
1147
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1148 if (m_do_strlist && m_mode == MODE_RENDER)
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1149 {
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1150 // Start a new string in m_strlist
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1151 ibegin = icurr+1;
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1152 xdata.clear ();
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1153 fs = text_renderer::string (str.substr (ibegin), m_font,
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1154 m_line_xoffset, m_yoffset);
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1155 }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1156 }
25362
def1b446ba64 Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25336
diff changeset
1157 else
def1b446ba64 Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25336
diff changeset
1158 previous = glyph_index;
def1b446ba64 Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25336
diff changeset
1159
26187
8d4f23b7f4eb Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26152
diff changeset
1160 icurr += mblen;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1161 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1162
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1163 if (m_do_strlist && m_mode == MODE_RENDER
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1164 && ! fs.get_string ().empty ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1165 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1166 fs.set_y (m_line_yoffset + m_yoffset);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1167 fs.set_color (m_color);
24076
1b7e49a72c62 improve text rendering in svg printout (bug #48567)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23807
diff changeset
1168 fs.set_xdata (xdata);
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1169 m_strlist.push_back (fs);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1170 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1171 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1172 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1173
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1174 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1175 ft_text_renderer::visit (text_element_list& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1176 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1177 // Save and restore (after processing the list) the current font and color.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1178
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1179 ft_font saved_font (m_font);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1180 uint8NDArray saved_color (m_color);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1181
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1182 text_processor::visit (e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1183
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1184 m_font = saved_font;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1185 m_color = saved_color;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1186 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1187
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1188 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1189 ft_text_renderer::visit (text_element_subscript& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1190 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1191 ft_font saved_font (m_font);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1192 int saved_line_yoffset = m_line_yoffset;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1193 int saved_yoffset = m_yoffset;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1194
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1195 double sz = m_font.get_size ();
28305
6e8d5c99263c Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 28206
diff changeset
1196
6e8d5c99263c Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 28206
diff changeset
1197 // Reducing font size by 70% produces decent results.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1198 set_font (m_font.get_name (), m_font.get_weight (), m_font.get_angle (),
28305
6e8d5c99263c Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 28206
diff changeset
1199 std::max (5.0, sz * 0.7));
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1200
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1201 if (m_font.is_valid ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1202 {
28305
6e8d5c99263c Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 28206
diff changeset
1203 // Shifting the baseline by 15% of the font size gives decent results.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1204 m_yoffset -= std::ceil (sz * 0.15);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1205
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1206 if (m_mode == MODE_BBOX)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1207 update_line_bbox ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1208 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1209
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1210 text_processor::visit (e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1211
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1212 m_font = saved_font;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1213 // If line_yoffset changed, this means we moved to a new line; hence yoffset
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1214 // cannot be restored, because the saved value is not relevant anymore.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1215 if (m_line_yoffset == saved_line_yoffset)
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1216 m_yoffset = saved_yoffset;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1217 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1218
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1219 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1220 ft_text_renderer::visit (text_element_superscript& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1221 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1222 ft_font saved_font (m_font);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1223 int saved_line_yoffset = m_line_yoffset;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1224 int saved_yoffset = m_yoffset;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1225
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1226 double sz = m_font.get_size ();
28305
6e8d5c99263c Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 28206
diff changeset
1227
6e8d5c99263c Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 28206
diff changeset
1228 // Reducing font size by 70% produces decent results.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1229 set_font (m_font.get_name (), m_font.get_weight (), m_font.get_angle (),
28305
6e8d5c99263c Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 28206
diff changeset
1230 std::max (5.0, sz * 0.7));
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1231
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1232 if (saved_font.is_valid ())
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1233 {
28305
6e8d5c99263c Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 28206
diff changeset
1234 // Shifting the baseline by 40% of the font size gives decent results.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1235 m_yoffset += std::ceil (sz * 0.4);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1236
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1237 if (m_mode == MODE_BBOX)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1238 update_line_bbox ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1239 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1240
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1241 text_processor::visit (e);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1242
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1243 m_font = saved_font;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1244 // If line_yoffset changed, this means we moved to a new line; hence yoffset
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1245 // cannot be restored, because the saved value is not relevant anymore.
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1246 if (m_line_yoffset == saved_line_yoffset)
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1247 m_yoffset = saved_yoffset;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1248 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1249
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1250 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1251 ft_text_renderer::visit (text_element_color& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1252 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1253 if (m_mode == MODE_RENDER)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1254 set_color (e.get_color ());
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1255 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1256
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1257 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1258 ft_text_renderer::visit (text_element_fontsize& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1259 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1260 double sz = e.get_fontsize ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1261
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1262 // FIXME: Matlab documentation says that the font size is expressed
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1263 // in the text object FontUnit.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1264
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1265 set_font (m_font.get_name (), m_font.get_weight (),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1266 m_font.get_angle (), sz);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1267
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1268 if (m_mode == MODE_BBOX)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1269 update_line_bbox ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1270 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1271
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1272 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1273 ft_text_renderer::visit (text_element_fontname& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1274 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1275 set_font (e.get_fontname (), m_font.get_weight (), m_font.get_angle (),
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1276 m_font.get_size ());
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1277
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1278 if (m_mode == MODE_BBOX)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1279 update_line_bbox ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1280 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1281
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1282 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1283 ft_text_renderer::visit (text_element_fontstyle& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1284 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1285 switch (e.get_fontstyle ())
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1286 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1287 case text_element_fontstyle::normal:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1288 set_font (m_font.get_name (), "normal", "normal", m_font.get_size ());
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1289 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1290
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1291 case text_element_fontstyle::bold:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1292 set_font (m_font.get_name (), "bold", "normal", m_font.get_size ());
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1293 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1294
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1295 case text_element_fontstyle::italic:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1296 set_font (m_font.get_name (), "normal", "italic", m_font.get_size ());
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1297 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1298
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1299 case text_element_fontstyle::oblique:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1300 set_font (m_font.get_name (), "normal", "oblique", m_font.get_size ());
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1301 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1302 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1303
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1304 if (m_mode == MODE_BBOX)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1305 update_line_bbox ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1306 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1307
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1308 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1309 ft_text_renderer::visit (text_element_symbol& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1310 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1311 uint32_t code = e.get_symbol_code ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1312
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1313 std::vector<double> xdata (1, m_xoffset);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1314 text_renderer::string fs ("-", m_font, m_xoffset, m_yoffset);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1315
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1316 if (code != text_element_symbol::invalid_code && m_font.is_valid ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1317 {
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1318 std::string sub_name;
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1319
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1320 process_character (code, 0, sub_name);
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1321
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1322 if (m_do_strlist && m_mode == MODE_RENDER)
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1323 {
29683
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1324 if (! sub_name.empty ())
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1325 {
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1326 // Add substitution font to the family name
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1327 std::string tmp_family = fs.get_family ();
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1328
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1329 if (tmp_family.find (sub_name) == std::string::npos)
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1330 {
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1331 if (sub_name.find (" ") != std::string::npos)
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1332 sub_name = "'" + sub_name + "'";
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1333
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1334 fs.set_family (tmp_family + ", " + sub_name);
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1335 }
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1336 }
5ffe7159f94b Add substitution font to SVG font stack if necessary
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29679
diff changeset
1337
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1338 fs.set_code (code);
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1339 fs.set_xdata (xdata);
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1340 }
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1341 }
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1342 else if (m_font.is_valid ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1343 ::warning ("ignoring unknown symbol: %d", e.get_symbol ());
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1344
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1345 if (m_do_strlist && m_mode == MODE_RENDER && fs.get_code ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1346 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1347 fs.set_y (m_line_yoffset + m_yoffset);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1348 fs.set_color (m_color);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1349 fs.set_family (m_font.get_face ()->family_name);
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1350 m_strlist.push_back (fs);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1351 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1352 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1353
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1354 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1355 ft_text_renderer::visit (text_element_combined& e)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1356 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1357 int saved_xoffset = m_xoffset;
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1358 int max_xoffset = m_xoffset;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1359
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
1360 for (auto *txt_elt : e)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1361 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1362 m_xoffset = saved_xoffset;
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
1363 txt_elt->accept (*this);
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1364 max_xoffset = math::max (m_xoffset, max_xoffset);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1365 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1366
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1367 m_xoffset = max_xoffset;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1368 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1369
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1370 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1371 ft_text_renderer::reset (void)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1372 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1373 set_mode (MODE_BBOX);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1374 set_color (Matrix (1, 3, 0.0));
26573
ad70a85f702b Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26478
diff changeset
1375 m_strlist = std::list<text_renderer::string> ();
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1376 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1377
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1378 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1379 ft_text_renderer::set_color (const Matrix& c)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1380 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1381 if (c.numel () == 3)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1382 {
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1383 m_color(0) = static_cast<uint8_t> (c(0)*255);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1384 m_color(1) = static_cast<uint8_t> (c(1)*255);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1385 m_color(2) = static_cast<uint8_t> (c(2)*255);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1386 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1387 else
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1388 ::warning ("ft_text_renderer::set_color: invalid color");
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1389 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1390
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1391 uint8NDArray
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1392 ft_text_renderer::render (text_element *elt, Matrix& box, int rotation)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1393 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1394 set_mode (MODE_BBOX);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1395 elt->accept (*this);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1396 compute_bbox ();
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1397 box = m_bbox;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1398
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1399 set_mode (MODE_RENDER);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1400
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
1401 if (m_pixels.numel () > 0)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1402 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1403 elt->accept (*this);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1404
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
1405 rotate_pixels (m_pixels, rotation);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1406 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1407
30119
3161a1ee0045 maint: use "m_" prefix for member variables in file ft-text-renderer.cc.
Rik <rik@octave.org>
parents: 30041
diff changeset
1408 return m_pixels;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1409 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1410
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1411 // Note:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1412 // x-extent accurately measures width of glyphs.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1413 // y-extent is overly large because it is measured from baseline-to-baseline.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1414 // Calling routines, such as ylabel, may need to account for this mismatch.
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1415
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1416 Matrix
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1417 ft_text_renderer::get_extent (text_element *elt, double rotation)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1418 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1419 set_mode (MODE_BBOX);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1420 elt->accept (*this);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1421 compute_bbox ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1422
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1423 Matrix extent (1, 2, 0.0);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1424
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1425 switch (rotation_to_mode (rotation))
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1426 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1427 case ROTATION_0:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1428 case ROTATION_180:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1429 extent(0) = m_bbox(2);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1430 extent(1) = m_bbox(3);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1431 break;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1432
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1433 case ROTATION_90:
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1434 case ROTATION_270:
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1435 extent(0) = m_bbox(3);
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1436 extent(1) = m_bbox(2);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1437 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1438
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1439 return extent;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1440 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1441
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1442 Matrix
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1443 ft_text_renderer::get_extent (const std::string& txt, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1444 const caseless_str& interpreter)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1445 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1446 text_element *elt = text_parser::parse (txt, interpreter);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1447 Matrix extent = get_extent (elt, rotation);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1448 delete elt;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1449
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1450 return extent;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1451 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1452
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1453 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1454 ft_text_renderer::text_to_pixels (const std::string& txt,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1455 uint8NDArray& pxls, Matrix& box,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1456 int _halign, int valign, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1457 const caseless_str& interpreter,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1458 bool handle_rotation)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1459 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1460 int rot_mode = rotation_to_mode (rotation);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1461
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1462 m_halign = _halign;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1463
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1464 text_element *elt = text_parser::parse (txt, interpreter);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1465 pxls = render (elt, box, rot_mode);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1466 delete elt;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1467
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23462
diff changeset
1468 if (pxls.isempty ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1469 return; // nothing to render
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1470
29470
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29359
diff changeset
1471 // Move X0 and Y0 depending on alignments and eventually swap all values
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29359
diff changeset
1472 // for text rotated 90° 180° or 270°
29679
7ad7991e946a ft-text-renderer.cc: Use m_ prefix for class data members
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29678
diff changeset
1473 fix_bbox_anchor (box, m_halign, valign, rot_mode, handle_rotation);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1474 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1475
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1476 ft_text_renderer::ft_font::ft_font (const ft_font& ft)
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1477 : text_renderer::font (ft), m_face (nullptr)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1478 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1479 #if defined (HAVE_FT_REFERENCE_FACE)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1480 FT_Face ft_face = ft.get_face ();
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1481
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1482 if (ft_face && FT_Reference_Face (ft_face) == 0)
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1483 m_face = ft_face;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1484 #endif
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1485 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1486
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1487 ft_text_renderer::ft_font&
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1488 ft_text_renderer::ft_font::operator = (const ft_font& ft)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1489 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1490 if (&ft != this)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1491 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1492 text_renderer::font::operator = (ft);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
1493
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1494 if (m_face)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1495 {
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1496 FT_Done_Face (m_face);
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1497 m_face = nullptr;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1498 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1499
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1500 #if defined (HAVE_FT_REFERENCE_FACE)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1501 FT_Face ft_face = ft.get_face ();
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1502
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1503 if (ft_face && FT_Reference_Face (ft_face) == 0)
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1504 m_face = ft_face;
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1505 #endif
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1506 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1507
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1508 return *this;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1509 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1510
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1511 FT_Face
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1512 ft_text_renderer::ft_font::get_face (void) const
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1513 {
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1514 if (! m_face && ! m_name.empty ())
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1515 {
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1516 m_face = ft_manager::get_font (m_name, m_weight, m_angle, m_size);
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1517
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1518 if (m_face)
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1519 {
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1520 if (FT_Set_Char_Size (m_face, 0, m_size*64, 0, 0))
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1521 ::warning ("ft_text_renderer: unable to set font size to %g", m_size);
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1522 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1523 else
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1524 ::warning ("ft_text_renderer: unable to load appropriate font");
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1525 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1526
30041
f148aff802b6 maint: use "m_" prefix for member variables of text_renderer objects.
Rik <rik@octave.org>
parents: 29683
diff changeset
1527 return m_face;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
1528 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
1529
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
1530 OCTAVE_END_NAMESPACE(octave)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1531
20945
9d9270e2f98f eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
1532 #endif
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1533
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
1534 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
1535
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1536 base_text_renderer *
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1537 make_ft_text_renderer (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1538 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1539 #if defined (HAVE_FREETYPE)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1540 return new ft_text_renderer ();
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1541 #else
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1542 return 0;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1543 #endif
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1544 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
1545
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
1546 OCTAVE_END_NAMESPACE(octave)