--- psiconv/trunk/program/psiconv/gen_latex.c 2002/01/29 20:15:23 146 +++ psiconv/trunk/program/psiconv/gen_latex.c 2002/05/10 15:55:55 147 @@ -40,6 +40,30 @@ */ +/* + 2002/Apr. Keita KAWABE + Support for narrow build Asian Psions added (experimental). + + If the encoding_type is PSICONV_ENCODING_UTF8, use utf8_table for + character conversion. Otherwise use char_table. + + When using UTF8 for LaTeX type, note that the resulting latex source + is not at all usable unless the user him/herself converts it to + appropriate encoding. This is because the encoding in localized TeXs + differ from system to system. + For example, if the user wants to generate a Japanese LaTeX source + from a UTF8 Psion Word, he/she first has to convert the Word document by + +psiconv -TLaTeX -u word | iconv --from-code=utf8 --to-code=EUC-JP > test.tex + + or something similar. After that, just proceed as normal. + + If you want to use Japanese-localized documentclass "jarticle" rather + than "article", please uncomment all the commented-out lines that are + explicitly stated as "Uncomment if you'd like to use jarticle" in this + source. +*/ + #include "config.h" #include #include @@ -115,6 +139,60 @@ /* 0xf8 */ "{\\o}","\\`u","\\'u","\\^u", "\\\"u","\\'y","","\\\"y" }; +static const char *utf_table[0x100] = +{ + /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"\n\n","\\\\" +, + /* 0x08 */ "\n\n" ," " ,"" ,"" ,"" ,"" ,"" ,"" +, + /* 0x10 */ " " ,"" ,"" ,"" ,"" ,"" ,"" ,"" +, + /* 0x18 */ "" ,"" ,"" ,"" ,"" ,"" ,"" ,"" +, + /* 0x20 */ " " ,"!" ,"\"" ,"\\#" ,"\\$" ,"\\%" ,"\\&","'" +, + /* 0x28 */ "(" ,")" ,"*" ,"+" ,"," ,"-" ,"." ,"/" +, + /* 0x30 */ "0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" +, + /* 0x38 */ "8" ,"9" ,":" ,";" ,"$<$" ,"=" ,"$>$" ,"?" , + /* 0x40 */ "@" ,"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G" +, + /* 0x48 */ "H" ,"I" ,"J" ,"K" ,"L" ,"M" ,"N" ,"O" +, + /* 0x50 */ "P" ,"Q" ,"R" ,"S" ,"T" ,"U" ,"V" ,"W" +, + /* 0x58 */ "X" ,"Y" ,"Z" ,"[" ,"$\\backslash$" ,"]" ,"\\^{}" +,"\\_" , + /* 0x60 */ "`" ,"a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g" +, + /* 0x68 */ "h" ,"i" ,"j" ,"k" ,"l" ,"m" ,"n" ,"o" +, + /* 0x70 */ "p" ,"q" ,"r" ,"s" ,"t" ,"u" ,"v" ,"w" +, + /* 0x78 */ "x" ,"y" ,"z" ,"\\{" ,"$|$" ,"\\}" ,"~" +,"" , + /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87", + /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f", + /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97", + /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f", + /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7", + /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf", + /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7", + /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf", + /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7", + /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf", + /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7", + /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf", + /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7", + /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef", + /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7", + /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff", +}; + +/* a flag to indicate the use of UTF8 */ +static psiconv_encoding encoding = PSICONV_ENCODING_CP1252; + static psiconv_character_layout gen_base_char(const psiconv_font font, const psiconv_color color, const psiconv_color @@ -224,6 +302,13 @@ psiconv_word_style sty; char *env = NULL; + char ** table; + if (encoding == PSICONV_ENCODING_UTF8){ + table = (char**)utf_table; + }else{ + table = (char**)char_table; + } + if (para->base_paragraph->bullet->on) { if (! bullet_switch_on) { fputs("\\begin{itemize}\n\n", of); @@ -268,7 +353,7 @@ diff_char(of,cur_char,inl->layout,&flags); cur_char = inl->layout; for (j = loc; j < inl->length + loc; j ++) { - fputs(char_table[(unsigned char) (para->text[j])],of); + fputs(table[(unsigned char) (para->text[j])],of); } loc = j; } @@ -277,7 +362,7 @@ diff_char(of,cur_char,para->base_character,&flags); cur_char = para->base_character; for (j = loc; j < strlen(para->text); j ++) { - fputs(char_table[(unsigned char) (para->text[j])],of); + fputs(table[(unsigned char) (para->text[j])],of); } } @@ -294,12 +379,14 @@ } int psiconv_gen_latex(const char * filename,const psiconv_file file, - const char *dest) + const char *dest, const psiconv_encoding encoding_type) { FILE *of = fopen(filename,"w"); if (! of) return -1; + encoding = encoding_type; + if (file->type == psiconv_word_file) { psiconv_gen_latex_word(of,(psiconv_word_f) file->file); } else if (file->type == psiconv_texted_file) { @@ -321,7 +408,15 @@ /* We have nothing better */ base_char = psiconv_basic_character_layout(); - fputs("\\documentclass{article}\n\n\\begin{document}\n\n", of); + /* Uncomment if you'd like to use jarticle... + if (encoding == PSICONV_ENCODING_UTF8){ + fputs("\\documentclass{jarticle}\n\n\\begin{document}\n\n", of); + }else{ + */ + fputs("\\documentclass{article}\n\n\\begin{document}\n\n", of); + /* Uncomment if you'd like to use jarticle... + } + */ for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { para = psiconv_list_get(tf->texted_sec->paragraphs,i); gen_para(of,para,base_char, NULL); @@ -353,7 +448,15 @@ psiconv_free_color(black); psiconv_free_color(white); - fputs("\\documentclass{article}\n\n\\begin{document}\n\n", of); + /* Uncomment if you'd like to use jarticle + if (encoding == PSICONV_ENCODING_UTF8){ + fputs("\\documentclass{jarticle}\n\n\\begin{document}\n\n", of); + }else{ + */ + fputs("\\documentclass{article}\n\n\\begin{document}\n\n", of); + /* Uncomment if you'd like to use jarticle + } + */ for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { para = psiconv_list_get(wf->paragraphs,i);