4 * Copyright (C) 1999, 2000 Rasca, Berlin
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 #include <gnumeric-config.h>
22 #include <glib/gi18n-lib.h>
24 #include "workbook-view.h"
32 #include <goffice/goffice.h>
35 #include <gsf/gsf-output.h>
38 * escape special characters .. needs work
41 roff_fprintf (GsfOutput
*output
, GnmCell
*cell
)
46 GnmStyle
const *style
;
48 if (gnm_cell_is_empty (cell
))
51 style
= gnm_cell_get_style (cell
);
52 if (style
!= NULL
&& gnm_style_get_contents_hidden (style
))
55 s
= gnm_cell_get_rendered_text (cell
);
58 for (i
= 0; i
< len
; i
++) {
61 gsf_output_printf (output
, "\\.");
64 gsf_output_printf (output
, "\\\\");
67 gsf_output_printf (output
, "%c", *p
);
76 /* default point size */
80 * write every sheet of the workbook to a roff file
82 * FIXME: Should roff quote sheet name (and everything else)
85 roff_file_save (GOFileSaver
const *fs
, GOIOContext
*io_context
,
86 WorkbookView
const *wb_view
, GsfOutput
*output
)
90 int row
, col
, fontsize
, v_size
;
91 Workbook
*wb
= wb_view_get_workbook (wb_view
);
93 g_return_if_fail (wb
!= NULL
);
95 gsf_output_printf (output
, ".\\\" TROFF file\n");
96 gsf_output_printf (output
, ".fo ''%%''\n");
97 sheets
= workbook_sheets (wb
);
98 for (ptr
= sheets
; ptr
!= NULL
; ptr
= ptr
->next
) {
99 Sheet
*sheet
= ptr
->data
;
100 GnmRange r
= sheet_get_extent (sheet
, FALSE
, TRUE
);
102 gsf_output_printf (output
, "%s\n\n", sheet
->name_unquoted
);
103 gsf_output_printf (output
, ".TS H\n");
104 gsf_output_printf (output
, "allbox;\n");
106 for (row
= r
.start
.row
; row
<= r
.end
.row
; row
++) {
107 ColRowInfo
const * ri
;
108 ri
= sheet_row_get_info (sheet
, row
);
109 if (ri
->needs_respan
)
110 row_calc_spans ((ColRowInfo
*) ri
, row
, sheet
);
112 if (row
> r
.start
.row
)
113 gsf_output_printf (output
, ".T&\n");
114 /* define alignments, bold etc. per cell */
116 for (col
= r
.start
.col
; col
<= r
.end
.col
; col
++) {
117 cell
= sheet_cell_get (sheet
, col
, row
);
118 if (col
> r
.start
.col
)
119 gsf_output_printf (output
, " ");
121 gsf_output_printf (output
, "l");
123 GnmStyle
const *style
= gnm_cell_get_style (cell
);
126 if (gnm_style_get_align_h (style
) & GNM_HALIGN_RIGHT
)
127 gsf_output_printf (output
, "r");
128 else if (gnm_style_get_align_h (style
) == GNM_HALIGN_CENTER
||
129 /* FIXME : center across selection is different */
130 gnm_style_get_align_h (style
) == GNM_HALIGN_CENTER_ACROSS_SELECTION
||
131 gnm_style_get_align_h (style
) == GNM_HALIGN_DISTRIBUTED
)
132 gsf_output_printf (output
, "c");
134 gsf_output_printf (output
, "l");
135 if (font_is_monospaced (style
)) {
136 if (gnm_style_get_font_bold (style
) &&
137 gnm_style_get_font_italic (style
))
138 gsf_output_printf (output
, "fCBI");
139 else if (gnm_style_get_font_bold (style
))
140 gsf_output_printf (output
, "fCB");
141 else if (gnm_style_get_font_italic (style
))
142 gsf_output_printf (output
, "fCI");
144 gsf_output_printf (output
, "fCR");
145 } else if (font_is_helvetica (style
)) {
146 if (gnm_style_get_font_bold (style
) &&
147 gnm_style_get_font_italic (style
))
148 gsf_output_printf (output
, "fHBI");
149 else if (gnm_style_get_font_bold (style
))
150 gsf_output_printf (output
, "fHB");
151 else if (gnm_style_get_font_italic (style
))
152 gsf_output_printf (output
, "fHI");
154 gsf_output_printf (output
, "fHR");
156 /* default is times */
157 if (gnm_style_get_font_bold (style
) &&
158 gnm_style_get_font_italic (style
))
159 gsf_output_printf (output
, "fTBI");
160 else if (gnm_style_get_font_bold (style
))
161 gsf_output_printf (output
, "fTB");
162 else if (gnm_style_get_font_italic (style
))
163 gsf_output_printf (output
, "fTI");
165 fontsize
= gnm_style_get_font_size (style
);
167 gsf_output_printf (output
, "p%d", fontsize
);
168 v_size
= v_size
> fontsize
? v_size
:
173 gsf_output_printf (output
, ".\n");
174 gsf_output_printf (output
, ".vs %.2fp\n", 2.5 + v_size
);
175 for (col
= r
.start
.col
; col
<= r
.end
.col
; col
++) {
176 if (col
> r
.start
.col
)
177 gsf_output_printf (output
, "\t");
178 cell
= sheet_cell_get (sheet
, col
, row
);
179 if (!cell
) { /* empty cell */
180 gsf_output_printf (output
, " ");
182 roff_fprintf (output
, cell
);
185 gsf_output_printf (output
, "\n");
186 if (row
== r
.start
.row
)
187 gsf_output_printf (output
, ".TH\n");
189 gsf_output_printf (output
, ".TE\n\n");
191 g_slist_free (sheets
);