Mercurial > vim
annotate src/hardcopy.c @ 14864:40ef13331e02
Update runtime files.
commit https://github.com/vim/vim/commit/95bafa296ae97bf420d5c74dd6db517b404c5df7
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Oct 2 13:26:25 2018 +0200
Update runtime files.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 02 Oct 2018 13:30:07 +0200 |
parents | 27b9a84395b5 |
children | 55ccc2d353bd |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
442 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * hardcopy.c: printing to paper | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 #include "version.h" | |
16 | |
17 #if defined(FEAT_PRINTER) || defined(PROTO) | |
18 /* | |
19 * To implement printing on a platform, the following functions must be | |
20 * defined: | |
21 * | |
22 * int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) | |
23 * Called once. Code should display printer dialogue (if appropriate) and | |
24 * determine printer font and margin settings. Reset has_color if the printer | |
25 * doesn't support colors at all. | |
26 * Returns FAIL to abort. | |
27 * | |
28 * int mch_print_begin(prt_settings_T *settings) | |
29 * Called to start the print job. | |
30 * Return FALSE to abort. | |
31 * | |
32 * int mch_print_begin_page(char_u *msg) | |
33 * Called at the start of each page. | |
34 * "msg" indicates the progress of the print job, can be NULL. | |
35 * Return FALSE to abort. | |
36 * | |
37 * int mch_print_end_page() | |
38 * Called at the end of each page. | |
39 * Return FALSE to abort. | |
40 * | |
41 * int mch_print_blank_page() | |
42 * Called to generate a blank page for collated, duplex, multiple copy | |
43 * document. Return FALSE to abort. | |
44 * | |
45 * void mch_print_end(prt_settings_T *psettings) | |
46 * Called at normal end of print job. | |
47 * | |
48 * void mch_print_cleanup() | |
49 * Called if print job ends normally or is abandoned. Free any memory, close | |
50 * devices and handles. Also called when mch_print_begin() fails, but not | |
51 * when mch_print_init() fails. | |
52 * | |
53 * void mch_print_set_font(int Bold, int Italic, int Underline); | |
54 * Called whenever the font style changes. | |
55 * | |
843 | 56 * void mch_print_set_bg(long_u bgcol); |
442 | 57 * Called to set the background color for the following text. Parameter is an |
58 * RGB value. | |
59 * | |
843 | 60 * void mch_print_set_fg(long_u fgcol); |
442 | 61 * Called to set the foreground color for the following text. Parameter is an |
62 * RGB value. | |
63 * | |
64 * mch_print_start_line(int margin, int page_line) | |
65 * Sets the current position at the start of line "page_line". | |
66 * If margin is TRUE start in the left margin (for header and line number). | |
67 * | |
68 * int mch_print_text_out(char_u *p, int len); | |
69 * Output one character of text p[len] at the current position. | |
70 * Return TRUE if there is no room for another character in the same line. | |
71 * | |
72 * Note that the generic code has no idea of margins. The machine code should | |
73 * simply make the page look smaller! The header and the line numbers are | |
74 * printed in the margin. | |
75 */ | |
76 | |
77 #ifdef FEAT_SYN_HL | |
78 static const long_u cterm_color_8[8] = | |
79 { | |
80 (long_u)0x000000L, (long_u)0xff0000L, (long_u)0x00ff00L, (long_u)0xffff00L, | |
81 (long_u)0x0000ffL, (long_u)0xff00ffL, (long_u)0x00ffffL, (long_u)0xffffffL | |
82 }; | |
83 | |
84 static const long_u cterm_color_16[16] = | |
85 { | |
86 (long_u)0x000000L, (long_u)0x0000c0L, (long_u)0x008000L, (long_u)0x004080L, | |
87 (long_u)0xc00000L, (long_u)0xc000c0L, (long_u)0x808000L, (long_u)0xc0c0c0L, | |
88 (long_u)0x808080L, (long_u)0x6060ffL, (long_u)0x00ff00L, (long_u)0x00ffffL, | |
89 (long_u)0xff8080L, (long_u)0xff40ffL, (long_u)0xffff00L, (long_u)0xffffffL | |
90 }; | |
91 | |
92 static int current_syn_id; | |
93 #endif | |
94 | |
95 #define PRCOLOR_BLACK (long_u)0 | |
96 #define PRCOLOR_WHITE (long_u)0xFFFFFFL | |
97 | |
98 static int curr_italic; | |
99 static int curr_bold; | |
100 static int curr_underline; | |
101 static long_u curr_bg; | |
102 static long_u curr_fg; | |
103 static int page_count; | |
104 | |
105 #if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT) | |
106 # define OPT_MBFONT_USECOURIER 0 | |
107 # define OPT_MBFONT_ASCII 1 | |
108 # define OPT_MBFONT_REGULAR 2 | |
856 | 109 # define OPT_MBFONT_BOLD 3 |
442 | 110 # define OPT_MBFONT_OBLIQUE 4 |
111 # define OPT_MBFONT_BOLDOBLIQUE 5 | |
112 # define OPT_MBFONT_NUM_OPTIONS 6 | |
113 | |
114 static option_table_T mbfont_opts[OPT_MBFONT_NUM_OPTIONS] = | |
115 { | |
116 {"c", FALSE, 0, NULL, 0, FALSE}, | |
117 {"a", FALSE, 0, NULL, 0, FALSE}, | |
118 {"r", FALSE, 0, NULL, 0, FALSE}, | |
119 {"b", FALSE, 0, NULL, 0, FALSE}, | |
120 {"i", FALSE, 0, NULL, 0, FALSE}, | |
121 {"o", FALSE, 0, NULL, 0, FALSE}, | |
122 }; | |
123 #endif | |
124 | |
125 /* | |
126 * These values determine the print position on a page. | |
127 */ | |
128 typedef struct | |
129 { | |
130 int lead_spaces; /* remaining spaces for a TAB */ | |
131 int print_pos; /* virtual column for computing TABs */ | |
132 colnr_T column; /* byte column */ | |
133 linenr_T file_line; /* line nr in the buffer */ | |
134 long_u bytes_printed; /* bytes printed so far */ | |
135 int ff; /* seen form feed character */ | |
136 } prt_pos_T; | |
137 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6759
diff
changeset
|
138 static char_u *parse_list_options(char_u *option_str, option_table_T *table, int table_size); |
442 | 139 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6759
diff
changeset
|
140 static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T *ppos); |
442 | 141 |
142 /* | |
143 * Parse 'printoptions' and set the flags in "printer_opts". | |
144 * Returns an error message or NULL; | |
145 */ | |
146 char_u * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
147 parse_printoptions(void) |
442 | 148 { |
149 return parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS); | |
150 } | |
151 | |
152 #if (defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)) || defined(PROTO) | |
153 /* | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8829
diff
changeset
|
154 * Parse 'printmbfont' and set the flags in "mbfont_opts". |
442 | 155 * Returns an error message or NULL; |
156 */ | |
157 char_u * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
158 parse_printmbfont(void) |
442 | 159 { |
160 return parse_list_options(p_pmfn, mbfont_opts, OPT_MBFONT_NUM_OPTIONS); | |
161 } | |
162 #endif | |
163 | |
164 /* | |
165 * Parse a list of options in the form | |
166 * option:value,option:value,option:value | |
167 * | |
168 * "value" can start with a number which is parsed out, e.g. margin:12mm | |
169 * | |
170 * Returns an error message for an illegal option, NULL otherwise. | |
171 * Only used for the printer at the moment... | |
172 */ | |
173 static char_u * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
174 parse_list_options( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
175 char_u *option_str, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
176 option_table_T *table, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
177 int table_size) |
442 | 178 { |
8829
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
179 option_table_T *old_opts; |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
180 char_u *ret = NULL; |
442 | 181 char_u *stringp; |
182 char_u *colonp; | |
183 char_u *commap; | |
184 char_u *p; | |
185 int idx = 0; /* init for GCC */ | |
186 int len; | |
187 | |
8829
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
188 /* Save the old values, so that they can be restored in case of an error. */ |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
189 old_opts = (option_table_T *)alloc(sizeof(option_table_T) * table_size); |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
190 if (old_opts == NULL) |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
191 return NULL; |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
192 |
442 | 193 for (idx = 0; idx < table_size; ++idx) |
8829
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
194 { |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
195 old_opts[idx] = table[idx]; |
442 | 196 table[idx].present = FALSE; |
8829
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
197 } |
442 | 198 |
199 /* | |
200 * Repeat for all comma separated parts. | |
201 */ | |
202 stringp = option_str; | |
203 while (*stringp) | |
204 { | |
205 colonp = vim_strchr(stringp, ':'); | |
206 if (colonp == NULL) | |
8829
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
207 { |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
208 ret = (char_u *)N_("E550: Missing colon"); |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
209 break; |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
210 } |
442 | 211 commap = vim_strchr(stringp, ','); |
212 if (commap == NULL) | |
213 commap = option_str + STRLEN(option_str); | |
214 | |
215 len = (int)(colonp - stringp); | |
216 | |
217 for (idx = 0; idx < table_size; ++idx) | |
218 if (STRNICMP(stringp, table[idx].name, len) == 0) | |
219 break; | |
220 | |
221 if (idx == table_size) | |
8829
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
222 { |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
223 ret = (char_u *)N_("E551: Illegal component"); |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
224 break; |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
225 } |
442 | 226 p = colonp + 1; |
227 table[idx].present = TRUE; | |
228 | |
229 if (table[idx].hasnum) | |
230 { | |
231 if (!VIM_ISDIGIT(*p)) | |
8829
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
232 { |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
233 ret = (char_u *)N_("E552: digit expected"); |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
234 break; |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
235 } |
442 | 236 |
237 table[idx].number = getdigits(&p); /*advances p*/ | |
238 } | |
239 | |
240 table[idx].string = p; | |
241 table[idx].strlen = (int)(commap - p); | |
242 | |
243 stringp = commap; | |
244 if (*stringp == ',') | |
245 ++stringp; | |
246 } | |
247 | |
8829
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
248 if (ret != NULL) |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
249 { |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
250 /* Restore old options in case of error */ |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
251 for (idx = 0; idx < table_size; ++idx) |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
252 table[idx] = old_opts[idx]; |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
253 } |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
254 vim_free(old_opts); |
a2c27f6aaf3a
commit https://github.com/vim/vim/commit/4afc7c5d4a73340831077a02bfe1f74935e7f4a1
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
255 return ret; |
442 | 256 } |
257 | |
258 | |
259 #ifdef FEAT_SYN_HL | |
260 /* | |
261 * If using a dark background, the colors will probably be too bright to show | |
262 * up well on white paper, so reduce their brightness. | |
263 */ | |
264 static long_u | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
265 darken_rgb(long_u rgb) |
442 | 266 { |
267 return ((rgb >> 17) << 16) | |
268 + (((rgb & 0xff00) >> 9) << 8) | |
269 + ((rgb & 0xff) >> 1); | |
270 } | |
271 | |
272 static long_u | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
273 prt_get_term_color(int colorindex) |
442 | 274 { |
275 /* TODO: Should check for xterm with 88 or 256 colors. */ | |
276 if (t_colors > 8) | |
277 return cterm_color_16[colorindex % 16]; | |
278 return cterm_color_8[colorindex % 8]; | |
279 } | |
280 | |
281 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
282 prt_get_attr( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
283 int hl_id, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
284 prt_text_attr_T *pattr, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
285 int modec) |
442 | 286 { |
287 int colorindex; | |
288 long_u fg_color; | |
289 long_u bg_color; | |
290 char *color; | |
291 | |
292 pattr->bold = (highlight_has_attr(hl_id, HL_BOLD, modec) != NULL); | |
293 pattr->italic = (highlight_has_attr(hl_id, HL_ITALIC, modec) != NULL); | |
294 pattr->underline = (highlight_has_attr(hl_id, HL_UNDERLINE, modec) != NULL); | |
295 pattr->undercurl = (highlight_has_attr(hl_id, HL_UNDERCURL, modec) != NULL); | |
296 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8969
diff
changeset
|
297 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8829
diff
changeset
|
298 if (USE_24BIT) |
442 | 299 { |
300 bg_color = highlight_gui_color_rgb(hl_id, FALSE); | |
301 if (bg_color == PRCOLOR_BLACK) | |
302 bg_color = PRCOLOR_WHITE; | |
303 | |
304 fg_color = highlight_gui_color_rgb(hl_id, TRUE); | |
305 } | |
306 else | |
307 # endif | |
308 { | |
309 bg_color = PRCOLOR_WHITE; | |
310 | |
311 color = (char *)highlight_color(hl_id, (char_u *)"fg", modec); | |
312 if (color == NULL) | |
313 colorindex = 0; | |
314 else | |
315 colorindex = atoi(color); | |
316 | |
317 if (colorindex >= 0 && colorindex < t_colors) | |
318 fg_color = prt_get_term_color(colorindex); | |
319 else | |
320 fg_color = PRCOLOR_BLACK; | |
321 } | |
322 | |
323 if (fg_color == PRCOLOR_WHITE) | |
324 fg_color = PRCOLOR_BLACK; | |
325 else if (*p_bg == 'd') | |
326 fg_color = darken_rgb(fg_color); | |
327 | |
328 pattr->fg_color = fg_color; | |
329 pattr->bg_color = bg_color; | |
330 } | |
331 #endif /* FEAT_SYN_HL */ | |
332 | |
333 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
334 prt_set_fg(long_u fg) |
442 | 335 { |
336 if (fg != curr_fg) | |
337 { | |
338 curr_fg = fg; | |
339 mch_print_set_fg(fg); | |
340 } | |
341 } | |
342 | |
343 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
344 prt_set_bg(long_u bg) |
442 | 345 { |
346 if (bg != curr_bg) | |
347 { | |
348 curr_bg = bg; | |
349 mch_print_set_bg(bg); | |
350 } | |
351 } | |
352 | |
353 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
354 prt_set_font(int bold, int italic, int underline) |
442 | 355 { |
356 if (curr_bold != bold | |
357 || curr_italic != italic | |
358 || curr_underline != underline) | |
359 { | |
360 curr_underline = underline; | |
361 curr_italic = italic; | |
362 curr_bold = bold; | |
363 mch_print_set_font(bold, italic, underline); | |
364 } | |
365 } | |
366 | |
367 /* | |
368 * Print the line number in the left margin. | |
369 */ | |
370 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
371 prt_line_number( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
372 prt_settings_T *psettings, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
373 int page_line, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
374 linenr_T lnum) |
442 | 375 { |
376 int i; | |
377 char_u tbuf[20]; | |
378 | |
379 prt_set_fg(psettings->number.fg_color); | |
380 prt_set_bg(psettings->number.bg_color); | |
381 prt_set_font(psettings->number.bold, psettings->number.italic, psettings->number.underline); | |
382 mch_print_start_line(TRUE, page_line); | |
383 | |
384 /* Leave two spaces between the number and the text; depends on | |
385 * PRINT_NUMBER_WIDTH. */ | |
386 sprintf((char *)tbuf, "%6ld", (long)lnum); | |
387 for (i = 0; i < 6; i++) | |
388 (void)mch_print_text_out(&tbuf[i], 1); | |
389 | |
390 #ifdef FEAT_SYN_HL | |
391 if (psettings->do_syntax) | |
392 /* Set colors for next character. */ | |
393 current_syn_id = -1; | |
394 else | |
395 #endif | |
396 { | |
397 /* Set colors and font back to normal. */ | |
398 prt_set_fg(PRCOLOR_BLACK); | |
399 prt_set_bg(PRCOLOR_WHITE); | |
400 prt_set_font(FALSE, FALSE, FALSE); | |
401 } | |
402 } | |
403 | |
404 /* | |
405 * Get the currently effective header height. | |
406 */ | |
407 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
408 prt_header_height(void) |
442 | 409 { |
410 if (printer_opts[OPT_PRINT_HEADERHEIGHT].present) | |
411 return printer_opts[OPT_PRINT_HEADERHEIGHT].number; | |
412 return 2; | |
413 } | |
414 | |
415 /* | |
416 * Return TRUE if using a line number for printing. | |
417 */ | |
418 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
419 prt_use_number(void) |
442 | 420 { |
421 return (printer_opts[OPT_PRINT_NUMBER].present | |
422 && TOLOWER_ASC(printer_opts[OPT_PRINT_NUMBER].string[0]) == 'y'); | |
423 } | |
424 | |
425 /* | |
426 * Return the unit used in a margin item in 'printoptions'. | |
427 * Returns PRT_UNIT_NONE if not recognized. | |
428 */ | |
429 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
430 prt_get_unit(int idx) |
442 | 431 { |
432 int u = PRT_UNIT_NONE; | |
433 int i; | |
434 static char *(units[4]) = PRT_UNIT_NAMES; | |
435 | |
436 if (printer_opts[idx].present) | |
437 for (i = 0; i < 4; ++i) | |
438 if (STRNICMP(printer_opts[idx].string, units[i], 2) == 0) | |
439 { | |
440 u = i; | |
441 break; | |
442 } | |
443 return u; | |
444 } | |
445 | |
446 /* | |
447 * Print the page header. | |
448 */ | |
449 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
450 prt_header( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
451 prt_settings_T *psettings, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
452 int pagenum, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
453 linenr_T lnum UNUSED) |
442 | 454 { |
455 int width = psettings->chars_per_line; | |
456 int page_line; | |
457 char_u *tbuf; | |
458 char_u *p; | |
459 #ifdef FEAT_MBYTE | |
460 int l; | |
461 #endif | |
462 | |
463 /* Also use the space for the line number. */ | |
464 if (prt_use_number()) | |
465 width += PRINT_NUMBER_WIDTH; | |
466 | |
467 tbuf = alloc(width + IOSIZE); | |
468 if (tbuf == NULL) | |
469 return; | |
470 | |
471 #ifdef FEAT_STL_OPT | |
472 if (*p_header != NUL) | |
473 { | |
474 linenr_T tmp_lnum, tmp_topline, tmp_botline; | |
677 | 475 int use_sandbox = FALSE; |
442 | 476 |
477 /* | |
478 * Need to (temporarily) set current line number and first/last line | |
479 * number on the 'window'. Since we don't know how long the page is, | |
480 * set the first and current line number to the top line, and guess | |
481 * that the page length is 64. | |
482 */ | |
483 tmp_lnum = curwin->w_cursor.lnum; | |
484 tmp_topline = curwin->w_topline; | |
485 tmp_botline = curwin->w_botline; | |
486 curwin->w_cursor.lnum = lnum; | |
487 curwin->w_topline = lnum; | |
488 curwin->w_botline = lnum + 63; | |
489 printer_page_num = pagenum; | |
490 | |
677 | 491 # ifdef FEAT_EVAL |
681 | 492 use_sandbox = was_set_insecurely((char_u *)"printheader", 0); |
677 | 493 # endif |
442 | 494 build_stl_str_hl(curwin, tbuf, (size_t)(width + IOSIZE), |
677 | 495 p_header, use_sandbox, |
681 | 496 ' ', width, NULL, NULL); |
442 | 497 |
498 /* Reset line numbers */ | |
499 curwin->w_cursor.lnum = tmp_lnum; | |
500 curwin->w_topline = tmp_topline; | |
501 curwin->w_botline = tmp_botline; | |
502 } | |
503 else | |
504 #endif | |
505 sprintf((char *)tbuf, _("Page %d"), pagenum); | |
506 | |
507 prt_set_fg(PRCOLOR_BLACK); | |
508 prt_set_bg(PRCOLOR_WHITE); | |
509 prt_set_font(TRUE, FALSE, FALSE); | |
510 | |
511 /* Use a negative line number to indicate printing in the top margin. */ | |
512 page_line = 0 - prt_header_height(); | |
513 mch_print_start_line(TRUE, page_line); | |
514 for (p = tbuf; *p != NUL; ) | |
515 { | |
516 if (mch_print_text_out(p, | |
517 #ifdef FEAT_MBYTE | |
474 | 518 (l = (*mb_ptr2len)(p)) |
442 | 519 #else |
520 1 | |
521 #endif | |
522 )) | |
523 { | |
524 ++page_line; | |
525 if (page_line >= 0) /* out of room in header */ | |
526 break; | |
527 mch_print_start_line(TRUE, page_line); | |
528 } | |
529 #ifdef FEAT_MBYTE | |
530 p += l; | |
531 #else | |
532 p++; | |
533 #endif | |
534 } | |
535 | |
536 vim_free(tbuf); | |
537 | |
538 #ifdef FEAT_SYN_HL | |
539 if (psettings->do_syntax) | |
540 /* Set colors for next character. */ | |
541 current_syn_id = -1; | |
542 else | |
543 #endif | |
544 { | |
545 /* Set colors and font back to normal. */ | |
546 prt_set_fg(PRCOLOR_BLACK); | |
547 prt_set_bg(PRCOLOR_WHITE); | |
548 prt_set_font(FALSE, FALSE, FALSE); | |
549 } | |
550 } | |
551 | |
552 /* | |
553 * Display a print status message. | |
554 */ | |
555 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
556 prt_message(char_u *s) |
442 | 557 { |
558 screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
559 screen_puts(s, (int)Rows - 1, 0, HL_ATTR(HLF_R)); |
442 | 560 out_flush(); |
561 } | |
562 | |
563 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
564 ex_hardcopy(exarg_T *eap) |
442 | 565 { |
566 linenr_T lnum; | |
567 int collated_copies, uncollated_copies; | |
568 prt_settings_T settings; | |
569 long_u bytes_to_print = 0; | |
570 int page_line; | |
571 int jobsplit; | |
572 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1880
diff
changeset
|
573 vim_memset(&settings, 0, sizeof(prt_settings_T)); |
442 | 574 settings.has_color = TRUE; |
575 | |
576 # ifdef FEAT_POSTSCRIPT | |
577 if (*eap->arg == '>') | |
578 { | |
579 char_u *errormsg = NULL; | |
580 | |
581 /* Expand things like "%.ps". */ | |
582 if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) | |
583 { | |
584 if (errormsg != NULL) | |
585 EMSG(errormsg); | |
586 return; | |
587 } | |
588 settings.outfile = skipwhite(eap->arg + 1); | |
589 } | |
590 else if (*eap->arg != NUL) | |
591 settings.arguments = eap->arg; | |
592 # endif | |
593 | |
594 /* | |
595 * Initialise for printing. Ask the user for settings, unless forceit is | |
596 * set. | |
597 * The mch_print_init() code should set up margins if applicable. (It may | |
598 * not be a real printer - for example the engine might generate HTML or | |
599 * PS.) | |
600 */ | |
601 if (mch_print_init(&settings, | |
602 curbuf->b_fname == NULL | |
603 ? (char_u *)buf_spname(curbuf) | |
604 : curbuf->b_sfname == NULL | |
605 ? curbuf->b_fname | |
606 : curbuf->b_sfname, | |
607 eap->forceit) == FAIL) | |
608 return; | |
609 | |
610 #ifdef FEAT_SYN_HL | |
611 # ifdef FEAT_GUI | |
612 if (gui.in_use) | |
613 settings.modec = 'g'; | |
614 else | |
615 # endif | |
616 if (t_colors > 1) | |
617 settings.modec = 'c'; | |
618 else | |
619 settings.modec = 't'; | |
620 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
621 if (!syntax_present(curwin)) |
442 | 622 settings.do_syntax = FALSE; |
623 else if (printer_opts[OPT_PRINT_SYNTAX].present | |
624 && TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) != 'a') | |
625 settings.do_syntax = | |
626 (TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) == 'y'); | |
627 else | |
628 settings.do_syntax = settings.has_color; | |
629 #endif | |
630 | |
631 /* Set up printing attributes for line numbers */ | |
632 settings.number.fg_color = PRCOLOR_BLACK; | |
633 settings.number.bg_color = PRCOLOR_WHITE; | |
634 settings.number.bold = FALSE; | |
635 settings.number.italic = TRUE; | |
636 settings.number.underline = FALSE; | |
637 #ifdef FEAT_SYN_HL | |
638 /* | |
639 * Syntax highlighting of line numbers. | |
640 */ | |
641 if (prt_use_number() && settings.do_syntax) | |
642 { | |
744 | 643 int id; |
644 | |
442 | 645 id = syn_name2id((char_u *)"LineNr"); |
646 if (id > 0) | |
647 id = syn_get_final_id(id); | |
648 | |
649 prt_get_attr(id, &settings.number, settings.modec); | |
650 } | |
744 | 651 #endif |
442 | 652 |
653 /* | |
654 * Estimate the total lines to be printed | |
655 */ | |
656 for (lnum = eap->line1; lnum <= eap->line2; lnum++) | |
657 bytes_to_print += (long_u)STRLEN(skipwhite(ml_get(lnum))); | |
658 if (bytes_to_print == 0) | |
659 { | |
660 MSG(_("No text to be printed")); | |
661 goto print_fail_no_begin; | |
662 } | |
663 | |
664 /* Set colors and font to normal. */ | |
665 curr_bg = (long_u)0xffffffffL; | |
666 curr_fg = (long_u)0xffffffffL; | |
667 curr_italic = MAYBE; | |
668 curr_bold = MAYBE; | |
669 curr_underline = MAYBE; | |
670 | |
671 prt_set_fg(PRCOLOR_BLACK); | |
672 prt_set_bg(PRCOLOR_WHITE); | |
673 prt_set_font(FALSE, FALSE, FALSE); | |
674 #ifdef FEAT_SYN_HL | |
675 current_syn_id = -1; | |
676 #endif | |
677 | |
678 jobsplit = (printer_opts[OPT_PRINT_JOBSPLIT].present | |
679 && TOLOWER_ASC(printer_opts[OPT_PRINT_JOBSPLIT].string[0]) == 'y'); | |
680 | |
681 if (!mch_print_begin(&settings)) | |
682 goto print_fail_no_begin; | |
683 | |
684 /* | |
685 * Loop over collated copies: 1 2 3, 1 2 3, ... | |
686 */ | |
687 page_count = 0; | |
688 for (collated_copies = 0; | |
689 collated_copies < settings.n_collated_copies; | |
690 collated_copies++) | |
691 { | |
692 prt_pos_T prtpos; /* current print position */ | |
693 prt_pos_T page_prtpos; /* print position at page start */ | |
694 int side; | |
695 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1880
diff
changeset
|
696 vim_memset(&page_prtpos, 0, sizeof(prt_pos_T)); |
442 | 697 page_prtpos.file_line = eap->line1; |
698 prtpos = page_prtpos; | |
699 | |
700 if (jobsplit && collated_copies > 0) | |
701 { | |
702 /* Splitting jobs: Stop a previous job and start a new one. */ | |
703 mch_print_end(&settings); | |
704 if (!mch_print_begin(&settings)) | |
705 goto print_fail_no_begin; | |
706 } | |
707 | |
708 /* | |
709 * Loop over all pages in the print job: 1 2 3 ... | |
710 */ | |
711 for (page_count = 0; prtpos.file_line <= eap->line2; ++page_count) | |
712 { | |
713 /* | |
714 * Loop over uncollated copies: 1 1 1, 2 2 2, 3 3 3, ... | |
715 * For duplex: 12 12 12 34 34 34, ... | |
716 */ | |
717 for (uncollated_copies = 0; | |
718 uncollated_copies < settings.n_uncollated_copies; | |
719 uncollated_copies++) | |
720 { | |
721 /* Set the print position to the start of this page. */ | |
722 prtpos = page_prtpos; | |
723 | |
724 /* | |
725 * Do front and rear side of a page. | |
726 */ | |
727 for (side = 0; side <= settings.duplex; ++side) | |
728 { | |
729 /* | |
730 * Print one page. | |
731 */ | |
732 | |
733 /* Check for interrupt character every page. */ | |
734 ui_breakcheck(); | |
735 if (got_int || settings.user_abort) | |
736 goto print_fail; | |
737 | |
738 sprintf((char *)IObuff, _("Printing page %d (%d%%)"), | |
739 page_count + 1 + side, | |
740 prtpos.bytes_printed > 1000000 | |
741 ? (int)(prtpos.bytes_printed / | |
742 (bytes_to_print / 100)) | |
743 : (int)((prtpos.bytes_printed * 100) | |
744 / bytes_to_print)); | |
745 if (!mch_print_begin_page(IObuff)) | |
746 goto print_fail; | |
747 | |
748 if (settings.n_collated_copies > 1) | |
749 sprintf((char *)IObuff + STRLEN(IObuff), | |
750 _(" Copy %d of %d"), | |
751 collated_copies + 1, | |
752 settings.n_collated_copies); | |
753 prt_message(IObuff); | |
754 | |
755 /* | |
756 * Output header if required | |
757 */ | |
758 if (prt_header_height() > 0) | |
759 prt_header(&settings, page_count + 1 + side, | |
760 prtpos.file_line); | |
761 | |
762 for (page_line = 0; page_line < settings.lines_per_page; | |
763 ++page_line) | |
764 { | |
765 prtpos.column = hardcopy_line(&settings, | |
766 page_line, &prtpos); | |
767 if (prtpos.column == 0) | |
768 { | |
769 /* finished a file line */ | |
770 prtpos.bytes_printed += | |
771 STRLEN(skipwhite(ml_get(prtpos.file_line))); | |
772 if (++prtpos.file_line > eap->line2) | |
773 break; /* reached the end */ | |
774 } | |
775 else if (prtpos.ff) | |
776 { | |
777 /* Line had a formfeed in it - start new page but | |
778 * stay on the current line */ | |
779 break; | |
780 } | |
781 } | |
782 | |
783 if (!mch_print_end_page()) | |
784 goto print_fail; | |
785 if (prtpos.file_line > eap->line2) | |
786 break; /* reached the end */ | |
787 } | |
788 | |
789 /* | |
790 * Extra blank page for duplexing with odd number of pages and | |
791 * more copies to come. | |
792 */ | |
793 if (prtpos.file_line > eap->line2 && settings.duplex | |
794 && side == 0 | |
795 && uncollated_copies + 1 < settings.n_uncollated_copies) | |
796 { | |
797 if (!mch_print_blank_page()) | |
798 goto print_fail; | |
799 } | |
800 } | |
801 if (settings.duplex && prtpos.file_line <= eap->line2) | |
802 ++page_count; | |
803 | |
804 /* Remember the position where the next page starts. */ | |
805 page_prtpos = prtpos; | |
806 } | |
807 | |
808 vim_snprintf((char *)IObuff, IOSIZE, _("Printed: %s"), | |
809 settings.jobname); | |
810 prt_message(IObuff); | |
811 } | |
812 | |
813 print_fail: | |
814 if (got_int || settings.user_abort) | |
815 { | |
816 sprintf((char *)IObuff, "%s", _("Printing aborted")); | |
817 prt_message(IObuff); | |
818 } | |
819 mch_print_end(&settings); | |
820 | |
821 print_fail_no_begin: | |
822 mch_print_cleanup(); | |
823 } | |
824 | |
825 /* | |
826 * Print one page line. | |
827 * Return the next column to print, or zero if the line is finished. | |
828 */ | |
829 static colnr_T | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
830 hardcopy_line( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
831 prt_settings_T *psettings, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
832 int page_line, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
833 prt_pos_T *ppos) |
442 | 834 { |
835 colnr_T col; | |
836 char_u *line; | |
837 int need_break = FALSE; | |
838 int outputlen; | |
839 int tab_spaces; | |
840 long_u print_pos; | |
841 #ifdef FEAT_SYN_HL | |
842 prt_text_attr_T attr; | |
843 int id; | |
844 #endif | |
845 | |
846 if (ppos->column == 0 || ppos->ff) | |
847 { | |
848 print_pos = 0; | |
849 tab_spaces = 0; | |
850 if (!ppos->ff && prt_use_number()) | |
851 prt_line_number(psettings, page_line, ppos->file_line); | |
852 ppos->ff = FALSE; | |
853 } | |
854 else | |
855 { | |
856 /* left over from wrap halfway a tab */ | |
857 print_pos = ppos->print_pos; | |
858 tab_spaces = ppos->lead_spaces; | |
859 } | |
860 | |
861 mch_print_start_line(0, page_line); | |
862 line = ml_get(ppos->file_line); | |
863 | |
864 /* | |
865 * Loop over the columns until the end of the file line or right margin. | |
866 */ | |
867 for (col = ppos->column; line[col] != NUL && !need_break; col += outputlen) | |
868 { | |
869 outputlen = 1; | |
870 #ifdef FEAT_MBYTE | |
474 | 871 if (has_mbyte && (outputlen = (*mb_ptr2len)(line + col)) < 1) |
442 | 872 outputlen = 1; |
873 #endif | |
874 #ifdef FEAT_SYN_HL | |
875 /* | |
876 * syntax highlighting stuff. | |
877 */ | |
878 if (psettings->do_syntax) | |
879 { | |
1504 | 880 id = syn_get_id(curwin, ppos->file_line, col, 1, NULL, FALSE); |
442 | 881 if (id > 0) |
882 id = syn_get_final_id(id); | |
883 else | |
884 id = 0; | |
885 /* Get the line again, a multi-line regexp may invalidate it. */ | |
886 line = ml_get(ppos->file_line); | |
887 | |
888 if (id != current_syn_id) | |
889 { | |
890 current_syn_id = id; | |
891 prt_get_attr(id, &attr, psettings->modec); | |
892 prt_set_font(attr.bold, attr.italic, attr.underline); | |
893 prt_set_fg(attr.fg_color); | |
894 prt_set_bg(attr.bg_color); | |
895 } | |
896 } | |
744 | 897 #endif |
442 | 898 |
899 /* | |
900 * Appropriately expand any tabs to spaces. | |
901 */ | |
902 if (line[col] == TAB || tab_spaces != 0) | |
903 { | |
904 if (tab_spaces == 0) | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14077
diff
changeset
|
905 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14077
diff
changeset
|
906 tab_spaces = tabstop_padding(print_pos, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14077
diff
changeset
|
907 curbuf->b_p_vts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14077
diff
changeset
|
908 #else |
835 | 909 tab_spaces = (int)(curbuf->b_p_ts - (print_pos % curbuf->b_p_ts)); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14077
diff
changeset
|
910 #endif |
442 | 911 |
912 while (tab_spaces > 0) | |
913 { | |
914 need_break = mch_print_text_out((char_u *)" ", 1); | |
915 print_pos++; | |
916 tab_spaces--; | |
917 if (need_break) | |
918 break; | |
919 } | |
920 /* Keep the TAB if we didn't finish it. */ | |
921 if (need_break && tab_spaces > 0) | |
922 break; | |
923 } | |
924 else if (line[col] == FF | |
925 && printer_opts[OPT_PRINT_FORMFEED].present | |
926 && TOLOWER_ASC(printer_opts[OPT_PRINT_FORMFEED].string[0]) | |
927 == 'y') | |
928 { | |
929 ppos->ff = TRUE; | |
930 need_break = 1; | |
931 } | |
932 else | |
933 { | |
934 need_break = mch_print_text_out(line + col, outputlen); | |
935 #ifdef FEAT_MBYTE | |
936 if (has_mbyte) | |
937 print_pos += (*mb_ptr2cells)(line + col); | |
938 else | |
939 #endif | |
940 print_pos++; | |
941 } | |
942 } | |
943 | |
944 ppos->lead_spaces = tab_spaces; | |
835 | 945 ppos->print_pos = (int)print_pos; |
442 | 946 |
947 /* | |
948 * Start next line of file if we clip lines, or have reached end of the | |
949 * line, unless we are doing a formfeed. | |
950 */ | |
951 if (!ppos->ff | |
952 && (line[col] == NUL | |
953 || (printer_opts[OPT_PRINT_WRAP].present | |
954 && TOLOWER_ASC(printer_opts[OPT_PRINT_WRAP].string[0]) | |
955 == 'n'))) | |
956 return 0; | |
957 return col; | |
958 } | |
959 | |
960 # if defined(FEAT_POSTSCRIPT) || defined(PROTO) | |
961 | |
962 /* | |
963 * PS printer stuff. | |
964 * | |
965 * Sources of information to help maintain the PS printing code: | |
966 * | |
967 * 1. PostScript Language Reference, 3rd Edition, | |
968 * Addison-Wesley, 1999, ISBN 0-201-37922-8 | |
969 * 2. PostScript Language Program Design, | |
970 * Addison-Wesley, 1988, ISBN 0-201-14396-8 | |
971 * 3. PostScript Tutorial and Cookbook, | |
972 * Addison Wesley, 1985, ISBN 0-201-10179-3 | |
973 * 4. PostScript Language Document Structuring Conventions Specification, | |
974 * version 3.0, | |
975 * Adobe Technote 5001, 25th September 1992 | |
976 * 5. PostScript Printer Description File Format Specification, Version 4.3, | |
977 * Adobe technote 5003, 9th February 1996 | |
978 * 6. Adobe Font Metrics File Format Specification, Version 4.1, | |
979 * Adobe Technote 5007, 7th October 1998 | |
980 * 7. Adobe CMap and CIDFont Files Specification, Version 1.0, | |
981 * Adobe Technote 5014, 8th October 1996 | |
982 * 8. Adobe CJKV Character Collections and CMaps for CID-Keyed Fonts, | |
983 * Adoboe Technote 5094, 8th September, 2001 | |
984 * 9. CJKV Information Processing, 2nd Edition, | |
985 * O'Reilly, 2002, ISBN 1-56592-224-7 | |
986 * | |
987 * Some of these documents can be found in PDF form on Adobe's web site - | |
988 * http://www.adobe.com | |
989 */ | |
990 | |
991 #define NUM_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0])) | |
992 | |
993 #define PRT_PS_DEFAULT_DPI (72) /* Default user space resolution */ | |
994 #define PRT_PS_DEFAULT_FONTSIZE (10) | |
995 #define PRT_PS_DEFAULT_BUFFER_SIZE (80) | |
996 | |
997 struct prt_mediasize_S | |
998 { | |
999 char *name; | |
1000 float width; /* width and height in points for portrait */ | |
1001 float height; | |
1002 }; | |
1003 | |
1004 #define PRT_MEDIASIZE_LEN (sizeof(prt_mediasize) / sizeof(struct prt_mediasize_S)) | |
1005 | |
1006 static struct prt_mediasize_S prt_mediasize[] = | |
1007 { | |
1008 {"A4", 595.0, 842.0}, | |
1009 {"letter", 612.0, 792.0}, | |
1010 {"10x14", 720.0, 1008.0}, | |
1011 {"A3", 842.0, 1191.0}, | |
1012 {"A5", 420.0, 595.0}, | |
1013 {"B4", 729.0, 1032.0}, | |
1014 {"B5", 516.0, 729.0}, | |
1015 {"executive", 522.0, 756.0}, | |
1016 {"folio", 595.0, 935.0}, | |
1017 {"ledger", 1224.0, 792.0}, /* Yes, it is wider than taller! */ | |
1018 {"legal", 612.0, 1008.0}, | |
1019 {"quarto", 610.0, 780.0}, | |
1020 {"statement", 396.0, 612.0}, | |
1021 {"tabloid", 792.0, 1224.0} | |
1022 }; | |
1023 | |
1024 /* PS font names, must be in Roman, Bold, Italic, Bold-Italic order */ | |
1025 struct prt_ps_font_S | |
1026 { | |
1027 int wx; | |
1028 int uline_offset; | |
1029 int uline_width; | |
1030 int bbox_min_y; | |
1031 int bbox_max_y; | |
1032 char *(ps_fontname[4]); | |
1033 }; | |
1034 | |
1035 #define PRT_PS_FONT_ROMAN (0) | |
1036 #define PRT_PS_FONT_BOLD (1) | |
1037 #define PRT_PS_FONT_OBLIQUE (2) | |
1038 #define PRT_PS_FONT_BOLDOBLIQUE (3) | |
1039 | |
1040 /* Standard font metrics for Courier family */ | |
1041 static struct prt_ps_font_S prt_ps_courier_font = | |
1042 { | |
1043 600, | |
1044 -100, 50, | |
1045 -250, 805, | |
1046 {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"} | |
1047 }; | |
1048 | |
1049 #ifdef FEAT_MBYTE | |
1050 /* Generic font metrics for multi-byte fonts */ | |
1051 static struct prt_ps_font_S prt_ps_mb_font = | |
1052 { | |
1053 1000, | |
1054 -100, 50, | |
1055 -250, 805, | |
1056 {NULL, NULL, NULL, NULL} | |
1057 }; | |
1058 #endif | |
1059 | |
1060 /* Pointer to current font set being used */ | |
1061 static struct prt_ps_font_S* prt_ps_font; | |
1062 | |
1063 /* Structures to map user named encoding and mapping to PS equivalents for | |
1064 * building CID font name */ | |
1065 struct prt_ps_encoding_S | |
1066 { | |
1067 char *encoding; | |
1068 char *cmap_encoding; | |
1069 int needs_charset; | |
1070 }; | |
1071 | |
1072 struct prt_ps_charset_S | |
1073 { | |
1074 char *charset; | |
1075 char *cmap_charset; | |
1076 int has_charset; | |
1077 }; | |
1078 | |
1079 #ifdef FEAT_MBYTE | |
1080 | |
1081 #define CS_JIS_C_1978 (0x01) | |
1082 #define CS_JIS_X_1983 (0x02) | |
1083 #define CS_JIS_X_1990 (0x04) | |
856 | 1084 #define CS_NEC (0x08) |
1085 #define CS_MSWINDOWS (0x10) | |
1086 #define CS_CP932 (0x20) | |
1087 #define CS_KANJITALK6 (0x40) | |
442 | 1088 #define CS_KANJITALK7 (0x80) |
1089 | |
1090 /* Japanese encodings and charsets */ | |
1091 static struct prt_ps_encoding_S j_encodings[] = | |
1092 { | |
1093 {"iso-2022-jp", NULL, (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990| | |
856 | 1094 CS_NEC)}, |
1095 {"euc-jp", "EUC", (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990)}, | |
1096 {"sjis", "RKSJ", (CS_JIS_C_1978|CS_JIS_X_1983|CS_MSWINDOWS| | |
1097 CS_KANJITALK6|CS_KANJITALK7)}, | |
442 | 1098 {"cp932", "RKSJ", CS_JIS_X_1983}, |
1099 {"ucs-2", "UCS2", CS_JIS_X_1990}, | |
1100 {"utf-8", "UTF8" , CS_JIS_X_1990} | |
1101 }; | |
1102 static struct prt_ps_charset_S j_charsets[] = | |
1103 { | |
1104 {"JIS_C_1978", "78", CS_JIS_C_1978}, | |
1105 {"JIS_X_1983", NULL, CS_JIS_X_1983}, | |
1106 {"JIS_X_1990", "Hojo", CS_JIS_X_1990}, | |
856 | 1107 {"NEC", "Ext", CS_NEC}, |
442 | 1108 {"MSWINDOWS", "90ms", CS_MSWINDOWS}, |
1109 {"CP932", "90ms", CS_JIS_X_1983}, | |
1110 {"KANJITALK6", "83pv", CS_KANJITALK6}, | |
1111 {"KANJITALK7", "90pv", CS_KANJITALK7} | |
1112 }; | |
1113 | |
1114 #define CS_GB_2312_80 (0x01) | |
1115 #define CS_GBT_12345_90 (0x02) | |
856 | 1116 #define CS_GBK2K (0x04) |
1117 #define CS_SC_MAC (0x08) | |
1118 #define CS_GBT_90_MAC (0x10) | |
1119 #define CS_GBK (0x20) | |
442 | 1120 #define CS_SC_ISO10646 (0x40) |
1121 | |
1122 /* Simplified Chinese encodings and charsets */ | |
1123 static struct prt_ps_encoding_S sc_encodings[] = | |
1124 { | |
1125 {"iso-2022", NULL, (CS_GB_2312_80|CS_GBT_12345_90)}, | |
1126 {"gb18030", NULL, CS_GBK2K}, | |
1127 {"euc-cn", "EUC", (CS_GB_2312_80|CS_GBT_12345_90|CS_SC_MAC| | |
856 | 1128 CS_GBT_90_MAC)}, |
1129 {"gbk", "EUC", CS_GBK}, | |
442 | 1130 {"ucs-2", "UCS2", CS_SC_ISO10646}, |
1131 {"utf-8", "UTF8", CS_SC_ISO10646} | |
1132 }; | |
1133 static struct prt_ps_charset_S sc_charsets[] = | |
1134 { | |
1135 {"GB_2312-80", "GB", CS_GB_2312_80}, | |
1136 {"GBT_12345-90","GBT", CS_GBT_12345_90}, | |
856 | 1137 {"MAC", "GBpc", CS_SC_MAC}, |
1138 {"GBT-90_MAC", "GBTpc", CS_GBT_90_MAC}, | |
1139 {"GBK", "GBK", CS_GBK}, | |
442 | 1140 {"GB18030", "GBK2K", CS_GBK2K}, |
1141 {"ISO10646", "UniGB", CS_SC_ISO10646} | |
1142 }; | |
1143 | |
1144 #define CS_CNS_PLANE_1 (0x01) | |
1145 #define CS_CNS_PLANE_2 (0x02) | |
1146 #define CS_CNS_PLANE_1_2 (0x04) | |
856 | 1147 #define CS_B5 (0x08) |
1148 #define CS_ETEN (0x10) | |
1149 #define CS_HK_GCCS (0x20) | |
1150 #define CS_HK_SCS (0x40) | |
1151 #define CS_HK_SCS_ETEN (0x80) | |
1152 #define CS_MTHKL (0x100) | |
1153 #define CS_MTHKS (0x200) | |
1154 #define CS_DLHKL (0x400) | |
1155 #define CS_DLHKS (0x800) | |
1156 #define CS_TC_ISO10646 (0x1000) | |
442 | 1157 |
1158 /* Traditional Chinese encodings and charsets */ | |
1159 static struct prt_ps_encoding_S tc_encodings[] = | |
1160 { | |
1161 {"iso-2022", NULL, (CS_CNS_PLANE_1|CS_CNS_PLANE_2)}, | |
1162 {"euc-tw", "EUC", CS_CNS_PLANE_1_2}, | |
856 | 1163 {"big5", "B5", (CS_B5|CS_ETEN|CS_HK_GCCS|CS_HK_SCS| |
1164 CS_HK_SCS_ETEN|CS_MTHKL|CS_MTHKS|CS_DLHKL| | |
1165 CS_DLHKS)}, | |
442 | 1166 {"cp950", "B5", CS_B5}, |
1167 {"ucs-2", "UCS2", CS_TC_ISO10646}, | |
1168 {"utf-8", "UTF8", CS_TC_ISO10646}, | |
1169 {"utf-16", "UTF16", CS_TC_ISO10646}, | |
1170 {"utf-32", "UTF32", CS_TC_ISO10646} | |
1171 }; | |
1172 static struct prt_ps_charset_S tc_charsets[] = | |
1173 { | |
1174 {"CNS_1992_1", "CNS1", CS_CNS_PLANE_1}, | |
1175 {"CNS_1992_2", "CNS2", CS_CNS_PLANE_2}, | |
1176 {"CNS_1993", "CNS", CS_CNS_PLANE_1_2}, | |
856 | 1177 {"BIG5", NULL, CS_B5}, |
1178 {"CP950", NULL, CS_B5}, | |
1179 {"ETEN", "ETen", CS_ETEN}, | |
1180 {"HK_GCCS", "HKgccs", CS_HK_GCCS}, | |
1181 {"SCS", "HKscs", CS_HK_SCS}, | |
442 | 1182 {"SCS_ETEN", "ETHK", CS_HK_SCS_ETEN}, |
1183 {"MTHKL", "HKm471", CS_MTHKL}, | |
1184 {"MTHKS", "HKm314", CS_MTHKS}, | |
1185 {"DLHKL", "HKdla", CS_DLHKL}, | |
1186 {"DLHKS", "HKdlb", CS_DLHKS}, | |
1187 {"ISO10646", "UniCNS", CS_TC_ISO10646} | |
1188 }; | |
1189 | |
856 | 1190 #define CS_KR_X_1992 (0x01) |
1191 #define CS_KR_MAC (0x02) | |
442 | 1192 #define CS_KR_X_1992_MS (0x04) |
1193 #define CS_KR_ISO10646 (0x08) | |
1194 | |
1195 /* Korean encodings and charsets */ | |
1196 static struct prt_ps_encoding_S k_encodings[] = | |
1197 { | |
1198 {"iso-2022-kr", NULL, CS_KR_X_1992}, | |
1199 {"euc-kr", "EUC", (CS_KR_X_1992|CS_KR_MAC)}, | |
1200 {"johab", "Johab", CS_KR_X_1992}, | |
1201 {"cp1361", "Johab", CS_KR_X_1992}, | |
856 | 1202 {"uhc", "UHC", CS_KR_X_1992_MS}, |
442 | 1203 {"cp949", "UHC", CS_KR_X_1992_MS}, |
1204 {"ucs-2", "UCS2", CS_KR_ISO10646}, | |
1205 {"utf-8", "UTF8", CS_KR_ISO10646} | |
1206 }; | |
1207 static struct prt_ps_charset_S k_charsets[] = | |
1208 { | |
1209 {"KS_X_1992", "KSC", CS_KR_X_1992}, | |
1210 {"CP1361", "KSC", CS_KR_X_1992}, | |
856 | 1211 {"MAC", "KSCpc", CS_KR_MAC}, |
442 | 1212 {"MSWINDOWS", "KSCms", CS_KR_X_1992_MS}, |
1213 {"CP949", "KSCms", CS_KR_X_1992_MS}, | |
1214 {"WANSUNG", "KSCms", CS_KR_X_1992_MS}, | |
1215 {"ISO10646", "UniKS", CS_KR_ISO10646} | |
1216 }; | |
1217 | |
1218 /* Collections of encodings and charsets for multi-byte printing */ | |
1219 struct prt_ps_mbfont_S | |
1220 { | |
856 | 1221 int num_encodings; |
1222 struct prt_ps_encoding_S *encodings; | |
1223 int num_charsets; | |
1224 struct prt_ps_charset_S *charsets; | |
1225 char *ascii_enc; | |
1226 char *defcs; | |
442 | 1227 }; |
1228 | |
1229 static struct prt_ps_mbfont_S prt_ps_mbfonts[] = | |
1230 { | |
1231 { | |
856 | 1232 NUM_ELEMENTS(j_encodings), |
1233 j_encodings, | |
1234 NUM_ELEMENTS(j_charsets), | |
1235 j_charsets, | |
1236 "jis_roman", | |
1237 "JIS_X_1983" | |
442 | 1238 }, |
1239 { | |
856 | 1240 NUM_ELEMENTS(sc_encodings), |
1241 sc_encodings, | |
1242 NUM_ELEMENTS(sc_charsets), | |
1243 sc_charsets, | |
1244 "gb_roman", | |
1245 "GB_2312-80" | |
442 | 1246 }, |
1247 { | |
856 | 1248 NUM_ELEMENTS(tc_encodings), |
1249 tc_encodings, | |
1250 NUM_ELEMENTS(tc_charsets), | |
1251 tc_charsets, | |
1252 "cns_roman", | |
1253 "BIG5" | |
442 | 1254 }, |
1255 { | |
856 | 1256 NUM_ELEMENTS(k_encodings), |
1257 k_encodings, | |
1258 NUM_ELEMENTS(k_charsets), | |
1259 k_charsets, | |
1260 "ks_roman", | |
1261 "KS_X_1992" | |
442 | 1262 } |
1263 }; | |
1264 #endif /* FEAT_MBYTE */ | |
1265 | |
1266 struct prt_ps_resource_S | |
1267 { | |
1268 char_u name[64]; | |
1269 char_u filename[MAXPATHL + 1]; | |
1270 int type; | |
1271 char_u title[256]; | |
1272 char_u version[256]; | |
1273 }; | |
1274 | |
1275 /* Types of PS resource file currently used */ | |
1276 #define PRT_RESOURCE_TYPE_PROCSET (0) | |
1277 #define PRT_RESOURCE_TYPE_ENCODING (1) | |
1278 #define PRT_RESOURCE_TYPE_CMAP (2) | |
1279 | |
1280 /* The PS prolog file version number has to match - if the prolog file is | |
1281 * updated, increment the number in the file and here. Version checking was | |
1282 * added as of VIM 6.2. | |
1283 * The CID prolog file version number behaves as per PS prolog. | |
1284 * Table of VIM and prolog versions: | |
1285 * | |
1286 * VIM Prolog CIDProlog | |
1287 * 6.2 1.3 | |
1288 * 7.0 1.4 1.0 | |
1289 */ | |
1290 #define PRT_PROLOG_VERSION ((char_u *)"1.4") | |
1291 #define PRT_CID_PROLOG_VERSION ((char_u *)"1.0") | |
1292 | |
1293 /* String versions of PS resource types - indexed by constants above so don't | |
1294 * re-order! | |
1295 */ | |
1296 static char *prt_resource_types[] = | |
1297 { | |
1298 "procset", | |
1299 "encoding", | |
1300 "cmap" | |
1301 }; | |
1302 | |
1303 /* Strings to look for in a PS resource file */ | |
1304 #define PRT_RESOURCE_HEADER "%!PS-Adobe-" | |
1305 #define PRT_RESOURCE_RESOURCE "Resource-" | |
1306 #define PRT_RESOURCE_PROCSET "ProcSet" | |
1307 #define PRT_RESOURCE_ENCODING "Encoding" | |
856 | 1308 #define PRT_RESOURCE_CMAP "CMap" |
442 | 1309 |
1310 | |
1311 /* Data for table based DSC comment recognition, easy to extend if VIM needs to | |
1312 * read more comments. */ | |
856 | 1313 #define PRT_DSC_MISC_TYPE (-1) |
1314 #define PRT_DSC_TITLE_TYPE (1) | |
1315 #define PRT_DSC_VERSION_TYPE (2) | |
442 | 1316 #define PRT_DSC_ENDCOMMENTS_TYPE (3) |
1317 | |
856 | 1318 #define PRT_DSC_TITLE "%%Title:" |
1319 #define PRT_DSC_VERSION "%%Version:" | |
1320 #define PRT_DSC_ENDCOMMENTS "%%EndComments:" | |
442 | 1321 |
1322 struct prt_dsc_comment_S | |
1323 { | |
1324 char *string; | |
1325 int len; | |
1326 int type; | |
1327 }; | |
1328 | |
1329 struct prt_dsc_line_S | |
1330 { | |
1331 int type; | |
1332 char_u *string; | |
1333 int len; | |
1334 }; | |
1335 | |
1336 | |
1337 #define SIZEOF_CSTR(s) (sizeof(s) - 1) | |
1338 static struct prt_dsc_comment_S prt_dsc_table[] = | |
1339 { | |
1340 {PRT_DSC_TITLE, SIZEOF_CSTR(PRT_DSC_TITLE), PRT_DSC_TITLE_TYPE}, | |
1341 {PRT_DSC_VERSION, SIZEOF_CSTR(PRT_DSC_VERSION), | |
1342 PRT_DSC_VERSION_TYPE}, | |
1343 {PRT_DSC_ENDCOMMENTS, SIZEOF_CSTR(PRT_DSC_ENDCOMMENTS), | |
1344 PRT_DSC_ENDCOMMENTS_TYPE} | |
1345 }; | |
1346 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6759
diff
changeset
|
1347 static void prt_write_file_len(char_u *buffer, int bytes); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6759
diff
changeset
|
1348 static int prt_next_dsc(struct prt_dsc_line_S *p_dsc_line); |
442 | 1349 |
1350 /* | |
1351 * Variables for the output PostScript file. | |
1352 */ | |
1353 static FILE *prt_ps_fd; | |
1354 static int prt_file_error; | |
1355 static char_u *prt_ps_file_name = NULL; | |
1356 | |
1357 /* | |
1358 * Various offsets and dimensions in default PostScript user space (points). | |
1359 * Used for text positioning calculations | |
1360 */ | |
1361 static float prt_page_width; | |
1362 static float prt_page_height; | |
1363 static float prt_left_margin; | |
1364 static float prt_right_margin; | |
1365 static float prt_top_margin; | |
1366 static float prt_bottom_margin; | |
1367 static float prt_line_height; | |
1368 static float prt_first_line_height; | |
1369 static float prt_char_width; | |
1370 static float prt_number_width; | |
1371 static float prt_bgcol_offset; | |
1372 static float prt_pos_x_moveto = 0.0; | |
1373 static float prt_pos_y_moveto = 0.0; | |
1374 | |
1375 /* | |
1376 * Various control variables used to decide when and how to change the | |
1377 * PostScript graphics state. | |
1378 */ | |
1379 static int prt_need_moveto; | |
1380 static int prt_do_moveto; | |
1381 static int prt_need_font; | |
1382 static int prt_font; | |
1383 static int prt_need_underline; | |
1384 static int prt_underline; | |
1385 static int prt_do_underline; | |
1386 static int prt_need_fgcol; | |
1387 static int prt_fgcol; | |
1388 static int prt_need_bgcol; | |
1389 static int prt_do_bgcol; | |
1390 static int prt_bgcol; | |
1391 static int prt_new_bgcol; | |
1392 static int prt_attribute_change; | |
1393 static float prt_text_run; | |
1394 static int prt_page_num; | |
1395 static int prt_bufsiz; | |
1396 | |
1397 /* | |
1398 * Variables controlling physical printing. | |
1399 */ | |
1400 static int prt_media; | |
1401 static int prt_portrait; | |
1402 static int prt_num_copies; | |
1403 static int prt_duplex; | |
1404 static int prt_tumble; | |
1405 static int prt_collate; | |
1406 | |
1407 /* | |
1408 * Buffers used when generating PostScript output | |
1409 */ | |
1410 static char_u prt_line_buffer[257]; | |
1411 static garray_T prt_ps_buffer; | |
1412 | |
1413 # ifdef FEAT_MBYTE | |
1414 static int prt_do_conv; | |
1415 static vimconv_T prt_conv; | |
1416 | |
1417 static int prt_out_mbyte; | |
1418 static int prt_custom_cmap; | |
1419 static char prt_cmap[80]; | |
1420 static int prt_use_courier; | |
1421 static int prt_in_ascii; | |
1422 static int prt_half_width; | |
1423 static char *prt_ascii_encoding; | |
1424 static char_u prt_hexchar[] = "0123456789abcdef"; | |
1425 # endif | |
1426 | |
1427 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1428 prt_write_file_raw_len(char_u *buffer, int bytes) |
442 | 1429 { |
1430 if (!prt_file_error | |
1431 && fwrite(buffer, sizeof(char_u), bytes, prt_ps_fd) | |
1432 != (size_t)bytes) | |
1433 { | |
1434 EMSG(_("E455: Error writing to PostScript output file")); | |
1435 prt_file_error = TRUE; | |
1436 } | |
1437 } | |
1438 | |
1439 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1440 prt_write_file(char_u *buffer) |
442 | 1441 { |
835 | 1442 prt_write_file_len(buffer, (int)STRLEN(buffer)); |
442 | 1443 } |
1444 | |
1445 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1446 prt_write_file_len(char_u *buffer, int bytes) |
442 | 1447 { |
1448 #ifdef EBCDIC | |
1449 ebcdic2ascii(buffer, bytes); | |
1450 #endif | |
1451 prt_write_file_raw_len(buffer, bytes); | |
1452 } | |
1453 | |
1454 /* | |
1455 * Write a string. | |
1456 */ | |
1457 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1458 prt_write_string(char *s) |
442 | 1459 { |
1460 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%s", s); | |
1461 prt_write_file(prt_line_buffer); | |
1462 } | |
1463 | |
1464 /* | |
1465 * Write an int and a space. | |
1466 */ | |
1467 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1468 prt_write_int(int i) |
442 | 1469 { |
1470 sprintf((char *)prt_line_buffer, "%d ", i); | |
1471 prt_write_file(prt_line_buffer); | |
1472 } | |
1473 | |
1474 /* | |
1475 * Write a boolean and a space. | |
1476 */ | |
1477 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1478 prt_write_boolean(int b) |
442 | 1479 { |
1480 sprintf((char *)prt_line_buffer, "%s ", (b ? "T" : "F")); | |
1481 prt_write_file(prt_line_buffer); | |
1482 } | |
1483 | |
1484 /* | |
1485 * Write PostScript to re-encode and define the font. | |
1486 */ | |
1487 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1488 prt_def_font( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1489 char *new_name, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1490 char *encoding, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1491 int height, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1492 char *font) |
442 | 1493 { |
1494 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
1495 "/_%s /VIM-%s /%s ref\n", new_name, encoding, font); | |
1496 prt_write_file(prt_line_buffer); | |
1497 #ifdef FEAT_MBYTE | |
1498 if (prt_out_mbyte) | |
856 | 1499 sprintf((char *)prt_line_buffer, "/%s %d %f /_%s sffs\n", |
442 | 1500 new_name, height, 500./prt_ps_courier_font.wx, new_name); |
1501 else | |
1502 #endif | |
1503 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
1504 "/%s %d /_%s ffs\n", new_name, height, new_name); | |
1505 prt_write_file(prt_line_buffer); | |
1506 } | |
1507 | |
1508 #ifdef FEAT_MBYTE | |
1509 /* | |
1510 * Write a line to define the CID font. | |
1511 */ | |
1512 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1513 prt_def_cidfont(char *new_name, int height, char *cidfont) |
442 | 1514 { |
1515 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
1516 "/_%s /%s[/%s] vim_composefont\n", new_name, prt_cmap, cidfont); | |
1517 prt_write_file(prt_line_buffer); | |
1518 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
1519 "/%s %d /_%s ffs\n", new_name, height, new_name); | |
1520 prt_write_file(prt_line_buffer); | |
1521 } | |
1522 | |
1523 /* | |
1524 * Write a line to define a duplicate of a CID font | |
1525 */ | |
1526 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1527 prt_dup_cidfont(char *original_name, char *new_name) |
442 | 1528 { |
1529 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
1530 "/%s %s d\n", new_name, original_name); | |
1531 prt_write_file(prt_line_buffer); | |
1532 } | |
1533 #endif | |
1534 | |
1535 /* | |
1536 * Convert a real value into an integer and fractional part as integers, with | |
1537 * the fractional part being in the range [0,10^precision). The fractional part | |
1538 * is also rounded based on the precision + 1'th fractional digit. | |
1539 */ | |
1540 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1541 prt_real_bits( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1542 double real, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1543 int precision, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1544 int *pinteger, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1545 int *pfraction) |
442 | 1546 { |
1547 int i; | |
1548 int integer; | |
1549 float fraction; | |
1550 | |
1551 integer = (int)real; | |
1552 fraction = (float)(real - integer); | |
1553 if (real < (double)integer) | |
1554 fraction = -fraction; | |
1555 for (i = 0; i < precision; i++) | |
1556 fraction *= 10.0; | |
1557 | |
1558 *pinteger = integer; | |
1559 *pfraction = (int)(fraction + 0.5); | |
1560 } | |
1561 | |
1562 /* | |
1563 * Write a real and a space. Save bytes if real value has no fractional part! | |
1564 * We use prt_real_bits() as %f in sprintf uses the locale setting to decide | |
1565 * what decimal point character to use, but PS always requires a '.'. | |
1566 */ | |
1567 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1568 prt_write_real(double val, int prec) |
442 | 1569 { |
1570 int integer; | |
1571 int fraction; | |
1572 | |
1573 prt_real_bits(val, prec, &integer, &fraction); | |
1574 /* Emit integer part */ | |
1575 sprintf((char *)prt_line_buffer, "%d", integer); | |
1576 prt_write_file(prt_line_buffer); | |
1577 /* Only emit fraction if necessary */ | |
1578 if (fraction != 0) | |
1579 { | |
1580 /* Remove any trailing zeros */ | |
1581 while ((fraction % 10) == 0) | |
1582 { | |
1583 prec--; | |
1584 fraction /= 10; | |
1585 } | |
1586 /* Emit fraction left padded with zeros */ | |
1587 sprintf((char *)prt_line_buffer, ".%0*d", prec, fraction); | |
1588 prt_write_file(prt_line_buffer); | |
1589 } | |
1590 sprintf((char *)prt_line_buffer, " "); | |
1591 prt_write_file(prt_line_buffer); | |
1592 } | |
1593 | |
1594 /* | |
1595 * Write a line to define a numeric variable. | |
1596 */ | |
1597 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1598 prt_def_var(char *name, double value, int prec) |
442 | 1599 { |
1600 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
1601 "/%s ", name); | |
1602 prt_write_file(prt_line_buffer); | |
1603 prt_write_real(value, prec); | |
1604 sprintf((char *)prt_line_buffer, "d\n"); | |
1605 prt_write_file(prt_line_buffer); | |
1606 } | |
1607 | |
1608 /* Convert size from font space to user space at current font scale */ | |
1609 #define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0)) | |
1610 | |
1611 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1612 prt_flush_buffer(void) |
442 | 1613 { |
1614 if (prt_ps_buffer.ga_len > 0) | |
1615 { | |
1616 /* Any background color must be drawn first */ | |
1617 if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) | |
1618 { | |
1619 int r, g, b; | |
1620 | |
1621 if (prt_do_moveto) | |
1622 { | |
1623 prt_write_real(prt_pos_x_moveto, 2); | |
1624 prt_write_real(prt_pos_y_moveto, 2); | |
1625 prt_write_string("m\n"); | |
1626 prt_do_moveto = FALSE; | |
1627 } | |
1628 | |
1629 /* Size of rect of background color on which text is printed */ | |
1630 prt_write_real(prt_text_run, 2); | |
1631 prt_write_real(prt_line_height, 2); | |
1632 | |
1633 /* Lastly add the color of the background */ | |
1634 r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16; | |
1635 g = ((unsigned)prt_new_bgcol & 0xff00) >> 8; | |
1636 b = prt_new_bgcol & 0xff; | |
1637 prt_write_real(r / 255.0, 3); | |
1638 prt_write_real(g / 255.0, 3); | |
1639 prt_write_real(b / 255.0, 3); | |
1640 prt_write_string("bg\n"); | |
1641 } | |
1642 /* Draw underlines before the text as it makes it slightly easier to | |
1643 * find the starting point. | |
1644 */ | |
1645 if (prt_do_underline) | |
1646 { | |
1647 if (prt_do_moveto) | |
1648 { | |
1649 prt_write_real(prt_pos_x_moveto, 2); | |
1650 prt_write_real(prt_pos_y_moveto, 2); | |
1651 prt_write_string("m\n"); | |
1652 prt_do_moveto = FALSE; | |
1653 } | |
1654 | |
856 | 1655 /* Underline length of text run */ |
442 | 1656 prt_write_real(prt_text_run, 2); |
1657 prt_write_string("ul\n"); | |
1658 } | |
1659 /* Draw the text | |
1660 * Note: we write text out raw - EBCDIC conversion is handled in the | |
1661 * PostScript world via the font encoding vector. */ | |
1662 #ifdef FEAT_MBYTE | |
856 | 1663 if (prt_out_mbyte) |
1664 prt_write_string("<"); | |
1665 else | |
442 | 1666 #endif |
856 | 1667 prt_write_string("("); |
442 | 1668 prt_write_file_raw_len(prt_ps_buffer.ga_data, prt_ps_buffer.ga_len); |
1669 #ifdef FEAT_MBYTE | |
856 | 1670 if (prt_out_mbyte) |
1671 prt_write_string(">"); | |
1672 else | |
442 | 1673 #endif |
856 | 1674 prt_write_string(")"); |
442 | 1675 /* Add a moveto if need be and use the appropriate show procedure */ |
1676 if (prt_do_moveto) | |
1677 { | |
1678 prt_write_real(prt_pos_x_moveto, 2); | |
1679 prt_write_real(prt_pos_y_moveto, 2); | |
1680 /* moveto and a show */ | |
1681 prt_write_string("ms\n"); | |
1682 prt_do_moveto = FALSE; | |
1683 } | |
1684 else /* Simple show */ | |
1685 prt_write_string("s\n"); | |
1686 | |
1687 ga_clear(&prt_ps_buffer); | |
1688 ga_init2(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz); | |
1689 } | |
1690 } | |
1691 | |
1692 | |
1693 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1694 prt_resource_name(char_u *filename, void *cookie) |
442 | 1695 { |
1696 char_u *resource_filename = cookie; | |
1697 | |
1698 if (STRLEN(filename) >= MAXPATHL) | |
1699 *resource_filename = NUL; | |
1700 else | |
1701 STRCPY(resource_filename, filename); | |
1702 } | |
1703 | |
1704 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1705 prt_find_resource(char *name, struct prt_ps_resource_S *resource) |
442 | 1706 { |
2770 | 1707 char_u *buffer; |
1708 int retval; | |
1709 | |
1710 buffer = alloc(MAXPATHL + 1); | |
1711 if (buffer == NULL) | |
1712 return FALSE; | |
442 | 1713 |
2768 | 1714 vim_strncpy(resource->name, (char_u *)name, 63); |
442 | 1715 /* Look for named resource file in runtimepath */ |
1716 STRCPY(buffer, "print"); | |
1717 add_pathsep(buffer); | |
2768 | 1718 vim_strcat(buffer, (char_u *)name, MAXPATHL); |
1719 vim_strcat(buffer, (char_u *)".ps", MAXPATHL); | |
442 | 1720 resource->filename[0] = NUL; |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1721 retval = (do_in_runtimepath(buffer, 0, prt_resource_name, |
442 | 1722 resource->filename) |
1723 && resource->filename[0] != NUL); | |
2770 | 1724 vim_free(buffer); |
1725 return retval; | |
442 | 1726 } |
1727 | |
1728 /* PS CR and LF characters have platform independent values */ | |
1729 #define PSLF (0x0a) | |
1730 #define PSCR (0x0d) | |
1731 | |
1732 /* Static buffer to read initial comments in a resource file, some can have a | |
1733 * couple of KB of comments! */ | |
1734 #define PRT_FILE_BUFFER_LEN (2048) | |
1735 struct prt_resfile_buffer_S | |
1736 { | |
1737 char_u buffer[PRT_FILE_BUFFER_LEN]; | |
1738 int len; | |
1739 int line_start; | |
1740 int line_end; | |
1741 }; | |
1742 | |
1743 static struct prt_resfile_buffer_S prt_resfile; | |
1744 | |
1745 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1746 prt_resfile_next_line(void) |
442 | 1747 { |
944 | 1748 int idx; |
442 | 1749 |
1750 /* Move to start of next line and then find end of line */ | |
944 | 1751 idx = prt_resfile.line_end + 1; |
1752 while (idx < prt_resfile.len) | |
442 | 1753 { |
944 | 1754 if (prt_resfile.buffer[idx] != PSLF && prt_resfile.buffer[idx] != PSCR) |
856 | 1755 break; |
944 | 1756 idx++; |
442 | 1757 } |
944 | 1758 prt_resfile.line_start = idx; |
1759 | |
1760 while (idx < prt_resfile.len) | |
442 | 1761 { |
944 | 1762 if (prt_resfile.buffer[idx] == PSLF || prt_resfile.buffer[idx] == PSCR) |
856 | 1763 break; |
944 | 1764 idx++; |
442 | 1765 } |
944 | 1766 prt_resfile.line_end = idx; |
1767 | |
1768 return (idx < prt_resfile.len); | |
442 | 1769 } |
1770 | |
1771 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1772 prt_resfile_strncmp(int offset, char *string, int len) |
442 | 1773 { |
1774 /* Force not equal if string is longer than remainder of line */ | |
1775 if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset))) | |
856 | 1776 return 1; |
442 | 1777 |
1778 return STRNCMP(&prt_resfile.buffer[prt_resfile.line_start + offset], | |
856 | 1779 string, len); |
442 | 1780 } |
1781 | |
1782 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1783 prt_resfile_skip_nonws(int offset) |
442 | 1784 { |
944 | 1785 int idx; |
1786 | |
1787 idx = prt_resfile.line_start + offset; | |
1788 while (idx < prt_resfile.line_end) | |
442 | 1789 { |
944 | 1790 if (isspace(prt_resfile.buffer[idx])) |
1791 return idx - prt_resfile.line_start; | |
1792 idx++; | |
442 | 1793 } |
1794 return -1; | |
1795 } | |
1796 | |
1797 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1798 prt_resfile_skip_ws(int offset) |
442 | 1799 { |
944 | 1800 int idx; |
1801 | |
1802 idx = prt_resfile.line_start + offset; | |
1803 while (idx < prt_resfile.line_end) | |
442 | 1804 { |
944 | 1805 if (!isspace(prt_resfile.buffer[idx])) |
1806 return idx - prt_resfile.line_start; | |
1807 idx++; | |
442 | 1808 } |
1809 return -1; | |
1810 } | |
1811 | |
1812 /* prt_next_dsc() - returns detail on next DSC comment line found. Returns true | |
1813 * if a DSC comment is found, else false */ | |
1814 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1815 prt_next_dsc(struct prt_dsc_line_S *p_dsc_line) |
442 | 1816 { |
1817 int comment; | |
1818 int offset; | |
1819 | |
1820 /* Move to start of next line */ | |
1821 if (!prt_resfile_next_line()) | |
856 | 1822 return FALSE; |
442 | 1823 |
1824 /* DSC comments always start %% */ | |
1825 if (prt_resfile_strncmp(0, "%%", 2) != 0) | |
856 | 1826 return FALSE; |
442 | 1827 |
1828 /* Find type of DSC comment */ | |
1880 | 1829 for (comment = 0; comment < (int)NUM_ELEMENTS(prt_dsc_table); comment++) |
856 | 1830 if (prt_resfile_strncmp(0, prt_dsc_table[comment].string, |
1831 prt_dsc_table[comment].len) == 0) | |
1832 break; | |
442 | 1833 |
1834 if (comment != NUM_ELEMENTS(prt_dsc_table)) | |
1835 { | |
856 | 1836 /* Return type of comment */ |
1837 p_dsc_line->type = prt_dsc_table[comment].type; | |
1838 offset = prt_dsc_table[comment].len; | |
442 | 1839 } |
1840 else | |
1841 { | |
856 | 1842 /* Unrecognised DSC comment, skip to ws after comment leader */ |
1843 p_dsc_line->type = PRT_DSC_MISC_TYPE; | |
1844 offset = prt_resfile_skip_nonws(0); | |
1845 if (offset == -1) | |
1846 return FALSE; | |
442 | 1847 } |
1848 | |
1849 /* Skip ws to comment value */ | |
1850 offset = prt_resfile_skip_ws(offset); | |
1851 if (offset == -1) | |
856 | 1852 return FALSE; |
442 | 1853 |
1854 p_dsc_line->string = &prt_resfile.buffer[prt_resfile.line_start + offset]; | |
1855 p_dsc_line->len = prt_resfile.line_end - (prt_resfile.line_start + offset); | |
1856 | |
1857 return TRUE; | |
1858 } | |
1859 | |
1860 /* Improved hand crafted parser to get the type, title, and version number of a | |
1861 * PS resource file so the file details can be added to the DSC header comments. | |
1862 */ | |
1863 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1864 prt_open_resource(struct prt_ps_resource_S *resource) |
442 | 1865 { |
856 | 1866 int offset; |
1867 int seen_all; | |
1868 int seen_title; | |
1869 int seen_version; | |
442 | 1870 FILE *fd_resource; |
1871 struct prt_dsc_line_S dsc_line; | |
1872 | |
1873 fd_resource = mch_fopen((char *)resource->filename, READBIN); | |
1874 if (fd_resource == NULL) | |
1875 { | |
1876 EMSG2(_("E624: Can't open file \"%s\""), resource->filename); | |
1877 return FALSE; | |
1878 } | |
1879 vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN); | |
1880 | |
1881 /* Parse first line to ensure valid resource file */ | |
835 | 1882 prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u), |
856 | 1883 PRT_FILE_BUFFER_LEN, fd_resource); |
442 | 1884 if (ferror(fd_resource)) |
1885 { | |
1886 EMSG2(_("E457: Can't read PostScript resource file \"%s\""), | |
1887 resource->filename); | |
1888 fclose(fd_resource); | |
1889 return FALSE; | |
1890 } | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
1891 fclose(fd_resource); |
442 | 1892 |
1893 prt_resfile.line_end = -1; | |
1894 prt_resfile.line_start = 0; | |
1895 if (!prt_resfile_next_line()) | |
856 | 1896 return FALSE; |
442 | 1897 |
1898 offset = 0; | |
1899 | |
1900 if (prt_resfile_strncmp(offset, PRT_RESOURCE_HEADER, | |
835 | 1901 (int)STRLEN(PRT_RESOURCE_HEADER)) != 0) |
442 | 1902 { |
1903 EMSG2(_("E618: file \"%s\" is not a PostScript resource file"), | |
1904 resource->filename); | |
1905 return FALSE; | |
1906 } | |
1907 | |
1908 /* Skip over any version numbers and following ws */ | |
835 | 1909 offset += (int)STRLEN(PRT_RESOURCE_HEADER); |
442 | 1910 offset = prt_resfile_skip_nonws(offset); |
1911 if (offset == -1) | |
856 | 1912 return FALSE; |
442 | 1913 offset = prt_resfile_skip_ws(offset); |
1914 if (offset == -1) | |
856 | 1915 return FALSE; |
442 | 1916 |
1917 if (prt_resfile_strncmp(offset, PRT_RESOURCE_RESOURCE, | |
835 | 1918 (int)STRLEN(PRT_RESOURCE_RESOURCE)) != 0) |
442 | 1919 { |
1920 EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"), | |
1921 resource->filename); | |
1922 return FALSE; | |
1923 } | |
835 | 1924 offset += (int)STRLEN(PRT_RESOURCE_RESOURCE); |
442 | 1925 |
1926 /* Decide type of resource in the file */ | |
1927 if (prt_resfile_strncmp(offset, PRT_RESOURCE_PROCSET, | |
835 | 1928 (int)STRLEN(PRT_RESOURCE_PROCSET)) == 0) |
442 | 1929 resource->type = PRT_RESOURCE_TYPE_PROCSET; |
1930 else if (prt_resfile_strncmp(offset, PRT_RESOURCE_ENCODING, | |
835 | 1931 (int)STRLEN(PRT_RESOURCE_ENCODING)) == 0) |
442 | 1932 resource->type = PRT_RESOURCE_TYPE_ENCODING; |
1933 else if (prt_resfile_strncmp(offset, PRT_RESOURCE_CMAP, | |
835 | 1934 (int)STRLEN(PRT_RESOURCE_CMAP)) == 0) |
442 | 1935 resource->type = PRT_RESOURCE_TYPE_CMAP; |
1936 else | |
1937 { | |
1938 EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"), | |
1939 resource->filename); | |
1940 return FALSE; | |
1941 } | |
1942 | |
1943 /* Look for title and version of resource */ | |
1944 resource->title[0] = '\0'; | |
1945 resource->version[0] = '\0'; | |
1946 seen_title = FALSE; | |
1947 seen_version = FALSE; | |
1948 seen_all = FALSE; | |
1949 while (!seen_all && prt_next_dsc(&dsc_line)) | |
1950 { | |
856 | 1951 switch (dsc_line.type) |
1952 { | |
1953 case PRT_DSC_TITLE_TYPE: | |
1954 vim_strncpy(resource->title, dsc_line.string, dsc_line.len); | |
1955 seen_title = TRUE; | |
1956 if (seen_version) | |
1957 seen_all = TRUE; | |
1958 break; | |
1959 | |
1960 case PRT_DSC_VERSION_TYPE: | |
1961 vim_strncpy(resource->version, dsc_line.string, dsc_line.len); | |
1962 seen_version = TRUE; | |
1963 if (seen_title) | |
1964 seen_all = TRUE; | |
1965 break; | |
1966 | |
1967 case PRT_DSC_ENDCOMMENTS_TYPE: | |
1968 /* Wont find title or resource after this comment, stop searching */ | |
1969 seen_all = TRUE; | |
1970 break; | |
1971 | |
1972 case PRT_DSC_MISC_TYPE: | |
1973 /* Not interested in whatever comment this line had */ | |
1974 break; | |
1975 } | |
442 | 1976 } |
1977 | |
1978 if (!seen_title || !seen_version) | |
1979 { | |
1980 EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"), | |
1981 resource->filename); | |
1982 return FALSE; | |
1983 } | |
1984 | |
1985 return TRUE; | |
1986 } | |
1987 | |
1988 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1989 prt_check_resource(struct prt_ps_resource_S *resource, char_u *version) |
442 | 1990 { |
1991 /* Version number m.n should match, the revision number does not matter */ | |
1992 if (STRNCMP(resource->version, version, STRLEN(version))) | |
1993 { | |
1994 EMSG2(_("E621: \"%s\" resource file has wrong version"), | |
1995 resource->name); | |
1996 return FALSE; | |
1997 } | |
1998 | |
1999 /* Other checks to be added as needed */ | |
2000 return TRUE; | |
2001 } | |
2002 | |
2003 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2004 prt_dsc_start(void) |
442 | 2005 { |
2006 prt_write_string("%!PS-Adobe-3.0\n"); | |
2007 } | |
2008 | |
2009 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2010 prt_dsc_noarg(char *comment) |
442 | 2011 { |
2012 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
2013 "%%%%%s\n", comment); | |
2014 prt_write_file(prt_line_buffer); | |
2015 } | |
2016 | |
2017 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2018 prt_dsc_textline(char *comment, char *text) |
442 | 2019 { |
2020 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
2021 "%%%%%s: %s\n", comment, text); | |
2022 prt_write_file(prt_line_buffer); | |
2023 } | |
2024 | |
2025 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2026 prt_dsc_text(char *comment, char *text) |
442 | 2027 { |
2028 /* TODO - should scan 'text' for any chars needing escaping! */ | |
2029 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
2030 "%%%%%s: (%s)\n", comment, text); | |
2031 prt_write_file(prt_line_buffer); | |
2032 } | |
2033 | |
2034 #define prt_dsc_atend(c) prt_dsc_text((c), "atend") | |
2035 | |
2036 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2037 prt_dsc_ints(char *comment, int count, int *ints) |
442 | 2038 { |
2039 int i; | |
2040 | |
2041 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
2042 "%%%%%s:", comment); | |
2043 prt_write_file(prt_line_buffer); | |
2044 | |
2045 for (i = 0; i < count; i++) | |
2046 { | |
2047 sprintf((char *)prt_line_buffer, " %d", ints[i]); | |
2048 prt_write_file(prt_line_buffer); | |
2049 } | |
2050 | |
2051 prt_write_string("\n"); | |
2052 } | |
2053 | |
2054 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2055 prt_dsc_resources( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2056 char *comment, /* if NULL add to previous */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2057 char *type, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2058 char *string) |
442 | 2059 { |
2060 if (comment != NULL) | |
2061 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
2062 "%%%%%s: %s", comment, type); | |
2063 else | |
2064 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
2065 "%%%%+ %s", type); | |
2066 prt_write_file(prt_line_buffer); | |
2067 | |
2068 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
2069 " %s\n", string); | |
2070 prt_write_file(prt_line_buffer); | |
2071 } | |
2072 | |
2073 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2074 prt_dsc_font_resource(char *resource, struct prt_ps_font_S *ps_font) |
442 | 2075 { |
2076 int i; | |
2077 | |
2078 prt_dsc_resources(resource, "font", | |
856 | 2079 ps_font->ps_fontname[PRT_PS_FONT_ROMAN]); |
442 | 2080 for (i = PRT_PS_FONT_BOLD ; i <= PRT_PS_FONT_BOLDOBLIQUE ; i++) |
856 | 2081 if (ps_font->ps_fontname[i] != NULL) |
2082 prt_dsc_resources(NULL, "font", ps_font->ps_fontname[i]); | |
442 | 2083 } |
2084 | |
2085 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2086 prt_dsc_requirements( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2087 int duplex, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2088 int tumble, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2089 int collate, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2090 int color, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2091 int num_copies) |
442 | 2092 { |
2093 /* Only output the comment if we need to. | |
2094 * Note: tumble is ignored if we are not duplexing | |
2095 */ | |
2096 if (!(duplex || collate || color || (num_copies > 1))) | |
2097 return; | |
2098 | |
2099 sprintf((char *)prt_line_buffer, "%%%%Requirements:"); | |
2100 prt_write_file(prt_line_buffer); | |
2101 | |
2102 if (duplex) | |
2103 { | |
2104 prt_write_string(" duplex"); | |
2105 if (tumble) | |
2106 prt_write_string("(tumble)"); | |
2107 } | |
2108 if (collate) | |
2109 prt_write_string(" collate"); | |
2110 if (color) | |
2111 prt_write_string(" color"); | |
2112 if (num_copies > 1) | |
2113 { | |
2114 prt_write_string(" numcopies("); | |
4352 | 2115 /* Note: no space wanted so don't use prt_write_int() */ |
442 | 2116 sprintf((char *)prt_line_buffer, "%d", num_copies); |
2117 prt_write_file(prt_line_buffer); | |
2118 prt_write_string(")"); | |
2119 } | |
2120 prt_write_string("\n"); | |
2121 } | |
2122 | |
2123 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2124 prt_dsc_docmedia( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2125 char *paper_name, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2126 double width, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2127 double height, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2128 double weight, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2129 char *colour, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2130 char *type) |
442 | 2131 { |
2132 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), | |
2133 "%%%%DocumentMedia: %s ", paper_name); | |
2134 prt_write_file(prt_line_buffer); | |
2135 prt_write_real(width, 2); | |
2136 prt_write_real(height, 2); | |
2137 prt_write_real(weight, 2); | |
2138 if (colour == NULL) | |
2139 prt_write_string("()"); | |
2140 else | |
2141 prt_write_string(colour); | |
2142 prt_write_string(" "); | |
2143 if (type == NULL) | |
2144 prt_write_string("()"); | |
2145 else | |
2146 prt_write_string(type); | |
2147 prt_write_string("\n"); | |
2148 } | |
2149 | |
2150 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2151 mch_print_cleanup(void) |
442 | 2152 { |
2153 #ifdef FEAT_MBYTE | |
2154 if (prt_out_mbyte) | |
2155 { | |
856 | 2156 int i; |
2157 | |
2158 /* Free off all CID font names created, but first clear duplicate | |
2159 * pointers to the same string (when the same font is used for more than | |
2160 * one style). | |
2161 */ | |
2162 for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) | |
2163 { | |
2164 if (prt_ps_mb_font.ps_fontname[i] != NULL) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2165 VIM_CLEAR(prt_ps_mb_font.ps_fontname[i]); |
856 | 2166 } |
442 | 2167 } |
2168 | |
2169 if (prt_do_conv) | |
2170 { | |
2171 convert_setup(&prt_conv, NULL, NULL); | |
2172 prt_do_conv = FALSE; | |
2173 } | |
2174 #endif | |
2175 if (prt_ps_fd != NULL) | |
2176 { | |
2177 fclose(prt_ps_fd); | |
2178 prt_ps_fd = NULL; | |
2179 prt_file_error = FALSE; | |
2180 } | |
2181 if (prt_ps_file_name != NULL) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2182 VIM_CLEAR(prt_ps_file_name); |
442 | 2183 } |
2184 | |
2185 static float | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2186 to_device_units(int idx, double physsize, int def_number) |
442 | 2187 { |
2188 float ret; | |
2189 int u; | |
2190 int nr; | |
2191 | |
2192 u = prt_get_unit(idx); | |
2193 if (u == PRT_UNIT_NONE) | |
2194 { | |
2195 u = PRT_UNIT_PERC; | |
2196 nr = def_number; | |
2197 } | |
2198 else | |
2199 nr = printer_opts[idx].number; | |
2200 | |
2201 switch (u) | |
2202 { | |
2203 case PRT_UNIT_INCH: | |
2204 ret = (float)(nr * PRT_PS_DEFAULT_DPI); | |
2205 break; | |
2206 case PRT_UNIT_MM: | |
2207 ret = (float)(nr * PRT_PS_DEFAULT_DPI) / (float)25.4; | |
2208 break; | |
2209 case PRT_UNIT_POINT: | |
2210 ret = (float)nr; | |
2211 break; | |
2212 case PRT_UNIT_PERC: | |
2213 default: | |
2214 ret = (float)(physsize * nr) / 100; | |
2215 break; | |
2216 } | |
2217 | |
2218 return ret; | |
2219 } | |
2220 | |
2221 /* | |
2222 * Calculate margins for given width and height from printoptions settings. | |
2223 */ | |
2224 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2225 prt_page_margins( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2226 double width, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2227 double height, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2228 double *left, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2229 double *right, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2230 double *top, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2231 double *bottom) |
442 | 2232 { |
2233 *left = to_device_units(OPT_PRINT_LEFT, width, 10); | |
2234 *right = width - to_device_units(OPT_PRINT_RIGHT, width, 5); | |
2235 *top = height - to_device_units(OPT_PRINT_TOP, height, 5); | |
2236 *bottom = to_device_units(OPT_PRINT_BOT, height, 5); | |
2237 } | |
2238 | |
2239 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2240 prt_font_metrics(int font_scale) |
442 | 2241 { |
2242 prt_line_height = (float)font_scale; | |
2243 prt_char_width = (float)PRT_PS_FONT_TO_USER(font_scale, prt_ps_font->wx); | |
2244 } | |
2245 | |
2246 | |
2247 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2248 prt_get_cpl(void) |
442 | 2249 { |
2250 if (prt_use_number()) | |
2251 { | |
2252 prt_number_width = PRINT_NUMBER_WIDTH * prt_char_width; | |
2253 #ifdef FEAT_MBYTE | |
856 | 2254 /* If we are outputting multi-byte characters then line numbers will be |
2255 * printed with half width characters | |
2256 */ | |
2257 if (prt_out_mbyte) | |
2258 prt_number_width /= 2; | |
442 | 2259 #endif |
2260 prt_left_margin += prt_number_width; | |
2261 } | |
2262 else | |
2263 prt_number_width = 0.0; | |
2264 | |
2265 return (int)((prt_right_margin - prt_left_margin) / prt_char_width); | |
2266 } | |
2267 | |
2268 #ifdef FEAT_MBYTE | |
2269 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2270 prt_build_cid_fontname(int font, char_u *name, int name_len) |
442 | 2271 { |
2272 char *fontname; | |
2273 | |
2274 fontname = (char *)alloc(name_len + 1); | |
2275 if (fontname == NULL) | |
856 | 2276 return FALSE; |
442 | 2277 vim_strncpy((char_u *)fontname, name, name_len); |
2278 prt_ps_mb_font.ps_fontname[font] = fontname; | |
2279 | |
2280 return TRUE; | |
2281 } | |
2282 #endif | |
2283 | |
2284 /* | |
2285 * Get number of lines of text that fit on a page (excluding the header). | |
2286 */ | |
2287 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2288 prt_get_lpp(void) |
442 | 2289 { |
2290 int lpp; | |
2291 | |
2292 /* | |
2293 * Calculate offset to lower left corner of background rect based on actual | |
2294 * font height (based on its bounding box) and the line height, handling the | |
2295 * case where the font height can exceed the line height. | |
2296 */ | |
2297 prt_bgcol_offset = (float)PRT_PS_FONT_TO_USER(prt_line_height, | |
2298 prt_ps_font->bbox_min_y); | |
2299 if ((prt_ps_font->bbox_max_y - prt_ps_font->bbox_min_y) < 1000.0) | |
2300 { | |
2301 prt_bgcol_offset -= (float)PRT_PS_FONT_TO_USER(prt_line_height, | |
2302 (1000.0 - (prt_ps_font->bbox_max_y - | |
2303 prt_ps_font->bbox_min_y)) / 2); | |
2304 } | |
2305 | |
2306 /* Get height for topmost line based on background rect offset. */ | |
2307 prt_first_line_height = prt_line_height + prt_bgcol_offset; | |
2308 | |
2309 /* Calculate lpp */ | |
2310 lpp = (int)((prt_top_margin - prt_bottom_margin) / prt_line_height); | |
2311 | |
2312 /* Adjust top margin if there is a header */ | |
2313 prt_top_margin -= prt_line_height * prt_header_height(); | |
2314 | |
2315 return lpp - prt_header_height(); | |
2316 } | |
2317 | |
2318 #ifdef FEAT_MBYTE | |
2319 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2320 prt_match_encoding( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2321 char *p_encoding, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2322 struct prt_ps_mbfont_S *p_cmap, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2323 struct prt_ps_encoding_S **pp_mbenc) |
442 | 2324 { |
2325 int mbenc; | |
2326 int enc_len; | |
2327 struct prt_ps_encoding_S *p_mbenc; | |
2328 | |
2329 *pp_mbenc = NULL; | |
2330 /* Look for recognised encoding */ | |
835 | 2331 enc_len = (int)STRLEN(p_encoding); |
442 | 2332 p_mbenc = p_cmap->encodings; |
2333 for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++) | |
2334 { | |
856 | 2335 if (STRNICMP(p_mbenc->encoding, p_encoding, enc_len) == 0) |
2336 { | |
2337 *pp_mbenc = p_mbenc; | |
2338 return TRUE; | |
2339 } | |
2340 p_mbenc++; | |
442 | 2341 } |
2342 return FALSE; | |
2343 } | |
2344 | |
2345 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2346 prt_match_charset( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2347 char *p_charset, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2348 struct prt_ps_mbfont_S *p_cmap, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2349 struct prt_ps_charset_S **pp_mbchar) |
442 | 2350 { |
2351 int mbchar; | |
2352 int char_len; | |
2353 struct prt_ps_charset_S *p_mbchar; | |
2354 | |
2355 /* Look for recognised character set, using default if one is not given */ | |
2356 if (*p_charset == NUL) | |
856 | 2357 p_charset = p_cmap->defcs; |
835 | 2358 char_len = (int)STRLEN(p_charset); |
442 | 2359 p_mbchar = p_cmap->charsets; |
2360 for (mbchar = 0; mbchar < p_cmap->num_charsets; mbchar++) | |
2361 { | |
856 | 2362 if (STRNICMP(p_mbchar->charset, p_charset, char_len) == 0) |
2363 { | |
2364 *pp_mbchar = p_mbchar; | |
2365 return TRUE; | |
2366 } | |
2367 p_mbchar++; | |
442 | 2368 } |
2369 return FALSE; | |
2370 } | |
2371 #endif | |
2372 | |
2373 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2374 mch_print_init( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2375 prt_settings_T *psettings, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2376 char_u *jobname, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2377 int forceit UNUSED) |
442 | 2378 { |
2379 int i; | |
2380 char *paper_name; | |
2381 int paper_strlen; | |
2382 int fontsize; | |
2383 char_u *p; | |
2384 double left; | |
2385 double right; | |
2386 double top; | |
2387 double bottom; | |
2388 #ifdef FEAT_MBYTE | |
856 | 2389 int props; |
2390 int cmap = 0; | |
442 | 2391 char_u *p_encoding; |
2392 struct prt_ps_encoding_S *p_mbenc; | |
2393 struct prt_ps_encoding_S *p_mbenc_first; | |
944 | 2394 struct prt_ps_charset_S *p_mbchar = NULL; |
442 | 2395 #endif |
2396 | |
2397 #if 0 | |
2398 /* | |
2399 * TODO: | |
2400 * If "forceit" is false: pop up a dialog to select: | |
2401 * - printer name | |
2402 * - copies | |
2403 * - collated/uncollated | |
2404 * - duplex off/long side/short side | |
2405 * - paper size | |
2406 * - portrait/landscape | |
2407 * - font size | |
2408 * | |
2409 * If "forceit" is true: use the default printer and settings | |
2410 */ | |
2411 if (forceit) | |
2412 s_pd.Flags |= PD_RETURNDEFAULT; | |
2413 #endif | |
2414 | |
2415 /* | |
2416 * Set up font and encoding. | |
2417 */ | |
2418 #ifdef FEAT_MBYTE | |
2419 p_encoding = enc_skip(p_penc); | |
2420 if (*p_encoding == NUL) | |
856 | 2421 p_encoding = enc_skip(p_enc); |
442 | 2422 |
864 | 2423 /* Look for a multi-byte font that matches the encoding and character set. |
2424 * Only look if multi-byte character set is defined, or using multi-byte | |
2425 * encoding other than Unicode. This is because a Unicode encoding does not | |
2426 * uniquely identify a CJK character set to use. */ | |
442 | 2427 p_mbenc = NULL; |
819 | 2428 props = enc_canon_props(p_encoding); |
864 | 2429 if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) |
819 | 2430 { |
6759 | 2431 int cmap_first = 0; |
6745 | 2432 |
856 | 2433 p_mbenc_first = NULL; |
1880 | 2434 for (cmap = 0; cmap < (int)NUM_ELEMENTS(prt_ps_mbfonts); cmap++) |
856 | 2435 if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap], |
442 | 2436 &p_mbenc)) |
856 | 2437 { |
2438 if (p_mbenc_first == NULL) | |
6745 | 2439 { |
856 | 2440 p_mbenc_first = p_mbenc; |
6745 | 2441 cmap_first = cmap; |
2442 } | |
856 | 2443 if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap], |
442 | 2444 &p_mbchar)) |
856 | 2445 break; |
2446 } | |
2447 | |
2448 /* Use first encoding matched if no charset matched */ | |
2449 if (p_mbchar == NULL && p_mbenc_first != NULL) | |
6745 | 2450 { |
856 | 2451 p_mbenc = p_mbenc_first; |
6745 | 2452 cmap = cmap_first; |
2453 } | |
819 | 2454 } |
442 | 2455 |
2456 prt_out_mbyte = (p_mbenc != NULL); | |
2457 if (prt_out_mbyte) | |
2458 { | |
856 | 2459 /* Build CMap name - will be same for all multi-byte fonts used */ |
2460 prt_cmap[0] = NUL; | |
2461 | |
2462 prt_custom_cmap = (p_mbchar == NULL); | |
2463 if (!prt_custom_cmap) | |
2464 { | |
2465 /* Check encoding and character set are compatible */ | |
2466 if ((p_mbenc->needs_charset & p_mbchar->has_charset) == 0) | |
2467 { | |
2468 EMSG(_("E673: Incompatible multi-byte encoding and character set.")); | |
2469 return FALSE; | |
2470 } | |
2471 | |
2472 /* Add charset name if not empty */ | |
2473 if (p_mbchar->cmap_charset != NULL) | |
2474 { | |
2475 vim_strncpy((char_u *)prt_cmap, | |
442 | 2476 (char_u *)p_mbchar->cmap_charset, sizeof(prt_cmap) - 3); |
856 | 2477 STRCAT(prt_cmap, "-"); |
2478 } | |
2479 } | |
2480 else | |
2481 { | |
2482 /* Add custom CMap character set name */ | |
2483 if (*p_pmcs == NUL) | |
2484 { | |
2485 EMSG(_("E674: printmbcharset cannot be empty with multi-byte encoding.")); | |
2486 return FALSE; | |
2487 } | |
2488 vim_strncpy((char_u *)prt_cmap, p_pmcs, sizeof(prt_cmap) - 3); | |
2489 STRCAT(prt_cmap, "-"); | |
2490 } | |
2491 | |
2492 /* CMap name ends with (optional) encoding name and -H for horizontal */ | |
2493 if (p_mbenc->cmap_encoding != NULL && STRLEN(prt_cmap) | |
442 | 2494 + STRLEN(p_mbenc->cmap_encoding) + 3 < sizeof(prt_cmap)) |
856 | 2495 { |
2496 STRCAT(prt_cmap, p_mbenc->cmap_encoding); | |
2497 STRCAT(prt_cmap, "-"); | |
2498 } | |
2499 STRCAT(prt_cmap, "H"); | |
2500 | |
2501 if (!mbfont_opts[OPT_MBFONT_REGULAR].present) | |
2502 { | |
2503 EMSG(_("E675: No default font specified for multi-byte printing.")); | |
2504 return FALSE; | |
2505 } | |
2506 | |
2507 /* Derive CID font names with fallbacks if not defined */ | |
2508 if (!prt_build_cid_fontname(PRT_PS_FONT_ROMAN, | |
2509 mbfont_opts[OPT_MBFONT_REGULAR].string, | |
2510 mbfont_opts[OPT_MBFONT_REGULAR].strlen)) | |
2511 return FALSE; | |
2512 if (mbfont_opts[OPT_MBFONT_BOLD].present) | |
2513 if (!prt_build_cid_fontname(PRT_PS_FONT_BOLD, | |
2514 mbfont_opts[OPT_MBFONT_BOLD].string, | |
2515 mbfont_opts[OPT_MBFONT_BOLD].strlen)) | |
2516 return FALSE; | |
2517 if (mbfont_opts[OPT_MBFONT_OBLIQUE].present) | |
2518 if (!prt_build_cid_fontname(PRT_PS_FONT_OBLIQUE, | |
2519 mbfont_opts[OPT_MBFONT_OBLIQUE].string, | |
2520 mbfont_opts[OPT_MBFONT_OBLIQUE].strlen)) | |
2521 return FALSE; | |
2522 if (mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].present) | |
2523 if (!prt_build_cid_fontname(PRT_PS_FONT_BOLDOBLIQUE, | |
442 | 2524 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].string, |
2525 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen)) | |
856 | 2526 return FALSE; |
2527 | |
2528 /* Check if need to use Courier for ASCII code range, and if so pick up | |
2529 * the encoding to use */ | |
2530 prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && | |
2531 (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y'); | |
2532 if (prt_use_courier) | |
2533 { | |
2534 /* Use national ASCII variant unless ASCII wanted */ | |
2535 if (mbfont_opts[OPT_MBFONT_ASCII].present && | |
2536 (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) | |
2537 prt_ascii_encoding = "ascii"; | |
2538 else | |
2539 prt_ascii_encoding = prt_ps_mbfonts[cmap].ascii_enc; | |
2540 } | |
2541 | |
2542 prt_ps_font = &prt_ps_mb_font; | |
442 | 2543 } |
2544 else | |
2545 #endif | |
2546 { | |
2547 #ifdef FEAT_MBYTE | |
856 | 2548 prt_use_courier = FALSE; |
442 | 2549 #endif |
856 | 2550 prt_ps_font = &prt_ps_courier_font; |
442 | 2551 } |
2552 | |
2553 /* | |
2554 * Find the size of the paper and set the margins. | |
2555 */ | |
2556 prt_portrait = (!printer_opts[OPT_PRINT_PORTRAIT].present | |
2557 || TOLOWER_ASC(printer_opts[OPT_PRINT_PORTRAIT].string[0]) == 'y'); | |
2558 if (printer_opts[OPT_PRINT_PAPER].present) | |
2559 { | |
2560 paper_name = (char *)printer_opts[OPT_PRINT_PAPER].string; | |
2561 paper_strlen = printer_opts[OPT_PRINT_PAPER].strlen; | |
2562 } | |
2563 else | |
2564 { | |
2565 paper_name = "A4"; | |
2566 paper_strlen = 2; | |
2567 } | |
1880 | 2568 for (i = 0; i < (int)PRT_MEDIASIZE_LEN; ++i) |
442 | 2569 if (STRLEN(prt_mediasize[i].name) == (unsigned)paper_strlen |
2570 && STRNICMP(prt_mediasize[i].name, paper_name, | |
2571 paper_strlen) == 0) | |
2572 break; | |
2573 if (i == PRT_MEDIASIZE_LEN) | |
2574 i = 0; | |
2575 prt_media = i; | |
2576 | |
2577 /* | |
2578 * Set PS pagesize based on media dimensions and print orientation. | |
2579 * Note: Media and page sizes have defined meanings in PostScript and should | |
2580 * be kept distinct. Media is the paper (or transparency, or ...) that is | |
2581 * printed on, whereas the page size is the area that the PostScript | |
2582 * interpreter renders into. | |
2583 */ | |
2584 if (prt_portrait) | |
2585 { | |
2586 prt_page_width = prt_mediasize[i].width; | |
2587 prt_page_height = prt_mediasize[i].height; | |
2588 } | |
2589 else | |
2590 { | |
2591 prt_page_width = prt_mediasize[i].height; | |
2592 prt_page_height = prt_mediasize[i].width; | |
2593 } | |
2594 | |
2595 /* | |
2596 * Set PS page margins based on the PS pagesize, not the mediasize - this | |
2597 * needs to be done before the cpl and lpp are calculated. | |
2598 */ | |
2599 prt_page_margins(prt_page_width, prt_page_height, &left, &right, &top, | |
2600 &bottom); | |
2601 prt_left_margin = (float)left; | |
2602 prt_right_margin = (float)right; | |
2603 prt_top_margin = (float)top; | |
2604 prt_bottom_margin = (float)bottom; | |
2605 | |
2606 /* | |
2607 * Set up the font size. | |
2608 */ | |
2609 fontsize = PRT_PS_DEFAULT_FONTSIZE; | |
2610 for (p = p_pfn; (p = vim_strchr(p, ':')) != NULL; ++p) | |
2611 if (p[1] == 'h' && VIM_ISDIGIT(p[2])) | |
2612 fontsize = atoi((char *)p + 2); | |
2613 prt_font_metrics(fontsize); | |
2614 | |
2615 /* | |
2616 * Return the number of characters per line, and lines per page for the | |
2617 * generic print code. | |
2618 */ | |
2619 psettings->chars_per_line = prt_get_cpl(); | |
2620 psettings->lines_per_page = prt_get_lpp(); | |
2621 | |
2622 /* Catch margin settings that leave no space for output! */ | |
2623 if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0) | |
2624 return FAIL; | |
2625 | |
2626 /* | |
2627 * Sort out the number of copies to be printed. PS by default will do | |
2628 * uncollated copies for you, so once we know how many uncollated copies are | |
2629 * wanted cache it away and lie to the generic code that we only want one | |
2630 * uncollated copy. | |
2631 */ | |
2632 psettings->n_collated_copies = 1; | |
2633 psettings->n_uncollated_copies = 1; | |
2634 prt_num_copies = 1; | |
2635 prt_collate = (!printer_opts[OPT_PRINT_COLLATE].present | |
2636 || TOLOWER_ASC(printer_opts[OPT_PRINT_COLLATE].string[0]) == 'y'); | |
2637 if (prt_collate) | |
2638 { | |
2639 /* TODO: Get number of collated copies wanted. */ | |
2640 psettings->n_collated_copies = 1; | |
2641 } | |
2642 else | |
2643 { | |
2644 /* TODO: Get number of uncollated copies wanted and update the cached | |
2645 * count. | |
2646 */ | |
2647 prt_num_copies = 1; | |
2648 } | |
2649 | |
2650 psettings->jobname = jobname; | |
2651 | |
2652 /* | |
2653 * Set up printer duplex and tumble based on Duplex option setting - default | |
2654 * is long sided duplex printing (i.e. no tumble). | |
2655 */ | |
2656 prt_duplex = TRUE; | |
2657 prt_tumble = FALSE; | |
2658 psettings->duplex = 1; | |
2659 if (printer_opts[OPT_PRINT_DUPLEX].present) | |
2660 { | |
2661 if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "off", 3) == 0) | |
2662 { | |
2663 prt_duplex = FALSE; | |
2664 psettings->duplex = 0; | |
2665 } | |
2666 else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5) | |
2667 == 0) | |
2668 prt_tumble = TRUE; | |
2669 } | |
2670 | |
2671 /* For now user abort not supported */ | |
2672 psettings->user_abort = 0; | |
2673 | |
2674 /* If the user didn't specify a file name, use a temp file. */ | |
2675 if (psettings->outfile == NULL) | |
2676 { | |
6721 | 2677 prt_ps_file_name = vim_tempname('p', TRUE); |
442 | 2678 if (prt_ps_file_name == NULL) |
2679 { | |
2680 EMSG(_(e_notmp)); | |
2681 return FAIL; | |
2682 } | |
2683 prt_ps_fd = mch_fopen((char *)prt_ps_file_name, WRITEBIN); | |
2684 } | |
2685 else | |
2686 { | |
2687 p = expand_env_save(psettings->outfile); | |
2688 if (p != NULL) | |
2689 { | |
2690 prt_ps_fd = mch_fopen((char *)p, WRITEBIN); | |
2691 vim_free(p); | |
2692 } | |
2693 } | |
2694 if (prt_ps_fd == NULL) | |
2695 { | |
2696 EMSG(_("E324: Can't open PostScript output file")); | |
2697 mch_print_cleanup(); | |
2698 return FAIL; | |
2699 } | |
2700 | |
2701 prt_bufsiz = psettings->chars_per_line; | |
2702 #ifdef FEAT_MBYTE | |
2703 if (prt_out_mbyte) | |
856 | 2704 prt_bufsiz *= 2; |
442 | 2705 #endif |
2706 ga_init2(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz); | |
2707 | |
2708 prt_page_num = 0; | |
2709 | |
2710 prt_attribute_change = FALSE; | |
2711 prt_need_moveto = FALSE; | |
2712 prt_need_font = FALSE; | |
2713 prt_need_fgcol = FALSE; | |
2714 prt_need_bgcol = FALSE; | |
2715 prt_need_underline = FALSE; | |
2716 | |
2717 prt_file_error = FALSE; | |
2718 | |
2719 return OK; | |
2720 } | |
2721 | |
2722 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2723 prt_add_resource(struct prt_ps_resource_S *resource) |
442 | 2724 { |
2725 FILE* fd_resource; | |
2726 char_u resource_buffer[512]; | |
2727 size_t bytes_read; | |
2728 | |
2729 fd_resource = mch_fopen((char *)resource->filename, READBIN); | |
2730 if (fd_resource == NULL) | |
2731 { | |
2732 EMSG2(_("E456: Can't open file \"%s\""), resource->filename); | |
2733 return FALSE; | |
2734 } | |
2735 prt_dsc_resources("BeginResource", prt_resource_types[resource->type], | |
2736 (char *)resource->title); | |
2737 | |
2738 prt_dsc_textline("BeginDocument", (char *)resource->filename); | |
2739 | |
2740 for (;;) | |
2741 { | |
2742 bytes_read = fread((char *)resource_buffer, sizeof(char_u), | |
2743 sizeof(resource_buffer), fd_resource); | |
2744 if (ferror(fd_resource)) | |
2745 { | |
2746 EMSG2(_("E457: Can't read PostScript resource file \"%s\""), | |
2747 resource->filename); | |
2748 fclose(fd_resource); | |
2749 return FALSE; | |
2750 } | |
2751 if (bytes_read == 0) | |
2752 break; | |
835 | 2753 prt_write_file_raw_len(resource_buffer, (int)bytes_read); |
442 | 2754 if (prt_file_error) |
2755 { | |
2756 fclose(fd_resource); | |
2757 return FALSE; | |
2758 } | |
2759 } | |
2760 fclose(fd_resource); | |
2761 | |
2762 prt_dsc_noarg("EndDocument"); | |
2763 | |
2764 prt_dsc_noarg("EndResource"); | |
2765 | |
2766 return TRUE; | |
2767 } | |
2768 | |
2769 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2770 mch_print_begin(prt_settings_T *psettings) |
442 | 2771 { |
2772 time_t now; | |
2773 int bbox[4]; | |
2774 char *p_time; | |
2775 double left; | |
2776 double right; | |
2777 double top; | |
2778 double bottom; | |
2770 | 2779 struct prt_ps_resource_S *res_prolog; |
2780 struct prt_ps_resource_S *res_encoding; | |
442 | 2781 char buffer[256]; |
2782 char_u *p_encoding; | |
840 | 2783 char_u *p; |
442 | 2784 #ifdef FEAT_MBYTE |
2770 | 2785 struct prt_ps_resource_S *res_cidfont; |
2786 struct prt_ps_resource_S *res_cmap; | |
442 | 2787 #endif |
2770 | 2788 int retval = FALSE; |
2789 | |
2790 res_prolog = (struct prt_ps_resource_S *) | |
2791 alloc(sizeof(struct prt_ps_resource_S)); | |
2792 res_encoding = (struct prt_ps_resource_S *) | |
2793 alloc(sizeof(struct prt_ps_resource_S)); | |
2794 #ifdef FEAT_MBYTE | |
2795 res_cidfont = (struct prt_ps_resource_S *) | |
2796 alloc(sizeof(struct prt_ps_resource_S)); | |
2797 res_cmap = (struct prt_ps_resource_S *) | |
2798 alloc(sizeof(struct prt_ps_resource_S)); | |
2799 #endif | |
2800 if (res_prolog == NULL || res_encoding == NULL | |
2801 #ifdef FEAT_MBYTE | |
2802 || res_cidfont == NULL || res_cmap == NULL | |
2803 #endif | |
2804 ) | |
2805 goto theend; | |
442 | 2806 |
2807 /* | |
2808 * PS DSC Header comments - no PS code! | |
2809 */ | |
2810 prt_dsc_start(); | |
2811 prt_dsc_textline("Title", (char *)psettings->jobname); | |
2812 if (!get_user_name((char_u *)buffer, 256)) | |
856 | 2813 STRCPY(buffer, "Unknown"); |
442 | 2814 prt_dsc_textline("For", buffer); |
2815 prt_dsc_textline("Creator", VIM_VERSION_LONG); | |
2816 /* Note: to ensure Clean8bit I don't think we can use LC_TIME */ | |
2817 now = time(NULL); | |
2818 p_time = ctime(&now); | |
2819 /* Note: ctime() adds a \n so we have to remove it :-( */ | |
840 | 2820 p = vim_strchr((char_u *)p_time, '\n'); |
2821 if (p != NULL) | |
2822 *p = NUL; | |
442 | 2823 prt_dsc_textline("CreationDate", p_time); |
2824 prt_dsc_textline("DocumentData", "Clean8Bit"); | |
2825 prt_dsc_textline("Orientation", "Portrait"); | |
2826 prt_dsc_atend("Pages"); | |
2827 prt_dsc_textline("PageOrder", "Ascend"); | |
2828 /* The bbox does not change with orientation - it is always in the default | |
2829 * user coordinate system! We have to recalculate right and bottom | |
2830 * coordinates based on the font metrics for the bbox to be accurate. */ | |
2831 prt_page_margins(prt_mediasize[prt_media].width, | |
2832 prt_mediasize[prt_media].height, | |
2833 &left, &right, &top, &bottom); | |
2834 bbox[0] = (int)left; | |
2835 if (prt_portrait) | |
2836 { | |
2837 /* In portrait printing the fixed point is the top left corner so we | |
2838 * derive the bbox from that point. We have the expected cpl chars | |
2839 * across the media and lpp lines down the media. | |
2840 */ | |
2841 bbox[1] = (int)(top - (psettings->lines_per_page + prt_header_height()) | |
2842 * prt_line_height); | |
2843 bbox[2] = (int)(left + psettings->chars_per_line * prt_char_width | |
2844 + 0.5); | |
2845 bbox[3] = (int)(top + 0.5); | |
2846 } | |
2847 else | |
2848 { | |
2849 /* In landscape printing the fixed point is the bottom left corner so we | |
2850 * derive the bbox from that point. We have lpp chars across the media | |
2851 * and cpl lines up the media. | |
2852 */ | |
2853 bbox[1] = (int)bottom; | |
2854 bbox[2] = (int)(left + ((psettings->lines_per_page | |
2855 + prt_header_height()) * prt_line_height) + 0.5); | |
2856 bbox[3] = (int)(bottom + psettings->chars_per_line * prt_char_width | |
2857 + 0.5); | |
2858 } | |
2859 prt_dsc_ints("BoundingBox", 4, bbox); | |
2860 /* The media width and height does not change with landscape printing! */ | |
2861 prt_dsc_docmedia(prt_mediasize[prt_media].name, | |
2862 prt_mediasize[prt_media].width, | |
2863 prt_mediasize[prt_media].height, | |
2864 (double)0, NULL, NULL); | |
2865 /* Define fonts needed */ | |
2866 #ifdef FEAT_MBYTE | |
2867 if (!prt_out_mbyte || prt_use_courier) | |
2868 #endif | |
856 | 2869 prt_dsc_font_resource("DocumentNeededResources", &prt_ps_courier_font); |
442 | 2870 #ifdef FEAT_MBYTE |
2871 if (prt_out_mbyte) | |
2872 { | |
856 | 2873 prt_dsc_font_resource((prt_use_courier ? NULL |
2874 : "DocumentNeededResources"), &prt_ps_mb_font); | |
2875 if (!prt_custom_cmap) | |
2876 prt_dsc_resources(NULL, "cmap", prt_cmap); | |
442 | 2877 } |
2878 #endif | |
2879 | |
2880 /* Search for external resources VIM supplies */ | |
2770 | 2881 if (!prt_find_resource("prolog", res_prolog)) |
442 | 2882 { |
2883 EMSG(_("E456: Can't find PostScript resource file \"prolog.ps\"")); | |
6404 | 2884 goto theend; |
442 | 2885 } |
2770 | 2886 if (!prt_open_resource(res_prolog)) |
6404 | 2887 goto theend; |
2770 | 2888 if (!prt_check_resource(res_prolog, PRT_PROLOG_VERSION)) |
6404 | 2889 goto theend; |
442 | 2890 #ifdef FEAT_MBYTE |
2891 if (prt_out_mbyte) | |
2892 { | |
856 | 2893 /* Look for required version of multi-byte printing procset */ |
2770 | 2894 if (!prt_find_resource("cidfont", res_cidfont)) |
856 | 2895 { |
2896 EMSG(_("E456: Can't find PostScript resource file \"cidfont.ps\"")); | |
6404 | 2897 goto theend; |
856 | 2898 } |
2770 | 2899 if (!prt_open_resource(res_cidfont)) |
6404 | 2900 goto theend; |
2770 | 2901 if (!prt_check_resource(res_cidfont, PRT_CID_PROLOG_VERSION)) |
6404 | 2902 goto theend; |
442 | 2903 } |
2904 #endif | |
2905 | |
2906 /* Find an encoding to use for printing. | |
2907 * Check 'printencoding'. If not set or not found, then use 'encoding'. If | |
2908 * that cannot be found then default to "latin1". | |
2909 * Note: VIM specific encoding header is always skipped. | |
2910 */ | |
2911 #ifdef FEAT_MBYTE | |
2912 if (!prt_out_mbyte) | |
2913 { | |
2914 #endif | |
856 | 2915 p_encoding = enc_skip(p_penc); |
2916 if (*p_encoding == NUL | |
2770 | 2917 || !prt_find_resource((char *)p_encoding, res_encoding)) |
856 | 2918 { |
2919 /* 'printencoding' not set or not supported - find alternate */ | |
442 | 2920 #ifdef FEAT_MBYTE |
856 | 2921 int props; |
2922 | |
2923 p_encoding = enc_skip(p_enc); | |
2924 props = enc_canon_props(p_encoding); | |
2925 if (!(props & ENC_8BIT) | |
2770 | 2926 || !prt_find_resource((char *)p_encoding, res_encoding)) |
856 | 2927 /* 8-bit 'encoding' is not supported */ |
442 | 2928 #endif |
856 | 2929 { |
2930 /* Use latin1 as default printing encoding */ | |
2931 p_encoding = (char_u *)"latin1"; | |
2770 | 2932 if (!prt_find_resource((char *)p_encoding, res_encoding)) |
856 | 2933 { |
2934 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), | |
2935 p_encoding); | |
6404 | 2936 goto theend; |
856 | 2937 } |
2938 } | |
2939 } | |
2770 | 2940 if (!prt_open_resource(res_encoding)) |
6404 | 2941 goto theend; |
856 | 2942 /* For the moment there are no checks on encoding resource files to |
2943 * perform */ | |
442 | 2944 #ifdef FEAT_MBYTE |
2945 } | |
2946 else | |
2947 { | |
856 | 2948 p_encoding = enc_skip(p_penc); |
2949 if (*p_encoding == NUL) | |
2950 p_encoding = enc_skip(p_enc); | |
2951 if (prt_use_courier) | |
2952 { | |
2953 /* Include ASCII range encoding vector */ | |
2770 | 2954 if (!prt_find_resource(prt_ascii_encoding, res_encoding)) |
856 | 2955 { |
2956 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), | |
442 | 2957 prt_ascii_encoding); |
6404 | 2958 goto theend; |
856 | 2959 } |
2770 | 2960 if (!prt_open_resource(res_encoding)) |
6404 | 2961 goto theend; |
856 | 2962 /* For the moment there are no checks on encoding resource files to |
2963 * perform */ | |
2964 } | |
442 | 2965 } |
2966 | |
2967 prt_conv.vc_type = CONV_NONE; | |
2968 if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { | |
856 | 2969 /* Set up encoding conversion if required */ |
442 | 2970 if (FAIL == convert_setup(&prt_conv, p_enc, p_encoding)) |
2971 { | |
856 | 2972 EMSG2(_("E620: Unable to convert to print encoding \"%s\""), |
442 | 2973 p_encoding); |
6404 | 2974 goto theend; |
442 | 2975 } |
2976 prt_do_conv = TRUE; | |
2977 } | |
2978 prt_do_conv = prt_conv.vc_type != CONV_NONE; | |
2979 | |
2980 if (prt_out_mbyte && prt_custom_cmap) | |
2981 { | |
856 | 2982 /* Find user supplied CMap */ |
2770 | 2983 if (!prt_find_resource(prt_cmap, res_cmap)) |
856 | 2984 { |
2985 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), | |
442 | 2986 prt_cmap); |
6404 | 2987 goto theend; |
856 | 2988 } |
2770 | 2989 if (!prt_open_resource(res_cmap)) |
6404 | 2990 goto theend; |
442 | 2991 } |
2992 #endif | |
2993 | |
2994 /* List resources supplied */ | |
2770 | 2995 STRCPY(buffer, res_prolog->title); |
442 | 2996 STRCAT(buffer, " "); |
2770 | 2997 STRCAT(buffer, res_prolog->version); |
442 | 2998 prt_dsc_resources("DocumentSuppliedResources", "procset", buffer); |
2999 #ifdef FEAT_MBYTE | |
3000 if (prt_out_mbyte) | |
3001 { | |
2770 | 3002 STRCPY(buffer, res_cidfont->title); |
856 | 3003 STRCAT(buffer, " "); |
2770 | 3004 STRCAT(buffer, res_cidfont->version); |
856 | 3005 prt_dsc_resources(NULL, "procset", buffer); |
3006 | |
3007 if (prt_custom_cmap) | |
3008 { | |
2770 | 3009 STRCPY(buffer, res_cmap->title); |
856 | 3010 STRCAT(buffer, " "); |
2770 | 3011 STRCAT(buffer, res_cmap->version); |
856 | 3012 prt_dsc_resources(NULL, "cmap", buffer); |
3013 } | |
442 | 3014 } |
3015 if (!prt_out_mbyte || prt_use_courier) | |
3016 #endif | |
3017 { | |
2770 | 3018 STRCPY(buffer, res_encoding->title); |
856 | 3019 STRCAT(buffer, " "); |
2770 | 3020 STRCAT(buffer, res_encoding->version); |
856 | 3021 prt_dsc_resources(NULL, "encoding", buffer); |
442 | 3022 } |
3023 prt_dsc_requirements(prt_duplex, prt_tumble, prt_collate, | |
3024 #ifdef FEAT_SYN_HL | |
3025 psettings->do_syntax | |
3026 #else | |
3027 0 | |
3028 #endif | |
3029 , prt_num_copies); | |
3030 prt_dsc_noarg("EndComments"); | |
3031 | |
3032 /* | |
3033 * PS Document page defaults | |
3034 */ | |
3035 prt_dsc_noarg("BeginDefaults"); | |
3036 | |
3037 /* List font resources most likely common to all pages */ | |
3038 #ifdef FEAT_MBYTE | |
3039 if (!prt_out_mbyte || prt_use_courier) | |
3040 #endif | |
856 | 3041 prt_dsc_font_resource("PageResources", &prt_ps_courier_font); |
442 | 3042 #ifdef FEAT_MBYTE |
3043 if (prt_out_mbyte) | |
3044 { | |
856 | 3045 prt_dsc_font_resource((prt_use_courier ? NULL : "PageResources"), |
3046 &prt_ps_mb_font); | |
3047 if (!prt_custom_cmap) | |
3048 prt_dsc_resources(NULL, "cmap", prt_cmap); | |
442 | 3049 } |
3050 #endif | |
3051 | |
3052 /* Paper will be used for all pages */ | |
3053 prt_dsc_textline("PageMedia", prt_mediasize[prt_media].name); | |
3054 | |
3055 prt_dsc_noarg("EndDefaults"); | |
3056 | |
3057 /* | |
3058 * PS Document prolog inclusion - all required procsets. | |
3059 */ | |
3060 prt_dsc_noarg("BeginProlog"); | |
3061 | |
3062 /* Add required procsets - NOTE: order is important! */ | |
2770 | 3063 if (!prt_add_resource(res_prolog)) |
6404 | 3064 goto theend; |
442 | 3065 #ifdef FEAT_MBYTE |
3066 if (prt_out_mbyte) | |
3067 { | |
856 | 3068 /* Add CID font procset, and any user supplied CMap */ |
2770 | 3069 if (!prt_add_resource(res_cidfont)) |
6404 | 3070 goto theend; |
2770 | 3071 if (prt_custom_cmap && !prt_add_resource(res_cmap)) |
6404 | 3072 goto theend; |
442 | 3073 } |
3074 #endif | |
3075 | |
3076 #ifdef FEAT_MBYTE | |
3077 if (!prt_out_mbyte || prt_use_courier) | |
3078 #endif | |
856 | 3079 /* There will be only one Roman font encoding to be included in the PS |
3080 * file. */ | |
2770 | 3081 if (!prt_add_resource(res_encoding)) |
6404 | 3082 goto theend; |
442 | 3083 |
3084 prt_dsc_noarg("EndProlog"); | |
3085 | |
3086 /* | |
3087 * PS Document setup - must appear after the prolog | |
3088 */ | |
3089 prt_dsc_noarg("BeginSetup"); | |
3090 | |
3091 /* Device setup - page size and number of uncollated copies */ | |
3092 prt_write_int((int)prt_mediasize[prt_media].width); | |
3093 prt_write_int((int)prt_mediasize[prt_media].height); | |
3094 prt_write_int(0); | |
3095 prt_write_string("sps\n"); | |
3096 prt_write_int(prt_num_copies); | |
3097 prt_write_string("nc\n"); | |
3098 prt_write_boolean(prt_duplex); | |
3099 prt_write_boolean(prt_tumble); | |
3100 prt_write_string("dt\n"); | |
3101 prt_write_boolean(prt_collate); | |
3102 prt_write_string("c\n"); | |
3103 | |
3104 /* Font resource inclusion and definition */ | |
3105 #ifdef FEAT_MBYTE | |
3106 if (!prt_out_mbyte || prt_use_courier) | |
3107 { | |
856 | 3108 /* When using Courier for ASCII range when printing multi-byte, need to |
3109 * pick up ASCII encoding to use with it. */ | |
3110 if (prt_use_courier) | |
3111 p_encoding = (char_u *)prt_ascii_encoding; | |
442 | 3112 #endif |
856 | 3113 prt_dsc_resources("IncludeResource", "font", |
3114 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); | |
3115 prt_def_font("F0", (char *)p_encoding, (int)prt_line_height, | |
3116 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); | |
3117 prt_dsc_resources("IncludeResource", "font", | |
3118 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLD]); | |
3119 prt_def_font("F1", (char *)p_encoding, (int)prt_line_height, | |
3120 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLD]); | |
3121 prt_dsc_resources("IncludeResource", "font", | |
3122 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); | |
3123 prt_def_font("F2", (char *)p_encoding, (int)prt_line_height, | |
3124 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); | |
3125 prt_dsc_resources("IncludeResource", "font", | |
3126 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); | |
3127 prt_def_font("F3", (char *)p_encoding, (int)prt_line_height, | |
3128 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); | |
442 | 3129 #ifdef FEAT_MBYTE |
3130 } | |
3131 if (prt_out_mbyte) | |
3132 { | |
856 | 3133 /* Define the CID fonts to be used in the job. Typically CJKV fonts do |
3134 * not have an italic form being a western style, so where no font is | |
3135 * defined for these faces VIM falls back to an existing face. | |
3136 * Note: if using Courier for the ASCII range then the printout will | |
3137 * have bold/italic/bolditalic regardless of the setting of printmbfont. | |
3138 */ | |
3139 prt_dsc_resources("IncludeResource", "font", | |
3140 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); | |
3141 if (!prt_custom_cmap) | |
3142 prt_dsc_resources("IncludeResource", "cmap", prt_cmap); | |
3143 prt_def_cidfont("CF0", (int)prt_line_height, | |
3144 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); | |
3145 | |
3146 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD] != NULL) | |
3147 { | |
3148 prt_dsc_resources("IncludeResource", "font", | |
3149 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); | |
3150 if (!prt_custom_cmap) | |
3151 prt_dsc_resources("IncludeResource", "cmap", prt_cmap); | |
3152 prt_def_cidfont("CF1", (int)prt_line_height, | |
3153 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); | |
3154 } | |
3155 else | |
3156 /* Use ROMAN for BOLD */ | |
3157 prt_dup_cidfont("CF0", "CF1"); | |
3158 | |
3159 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL) | |
3160 { | |
3161 prt_dsc_resources("IncludeResource", "font", | |
3162 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); | |
3163 if (!prt_custom_cmap) | |
3164 prt_dsc_resources("IncludeResource", "cmap", prt_cmap); | |
3165 prt_def_cidfont("CF2", (int)prt_line_height, | |
3166 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); | |
3167 } | |
3168 else | |
3169 /* Use ROMAN for OBLIQUE */ | |
3170 prt_dup_cidfont("CF0", "CF2"); | |
3171 | |
3172 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL) | |
3173 { | |
3174 prt_dsc_resources("IncludeResource", "font", | |
3175 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); | |
3176 if (!prt_custom_cmap) | |
3177 prt_dsc_resources("IncludeResource", "cmap", prt_cmap); | |
3178 prt_def_cidfont("CF3", (int)prt_line_height, | |
3179 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); | |
3180 } | |
3181 else | |
3182 /* Use BOLD for BOLDOBLIQUE */ | |
3183 prt_dup_cidfont("CF1", "CF3"); | |
442 | 3184 } |
3185 #endif | |
3186 | |
3187 /* Misc constant vars used for underlining and background rects */ | |
3188 prt_def_var("UO", PRT_PS_FONT_TO_USER(prt_line_height, | |
3189 prt_ps_font->uline_offset), 2); | |
3190 prt_def_var("UW", PRT_PS_FONT_TO_USER(prt_line_height, | |
3191 prt_ps_font->uline_width), 2); | |
3192 prt_def_var("BO", prt_bgcol_offset, 2); | |
3193 | |
3194 prt_dsc_noarg("EndSetup"); | |
3195 | |
3196 /* Fail if any problems writing out to the PS file */ | |
2770 | 3197 retval = !prt_file_error; |
3198 | |
3199 theend: | |
3200 vim_free(res_prolog); | |
3201 vim_free(res_encoding); | |
3202 #ifdef FEAT_MBYTE | |
3203 vim_free(res_cidfont); | |
3204 vim_free(res_cmap); | |
3205 #endif | |
3206 | |
3207 return retval; | |
442 | 3208 } |
3209 | |
3210 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3211 mch_print_end(prt_settings_T *psettings) |
442 | 3212 { |
3213 prt_dsc_noarg("Trailer"); | |
3214 | |
3215 /* | |
3216 * Output any info we don't know in toto until we finish | |
3217 */ | |
3218 prt_dsc_ints("Pages", 1, &prt_page_num); | |
3219 | |
3220 prt_dsc_noarg("EOF"); | |
3221 | |
3222 /* Write CTRL-D to close serial communication link if used. | |
3223 * NOTHING MUST BE WRITTEN AFTER THIS! */ | |
3224 prt_write_file((char_u *)IF_EB("\004", "\067")); | |
3225 | |
3226 if (!prt_file_error && psettings->outfile == NULL | |
3227 && !got_int && !psettings->user_abort) | |
3228 { | |
3229 /* Close the file first. */ | |
3230 if (prt_ps_fd != NULL) | |
3231 { | |
3232 fclose(prt_ps_fd); | |
3233 prt_ps_fd = NULL; | |
3234 } | |
3235 prt_message((char_u *)_("Sending to printer...")); | |
3236 | |
3237 /* Not printing to a file: use 'printexpr' to print the file. */ | |
3238 if (eval_printexpr(prt_ps_file_name, psettings->arguments) == FAIL) | |
3239 EMSG(_("E365: Failed to print PostScript file")); | |
3240 else | |
3241 prt_message((char_u *)_("Print job sent.")); | |
3242 } | |
3243 | |
3244 mch_print_cleanup(); | |
3245 } | |
3246 | |
3247 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3248 mch_print_end_page(void) |
442 | 3249 { |
3250 prt_flush_buffer(); | |
3251 | |
3252 prt_write_string("re sp\n"); | |
3253 | |
3254 prt_dsc_noarg("PageTrailer"); | |
3255 | |
3256 return !prt_file_error; | |
3257 } | |
3258 | |
3259 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3260 mch_print_begin_page(char_u *str UNUSED) |
442 | 3261 { |
3262 int page_num[2]; | |
3263 | |
3264 prt_page_num++; | |
3265 | |
3266 page_num[0] = page_num[1] = prt_page_num; | |
3267 prt_dsc_ints("Page", 2, page_num); | |
3268 | |
3269 prt_dsc_noarg("BeginPageSetup"); | |
3270 | |
3271 prt_write_string("sv\n0 g\n"); | |
3272 #ifdef FEAT_MBYTE | |
3273 prt_in_ascii = !prt_out_mbyte; | |
3274 if (prt_out_mbyte) | |
856 | 3275 prt_write_string("CF0 sf\n"); |
442 | 3276 else |
3277 #endif | |
856 | 3278 prt_write_string("F0 sf\n"); |
442 | 3279 prt_fgcol = PRCOLOR_BLACK; |
3280 prt_bgcol = PRCOLOR_WHITE; | |
3281 prt_font = PRT_PS_FONT_ROMAN; | |
3282 | |
3283 /* Set up page transformation for landscape printing. */ | |
3284 if (!prt_portrait) | |
3285 { | |
3286 prt_write_int(-((int)prt_mediasize[prt_media].width)); | |
3287 prt_write_string("sl\n"); | |
3288 } | |
3289 | |
3290 prt_dsc_noarg("EndPageSetup"); | |
3291 | |
3292 /* We have reset the font attributes, force setting them again. */ | |
3293 curr_bg = (long_u)0xffffffff; | |
3294 curr_fg = (long_u)0xffffffff; | |
3295 curr_bold = MAYBE; | |
3296 | |
3297 return !prt_file_error; | |
3298 } | |
3299 | |
3300 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3301 mch_print_blank_page(void) |
442 | 3302 { |
3303 return (mch_print_begin_page(NULL) ? (mch_print_end_page()) : FALSE); | |
3304 } | |
3305 | |
3306 static float prt_pos_x = 0; | |
3307 static float prt_pos_y = 0; | |
3308 | |
3309 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3310 mch_print_start_line(int margin, int page_line) |
442 | 3311 { |
3312 prt_pos_x = prt_left_margin; | |
3313 if (margin) | |
3314 prt_pos_x -= prt_number_width; | |
3315 | |
3316 prt_pos_y = prt_top_margin - prt_first_line_height - | |
3317 page_line * prt_line_height; | |
3318 | |
3319 prt_attribute_change = TRUE; | |
3320 prt_need_moveto = TRUE; | |
3321 #ifdef FEAT_MBYTE | |
3322 prt_half_width = FALSE; | |
3323 #endif | |
3324 } | |
3325 | |
3326 int | |
14077
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3327 mch_print_text_out(char_u *textp, int len UNUSED) |
442 | 3328 { |
14077
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3329 char_u *p = textp; |
442 | 3330 int need_break; |
3331 char_u ch; | |
3332 char_u ch_buff[8]; | |
3333 float char_width; | |
3334 float next_pos; | |
3335 #ifdef FEAT_MBYTE | |
856 | 3336 int in_ascii; |
3337 int half_width; | |
13258
6acb9148d83e
patch 8.0.1503: access memory beyond end of string
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3338 char_u *tofree = NULL; |
442 | 3339 #endif |
3340 | |
3341 char_width = prt_char_width; | |
3342 | |
3343 #ifdef FEAT_MBYTE | |
3344 /* Ideally VIM would create a rearranged CID font to combine a Roman and | |
3345 * CJKV font to do what VIM is doing here - use a Roman font for characters | |
1218 | 3346 * in the ASCII range, and the original CID font for everything else. |
442 | 3347 * The problem is that GhostScript still (as of 8.13) does not support |
3348 * rearranged fonts even though they have been documented by Adobe for 7 | |
3349 * years! If they ever do, a lot of this code will disappear. | |
3350 */ | |
3351 if (prt_use_courier) | |
3352 { | |
856 | 3353 in_ascii = (len == 1 && *p < 0x80); |
3354 if (prt_in_ascii) | |
3355 { | |
3356 if (!in_ascii) | |
3357 { | |
3358 /* No longer in ASCII range - need to switch font */ | |
3359 prt_in_ascii = FALSE; | |
3360 prt_need_font = TRUE; | |
3361 prt_attribute_change = TRUE; | |
3362 } | |
3363 } | |
3364 else if (in_ascii) | |
3365 { | |
3366 /* Now in ASCII range - need to switch font */ | |
3367 prt_in_ascii = TRUE; | |
3368 prt_need_font = TRUE; | |
3369 prt_attribute_change = TRUE; | |
3370 } | |
442 | 3371 } |
3372 if (prt_out_mbyte) | |
3373 { | |
856 | 3374 half_width = ((*mb_ptr2cells)(p) == 1); |
3375 if (half_width) | |
3376 char_width /= 2; | |
3377 if (prt_half_width) | |
3378 { | |
3379 if (!half_width) | |
3380 { | |
3381 prt_half_width = FALSE; | |
3382 prt_pos_x += prt_char_width/4; | |
3383 prt_need_moveto = TRUE; | |
3384 prt_attribute_change = TRUE; | |
3385 } | |
3386 } | |
3387 else if (half_width) | |
3388 { | |
3389 prt_half_width = TRUE; | |
3390 prt_pos_x += prt_char_width/4; | |
3391 prt_need_moveto = TRUE; | |
3392 prt_attribute_change = TRUE; | |
3393 } | |
442 | 3394 } |
3395 #endif | |
3396 | |
3397 /* Output any required changes to the graphics state, after flushing any | |
3398 * text buffered so far. | |
3399 */ | |
3400 if (prt_attribute_change) | |
3401 { | |
3402 prt_flush_buffer(); | |
3403 /* Reset count of number of chars that will be printed */ | |
3404 prt_text_run = 0; | |
3405 | |
3406 if (prt_need_moveto) | |
3407 { | |
3408 prt_pos_x_moveto = prt_pos_x; | |
3409 prt_pos_y_moveto = prt_pos_y; | |
3410 prt_do_moveto = TRUE; | |
3411 | |
3412 prt_need_moveto = FALSE; | |
3413 } | |
3414 if (prt_need_font) | |
3415 { | |
3416 #ifdef FEAT_MBYTE | |
856 | 3417 if (!prt_in_ascii) |
3418 prt_write_string("CF"); | |
3419 else | |
442 | 3420 #endif |
856 | 3421 prt_write_string("F"); |
3422 prt_write_int(prt_font); | |
3423 prt_write_string("sf\n"); | |
3424 prt_need_font = FALSE; | |
442 | 3425 } |
3426 if (prt_need_fgcol) | |
3427 { | |
3428 int r, g, b; | |
3429 r = ((unsigned)prt_fgcol & 0xff0000) >> 16; | |
3430 g = ((unsigned)prt_fgcol & 0xff00) >> 8; | |
3431 b = prt_fgcol & 0xff; | |
3432 | |
3433 prt_write_real(r / 255.0, 3); | |
3434 if (r == g && g == b) | |
3435 prt_write_string("g\n"); | |
3436 else | |
3437 { | |
3438 prt_write_real(g / 255.0, 3); | |
3439 prt_write_real(b / 255.0, 3); | |
3440 prt_write_string("r\n"); | |
3441 } | |
3442 prt_need_fgcol = FALSE; | |
3443 } | |
3444 | |
3445 if (prt_bgcol != PRCOLOR_WHITE) | |
3446 { | |
3447 prt_new_bgcol = prt_bgcol; | |
3448 if (prt_need_bgcol) | |
3449 prt_do_bgcol = TRUE; | |
3450 } | |
3451 else | |
3452 prt_do_bgcol = FALSE; | |
3453 prt_need_bgcol = FALSE; | |
3454 | |
3455 if (prt_need_underline) | |
3456 prt_do_underline = prt_underline; | |
3457 prt_need_underline = FALSE; | |
3458 | |
3459 prt_attribute_change = FALSE; | |
3460 } | |
3461 | |
3462 #ifdef FEAT_MBYTE | |
3463 if (prt_do_conv) | |
14077
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3464 { |
442 | 3465 /* Convert from multi-byte to 8-bit encoding */ |
13258
6acb9148d83e
patch 8.0.1503: access memory beyond end of string
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3466 tofree = p = string_convert(&prt_conv, p, &len); |
14077
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3467 if (p == NULL) |
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3468 { |
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3469 p = (char_u *)""; |
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3470 len = 0; |
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3471 } |
873542706b0b
patch 8.1.0056: crash when using :hardcopy with illegal byte
Christian Brabandt <cb@256bit.org>
parents:
13258
diff
changeset
|
3472 } |
442 | 3473 |
3474 if (prt_out_mbyte) | |
3475 { | |
856 | 3476 /* Multi-byte character strings are represented more efficiently as hex |
3477 * strings when outputting clean 8 bit PS. | |
3478 */ | |
13258
6acb9148d83e
patch 8.0.1503: access memory beyond end of string
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3479 while (len-- > 0) |
856 | 3480 { |
3481 ch = prt_hexchar[(unsigned)(*p) >> 4]; | |
3482 ga_append(&prt_ps_buffer, ch); | |
3483 ch = prt_hexchar[(*p) & 0xf]; | |
3484 ga_append(&prt_ps_buffer, ch); | |
3485 p++; | |
3486 } | |
442 | 3487 } |
3488 else | |
3489 #endif | |
3490 { | |
856 | 3491 /* Add next character to buffer of characters to output. |
3492 * Note: One printed character may require several PS characters to | |
3493 * represent it, but we only count them as one printed character. | |
3494 */ | |
3495 ch = *p; | |
3496 if (ch < 32 || ch == '(' || ch == ')' || ch == '\\') | |
3497 { | |
3498 /* Convert non-printing characters to either their escape or octal | |
3499 * sequence, ensures PS sent over a serial line does not interfere | |
3500 * with the comms protocol. Note: For EBCDIC we need to write out | |
3501 * the escape sequences as ASCII codes! | |
442 | 3502 * Note 2: Char codes < 32 are identical in EBCDIC and ASCII AFAIK! |
3503 */ | |
856 | 3504 ga_append(&prt_ps_buffer, IF_EB('\\', 0134)); |
3505 switch (ch) | |
3506 { | |
3507 case BS: ga_append(&prt_ps_buffer, IF_EB('b', 0142)); break; | |
3508 case TAB: ga_append(&prt_ps_buffer, IF_EB('t', 0164)); break; | |
3509 case NL: ga_append(&prt_ps_buffer, IF_EB('n', 0156)); break; | |
3510 case FF: ga_append(&prt_ps_buffer, IF_EB('f', 0146)); break; | |
3511 case CAR: ga_append(&prt_ps_buffer, IF_EB('r', 0162)); break; | |
3512 case '(': ga_append(&prt_ps_buffer, IF_EB('(', 0050)); break; | |
3513 case ')': ga_append(&prt_ps_buffer, IF_EB(')', 0051)); break; | |
3514 case '\\': ga_append(&prt_ps_buffer, IF_EB('\\', 0134)); break; | |
3515 | |
3516 default: | |
3517 sprintf((char *)ch_buff, "%03o", (unsigned int)ch); | |
442 | 3518 #ifdef EBCDIC |
856 | 3519 ebcdic2ascii(ch_buff, 3); |
442 | 3520 #endif |
856 | 3521 ga_append(&prt_ps_buffer, ch_buff[0]); |
3522 ga_append(&prt_ps_buffer, ch_buff[1]); | |
3523 ga_append(&prt_ps_buffer, ch_buff[2]); | |
3524 break; | |
3525 } | |
3526 } | |
3527 else | |
3528 ga_append(&prt_ps_buffer, ch); | |
442 | 3529 } |
3530 | |
3531 #ifdef FEAT_MBYTE | |
3532 /* Need to free any translated characters */ | |
13258
6acb9148d83e
patch 8.0.1503: access memory beyond end of string
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3533 vim_free(tofree); |
442 | 3534 #endif |
3535 | |
3536 prt_text_run += char_width; | |
3537 prt_pos_x += char_width; | |
3538 | |
3539 /* The downside of fp - use relative error on right margin check */ | |
3540 next_pos = prt_pos_x + prt_char_width; | |
3541 need_break = (next_pos > prt_right_margin) && | |
856 | 3542 ((next_pos - prt_right_margin) > (prt_right_margin*1e-5)); |
442 | 3543 |
3544 if (need_break) | |
3545 prt_flush_buffer(); | |
3546 | |
3547 return need_break; | |
3548 } | |
3549 | |
3550 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3551 mch_print_set_font(int iBold, int iItalic, int iUnderline) |
442 | 3552 { |
3553 int font = 0; | |
3554 | |
3555 if (iBold) | |
3556 font |= 0x01; | |
3557 if (iItalic) | |
3558 font |= 0x02; | |
3559 | |
3560 if (font != prt_font) | |
3561 { | |
3562 prt_font = font; | |
3563 prt_attribute_change = TRUE; | |
3564 prt_need_font = TRUE; | |
3565 } | |
3566 if (prt_underline != iUnderline) | |
3567 { | |
3568 prt_underline = iUnderline; | |
3569 prt_attribute_change = TRUE; | |
3570 prt_need_underline = TRUE; | |
3571 } | |
3572 } | |
3573 | |
3574 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3575 mch_print_set_bg(long_u bgcol) |
442 | 3576 { |
835 | 3577 prt_bgcol = (int)bgcol; |
442 | 3578 prt_attribute_change = TRUE; |
3579 prt_need_bgcol = TRUE; | |
3580 } | |
3581 | |
3582 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3583 mch_print_set_fg(long_u fgcol) |
442 | 3584 { |
3585 if (fgcol != (long_u)prt_fgcol) | |
3586 { | |
835 | 3587 prt_fgcol = (int)fgcol; |
442 | 3588 prt_attribute_change = TRUE; |
3589 prt_need_fgcol = TRUE; | |
3590 } | |
3591 } | |
3592 | |
3593 # endif /*FEAT_POSTSCRIPT*/ | |
3594 #endif /*FEAT_PRINTER*/ |