/[public]/psiconv/trunk/lib/psiconv/generate_word.c
ViewVC logotype

Contents of /psiconv/trunk/lib/psiconv/generate_word.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 85 - (show annotations)
Thu Dec 28 00:29:23 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 5283 byte(s)
(Frodo) Life is beautiful: Word documents now seem to be generated
        flawlessly!

1 /*
2 generate_word.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>
4
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
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "config.h"
21 #include "compat.h"
22
23 #include <stdlib.h>
24
25 #include "generate_routines.h"
26 #include "error.h"
27
28 int psiconv_write_word_status_section(psiconv_buffer buf,
29 psiconv_word_status_section value)
30 {
31 int res;
32
33 if (!value) {
34 psiconv_warn(0,psiconv_buffer_length(buf),"Null word status section");
35 return -PSICONV_E_GENERATE;
36 }
37
38 if ((res = psiconv_write_u8(buf,0x02)))
39 return res;
40 if ((res = psiconv_write_u8(buf,(value->show_tabs?0x01:0x00) |
41 (value->show_spaces?0x02:0x00) |
42 (value->show_paragraph_ends?0x04:0x00) |
43 (value->show_line_breaks?0x08:0x00) |
44 (value->show_hard_minus?0x20:0x00) |
45 (value->show_hard_space?0x40:0x00))))
46 return res;
47 if ((res = psiconv_write_u8(buf,(value->show_full_pictures?0x01:0x00) |
48 (value->show_full_graphs?0x02:0x00))))
49 return res;
50 if ((res = psiconv_write_bool(buf,value->show_top_toolbar)))
51 return res;
52 if ((res = psiconv_write_bool(buf,value->show_side_toolbar)))
53 return res;
54 if ((res = psiconv_write_u8(buf,(value->fit_lines_to_screen?0x08:0x00))))
55 return res;
56 if ((res = psiconv_write_u32(buf,value->cursor_position)))
57 return res;
58 return psiconv_write_u32(buf,value->display_size);
59 }
60
61 int psiconv_write_word_styles_section(psiconv_buffer buf,
62 psiconv_word_styles_section value)
63 {
64 int res,i;
65 psiconv_word_style style;
66 psiconv_paragraph_layout basepara;
67 psiconv_character_layout basechar;
68 psiconv_font font;
69
70
71 if (!value || !value->normal || !value->styles) {
72 psiconv_warn(0,psiconv_buffer_length(buf),"Null word styles section");
73 res = -PSICONV_E_GENERATE;
74 goto ERROR1;
75 }
76
77 if (!(basepara=psiconv_basic_paragraph_layout())) {
78 res = -PSICONV_E_NOMEM;
79 goto ERROR1;
80 }
81
82 if (!(basechar=psiconv_basic_character_layout())) {
83 res = -PSICONV_E_NOMEM;
84 goto ERROR2;
85 }
86
87
88 if ((res = psiconv_write_paragraph_layout_list(buf,value->normal->paragraph,
89 basepara)))
90 goto ERROR3;
91 /* Always generate the font for Normal */
92 font = basechar->font;
93 basechar->font = NULL;
94 res = psiconv_write_character_layout_list(buf,value->normal->character,
95 basechar);
96 basechar->font = font;
97 if (res)
98 goto ERROR3;
99 if ((res = psiconv_write_u32(buf,value->normal->hotkey)))
100 goto ERROR3;
101 if ((res = psiconv_write_u8(buf,psiconv_list_length(value->styles))))
102 goto ERROR3;
103
104
105
106 for (i = 0; i < psiconv_list_length(value->styles); i++) {
107 if (!(style = psiconv_list_get(value->styles,i))) {
108 psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption");
109 res = -PSICONV_E_OTHER;
110 goto ERROR3;
111 }
112 if ((res = psiconv_write_u32(buf,style->hotkey)))
113 goto ERROR3;
114 }
115 if ((res = psiconv_write_u8(buf,psiconv_list_length(value->styles))))
116 goto ERROR3;
117 for (i = 0; i < psiconv_list_length(value->styles); i++) {
118 if (!(style = psiconv_list_get(value->styles,i))) {
119 psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption");
120 res = -PSICONV_E_OTHER;
121 goto ERROR3;
122 }
123 if (!style->name) {
124 psiconv_warn(0,psiconv_buffer_length(buf),"Null style name");
125 res = -PSICONV_E_GENERATE;
126 goto ERROR3;
127 }
128 if ((res = psiconv_write_string(buf,style->name)))
129 goto ERROR3;
130 if ((res = psiconv_write_u32(buf,style->built_in?PSICONV_ID_STYLE_BUILT_IN:
131 PSICONV_ID_STYLE_REMOVABLE)))
132 goto ERROR3;
133 if ((res = psiconv_write_u32(buf,style->outline_level)))
134 goto ERROR3;
135 if ((res = psiconv_write_character_layout_list(buf,style->character,
136 value->normal->character)))
137 goto ERROR3;
138 if ((res = psiconv_write_paragraph_layout_list(buf,style->paragraph,
139 value->normal->paragraph)))
140 goto ERROR3;
141 }
142
143 for (i = 0; i < psiconv_list_length(value->styles); i++)
144 if ((res = psiconv_write_u8(buf,0xff)))
145 goto ERROR3;
146 res = -PSICONV_E_OK;
147
148 ERROR3:
149 psiconv_free_character_layout(basechar);
150 ERROR2:
151 psiconv_free_paragraph_layout(basepara);
152 ERROR1:
153 return res;
154 }

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