1 | /* |
1 | /* |
2 | data.c - Part of psiconv, a PSION 5 file formats converter |
2 | data.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999-2005 Frodo Looijaard <frodo@frodo.looijaard.name> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
21 | #include "compat.h" |
21 | #include "compat.h" |
22 | #include <stdlib.h> |
22 | #include <stdlib.h> |
23 | #include <string.h> |
23 | #include <string.h> |
24 | #include "data.h" |
24 | #include "data.h" |
25 | #include "list.h" |
25 | #include "list.h" |
|
|
26 | #include "unicode.h" |
|
|
27 | #include "error.h" |
26 | |
28 | |
27 | #ifdef DMALLOC |
29 | #ifdef DMALLOC |
28 | #include <dmalloc.h> |
30 | #include <dmalloc.h> |
29 | #endif |
31 | #endif |
30 | |
32 | |
… | |
… | |
39 | static void psiconv_free_paint_data_section_aux(void * section); |
41 | static void psiconv_free_paint_data_section_aux(void * section); |
40 | static void psiconv_free_clipart_section_aux(void * section); |
42 | static void psiconv_free_clipart_section_aux(void * section); |
41 | static void psiconv_free_formula_aux(void *data); |
43 | static void psiconv_free_formula_aux(void *data); |
42 | static void psiconv_free_sheet_worksheet_aux (void *data); |
44 | static void psiconv_free_sheet_worksheet_aux (void *data); |
43 | static void psiconv_free_sheet_variable_aux(void * variable); |
45 | static void psiconv_free_sheet_variable_aux(void * variable); |
|
|
46 | static void psiconv_free_sheet_cell_aux(void *cell); |
|
|
47 | static void psiconv_free_sheet_line_aux(void *line); |
|
|
48 | static void psiconv_free_sheet_worksheet_aux (void *data); |
44 | |
49 | |
45 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
50 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
46 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
51 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
47 | static psiconv_texted_section psiconv_empty_texted_section(void); |
52 | static psiconv_texted_section psiconv_empty_texted_section(void); |
48 | static psiconv_page_header psiconv_empty_page_header(void); |
53 | static psiconv_page_header psiconv_empty_page_header(void); |
… | |
… | |
79 | { |
84 | { |
80 | 0xff, /* red */ |
85 | 0xff, /* red */ |
81 | 0xff, /* green */ |
86 | 0xff, /* green */ |
82 | 0xff, /* blue */ |
87 | 0xff, /* blue */ |
83 | }; |
88 | }; |
|
|
89 | static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', |
|
|
90 | 'N','e','w',' ', |
|
|
91 | 'R','o','m','a','n',0 }; |
84 | static struct psiconv_font_s font = |
92 | static struct psiconv_font_s font = |
85 | { |
93 | { |
86 | "Times New Roman", /* name */ |
94 | font_times, /* name */ |
87 | 3 /* screenfont */ |
95 | 3 /* screenfont */ |
88 | }; |
96 | }; |
89 | struct psiconv_character_layout_s cl = |
97 | struct psiconv_character_layout_s cl = |
90 | { |
98 | { |
91 | &black, /* color */ |
99 | &black, /* color */ |
… | |
… | |
104 | |
112 | |
105 | /* Note: these defaults seem to be hard-coded somewhere outside the |
113 | /* Note: these defaults seem to be hard-coded somewhere outside the |
106 | files themself. */ |
114 | files themself. */ |
107 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
115 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
108 | { |
116 | { |
|
|
117 | static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', |
|
|
118 | 'N','e','w',' ', |
|
|
119 | 'R','o','m','a','n',0 }; |
|
|
120 | |
109 | static struct psiconv_font_s font = |
121 | static struct psiconv_font_s font = |
110 | { |
122 | { |
111 | "Times New Roman", /* name */ |
123 | font_times, /* name */ |
112 | 2 /* screenfont */ |
124 | 2 /* screenfont */ |
113 | }; |
125 | }; |
114 | static struct psiconv_color_s black = |
126 | static struct psiconv_color_s black = |
115 | { |
127 | { |
116 | 0x00, /* red */ |
128 | 0x00, /* red */ |
… | |
… | |
131 | }; |
143 | }; |
132 | static struct psiconv_bullet_s bullet = |
144 | static struct psiconv_bullet_s bullet = |
133 | { |
145 | { |
134 | psiconv_bool_false, /* on */ |
146 | psiconv_bool_false, /* on */ |
135 | 10.0, /* font_size */ |
147 | 10.0, /* font_size */ |
136 | 0x95, /* character */ |
148 | 0x201d, /* character */ |
137 | psiconv_bool_true, /* indent */ |
149 | psiconv_bool_true, /* indent */ |
138 | &black, /* color */ |
150 | &black, /* color */ |
139 | &font, /* font */ |
151 | &font, /* font */ |
140 | }; |
152 | }; |
141 | static struct psiconv_all_tabs_s tabs = |
153 | static struct psiconv_all_tabs_s tabs = |
… | |
… | |
190 | { |
202 | { |
191 | psiconv_font result; |
203 | psiconv_font result; |
192 | if(!(result = malloc(sizeof(*result)))) |
204 | if(!(result = malloc(sizeof(*result)))) |
193 | goto ERROR1; |
205 | goto ERROR1; |
194 | *result = *font; |
206 | *result = *font; |
195 | if (!(result->name = strdup(result->name))) |
207 | if (!(result->name = psiconv_unicode_strdup(result->name))) |
196 | goto ERROR2; |
208 | goto ERROR2; |
197 | return result; |
209 | return result; |
198 | ERROR2: |
210 | ERROR2: |
199 | free(result); |
211 | free(result); |
200 | ERROR1: |
212 | ERROR1: |
… | |
… | |
322 | return ss->normal; |
334 | return ss->normal; |
323 | else |
335 | else |
324 | return psiconv_list_get(ss->styles,0xff - nr); |
336 | return psiconv_list_get(ss->styles,0xff - nr); |
325 | } |
337 | } |
326 | |
338 | |
|
|
339 | int psiconv_find_style(const psiconv_word_styles_section ss, |
|
|
340 | const psiconv_ucs2 *name, |
|
|
341 | int *nr) |
|
|
342 | { |
|
|
343 | const psiconv_ucs2 value_normal[] = { 'N','o','r','m','a','l',0 }; |
|
|
344 | psiconv_word_style style; |
|
|
345 | int i; |
|
|
346 | |
|
|
347 | if (!nr) |
|
|
348 | return PSICONV_E_OTHER; |
|
|
349 | if(!psiconv_unicode_strcmp(value_normal,name)) { |
|
|
350 | *nr = 0; |
|
|
351 | return 0; |
|
|
352 | } |
|
|
353 | for (i = 0; i < psiconv_list_length(ss->styles);i++) { |
|
|
354 | if (!(style = psiconv_list_get(ss->styles,i))) |
|
|
355 | return PSICONV_E_NOMEM; |
|
|
356 | if (!psiconv_unicode_strcmp(style->name,name)) { |
|
|
357 | *nr = 0xff - i; |
|
|
358 | return 0; |
|
|
359 | } |
|
|
360 | } |
|
|
361 | *nr = 0; |
|
|
362 | return PSICONV_E_OTHER; |
|
|
363 | } |
|
|
364 | |
|
|
365 | |
327 | psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) |
366 | psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) |
328 | { |
367 | { |
329 | return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); |
368 | return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); |
330 | } |
369 | } |
331 | |
370 | |
… | |
… | |
436 | psiconv_free_style_aux(style); |
475 | psiconv_free_style_aux(style); |
437 | free(style); |
476 | free(style); |
438 | } |
477 | } |
439 | } |
478 | } |
440 | |
479 | |
|
|
480 | void psiconv_free_word_style_list(psiconv_word_style_list style_list) |
|
|
481 | { |
|
|
482 | if (style_list) |
|
|
483 | psiconv_list_free_el(style_list,psiconv_free_style_aux); |
|
|
484 | } |
|
|
485 | |
441 | void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
486 | void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
442 | { |
487 | { |
443 | if (styles) { |
488 | if (styles) { |
444 | psiconv_free_word_style(styles->normal); |
489 | psiconv_free_word_style(styles->normal); |
445 | if (styles->styles) |
490 | psiconv_free_word_style_list(styles->styles); |
446 | psiconv_list_free_el(styles->styles,psiconv_free_style_aux); |
|
|
447 | free(styles); |
491 | free(styles); |
448 | } |
492 | } |
449 | } |
493 | } |
450 | |
494 | |
451 | void psiconv_free_header_section(psiconv_header_section header) |
495 | void psiconv_free_header_section(psiconv_header_section header) |
… | |
… | |
488 | { |
532 | { |
489 | if (section) |
533 | if (section) |
490 | free(section); |
534 | free(section); |
491 | } |
535 | } |
492 | |
536 | |
493 | void psiconv_free_object(psiconv_object object) |
537 | void psiconv_free_embedded_object_section |
|
|
538 | (psiconv_embedded_object_section object) |
494 | { |
539 | { |
495 | if (object) { |
540 | if (object) { |
496 | psiconv_free_object_icon_section(object->icon); |
541 | psiconv_free_object_icon_section(object->icon); |
497 | psiconv_free_object_display_section(object->display); |
542 | psiconv_free_object_display_section(object->display); |
498 | psiconv_free_file(object->object); |
543 | psiconv_free_file(object->object); |
… | |
… | |
501 | } |
546 | } |
502 | |
547 | |
503 | void psiconv_free_in_line_layout_aux(void * layout) |
548 | void psiconv_free_in_line_layout_aux(void * layout) |
504 | { |
549 | { |
505 | psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); |
550 | psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); |
506 | psiconv_free_object(((psiconv_in_line_layout) layout)->object); |
551 | psiconv_free_embedded_object_section |
|
|
552 | (((psiconv_in_line_layout) layout)->object); |
507 | } |
553 | } |
508 | |
554 | |
509 | void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
555 | void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
510 | { |
556 | { |
511 | if (layout) { |
557 | if (layout) { |
… | |
… | |
880 | } |
926 | } |
881 | |
927 | |
882 | void psiconv_free_clipart_section_aux(void *section) |
928 | void psiconv_free_clipart_section_aux(void *section) |
883 | { |
929 | { |
884 | if (section) |
930 | if (section) |
885 | free(((psiconv_clipart_section ) section)->picture); |
931 | psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture); |
886 | } |
932 | } |
887 | |
933 | |
888 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
934 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
889 | { |
935 | { |
890 | if (section) { |
936 | if (section) { |
… | |
… | |
943 | const psiconv_font value2) |
989 | const psiconv_font value2) |
944 | { |
990 | { |
945 | if (!value1 || !value2 || !value1->name || !value2->name) |
991 | if (!value1 || !value2 || !value1->name || !value2->name) |
946 | return 1; |
992 | return 1; |
947 | if ((value1->screenfont == value2->screenfont) && |
993 | if ((value1->screenfont == value2->screenfont) && |
948 | !strcmp(value1->name,value2->name)) |
994 | !psiconv_unicode_strcmp(value1->name,value2->name)) |
949 | return 0; |
995 | return 0; |
950 | else |
996 | else |
951 | return 1; |
997 | return 1; |
952 | } |
998 | } |
953 | |
999 | |