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