--- psiconv/trunk/lib/psiconv/data.c 2001/01/22 20:36:50 97 +++ psiconv/trunk/lib/psiconv/data.c 2004/02/09 23:12:58 208 @@ -1,6 +1,6 @@ /* data.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 1999, 2000 Frodo Looijaard + Copyright (c) 1999-2004 Frodo Looijaard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,6 +23,11 @@ #include #include "data.h" #include "list.h" +#include "unicode.h" + +#ifdef DMALLOC +#include +#endif static psiconv_color clone_color(psiconv_color color); static psiconv_font clone_font(psiconv_font font); @@ -34,6 +39,12 @@ static void psiconv_free_paragraph_aux(void * paragraph); static void psiconv_free_paint_data_section_aux(void * section); static void psiconv_free_clipart_section_aux(void * section); +static void psiconv_free_formula_aux(void *data); +static void psiconv_free_sheet_worksheet_aux (void *data); +static void psiconv_free_sheet_variable_aux(void * variable); +static void psiconv_free_sheet_cell_aux(void *cell); +static void psiconv_free_sheet_line_aux(void *line); +static void psiconv_free_sheet_worksheet_aux (void *data); static psiconv_word_styles_section psiconv_empty_word_styles_section(void); static psiconv_text_and_layout psiconv_empty_text_and_layout(void); @@ -43,7 +54,7 @@ static psiconv_word_status_section psiconv_empty_word_status_section(void); static psiconv_word_f psiconv_empty_word_f(void); static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void); -static psiconv_sheet_formula_list psiconv_empty_sheet_formula_list(void); +static psiconv_formula_list psiconv_empty_formula_list(void); static psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void); static psiconv_sheet_f psiconv_empty_sheet_f(void); @@ -74,9 +85,12 @@ 0xff, /* green */ 0xff, /* blue */ }; + static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', + 'N','e','w',' ', + 'R','o','m','a','n',0 }; static struct psiconv_font_s font = { - "Times New Roman", /* name */ + font_times, /* name */ 3 /* screenfont */ }; struct psiconv_character_layout_s cl = @@ -99,9 +113,13 @@ files themself. */ psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) { + static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', + 'N','e','w',' ', + 'R','o','m','a','n',0 }; + static struct psiconv_font_s font = { - "Times New Roman", /* name */ + font_times, /* name */ 2 /* screenfont */ }; static struct psiconv_color_s black = @@ -126,7 +144,7 @@ { psiconv_bool_false, /* on */ 10.0, /* font_size */ - 0x95, /* character */ + 0x201d, /* character */ psiconv_bool_true, /* indent */ &black, /* color */ &font, /* font */ @@ -152,6 +170,7 @@ psiconv_bool_false, /* keep_with_next */ psiconv_bool_false, /* on_next_page */ psiconv_bool_false, /* no_widow_protection */ + psiconv_bool_false, /* wrap_to_fit_cell */ 0.0, /* left_margin */ &bullet, /* bullet */ &no_border, /* left_border */ @@ -184,7 +203,7 @@ if(!(result = malloc(sizeof(*result)))) goto ERROR1; *result = *font; - if (!(result->name = strdup(result->name))) + if (!(result->name = psiconv_unicode_strdup(result->name))) goto ERROR2; return result; ERROR2: @@ -316,6 +335,34 @@ return psiconv_list_get(ss->styles,0xff - nr); } +psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) +{ + return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); +} + +/* TODO: What if a cell is both in a default row and a default column?!? */ +psiconv_sheet_cell_layout psiconv_get_default_layout + (psiconv_sheet_line_list row_defaults, + psiconv_sheet_line_list col_defaults, + psiconv_sheet_cell_layout cell_default, + int row,int col) +{ + int i; + psiconv_sheet_line line; + for (i = 0;i < psiconv_list_length(row_defaults);i++) { + line = psiconv_list_get(row_defaults,i); + if (line->position == row) + return line->layout; + } + for (i = 0;i < psiconv_list_length(col_defaults);i++) { + line = psiconv_list_get(col_defaults,i); + if (line->position == col) + return line->layout; + } + return cell_default; +} + + void psiconv_free_color (psiconv_color color) { if (color) @@ -408,6 +455,7 @@ psiconv_free_word_style(styles->normal); if (styles->styles) psiconv_list_free_el(styles->styles,psiconv_free_style_aux); + free(styles); } } @@ -438,9 +486,37 @@ } } +void psiconv_free_object_icon_section(psiconv_object_icon_section section) +{ + if (section) { + if (section->icon_name) + free(section->icon_name); + free(section); + } +} + +void psiconv_free_object_display_section(psiconv_object_display_section section) +{ + if (section) + free(section); +} + +void psiconv_free_embedded_object_section + (psiconv_embedded_object_section object) +{ + if (object) { + psiconv_free_object_icon_section(object->icon); + psiconv_free_object_display_section(object->display); + psiconv_free_file(object->object); + free(object); + } +} + void psiconv_free_in_line_layout_aux(void * layout) { psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); + psiconv_free_embedded_object_section + (((psiconv_in_line_layout) layout)->object); } void psiconv_free_in_line_layout(psiconv_in_line_layout layout) @@ -547,22 +623,198 @@ free(section); } -void psiconv_free_sheet_formula(psiconv_sheet_formula formula) +void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat) { - if (formula) - free(formula); + if (numberformat) + free(numberformat); +} + +void psiconv_free_sheet_cell_layout(psiconv_sheet_cell_layout layout) +{ + psiconv_free_paragraph_layout(layout->paragraph); + psiconv_free_character_layout(layout->character); + psiconv_free_sheet_numberformat(layout->numberformat); +} + +void psiconv_free_sheet_cell_aux(void *cell) +{ + psiconv_sheet_cell data = cell; + + psiconv_free_sheet_cell_layout(data->layout); + + if ((data->type == psiconv_cell_string) && (data->data.dat_string)) + free(data->data.dat_string); +} + +void psiconv_free_sheet_cell(psiconv_sheet_cell cell) +{ + if (cell) { + psiconv_free_sheet_cell_aux(cell); + free(cell); + } +} + +void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); +} + +void psiconv_free_sheet_line_aux(void *line) +{ + psiconv_sheet_line data = line; + + psiconv_free_sheet_cell_layout(data->layout); +} + +void psiconv_free_sheet_line(psiconv_sheet_line line) +{ + if (line) { + psiconv_free_sheet_line_aux(line); + free(line); + } +} + + +void psiconv_free_sheet_line_list(psiconv_sheet_line_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_line_aux); +} + +void psiconv_free_sheet_grid_break_list(psiconv_sheet_grid_break_list list) +{ + if (list) + psiconv_list_free(list); } -void psiconv_free_sheet_formula_list(psiconv_sheet_formula_list list) +void psiconv_free_sheet_grid_size(psiconv_sheet_grid_size s) +{ + if (s) + free(s); +} + +void psiconv_free_sheet_grid_size_list(psiconv_sheet_grid_size_list list) { if (list) psiconv_list_free(list); } +void psiconv_free_sheet_grid_section(psiconv_sheet_grid_section sec) +{ + if (sec) { + psiconv_free_sheet_grid_size_list(sec->row_heights); + psiconv_free_sheet_grid_size_list(sec->column_heights); + psiconv_free_sheet_grid_break_list(sec->row_page_breaks); + psiconv_free_sheet_grid_break_list(sec->column_page_breaks); + free(sec); + } +} + +void psiconv_free_sheet_worksheet_aux (void *data) +{ + psiconv_sheet_worksheet section = data; + psiconv_free_sheet_cell_layout(section->default_layout); + psiconv_free_sheet_cell_list(section->cells); + psiconv_free_sheet_line_list(section->row_default_layouts); + psiconv_free_sheet_line_list(section->col_default_layouts); + psiconv_free_sheet_grid_section(section->grid); +} + +void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) +{ + if (sheet) { + psiconv_free_sheet_worksheet_aux(sheet); + free(sheet); + } +} + +void psiconv_free_sheet_worksheet_list(psiconv_sheet_worksheet_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_worksheet_aux); +} + +void psiconv_free_formula_aux(void *data) +{ + psiconv_formula formula; + formula = data; + if (formula->type == psiconv_formula_dat_string) + free(formula->data.dat_string); + else if ((formula->type != psiconv_formula_dat_int) && + (formula->type != psiconv_formula_dat_var) && + (formula->type != psiconv_formula_dat_float) && + (formula->type != psiconv_formula_dat_cellref) && + (formula->type != psiconv_formula_dat_cellblock) && + (formula->type != psiconv_formula_dat_vcellblock) && + (formula->type != psiconv_formula_mark_opsep) && + (formula->type != psiconv_formula_mark_opend) && + (formula->type != psiconv_formula_mark_eof) && + (formula->type != psiconv_formula_unknown)) + psiconv_free_formula_list(formula->data.fun_operands); +} + +void psiconv_free_formula(psiconv_formula formula) +{ + if (formula) { + psiconv_free_formula_aux(formula); + free(formula); + } +} + +void psiconv_free_formula_list(psiconv_formula_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_formula_aux); +} + +void psiconv_free_sheet_name_section(psiconv_sheet_name_section section) +{ + if (section) { + if(section->name) + free(section->name); + free(section); + } +} + +void psiconv_free_sheet_info_section(psiconv_sheet_info_section section) +{ + if (section) { + free(section); + } +} + +void psiconv_free_sheet_variable_aux(void * variable) +{ + psiconv_sheet_variable var = variable; + if (var->name) + free(var->name); + if (var->type == psiconv_var_string) + free(var->data.dat_string); +} + +void psiconv_free_sheet_variable(psiconv_sheet_variable var) +{ + if (var) { + psiconv_free_sheet_variable_aux(var); + free(var); + } +} + +void psiconv_free_sheet_variable_list(psiconv_sheet_variable_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_variable_aux); +} + void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) { if (section) { - psiconv_free_sheet_formula_list(section->formulas); + psiconv_free_formula_list(section->formulas); + psiconv_free_sheet_worksheet_list(section->worksheets); + psiconv_free_sheet_name_section(section->name); + psiconv_free_sheet_info_section(section->info); + psiconv_free_sheet_variable_list(section->variables); free(section); } } @@ -643,7 +895,7 @@ void psiconv_free_clipart_section_aux(void *section) { if (section) - free(((psiconv_clipart_section ) section)->picture); + psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture); } void psiconv_free_clipart_section(psiconv_clipart_section section) @@ -706,7 +958,7 @@ if (!value1 || !value2 || !value1->name || !value2->name) return 1; if ((value1->screenfont == value2->screenfont) && - !strcmp(value1->name,value2->name)) + !psiconv_unicode_strcmp(value1->name,value2->name)) return 0; else return 1; @@ -979,9 +1231,9 @@ return result; } -psiconv_sheet_formula_list psiconv_empty_sheet_formula_list(void) +psiconv_formula_list psiconv_empty_formula_list(void) { - return psiconv_list_new(sizeof(struct psiconv_sheet_formula_s)); + return psiconv_list_new(sizeof(struct psiconv_formula_s)); } psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void) @@ -989,7 +1241,7 @@ psiconv_sheet_workbook_section result; if (!(result = malloc(sizeof(*result)))) goto ERROR1; - if (!(result->formulas = psiconv_empty_sheet_formula_list())) + if (!(result->formulas = psiconv_empty_formula_list())) goto ERROR2; return result; ERROR2: @@ -1104,10 +1356,11 @@ psiconv_sketch_section result; if (!(result = malloc(sizeof(*result)))) goto ERROR1; - result->form_xsize = 320; - result->form_ysize = 200; - result->picture_x_offset = result->picture_y_offset = result->picture_xsize = - result->picture_ysize = 0; + result->displayed_xsize = 320; + result->displayed_ysize = 200; + result->picture_data_x_offset = result->picture_data_y_offset = + result->form_xsize = result->form_ysize = + result->displayed_size_x_offset = result->displayed_size_y_offset = 0; result->magnification_x = result->magnification_y = 1.0; result->cut_left = result->cut_right = result->cut_top = result->cut_bottom = 0.0;