Mercurial > vim
comparison src/ex_cmds2.c @ 20:4ac1dce8dd5e v7.0012
updated for version 7.0012
author | vimboss |
---|---|
date | Mon, 26 Jul 2004 12:53:41 +0000 |
parents | 3ba373b54370 |
children | cc049b00ee70 |
comparison
equal
deleted
inserted
replaced
19:a81bc802c17c | 20:4ac1dce8dd5e |
---|---|
3804 -100, 50, | 3804 -100, 50, |
3805 -250, 805, | 3805 -250, 805, |
3806 {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"} | 3806 {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"} |
3807 }; | 3807 }; |
3808 | 3808 |
3809 #ifdef FEAT_MBYTE | |
3809 /* Generic font metrics for multi-byte fonts */ | 3810 /* Generic font metrics for multi-byte fonts */ |
3810 static struct prt_ps_font_S prt_ps_mb_font = | 3811 static struct prt_ps_font_S prt_ps_mb_font = |
3811 { | 3812 { |
3812 1000, | 3813 1000, |
3813 -100, 50, | 3814 -100, 50, |
3814 -250, 805, | 3815 -250, 805, |
3815 {NULL, NULL, NULL, NULL} | 3816 {NULL, NULL, NULL, NULL} |
3816 }; | 3817 }; |
3818 #endif | |
3817 | 3819 |
3818 /* Pointer to current font set being used */ | 3820 /* Pointer to current font set being used */ |
3819 static struct prt_ps_font_S* prt_ps_font; | 3821 static struct prt_ps_font_S* prt_ps_font; |
3820 | 3822 |
3821 /* Structures to map user named encoding and mapping to PS equivalents for | 3823 /* Structures to map user named encoding and mapping to PS equivalents for |
3822 * building CID font name */ | 3824 * building CID font name */ |
3823 struct prt_ps_encoding_S | 3825 struct prt_ps_encoding_S |
3824 { | 3826 { |
3825 char_u *encoding; | 3827 char *encoding; |
3826 char_u *cmap_encoding; | 3828 char *cmap_encoding; |
3827 int needs_charset; | 3829 int needs_charset; |
3828 }; | 3830 }; |
3829 | 3831 |
3830 struct prt_ps_charset_S | 3832 struct prt_ps_charset_S |
3831 { | 3833 { |
3832 char *charset; | 3834 char *charset; |
3833 char *cmap_charset; | 3835 char *cmap_charset; |
3834 int has_charset; | 3836 int has_charset; |
3835 }; | 3837 }; |
3838 | |
3839 #ifdef FEAT_MBYTE | |
3836 | 3840 |
3837 #define CS_JIS_C_1978 (0x01) | 3841 #define CS_JIS_C_1978 (0x01) |
3838 #define CS_JIS_X_1983 (0x02) | 3842 #define CS_JIS_X_1983 (0x02) |
3839 #define CS_JIS_X_1990 (0x04) | 3843 #define CS_JIS_X_1990 (0x04) |
3840 #define CS_NEC (0x08) | 3844 #define CS_NEC (0x08) |
4015 k_charsets, | 4019 k_charsets, |
4016 "ks_roman", | 4020 "ks_roman", |
4017 "KS_X_1992" | 4021 "KS_X_1992" |
4018 } | 4022 } |
4019 }; | 4023 }; |
4024 #endif /* FEAT_MBYTE */ | |
4020 | 4025 |
4021 struct prt_ps_resource_S | 4026 struct prt_ps_resource_S |
4022 { | 4027 { |
4023 char_u name[64]; | 4028 char_u name[64]; |
4024 char_u filename[MAXPATHL + 1]; | 4029 char_u filename[MAXPATHL + 1]; |
4074 #define PRT_DSC_VERSION "%%Version:" | 4079 #define PRT_DSC_VERSION "%%Version:" |
4075 #define PRT_DSC_ENDCOMMENTS "%%EndComments:" | 4080 #define PRT_DSC_ENDCOMMENTS "%%EndComments:" |
4076 | 4081 |
4077 struct prt_dsc_comment_S | 4082 struct prt_dsc_comment_S |
4078 { | 4083 { |
4079 char_u *string; | 4084 char *string; |
4080 int len; | 4085 int len; |
4081 int type; | 4086 int type; |
4082 }; | 4087 }; |
4083 | 4088 |
4084 struct prt_dsc_line_S | 4089 struct prt_dsc_line_S |
4090 | 4095 |
4091 | 4096 |
4092 #define SIZEOF_CSTR(s) (sizeof(s) - 1) | 4097 #define SIZEOF_CSTR(s) (sizeof(s) - 1) |
4093 struct prt_dsc_comment_S prt_dsc_table[] = | 4098 struct prt_dsc_comment_S prt_dsc_table[] = |
4094 { | 4099 { |
4095 {PRT_DSC_TITLE, SIZEOF_CSTR(PRT_DSC_TITLE), PRT_DSC_TITLE_TYPE}, | 4100 {PRT_DSC_TITLE, SIZEOF_CSTR(PRT_DSC_TITLE), PRT_DSC_TITLE_TYPE}, |
4096 {PRT_DSC_VERSION, SIZEOF_CSTR(PRT_DSC_VERSION), | 4101 {PRT_DSC_VERSION, SIZEOF_CSTR(PRT_DSC_VERSION), |
4097 PRT_DSC_VERSION_TYPE}, | 4102 PRT_DSC_VERSION_TYPE}, |
4098 {PRT_DSC_ENDCOMMENTS, SIZEOF_CSTR(PRT_DSC_ENDCOMMENTS), | 4103 {PRT_DSC_ENDCOMMENTS, SIZEOF_CSTR(PRT_DSC_ENDCOMMENTS), |
4099 PRT_DSC_ENDCOMMENTS_TYPE} | 4104 PRT_DSC_ENDCOMMENTS_TYPE} |
4100 }; | 4105 }; |
4101 | 4106 |
4102 static void prt_write_file_raw_len __ARGS((char_u *buffer, int bytes)); | 4107 static void prt_write_file_raw_len __ARGS((char_u *buffer, int bytes)); |
4103 static void prt_write_file __ARGS((char_u *buffer)); | 4108 static void prt_write_file __ARGS((char_u *buffer)); |
4104 static void prt_write_file_len __ARGS((char_u *buffer, int bytes)); | 4109 static void prt_write_file_len __ARGS((char_u *buffer, int bytes)); |
4133 static int prt_resfile_strncmp __ARGS((int offset, char *string, int len)); | 4138 static int prt_resfile_strncmp __ARGS((int offset, char *string, int len)); |
4134 static int prt_resfile_skip_nonws __ARGS((int offset)); | 4139 static int prt_resfile_skip_nonws __ARGS((int offset)); |
4135 static int prt_resfile_skip_ws __ARGS((int offset)); | 4140 static int prt_resfile_skip_ws __ARGS((int offset)); |
4136 static int prt_next_dsc __ARGS((struct prt_dsc_line_S *p_dsc_line)); | 4141 static int prt_next_dsc __ARGS((struct prt_dsc_line_S *p_dsc_line)); |
4137 #ifdef FEAT_MBYTE | 4142 #ifdef FEAT_MBYTE |
4143 static int prt_build_cid_fontname __ARGS((int font, char_u *name, int name_len)); | |
4138 static void prt_def_cidfont __ARGS((char *new_name, int height, char *cidfont)); | 4144 static void prt_def_cidfont __ARGS((char *new_name, int height, char *cidfont)); |
4139 static int prt_match_encoding __ARGS((char *p_encoding, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_encoding_S **pp_mbenc)); | 4145 static int prt_match_encoding __ARGS((char *p_encoding, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_encoding_S **pp_mbenc)); |
4140 static int prt_match_charset __ARGS((char *p_charset, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_charset_S **pp_mbchar)); | 4146 static int prt_match_charset __ARGS((char *p_charset, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_charset_S **pp_mbchar)); |
4141 #endif | 4147 #endif |
4142 | 4148 |
5095 prt_number_width = 0.0; | 5101 prt_number_width = 0.0; |
5096 | 5102 |
5097 return (int)((prt_right_margin - prt_left_margin) / prt_char_width); | 5103 return (int)((prt_right_margin - prt_left_margin) / prt_char_width); |
5098 } | 5104 } |
5099 | 5105 |
5106 #ifdef FEAT_MBYTE | |
5100 static int | 5107 static int |
5101 prt_build_cid_fontname(font, name, name_len) | 5108 prt_build_cid_fontname(font, name, name_len) |
5102 int font; | 5109 int font; |
5103 char *name; | 5110 char_u *name; |
5104 int name_len; | 5111 int name_len; |
5105 { | 5112 { |
5106 char *fontname; | 5113 char *fontname; |
5107 | 5114 |
5108 fontname = alloc(name_len + 1); | 5115 fontname = (char *)alloc(name_len + 1); |
5109 if (fontname == NULL) | 5116 if (fontname == NULL) |
5110 return FALSE; | 5117 return FALSE; |
5111 STRNCPY(fontname, name, name_len); | 5118 STRNCPY(fontname, name, name_len); |
5112 fontname[name_len] = '\0'; | 5119 fontname[name_len] = '\0'; |
5113 prt_ps_mb_font.ps_fontname[font] = fontname; | 5120 prt_ps_mb_font.ps_fontname[font] = fontname; |
5114 | 5121 |
5115 return TRUE; | 5122 return TRUE; |
5116 } | 5123 } |
5124 #endif | |
5117 | 5125 |
5118 /* | 5126 /* |
5119 * Get number of lines of text that fit on a page (excluding the header). | 5127 * Get number of lines of text that fit on a page (excluding the header). |
5120 */ | 5128 */ |
5121 static int | 5129 static int |
5150 } | 5158 } |
5151 | 5159 |
5152 #ifdef FEAT_MBYTE | 5160 #ifdef FEAT_MBYTE |
5153 static int | 5161 static int |
5154 prt_match_encoding(p_encoding, p_cmap, pp_mbenc) | 5162 prt_match_encoding(p_encoding, p_cmap, pp_mbenc) |
5155 char *p_encoding; | 5163 char *p_encoding; |
5156 struct prt_ps_mbfont_S *p_cmap; | 5164 struct prt_ps_mbfont_S *p_cmap; |
5157 struct prt_ps_encoding_S **pp_mbenc; | 5165 struct prt_ps_encoding_S **pp_mbenc; |
5158 { | 5166 { |
5159 int mbenc; | 5167 int mbenc; |
5160 int enc_len; | 5168 int enc_len; |
5161 struct prt_ps_encoding_S *p_mbenc; | 5169 struct prt_ps_encoding_S *p_mbenc; |
5162 | 5170 |
5163 *pp_mbenc = NULL; | 5171 *pp_mbenc = NULL; |
5164 /* Look for recognised encoding */ | 5172 /* Look for recognised encoding */ |
5165 enc_len = STRLEN(p_encoding); | 5173 enc_len = STRLEN(p_encoding); |
5166 p_mbenc = p_cmap->encodings; | 5174 p_mbenc = p_cmap->encodings; |
5176 return FALSE; | 5184 return FALSE; |
5177 } | 5185 } |
5178 | 5186 |
5179 static int | 5187 static int |
5180 prt_match_charset(p_charset, p_cmap, pp_mbchar) | 5188 prt_match_charset(p_charset, p_cmap, pp_mbchar) |
5181 char *p_charset; | 5189 char *p_charset; |
5182 struct prt_ps_mbfont_S *p_cmap; | 5190 struct prt_ps_mbfont_S *p_cmap; |
5183 struct prt_ps_charset_S **pp_mbchar; | 5191 struct prt_ps_charset_S **pp_mbchar; |
5184 { | 5192 { |
5185 int mbchar; | 5193 int mbchar; |
5186 int char_len; | 5194 int char_len; |
5187 struct prt_ps_charset_S *p_mbchar; | 5195 struct prt_ps_charset_S *p_mbchar; |
5188 | 5196 |
5189 /* Look for recognised character set, using default if one is not given */ | 5197 /* Look for recognised character set, using default if one is not given */ |
5190 if (*p_charset == NUL) | 5198 if (*p_charset == NUL) |
5191 p_charset = p_cmap->defcs; | 5199 p_charset = p_cmap->defcs; |
5224 int cmap; | 5232 int cmap; |
5225 int pmcs_len; | 5233 int pmcs_len; |
5226 char_u *p_encoding; | 5234 char_u *p_encoding; |
5227 struct prt_ps_encoding_S *p_mbenc; | 5235 struct prt_ps_encoding_S *p_mbenc; |
5228 struct prt_ps_encoding_S *p_mbenc_first; | 5236 struct prt_ps_encoding_S *p_mbenc_first; |
5229 struct prt_ps_charset_S *p_mbchar; | 5237 struct prt_ps_charset_S *p_mbchar; |
5230 #endif | 5238 #endif |
5231 | 5239 |
5232 #if 0 | 5240 #if 0 |
5233 /* | 5241 /* |
5234 * TODO: | 5242 * TODO: |
5260 * supported in more than one of CJK. */ | 5268 * supported in more than one of CJK. */ |
5261 p_mbenc = NULL; | 5269 p_mbenc = NULL; |
5262 p_mbenc_first = NULL; | 5270 p_mbenc_first = NULL; |
5263 p_mbchar = NULL; | 5271 p_mbchar = NULL; |
5264 for (cmap = 0; cmap < NUM_ELEMENTS(prt_ps_mbfonts); cmap++) | 5272 for (cmap = 0; cmap < NUM_ELEMENTS(prt_ps_mbfonts); cmap++) |
5265 if (prt_match_encoding(p_encoding, &prt_ps_mbfonts[cmap], &p_mbenc)) | 5273 if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap], |
5274 &p_mbenc)) | |
5266 { | 5275 { |
5267 if (p_mbenc_first == NULL) | 5276 if (p_mbenc_first == NULL) |
5268 p_mbenc_first = p_mbenc; | 5277 p_mbenc_first = p_mbenc; |
5269 if (prt_match_charset(p_pmcs, &prt_ps_mbfonts[cmap], &p_mbchar)) | 5278 if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap], |
5279 &p_mbchar)) | |
5270 break; | 5280 break; |
5271 } | 5281 } |
5272 | 5282 |
5273 /* Use first encoding matched if no charset matched */ | 5283 /* Use first encoding matched if no charset matched */ |
5274 if (p_mbchar == NULL && p_mbenc_first != NULL) | 5284 if (p_mbchar == NULL && p_mbenc_first != NULL) |
5341 mbfont_opts[OPT_MBFONT_OBLIQUE].string, | 5351 mbfont_opts[OPT_MBFONT_OBLIQUE].string, |
5342 mbfont_opts[OPT_MBFONT_OBLIQUE].strlen)) | 5352 mbfont_opts[OPT_MBFONT_OBLIQUE].strlen)) |
5343 return FALSE; | 5353 return FALSE; |
5344 if (mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].present) | 5354 if (mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].present) |
5345 if (!prt_build_cid_fontname(PRT_PS_FONT_BOLDOBLIQUE, | 5355 if (!prt_build_cid_fontname(PRT_PS_FONT_BOLDOBLIQUE, |
5346 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].string, | 5356 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].string, |
5347 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen)) | 5357 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen)) |
5348 return FALSE; | 5358 return FALSE; |
5349 | 5359 |
5350 /* Check if need to use Courier for ASCII code range, and if so pick up | 5360 /* Check if need to use Courier for ASCII code range, and if so pick up |
5351 * the encoding to use */ | 5361 * the encoding to use */ |
5352 prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && | 5362 prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && |
5553 if (fd_resource == NULL) | 5563 if (fd_resource == NULL) |
5554 { | 5564 { |
5555 EMSG2(_("E456: Can't open file \"%s\""), resource->filename); | 5565 EMSG2(_("E456: Can't open file \"%s\""), resource->filename); |
5556 return FALSE; | 5566 return FALSE; |
5557 } | 5567 } |
5558 prt_dsc_resources("BeginResource", | 5568 prt_dsc_resources("BeginResource", prt_resource_types[resource->type], |
5559 prt_resource_types[resource->type], resource->title); | 5569 (char *)resource->title); |
5560 | 5570 |
5561 prt_dsc_textline("BeginDocument", (char *)resource->filename); | 5571 prt_dsc_textline("BeginDocument", (char *)resource->filename); |
5562 | 5572 |
5563 for (;;) | 5573 for (;;) |
5564 { | 5574 { |
5600 double right; | 5610 double right; |
5601 double top; | 5611 double top; |
5602 double bottom; | 5612 double bottom; |
5603 struct prt_ps_resource_S res_prolog; | 5613 struct prt_ps_resource_S res_prolog; |
5604 struct prt_ps_resource_S res_encoding; | 5614 struct prt_ps_resource_S res_encoding; |
5605 char_u buffer[256]; | 5615 char buffer[256]; |
5606 char_u *p_encoding; | 5616 char_u *p_encoding; |
5607 #ifdef FEAT_MBYTE | 5617 #ifdef FEAT_MBYTE |
5608 struct prt_ps_resource_S res_cidfont; | 5618 struct prt_ps_resource_S res_cidfont; |
5609 struct prt_ps_resource_S res_cmap; | 5619 struct prt_ps_resource_S res_cmap; |
5610 #endif | 5620 #endif |
5612 /* | 5622 /* |
5613 * PS DSC Header comments - no PS code! | 5623 * PS DSC Header comments - no PS code! |
5614 */ | 5624 */ |
5615 prt_dsc_start(); | 5625 prt_dsc_start(); |
5616 prt_dsc_textline("Title", (char *)psettings->jobname); | 5626 prt_dsc_textline("Title", (char *)psettings->jobname); |
5617 if (!get_user_name(buffer, 256)) | 5627 if (!get_user_name((char_u *)buffer, 256)) |
5618 STRCPY(buffer, "Unknown"); | 5628 STRCPY(buffer, "Unknown"); |
5619 prt_dsc_textline("For", buffer); | 5629 prt_dsc_textline("For", buffer); |
5620 prt_dsc_textline("Creator", VIM_VERSION_LONG); | 5630 prt_dsc_textline("Creator", VIM_VERSION_LONG); |
5621 /* Note: to ensure Clean8bit I don't think we can use LC_TIME */ | 5631 /* Note: to ensure Clean8bit I don't think we can use LC_TIME */ |
5622 now = time(NULL); | 5632 now = time(NULL); |
5755 { | 5765 { |
5756 /* Include ASCII range encoding vector */ | 5766 /* Include ASCII range encoding vector */ |
5757 if (!prt_find_resource(prt_ascii_encoding, &res_encoding)) | 5767 if (!prt_find_resource(prt_ascii_encoding, &res_encoding)) |
5758 { | 5768 { |
5759 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), | 5769 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), |
5760 prt_ascii_encoding); | 5770 prt_ascii_encoding); |
5761 return FALSE; | 5771 return FALSE; |
5762 } | 5772 } |
5763 if (!prt_open_resource(&res_encoding)) | 5773 if (!prt_open_resource(&res_encoding)) |
5764 return FALSE; | 5774 return FALSE; |
5765 /* For the moment there are no checks on encoding resource files to | 5775 /* For the moment there are no checks on encoding resource files to |
5784 { | 5794 { |
5785 /* Find user supplied CMap */ | 5795 /* Find user supplied CMap */ |
5786 if (!prt_find_resource(prt_cmap, &res_cmap)) | 5796 if (!prt_find_resource(prt_cmap, &res_cmap)) |
5787 { | 5797 { |
5788 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), | 5798 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), |
5789 prt_cmap); | 5799 prt_cmap); |
5790 return FALSE; | 5800 return FALSE; |
5791 } | 5801 } |
5792 if (!prt_open_resource(&res_cmap)) | 5802 if (!prt_open_resource(&res_cmap)) |
5793 return FALSE; | 5803 return FALSE; |
5794 } | 5804 } |
5909 if (!prt_out_mbyte || prt_use_courier) | 5919 if (!prt_out_mbyte || prt_use_courier) |
5910 { | 5920 { |
5911 /* When using Courier for ASCII range when printing multi-byte, need to | 5921 /* When using Courier for ASCII range when printing multi-byte, need to |
5912 * pick up ASCII encoding to use with it. */ | 5922 * pick up ASCII encoding to use with it. */ |
5913 if (prt_use_courier) | 5923 if (prt_use_courier) |
5914 p_encoding = prt_ascii_encoding; | 5924 p_encoding = (char_u *)prt_ascii_encoding; |
5915 #endif | 5925 #endif |
5916 prt_dsc_resources("IncludeResource", "font", | 5926 prt_dsc_resources("IncludeResource", "font", |
5917 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); | 5927 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); |
5918 prt_def_font("F0", (char *)p_encoding, (int)prt_line_height, | 5928 prt_def_font("F0", (char *)p_encoding, (int)prt_line_height, |
5919 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); | 5929 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); |
6013 | 6023 |
6014 prt_dsc_noarg("EOF"); | 6024 prt_dsc_noarg("EOF"); |
6015 | 6025 |
6016 /* Write CTRL-D to close serial communication link if used. | 6026 /* Write CTRL-D to close serial communication link if used. |
6017 * NOTHING MUST BE WRITTEN AFTER THIS! */ | 6027 * NOTHING MUST BE WRITTEN AFTER THIS! */ |
6018 prt_write_file(IF_EB("\004", "\067")); | 6028 prt_write_file((char_u *)IF_EB("\004", "\067")); |
6019 | 6029 |
6020 if (!prt_file_error && psettings->outfile == NULL | 6030 if (!prt_file_error && psettings->outfile == NULL |
6021 && !got_int && !psettings->user_abort) | 6031 && !got_int && !psettings->user_abort) |
6022 { | 6032 { |
6023 /* Close the file first. */ | 6033 /* Close the file first. */ |
6272 /* Multi-byte character strings are represented more efficiently as hex | 6282 /* Multi-byte character strings are represented more efficiently as hex |
6273 * strings when outputting clean 8 bit PS. | 6283 * strings when outputting clean 8 bit PS. |
6274 */ | 6284 */ |
6275 do | 6285 do |
6276 { | 6286 { |
6277 ch = prt_hexchar[(*p) >> 4]; | 6287 ch = prt_hexchar[(unsigned)(*p) >> 4]; |
6278 ga_append(&prt_ps_buffer, ch); | 6288 ga_append(&prt_ps_buffer, ch); |
6279 ch = prt_hexchar[(*p) & 0xf]; | 6289 ch = prt_hexchar[(*p) & 0xf]; |
6280 ga_append(&prt_ps_buffer, ch); | 6290 ga_append(&prt_ps_buffer, ch); |
6281 p++; | 6291 p++; |
6282 } | 6292 } |