annotate libinterp/corefcn/ft-text-renderer.cc @ 21724:aba2e6293dd8

use "#if ..." consistently instead of "#ifdef" and "#ifndef" * configure.ac, Doxyfile.in, make_int.cc, Backend.cc, BaseControl.cc, ButtonControl.cc, Canvas.cc, CheckBoxControl.cc, Container.cc, ContextMenu.cc, EditControl.cc, Figure.cc, FigureWindow.cc, GLCanvas.cc, KeyMap.cc, ListBoxControl.cc, Logger.cc, Menu.cc, MouseModeActionGroup.cc, Object.cc, ObjectFactory.cc, ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc, PushTool.cc, QtHandlesUtils.cc, RadioButtonControl.cc, SliderControl.cc, TextControl.cc, TextEdit.cc, ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, __init_qt__.cc, annotation-dialog.cc, gl-select.cc, module.mk, color-picker.cc, dialog.cc, documentation-dock-widget.cc, files-dock-widget.cc, find-files-dialog.cc, find-files-model.cc, history-dock-widget.cc, liboctgui-build-info.in.cc, file-editor-tab.cc, file-editor.cc, find-dialog.cc, marker.cc, marker.h, octave-qscintilla.cc, octave-txt-lexer.cc, main-window.cc, octave-cmd.cc, octave-dock-widget.cc, octave-gui.cc, octave-interpreter.cc, octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc, settings-dialog.cc, shortcut-manager.cc, terminal-dock-widget.cc, thread-manager.cc, welcome-wizard.cc, workspace-model.cc, workspace-view.cc, build-env.in.cc, Cell.cc, __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc, __lin_interpn__.cc, __luinc__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, cdisplay.c, cdisplay.h, cellfun.cc, coct-hdf5-types.c, colloc.cc, comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, defaults.in.h, defun.cc, det.cc, dirfns.cc, display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc, error.cc, errwarn.cc, event-queue.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, gripes.cc, hash.cc, help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, kron.cc, load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc, ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mex.h, mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-iostrm.cc, oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc, oct-stdstrm.h, oct-stream.cc, oct-strstrm.cc, oct-tex-lexer.in.ll, oct-tex-parser.in.yy, octave-link.cc, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc, pt-jit.cc, pt-jit.h, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sighandlers.h, siglist.c, siglist.h, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, text-renderer.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xgl2ps.c, xnorm.cc, xpow.cc, zfstream.cc, zfstream.h, __delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc, liboctinterp-build-info.in.cc, mkbuiltins, mkops, ov-base.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc, ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc, ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ovl.cc, octave.cc, octave.h, 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-cdm-cm.cc, op-cdm-dm.cc, op-cdm-m.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cdm.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-dm.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-cdm.cc, op-dm-cm.cc, op-dm-dm.cc, op-dm-m.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-double-conv.cc, op-fcdm-fcdm.cc, op-fcdm-fcm.cc, op-fcdm-fdm.cc, op-fcdm-fm.cc, op-fcm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fdm.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-fcdm.cc, op-fdm-fcm.cc, op-fdm-fdm.cc, op-fdm-fm.cc, op-float-conv.cc, op-fm-fcdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fdm.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-int-conv.cc, op-m-cdm.cc, op-m-cm.cc, op-m-cs.cc, op-m-dm.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.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, lex.ll, oct-parse.in.yy, pt-arg-list.cc, pt-array-list.cc, pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc, pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-const.cc, pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc, pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc, pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-tc.cc, version.cc, Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc, Array-f.cc, Array-fC.cc, Array-i.cc, Array-idx-vec.cc, Array-s.cc, Array-str.cc, Array-util.cc, Array-voidp.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc, MArray-C.cc, MArray-d.cc, MArray-f.cc, MArray-fC.cc, MArray-i.cc, MArray-s.cc, MSparse-C.cc, MSparse-d.cc, MatrixType.cc, PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc, Sparse-d.cc, boolMatrix.cc, boolNDArray.cc, boolSparse.cc, chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dim-vector.cc, dim-vector.h, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc, uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc, Faddeeva.cc, blaswrap.c, cquit.c, f77-extern.cc, f77-fcn.c, f77-fcn.h, lo-error.c, lo-error.h, quit.cc, quit.h, liboctave-build-info.in.cc, CollocWt.cc, DASPK.cc, DASRT.cc, DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, aepbalance.cc, chol.cc, eigs-base.cc, fEIG.cc, gepbalance.cc, hess.cc, lo-mappers.cc, lo-specfun.cc, lu.cc, oct-convn.cc, oct-fftw.cc, oct-norm.cc, oct-rand.cc, oct-spparms.cc, qr.cc, qrp.cc, randmtzig.cc, randpoisson.cc, schur.cc, sparse-chol.cc, sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, svd.cc, mk-ops.awk, mx-defs.h, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc, mach-info.cc, oct-env.cc, oct-group.cc, oct-passwd.cc, oct-syscalls.cc, oct-time.cc, oct-uname.cc, pathlen.h, syswait.h, cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c, glob-match.cc, kpse.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c, lo-cutils.h, lo-ieee.cc, lo-ieee.h, lo-regexp.cc, lo-utils.cc, oct-base64.cc, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h, oct-locbuf.cc, oct-mutex.cc, oct-rl-edit.c, oct-rl-edit.h, oct-rl-hist.c, oct-rl-hist.h, oct-shlib.cc, oct-sort.cc, pathsearch.cc, singleton-cleanup.cc, sparse-sort.cc, sparse-util.cc, statdefs.h, str-vec.cc, unwind-prot.cc, url-transfer.cc, acinclude.m4, display-available.c, display-available.h, main-cli.cc, main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-build-info.in.cc, octave-config.in.cc, shared-fcns.h: Use "#if ..." consistently instead of "#ifdef" and "#ifndef".
author John W. Eaton <jwe@octave.org>
date Tue, 17 May 2016 12:09:30 -0400
parents 3d60ed163b70
children b571fc85953f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1 /*
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
3 Copyright (C) 2016 John W. Eaton
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18736
diff changeset
4 Copyright (C) 2009-2015 Michael Goffioul
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
5
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
6 This file is part of Octave.
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
7
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
11 option) any later version.
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
12
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
16 for more details.
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
17
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
20 <http://www.gnu.org/licenses/>.
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
21
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
22 */
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
23
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21568
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21209
diff changeset
25 # include "config.h"
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
26 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
27
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
28 #include "base-text-renderer.h"
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
29
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
30 #if defined (HAVE_FREETYPE)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
31
21334
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
32 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
33 #pragma GCC diagnostic push
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
34 #pragma GCC diagnostic ignored "-Wold-style-cast"
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
35 #endif
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
36
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
37 #include <ft2build.h>
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
38 #include FT_FREETYPE_H
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
39
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
40 #if defined (HAVE_FONTCONFIG)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21102
diff changeset
41 # include <fontconfig/fontconfig.h>
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
42 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
43
21334
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
44 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
45 #pragma GCC diagnostic pop
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
46 #endif
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
47
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
48 #include <clocale>
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
49 #include <cwchar>
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
50 #include <iostream>
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
51 #include <map>
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
52 #include <utility>
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
53
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
54 #include "singleton-cleanup.h"
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
55
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
56 #include "error.h"
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
57 #include "pr-output.h"
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
58 #include "text-renderer.h"
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
59
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
60 // FIXME: maybe issue at most one warning per glyph/font/size/weight
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
61 // combination.
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
62
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
63 static void
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
64 warn_missing_glyph (FT_ULong c)
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
65 {
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
66 warning_with_id ("Octave:missing-glyph",
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
67 "text_renderer: skipping missing glyph for character '%x'", c);
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
68 }
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
69
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
70 static void
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
71 warn_glyph_render (FT_ULong c)
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
72 {
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
73 warning_with_id ("Octave:glyph-render",
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
74 "text_renderer: unable to render glyph for character '%x'", c);
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
75 }
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
76
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
77 #if defined (_MSC_VER)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
78 // FIXME: is this really needed?
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
79 //
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
80 // This is just a trick to avoid multiple symbol definitions.
13730
a2c74b5c02de [MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13317
diff changeset
81 // PermMatrix.h contains a dllexport'ed Array<octave_idx_type>
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
82 // that will cause MSVC not to generate a new instantiation and
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
83 // use the imported one instead.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
84 # include "PermMatrix.h"
13730
a2c74b5c02de [MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13317
diff changeset
85 #endif
a2c74b5c02de [MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13317
diff changeset
86
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
87 // Forward declaration
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
88 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
89
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
90 class
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
91 ft_manager
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
92 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
93 public:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
94 static bool instance_ok (void)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
95 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
96 bool retval = true;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
97
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
98 if (! instance)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
99 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
100 instance = new ft_manager ();
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
101
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
102 if (instance)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
103 singleton_cleanup_list::add (cleanup_instance);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
104 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
105
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
106 if (! instance)
20956
850e3d2533d4 maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents: 20945
diff changeset
107 error ("unable to create ft_manager!");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
108
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
109 return retval;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
110 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
111
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
112 static void cleanup_instance (void) { delete instance; instance = 0; }
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
113
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
114 static FT_Face get_font (const std::string& name, const std::string& weight,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
115 const std::string& angle, double size)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
116 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
117 return (instance_ok ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
118 ? instance->do_get_font (name, weight, angle, size)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
119 : 0);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
120 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
121
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
122 static void font_destroyed (FT_Face face)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
123 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
124 if (instance_ok ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
125 instance->do_font_destroyed (face);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
126 }
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
127
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
128 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
129
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
130 static ft_manager *instance;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
131
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
132 typedef std::pair<std::string, double> ft_key;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
133 typedef std::map<ft_key, FT_Face> ft_cache;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
134
18736
333901476119 maint: Use "FreeType" rather than "freetype" in messages and comments.
Rik <rik@octave.org>
parents: 18100
diff changeset
135 // Cache the fonts loaded by FreeType. This cache only contains
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
136 // weak references to the fonts, strong references are only present
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
137 // in class text_renderer.
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
138 ft_cache cache;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
139
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
140 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
141
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
142 // No copying!
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
143
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
144 ft_manager (const ft_manager&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
145
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
146 ft_manager& operator = (const ft_manager&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
147
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
148 ft_manager (void)
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
149 : library (), freetype_initialized (false), fontconfig_initialized (false)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
150 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
151 if (FT_Init_FreeType (&library))
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 19697
diff changeset
152 error ("unable to initialize FreeType library");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
153 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
154 freetype_initialized = true;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
155
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
156 #if defined (HAVE_FONTCONFIG)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
157 if (! FcInit ())
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 19697
diff changeset
158 error ("unable to initialize fontconfig library");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
159 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
160 fontconfig_initialized = true;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
161 #endif
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
162 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
163
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
164 ~ft_manager (void)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
165 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
166 if (freetype_initialized)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
167 FT_Done_FreeType (library);
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
168
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
169 #if defined (HAVE_FONTCONFIG)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
170 // FIXME: Skip the call to FcFini because it can trigger the assertion
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
171 //
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
172 // octave: fccache.c:507: FcCacheFini: Assertion 'fcCacheChains[i] == ((void *)0)' failed.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
173 //
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
174 // if (fontconfig_initialized)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
175 // FcFini ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
176 #endif
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
177 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
178
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
179
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
180 FT_Face do_get_font (const std::string& name, const std::string& weight,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
181 const std::string& angle, double size)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
182 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
183 FT_Face retval = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
184
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
185 #if defined (HAVE_FT_REFERENCE_FACE)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
186 // Look first into the font cache, then use fontconfig. If the font
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
187 // 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
188
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
189 ft_key key (name + ":" + weight + ":" + angle, size);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
190 ft_cache::const_iterator it = cache.find (key);
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
191
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
192 if (it != cache.end ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
193 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
194 FT_Reference_Face (it->second);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
195 return it->second;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
196 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
197 #endif
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
198
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
199 std::string file;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
200
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
201 #if defined (HAVE_FONTCONFIG)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
202 if (fontconfig_initialized)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
203 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
204 int fc_weight, fc_angle;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
205
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
206 if (weight == "bold")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
207 fc_weight = FC_WEIGHT_BOLD;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
208 else if (weight == "light")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
209 fc_weight = FC_WEIGHT_LIGHT;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
210 else if (weight == "demi")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
211 fc_weight = FC_WEIGHT_DEMIBOLD;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
212 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
213 fc_weight = FC_WEIGHT_NORMAL;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
214
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
215 if (angle == "italic")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
216 fc_angle = FC_SLANT_ITALIC;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
217 else if (angle == "oblique")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
218 fc_angle = FC_SLANT_OBLIQUE;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
219 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
220 fc_angle = FC_SLANT_ROMAN;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
221
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
222 FcPattern *pat = FcPatternCreate ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
223
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
224 FcPatternAddString (pat, FC_FAMILY,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
225 (reinterpret_cast<const FcChar8*>
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
226 (name == "*" ? "sans" : name.c_str ())));
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
227
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
228 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
229 FcPatternAddInteger (pat, FC_SLANT, fc_angle);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
230 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
231
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
232 if (FcConfigSubstitute (0, pat, FcMatchPattern))
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
233 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
234 FcResult res;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
235 FcPattern *match;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
236
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
237 FcDefaultSubstitute (pat);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
238 match = FcFontMatch (0, pat, &res);
9833
637fa784d102 Allow more font matches
godfrey@isl.Stanford.EDU
parents: 9619
diff changeset
239
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
240 // FIXME: originally, this test also required that
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
241 // res != FcResultNoMatch. Is that really needed?
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
242 if (match)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
243 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
244 unsigned char *tmp;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
245
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
246 FcPatternGetString (match, FC_FILE, 0, &tmp);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
247 file = reinterpret_cast<char*> (tmp);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
248 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
249 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
250 ::warning ("could not match any font: %s-%s-%s-%g",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
251 name.c_str (), weight.c_str (), angle.c_str (),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
252 size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
253
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
254 if (match)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
255 FcPatternDestroy (match);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
256 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
257
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
258 FcPatternDestroy (pat);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
259 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
260 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
261
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
262 if (file.empty ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
263 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
264 #if defined (__WIN32__)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
265 file = "C:/WINDOWS/Fonts/verdana.ttf";
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
266 #else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
267 // FIXME: find a "standard" font for UNIX platforms
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
268 #endif
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
269 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
270
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
271 if (! file.empty ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
272 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
273 if (FT_New_Face (library, file.c_str (), 0, &retval))
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
274 ::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
275 #if defined (HAVE_FT_REFERENCE_FACE)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
276 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
277 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
278 // Install a finalizer to notify ft_manager that the font is
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
279 // being destroyed. The class ft_manager only keeps weak
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
280 // 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
281
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
282 retval->generic.data = new ft_key (key);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
283 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
284
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
285 // Insert loaded font into the cache.
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
286
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
287 cache[key] = retval;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
288 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
289 #endif
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
290 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
291
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
292 return retval;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
293 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
294
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
295 void do_font_destroyed (FT_Face face)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
296 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
297 if (face->generic.data)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
298 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
299 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
300
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
301 cache.erase (*pkey);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
302 delete pkey;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
303 face->generic.data = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
304 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
305 }
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
306
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
307 private:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
308 FT_Library library;
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
309 bool freetype_initialized;
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
310 bool fontconfig_initialized;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
311 };
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
312
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
313 ft_manager *ft_manager::instance = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
314
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
315 static void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
316 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
317 { ft_manager::font_destroyed (reinterpret_cast<FT_Face> (object)); }
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
318
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
319 // ---------------------------------------------------------------------------
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
320
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
321 class
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
322 OCTINTERP_API
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
323 ft_text_renderer : public base_text_renderer
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
324 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
325 public:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
326
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
327 enum
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
328 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
329 MODE_BBOX = 0,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
330 MODE_RENDER = 1
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
331 };
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
332
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
333 enum
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
334 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
335 ROTATION_0 = 0,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
336 ROTATION_90 = 1,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
337 ROTATION_180 = 2,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
338 ROTATION_270 = 3
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
339 };
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
340
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
341 public:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
342
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
343 ft_text_renderer (void)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
344 : base_text_renderer (), font (), bbox (1, 4, 0.0), halign (0),
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
345 xoffset (0), line_yoffset (0), yoffset (0), mode (MODE_BBOX),
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
346 color (dim_vector (1, 3), 0)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
347 { }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
348
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
349 ~ft_text_renderer (void) { }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
350
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
351 void visit (text_element_string& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
352
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
353 void visit (text_element_list& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
354
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
355 void visit (text_element_subscript& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
356
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
357 void visit (text_element_superscript& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
358
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
359 void visit (text_element_color& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
360
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
361 void visit (text_element_fontsize& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
362
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
363 void visit (text_element_fontname& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
364
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
365 void visit (text_element_fontstyle& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
366
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
367 void visit (text_element_symbol& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
368
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
369 void visit (text_element_combined& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
370
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
371 void reset (void);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
372
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
373 uint8NDArray get_pixels (void) const { return pixels; }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
374
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
375 Matrix get_boundingbox (void) const { return bbox; }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
376
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
377 uint8NDArray render (text_element *elt, Matrix& box,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
378 int rotation = ROTATION_0);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
379
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
380 Matrix get_extent (text_element *elt, double rotation = 0.0);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
381 Matrix get_extent (const std::string& txt, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
382 const caseless_str& interpreter);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
383
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
384 void set_font (const std::string& name, const std::string& weight,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
385 const std::string& angle, double size);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
386
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
387 void set_color (const Matrix& c);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
388
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
389 void set_mode (int m);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
390
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
391 void text_to_pixels (const std::string& txt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
392 uint8NDArray& pxls, Matrix& bbox,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
393 int halign, int valign, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
394 const caseless_str& interpreter,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
395 bool handle_rotation);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
396
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
397 private:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
398
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
399 int rotation_to_mode (double rotation) const;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
400
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
401 // No copying!
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
402
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
403 ft_text_renderer (const ft_text_renderer&);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
404
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
405 ft_text_renderer& operator = (const ft_text_renderer&);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
406
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
407 // Class to hold information about fonts and a strong
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
408 // reference to the font objects loaded by FreeType.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
409
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
410 class ft_font : public text_renderer::font
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
411 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
412 public:
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
413
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
414 ft_font (void)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
415 : text_renderer::font (), face (0) { }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
416
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
417 ft_font (const std::string& nm, const std::string& wt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
418 const std::string& ang, double sz, FT_Face f = 0)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
419 : text_renderer::font (nm, wt, ang, sz), face (f)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
420 { }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
421
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
422 ft_font (const ft_font& ft);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
423
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
424 ~ft_font (void)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
425 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
426 if (face)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
427 FT_Done_Face (face);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
428 }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
429
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
430 ft_font& operator = (const ft_font& ft);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
431
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
432 bool is_valid (void) const { return get_face (); }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
433
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
434 FT_Face get_face (void) const;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
435
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
436 private:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
437
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
438 mutable FT_Face face;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
439 };
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
440
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
441 void push_new_line (void);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
442
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
443 void update_line_bbox (void);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
444
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
445 void compute_bbox (void);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
446
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
447 int compute_line_xoffset (const Matrix& lb) const;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
448
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
449 FT_UInt process_character (FT_ULong code, FT_UInt previous = 0);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
450
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
451 public:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
452
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
453 void text_to_strlist (const std::string& txt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
454 std::list<text_renderer::string>& lst, Matrix& bbox,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
455 int halign, int valign, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
456 const caseless_str& interp);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
457
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
458 private:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
459
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
460 // The current font used by the renderer.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
461 ft_font font;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
462
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
463 // Used to stored the bounding box corresponding to the rendered text.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
464 // The bounding box has the form [x, y, w, h] where x and y represent the
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
465 // coordinates of the bottom left corner relative to the anchor point of
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
466 // the text (== start of text on the baseline). Due to font descent or
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
467 // multiple lines, the value y is usually negative.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
468 Matrix bbox;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
469
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
470 // Used to stored the rendered text. It's a 3D matrix with size MxNx4
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
471 // where M and N are the width and height of the bounding box.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
472 uint8NDArray pixels;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
473
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
474 // Used to store the bounding box of each line. This is used to layout
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
475 // multiline text properly.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
476 std::list<Matrix> line_bbox;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
477
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
478 // The current horizontal alignment. This is used to align multi-line text.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
479 int halign;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
480
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
481 // The X offset for the next glyph.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
482 int xoffset;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
483
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
484 // The Y offset of the baseline for the current line.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
485 int line_yoffset;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
486
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
487 // The Y offset of the baseline for the next glyph. The offset is relative
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
488 // to line_yoffset. The total Y offset is computed with:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
489 // line_yoffset + yoffset.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
490 int yoffset;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
491
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
492 // The current mode of the rendering process (box computing or rendering).
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
493 int mode;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
494
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
495 // The base color of the rendered text.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
496 uint8NDArray color;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
497
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
498 // A list of parsed strings to be used for printing.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
499 std::list<text_renderer::string> strlist;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
500
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
501 // The X offset of the baseline for the current line.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
502 int line_xoffset;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
503
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
504 };
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
505
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
506 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
507 ft_text_renderer::set_font (const std::string& name, const std::string& weight,
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
508 const std::string& angle, double size)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
509 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
510 // FIXME: take "fontunits" into account
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
511
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
512 font = ft_font (name, weight, angle, size, 0);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
513 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
514
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
515 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
516 ft_text_renderer::push_new_line (void)
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
517 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
518 switch (mode)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
519 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
520 case MODE_BBOX:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
521 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
522 // Create a new bbox entry based on the current font.
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
523
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
524 FT_Face face = font.get_face ();
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
525
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
526 if (face)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
527 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
528 int asc = face->size->metrics.ascender >> 6;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
529 int desc = face->size->metrics.descender >> 6;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
530 int h = face->size->metrics.height >> 6;
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
531
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
532 Matrix bb (1, 5, 0.0);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
533
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
534 bb(1) = desc;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
535 bb(3) = asc - desc;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
536 bb(4) = h;
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
537
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
538 line_bbox.push_back (bb);
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
539
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
540 xoffset = yoffset = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
541 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
542 }
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
543 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
544
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
545 case MODE_RENDER:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
546 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
547 // Move to the next line bbox, adjust xoffset based on alignment
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
548 // and yoffset based on the old and new line bbox.
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
549
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
550 Matrix old_bbox = line_bbox.front ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
551 line_bbox.pop_front ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
552 Matrix new_bbox = line_bbox.front ();
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
553
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
554 xoffset = line_xoffset = compute_line_xoffset (new_bbox);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
555 line_yoffset += (old_bbox(1) - (new_bbox(1) + new_bbox(3)));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
556 yoffset = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
557 }
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
558 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
559 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
560 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
561
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
562 int
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
563 ft_text_renderer::compute_line_xoffset (const Matrix& lb) const
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
564 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
565 if (! bbox.is_empty ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
566 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
567 switch (halign)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
568 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
569 case 0:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
570 return 0;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
571 case 1:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
572 return (bbox(2) - lb(2)) / 2;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
573 case 2:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
574 return (bbox(2) - lb(2));
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
575 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
576 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
577
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
578 return 0;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
579 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
580
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
581 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
582 ft_text_renderer::compute_bbox (void)
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
583 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
584 // Stack the various line bbox together and compute the final
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
585 // bounding box for the entire text string.
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
586
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
587 bbox = Matrix ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
588
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
589 switch (line_bbox.size ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
590 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
591 case 0:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
592 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
593
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
594 case 1:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
595 bbox = line_bbox.front ().extract (0, 0, 0, 3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
596 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
597
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
598 default:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
599 for (std::list<Matrix>::const_iterator it = line_bbox.begin ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
600 it != line_bbox.end (); ++it)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
601 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
602 if (bbox.is_empty ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
603 bbox = it->extract (0, 0, 0, 3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
604 else
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
605 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
606 bbox(1) -= (*it)(3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
607 bbox(3) += (*it)(3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
608 bbox(2) = xmax (bbox(2), (*it)(2));
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
609 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
610 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
611 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
612 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
613 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
614
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
615 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
616 ft_text_renderer::update_line_bbox (void)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
617 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
618 // Called after a font change, when in MODE_BBOX mode, to update the
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
619 // current line bbox with the new font metrics. This also includes the
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
620 // current yoffset, that is the offset of the current glyph's baseline
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
621 // the line's baseline.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
622
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
623 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
624 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
625 int asc = font.get_face ()->size->metrics.ascender >> 6;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
626 int desc = font.get_face ()->size->metrics.descender >> 6;
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
627
20471
25caa0deaabb Fix multi-line text bounding box when using subscripts (bug #45508)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20454
diff changeset
628 Matrix& bb = line_bbox.back ();
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
629
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
630 if ((yoffset + desc) < bb(1))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
631 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
632 // The new font goes below the bottom of the current bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
633
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
634 int delta = bb(1) - (yoffset + desc);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
635
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
636 bb(1) -= delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
637 bb(3) += delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
638 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
639
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
640 if ((yoffset + asc) > (bb(1) + bb(3)))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
641 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
642 // The new font goes above the top of the current bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
643
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
644 int delta = (yoffset + asc) - (bb(1) + bb(3));
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
645
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
646 bb(3) += delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
647 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
648 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
649 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
650
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
651 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
652 ft_text_renderer::set_mode (int m)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
653 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
654 mode = m;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
655
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
656 switch (mode)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
657 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
658 case MODE_BBOX:
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
659 xoffset = line_yoffset = yoffset = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
660 bbox = Matrix (1, 4, 0.0);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
661 line_bbox.clear ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
662 push_new_line ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
663 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
664
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
665 case MODE_RENDER:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
666 if (bbox.numel () != 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
667 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
668 ::warning ("ft_text_renderer: invalid bounding box, cannot render");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
669
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
670 xoffset = line_yoffset = yoffset = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
671 pixels = uint8NDArray ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
672 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
673 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
674 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
675 pixels = uint8NDArray (dim_vector (4, bbox(2), bbox(3)),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
676 static_cast<uint8_t> (0));
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
677 xoffset = compute_line_xoffset (line_bbox.front ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
678 line_yoffset = -bbox(1)-1;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
679 yoffset = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
680 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
681 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
682
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
683 default:
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
684 error ("ft_text_renderer: invalid mode '%d'", mode);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
685 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
686 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
687 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
688
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
689 FT_UInt
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
690 ft_text_renderer::process_character (FT_ULong code, FT_UInt previous)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
691 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
692 FT_Face face = font.get_face ();
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
693 FT_UInt glyph_index = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
694
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
695 if (face)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
696 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
697 glyph_index = FT_Get_Char_Index (face, code);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
698
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
699 if (code != '\n'
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
700 && (! glyph_index
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
701 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
702 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
703 glyph_index = 0;
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
704 warn_missing_glyph (code);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
705 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
706 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
707 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
708 switch (mode)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
709 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
710 case MODE_RENDER:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
711 if (code == '\n')
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
712 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
713 glyph_index = FT_Get_Char_Index (face, ' ');
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
714 if (! glyph_index
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
715 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
716 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
717 glyph_index = 0;
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
718 warn_missing_glyph (' ');
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
719 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
720 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
721 push_new_line ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
722 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
723 else if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
724 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
725 glyph_index = 0;
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
726 warn_glyph_render (code);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
727 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
728 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
729 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
730 FT_Bitmap& bitmap = face->glyph->bitmap;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
731 int x0, y0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
732
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
733 if (previous)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
734 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
735 FT_Vector delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
736
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
737 FT_Get_Kerning (face, previous, glyph_index,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
738 FT_KERNING_DEFAULT, &delta);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
739 xoffset += (delta.x >> 6);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
740 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
741
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
742 x0 = xoffset + face->glyph->bitmap_left;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
743 y0 = line_yoffset + yoffset + face->glyph->bitmap_top;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
744
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
745 // 'w' seems to have a negative -1
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
746 // face->glyph->bitmap_left, this is so we don't
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
747 // index out of bound, and assumes we we allocated
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
748 // the right amount of horizontal space in the bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
749 if (x0 < 0)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
750 x0 = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
751
20454
1a22083b5929 use different approach to avoid unsigned/signed comparison warning
John W. Eaton <jwe@octave.org>
parents: 20451
diff changeset
752 for (int r = 0; static_cast<unsigned int> (r) < bitmap.rows; r++)
1a22083b5929 use different approach to avoid unsigned/signed comparison warning
John W. Eaton <jwe@octave.org>
parents: 20451
diff changeset
753 for (int c = 0; static_cast<unsigned int> (c) < bitmap.width; c++)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
754 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
755 unsigned char pix = bitmap.buffer[r*bitmap.width+c];
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
756 if (x0+c < 0 || x0+c >= pixels.dim2 ()
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
757 || y0-r < 0 || y0-r >= pixels.dim3 ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
758 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
759 //::warning ("ft_text_renderer: pixel out of bound (char=%d, (x,y)=(%d,%d), (w,h)=(%d,%d)",
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
760 // str[i], x0+c, y0-r, pixels.dim2 (), pixels.dim3 ());
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
761 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
762 else if (pixels(3, x0+c, y0-r).value () == 0)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
763 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
764 pixels(0, x0+c, y0-r) = color(0);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
765 pixels(1, x0+c, y0-r) = color(1);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
766 pixels(2, x0+c, y0-r) = color(2);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
767 pixels(3, x0+c, y0-r) = pix;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
768 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
769 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
770
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
771 xoffset += (face->glyph->advance.x >> 6);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
772 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
773 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
774
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
775 case MODE_BBOX:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
776 if (code == '\n')
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
777 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
778 glyph_index = FT_Get_Char_Index (face, ' ');
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
779 if (! glyph_index
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
780 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
781 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
782 glyph_index = 0;
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
783 warn_missing_glyph (' ');
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
784 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
785 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
786 push_new_line ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
787 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
788 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
789 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
790 Matrix& bb = line_bbox.back ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
791
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
792 // If we have a previous glyph, use kerning information.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
793 // This usually means moving a bit backward before adding
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
794 // the next glyph. That is, "delta.x" is usually < 0.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
795 if (previous)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
796 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
797 FT_Vector delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
798
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
799 FT_Get_Kerning (face, previous, glyph_index,
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
800 FT_KERNING_DEFAULT, &delta);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
801
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
802 xoffset += (delta.x >> 6);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
803 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
804
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
805 // Extend current X offset box by the width of the current
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
806 // glyph. Then extend the line bounding box if necessary.
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
807
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
808 xoffset += (face->glyph->advance.x >> 6);
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
809 bb(2) = xmax (bb(2), xoffset);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
810 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
811 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
812 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
813 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
814 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
815
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
816 return glyph_index;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
817 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
818
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
819 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
820 ft_text_renderer::text_to_strlist (const std::string& txt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
821 std::list<text_renderer::string>& lst,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
822 Matrix& box,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
823 int ha, int va, double rot,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
824 const caseless_str& interp)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
825 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
826 uint8NDArray pxls;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
827
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
828 // First run text_to_pixels which will also build the string list
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
829
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
830 text_to_pixels (txt, pxls, box, ha, va, rot, interp, false);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
831
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
832 lst = strlist;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
833 }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
834
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
835 void
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
836 ft_text_renderer::visit (text_element_string& e)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
837 {
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
838 if (font.is_valid ())
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
839 {
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
840 FT_UInt glyph_index, previous = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
841
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
842 std::string str = e.string_value ();
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17898
diff changeset
843 size_t n = str.length ();
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17898
diff changeset
844 size_t curr = 0;
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
845 size_t idx = 0;
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
846 mbstate_t ps;
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
847 memset (&ps, 0, sizeof (ps)); // Initialize state to 0.
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
848 wchar_t wc;
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
849
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
850 text_renderer::string fs (str, font, xoffset, yoffset);
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
851
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
852 while (n > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
853 {
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
854 size_t r = gnulib::mbrtowc (&wc, str.data () + curr, n, &ps);
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
855
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
856 if (r > 0
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
857 && r != static_cast<size_t> (-1)
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
858 && r != static_cast<size_t> (-2))
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
859 {
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
860 n -= r;
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
861 curr += r;
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
862
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
863 if (wc == L'\n')
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
864 {
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20622
diff changeset
865 // Finish previous string in srtlist before processing
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
866 // the newline character
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
867 fs.set_y (line_yoffset + yoffset);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
868 fs.set_color (color);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
869 std::string s = str.substr (idx, curr - idx - 1);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
870 if (! s.empty ())
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
871 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
872 fs.set_string (s);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
873 strlist.push_back (fs);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
874 }
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
875 }
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
876
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
877 glyph_index = process_character (wc, previous);
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
878
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
879 if (wc == L'\n')
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
880 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
881 previous = 0;
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
882 // Start a new string in strlist
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
883 idx = curr;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
884 fs = text_renderer::string (str.substr (idx), font,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
885 line_xoffset, yoffset);
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20622
diff changeset
886
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
887 }
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
888 else
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
889 previous = glyph_index;
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
890 }
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
891 else
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
892 {
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
893 if (r != 0)
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
894 ::warning ("ft_text_renderer: failed to decode string `%s' with "
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
895 "locale `%s'", str.c_str (),
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
896 std::setlocale (LC_CTYPE, 0));
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
897 break;
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
898 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
899 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
900
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
901 if (! fs.get_string ().empty ())
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
902 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
903 fs.set_y (line_yoffset + yoffset);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
904 fs.set_color (color);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
905 strlist.push_back (fs);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
906 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
907 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
908 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
909
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
910 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
911 ft_text_renderer::visit (text_element_list& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
912 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
913 // Save and restore (after processing the list) the current font and color.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
914
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
915 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
916 uint8NDArray saved_color (color);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
917
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
918 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
919
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
920 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
921 color = saved_color;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
922 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
923
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
924 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
925 ft_text_renderer::visit (text_element_subscript& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
926 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
927 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
928 int saved_line_yoffset = line_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
929 int saved_yoffset = yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
930
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
931 set_font (font.get_name (), font.get_weight (), font.get_angle (),
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
932 font.get_size () - 2);
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
933
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
934 if (font.is_valid ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
935 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
936 int h = font.get_face ()->size->metrics.height >> 6;
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
937
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
938 // Shifting the baseline by 2/3 the font height seems to produce
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
939 // decent result.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
940 yoffset -= (h * 2) / 3;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
941
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
942 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
943 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
944 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
945
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
946 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
947
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
948 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
949 // If line_yoffset changed, this means we moved to a new line; hence yoffset
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
950 // cannot be restored, because the saved value is not relevant anymore.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
951 if (line_yoffset == saved_line_yoffset)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
952 yoffset = saved_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
953 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
954
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
955 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
956 ft_text_renderer::visit (text_element_superscript& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
957 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
958 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
959 int saved_line_yoffset = line_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
960 int saved_yoffset = yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
961
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
962 set_font (font.get_name (), font.get_weight (), font.get_angle (),
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
963 font.get_size () - 2);
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
964
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
965 if (saved_font.is_valid ())
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
966 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
967 int s_asc = saved_font.get_face ()->size->metrics.ascender >> 6;
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
968
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
969 // Shifting the baseline by 2/3 base font ascender seems to produce
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
970 // decent result.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
971 yoffset += (s_asc * 2) / 3;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
972
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
973 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
974 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
975 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
976
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
977 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
978
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
979 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
980 // If line_yoffset changed, this means we moved to a new line; hence yoffset
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
981 // cannot be restored, because the saved value is not relevant anymore.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
982 if (line_yoffset == saved_line_yoffset)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
983 yoffset = saved_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
984 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
985
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
986 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
987 ft_text_renderer::visit (text_element_color& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
988 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
989 if (mode == MODE_RENDER)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
990 set_color (e.get_color ());
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
991 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
992
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
993 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
994 ft_text_renderer::visit (text_element_fontsize& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
995 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
996 double sz = e.get_fontsize ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
997
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
998 // FIXME: Matlab documentation says that the font size is expressed
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
999 // in the text object FontUnit.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1000
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1001 set_font (font.get_name (), font.get_weight (), font.get_angle (), sz);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1002
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1003 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1004 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1005 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1006
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1007 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1008 ft_text_renderer::visit (text_element_fontname& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1009 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1010 set_font (e.get_fontname (), font.get_weight (), font.get_angle (),
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1011 font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1012
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1013 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1014 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1015 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1016
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1017 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1018 ft_text_renderer::visit (text_element_fontstyle& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1019 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1020 switch (e.get_fontstyle ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1021 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1022 case text_element_fontstyle::normal:
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1023 set_font (font.get_name (), "normal", "normal", font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1024 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1025
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1026 case text_element_fontstyle::bold:
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1027 set_font (font.get_name (), "bold", "normal", font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1028 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1029
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1030 case text_element_fontstyle::italic:
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1031 set_font (font.get_name (), "normal", "italic", font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1032 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1033
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1034 case text_element_fontstyle::oblique:
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1035 set_font (font.get_name (), "normal", "oblique", font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1036 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1037 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1038
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1039 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1040 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1041 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1042
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1043 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1044 ft_text_renderer::visit (text_element_symbol& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1045 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1046 uint32_t code = e.get_symbol_code ();
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20622
diff changeset
1047
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1048 text_renderer::string fs (std::string ("-"), font, xoffset, yoffset);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1049
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1050 if (code != text_element_symbol::invalid_code && font.is_valid ())
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1051 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1052 process_character (code);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1053 fs.set_code (code);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1054 }
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1055 else if (font.is_valid ())
17327
fe6518a1d87c Move TeX symbol decoding into the lexer (bug #39831).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17324
diff changeset
1056 ::warning ("ignoring unknown symbol: %d", e.get_symbol ());
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1057
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1058 if (fs.get_code ())
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1059 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1060 fs.set_y (line_yoffset + yoffset);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1061 fs.set_color (color);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1062 strlist.push_back (fs);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1063 }
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1064 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1065
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1066 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1067 ft_text_renderer::visit (text_element_combined& e)
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1068 {
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1069 int saved_xoffset = xoffset;
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1070 int max_xoffset = xoffset;
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1071
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1072 for (text_element_combined::iterator it = e.begin (); it != e.end (); ++it)
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1073 {
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1074 xoffset = saved_xoffset;
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1075 (*it)->accept (*this);
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1076 max_xoffset = xmax (xoffset, max_xoffset);
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1077 }
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1078
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1079 xoffset = max_xoffset;
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1080 }
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1081
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1082 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1083 ft_text_renderer::reset (void)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1084 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1085 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1086 set_color (Matrix (1, 3, 0.0));
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1087 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1088
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1089 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1090 ft_text_renderer::set_color (const Matrix& c)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1091 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1092 if (c.numel () == 3)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1093 {
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1094 color(0) = static_cast<uint8_t> (c(0)*255);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1095 color(1) = static_cast<uint8_t> (c(1)*255);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1096 color(2) = static_cast<uint8_t> (c(2)*255);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1097 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1098 else
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1099 ::warning ("ft_text_renderer::set_color: invalid color");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1100 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1101
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1102 uint8NDArray
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1103 ft_text_renderer::render (text_element *elt, Matrix& box, int rotation)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1104 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1105 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1106 elt->accept (*this);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
1107 compute_bbox ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1108 box = bbox;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1109
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1110 set_mode (MODE_RENDER);
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1111 // Clear the list of parsed strings
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1112 strlist.clear ();
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1113
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1114 if (pixels.numel () > 0)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1115 {
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1116 elt->accept (*this);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1117
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1118 switch (rotation)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1119 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1120 case ROTATION_0:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1121 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1122
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1123 case ROTATION_90:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1124 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1125 Array<octave_idx_type> perm (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1126 perm(0) = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1127 perm(1) = 2;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1128 perm(2) = 1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1129 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1130
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1131 Array<idx_vector> idx (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1132 idx(0) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1133 idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1134 idx(2) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1135 pixels = uint8NDArray (pixels.index (idx));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1136 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1137 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1138
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1139 case ROTATION_180:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1140 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1141 Array<idx_vector> idx (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1142 idx(0) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1143 idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1);
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21334
diff changeset
1144 idx(2) = idx_vector (pixels.dim3 ()-1, -1, -1);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1145 pixels = uint8NDArray (pixels.index (idx));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1146 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1147 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1148
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1149 case ROTATION_270:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1150 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1151 Array<octave_idx_type> perm (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1152 perm(0) = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1153 perm(1) = 2;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1154 perm(2) = 1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1155 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1156
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1157 Array<idx_vector> idx (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1158 idx(0) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1159 idx(1) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1160 idx(2) = idx_vector (pixels.dim3 ()-1, -1, -1);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1161 pixels = uint8NDArray (pixels.index (idx));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1162 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1163 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1164 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1165 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1166
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1167 return pixels;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1168 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1169
16201
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1170 // Note:
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1171 // x-extent accurately measures width of glyphs.
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1172 // y-extent is overly large because it is measured from baseline-to-baseline.
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1173 // Calling routines, such as ylabel, may need to account for this mismatch.
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1174
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1175 Matrix
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1176 ft_text_renderer::get_extent (text_element *elt, double rotation)
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1177 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1178 set_mode (MODE_BBOX);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1179 elt->accept (*this);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
1180 compute_bbox ();
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1181
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1182 Matrix extent (1, 2, 0.0);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1183
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1184 switch (rotation_to_mode (rotation))
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1185 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1186 case ROTATION_0:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1187 case ROTATION_180:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1188 extent(0) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1189 extent(1) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1190 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1191
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1192 case ROTATION_90:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1193 case ROTATION_270:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1194 extent(0) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1195 extent(1) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1196 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1197
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1198 return extent;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1199 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1200
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1201 Matrix
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1202 ft_text_renderer::get_extent (const std::string& txt, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1203 const caseless_str& interpreter)
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1204 {
17269
5b088598df1d Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16892
diff changeset
1205 text_element *elt = text_parser::parse (txt, interpreter);
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1206 Matrix extent = get_extent (elt, rotation);
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1207 delete elt;
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
1208
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1209 return extent;
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1210 }
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1211
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1212 int
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1213 ft_text_renderer::rotation_to_mode (double rotation) const
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1214 {
17526
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1215 // Clip rotation to range [0, 360]
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1216 while (rotation < 0)
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1217 rotation += 360.0;
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1218 while (rotation > 360.0)
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1219 rotation -= 360.0;
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1220
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1221 if (rotation == 0.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1222 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1223 else if (rotation == 90.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1224 return ROTATION_90;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1225 else if (rotation == 180.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1226 return ROTATION_180;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1227 else if (rotation == 270.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1228 return ROTATION_270;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1229 else
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1230 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1231 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1232
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1233 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1234 ft_text_renderer::text_to_pixels (const std::string& txt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1235 uint8NDArray& pxls, Matrix& box,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1236 int _halign, int valign, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1237 const caseless_str& interpreter,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1238 bool handle_rotation)
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1239 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1240 int rot_mode = rotation_to_mode (rotation);
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
1241
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
1242 halign = _halign;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1243
17269
5b088598df1d Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16892
diff changeset
1244 text_element *elt = text_parser::parse (txt, interpreter);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1245 pxls = render (elt, box, rot_mode);
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1246 delete elt;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1247
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1248 if (pxls.is_empty ())
20974
1edf15793cac maint: Use is_empty rather than "numel () == 0" for clarity.
Rik <rik@octave.org>
parents: 20956
diff changeset
1249 return; // nothing to render
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1250
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1251 switch (halign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1252 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1253 case 1:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1254 box(0) = -box(2)/2;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1255 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1256
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1257 case 2:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1258 box(0) = -box(2);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1259 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1260
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1261 default:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1262 box(0) = 0;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1263 break;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1264 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1265
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1266 switch (valign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1267 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1268 case 1:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1269 box(1) = -box(3)/2;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1270 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1271
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1272 case 2:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1273 box(1) = -box(3);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1274 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1275
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1276 case 3:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1277 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1278
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1279 case 4:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1280 box(1) = -box(3)-box(1);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1281 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1282
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1283 default:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1284 box(1) = 0;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1285 break;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1286 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1287
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1288 if (handle_rotation)
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1289 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1290 switch (rot_mode)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1291 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1292 case ROTATION_90:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1293 std::swap (box(0), box(1));
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1294 std::swap (box(2), box(3));
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1295 box(0) = -box(0)-box(2);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1296 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1297
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1298 case ROTATION_180:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1299 box(0) = -box(0)-box(2);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1300 box(1) = -box(1)-box(3);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1301 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1302
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1303 case ROTATION_270:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1304 std::swap (box(0), box(1));
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1305 std::swap (box(2), box(3));
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1306 box(1) = -box(1)-box(3);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1307 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1308 }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1309 }
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1310 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1311
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1312 ft_text_renderer::ft_font::ft_font (const ft_font& ft)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1313 : text_renderer::font (ft), face (0)
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1314 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1315 #if defined (HAVE_FT_REFERENCE_FACE)
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1316 FT_Face ft_face = ft.get_face ();
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1317
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1318 if (ft_face && FT_Reference_Face (ft_face) == 0)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1319 face = ft_face;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1320 #endif
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1321 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1322
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1323 ft_text_renderer::ft_font&
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1324 ft_text_renderer::ft_font::operator = (const ft_font& ft)
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1325 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1326 if (&ft != this)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1327 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1328 text_renderer::font::operator = (ft);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1329
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1330 if (face)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1331 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1332 FT_Done_Face (face);
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1333 face = 0;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1334 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1335
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1336 #if defined (HAVE_FT_REFERENCE_FACE)
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1337 FT_Face ft_face = ft.get_face ();
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1338
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1339 if (ft_face && FT_Reference_Face (ft_face) == 0)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1340 face = ft_face;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1341 #endif
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1342 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1343
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1344 return *this;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1345 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1346
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1347 FT_Face
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1348 ft_text_renderer::ft_font::get_face (void) const
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1349 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1350 if (! face && ! name.empty ())
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1351 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1352 face = ft_manager::get_font (name, weight, angle, size);
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1353
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1354 if (face)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1355 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1356 if (FT_Set_Char_Size (face, 0, size*64, 0, 0))
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1357 ::warning ("ft_text_renderer: unable to set font size to %g", size);
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1358 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1359 else
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1360 ::warning ("ft_text_renderer: unable to load appropriate font");
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1361 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1362
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1363 return face;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1364 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1365
20945
9d9270e2f98f eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
1366 #endif
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1367
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1368 base_text_renderer *
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1369 make_ft_text_renderer (void)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1370 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1371 #if defined (HAVE_FREETYPE)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1372 return new ft_text_renderer ();
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1373 #else
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1374 return 0;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1375 #endif
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1376 }