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-2004 Frodo Looijaard <frodol@dds.nl> |
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" |
26 | |
27 | |
27 | #ifdef DMALLOC |
28 | #ifdef DMALLOC |
28 | #include <dmalloc.h> |
29 | #include <dmalloc.h> |
29 | #endif |
30 | #endif |
30 | |
31 | |
… | |
… | |
39 | static void psiconv_free_paint_data_section_aux(void * section); |
40 | static void psiconv_free_paint_data_section_aux(void * section); |
40 | static void psiconv_free_clipart_section_aux(void * section); |
41 | static void psiconv_free_clipart_section_aux(void * section); |
41 | static void psiconv_free_formula_aux(void *data); |
42 | static void psiconv_free_formula_aux(void *data); |
42 | static void psiconv_free_sheet_worksheet_aux (void *data); |
43 | static void psiconv_free_sheet_worksheet_aux (void *data); |
43 | static void psiconv_free_sheet_variable_aux(void * variable); |
44 | static void psiconv_free_sheet_variable_aux(void * variable); |
|
|
45 | static void psiconv_free_sheet_cell_aux(void *cell); |
|
|
46 | static void psiconv_free_sheet_line_aux(void *line); |
|
|
47 | static void psiconv_free_sheet_worksheet_aux (void *data); |
44 | |
48 | |
45 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
49 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
46 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
50 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
47 | static psiconv_texted_section psiconv_empty_texted_section(void); |
51 | static psiconv_texted_section psiconv_empty_texted_section(void); |
48 | static psiconv_page_header psiconv_empty_page_header(void); |
52 | static psiconv_page_header psiconv_empty_page_header(void); |
… | |
… | |
79 | { |
83 | { |
80 | 0xff, /* red */ |
84 | 0xff, /* red */ |
81 | 0xff, /* green */ |
85 | 0xff, /* green */ |
82 | 0xff, /* blue */ |
86 | 0xff, /* blue */ |
83 | }; |
87 | }; |
|
|
88 | static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', |
|
|
89 | 'N','e','w',' ', |
|
|
90 | 'R','o','m','a','n',0 }; |
84 | static struct psiconv_font_s font = |
91 | static struct psiconv_font_s font = |
85 | { |
92 | { |
86 | "Times New Roman", /* name */ |
93 | font_times, /* name */ |
87 | 3 /* screenfont */ |
94 | 3 /* screenfont */ |
88 | }; |
95 | }; |
89 | struct psiconv_character_layout_s cl = |
96 | struct psiconv_character_layout_s cl = |
90 | { |
97 | { |
91 | &black, /* color */ |
98 | &black, /* color */ |
… | |
… | |
104 | |
111 | |
105 | /* Note: these defaults seem to be hard-coded somewhere outside the |
112 | /* Note: these defaults seem to be hard-coded somewhere outside the |
106 | files themself. */ |
113 | files themself. */ |
107 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
114 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
108 | { |
115 | { |
|
|
116 | static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', |
|
|
117 | 'N','e','w',' ', |
|
|
118 | 'R','o','m','a','n',0 }; |
|
|
119 | |
109 | static struct psiconv_font_s font = |
120 | static struct psiconv_font_s font = |
110 | { |
121 | { |
111 | "Times New Roman", /* name */ |
122 | font_times, /* name */ |
112 | 2 /* screenfont */ |
123 | 2 /* screenfont */ |
113 | }; |
124 | }; |
114 | static struct psiconv_color_s black = |
125 | static struct psiconv_color_s black = |
115 | { |
126 | { |
116 | 0x00, /* red */ |
127 | 0x00, /* red */ |
… | |
… | |
131 | }; |
142 | }; |
132 | static struct psiconv_bullet_s bullet = |
143 | static struct psiconv_bullet_s bullet = |
133 | { |
144 | { |
134 | psiconv_bool_false, /* on */ |
145 | psiconv_bool_false, /* on */ |
135 | 10.0, /* font_size */ |
146 | 10.0, /* font_size */ |
136 | 0x95, /* character */ |
147 | 0x201d, /* character */ |
137 | psiconv_bool_true, /* indent */ |
148 | psiconv_bool_true, /* indent */ |
138 | &black, /* color */ |
149 | &black, /* color */ |
139 | &font, /* font */ |
150 | &font, /* font */ |
140 | }; |
151 | }; |
141 | static struct psiconv_all_tabs_s tabs = |
152 | static struct psiconv_all_tabs_s tabs = |
… | |
… | |
190 | { |
201 | { |
191 | psiconv_font result; |
202 | psiconv_font result; |
192 | if(!(result = malloc(sizeof(*result)))) |
203 | if(!(result = malloc(sizeof(*result)))) |
193 | goto ERROR1; |
204 | goto ERROR1; |
194 | *result = *font; |
205 | *result = *font; |
195 | if (!(result->name = strdup(result->name))) |
206 | if (!(result->name = psiconv_unicode_strdup(result->name))) |
196 | goto ERROR2; |
207 | goto ERROR2; |
197 | return result; |
208 | return result; |
198 | ERROR2: |
209 | ERROR2: |
199 | free(result); |
210 | free(result); |
200 | ERROR1: |
211 | ERROR1: |
… | |
… | |
436 | psiconv_free_style_aux(style); |
447 | psiconv_free_style_aux(style); |
437 | free(style); |
448 | free(style); |
438 | } |
449 | } |
439 | } |
450 | } |
440 | |
451 | |
|
|
452 | void psiconv_free_word_style_list(psiconv_word_style_list style_list) |
|
|
453 | { |
|
|
454 | if (style_list) |
|
|
455 | psiconv_list_free_el(style_list,psiconv_free_style_aux); |
|
|
456 | } |
|
|
457 | |
441 | void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
458 | void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
442 | { |
459 | { |
443 | if (styles) { |
460 | if (styles) { |
444 | psiconv_free_word_style(styles->normal); |
461 | psiconv_free_word_style(styles->normal); |
445 | if (styles->styles) |
462 | psiconv_free_word_style_list(styles->styles); |
446 | psiconv_list_free_el(styles->styles,psiconv_free_style_aux); |
|
|
447 | free(styles); |
463 | free(styles); |
448 | } |
464 | } |
449 | } |
465 | } |
450 | |
466 | |
451 | void psiconv_free_header_section(psiconv_header_section header) |
467 | void psiconv_free_header_section(psiconv_header_section header) |
… | |
… | |
473 | free(section->name); |
489 | free(section->name); |
474 | free(section); |
490 | free(section); |
475 | } |
491 | } |
476 | } |
492 | } |
477 | |
493 | |
|
|
494 | void psiconv_free_object_icon_section(psiconv_object_icon_section section) |
|
|
495 | { |
|
|
496 | if (section) { |
|
|
497 | if (section->icon_name) |
|
|
498 | free(section->icon_name); |
|
|
499 | free(section); |
|
|
500 | } |
|
|
501 | } |
|
|
502 | |
|
|
503 | void psiconv_free_object_display_section(psiconv_object_display_section section) |
|
|
504 | { |
|
|
505 | if (section) |
|
|
506 | free(section); |
|
|
507 | } |
|
|
508 | |
|
|
509 | void psiconv_free_embedded_object_section |
|
|
510 | (psiconv_embedded_object_section object) |
|
|
511 | { |
|
|
512 | if (object) { |
|
|
513 | psiconv_free_object_icon_section(object->icon); |
|
|
514 | psiconv_free_object_display_section(object->display); |
|
|
515 | psiconv_free_file(object->object); |
|
|
516 | free(object); |
|
|
517 | } |
|
|
518 | } |
|
|
519 | |
478 | void psiconv_free_in_line_layout_aux(void * layout) |
520 | void psiconv_free_in_line_layout_aux(void * layout) |
479 | { |
521 | { |
480 | psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); |
522 | psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); |
|
|
523 | psiconv_free_embedded_object_section |
|
|
524 | (((psiconv_in_line_layout) layout)->object); |
481 | } |
525 | } |
482 | |
526 | |
483 | void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
527 | void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
484 | { |
528 | { |
485 | if (layout) { |
529 | if (layout) { |
… | |
… | |
854 | } |
898 | } |
855 | |
899 | |
856 | void psiconv_free_clipart_section_aux(void *section) |
900 | void psiconv_free_clipart_section_aux(void *section) |
857 | { |
901 | { |
858 | if (section) |
902 | if (section) |
859 | free(((psiconv_clipart_section ) section)->picture); |
903 | psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture); |
860 | } |
904 | } |
861 | |
905 | |
862 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
906 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
863 | { |
907 | { |
864 | if (section) { |
908 | if (section) { |
… | |
… | |
917 | const psiconv_font value2) |
961 | const psiconv_font value2) |
918 | { |
962 | { |
919 | if (!value1 || !value2 || !value1->name || !value2->name) |
963 | if (!value1 || !value2 || !value1->name || !value2->name) |
920 | return 1; |
964 | return 1; |
921 | if ((value1->screenfont == value2->screenfont) && |
965 | if ((value1->screenfont == value2->screenfont) && |
922 | !strcmp(value1->name,value2->name)) |
966 | !psiconv_unicode_strcmp(value1->name,value2->name)) |
923 | return 0; |
967 | return 0; |
924 | else |
968 | else |
925 | return 1; |
969 | return 1; |
926 | } |
970 | } |
927 | |
971 | |
… | |
… | |
1315 | psiconv_sketch_section psiconv_empty_sketch_section(void) |
1359 | psiconv_sketch_section psiconv_empty_sketch_section(void) |
1316 | { |
1360 | { |
1317 | psiconv_sketch_section result; |
1361 | psiconv_sketch_section result; |
1318 | if (!(result = malloc(sizeof(*result)))) |
1362 | if (!(result = malloc(sizeof(*result)))) |
1319 | goto ERROR1; |
1363 | goto ERROR1; |
1320 | result->form_xsize = 320; |
1364 | result->displayed_xsize = 320; |
1321 | result->form_ysize = 200; |
1365 | result->displayed_ysize = 200; |
1322 | result->picture_x_offset = result->picture_y_offset = result->picture_xsize = |
1366 | result->picture_data_x_offset = result->picture_data_y_offset = |
1323 | result->picture_ysize = 0; |
1367 | result->form_xsize = result->form_ysize = |
|
|
1368 | result->displayed_size_x_offset = result->displayed_size_y_offset = 0; |
1324 | result->magnification_x = result->magnification_y = 1.0; |
1369 | result->magnification_x = result->magnification_y = 1.0; |
1325 | result->cut_left = result->cut_right = result->cut_top = |
1370 | result->cut_left = result->cut_right = result->cut_top = |
1326 | result->cut_bottom = 0.0; |
1371 | result->cut_bottom = 0.0; |
1327 | if (!(result->picture = psiconv_empty_paint_data_section())) |
1372 | if (!(result->picture = psiconv_empty_paint_data_section())) |
1328 | goto ERROR2; |
1373 | goto ERROR2; |