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