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