/[public]/psiconv/trunk/program/psiconv/gen_latex.c
ViewVC logotype

Diff of /psiconv/trunk/program/psiconv/gen_latex.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 146 Revision 147
36 could be added) 36 could be added)
37 37
38 * Also does formatting commands (italics -> \emph, bold -> \textbf, 38 * Also does formatting commands (italics -> \emph, bold -> \textbf,
39 underline -> \underline), and character translation 39 underline -> \underline), and character translation
40 40
41*/
42
43/*
44 2002/Apr. Keita KAWABE
45 Support for narrow build Asian Psions added (experimental).
46
47 If the encoding_type is PSICONV_ENCODING_UTF8, use utf8_table for
48 character conversion. Otherwise use char_table.
49
50 When using UTF8 for LaTeX type, note that the resulting latex source
51 is not at all usable unless the user him/herself converts it to
52 appropriate encoding. This is because the encoding in localized TeXs
53 differ from system to system.
54 For example, if the user wants to generate a Japanese LaTeX source
55 from a UTF8 Psion Word, he/she first has to convert the Word document by
56
57psiconv -TLaTeX -u word | iconv --from-code=utf8 --to-code=EUC-JP > test.tex
58
59 or something similar. After that, just proceed as normal.
60
61 If you want to use Japanese-localized documentclass "jarticle" rather
62 than "article", please uncomment all the commented-out lines that are
63 explicitly stated as "Uncomment if you'd like to use jarticle" in this
64 source.
41*/ 65*/
42 66
43#include "config.h" 67#include "config.h"
44#include <stdio.h> 68#include <stdio.h>
45#include <string.h> 69#include <string.h>
113"\\`{\\i}","\\'{\\i}","\\^{\\i}","\\\"{\\i}", 137"\\`{\\i}","\\'{\\i}","\\^{\\i}","\\\"{\\i}",
114 /* 0xf0 */ "\\v{o}","\\~n","\\`o","\\'o", "\\^o","\\~o","\\\"o","$\\div$", 138 /* 0xf0 */ "\\v{o}","\\~n","\\`o","\\'o", "\\^o","\\~o","\\\"o","$\\div$",
115 /* 0xf8 */ "{\\o}","\\`u","\\'u","\\^u", "\\\"u","\\'y","","\\\"y" 139 /* 0xf8 */ "{\\o}","\\`u","\\'u","\\^u", "\\\"u","\\'y","","\\\"y"
116}; 140};
117 141
142static const char *utf_table[0x100] =
143{
144 /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"\n\n","\\\\"
145,
146 /* 0x08 */ "\n\n" ," " ,"" ,"" ,"" ,"" ,"" ,""
147,
148 /* 0x10 */ " " ,"" ,"" ,"" ,"" ,"" ,"" ,""
149,
150 /* 0x18 */ "" ,"" ,"" ,"" ,"" ,"" ,"" ,""
151,
152 /* 0x20 */ " " ,"!" ,"\"" ,"\\#" ,"\\$" ,"\\%" ,"\\&","'"
153,
154 /* 0x28 */ "(" ,")" ,"*" ,"+" ,"," ,"-" ,"." ,"/"
155,
156 /* 0x30 */ "0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7"
157,
158 /* 0x38 */ "8" ,"9" ,":" ,";" ,"$<$" ,"=" ,"$>$" ,"?" ,
159 /* 0x40 */ "@" ,"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G"
160,
161 /* 0x48 */ "H" ,"I" ,"J" ,"K" ,"L" ,"M" ,"N" ,"O"
162,
163 /* 0x50 */ "P" ,"Q" ,"R" ,"S" ,"T" ,"U" ,"V" ,"W"
164,
165 /* 0x58 */ "X" ,"Y" ,"Z" ,"[" ,"$\\backslash$" ,"]" ,"\\^{}"
166,"\\_" ,
167 /* 0x60 */ "`" ,"a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g"
168,
169 /* 0x68 */ "h" ,"i" ,"j" ,"k" ,"l" ,"m" ,"n" ,"o"
170,
171 /* 0x70 */ "p" ,"q" ,"r" ,"s" ,"t" ,"u" ,"v" ,"w"
172,
173 /* 0x78 */ "x" ,"y" ,"z" ,"\\{" ,"$|$" ,"\\}" ,"~"
174,"" ,
175 /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87",
176 /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f",
177 /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97",
178 /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f",
179 /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7",
180 /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf",
181 /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7",
182 /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf",
183 /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7",
184 /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf",
185 /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7",
186 /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf",
187 /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7",
188 /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef",
189 /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7",
190 /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff",
191};
192
193/* a flag to indicate the use of UTF8 */
194static psiconv_encoding encoding = PSICONV_ENCODING_CP1252;
195
118static psiconv_character_layout gen_base_char(const psiconv_font font, 196static psiconv_character_layout gen_base_char(const psiconv_font font,
119 const psiconv_color color, 197 const psiconv_color color,
120 const psiconv_color 198 const psiconv_color
121back_color); 199back_color);
122static void diff_char(FILE *of, const psiconv_character_layout old, 200static void diff_char(FILE *of, const psiconv_character_layout old,
222 psiconv_in_line_layout inl; 300 psiconv_in_line_layout inl;
223 int flags = 0; 301 int flags = 0;
224 psiconv_word_style sty; 302 psiconv_word_style sty;
225 char *env = NULL; 303 char *env = NULL;
226 304
305 char ** table;
306 if (encoding == PSICONV_ENCODING_UTF8){
307 table = (char**)utf_table;
308 }else{
309 table = (char**)char_table;
310 }
311
227 if (para->base_paragraph->bullet->on) { 312 if (para->base_paragraph->bullet->on) {
228 if (! bullet_switch_on) { 313 if (! bullet_switch_on) {
229 fputs("\\begin{itemize}\n\n", of); 314 fputs("\\begin{itemize}\n\n", of);
230 bullet_switch_on = psiconv_bool_true; 315 bullet_switch_on = psiconv_bool_true;
231 } 316 }
266 for (i = 0; i < psiconv_list_length(para->in_lines); i++) { 351 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
267 inl = psiconv_list_get(para->in_lines,i); 352 inl = psiconv_list_get(para->in_lines,i);
268 diff_char(of,cur_char,inl->layout,&flags); 353 diff_char(of,cur_char,inl->layout,&flags);
269 cur_char = inl->layout; 354 cur_char = inl->layout;
270 for (j = loc; j < inl->length + loc; j ++) { 355 for (j = loc; j < inl->length + loc; j ++) {
271 fputs(char_table[(unsigned char) (para->text[j])],of); 356 fputs(table[(unsigned char) (para->text[j])],of);
272 } 357 }
273 loc = j; 358 loc = j;
274 } 359 }
275 360
276 if (loc < strlen(para->text)) { 361 if (loc < strlen(para->text)) {
277 diff_char(of,cur_char,para->base_character,&flags); 362 diff_char(of,cur_char,para->base_character,&flags);
278 cur_char = para->base_character; 363 cur_char = para->base_character;
279 for (j = loc; j < strlen(para->text); j ++) { 364 for (j = loc; j < strlen(para->text); j ++) {
280 fputs(char_table[(unsigned char) (para->text[j])],of); 365 fputs(table[(unsigned char) (para->text[j])],of);
281 } 366 }
282 } 367 }
283 368
284 flags |= 2; 369 flags |= 2;
285 diff_char(of,cur_char,base_char,&flags); 370 diff_char(of,cur_char,base_char,&flags);
292 377
293 fputs("\n\n", of); 378 fputs("\n\n", of);
294} 379}
295 380
296int psiconv_gen_latex(const char * filename,const psiconv_file file, 381int psiconv_gen_latex(const char * filename,const psiconv_file file,
297 const char *dest) 382 const char *dest, const psiconv_encoding encoding_type)
298{ 383{
299 FILE *of = fopen(filename,"w"); 384 FILE *of = fopen(filename,"w");
300 if (! of) 385 if (! of)
301 return -1; 386 return -1;
387
388 encoding = encoding_type;
302 389
303 if (file->type == psiconv_word_file) { 390 if (file->type == psiconv_word_file) {
304 psiconv_gen_latex_word(of,(psiconv_word_f) file->file); 391 psiconv_gen_latex_word(of,(psiconv_word_f) file->file);
305 } else if (file->type == psiconv_texted_file) { 392 } else if (file->type == psiconv_texted_file) {
306 psiconv_gen_latex_texted(of,(psiconv_texted_f) file->file); 393 psiconv_gen_latex_texted(of,(psiconv_texted_f) file->file);
319 int i; 406 int i;
320 407
321 /* We have nothing better */ 408 /* We have nothing better */
322 base_char = psiconv_basic_character_layout(); 409 base_char = psiconv_basic_character_layout();
323 410
411 /* Uncomment if you'd like to use jarticle...
412 if (encoding == PSICONV_ENCODING_UTF8){
413 fputs("\\documentclass{jarticle}\n\n\\begin{document}\n\n", of);
414 }else{
415 */
324 fputs("\\documentclass{article}\n\n\\begin{document}\n\n", of); 416 fputs("\\documentclass{article}\n\n\\begin{document}\n\n", of);
417 /* Uncomment if you'd like to use jarticle...
418 }
419 */
325 for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { 420 for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) {
326 para = psiconv_list_get(tf->texted_sec->paragraphs,i); 421 para = psiconv_list_get(tf->texted_sec->paragraphs,i);
327 gen_para(of,para,base_char, NULL); 422 gen_para(of,para,base_char, NULL);
328 } 423 }
329 fputs("\\end{document}",of); 424 fputs("\\end{document}",of);
351 black,white); 446 black,white);
352 447
353 psiconv_free_color(black); 448 psiconv_free_color(black);
354 psiconv_free_color(white); 449 psiconv_free_color(white);
355 450
451 /* Uncomment if you'd like to use jarticle
452 if (encoding == PSICONV_ENCODING_UTF8){
453 fputs("\\documentclass{jarticle}\n\n\\begin{document}\n\n", of);
454 }else{
455 */
356 fputs("\\documentclass{article}\n\n\\begin{document}\n\n", of); 456 fputs("\\documentclass{article}\n\n\\begin{document}\n\n", of);
457 /* Uncomment if you'd like to use jarticle
458 }
459 */
357 460
358 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { 461 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) {
359 para = psiconv_list_get(wf->paragraphs,i); 462 para = psiconv_list_get(wf->paragraphs,i);
360 gen_para(of,para,base_char,wf); 463 gen_para(of,para,base_char,wf);
361 } 464 }

Legend:
Removed from v.146  
changed lines
  Added in v.147

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26