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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 351 - (hide annotations)
Wed Oct 22 19:53:40 2014 UTC (9 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 6814 byte(s)
(Frodo) Update copyright year in all source files

1 frodo 76 /*
2     generate_word.c - Part of psiconv, a PSION 5 file formats converter
3 frodo 351 Copyright (c) 2000-2014 Frodo Looijaard <frodo@frodo.looijaard.name>
4 frodo 76
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 frodo 142 #ifdef DMALLOC
29     #include <dmalloc.h>
30     #endif
31    
32    
33 frodo 168 int psiconv_write_word_status_section(const psiconv_config config,
34 frodo 184 psiconv_buffer buf, int lev,
35 frodo 168 psiconv_word_status_section value)
36 frodo 76 {
37     int res;
38    
39 frodo 184 psiconv_progress(config,lev,0,"Writing word status section");
40    
41 frodo 76 if (!value) {
42 frodo 231 psiconv_error(config,lev,0,"Null word status section");
43     res = -PSICONV_E_GENERATE;
44     goto ERROR;
45 frodo 76 }
46    
47 frodo 184 if ((res = psiconv_write_u8(config,buf,lev+1,0x02)))
48 frodo 231 goto ERROR;
49 frodo 184 if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_tabs?0x01:0x00) |
50 frodo 76 (value->show_spaces?0x02:0x00) |
51     (value->show_paragraph_ends?0x04:0x00) |
52     (value->show_line_breaks?0x08:0x00) |
53     (value->show_hard_minus?0x20:0x00) |
54     (value->show_hard_space?0x40:0x00))))
55 frodo 231 goto ERROR;
56 frodo 184 if ((res = psiconv_write_u8(config,buf,lev+1,(value->show_full_pictures?0x01:0x00) |
57 frodo 76 (value->show_full_graphs?0x02:0x00))))
58 frodo 231 goto ERROR;
59 frodo 184 if ((res = psiconv_write_bool(config,buf,lev+1,value->show_top_toolbar)))
60 frodo 231 goto ERROR;
61 frodo 184 if ((res = psiconv_write_bool(config,buf,lev+1,value->show_side_toolbar)))
62 frodo 231 goto ERROR;
63 frodo 184 if ((res = psiconv_write_u8(config,buf,lev+1,(value->fit_lines_to_screen?0x08:0x00))))
64 frodo 231 goto ERROR;
65 frodo 184 if ((res = psiconv_write_u32(config,buf,lev+1,value->cursor_position)))
66 frodo 231 goto ERROR;
67     if ((res = psiconv_write_u32(config,buf,lev+1,value->display_size)))
68     goto ERROR;
69     psiconv_progress(config,lev,0,"End of word status section");
70     return 0;
71    
72     ERROR:
73     psiconv_error(config,lev,0,"Writing of word status section failed");
74     return res;
75 frodo 76 }
76    
77 frodo 168 int psiconv_write_word_styles_section(const psiconv_config config,
78 frodo 184 psiconv_buffer buf, int lev,
79 frodo 76 psiconv_word_styles_section value)
80     {
81 frodo 224 int res,i,j;
82 frodo 76 psiconv_word_style style;
83     psiconv_paragraph_layout basepara;
84     psiconv_character_layout basechar;
85 frodo 85 psiconv_font font;
86 frodo 224 psiconv_u32 buflen;
87 frodo 76
88 frodo 184 psiconv_progress(config,lev,0,"Writing word styles section");
89 frodo 76
90     if (!value || !value->normal || !value->styles) {
91 frodo 231 psiconv_error(config,lev,0,"Null word styles section");
92 frodo 76 res = -PSICONV_E_GENERATE;
93     goto ERROR1;
94     }
95    
96     if (!(basepara=psiconv_basic_paragraph_layout())) {
97 frodo 233 psiconv_error(config,lev+1,0,"Out of memory error");
98 frodo 76 res = -PSICONV_E_NOMEM;
99     goto ERROR1;
100     }
101    
102     if (!(basechar=psiconv_basic_character_layout())) {
103 frodo 233 psiconv_error(config,lev+1,0,"Out of memory error");
104 frodo 76 res = -PSICONV_E_NOMEM;
105     goto ERROR2;
106     }
107    
108    
109 frodo 231 if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,
110     value->normal->paragraph,
111 frodo 76 basepara)))
112     goto ERROR3;
113 frodo 85 /* Always generate the font for Normal */
114     font = basechar->font;
115     basechar->font = NULL;
116 frodo 231 res = psiconv_write_character_layout_list(config,buf,lev+1,
117     value->normal->character,
118     basechar);
119 frodo 85 basechar->font = font;
120     if (res)
121 frodo 76 goto ERROR3;
122 frodo 224 buflen = psiconv_buffer_length(buf);
123 frodo 217 if ((res = psiconv_unicode_write_char(config,buf,lev+1,
124     value->normal->hotkey)))
125 frodo 76 goto ERROR3;
126 frodo 224 for (j = psiconv_buffer_length(buf) - buflen; j < 4; j++)
127     if ((res = psiconv_write_u8(config,buf,lev+1,0)))
128     goto ERROR3;
129    
130 frodo 231 if ((res = psiconv_write_u8(config,buf,lev+1,
131     psiconv_list_length(value->styles))))
132 frodo 76 goto ERROR3;
133    
134    
135    
136     for (i = 0; i < psiconv_list_length(value->styles); i++) {
137     if (!(style = psiconv_list_get(value->styles,i))) {
138 frodo 233 psiconv_error(config,lev,0,"Data structure corruption");
139 frodo 184 res = -PSICONV_E_NOMEM;
140 frodo 76 goto ERROR3;
141     }
142 frodo 224 buflen = psiconv_buffer_length(buf);
143 frodo 217 if ((res = psiconv_unicode_write_char(config,buf,lev+1,style->hotkey)))
144 frodo 76 goto ERROR3;
145 frodo 224 for (j = psiconv_buffer_length(buf) - buflen; j < 4; j++)
146     if ((res = psiconv_write_u8(config,buf,lev+1,0)))
147     goto ERROR3;
148 frodo 76 }
149 frodo 184 if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_list_length(value->styles))))
150 frodo 76 goto ERROR3;
151     for (i = 0; i < psiconv_list_length(value->styles); i++) {
152     if (!(style = psiconv_list_get(value->styles,i))) {
153 frodo 233 psiconv_error(config,lev,0,"Data structure corruption");
154 frodo 184 res = -PSICONV_E_NOMEM;
155 frodo 76 goto ERROR3;
156     }
157     if (!style->name) {
158 frodo 231 psiconv_error(config,lev,0,"Null style name");
159 frodo 76 res = -PSICONV_E_GENERATE;
160     goto ERROR3;
161     }
162 frodo 184 if ((res = psiconv_write_string(config,buf,lev+1,style->name)))
163 frodo 76 goto ERROR3;
164 frodo 184 if ((res = psiconv_write_u32(config,buf,lev+1,style->built_in?PSICONV_ID_STYLE_BUILT_IN:
165 frodo 76 PSICONV_ID_STYLE_REMOVABLE)))
166     goto ERROR3;
167 frodo 184 if ((res = psiconv_write_u32(config,buf,lev+1,style->outline_level)))
168 frodo 76 goto ERROR3;
169 frodo 184 if ((res = psiconv_write_character_layout_list(config,buf,lev+1,style->character,
170 frodo 76 value->normal->character)))
171     goto ERROR3;
172 frodo 184 if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,style->paragraph,
173 frodo 76 value->normal->paragraph)))
174     goto ERROR3;
175     }
176    
177 frodo 83 for (i = 0; i < psiconv_list_length(value->styles); i++)
178 frodo 184 if ((res = psiconv_write_u8(config,buf,lev+1,0xff)))
179 frodo 83 goto ERROR3;
180     res = -PSICONV_E_OK;
181    
182 frodo 76 ERROR3:
183     psiconv_free_character_layout(basechar);
184     ERROR2:
185     psiconv_free_paragraph_layout(basepara);
186     ERROR1:
187 frodo 231 if (res)
188     psiconv_error(config,lev,0,"Writing of word styles section failed");
189     else
190     psiconv_progress(config,lev,0,"End of word styles section");
191 frodo 76 return res;
192     }

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