comparison src/hardcopy.c @ 18798:f0f9692d4487 v8.1.2387

patch 8.1.2387: using old C style comments Commit: https://github.com/vim/vim/commit/2ab2e8608f9b2c85432715bb9a7f226fdbf8cd35 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 4 21:24:53 2019 +0100 patch 8.1.2387: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Dec 2019 21:30:04 +0100
parents ce04ebdf26b8
children aadd1cae2ff5
comparison
equal deleted inserted replaced
18797:76af6d0ea316 18798:f0f9692d4487
125 /* 125 /*
126 * These values determine the print position on a page. 126 * These values determine the print position on a page.
127 */ 127 */
128 typedef struct 128 typedef struct
129 { 129 {
130 int lead_spaces; /* remaining spaces for a TAB */ 130 int lead_spaces; // remaining spaces for a TAB
131 int print_pos; /* virtual column for computing TABs */ 131 int print_pos; // virtual column for computing TABs
132 colnr_T column; /* byte column */ 132 colnr_T column; // byte column
133 linenr_T file_line; /* line nr in the buffer */ 133 linenr_T file_line; // line nr in the buffer
134 long_u bytes_printed; /* bytes printed so far */ 134 long_u bytes_printed; // bytes printed so far
135 int ff; /* seen form feed character */ 135 int ff; // seen form feed character
136 } prt_pos_T; 136 } prt_pos_T;
137 137
138 static char *parse_list_options(char_u *option_str, option_table_T *table, int table_size); 138 static char *parse_list_options(char_u *option_str, option_table_T *table, int table_size);
139 139
140 static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T *ppos); 140 static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T *ppos);
180 char *ret = NULL; 180 char *ret = NULL;
181 char_u *stringp; 181 char_u *stringp;
182 char_u *colonp; 182 char_u *colonp;
183 char_u *commap; 183 char_u *commap;
184 char_u *p; 184 char_u *p;
185 int idx = 0; /* init for GCC */ 185 int idx = 0; // init for GCC
186 int len; 186 int len;
187 187
188 /* Save the old values, so that they can be restored in case of an error. */ 188 // Save the old values, so that they can be restored in case of an error.
189 old_opts = ALLOC_MULT(option_table_T, table_size); 189 old_opts = ALLOC_MULT(option_table_T, table_size);
190 if (old_opts == NULL) 190 if (old_opts == NULL)
191 return NULL; 191 return NULL;
192 192
193 for (idx = 0; idx < table_size; ++idx) 193 for (idx = 0; idx < table_size; ++idx)
232 { 232 {
233 ret = N_("E552: digit expected"); 233 ret = N_("E552: digit expected");
234 break; 234 break;
235 } 235 }
236 236
237 table[idx].number = getdigits(&p); /*advances p*/ 237 table[idx].number = getdigits(&p); // advances p
238 } 238 }
239 239
240 table[idx].string = p; 240 table[idx].string = p;
241 table[idx].strlen = (int)(commap - p); 241 table[idx].strlen = (int)(commap - p);
242 242
245 ++stringp; 245 ++stringp;
246 } 246 }
247 247
248 if (ret != NULL) 248 if (ret != NULL)
249 { 249 {
250 /* Restore old options in case of error */ 250 // Restore old options in case of error
251 for (idx = 0; idx < table_size; ++idx) 251 for (idx = 0; idx < table_size; ++idx)
252 table[idx] = old_opts[idx]; 252 table[idx] = old_opts[idx];
253 } 253 }
254 vim_free(old_opts); 254 vim_free(old_opts);
255 return ret; 255 return ret;
270 } 270 }
271 271
272 static long_u 272 static long_u
273 prt_get_term_color(int colorindex) 273 prt_get_term_color(int colorindex)
274 { 274 {
275 /* TODO: Should check for xterm with 88 or 256 colors. */ 275 // TODO: Should check for xterm with 88 or 256 colors.
276 if (t_colors > 8) 276 if (t_colors > 8)
277 return cterm_color_16[colorindex % 16]; 277 return cterm_color_16[colorindex % 16];
278 return cterm_color_8[colorindex % 8]; 278 return cterm_color_8[colorindex % 8];
279 } 279 }
280 280
326 fg_color = darken_rgb(fg_color); 326 fg_color = darken_rgb(fg_color);
327 327
328 pattr->fg_color = fg_color; 328 pattr->fg_color = fg_color;
329 pattr->bg_color = bg_color; 329 pattr->bg_color = bg_color;
330 } 330 }
331 #endif /* FEAT_SYN_HL */ 331 #endif // FEAT_SYN_HL
332 332
333 static void 333 static void
334 prt_set_fg(long_u fg) 334 prt_set_fg(long_u fg)
335 { 335 {
336 if (fg != curr_fg) 336 if (fg != curr_fg)
379 prt_set_fg(psettings->number.fg_color); 379 prt_set_fg(psettings->number.fg_color);
380 prt_set_bg(psettings->number.bg_color); 380 prt_set_bg(psettings->number.bg_color);
381 prt_set_font(psettings->number.bold, psettings->number.italic, psettings->number.underline); 381 prt_set_font(psettings->number.bold, psettings->number.italic, psettings->number.underline);
382 mch_print_start_line(TRUE, page_line); 382 mch_print_start_line(TRUE, page_line);
383 383
384 /* Leave two spaces between the number and the text; depends on 384 // Leave two spaces between the number and the text; depends on
385 * PRINT_NUMBER_WIDTH. */ 385 // PRINT_NUMBER_WIDTH.
386 sprintf((char *)tbuf, "%6ld", (long)lnum); 386 sprintf((char *)tbuf, "%6ld", (long)lnum);
387 for (i = 0; i < 6; i++) 387 for (i = 0; i < 6; i++)
388 (void)mch_print_text_out(&tbuf[i], 1); 388 (void)mch_print_text_out(&tbuf[i], 1);
389 389
390 #ifdef FEAT_SYN_HL 390 #ifdef FEAT_SYN_HL
391 if (psettings->do_syntax) 391 if (psettings->do_syntax)
392 /* Set colors for next character. */ 392 // Set colors for next character.
393 current_syn_id = -1; 393 current_syn_id = -1;
394 else 394 else
395 #endif 395 #endif
396 { 396 {
397 /* Set colors and font back to normal. */ 397 // Set colors and font back to normal.
398 prt_set_fg(PRCOLOR_BLACK); 398 prt_set_fg(PRCOLOR_BLACK);
399 prt_set_bg(PRCOLOR_WHITE); 399 prt_set_bg(PRCOLOR_WHITE);
400 prt_set_font(FALSE, FALSE, FALSE); 400 prt_set_font(FALSE, FALSE, FALSE);
401 } 401 }
402 } 402 }
456 int page_line; 456 int page_line;
457 char_u *tbuf; 457 char_u *tbuf;
458 char_u *p; 458 char_u *p;
459 int l; 459 int l;
460 460
461 /* Also use the space for the line number. */ 461 // Also use the space for the line number.
462 if (prt_use_number()) 462 if (prt_use_number())
463 width += PRINT_NUMBER_WIDTH; 463 width += PRINT_NUMBER_WIDTH;
464 464
465 tbuf = alloc(width + IOSIZE); 465 tbuf = alloc(width + IOSIZE);
466 if (tbuf == NULL) 466 if (tbuf == NULL)
491 # endif 491 # endif
492 build_stl_str_hl(curwin, tbuf, (size_t)(width + IOSIZE), 492 build_stl_str_hl(curwin, tbuf, (size_t)(width + IOSIZE),
493 p_header, use_sandbox, 493 p_header, use_sandbox,
494 ' ', width, NULL, NULL); 494 ' ', width, NULL, NULL);
495 495
496 /* Reset line numbers */ 496 // Reset line numbers
497 curwin->w_cursor.lnum = tmp_lnum; 497 curwin->w_cursor.lnum = tmp_lnum;
498 curwin->w_topline = tmp_topline; 498 curwin->w_topline = tmp_topline;
499 curwin->w_botline = tmp_botline; 499 curwin->w_botline = tmp_botline;
500 } 500 }
501 else 501 else
504 504
505 prt_set_fg(PRCOLOR_BLACK); 505 prt_set_fg(PRCOLOR_BLACK);
506 prt_set_bg(PRCOLOR_WHITE); 506 prt_set_bg(PRCOLOR_WHITE);
507 prt_set_font(TRUE, FALSE, FALSE); 507 prt_set_font(TRUE, FALSE, FALSE);
508 508
509 /* Use a negative line number to indicate printing in the top margin. */ 509 // Use a negative line number to indicate printing in the top margin.
510 page_line = 0 - prt_header_height(); 510 page_line = 0 - prt_header_height();
511 mch_print_start_line(TRUE, page_line); 511 mch_print_start_line(TRUE, page_line);
512 for (p = tbuf; *p != NUL; ) 512 for (p = tbuf; *p != NUL; )
513 { 513 {
514 if (mch_print_text_out(p, (l = (*mb_ptr2len)(p)))) 514 if (mch_print_text_out(p, (l = (*mb_ptr2len)(p))))
515 { 515 {
516 ++page_line; 516 ++page_line;
517 if (page_line >= 0) /* out of room in header */ 517 if (page_line >= 0) // out of room in header
518 break; 518 break;
519 mch_print_start_line(TRUE, page_line); 519 mch_print_start_line(TRUE, page_line);
520 } 520 }
521 p += l; 521 p += l;
522 } 522 }
523 523
524 vim_free(tbuf); 524 vim_free(tbuf);
525 525
526 #ifdef FEAT_SYN_HL 526 #ifdef FEAT_SYN_HL
527 if (psettings->do_syntax) 527 if (psettings->do_syntax)
528 /* Set colors for next character. */ 528 // Set colors for next character.
529 current_syn_id = -1; 529 current_syn_id = -1;
530 else 530 else
531 #endif 531 #endif
532 { 532 {
533 /* Set colors and font back to normal. */ 533 // Set colors and font back to normal.
534 prt_set_fg(PRCOLOR_BLACK); 534 prt_set_fg(PRCOLOR_BLACK);
535 prt_set_bg(PRCOLOR_WHITE); 535 prt_set_bg(PRCOLOR_WHITE);
536 prt_set_font(FALSE, FALSE, FALSE); 536 prt_set_font(FALSE, FALSE, FALSE);
537 } 537 }
538 } 538 }
564 # ifdef FEAT_POSTSCRIPT 564 # ifdef FEAT_POSTSCRIPT
565 if (*eap->arg == '>') 565 if (*eap->arg == '>')
566 { 566 {
567 char *errormsg = NULL; 567 char *errormsg = NULL;
568 568
569 /* Expand things like "%.ps". */ 569 // Expand things like "%.ps".
570 if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) 570 if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL)
571 { 571 {
572 if (errormsg != NULL) 572 if (errormsg != NULL)
573 emsg(errormsg); 573 emsg(errormsg);
574 return; 574 return;
614 (TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) == 'y'); 614 (TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) == 'y');
615 else 615 else
616 settings.do_syntax = settings.has_color; 616 settings.do_syntax = settings.has_color;
617 #endif 617 #endif
618 618
619 /* Set up printing attributes for line numbers */ 619 // Set up printing attributes for line numbers
620 settings.number.fg_color = PRCOLOR_BLACK; 620 settings.number.fg_color = PRCOLOR_BLACK;
621 settings.number.bg_color = PRCOLOR_WHITE; 621 settings.number.bg_color = PRCOLOR_WHITE;
622 settings.number.bold = FALSE; 622 settings.number.bold = FALSE;
623 settings.number.italic = TRUE; 623 settings.number.italic = TRUE;
624 settings.number.underline = FALSE; 624 settings.number.underline = FALSE;
647 { 647 {
648 msg(_("No text to be printed")); 648 msg(_("No text to be printed"));
649 goto print_fail_no_begin; 649 goto print_fail_no_begin;
650 } 650 }
651 651
652 /* Set colors and font to normal. */ 652 // Set colors and font to normal.
653 curr_bg = (long_u)0xffffffffL; 653 curr_bg = (long_u)0xffffffffL;
654 curr_fg = (long_u)0xffffffffL; 654 curr_fg = (long_u)0xffffffffL;
655 curr_italic = MAYBE; 655 curr_italic = MAYBE;
656 curr_bold = MAYBE; 656 curr_bold = MAYBE;
657 curr_underline = MAYBE; 657 curr_underline = MAYBE;
675 page_count = 0; 675 page_count = 0;
676 for (collated_copies = 0; 676 for (collated_copies = 0;
677 collated_copies < settings.n_collated_copies; 677 collated_copies < settings.n_collated_copies;
678 collated_copies++) 678 collated_copies++)
679 { 679 {
680 prt_pos_T prtpos; /* current print position */ 680 prt_pos_T prtpos; // current print position
681 prt_pos_T page_prtpos; /* print position at page start */ 681 prt_pos_T page_prtpos; // print position at page start
682 int side; 682 int side;
683 683
684 vim_memset(&page_prtpos, 0, sizeof(prt_pos_T)); 684 vim_memset(&page_prtpos, 0, sizeof(prt_pos_T));
685 page_prtpos.file_line = eap->line1; 685 page_prtpos.file_line = eap->line1;
686 prtpos = page_prtpos; 686 prtpos = page_prtpos;
687 687
688 if (jobsplit && collated_copies > 0) 688 if (jobsplit && collated_copies > 0)
689 { 689 {
690 /* Splitting jobs: Stop a previous job and start a new one. */ 690 // Splitting jobs: Stop a previous job and start a new one.
691 mch_print_end(&settings); 691 mch_print_end(&settings);
692 if (!mch_print_begin(&settings)) 692 if (!mch_print_begin(&settings))
693 goto print_fail_no_begin; 693 goto print_fail_no_begin;
694 } 694 }
695 695
704 */ 704 */
705 for (uncollated_copies = 0; 705 for (uncollated_copies = 0;
706 uncollated_copies < settings.n_uncollated_copies; 706 uncollated_copies < settings.n_uncollated_copies;
707 uncollated_copies++) 707 uncollated_copies++)
708 { 708 {
709 /* Set the print position to the start of this page. */ 709 // Set the print position to the start of this page.
710 prtpos = page_prtpos; 710 prtpos = page_prtpos;
711 711
712 /* 712 /*
713 * Do front and rear side of a page. 713 * Do front and rear side of a page.
714 */ 714 */
716 { 716 {
717 /* 717 /*
718 * Print one page. 718 * Print one page.
719 */ 719 */
720 720
721 /* Check for interrupt character every page. */ 721 // Check for interrupt character every page.
722 ui_breakcheck(); 722 ui_breakcheck();
723 if (got_int || settings.user_abort) 723 if (got_int || settings.user_abort)
724 goto print_fail; 724 goto print_fail;
725 725
726 sprintf((char *)IObuff, _("Printing page %d (%d%%)"), 726 sprintf((char *)IObuff, _("Printing page %d (%d%%)"),
752 { 752 {
753 prtpos.column = hardcopy_line(&settings, 753 prtpos.column = hardcopy_line(&settings,
754 page_line, &prtpos); 754 page_line, &prtpos);
755 if (prtpos.column == 0) 755 if (prtpos.column == 0)
756 { 756 {
757 /* finished a file line */ 757 // finished a file line
758 prtpos.bytes_printed += 758 prtpos.bytes_printed +=
759 STRLEN(skipwhite(ml_get(prtpos.file_line))); 759 STRLEN(skipwhite(ml_get(prtpos.file_line)));
760 if (++prtpos.file_line > eap->line2) 760 if (++prtpos.file_line > eap->line2)
761 break; /* reached the end */ 761 break; // reached the end
762 } 762 }
763 else if (prtpos.ff) 763 else if (prtpos.ff)
764 { 764 {
765 /* Line had a formfeed in it - start new page but 765 // Line had a formfeed in it - start new page but
766 * stay on the current line */ 766 // stay on the current line
767 break; 767 break;
768 } 768 }
769 } 769 }
770 770
771 if (!mch_print_end_page()) 771 if (!mch_print_end_page())
772 goto print_fail; 772 goto print_fail;
773 if (prtpos.file_line > eap->line2) 773 if (prtpos.file_line > eap->line2)
774 break; /* reached the end */ 774 break; // reached the end
775 } 775 }
776 776
777 /* 777 /*
778 * Extra blank page for duplexing with odd number of pages and 778 * Extra blank page for duplexing with odd number of pages and
779 * more copies to come. 779 * more copies to come.
787 } 787 }
788 } 788 }
789 if (settings.duplex && prtpos.file_line <= eap->line2) 789 if (settings.duplex && prtpos.file_line <= eap->line2)
790 ++page_count; 790 ++page_count;
791 791
792 /* Remember the position where the next page starts. */ 792 // Remember the position where the next page starts.
793 page_prtpos = prtpos; 793 page_prtpos = prtpos;
794 } 794 }
795 795
796 vim_snprintf((char *)IObuff, IOSIZE, _("Printed: %s"), 796 vim_snprintf((char *)IObuff, IOSIZE, _("Printed: %s"),
797 settings.jobname); 797 settings.jobname);
839 prt_line_number(psettings, page_line, ppos->file_line); 839 prt_line_number(psettings, page_line, ppos->file_line);
840 ppos->ff = FALSE; 840 ppos->ff = FALSE;
841 } 841 }
842 else 842 else
843 { 843 {
844 /* left over from wrap halfway a tab */ 844 // left over from wrap halfway a tab
845 print_pos = ppos->print_pos; 845 print_pos = ppos->print_pos;
846 tab_spaces = ppos->lead_spaces; 846 tab_spaces = ppos->lead_spaces;
847 } 847 }
848 848
849 mch_print_start_line(0, page_line); 849 mch_print_start_line(0, page_line);
866 id = syn_get_id(curwin, ppos->file_line, col, 1, NULL, FALSE); 866 id = syn_get_id(curwin, ppos->file_line, col, 1, NULL, FALSE);
867 if (id > 0) 867 if (id > 0)
868 id = syn_get_final_id(id); 868 id = syn_get_final_id(id);
869 else 869 else
870 id = 0; 870 id = 0;
871 /* Get the line again, a multi-line regexp may invalidate it. */ 871 // Get the line again, a multi-line regexp may invalidate it.
872 line = ml_get(ppos->file_line); 872 line = ml_get(ppos->file_line);
873 873
874 if (id != current_syn_id) 874 if (id != current_syn_id)
875 { 875 {
876 current_syn_id = id; 876 current_syn_id = id;
901 print_pos++; 901 print_pos++;
902 tab_spaces--; 902 tab_spaces--;
903 if (need_break) 903 if (need_break)
904 break; 904 break;
905 } 905 }
906 /* Keep the TAB if we didn't finish it. */ 906 // Keep the TAB if we didn't finish it.
907 if (need_break && tab_spaces > 0) 907 if (need_break && tab_spaces > 0)
908 break; 908 break;
909 } 909 }
910 else if (line[col] == FF 910 else if (line[col] == FF
911 && printer_opts[OPT_PRINT_FORMFEED].present 911 && printer_opts[OPT_PRINT_FORMFEED].present
972 * http://www.adobe.com 972 * http://www.adobe.com
973 */ 973 */
974 974
975 #define NUM_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0])) 975 #define NUM_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0]))
976 976
977 #define PRT_PS_DEFAULT_DPI (72) /* Default user space resolution */ 977 #define PRT_PS_DEFAULT_DPI (72) // Default user space resolution
978 #define PRT_PS_DEFAULT_FONTSIZE (10) 978 #define PRT_PS_DEFAULT_FONTSIZE (10)
979 #define PRT_PS_DEFAULT_BUFFER_SIZE (80) 979 #define PRT_PS_DEFAULT_BUFFER_SIZE (80)
980 980
981 struct prt_mediasize_S 981 struct prt_mediasize_S
982 { 982 {
983 char *name; 983 char *name;
984 float width; /* width and height in points for portrait */ 984 float width; // width and height in points for portrait
985 float height; 985 float height;
986 }; 986 };
987 987
988 #define PRT_MEDIASIZE_LEN (sizeof(prt_mediasize) / sizeof(struct prt_mediasize_S)) 988 #define PRT_MEDIASIZE_LEN (sizeof(prt_mediasize) / sizeof(struct prt_mediasize_S))
989 989
996 {"A5", 420.0, 595.0}, 996 {"A5", 420.0, 595.0},
997 {"B4", 729.0, 1032.0}, 997 {"B4", 729.0, 1032.0},
998 {"B5", 516.0, 729.0}, 998 {"B5", 516.0, 729.0},
999 {"executive", 522.0, 756.0}, 999 {"executive", 522.0, 756.0},
1000 {"folio", 595.0, 935.0}, 1000 {"folio", 595.0, 935.0},
1001 {"ledger", 1224.0, 792.0}, /* Yes, it is wider than taller! */ 1001 {"ledger", 1224.0, 792.0}, // Yes, it is wider than taller!
1002 {"legal", 612.0, 1008.0}, 1002 {"legal", 612.0, 1008.0},
1003 {"quarto", 610.0, 780.0}, 1003 {"quarto", 610.0, 780.0},
1004 {"statement", 396.0, 612.0}, 1004 {"statement", 396.0, 612.0},
1005 {"tabloid", 792.0, 1224.0} 1005 {"tabloid", 792.0, 1224.0}
1006 }; 1006 };
1007 1007
1008 /* PS font names, must be in Roman, Bold, Italic, Bold-Italic order */ 1008 // PS font names, must be in Roman, Bold, Italic, Bold-Italic order
1009 struct prt_ps_font_S 1009 struct prt_ps_font_S
1010 { 1010 {
1011 int wx; 1011 int wx;
1012 int uline_offset; 1012 int uline_offset;
1013 int uline_width; 1013 int uline_width;
1019 #define PRT_PS_FONT_ROMAN (0) 1019 #define PRT_PS_FONT_ROMAN (0)
1020 #define PRT_PS_FONT_BOLD (1) 1020 #define PRT_PS_FONT_BOLD (1)
1021 #define PRT_PS_FONT_OBLIQUE (2) 1021 #define PRT_PS_FONT_OBLIQUE (2)
1022 #define PRT_PS_FONT_BOLDOBLIQUE (3) 1022 #define PRT_PS_FONT_BOLDOBLIQUE (3)
1023 1023
1024 /* Standard font metrics for Courier family */ 1024 // Standard font metrics for Courier family
1025 static struct prt_ps_font_S prt_ps_courier_font = 1025 static struct prt_ps_font_S prt_ps_courier_font =
1026 { 1026 {
1027 600, 1027 600,
1028 -100, 50, 1028 -100, 50,
1029 -250, 805, 1029 -250, 805,
1030 {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"} 1030 {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"}
1031 }; 1031 };
1032 1032
1033 /* Generic font metrics for multi-byte fonts */ 1033 // Generic font metrics for multi-byte fonts
1034 static struct prt_ps_font_S prt_ps_mb_font = 1034 static struct prt_ps_font_S prt_ps_mb_font =
1035 { 1035 {
1036 1000, 1036 1000,
1037 -100, 50, 1037 -100, 50,
1038 -250, 805, 1038 -250, 805,
1039 {NULL, NULL, NULL, NULL} 1039 {NULL, NULL, NULL, NULL}
1040 }; 1040 };
1041 1041
1042 /* Pointer to current font set being used */ 1042 // Pointer to current font set being used
1043 static struct prt_ps_font_S* prt_ps_font; 1043 static struct prt_ps_font_S* prt_ps_font;
1044 1044
1045 /* Structures to map user named encoding and mapping to PS equivalents for 1045 // Structures to map user named encoding and mapping to PS equivalents for
1046 * building CID font name */ 1046 // building CID font name
1047 struct prt_ps_encoding_S 1047 struct prt_ps_encoding_S
1048 { 1048 {
1049 char *encoding; 1049 char *encoding;
1050 char *cmap_encoding; 1050 char *cmap_encoding;
1051 int needs_charset; 1051 int needs_charset;
1066 #define CS_MSWINDOWS (0x10) 1066 #define CS_MSWINDOWS (0x10)
1067 #define CS_CP932 (0x20) 1067 #define CS_CP932 (0x20)
1068 #define CS_KANJITALK6 (0x40) 1068 #define CS_KANJITALK6 (0x40)
1069 #define CS_KANJITALK7 (0x80) 1069 #define CS_KANJITALK7 (0x80)
1070 1070
1071 /* Japanese encodings and charsets */ 1071 // Japanese encodings and charsets
1072 static struct prt_ps_encoding_S j_encodings[] = 1072 static struct prt_ps_encoding_S j_encodings[] =
1073 { 1073 {
1074 {"iso-2022-jp", NULL, (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990| 1074 {"iso-2022-jp", NULL, (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990|
1075 CS_NEC)}, 1075 CS_NEC)},
1076 {"euc-jp", "EUC", (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990)}, 1076 {"euc-jp", "EUC", (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990)},
1098 #define CS_SC_MAC (0x08) 1098 #define CS_SC_MAC (0x08)
1099 #define CS_GBT_90_MAC (0x10) 1099 #define CS_GBT_90_MAC (0x10)
1100 #define CS_GBK (0x20) 1100 #define CS_GBK (0x20)
1101 #define CS_SC_ISO10646 (0x40) 1101 #define CS_SC_ISO10646 (0x40)
1102 1102
1103 /* Simplified Chinese encodings and charsets */ 1103 // Simplified Chinese encodings and charsets
1104 static struct prt_ps_encoding_S sc_encodings[] = 1104 static struct prt_ps_encoding_S sc_encodings[] =
1105 { 1105 {
1106 {"iso-2022", NULL, (CS_GB_2312_80|CS_GBT_12345_90)}, 1106 {"iso-2022", NULL, (CS_GB_2312_80|CS_GBT_12345_90)},
1107 {"gb18030", NULL, CS_GBK2K}, 1107 {"gb18030", NULL, CS_GBK2K},
1108 {"euc-cn", "EUC", (CS_GB_2312_80|CS_GBT_12345_90|CS_SC_MAC| 1108 {"euc-cn", "EUC", (CS_GB_2312_80|CS_GBT_12345_90|CS_SC_MAC|
1134 #define CS_MTHKS (0x200) 1134 #define CS_MTHKS (0x200)
1135 #define CS_DLHKL (0x400) 1135 #define CS_DLHKL (0x400)
1136 #define CS_DLHKS (0x800) 1136 #define CS_DLHKS (0x800)
1137 #define CS_TC_ISO10646 (0x1000) 1137 #define CS_TC_ISO10646 (0x1000)
1138 1138
1139 /* Traditional Chinese encodings and charsets */ 1139 // Traditional Chinese encodings and charsets
1140 static struct prt_ps_encoding_S tc_encodings[] = 1140 static struct prt_ps_encoding_S tc_encodings[] =
1141 { 1141 {
1142 {"iso-2022", NULL, (CS_CNS_PLANE_1|CS_CNS_PLANE_2)}, 1142 {"iso-2022", NULL, (CS_CNS_PLANE_1|CS_CNS_PLANE_2)},
1143 {"euc-tw", "EUC", CS_CNS_PLANE_1_2}, 1143 {"euc-tw", "EUC", CS_CNS_PLANE_1_2},
1144 {"big5", "B5", (CS_B5|CS_ETEN|CS_HK_GCCS|CS_HK_SCS| 1144 {"big5", "B5", (CS_B5|CS_ETEN|CS_HK_GCCS|CS_HK_SCS|
1171 #define CS_KR_X_1992 (0x01) 1171 #define CS_KR_X_1992 (0x01)
1172 #define CS_KR_MAC (0x02) 1172 #define CS_KR_MAC (0x02)
1173 #define CS_KR_X_1992_MS (0x04) 1173 #define CS_KR_X_1992_MS (0x04)
1174 #define CS_KR_ISO10646 (0x08) 1174 #define CS_KR_ISO10646 (0x08)
1175 1175
1176 /* Korean encodings and charsets */ 1176 // Korean encodings and charsets
1177 static struct prt_ps_encoding_S k_encodings[] = 1177 static struct prt_ps_encoding_S k_encodings[] =
1178 { 1178 {
1179 {"iso-2022-kr", NULL, CS_KR_X_1992}, 1179 {"iso-2022-kr", NULL, CS_KR_X_1992},
1180 {"euc-kr", "EUC", (CS_KR_X_1992|CS_KR_MAC)}, 1180 {"euc-kr", "EUC", (CS_KR_X_1992|CS_KR_MAC)},
1181 {"johab", "Johab", CS_KR_X_1992}, 1181 {"johab", "Johab", CS_KR_X_1992},
1194 {"CP949", "KSCms", CS_KR_X_1992_MS}, 1194 {"CP949", "KSCms", CS_KR_X_1992_MS},
1195 {"WANSUNG", "KSCms", CS_KR_X_1992_MS}, 1195 {"WANSUNG", "KSCms", CS_KR_X_1992_MS},
1196 {"ISO10646", "UniKS", CS_KR_ISO10646} 1196 {"ISO10646", "UniKS", CS_KR_ISO10646}
1197 }; 1197 };
1198 1198
1199 /* Collections of encodings and charsets for multi-byte printing */ 1199 // Collections of encodings and charsets for multi-byte printing
1200 struct prt_ps_mbfont_S 1200 struct prt_ps_mbfont_S
1201 { 1201 {
1202 int num_encodings; 1202 int num_encodings;
1203 struct prt_ps_encoding_S *encodings; 1203 struct prt_ps_encoding_S *encodings;
1204 int num_charsets; 1204 int num_charsets;
1250 int type; 1250 int type;
1251 char_u title[256]; 1251 char_u title[256];
1252 char_u version[256]; 1252 char_u version[256];
1253 }; 1253 };
1254 1254
1255 /* Types of PS resource file currently used */ 1255 // Types of PS resource file currently used
1256 #define PRT_RESOURCE_TYPE_PROCSET (0) 1256 #define PRT_RESOURCE_TYPE_PROCSET (0)
1257 #define PRT_RESOURCE_TYPE_ENCODING (1) 1257 #define PRT_RESOURCE_TYPE_ENCODING (1)
1258 #define PRT_RESOURCE_TYPE_CMAP (2) 1258 #define PRT_RESOURCE_TYPE_CMAP (2)
1259 1259
1260 /* The PS prolog file version number has to match - if the prolog file is 1260 // The PS prolog file version number has to match - if the prolog file is
1261 * updated, increment the number in the file and here. Version checking was 1261 // updated, increment the number in the file and here. Version checking was
1262 * added as of VIM 6.2. 1262 // added as of VIM 6.2.
1263 * The CID prolog file version number behaves as per PS prolog. 1263 // The CID prolog file version number behaves as per PS prolog.
1264 * Table of VIM and prolog versions: 1264 // Table of VIM and prolog versions:
1265 * 1265 //
1266 * VIM Prolog CIDProlog 1266 // VIM Prolog CIDProlog
1267 * 6.2 1.3 1267 // 6.2 1.3
1268 * 7.0 1.4 1.0 1268 // 7.0 1.4 1.0
1269 */
1270 #define PRT_PROLOG_VERSION ((char_u *)"1.4") 1269 #define PRT_PROLOG_VERSION ((char_u *)"1.4")
1271 #define PRT_CID_PROLOG_VERSION ((char_u *)"1.0") 1270 #define PRT_CID_PROLOG_VERSION ((char_u *)"1.0")
1272 1271
1273 /* String versions of PS resource types - indexed by constants above so don't 1272 // String versions of PS resource types - indexed by constants above so don't
1274 * re-order! 1273 // re-order!
1275 */
1276 static char *prt_resource_types[] = 1274 static char *prt_resource_types[] =
1277 { 1275 {
1278 "procset", 1276 "procset",
1279 "encoding", 1277 "encoding",
1280 "cmap" 1278 "cmap"
1281 }; 1279 };
1282 1280
1283 /* Strings to look for in a PS resource file */ 1281 // Strings to look for in a PS resource file
1284 #define PRT_RESOURCE_HEADER "%!PS-Adobe-" 1282 #define PRT_RESOURCE_HEADER "%!PS-Adobe-"
1285 #define PRT_RESOURCE_RESOURCE "Resource-" 1283 #define PRT_RESOURCE_RESOURCE "Resource-"
1286 #define PRT_RESOURCE_PROCSET "ProcSet" 1284 #define PRT_RESOURCE_PROCSET "ProcSet"
1287 #define PRT_RESOURCE_ENCODING "Encoding" 1285 #define PRT_RESOURCE_ENCODING "Encoding"
1288 #define PRT_RESOURCE_CMAP "CMap" 1286 #define PRT_RESOURCE_CMAP "CMap"
1289 1287
1290 1288
1291 /* Data for table based DSC comment recognition, easy to extend if VIM needs to 1289 // Data for table based DSC comment recognition, easy to extend if VIM needs to
1292 * read more comments. */ 1290 // read more comments.
1293 #define PRT_DSC_MISC_TYPE (-1) 1291 #define PRT_DSC_MISC_TYPE (-1)
1294 #define PRT_DSC_TITLE_TYPE (1) 1292 #define PRT_DSC_TITLE_TYPE (1)
1295 #define PRT_DSC_VERSION_TYPE (2) 1293 #define PRT_DSC_VERSION_TYPE (2)
1296 #define PRT_DSC_ENDCOMMENTS_TYPE (3) 1294 #define PRT_DSC_ENDCOMMENTS_TYPE (3)
1297 1295
1543 { 1541 {
1544 int integer; 1542 int integer;
1545 int fraction; 1543 int fraction;
1546 1544
1547 prt_real_bits(val, prec, &integer, &fraction); 1545 prt_real_bits(val, prec, &integer, &fraction);
1548 /* Emit integer part */ 1546 // Emit integer part
1549 sprintf((char *)prt_line_buffer, "%d", integer); 1547 sprintf((char *)prt_line_buffer, "%d", integer);
1550 prt_write_file(prt_line_buffer); 1548 prt_write_file(prt_line_buffer);
1551 /* Only emit fraction if necessary */ 1549 // Only emit fraction if necessary
1552 if (fraction != 0) 1550 if (fraction != 0)
1553 { 1551 {
1554 /* Remove any trailing zeros */ 1552 // Remove any trailing zeros
1555 while ((fraction % 10) == 0) 1553 while ((fraction % 10) == 0)
1556 { 1554 {
1557 prec--; 1555 prec--;
1558 fraction /= 10; 1556 fraction /= 10;
1559 } 1557 }
1560 /* Emit fraction left padded with zeros */ 1558 // Emit fraction left padded with zeros
1561 sprintf((char *)prt_line_buffer, ".%0*d", prec, fraction); 1559 sprintf((char *)prt_line_buffer, ".%0*d", prec, fraction);
1562 prt_write_file(prt_line_buffer); 1560 prt_write_file(prt_line_buffer);
1563 } 1561 }
1564 sprintf((char *)prt_line_buffer, " "); 1562 sprintf((char *)prt_line_buffer, " ");
1565 prt_write_file(prt_line_buffer); 1563 prt_write_file(prt_line_buffer);
1577 prt_write_real(value, prec); 1575 prt_write_real(value, prec);
1578 sprintf((char *)prt_line_buffer, "d\n"); 1576 sprintf((char *)prt_line_buffer, "d\n");
1579 prt_write_file(prt_line_buffer); 1577 prt_write_file(prt_line_buffer);
1580 } 1578 }
1581 1579
1582 /* Convert size from font space to user space at current font scale */ 1580 // Convert size from font space to user space at current font scale
1583 #define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0)) 1581 #define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0))
1584 1582
1585 static void 1583 static void
1586 prt_flush_buffer(void) 1584 prt_flush_buffer(void)
1587 { 1585 {
1588 if (prt_ps_buffer.ga_len > 0) 1586 if (prt_ps_buffer.ga_len > 0)
1589 { 1587 {
1590 /* Any background color must be drawn first */ 1588 // Any background color must be drawn first
1591 if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) 1589 if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE))
1592 { 1590 {
1593 int r, g, b; 1591 int r, g, b;
1594 1592
1595 if (prt_do_moveto) 1593 if (prt_do_moveto)
1598 prt_write_real(prt_pos_y_moveto, 2); 1596 prt_write_real(prt_pos_y_moveto, 2);
1599 prt_write_string("m\n"); 1597 prt_write_string("m\n");
1600 prt_do_moveto = FALSE; 1598 prt_do_moveto = FALSE;
1601 } 1599 }
1602 1600
1603 /* Size of rect of background color on which text is printed */ 1601 // Size of rect of background color on which text is printed
1604 prt_write_real(prt_text_run, 2); 1602 prt_write_real(prt_text_run, 2);
1605 prt_write_real(prt_line_height, 2); 1603 prt_write_real(prt_line_height, 2);
1606 1604
1607 /* Lastly add the color of the background */ 1605 // Lastly add the color of the background
1608 r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16; 1606 r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16;
1609 g = ((unsigned)prt_new_bgcol & 0xff00) >> 8; 1607 g = ((unsigned)prt_new_bgcol & 0xff00) >> 8;
1610 b = prt_new_bgcol & 0xff; 1608 b = prt_new_bgcol & 0xff;
1611 prt_write_real(r / 255.0, 3); 1609 prt_write_real(r / 255.0, 3);
1612 prt_write_real(g / 255.0, 3); 1610 prt_write_real(g / 255.0, 3);
1613 prt_write_real(b / 255.0, 3); 1611 prt_write_real(b / 255.0, 3);
1614 prt_write_string("bg\n"); 1612 prt_write_string("bg\n");
1615 } 1613 }
1616 /* Draw underlines before the text as it makes it slightly easier to 1614 // Draw underlines before the text as it makes it slightly easier to
1617 * find the starting point. 1615 // find the starting point.
1618 */
1619 if (prt_do_underline) 1616 if (prt_do_underline)
1620 { 1617 {
1621 if (prt_do_moveto) 1618 if (prt_do_moveto)
1622 { 1619 {
1623 prt_write_real(prt_pos_x_moveto, 2); 1620 prt_write_real(prt_pos_x_moveto, 2);
1624 prt_write_real(prt_pos_y_moveto, 2); 1621 prt_write_real(prt_pos_y_moveto, 2);
1625 prt_write_string("m\n"); 1622 prt_write_string("m\n");
1626 prt_do_moveto = FALSE; 1623 prt_do_moveto = FALSE;
1627 } 1624 }
1628 1625
1629 /* Underline length of text run */ 1626 // Underline length of text run
1630 prt_write_real(prt_text_run, 2); 1627 prt_write_real(prt_text_run, 2);
1631 prt_write_string("ul\n"); 1628 prt_write_string("ul\n");
1632 } 1629 }
1633 /* Draw the text 1630 // Draw the text
1634 * Note: we write text out raw - EBCDIC conversion is handled in the 1631 // Note: we write text out raw - EBCDIC conversion is handled in the
1635 * PostScript world via the font encoding vector. */ 1632 // PostScript world via the font encoding vector.
1636 if (prt_out_mbyte) 1633 if (prt_out_mbyte)
1637 prt_write_string("<"); 1634 prt_write_string("<");
1638 else 1635 else
1639 prt_write_string("("); 1636 prt_write_string("(");
1640 prt_write_file_raw_len(prt_ps_buffer.ga_data, prt_ps_buffer.ga_len); 1637 prt_write_file_raw_len(prt_ps_buffer.ga_data, prt_ps_buffer.ga_len);
1641 if (prt_out_mbyte) 1638 if (prt_out_mbyte)
1642 prt_write_string(">"); 1639 prt_write_string(">");
1643 else 1640 else
1644 prt_write_string(")"); 1641 prt_write_string(")");
1645 /* Add a moveto if need be and use the appropriate show procedure */ 1642 // Add a moveto if need be and use the appropriate show procedure
1646 if (prt_do_moveto) 1643 if (prt_do_moveto)
1647 { 1644 {
1648 prt_write_real(prt_pos_x_moveto, 2); 1645 prt_write_real(prt_pos_x_moveto, 2);
1649 prt_write_real(prt_pos_y_moveto, 2); 1646 prt_write_real(prt_pos_y_moveto, 2);
1650 /* moveto and a show */ 1647 // moveto and a show
1651 prt_write_string("ms\n"); 1648 prt_write_string("ms\n");
1652 prt_do_moveto = FALSE; 1649 prt_do_moveto = FALSE;
1653 } 1650 }
1654 else /* Simple show */ 1651 else // Simple show
1655 prt_write_string("s\n"); 1652 prt_write_string("s\n");
1656 1653
1657 ga_clear(&prt_ps_buffer); 1654 ga_clear(&prt_ps_buffer);
1658 ga_init2(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz); 1655 ga_init2(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz);
1659 } 1656 }
1680 buffer = alloc(MAXPATHL + 1); 1677 buffer = alloc(MAXPATHL + 1);
1681 if (buffer == NULL) 1678 if (buffer == NULL)
1682 return FALSE; 1679 return FALSE;
1683 1680
1684 vim_strncpy(resource->name, (char_u *)name, 63); 1681 vim_strncpy(resource->name, (char_u *)name, 63);
1685 /* Look for named resource file in runtimepath */ 1682 // Look for named resource file in runtimepath
1686 STRCPY(buffer, "print"); 1683 STRCPY(buffer, "print");
1687 add_pathsep(buffer); 1684 add_pathsep(buffer);
1688 vim_strcat(buffer, (char_u *)name, MAXPATHL); 1685 vim_strcat(buffer, (char_u *)name, MAXPATHL);
1689 vim_strcat(buffer, (char_u *)".ps", MAXPATHL); 1686 vim_strcat(buffer, (char_u *)".ps", MAXPATHL);
1690 resource->filename[0] = NUL; 1687 resource->filename[0] = NUL;
1693 && resource->filename[0] != NUL); 1690 && resource->filename[0] != NUL);
1694 vim_free(buffer); 1691 vim_free(buffer);
1695 return retval; 1692 return retval;
1696 } 1693 }
1697 1694
1698 /* PS CR and LF characters have platform independent values */ 1695 // PS CR and LF characters have platform independent values
1699 #define PSLF (0x0a) 1696 #define PSLF (0x0a)
1700 #define PSCR (0x0d) 1697 #define PSCR (0x0d)
1701 1698
1702 /* Static buffer to read initial comments in a resource file, some can have a 1699 // Static buffer to read initial comments in a resource file, some can have a
1703 * couple of KB of comments! */ 1700 // couple of KB of comments!
1704 #define PRT_FILE_BUFFER_LEN (2048) 1701 #define PRT_FILE_BUFFER_LEN (2048)
1705 struct prt_resfile_buffer_S 1702 struct prt_resfile_buffer_S
1706 { 1703 {
1707 char_u buffer[PRT_FILE_BUFFER_LEN]; 1704 char_u buffer[PRT_FILE_BUFFER_LEN];
1708 int len; 1705 int len;
1715 static int 1712 static int
1716 prt_resfile_next_line(void) 1713 prt_resfile_next_line(void)
1717 { 1714 {
1718 int idx; 1715 int idx;
1719 1716
1720 /* Move to start of next line and then find end of line */ 1717 // Move to start of next line and then find end of line
1721 idx = prt_resfile.line_end + 1; 1718 idx = prt_resfile.line_end + 1;
1722 while (idx < prt_resfile.len) 1719 while (idx < prt_resfile.len)
1723 { 1720 {
1724 if (prt_resfile.buffer[idx] != PSLF && prt_resfile.buffer[idx] != PSCR) 1721 if (prt_resfile.buffer[idx] != PSLF && prt_resfile.buffer[idx] != PSCR)
1725 break; 1722 break;
1739 } 1736 }
1740 1737
1741 static int 1738 static int
1742 prt_resfile_strncmp(int offset, char *string, int len) 1739 prt_resfile_strncmp(int offset, char *string, int len)
1743 { 1740 {
1744 /* Force not equal if string is longer than remainder of line */ 1741 // Force not equal if string is longer than remainder of line
1745 if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset))) 1742 if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset)))
1746 return 1; 1743 return 1;
1747 1744
1748 return STRNCMP(&prt_resfile.buffer[prt_resfile.line_start + offset], 1745 return STRNCMP(&prt_resfile.buffer[prt_resfile.line_start + offset],
1749 string, len); 1746 string, len);
1777 idx++; 1774 idx++;
1778 } 1775 }
1779 return -1; 1776 return -1;
1780 } 1777 }
1781 1778
1782 /* prt_next_dsc() - returns detail on next DSC comment line found. Returns true 1779 // prt_next_dsc() - returns detail on next DSC comment line found. Returns true
1783 * if a DSC comment is found, else false */ 1780 // if a DSC comment is found, else false
1784 static int 1781 static int
1785 prt_next_dsc(struct prt_dsc_line_S *p_dsc_line) 1782 prt_next_dsc(struct prt_dsc_line_S *p_dsc_line)
1786 { 1783 {
1787 int comment; 1784 int comment;
1788 int offset; 1785 int offset;
1789 1786
1790 /* Move to start of next line */ 1787 // Move to start of next line
1791 if (!prt_resfile_next_line()) 1788 if (!prt_resfile_next_line())
1792 return FALSE; 1789 return FALSE;
1793 1790
1794 /* DSC comments always start %% */ 1791 // DSC comments always start %%
1795 if (prt_resfile_strncmp(0, "%%", 2) != 0) 1792 if (prt_resfile_strncmp(0, "%%", 2) != 0)
1796 return FALSE; 1793 return FALSE;
1797 1794
1798 /* Find type of DSC comment */ 1795 // Find type of DSC comment
1799 for (comment = 0; comment < (int)NUM_ELEMENTS(prt_dsc_table); comment++) 1796 for (comment = 0; comment < (int)NUM_ELEMENTS(prt_dsc_table); comment++)
1800 if (prt_resfile_strncmp(0, prt_dsc_table[comment].string, 1797 if (prt_resfile_strncmp(0, prt_dsc_table[comment].string,
1801 prt_dsc_table[comment].len) == 0) 1798 prt_dsc_table[comment].len) == 0)
1802 break; 1799 break;
1803 1800
1804 if (comment != NUM_ELEMENTS(prt_dsc_table)) 1801 if (comment != NUM_ELEMENTS(prt_dsc_table))
1805 { 1802 {
1806 /* Return type of comment */ 1803 // Return type of comment
1807 p_dsc_line->type = prt_dsc_table[comment].type; 1804 p_dsc_line->type = prt_dsc_table[comment].type;
1808 offset = prt_dsc_table[comment].len; 1805 offset = prt_dsc_table[comment].len;
1809 } 1806 }
1810 else 1807 else
1811 { 1808 {
1812 /* Unrecognised DSC comment, skip to ws after comment leader */ 1809 // Unrecognised DSC comment, skip to ws after comment leader
1813 p_dsc_line->type = PRT_DSC_MISC_TYPE; 1810 p_dsc_line->type = PRT_DSC_MISC_TYPE;
1814 offset = prt_resfile_skip_nonws(0); 1811 offset = prt_resfile_skip_nonws(0);
1815 if (offset == -1) 1812 if (offset == -1)
1816 return FALSE; 1813 return FALSE;
1817 } 1814 }
1818 1815
1819 /* Skip ws to comment value */ 1816 // Skip ws to comment value
1820 offset = prt_resfile_skip_ws(offset); 1817 offset = prt_resfile_skip_ws(offset);
1821 if (offset == -1) 1818 if (offset == -1)
1822 return FALSE; 1819 return FALSE;
1823 1820
1824 p_dsc_line->string = &prt_resfile.buffer[prt_resfile.line_start + offset]; 1821 p_dsc_line->string = &prt_resfile.buffer[prt_resfile.line_start + offset];
1825 p_dsc_line->len = prt_resfile.line_end - (prt_resfile.line_start + offset); 1822 p_dsc_line->len = prt_resfile.line_end - (prt_resfile.line_start + offset);
1826 1823
1827 return TRUE; 1824 return TRUE;
1828 } 1825 }
1829 1826
1830 /* Improved hand crafted parser to get the type, title, and version number of a 1827 /*
1828 * Improved hand crafted parser to get the type, title, and version number of a
1831 * PS resource file so the file details can be added to the DSC header comments. 1829 * PS resource file so the file details can be added to the DSC header comments.
1832 */ 1830 */
1833 static int 1831 static int
1834 prt_open_resource(struct prt_ps_resource_S *resource) 1832 prt_open_resource(struct prt_ps_resource_S *resource)
1835 { 1833 {
1846 semsg(_("E624: Can't open file \"%s\""), resource->filename); 1844 semsg(_("E624: Can't open file \"%s\""), resource->filename);
1847 return FALSE; 1845 return FALSE;
1848 } 1846 }
1849 vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN); 1847 vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN);
1850 1848
1851 /* Parse first line to ensure valid resource file */ 1849 // Parse first line to ensure valid resource file
1852 prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u), 1850 prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u),
1853 PRT_FILE_BUFFER_LEN, fd_resource); 1851 PRT_FILE_BUFFER_LEN, fd_resource);
1854 if (ferror(fd_resource)) 1852 if (ferror(fd_resource))
1855 { 1853 {
1856 semsg(_("E457: Can't read PostScript resource file \"%s\""), 1854 semsg(_("E457: Can't read PostScript resource file \"%s\""),
1873 semsg(_("E618: file \"%s\" is not a PostScript resource file"), 1871 semsg(_("E618: file \"%s\" is not a PostScript resource file"),
1874 resource->filename); 1872 resource->filename);
1875 return FALSE; 1873 return FALSE;
1876 } 1874 }
1877 1875
1878 /* Skip over any version numbers and following ws */ 1876 // Skip over any version numbers and following ws
1879 offset += (int)STRLEN(PRT_RESOURCE_HEADER); 1877 offset += (int)STRLEN(PRT_RESOURCE_HEADER);
1880 offset = prt_resfile_skip_nonws(offset); 1878 offset = prt_resfile_skip_nonws(offset);
1881 if (offset == -1) 1879 if (offset == -1)
1882 return FALSE; 1880 return FALSE;
1883 offset = prt_resfile_skip_ws(offset); 1881 offset = prt_resfile_skip_ws(offset);
1891 resource->filename); 1889 resource->filename);
1892 return FALSE; 1890 return FALSE;
1893 } 1891 }
1894 offset += (int)STRLEN(PRT_RESOURCE_RESOURCE); 1892 offset += (int)STRLEN(PRT_RESOURCE_RESOURCE);
1895 1893
1896 /* Decide type of resource in the file */ 1894 // Decide type of resource in the file
1897 if (prt_resfile_strncmp(offset, PRT_RESOURCE_PROCSET, 1895 if (prt_resfile_strncmp(offset, PRT_RESOURCE_PROCSET,
1898 (int)STRLEN(PRT_RESOURCE_PROCSET)) == 0) 1896 (int)STRLEN(PRT_RESOURCE_PROCSET)) == 0)
1899 resource->type = PRT_RESOURCE_TYPE_PROCSET; 1897 resource->type = PRT_RESOURCE_TYPE_PROCSET;
1900 else if (prt_resfile_strncmp(offset, PRT_RESOURCE_ENCODING, 1898 else if (prt_resfile_strncmp(offset, PRT_RESOURCE_ENCODING,
1901 (int)STRLEN(PRT_RESOURCE_ENCODING)) == 0) 1899 (int)STRLEN(PRT_RESOURCE_ENCODING)) == 0)
1908 semsg(_("E619: file \"%s\" is not a supported PostScript resource file"), 1906 semsg(_("E619: file \"%s\" is not a supported PostScript resource file"),
1909 resource->filename); 1907 resource->filename);
1910 return FALSE; 1908 return FALSE;
1911 } 1909 }
1912 1910
1913 /* Look for title and version of resource */ 1911 // Look for title and version of resource
1914 resource->title[0] = '\0'; 1912 resource->title[0] = '\0';
1915 resource->version[0] = '\0'; 1913 resource->version[0] = '\0';
1916 seen_title = FALSE; 1914 seen_title = FALSE;
1917 seen_version = FALSE; 1915 seen_version = FALSE;
1918 seen_all = FALSE; 1916 seen_all = FALSE;
1933 if (seen_title) 1931 if (seen_title)
1934 seen_all = TRUE; 1932 seen_all = TRUE;
1935 break; 1933 break;
1936 1934
1937 case PRT_DSC_ENDCOMMENTS_TYPE: 1935 case PRT_DSC_ENDCOMMENTS_TYPE:
1938 /* Wont find title or resource after this comment, stop searching */ 1936 // Wont find title or resource after this comment, stop searching
1939 seen_all = TRUE; 1937 seen_all = TRUE;
1940 break; 1938 break;
1941 1939
1942 case PRT_DSC_MISC_TYPE: 1940 case PRT_DSC_MISC_TYPE:
1943 /* Not interested in whatever comment this line had */ 1941 // Not interested in whatever comment this line had
1944 break; 1942 break;
1945 } 1943 }
1946 } 1944 }
1947 1945
1948 if (!seen_title || !seen_version) 1946 if (!seen_title || !seen_version)
1956 } 1954 }
1957 1955
1958 static int 1956 static int
1959 prt_check_resource(struct prt_ps_resource_S *resource, char_u *version) 1957 prt_check_resource(struct prt_ps_resource_S *resource, char_u *version)
1960 { 1958 {
1961 /* Version number m.n should match, the revision number does not matter */ 1959 // Version number m.n should match, the revision number does not matter
1962 if (STRNCMP(resource->version, version, STRLEN(version))) 1960 if (STRNCMP(resource->version, version, STRLEN(version)))
1963 { 1961 {
1964 semsg(_("E621: \"%s\" resource file has wrong version"), 1962 semsg(_("E621: \"%s\" resource file has wrong version"),
1965 resource->name); 1963 resource->name);
1966 return FALSE; 1964 return FALSE;
1967 } 1965 }
1968 1966
1969 /* Other checks to be added as needed */ 1967 // Other checks to be added as needed
1970 return TRUE; 1968 return TRUE;
1971 } 1969 }
1972 1970
1973 static void 1971 static void
1974 prt_dsc_start(void) 1972 prt_dsc_start(void)
1993 } 1991 }
1994 1992
1995 static void 1993 static void
1996 prt_dsc_text(char *comment, char *text) 1994 prt_dsc_text(char *comment, char *text)
1997 { 1995 {
1998 /* TODO - should scan 'text' for any chars needing escaping! */ 1996 // TODO - should scan 'text' for any chars needing escaping!
1999 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), 1997 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
2000 "%%%%%s: (%s)\n", comment, text); 1998 "%%%%%s: (%s)\n", comment, text);
2001 prt_write_file(prt_line_buffer); 1999 prt_write_file(prt_line_buffer);
2002 } 2000 }
2003 2001
2021 prt_write_string("\n"); 2019 prt_write_string("\n");
2022 } 2020 }
2023 2021
2024 static void 2022 static void
2025 prt_dsc_resources( 2023 prt_dsc_resources(
2026 char *comment, /* if NULL add to previous */ 2024 char *comment, // if NULL add to previous
2027 char *type, 2025 char *type,
2028 char *string) 2026 char *string)
2029 { 2027 {
2030 if (comment != NULL) 2028 if (comment != NULL)
2031 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), 2029 vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
2058 int tumble, 2056 int tumble,
2059 int collate, 2057 int collate,
2060 int color, 2058 int color,
2061 int num_copies) 2059 int num_copies)
2062 { 2060 {
2063 /* Only output the comment if we need to. 2061 // Only output the comment if we need to.
2064 * Note: tumble is ignored if we are not duplexing 2062 // Note: tumble is ignored if we are not duplexing
2065 */
2066 if (!(duplex || collate || color || (num_copies > 1))) 2063 if (!(duplex || collate || color || (num_copies > 1)))
2067 return; 2064 return;
2068 2065
2069 sprintf((char *)prt_line_buffer, "%%%%Requirements:"); 2066 sprintf((char *)prt_line_buffer, "%%%%Requirements:");
2070 prt_write_file(prt_line_buffer); 2067 prt_write_file(prt_line_buffer);
2080 if (color) 2077 if (color)
2081 prt_write_string(" color"); 2078 prt_write_string(" color");
2082 if (num_copies > 1) 2079 if (num_copies > 1)
2083 { 2080 {
2084 prt_write_string(" numcopies("); 2081 prt_write_string(" numcopies(");
2085 /* Note: no space wanted so don't use prt_write_int() */ 2082 // Note: no space wanted so don't use prt_write_int()
2086 sprintf((char *)prt_line_buffer, "%d", num_copies); 2083 sprintf((char *)prt_line_buffer, "%d", num_copies);
2087 prt_write_file(prt_line_buffer); 2084 prt_write_file(prt_line_buffer);
2088 prt_write_string(")"); 2085 prt_write_string(")");
2089 } 2086 }
2090 prt_write_string("\n"); 2087 prt_write_string("\n");
2122 { 2119 {
2123 if (prt_out_mbyte) 2120 if (prt_out_mbyte)
2124 { 2121 {
2125 int i; 2122 int i;
2126 2123
2127 /* Free off all CID font names created, but first clear duplicate 2124 // Free off all CID font names created, but first clear duplicate
2128 * pointers to the same string (when the same font is used for more than 2125 // pointers to the same string (when the same font is used for more than
2129 * one style). 2126 // one style).
2130 */
2131 for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) 2127 for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++)
2132 { 2128 {
2133 if (prt_ps_mb_font.ps_fontname[i] != NULL) 2129 if (prt_ps_mb_font.ps_fontname[i] != NULL)
2134 VIM_CLEAR(prt_ps_mb_font.ps_fontname[i]); 2130 VIM_CLEAR(prt_ps_mb_font.ps_fontname[i]);
2135 } 2131 }
2216 prt_get_cpl(void) 2212 prt_get_cpl(void)
2217 { 2213 {
2218 if (prt_use_number()) 2214 if (prt_use_number())
2219 { 2215 {
2220 prt_number_width = PRINT_NUMBER_WIDTH * prt_char_width; 2216 prt_number_width = PRINT_NUMBER_WIDTH * prt_char_width;
2221 /* If we are outputting multi-byte characters then line numbers will be 2217 // If we are outputting multi-byte characters then line numbers will be
2222 * printed with half width characters 2218 // printed with half width characters
2223 */
2224 if (prt_out_mbyte) 2219 if (prt_out_mbyte)
2225 prt_number_width /= 2; 2220 prt_number_width /= 2;
2226 prt_left_margin += prt_number_width; 2221 prt_left_margin += prt_number_width;
2227 } 2222 }
2228 else 2223 else
2265 prt_bgcol_offset -= (float)PRT_PS_FONT_TO_USER(prt_line_height, 2260 prt_bgcol_offset -= (float)PRT_PS_FONT_TO_USER(prt_line_height,
2266 (1000.0 - (prt_ps_font->bbox_max_y - 2261 (1000.0 - (prt_ps_font->bbox_max_y -
2267 prt_ps_font->bbox_min_y)) / 2); 2262 prt_ps_font->bbox_min_y)) / 2);
2268 } 2263 }
2269 2264
2270 /* Get height for topmost line based on background rect offset. */ 2265 // Get height for topmost line based on background rect offset.
2271 prt_first_line_height = prt_line_height + prt_bgcol_offset; 2266 prt_first_line_height = prt_line_height + prt_bgcol_offset;
2272 2267
2273 /* Calculate lpp */ 2268 // Calculate lpp
2274 lpp = (int)((prt_top_margin - prt_bottom_margin) / prt_line_height); 2269 lpp = (int)((prt_top_margin - prt_bottom_margin) / prt_line_height);
2275 2270
2276 /* Adjust top margin if there is a header */ 2271 // Adjust top margin if there is a header
2277 prt_top_margin -= prt_line_height * prt_header_height(); 2272 prt_top_margin -= prt_line_height * prt_header_height();
2278 2273
2279 return lpp - prt_header_height(); 2274 return lpp - prt_header_height();
2280 } 2275 }
2281 2276
2288 int mbenc; 2283 int mbenc;
2289 int enc_len; 2284 int enc_len;
2290 struct prt_ps_encoding_S *p_mbenc; 2285 struct prt_ps_encoding_S *p_mbenc;
2291 2286
2292 *pp_mbenc = NULL; 2287 *pp_mbenc = NULL;
2293 /* Look for recognised encoding */ 2288 // Look for recognised encoding
2294 enc_len = (int)STRLEN(p_encoding); 2289 enc_len = (int)STRLEN(p_encoding);
2295 p_mbenc = p_cmap->encodings; 2290 p_mbenc = p_cmap->encodings;
2296 for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++) 2291 for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++)
2297 { 2292 {
2298 if (STRNICMP(p_mbenc->encoding, p_encoding, enc_len) == 0) 2293 if (STRNICMP(p_mbenc->encoding, p_encoding, enc_len) == 0)
2313 { 2308 {
2314 int mbchar; 2309 int mbchar;
2315 int char_len; 2310 int char_len;
2316 struct prt_ps_charset_S *p_mbchar; 2311 struct prt_ps_charset_S *p_mbchar;
2317 2312
2318 /* Look for recognised character set, using default if one is not given */ 2313 // Look for recognised character set, using default if one is not given
2319 if (*p_charset == NUL) 2314 if (*p_charset == NUL)
2320 p_charset = p_cmap->defcs; 2315 p_charset = p_cmap->defcs;
2321 char_len = (int)STRLEN(p_charset); 2316 char_len = (int)STRLEN(p_charset);
2322 p_mbchar = p_cmap->charsets; 2317 p_mbchar = p_cmap->charsets;
2323 for (mbchar = 0; mbchar < p_cmap->num_charsets; mbchar++) 2318 for (mbchar = 0; mbchar < p_cmap->num_charsets; mbchar++)
2377 */ 2372 */
2378 p_encoding = enc_skip(p_penc); 2373 p_encoding = enc_skip(p_penc);
2379 if (*p_encoding == NUL) 2374 if (*p_encoding == NUL)
2380 p_encoding = enc_skip(p_enc); 2375 p_encoding = enc_skip(p_enc);
2381 2376
2382 /* Look for a multi-byte font that matches the encoding and character set. 2377 // Look for a multi-byte font that matches the encoding and character set.
2383 * Only look if multi-byte character set is defined, or using multi-byte 2378 // Only look if multi-byte character set is defined, or using multi-byte
2384 * encoding other than Unicode. This is because a Unicode encoding does not 2379 // encoding other than Unicode. This is because a Unicode encoding does not
2385 * uniquely identify a CJK character set to use. */ 2380 // uniquely identify a CJK character set to use.
2386 p_mbenc = NULL; 2381 p_mbenc = NULL;
2387 props = enc_canon_props(p_encoding); 2382 props = enc_canon_props(p_encoding);
2388 if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) 2383 if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE)))
2389 { 2384 {
2390 int cmap_first = 0; 2385 int cmap_first = 0;
2402 if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap], 2397 if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap],
2403 &p_mbchar)) 2398 &p_mbchar))
2404 break; 2399 break;
2405 } 2400 }
2406 2401
2407 /* Use first encoding matched if no charset matched */ 2402 // Use first encoding matched if no charset matched
2408 if (p_mbchar == NULL && p_mbenc_first != NULL) 2403 if (p_mbchar == NULL && p_mbenc_first != NULL)
2409 { 2404 {
2410 p_mbenc = p_mbenc_first; 2405 p_mbenc = p_mbenc_first;
2411 cmap = cmap_first; 2406 cmap = cmap_first;
2412 } 2407 }
2413 } 2408 }
2414 2409
2415 prt_out_mbyte = (p_mbenc != NULL); 2410 prt_out_mbyte = (p_mbenc != NULL);
2416 if (prt_out_mbyte) 2411 if (prt_out_mbyte)
2417 { 2412 {
2418 /* Build CMap name - will be same for all multi-byte fonts used */ 2413 // Build CMap name - will be same for all multi-byte fonts used
2419 prt_cmap[0] = NUL; 2414 prt_cmap[0] = NUL;
2420 2415
2421 prt_custom_cmap = (p_mbchar == NULL); 2416 prt_custom_cmap = (p_mbchar == NULL);
2422 if (!prt_custom_cmap) 2417 if (!prt_custom_cmap)
2423 { 2418 {
2424 /* Check encoding and character set are compatible */ 2419 // Check encoding and character set are compatible
2425 if ((p_mbenc->needs_charset & p_mbchar->has_charset) == 0) 2420 if ((p_mbenc->needs_charset & p_mbchar->has_charset) == 0)
2426 { 2421 {
2427 emsg(_("E673: Incompatible multi-byte encoding and character set.")); 2422 emsg(_("E673: Incompatible multi-byte encoding and character set."));
2428 return FALSE; 2423 return FALSE;
2429 } 2424 }
2430 2425
2431 /* Add charset name if not empty */ 2426 // Add charset name if not empty
2432 if (p_mbchar->cmap_charset != NULL) 2427 if (p_mbchar->cmap_charset != NULL)
2433 { 2428 {
2434 vim_strncpy((char_u *)prt_cmap, 2429 vim_strncpy((char_u *)prt_cmap,
2435 (char_u *)p_mbchar->cmap_charset, sizeof(prt_cmap) - 3); 2430 (char_u *)p_mbchar->cmap_charset, sizeof(prt_cmap) - 3);
2436 STRCAT(prt_cmap, "-"); 2431 STRCAT(prt_cmap, "-");
2437 } 2432 }
2438 } 2433 }
2439 else 2434 else
2440 { 2435 {
2441 /* Add custom CMap character set name */ 2436 // Add custom CMap character set name
2442 if (*p_pmcs == NUL) 2437 if (*p_pmcs == NUL)
2443 { 2438 {
2444 emsg(_("E674: printmbcharset cannot be empty with multi-byte encoding.")); 2439 emsg(_("E674: printmbcharset cannot be empty with multi-byte encoding."));
2445 return FALSE; 2440 return FALSE;
2446 } 2441 }
2447 vim_strncpy((char_u *)prt_cmap, p_pmcs, sizeof(prt_cmap) - 3); 2442 vim_strncpy((char_u *)prt_cmap, p_pmcs, sizeof(prt_cmap) - 3);
2448 STRCAT(prt_cmap, "-"); 2443 STRCAT(prt_cmap, "-");
2449 } 2444 }
2450 2445
2451 /* CMap name ends with (optional) encoding name and -H for horizontal */ 2446 // CMap name ends with (optional) encoding name and -H for horizontal
2452 if (p_mbenc->cmap_encoding != NULL && STRLEN(prt_cmap) 2447 if (p_mbenc->cmap_encoding != NULL && STRLEN(prt_cmap)
2453 + STRLEN(p_mbenc->cmap_encoding) + 3 < sizeof(prt_cmap)) 2448 + STRLEN(p_mbenc->cmap_encoding) + 3 < sizeof(prt_cmap))
2454 { 2449 {
2455 STRCAT(prt_cmap, p_mbenc->cmap_encoding); 2450 STRCAT(prt_cmap, p_mbenc->cmap_encoding);
2456 STRCAT(prt_cmap, "-"); 2451 STRCAT(prt_cmap, "-");
2461 { 2456 {
2462 emsg(_("E675: No default font specified for multi-byte printing.")); 2457 emsg(_("E675: No default font specified for multi-byte printing."));
2463 return FALSE; 2458 return FALSE;
2464 } 2459 }
2465 2460
2466 /* Derive CID font names with fallbacks if not defined */ 2461 // Derive CID font names with fallbacks if not defined
2467 if (!prt_build_cid_fontname(PRT_PS_FONT_ROMAN, 2462 if (!prt_build_cid_fontname(PRT_PS_FONT_ROMAN,
2468 mbfont_opts[OPT_MBFONT_REGULAR].string, 2463 mbfont_opts[OPT_MBFONT_REGULAR].string,
2469 mbfont_opts[OPT_MBFONT_REGULAR].strlen)) 2464 mbfont_opts[OPT_MBFONT_REGULAR].strlen))
2470 return FALSE; 2465 return FALSE;
2471 if (mbfont_opts[OPT_MBFONT_BOLD].present) 2466 if (mbfont_opts[OPT_MBFONT_BOLD].present)
2482 if (!prt_build_cid_fontname(PRT_PS_FONT_BOLDOBLIQUE, 2477 if (!prt_build_cid_fontname(PRT_PS_FONT_BOLDOBLIQUE,
2483 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].string, 2478 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].string,
2484 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen)) 2479 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen))
2485 return FALSE; 2480 return FALSE;
2486 2481
2487 /* Check if need to use Courier for ASCII code range, and if so pick up 2482 // Check if need to use Courier for ASCII code range, and if so pick up
2488 * the encoding to use */ 2483 // the encoding to use
2489 prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && 2484 prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present &&
2490 (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y'); 2485 (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y');
2491 if (prt_use_courier) 2486 if (prt_use_courier)
2492 { 2487 {
2493 /* Use national ASCII variant unless ASCII wanted */ 2488 // Use national ASCII variant unless ASCII wanted
2494 if (mbfont_opts[OPT_MBFONT_ASCII].present && 2489 if (mbfont_opts[OPT_MBFONT_ASCII].present &&
2495 (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) 2490 (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y'))
2496 prt_ascii_encoding = "ascii"; 2491 prt_ascii_encoding = "ascii";
2497 else 2492 else
2498 prt_ascii_encoding = prt_ps_mbfonts[cmap].ascii_enc; 2493 prt_ascii_encoding = prt_ps_mbfonts[cmap].ascii_enc;
2573 * generic print code. 2568 * generic print code.
2574 */ 2569 */
2575 psettings->chars_per_line = prt_get_cpl(); 2570 psettings->chars_per_line = prt_get_cpl();
2576 psettings->lines_per_page = prt_get_lpp(); 2571 psettings->lines_per_page = prt_get_lpp();
2577 2572
2578 /* Catch margin settings that leave no space for output! */ 2573 // Catch margin settings that leave no space for output!
2579 if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0) 2574 if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0)
2580 return FAIL; 2575 return FAIL;
2581 2576
2582 /* 2577 /*
2583 * Sort out the number of copies to be printed. PS by default will do 2578 * Sort out the number of copies to be printed. PS by default will do
2590 prt_num_copies = 1; 2585 prt_num_copies = 1;
2591 prt_collate = (!printer_opts[OPT_PRINT_COLLATE].present 2586 prt_collate = (!printer_opts[OPT_PRINT_COLLATE].present
2592 || TOLOWER_ASC(printer_opts[OPT_PRINT_COLLATE].string[0]) == 'y'); 2587 || TOLOWER_ASC(printer_opts[OPT_PRINT_COLLATE].string[0]) == 'y');
2593 if (prt_collate) 2588 if (prt_collate)
2594 { 2589 {
2595 /* TODO: Get number of collated copies wanted. */ 2590 // TODO: Get number of collated copies wanted.
2596 psettings->n_collated_copies = 1; 2591 psettings->n_collated_copies = 1;
2597 } 2592 }
2598 else 2593 else
2599 { 2594 {
2600 /* TODO: Get number of uncollated copies wanted and update the cached 2595 // TODO: Get number of uncollated copies wanted and update the cached
2601 * count. 2596 // count.
2602 */
2603 prt_num_copies = 1; 2597 prt_num_copies = 1;
2604 } 2598 }
2605 2599
2606 psettings->jobname = jobname; 2600 psettings->jobname = jobname;
2607 2601
2622 else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5) 2616 else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5)
2623 == 0) 2617 == 0)
2624 prt_tumble = TRUE; 2618 prt_tumble = TRUE;
2625 } 2619 }
2626 2620
2627 /* For now user abort not supported */ 2621 // For now user abort not supported
2628 psettings->user_abort = 0; 2622 psettings->user_abort = 0;
2629 2623
2630 /* If the user didn't specify a file name, use a temp file. */ 2624 // If the user didn't specify a file name, use a temp file.
2631 if (psettings->outfile == NULL) 2625 if (psettings->outfile == NULL)
2632 { 2626 {
2633 prt_ps_file_name = vim_tempname('p', TRUE); 2627 prt_ps_file_name = vim_tempname('p', TRUE);
2634 if (prt_ps_file_name == NULL) 2628 if (prt_ps_file_name == NULL)
2635 { 2629 {
2755 prt_dsc_textline("Title", (char *)psettings->jobname); 2749 prt_dsc_textline("Title", (char *)psettings->jobname);
2756 if (!get_user_name((char_u *)buffer, 256)) 2750 if (!get_user_name((char_u *)buffer, 256))
2757 STRCPY(buffer, "Unknown"); 2751 STRCPY(buffer, "Unknown");
2758 prt_dsc_textline("For", buffer); 2752 prt_dsc_textline("For", buffer);
2759 prt_dsc_textline("Creator", VIM_VERSION_LONG); 2753 prt_dsc_textline("Creator", VIM_VERSION_LONG);
2760 /* Note: to ensure Clean8bit I don't think we can use LC_TIME */ 2754 // Note: to ensure Clean8bit I don't think we can use LC_TIME
2761 2755
2762 prt_dsc_textline("CreationDate", get_ctime(time(NULL), FALSE)); 2756 prt_dsc_textline("CreationDate", get_ctime(time(NULL), FALSE));
2763 prt_dsc_textline("DocumentData", "Clean8Bit"); 2757 prt_dsc_textline("DocumentData", "Clean8Bit");
2764 prt_dsc_textline("Orientation", "Portrait"); 2758 prt_dsc_textline("Orientation", "Portrait");
2765 prt_dsc_atend("Pages"); 2759 prt_dsc_atend("Pages");
2766 prt_dsc_textline("PageOrder", "Ascend"); 2760 prt_dsc_textline("PageOrder", "Ascend");
2767 /* The bbox does not change with orientation - it is always in the default 2761 // The bbox does not change with orientation - it is always in the default
2768 * user coordinate system! We have to recalculate right and bottom 2762 // user coordinate system! We have to recalculate right and bottom
2769 * coordinates based on the font metrics for the bbox to be accurate. */ 2763 // coordinates based on the font metrics for the bbox to be accurate.
2770 prt_page_margins(prt_mediasize[prt_media].width, 2764 prt_page_margins(prt_mediasize[prt_media].width,
2771 prt_mediasize[prt_media].height, 2765 prt_mediasize[prt_media].height,
2772 &left, &right, &top, &bottom); 2766 &left, &right, &top, &bottom);
2773 bbox[0] = (int)left; 2767 bbox[0] = (int)left;
2774 if (prt_portrait) 2768 if (prt_portrait)
2775 { 2769 {
2776 /* In portrait printing the fixed point is the top left corner so we 2770 // In portrait printing the fixed point is the top left corner so we
2777 * derive the bbox from that point. We have the expected cpl chars 2771 // derive the bbox from that point. We have the expected cpl chars
2778 * across the media and lpp lines down the media. 2772 // across the media and lpp lines down the media.
2779 */
2780 bbox[1] = (int)(top - (psettings->lines_per_page + prt_header_height()) 2773 bbox[1] = (int)(top - (psettings->lines_per_page + prt_header_height())
2781 * prt_line_height); 2774 * prt_line_height);
2782 bbox[2] = (int)(left + psettings->chars_per_line * prt_char_width 2775 bbox[2] = (int)(left + psettings->chars_per_line * prt_char_width
2783 + 0.5); 2776 + 0.5);
2784 bbox[3] = (int)(top + 0.5); 2777 bbox[3] = (int)(top + 0.5);
2785 } 2778 }
2786 else 2779 else
2787 { 2780 {
2788 /* In landscape printing the fixed point is the bottom left corner so we 2781 // In landscape printing the fixed point is the bottom left corner so we
2789 * derive the bbox from that point. We have lpp chars across the media 2782 // derive the bbox from that point. We have lpp chars across the media
2790 * and cpl lines up the media. 2783 // and cpl lines up the media.
2791 */
2792 bbox[1] = (int)bottom; 2784 bbox[1] = (int)bottom;
2793 bbox[2] = (int)(left + ((psettings->lines_per_page 2785 bbox[2] = (int)(left + ((psettings->lines_per_page
2794 + prt_header_height()) * prt_line_height) + 0.5); 2786 + prt_header_height()) * prt_line_height) + 0.5);
2795 bbox[3] = (int)(bottom + psettings->chars_per_line * prt_char_width 2787 bbox[3] = (int)(bottom + psettings->chars_per_line * prt_char_width
2796 + 0.5); 2788 + 0.5);
2797 } 2789 }
2798 prt_dsc_ints("BoundingBox", 4, bbox); 2790 prt_dsc_ints("BoundingBox", 4, bbox);
2799 /* The media width and height does not change with landscape printing! */ 2791 // The media width and height does not change with landscape printing!
2800 prt_dsc_docmedia(prt_mediasize[prt_media].name, 2792 prt_dsc_docmedia(prt_mediasize[prt_media].name,
2801 prt_mediasize[prt_media].width, 2793 prt_mediasize[prt_media].width,
2802 prt_mediasize[prt_media].height, 2794 prt_mediasize[prt_media].height,
2803 (double)0, NULL, NULL); 2795 (double)0, NULL, NULL);
2804 /* Define fonts needed */ 2796 // Define fonts needed
2805 if (!prt_out_mbyte || prt_use_courier) 2797 if (!prt_out_mbyte || prt_use_courier)
2806 prt_dsc_font_resource("DocumentNeededResources", &prt_ps_courier_font); 2798 prt_dsc_font_resource("DocumentNeededResources", &prt_ps_courier_font);
2807 if (prt_out_mbyte) 2799 if (prt_out_mbyte)
2808 { 2800 {
2809 prt_dsc_font_resource((prt_use_courier ? NULL 2801 prt_dsc_font_resource((prt_use_courier ? NULL
2810 : "DocumentNeededResources"), &prt_ps_mb_font); 2802 : "DocumentNeededResources"), &prt_ps_mb_font);
2811 if (!prt_custom_cmap) 2803 if (!prt_custom_cmap)
2812 prt_dsc_resources(NULL, "cmap", prt_cmap); 2804 prt_dsc_resources(NULL, "cmap", prt_cmap);
2813 } 2805 }
2814 2806
2815 /* Search for external resources VIM supplies */ 2807 // Search for external resources VIM supplies
2816 if (!prt_find_resource("prolog", res_prolog)) 2808 if (!prt_find_resource("prolog", res_prolog))
2817 { 2809 {
2818 emsg(_("E456: Can't find PostScript resource file \"prolog.ps\"")); 2810 emsg(_("E456: Can't find PostScript resource file \"prolog.ps\""));
2819 goto theend; 2811 goto theend;
2820 } 2812 }
2822 goto theend; 2814 goto theend;
2823 if (!prt_check_resource(res_prolog, PRT_PROLOG_VERSION)) 2815 if (!prt_check_resource(res_prolog, PRT_PROLOG_VERSION))
2824 goto theend; 2816 goto theend;
2825 if (prt_out_mbyte) 2817 if (prt_out_mbyte)
2826 { 2818 {
2827 /* Look for required version of multi-byte printing procset */ 2819 // Look for required version of multi-byte printing procset
2828 if (!prt_find_resource("cidfont", res_cidfont)) 2820 if (!prt_find_resource("cidfont", res_cidfont))
2829 { 2821 {
2830 emsg(_("E456: Can't find PostScript resource file \"cidfont.ps\"")); 2822 emsg(_("E456: Can't find PostScript resource file \"cidfont.ps\""));
2831 goto theend; 2823 goto theend;
2832 } 2824 }
2834 goto theend; 2826 goto theend;
2835 if (!prt_check_resource(res_cidfont, PRT_CID_PROLOG_VERSION)) 2827 if (!prt_check_resource(res_cidfont, PRT_CID_PROLOG_VERSION))
2836 goto theend; 2828 goto theend;
2837 } 2829 }
2838 2830
2839 /* Find an encoding to use for printing. 2831 // Find an encoding to use for printing.
2840 * Check 'printencoding'. If not set or not found, then use 'encoding'. If 2832 // Check 'printencoding'. If not set or not found, then use 'encoding'. If
2841 * that cannot be found then default to "latin1". 2833 // that cannot be found then default to "latin1".
2842 * Note: VIM specific encoding header is always skipped. 2834 // Note: VIM specific encoding header is always skipped.
2843 */
2844 if (!prt_out_mbyte) 2835 if (!prt_out_mbyte)
2845 { 2836 {
2846 p_encoding = enc_skip(p_penc); 2837 p_encoding = enc_skip(p_penc);
2847 if (*p_encoding == NUL 2838 if (*p_encoding == NUL
2848 || !prt_find_resource((char *)p_encoding, res_encoding)) 2839 || !prt_find_resource((char *)p_encoding, res_encoding))
2849 { 2840 {
2850 /* 'printencoding' not set or not supported - find alternate */ 2841 // 'printencoding' not set or not supported - find alternate
2851 int props; 2842 int props;
2852 2843
2853 p_encoding = enc_skip(p_enc); 2844 p_encoding = enc_skip(p_enc);
2854 props = enc_canon_props(p_encoding); 2845 props = enc_canon_props(p_encoding);
2855 if (!(props & ENC_8BIT) 2846 if (!(props & ENC_8BIT)
2856 || !prt_find_resource((char *)p_encoding, res_encoding)) 2847 || !prt_find_resource((char *)p_encoding, res_encoding))
2857 /* 8-bit 'encoding' is not supported */ 2848 // 8-bit 'encoding' is not supported
2858 { 2849 {
2859 /* Use latin1 as default printing encoding */ 2850 // Use latin1 as default printing encoding
2860 p_encoding = (char_u *)"latin1"; 2851 p_encoding = (char_u *)"latin1";
2861 if (!prt_find_resource((char *)p_encoding, res_encoding)) 2852 if (!prt_find_resource((char *)p_encoding, res_encoding))
2862 { 2853 {
2863 semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), 2854 semsg(_("E456: Can't find PostScript resource file \"%s.ps\""),
2864 p_encoding); 2855 p_encoding);
2866 } 2857 }
2867 } 2858 }
2868 } 2859 }
2869 if (!prt_open_resource(res_encoding)) 2860 if (!prt_open_resource(res_encoding))
2870 goto theend; 2861 goto theend;
2871 /* For the moment there are no checks on encoding resource files to 2862 // For the moment there are no checks on encoding resource files to
2872 * perform */ 2863 // perform
2873 } 2864 }
2874 else 2865 else
2875 { 2866 {
2876 p_encoding = enc_skip(p_penc); 2867 p_encoding = enc_skip(p_penc);
2877 if (*p_encoding == NUL) 2868 if (*p_encoding == NUL)
2878 p_encoding = enc_skip(p_enc); 2869 p_encoding = enc_skip(p_enc);
2879 if (prt_use_courier) 2870 if (prt_use_courier)
2880 { 2871 {
2881 /* Include ASCII range encoding vector */ 2872 // Include ASCII range encoding vector
2882 if (!prt_find_resource(prt_ascii_encoding, res_encoding)) 2873 if (!prt_find_resource(prt_ascii_encoding, res_encoding))
2883 { 2874 {
2884 semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), 2875 semsg(_("E456: Can't find PostScript resource file \"%s.ps\""),
2885 prt_ascii_encoding); 2876 prt_ascii_encoding);
2886 goto theend; 2877 goto theend;
2887 } 2878 }
2888 if (!prt_open_resource(res_encoding)) 2879 if (!prt_open_resource(res_encoding))
2889 goto theend; 2880 goto theend;
2890 /* For the moment there are no checks on encoding resource files to 2881 // For the moment there are no checks on encoding resource files to
2891 * perform */ 2882 // perform
2892 } 2883 }
2893 } 2884 }
2894 2885
2895 prt_conv.vc_type = CONV_NONE; 2886 prt_conv.vc_type = CONV_NONE;
2896 if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { 2887 if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) {
2897 /* Set up encoding conversion if required */ 2888 // Set up encoding conversion if required
2898 if (FAIL == convert_setup(&prt_conv, p_enc, p_encoding)) 2889 if (FAIL == convert_setup(&prt_conv, p_enc, p_encoding))
2899 { 2890 {
2900 semsg(_("E620: Unable to convert to print encoding \"%s\""), 2891 semsg(_("E620: Unable to convert to print encoding \"%s\""),
2901 p_encoding); 2892 p_encoding);
2902 goto theend; 2893 goto theend;
2905 } 2896 }
2906 prt_do_conv = prt_conv.vc_type != CONV_NONE; 2897 prt_do_conv = prt_conv.vc_type != CONV_NONE;
2907 2898
2908 if (prt_out_mbyte && prt_custom_cmap) 2899 if (prt_out_mbyte && prt_custom_cmap)
2909 { 2900 {
2910 /* Find user supplied CMap */ 2901 // Find user supplied CMap
2911 if (!prt_find_resource(prt_cmap, res_cmap)) 2902 if (!prt_find_resource(prt_cmap, res_cmap))
2912 { 2903 {
2913 semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), 2904 semsg(_("E456: Can't find PostScript resource file \"%s.ps\""),
2914 prt_cmap); 2905 prt_cmap);
2915 goto theend; 2906 goto theend;
2916 } 2907 }
2917 if (!prt_open_resource(res_cmap)) 2908 if (!prt_open_resource(res_cmap))
2918 goto theend; 2909 goto theend;
2919 } 2910 }
2920 2911
2921 /* List resources supplied */ 2912 // List resources supplied
2922 STRCPY(buffer, res_prolog->title); 2913 STRCPY(buffer, res_prolog->title);
2923 STRCAT(buffer, " "); 2914 STRCAT(buffer, " ");
2924 STRCAT(buffer, res_prolog->version); 2915 STRCAT(buffer, res_prolog->version);
2925 prt_dsc_resources("DocumentSuppliedResources", "procset", buffer); 2916 prt_dsc_resources("DocumentSuppliedResources", "procset", buffer);
2926 if (prt_out_mbyte) 2917 if (prt_out_mbyte)
2957 /* 2948 /*
2958 * PS Document page defaults 2949 * PS Document page defaults
2959 */ 2950 */
2960 prt_dsc_noarg("BeginDefaults"); 2951 prt_dsc_noarg("BeginDefaults");
2961 2952
2962 /* List font resources most likely common to all pages */ 2953 // List font resources most likely common to all pages
2963 if (!prt_out_mbyte || prt_use_courier) 2954 if (!prt_out_mbyte || prt_use_courier)
2964 prt_dsc_font_resource("PageResources", &prt_ps_courier_font); 2955 prt_dsc_font_resource("PageResources", &prt_ps_courier_font);
2965 if (prt_out_mbyte) 2956 if (prt_out_mbyte)
2966 { 2957 {
2967 prt_dsc_font_resource((prt_use_courier ? NULL : "PageResources"), 2958 prt_dsc_font_resource((prt_use_courier ? NULL : "PageResources"),
2968 &prt_ps_mb_font); 2959 &prt_ps_mb_font);
2969 if (!prt_custom_cmap) 2960 if (!prt_custom_cmap)
2970 prt_dsc_resources(NULL, "cmap", prt_cmap); 2961 prt_dsc_resources(NULL, "cmap", prt_cmap);
2971 } 2962 }
2972 2963
2973 /* Paper will be used for all pages */ 2964 // Paper will be used for all pages
2974 prt_dsc_textline("PageMedia", prt_mediasize[prt_media].name); 2965 prt_dsc_textline("PageMedia", prt_mediasize[prt_media].name);
2975 2966
2976 prt_dsc_noarg("EndDefaults"); 2967 prt_dsc_noarg("EndDefaults");
2977 2968
2978 /* 2969 /*
2979 * PS Document prolog inclusion - all required procsets. 2970 * PS Document prolog inclusion - all required procsets.
2980 */ 2971 */
2981 prt_dsc_noarg("BeginProlog"); 2972 prt_dsc_noarg("BeginProlog");
2982 2973
2983 /* Add required procsets - NOTE: order is important! */ 2974 // Add required procsets - NOTE: order is important!
2984 if (!prt_add_resource(res_prolog)) 2975 if (!prt_add_resource(res_prolog))
2985 goto theend; 2976 goto theend;
2986 if (prt_out_mbyte) 2977 if (prt_out_mbyte)
2987 { 2978 {
2988 /* Add CID font procset, and any user supplied CMap */ 2979 // Add CID font procset, and any user supplied CMap
2989 if (!prt_add_resource(res_cidfont)) 2980 if (!prt_add_resource(res_cidfont))
2990 goto theend; 2981 goto theend;
2991 if (prt_custom_cmap && !prt_add_resource(res_cmap)) 2982 if (prt_custom_cmap && !prt_add_resource(res_cmap))
2992 goto theend; 2983 goto theend;
2993 } 2984 }
2994 2985
2995 if (!prt_out_mbyte || prt_use_courier) 2986 if (!prt_out_mbyte || prt_use_courier)
2996 /* There will be only one Roman font encoding to be included in the PS 2987 // There will be only one Roman font encoding to be included in the PS
2997 * file. */ 2988 // file.
2998 if (!prt_add_resource(res_encoding)) 2989 if (!prt_add_resource(res_encoding))
2999 goto theend; 2990 goto theend;
3000 2991
3001 prt_dsc_noarg("EndProlog"); 2992 prt_dsc_noarg("EndProlog");
3002 2993
3003 /* 2994 /*
3004 * PS Document setup - must appear after the prolog 2995 * PS Document setup - must appear after the prolog
3005 */ 2996 */
3006 prt_dsc_noarg("BeginSetup"); 2997 prt_dsc_noarg("BeginSetup");
3007 2998
3008 /* Device setup - page size and number of uncollated copies */ 2999 // Device setup - page size and number of uncollated copies
3009 prt_write_int((int)prt_mediasize[prt_media].width); 3000 prt_write_int((int)prt_mediasize[prt_media].width);
3010 prt_write_int((int)prt_mediasize[prt_media].height); 3001 prt_write_int((int)prt_mediasize[prt_media].height);
3011 prt_write_int(0); 3002 prt_write_int(0);
3012 prt_write_string("sps\n"); 3003 prt_write_string("sps\n");
3013 prt_write_int(prt_num_copies); 3004 prt_write_int(prt_num_copies);
3016 prt_write_boolean(prt_tumble); 3007 prt_write_boolean(prt_tumble);
3017 prt_write_string("dt\n"); 3008 prt_write_string("dt\n");
3018 prt_write_boolean(prt_collate); 3009 prt_write_boolean(prt_collate);
3019 prt_write_string("c\n"); 3010 prt_write_string("c\n");
3020 3011
3021 /* Font resource inclusion and definition */ 3012 // Font resource inclusion and definition
3022 if (!prt_out_mbyte || prt_use_courier) 3013 if (!prt_out_mbyte || prt_use_courier)
3023 { 3014 {
3024 /* When using Courier for ASCII range when printing multi-byte, need to 3015 // When using Courier for ASCII range when printing multi-byte, need to
3025 * pick up ASCII encoding to use with it. */ 3016 // pick up ASCII encoding to use with it.
3026 if (prt_use_courier) 3017 if (prt_use_courier)
3027 p_encoding = (char_u *)prt_ascii_encoding; 3018 p_encoding = (char_u *)prt_ascii_encoding;
3028 prt_dsc_resources("IncludeResource", "font", 3019 prt_dsc_resources("IncludeResource", "font",
3029 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); 3020 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]);
3030 prt_def_font("F0", (char *)p_encoding, (int)prt_line_height, 3021 prt_def_font("F0", (char *)p_encoding, (int)prt_line_height,
3042 prt_def_font("F3", (char *)p_encoding, (int)prt_line_height, 3033 prt_def_font("F3", (char *)p_encoding, (int)prt_line_height,
3043 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); 3034 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
3044 } 3035 }
3045 if (prt_out_mbyte) 3036 if (prt_out_mbyte)
3046 { 3037 {
3047 /* Define the CID fonts to be used in the job. Typically CJKV fonts do 3038 // Define the CID fonts to be used in the job. Typically CJKV fonts do
3048 * not have an italic form being a western style, so where no font is 3039 // not have an italic form being a western style, so where no font is
3049 * defined for these faces VIM falls back to an existing face. 3040 // defined for these faces VIM falls back to an existing face.
3050 * Note: if using Courier for the ASCII range then the printout will 3041 // Note: if using Courier for the ASCII range then the printout will
3051 * have bold/italic/bolditalic regardless of the setting of printmbfont. 3042 // have bold/italic/bolditalic regardless of the setting of printmbfont.
3052 */
3053 prt_dsc_resources("IncludeResource", "font", 3043 prt_dsc_resources("IncludeResource", "font",
3054 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); 3044 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]);
3055 if (!prt_custom_cmap) 3045 if (!prt_custom_cmap)
3056 prt_dsc_resources("IncludeResource", "cmap", prt_cmap); 3046 prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
3057 prt_def_cidfont("CF0", (int)prt_line_height, 3047 prt_def_cidfont("CF0", (int)prt_line_height,
3065 prt_dsc_resources("IncludeResource", "cmap", prt_cmap); 3055 prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
3066 prt_def_cidfont("CF1", (int)prt_line_height, 3056 prt_def_cidfont("CF1", (int)prt_line_height,
3067 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); 3057 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]);
3068 } 3058 }
3069 else 3059 else
3070 /* Use ROMAN for BOLD */ 3060 // Use ROMAN for BOLD
3071 prt_dup_cidfont("CF0", "CF1"); 3061 prt_dup_cidfont("CF0", "CF1");
3072 3062
3073 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL) 3063 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL)
3074 { 3064 {
3075 prt_dsc_resources("IncludeResource", "font", 3065 prt_dsc_resources("IncludeResource", "font",
3078 prt_dsc_resources("IncludeResource", "cmap", prt_cmap); 3068 prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
3079 prt_def_cidfont("CF2", (int)prt_line_height, 3069 prt_def_cidfont("CF2", (int)prt_line_height,
3080 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); 3070 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
3081 } 3071 }
3082 else 3072 else
3083 /* Use ROMAN for OBLIQUE */ 3073 // Use ROMAN for OBLIQUE
3084 prt_dup_cidfont("CF0", "CF2"); 3074 prt_dup_cidfont("CF0", "CF2");
3085 3075
3086 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL) 3076 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL)
3087 { 3077 {
3088 prt_dsc_resources("IncludeResource", "font", 3078 prt_dsc_resources("IncludeResource", "font",
3091 prt_dsc_resources("IncludeResource", "cmap", prt_cmap); 3081 prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
3092 prt_def_cidfont("CF3", (int)prt_line_height, 3082 prt_def_cidfont("CF3", (int)prt_line_height,
3093 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); 3083 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
3094 } 3084 }
3095 else 3085 else
3096 /* Use BOLD for BOLDOBLIQUE */ 3086 // Use BOLD for BOLDOBLIQUE
3097 prt_dup_cidfont("CF1", "CF3"); 3087 prt_dup_cidfont("CF1", "CF3");
3098 } 3088 }
3099 3089
3100 /* Misc constant vars used for underlining and background rects */ 3090 // Misc constant vars used for underlining and background rects
3101 prt_def_var("UO", PRT_PS_FONT_TO_USER(prt_line_height, 3091 prt_def_var("UO", PRT_PS_FONT_TO_USER(prt_line_height,
3102 prt_ps_font->uline_offset), 2); 3092 prt_ps_font->uline_offset), 2);
3103 prt_def_var("UW", PRT_PS_FONT_TO_USER(prt_line_height, 3093 prt_def_var("UW", PRT_PS_FONT_TO_USER(prt_line_height,
3104 prt_ps_font->uline_width), 2); 3094 prt_ps_font->uline_width), 2);
3105 prt_def_var("BO", prt_bgcol_offset, 2); 3095 prt_def_var("BO", prt_bgcol_offset, 2);
3106 3096
3107 prt_dsc_noarg("EndSetup"); 3097 prt_dsc_noarg("EndSetup");
3108 3098
3109 /* Fail if any problems writing out to the PS file */ 3099 // Fail if any problems writing out to the PS file
3110 retval = !prt_file_error; 3100 retval = !prt_file_error;
3111 3101
3112 theend: 3102 theend:
3113 vim_free(res_prolog); 3103 vim_free(res_prolog);
3114 vim_free(res_encoding); 3104 vim_free(res_encoding);
3128 */ 3118 */
3129 prt_dsc_ints("Pages", 1, &prt_page_num); 3119 prt_dsc_ints("Pages", 1, &prt_page_num);
3130 3120
3131 prt_dsc_noarg("EOF"); 3121 prt_dsc_noarg("EOF");
3132 3122
3133 /* Write CTRL-D to close serial communication link if used. 3123 // Write CTRL-D to close serial communication link if used.
3134 * NOTHING MUST BE WRITTEN AFTER THIS! */ 3124 // NOTHING MUST BE WRITTEN AFTER THIS!
3135 prt_write_file((char_u *)IF_EB("\004", "\067")); 3125 prt_write_file((char_u *)IF_EB("\004", "\067"));
3136 3126
3137 if (!prt_file_error && psettings->outfile == NULL 3127 if (!prt_file_error && psettings->outfile == NULL
3138 && !got_int && !psettings->user_abort) 3128 && !got_int && !psettings->user_abort)
3139 { 3129 {
3140 /* Close the file first. */ 3130 // Close the file first.
3141 if (prt_ps_fd != NULL) 3131 if (prt_ps_fd != NULL)
3142 { 3132 {
3143 fclose(prt_ps_fd); 3133 fclose(prt_ps_fd);
3144 prt_ps_fd = NULL; 3134 prt_ps_fd = NULL;
3145 } 3135 }
3146 prt_message((char_u *)_("Sending to printer...")); 3136 prt_message((char_u *)_("Sending to printer..."));
3147 3137
3148 /* Not printing to a file: use 'printexpr' to print the file. */ 3138 // Not printing to a file: use 'printexpr' to print the file.
3149 if (eval_printexpr(prt_ps_file_name, psettings->arguments) == FAIL) 3139 if (eval_printexpr(prt_ps_file_name, psettings->arguments) == FAIL)
3150 emsg(_("E365: Failed to print PostScript file")); 3140 emsg(_("E365: Failed to print PostScript file"));
3151 else 3141 else
3152 prt_message((char_u *)_("Print job sent.")); 3142 prt_message((char_u *)_("Print job sent."));
3153 } 3143 }
3187 prt_write_string("F0 sf\n"); 3177 prt_write_string("F0 sf\n");
3188 prt_fgcol = PRCOLOR_BLACK; 3178 prt_fgcol = PRCOLOR_BLACK;
3189 prt_bgcol = PRCOLOR_WHITE; 3179 prt_bgcol = PRCOLOR_WHITE;
3190 prt_font = PRT_PS_FONT_ROMAN; 3180 prt_font = PRT_PS_FONT_ROMAN;
3191 3181
3192 /* Set up page transformation for landscape printing. */ 3182 // Set up page transformation for landscape printing.
3193 if (!prt_portrait) 3183 if (!prt_portrait)
3194 { 3184 {
3195 prt_write_int(-((int)prt_mediasize[prt_media].width)); 3185 prt_write_int(-((int)prt_mediasize[prt_media].width));
3196 prt_write_string("sl\n"); 3186 prt_write_string("sl\n");
3197 } 3187 }
3198 3188
3199 prt_dsc_noarg("EndPageSetup"); 3189 prt_dsc_noarg("EndPageSetup");
3200 3190
3201 /* We have reset the font attributes, force setting them again. */ 3191 // We have reset the font attributes, force setting them again.
3202 curr_bg = (long_u)0xffffffff; 3192 curr_bg = (long_u)0xffffffff;
3203 curr_fg = (long_u)0xffffffff; 3193 curr_fg = (long_u)0xffffffff;
3204 curr_bold = MAYBE; 3194 curr_bold = MAYBE;
3205 3195
3206 return !prt_file_error; 3196 return !prt_file_error;
3243 int half_width; 3233 int half_width;
3244 char_u *tofree = NULL; 3234 char_u *tofree = NULL;
3245 3235
3246 char_width = prt_char_width; 3236 char_width = prt_char_width;
3247 3237
3248 /* Ideally VIM would create a rearranged CID font to combine a Roman and 3238 // Ideally VIM would create a rearranged CID font to combine a Roman and
3249 * CJKV font to do what VIM is doing here - use a Roman font for characters 3239 // CJKV font to do what VIM is doing here - use a Roman font for characters
3250 * in the ASCII range, and the original CID font for everything else. 3240 // in the ASCII range, and the original CID font for everything else.
3251 * The problem is that GhostScript still (as of 8.13) does not support 3241 // The problem is that GhostScript still (as of 8.13) does not support
3252 * rearranged fonts even though they have been documented by Adobe for 7 3242 // rearranged fonts even though they have been documented by Adobe for 7
3253 * years! If they ever do, a lot of this code will disappear. 3243 // years! If they ever do, a lot of this code will disappear.
3254 */
3255 if (prt_use_courier) 3244 if (prt_use_courier)
3256 { 3245 {
3257 in_ascii = (len == 1 && *p < 0x80); 3246 in_ascii = (len == 1 && *p < 0x80);
3258 if (prt_in_ascii) 3247 if (prt_in_ascii)
3259 { 3248 {
3260 if (!in_ascii) 3249 if (!in_ascii)
3261 { 3250 {
3262 /* No longer in ASCII range - need to switch font */ 3251 // No longer in ASCII range - need to switch font
3263 prt_in_ascii = FALSE; 3252 prt_in_ascii = FALSE;
3264 prt_need_font = TRUE; 3253 prt_need_font = TRUE;
3265 prt_attribute_change = TRUE; 3254 prt_attribute_change = TRUE;
3266 } 3255 }
3267 } 3256 }
3268 else if (in_ascii) 3257 else if (in_ascii)
3269 { 3258 {
3270 /* Now in ASCII range - need to switch font */ 3259 // Now in ASCII range - need to switch font
3271 prt_in_ascii = TRUE; 3260 prt_in_ascii = TRUE;
3272 prt_need_font = TRUE; 3261 prt_need_font = TRUE;
3273 prt_attribute_change = TRUE; 3262 prt_attribute_change = TRUE;
3274 } 3263 }
3275 } 3264 }
3295 prt_need_moveto = TRUE; 3284 prt_need_moveto = TRUE;
3296 prt_attribute_change = TRUE; 3285 prt_attribute_change = TRUE;
3297 } 3286 }
3298 } 3287 }
3299 3288
3300 /* Output any required changes to the graphics state, after flushing any 3289 // Output any required changes to the graphics state, after flushing any
3301 * text buffered so far. 3290 // text buffered so far.
3302 */
3303 if (prt_attribute_change) 3291 if (prt_attribute_change)
3304 { 3292 {
3305 prt_flush_buffer(); 3293 prt_flush_buffer();
3306 /* Reset count of number of chars that will be printed */ 3294 // Reset count of number of chars that will be printed
3307 prt_text_run = 0; 3295 prt_text_run = 0;
3308 3296
3309 if (prt_need_moveto) 3297 if (prt_need_moveto)
3310 { 3298 {
3311 prt_pos_x_moveto = prt_pos_x; 3299 prt_pos_x_moveto = prt_pos_x;
3360 prt_attribute_change = FALSE; 3348 prt_attribute_change = FALSE;
3361 } 3349 }
3362 3350
3363 if (prt_do_conv) 3351 if (prt_do_conv)
3364 { 3352 {
3365 /* Convert from multi-byte to 8-bit encoding */ 3353 // Convert from multi-byte to 8-bit encoding
3366 tofree = p = string_convert(&prt_conv, p, &len); 3354 tofree = p = string_convert(&prt_conv, p, &len);
3367 if (p == NULL) 3355 if (p == NULL)
3368 { 3356 {
3369 p = (char_u *)""; 3357 p = (char_u *)"";
3370 len = 0; 3358 len = 0;
3371 } 3359 }
3372 } 3360 }
3373 3361
3374 if (prt_out_mbyte) 3362 if (prt_out_mbyte)
3375 { 3363 {
3376 /* Multi-byte character strings are represented more efficiently as hex 3364 // Multi-byte character strings are represented more efficiently as hex
3377 * strings when outputting clean 8 bit PS. 3365 // strings when outputting clean 8 bit PS.
3378 */
3379 while (len-- > 0) 3366 while (len-- > 0)
3380 { 3367 {
3381 ch = prt_hexchar[(unsigned)(*p) >> 4]; 3368 ch = prt_hexchar[(unsigned)(*p) >> 4];
3382 ga_append(&prt_ps_buffer, ch); 3369 ga_append(&prt_ps_buffer, ch);
3383 ch = prt_hexchar[(*p) & 0xf]; 3370 ch = prt_hexchar[(*p) & 0xf];
3385 p++; 3372 p++;
3386 } 3373 }
3387 } 3374 }
3388 else 3375 else
3389 { 3376 {
3390 /* Add next character to buffer of characters to output. 3377 // Add next character to buffer of characters to output.
3391 * Note: One printed character may require several PS characters to 3378 // Note: One printed character may require several PS characters to
3392 * represent it, but we only count them as one printed character. 3379 // represent it, but we only count them as one printed character.
3393 */
3394 ch = *p; 3380 ch = *p;
3395 if (ch < 32 || ch == '(' || ch == ')' || ch == '\\') 3381 if (ch < 32 || ch == '(' || ch == ')' || ch == '\\')
3396 { 3382 {
3397 /* Convert non-printing characters to either their escape or octal 3383 // Convert non-printing characters to either their escape or octal
3398 * sequence, ensures PS sent over a serial line does not interfere 3384 // sequence, ensures PS sent over a serial line does not interfere
3399 * with the comms protocol. Note: For EBCDIC we need to write out 3385 // with the comms protocol. Note: For EBCDIC we need to write out
3400 * the escape sequences as ASCII codes! 3386 // the escape sequences as ASCII codes!
3401 * Note 2: Char codes < 32 are identical in EBCDIC and ASCII AFAIK! 3387 // Note 2: Char codes < 32 are identical in EBCDIC and ASCII AFAIK!
3402 */
3403 ga_append(&prt_ps_buffer, IF_EB('\\', 0134)); 3388 ga_append(&prt_ps_buffer, IF_EB('\\', 0134));
3404 switch (ch) 3389 switch (ch)
3405 { 3390 {
3406 case BS: ga_append(&prt_ps_buffer, IF_EB('b', 0142)); break; 3391 case BS: ga_append(&prt_ps_buffer, IF_EB('b', 0142)); break;
3407 case TAB: ga_append(&prt_ps_buffer, IF_EB('t', 0164)); break; 3392 case TAB: ga_append(&prt_ps_buffer, IF_EB('t', 0164)); break;
3425 } 3410 }
3426 else 3411 else
3427 ga_append(&prt_ps_buffer, ch); 3412 ga_append(&prt_ps_buffer, ch);
3428 } 3413 }
3429 3414
3430 /* Need to free any translated characters */ 3415 // Need to free any translated characters
3431 vim_free(tofree); 3416 vim_free(tofree);
3432 3417
3433 prt_text_run += char_width; 3418 prt_text_run += char_width;
3434 prt_pos_x += char_width; 3419 prt_pos_x += char_width;
3435 3420
3436 /* The downside of fp - use relative error on right margin check */ 3421 // The downside of fp - use relative error on right margin check
3437 next_pos = prt_pos_x + prt_char_width; 3422 next_pos = prt_pos_x + prt_char_width;
3438 need_break = (next_pos > prt_right_margin) && 3423 need_break = (next_pos > prt_right_margin) &&
3439 ((next_pos - prt_right_margin) > (prt_right_margin*1e-5)); 3424 ((next_pos - prt_right_margin) > (prt_right_margin*1e-5));
3440 3425
3441 if (need_break) 3426 if (need_break)
3485 prt_attribute_change = TRUE; 3470 prt_attribute_change = TRUE;
3486 prt_need_fgcol = TRUE; 3471 prt_need_fgcol = TRUE;
3487 } 3472 }
3488 } 3473 }
3489 3474
3490 # endif /*FEAT_POSTSCRIPT*/ 3475 # endif //FEAT_POSTSCRIPT
3491 #endif /*FEAT_PRINTER*/ 3476 #endif //FEAT_PRINTER