/[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 109 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>
46#include <stdlib.h> 70#include <stdlib.h>
47#include "psiconv/data.h" 71#include "psiconv/data.h"
48#include "psiconv/list.h" 72#include "psiconv/list.h"
49#include "gen.h" 73#include "gen.h"
50#include "psiconv.h" 74#include "psiconv.h"
75
76#ifdef DMALLOC
77#include "dmalloc.h"
78#endif
51 79
52/* This is incomplete at the moment. 80/* This is incomplete at the moment.
53 81
54 Most of the translation/faking of chars is borrowed from the 82 Most of the translation/faking of chars is borrowed from the
55 HTML::Latex.pm perl module. */ 83 HTML::Latex.pm perl module. */
109"\\`{\\i}","\\'{\\i}","\\^{\\i}","\\\"{\\i}", 137"\\`{\\i}","\\'{\\i}","\\^{\\i}","\\\"{\\i}",
110 /* 0xf0 */ "\\v{o}","\\~n","\\`o","\\'o", "\\^o","\\~o","\\\"o","$\\div$", 138 /* 0xf0 */ "\\v{o}","\\~n","\\`o","\\'o", "\\^o","\\~o","\\\"o","$\\div$",
111 /* 0xf8 */ "{\\o}","\\`u","\\'u","\\^u", "\\\"u","\\'y","","\\\"y" 139 /* 0xf8 */ "{\\o}","\\`u","\\'u","\\^u", "\\\"u","\\'y","","\\\"y"
112}; 140};
113 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
114static psiconv_character_layout gen_base_char(const psiconv_font font, 196static psiconv_character_layout gen_base_char(const psiconv_font font,
115 const psiconv_color color, 197 const psiconv_color color,
116 const psiconv_color 198 const psiconv_color
117back_color); 199back_color);
118static void diff_char(FILE *of, const psiconv_character_layout old, 200static void diff_char(FILE *of, const psiconv_character_layout old,
218 psiconv_in_line_layout inl; 300 psiconv_in_line_layout inl;
219 int flags = 0; 301 int flags = 0;
220 psiconv_word_style sty; 302 psiconv_word_style sty;
221 char *env = NULL; 303 char *env = NULL;
222 304
305 char ** table;
306 if (encoding == PSICONV_ENCODING_UTF8){
307 table = (char**)utf_table;
308 }else{
309 table = (char**)char_table;
310 }
311
223 if (para->base_paragraph->bullet->on) { 312 if (para->base_paragraph->bullet->on) {
224 if (! bullet_switch_on) { 313 if (! bullet_switch_on) {
225 fputs("\\begin{itemize}\n\n", of); 314 fputs("\\begin{itemize}\n\n", of);
226 bullet_switch_on = psiconv_bool_true; 315 bullet_switch_on = psiconv_bool_true;
227 } 316 }
262 for (i = 0; i < psiconv_list_length(para->in_lines); i++) { 351 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
263 inl = psiconv_list_get(para->in_lines,i); 352 inl = psiconv_list_get(para->in_lines,i);
264 diff_char(of,cur_char,inl->layout,&flags); 353 diff_char(of,cur_char,inl->layout,&flags);
265 cur_char = inl->layout; 354 cur_char = inl->layout;
266 for (j = loc; j < inl->length + loc; j ++) { 355 for (j = loc; j < inl->length + loc; j ++) {
267 fputs(char_table[(unsigned char) (para->text[j])],of); 356 fputs(table[(unsigned char) (para->text[j])],of);
268 } 357 }
269 loc = j; 358 loc = j;
270 } 359 }
271 360
272 if (loc < strlen(para->text)) { 361 if (loc < strlen(para->text)) {
273 diff_char(of,cur_char,para->base_character,&flags); 362 diff_char(of,cur_char,para->base_character,&flags);
274 cur_char = para->base_character; 363 cur_char = para->base_character;
275 for (j = loc; j < strlen(para->text); j ++) { 364 for (j = loc; j < strlen(para->text); j ++) {
276 fputs(char_table[(unsigned char) (para->text[j])],of); 365 fputs(table[(unsigned char) (para->text[j])],of);
277 } 366 }
278 } 367 }
279 368
280 flags |= 2; 369 flags |= 2;
281 diff_char(of,cur_char,base_char,&flags); 370 diff_char(of,cur_char,base_char,&flags);
288 377
289 fputs("\n\n", of); 378 fputs("\n\n", of);
290} 379}
291 380
292int psiconv_gen_latex(const char * filename,const psiconv_file file, 381int psiconv_gen_latex(const char * filename,const psiconv_file file,
293 const char *dest) 382 const char *dest, const psiconv_encoding encoding_type)
294{ 383{
295 FILE *of = fopen(filename,"w"); 384 FILE *of = fopen(filename,"w");
296 if (! of) 385 if (! of)
297 return -1; 386 return -1;
387
388 encoding = encoding_type;
298 389
299 if (file->type == psiconv_word_file) { 390 if (file->type == psiconv_word_file) {
300 psiconv_gen_latex_word(of,(psiconv_word_f) file->file); 391 psiconv_gen_latex_word(of,(psiconv_word_f) file->file);
301 } else if (file->type == psiconv_texted_file) { 392 } else if (file->type == psiconv_texted_file) {
302 psiconv_gen_latex_texted(of,(psiconv_texted_f) file->file); 393 psiconv_gen_latex_texted(of,(psiconv_texted_f) file->file);
315 int i; 406 int i;
316 407
317 /* We have nothing better */ 408 /* We have nothing better */
318 base_char = psiconv_basic_character_layout(); 409 base_char = psiconv_basic_character_layout();
319 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 */
320 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 */
321 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++) {
322 para = psiconv_list_get(tf->texted_sec->paragraphs,i); 421 para = psiconv_list_get(tf->texted_sec->paragraphs,i);
323 gen_para(of,para,base_char, NULL); 422 gen_para(of,para,base_char, NULL);
324 } 423 }
325 fputs("\\end{document}",of); 424 fputs("\\end{document}",of);
347 black,white); 446 black,white);
348 447
349 psiconv_free_color(black); 448 psiconv_free_color(black);
350 psiconv_free_color(white); 449 psiconv_free_color(white);
351 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 */
352 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 */
353 460
354 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { 461 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) {
355 para = psiconv_list_get(wf->paragraphs,i); 462 para = psiconv_list_get(wf->paragraphs,i);
356 gen_para(of,para,base_char,wf); 463 gen_para(of,para,base_char,wf);
357 } 464 }

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

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