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