annotate libinterp/corefcn/gl2ps-renderer.cc @ 19925:a20f86786abb

style fixes * gl2ps-renderer.h, gl2ps-renderer.cc: Style fixes.
author John W. Eaton <jwe@octave.org>
date Mon, 02 Mar 2015 21:42:31 -0500
parents 00c3f2021cad
children 1929d9218ac0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
1 /*
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19727
diff changeset
3 Copyright (C) 2009-2015 Shai Ayal
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
4
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
5 This file is part of Octave.
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
6
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
10 option) any later version.
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
11
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
15 for more details.
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
16
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
20
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
21 */
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
22
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
24 #include <config.h>
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
25 #endif
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
26
19682
16f21db320b5 Fix compilation error when building without gl2ps
Mike Miller <mtmiller@ieee.org>
parents: 19673
diff changeset
27 #include "error.h"
16f21db320b5 Fix compilation error when building without gl2ps
Mike Miller <mtmiller@ieee.org>
parents: 19673
diff changeset
28 #include "gl2ps-renderer.h"
16f21db320b5 Fix compilation error when building without gl2ps
Mike Miller <mtmiller@ieee.org>
parents: 19673
diff changeset
29
17797
06a850f83dd4 build: Remove embedded gl2ps. Require gl2ps as external dependency.
Rik <rik@octave.org>
parents: 17787
diff changeset
30 #ifdef HAVE_GL2PS_H
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
31
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
32 #include <cstdio>
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
33
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
34 #include "lo-mappers.h"
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
35 #include "oct-locbuf.h"
19673
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
36 #include "unwind-prot.h"
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
37
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
38 #include "gl2ps.h"
19673
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
39 #include "sysdep.h"
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
40
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
41 void
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
42 glps_renderer::draw (const graphics_object& go, const std::string& print_cmd)
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
43 {
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
44 static bool in_draw = false;
16732
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
45 static std::string old_print_cmd;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
46
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
47 if (!in_draw)
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
48 {
19924
00c3f2021cad use unwind_protect to restore static variable value (bug #44406)
John W. Eaton <jwe@octave.org>
parents: 19907
diff changeset
49 unwind_protect frame;
00c3f2021cad use unwind_protect to restore static variable value (bug #44406)
John W. Eaton <jwe@octave.org>
parents: 19907
diff changeset
50
00c3f2021cad use unwind_protect to restore static variable value (bug #44406)
John W. Eaton <jwe@octave.org>
parents: 19907
diff changeset
51 frame.protect_var (in_draw);
00c3f2021cad use unwind_protect to restore static variable value (bug #44406)
John W. Eaton <jwe@octave.org>
parents: 19907
diff changeset
52
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
53 in_draw = true;
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
54
10857
2224236440c0 add more terminal types to gl2ps-renderer
Shai Ayal <shaiay@users.sourceforge.net>
parents: 10464
diff changeset
55 GLint gl2ps_term;
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
56 if (term.find ("eps") != std::string::npos)
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
57 gl2ps_term = GL2PS_EPS;
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
58 else if (term.find ("pdf") != std::string::npos)
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
59 gl2ps_term = GL2PS_PDF;
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
60 else if (term.find ("ps") != std::string::npos)
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
61 gl2ps_term = GL2PS_PS;
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
62 else if (term.find ("svg") != std::string::npos)
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
63 gl2ps_term = GL2PS_SVG;
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
64 else if (term.find ("pgf") != std::string::npos)
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
65 gl2ps_term = GL2PS_PGF;
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
66 else if (term.find ("tex") != std::string::npos)
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
67 gl2ps_term = GL2PS_TEX;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
68 else
10857
2224236440c0 add more terminal types to gl2ps-renderer
Shai Ayal <shaiay@users.sourceforge.net>
parents: 10464
diff changeset
69 {
18992
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
70 error ("gl2ps-renderer::draw: Unknown terminal %s", term.c_str ());
10857
2224236440c0 add more terminal types to gl2ps-renderer
Shai Ayal <shaiay@users.sourceforge.net>
parents: 10464
diff changeset
71 return;
2224236440c0 add more terminal types to gl2ps-renderer
Shai Ayal <shaiay@users.sourceforge.net>
parents: 10464
diff changeset
72 }
2224236440c0 add more terminal types to gl2ps-renderer
Shai Ayal <shaiay@users.sourceforge.net>
parents: 10464
diff changeset
73
2224236440c0 add more terminal types to gl2ps-renderer
Shai Ayal <shaiay@users.sourceforge.net>
parents: 10464
diff changeset
74 GLint gl2ps_text = 0;
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
75 if (term.find ("notxt") != std::string::npos)
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
76 gl2ps_text = GL2PS_NO_TEXT;
10857
2224236440c0 add more terminal types to gl2ps-renderer
Shai Ayal <shaiay@users.sourceforge.net>
parents: 10464
diff changeset
77
14389
6b2448555bbd Fix Z-order stacking of axis background for FLTK printing (bug #35559)
Rik <octave@nomad.inbox5.com>
parents: 14203
diff changeset
78 // Default sort order optimizes for 3D plots
6b2448555bbd Fix Z-order stacking of axis background for FLTK printing (bug #35559)
Rik <octave@nomad.inbox5.com>
parents: 14203
diff changeset
79 GLint gl2ps_sort = GL2PS_BSP_SORT;
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
80
18700
652d9ed6f88d Fix printing of axis grid lines above/below line objects based on "layer".
Rik <rik@octave.org>
parents: 18099
diff changeset
81 // For 2D plots we can use a simpler Z-depth sorting algorithm
652d9ed6f88d Fix printing of axis grid lines above/below line objects based on "layer".
Rik <rik@octave.org>
parents: 18099
diff changeset
82 if (term.find ("is2D") != std::string::npos)
652d9ed6f88d Fix printing of axis grid lines above/below line objects based on "layer".
Rik <rik@octave.org>
parents: 18099
diff changeset
83 gl2ps_sort = GL2PS_SIMPLE_SORT;
14389
6b2448555bbd Fix Z-order stacking of axis background for FLTK printing (bug #35559)
Rik <octave@nomad.inbox5.com>
parents: 14203
diff changeset
84
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
85 GLint state = GL2PS_OVERFLOW;
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
86 GLint buffsize = 0;
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
87
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
88 while (state == GL2PS_OVERFLOW)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
89 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
90 // For LaTeX output the fltk print process uses 2 drawnow() commands.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
91 // The first one is for the pdf/ps/eps graph to be included. The
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
92 // print_cmd is saved as old_print_cmd. Then the second drawnow()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
93 // outputs the tex-file and the graphic filename to be included is
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
94 // extracted from old_print_cmd.
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
95
16732
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
96 std::string include_graph;
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
97
19907
d575cd1e0da7 Replace std::size_t with bare size_t for conformity to rest of code.
Rik <rik@octave.org>
parents: 19743
diff changeset
98 size_t found_redirect = old_print_cmd.find (">");
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
99
16732
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
100 if (found_redirect != std::string::npos)
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
101 include_graph = old_print_cmd.substr (found_redirect + 1);
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
102 else
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
103 include_graph = old_print_cmd;
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
104
19907
d575cd1e0da7 Replace std::size_t with bare size_t for conformity to rest of code.
Rik <rik@octave.org>
parents: 19743
diff changeset
105 size_t n_begin = include_graph.find_first_not_of (" ");
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
106
16732
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
107 if (n_begin != std::string::npos)
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
108 {
19907
d575cd1e0da7 Replace std::size_t with bare size_t for conformity to rest of code.
Rik <rik@octave.org>
parents: 19743
diff changeset
109 size_t n_end = include_graph.find_last_not_of (" ");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
110 include_graph = include_graph.substr (n_begin,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
111 n_end - n_begin + 1);
16732
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
112 }
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
113 else
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
114 include_graph = "foobar-inc";
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
115
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
116 buffsize += 1024*1024;
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
117
18992
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
118 // GL2PS_SILENT was removed to allow gl2ps printing errors on stderr
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
119 GLint ret = gl2psBeginPage ("glps_renderer figure", "Octave", 0,
18992
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
120 gl2ps_term, gl2ps_sort,
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
121 (GL2PS_NO_BLENDING
18992
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
122 | GL2PS_OCCLUSION_CULL
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
123 | GL2PS_BEST_ROOT
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
124 | gl2ps_text
19727
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
125 | GL2PS_NO_PS3_SHADING
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
126 | GL2PS_USE_CURRENT_VIEWPORT),
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
127 GL_RGBA, 0, 0, 0, 0, 0,
18992
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
128 buffsize, fp, include_graph.c_str ());
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
129 if (ret == GL2PS_ERROR)
19727
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
130 {
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
131 old_print_cmd.clear ();
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
132 error ("gl2ps-renderer::draw: gl2psBeginPage returned GL2PS_ERROR");
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
133 return;
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
134 }
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
135
16732
3806afcf974a Include graphics image file name in latex file for {eps,pdf,ps}latex output.
Ben Abbott <bpabbott@mac.com>
parents: 15195
diff changeset
136 old_print_cmd = print_cmd;
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
137
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
138 opengl_renderer::draw (go);
18992
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
139
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
140 // Without glFinish () there may primitives be missing in the
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
141 // gl2ps output.
19727
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
142 glFinish ();
18992
c9f960441513 Overhaul FLTK plotting and printing
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18770
diff changeset
143
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
144 state = gl2psEndPage ();
19727
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
145
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
146 if (state == GL2PS_NO_FEEDBACK)
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
147 {
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
148 warning ("gl2ps-renderer::draw: empty feedback buffer and/or nothing else to print");
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
149 }
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
150 else if (state == GL2PS_ERROR)
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
151 {
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
152 old_print_cmd.clear ();
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
153 error ("gl2ps-renderer::draw: gl2psEndPage returned GL2PS_ERROR");
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
154 return;
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
155 }
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
156
19727
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
157 // Don't check state for GL2PS_UNINITIALIZED (should never happen)
05b40890bbb2 gl2ps-renderer.cc: Add errors and warnings, replace glFlush with glFinish
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19682
diff changeset
158 // GL2PS_OVERFLOW (see while loop) or GL2PS_SUCCESS
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
159 }
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
160 }
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
161 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
162 opengl_renderer::draw (go);
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
163 }
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
164
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
165 int
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
166 glps_renderer::alignment_to_mode (int ha, int va) const
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
167 {
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
168 int gl2psa = GL2PS_TEXT_BL;
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
169
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
170 if (ha == 0)
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
171 {
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
172 if (va == 0 || va == 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
173 gl2psa=GL2PS_TEXT_BL;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
174 else if (va == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
175 gl2psa=GL2PS_TEXT_TL;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
176 else if (va == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
177 gl2psa=GL2PS_TEXT_CL;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
178 }
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
179 else if (ha == 2)
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
180 {
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
181 if (va == 0 || va == 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
182 gl2psa=GL2PS_TEXT_BR;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
183 else if (va == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
184 gl2psa=GL2PS_TEXT_TR;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
185 else if (va == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
186 gl2psa=GL2PS_TEXT_CR;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
187 }
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
188 else if (ha == 1)
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
189 {
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
190 if (va == 0 || va == 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
191 gl2psa=GL2PS_TEXT_B;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
192 else if (va == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
193 gl2psa=GL2PS_TEXT_T;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
194 else if (va == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
195 gl2psa=GL2PS_TEXT_C;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
196 }
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
197
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
198 return gl2psa;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
199 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
200
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
201 Matrix
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
202 glps_renderer::render_text (const std::string& txt,
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
203 double x, double y, double z,
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
204 int ha, int va, double rotation)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
205 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
206 if (txt.empty ())
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
207 return Matrix (1, 4, 0.0);
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
208
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
209 glRasterPos3d (x, y, z);
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
210
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
211 gl2psTextOpt (txt.c_str (), fontname.c_str (), fontsize,
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
212 alignment_to_mode (ha, va), rotation);
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
213
17861
870f3e12e163 maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents: 17797
diff changeset
214 // FIXME?
18770
333901476119 maint: Use "FreeType" rather than "freetype" in messages and comments.
Rik <rik@octave.org>
parents: 18733
diff changeset
215 // We have no way of getting a bounding box from gl2ps, so we use FreeType.
9834
92d8f35ff217 compute bounding boxes for text in opengl graphics backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9798
diff changeset
216 Matrix bbox;
92d8f35ff217 compute bounding boxes for text in opengl graphics backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9798
diff changeset
217 uint8NDArray pixels;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
218 text_to_pixels (txt, pixels, bbox, 0, 0, rotation);
19925
a20f86786abb style fixes
John W. Eaton <jwe@octave.org>
parents: 19924
diff changeset
219
9834
92d8f35ff217 compute bounding boxes for text in opengl graphics backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9798
diff changeset
220 return bbox;
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
221 }
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
222
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
223 void
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
224 glps_renderer::set_font (const base_properties& props)
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
225 {
9834
92d8f35ff217 compute bounding boxes for text in opengl graphics backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9798
diff changeset
226 opengl_renderer::set_font (props);
92d8f35ff217 compute bounding boxes for text in opengl graphics backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9798
diff changeset
227
19081
1288a2f27769 Handle non "points" fontunits properties (bug # 40158)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18992
diff changeset
228 fontsize = props.get ("fontsize_points").double_value ();
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
229
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
230 caseless_str fn = props.get ("fontname").string_value ();
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
231 fontname = "";
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
232 if (fn == "times" || fn == "times-roman")
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
233 fontname = "Times-Roman";
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
234 else if (fn == "courier")
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
235 fontname = "Courier";
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
236 else if (fn == "symbol")
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
237 fontname = "Symbol";
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
238 else if (fn == "zapfdingbats")
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
239 fontname = "ZapfDingbats";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
240 else
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
241 fontname = "Helvetica";
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
242
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
243 // FIXME: add support for bold and italic
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
244 }
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
245
9950
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
246 template <typename T>
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
247 static void
18693
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
248 draw_pixels (GLsizei w, GLsizei h, GLenum format, const T *data, float maxval)
9950
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
249 {
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
250 OCTAVE_LOCAL_BUFFER (GLfloat, a, 3*w*h);
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
251
18693
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
252 // Convert to GL_FLOAT as it is the only type gl2ps accepts.
18714
ee7b23a48947 Clean up a few compiler warnings.
Rik <rik@octave.org>
parents: 18705
diff changeset
253 for (int i = 0; i < 3*w*h; i++)
18693
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
254 a[i] = data[i] / maxval;
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18693
diff changeset
255
9950
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
256 gl2psDrawPixels (w, h, 0, 0, format, GL_FLOAT, a);
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
257 }
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
258
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
259 void
9950
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
260 glps_renderer::draw_pixels (GLsizei w, GLsizei h, GLenum format,
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
261 GLenum type, const GLvoid *data)
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
262 {
18693
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
263 // gl2psDrawPixels only supports the GL_FLOAT type.
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
264 // Other formats, such as uint8, must be converted first.
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
265 if (type == GL_UNSIGNED_BYTE)
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
266 ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data), 255.0f);
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
267 else if (type == GL_UNSIGNED_SHORT)
3277514f36da Fix inverted colors when printing uint8/uint16 images (bug #42107).
Rik <rik@octave.org>
parents: 17861
diff changeset
268 ::draw_pixels (w, h, format, static_cast<const GLushort *> (data), 65535.0f);
9950
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
269 else
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
270 gl2psDrawPixels (w, h, 0, 0, format, type, data);
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
271 }
7dedfd70dd9f image printing for fltk backend
Shai Ayal <shaiay@users.sourceforge.net>
parents: 9834
diff changeset
272
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
273 void
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
274 glps_renderer::draw_text (const text::properties& props)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
275 {
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12322
diff changeset
276 if (props.get_string ().is_empty ())
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
277 return;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
278
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
279 set_font (props);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
280 set_color (props.get_color_rgb ());
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
281
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
282 const Matrix pos = get_transform ().scale (props.get_data_position ());
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17861
diff changeset
283 int halign = 0;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17861
diff changeset
284 int valign = 0;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
285
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
286 if (props.horizontalalignment_is ("center"))
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
287 halign = 1;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
288 else if (props.horizontalalignment_is ("right"))
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
289 halign = 2;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
290
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
291 if (props.verticalalignment_is ("top"))
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
292 valign = 2;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
293 else if (props.verticalalignment_is ("baseline"))
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
294 valign = 3;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
295 else if (props.verticalalignment_is ("middle"))
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
296 valign = 1;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
297
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
298 // FIXME: handle margin and surrounding box
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
299
14468
d16638f73691 Modify gl2ps_renderer.cc to properly specificy 2D/3D text object positions.
Konstantinos Poulios <logari81@googlemail.com>
parents: 14418
diff changeset
300 glRasterPos3d (pos(0), pos(1), pos.numel () > 2 ? pos(2) : 0.0);
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12322
diff changeset
301
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12322
diff changeset
302 octave_value string_prop = props.get_string ();
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12322
diff changeset
303
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12322
diff changeset
304 string_vector sv = string_prop.all_strings ();
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12322
diff changeset
305
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12322
diff changeset
306 std::string s = sv.join ("\n");
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12322
diff changeset
307
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12965
diff changeset
308 gl2psTextOpt (s.c_str (), fontname.c_str (), fontsize,
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
309 alignment_to_mode (halign, valign), props.get_rotation ());
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
310 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10955
diff changeset
311
19673
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
312 static void
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
313 safe_pclose (FILE *f)
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
314 {
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
315 if (f)
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
316 octave_pclose (f);
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
317 }
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
318
9798
2d6a5af744b6 printing for fltk backend using gl2ps
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
319 #endif
19673
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
320
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
321 void
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
322 gl2ps_print (const graphics_object& fig, const std::string& cmd,
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
323 const std::string& term)
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
324 {
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
325 #ifdef HAVE_GL2PS_H
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
326
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
327 FILE *fp = octave_popen (cmd.c_str (), "w");
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
328
19743
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
329 if (fp)
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
330 {
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
331 unwind_protect frame;
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
332
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
333 frame.add_fcn (safe_pclose, fp);
19673
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
334
19743
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
335 glps_renderer rend (fp, term);
19673
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
336
19743
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
337 rend.draw (fig, cmd);
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
338 }
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
339 else
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
340 error ("print: failed to open pipe for gl2ps renderer");
19673
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
341
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
342 #else
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
343
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
344 error ("print: printing not available without gl2ps library");
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
345
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
346 #endif
61cc00ebac60 move opengl printing code from __init_fltk__.cc to gl2ps-renderer.cc
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
347 }