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

Diff of /psiconv/trunk/lib/psiconv/generate_common.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 88 Revision 89
135 struct psiconv_paragraph_type_list_s new_type; 135 struct psiconv_paragraph_type_list_s new_type;
136 psiconv_buffer buf_types,buf_elements,buf_inlines; 136 psiconv_buffer buf_types,buf_elements,buf_inlines;
137 psiconv_paragraph paragraph; 137 psiconv_paragraph paragraph;
138 psiconv_in_line_layout in_line; 138 psiconv_in_line_layout in_line;
139 psiconv_word_style style; 139 psiconv_word_style style;
140 psiconv_character_layout para_charlayout;
140 int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length; 141 int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length,thislen,paralen;
141 142
142 if (!value) { 143 if (!value) {
143 psiconv_warn(0,psiconv_buffer_length(buf),"Null text section"); 144 psiconv_warn(0,psiconv_buffer_length(buf),"Null text section");
144 return -PSICONV_E_GENERATE; 145 return -PSICONV_E_GENERATE;
145 } 146 }
171 goto ERROR5; 172 goto ERROR5;
172 } 173 }
173 if ((res = psiconv_write_u32(buf_elements,strlen(paragraph->text)+1))) 174 if ((res = psiconv_write_u32(buf_elements,strlen(paragraph->text)+1)))
174 goto ERROR5; 175 goto ERROR5;
175 176
176 if (psiconv_list_length(paragraph->in_lines)) { 177 if (psiconv_list_length(paragraph->in_lines) > 1) {
177 /* Inline layouts, so we generate a paragraph element and inline 178 /* Inline layouts, so we generate a paragraph element and inline
178 elements */ 179 elements */
179 if ((res = psiconv_write_u8(buf_elements,0x00))) 180 if ((res = psiconv_write_u8(buf_elements,0x00)))
180 goto ERROR5; 181 goto ERROR5;
181 if (!(style = psiconv_get_style(styles,paragraph->base_style))) { 182 if (!(style = psiconv_get_style(styles,paragraph->base_style))) {
193 if ((res = psiconv_write_u32(buf_elements, 194 if ((res = psiconv_write_u32(buf_elements,
194 psiconv_list_length(paragraph->in_lines)))) 195 psiconv_list_length(paragraph->in_lines))))
195 goto ERROR5; 196 goto ERROR5;
196 197
197 /* Generate the inlines. NB: Against what are all settings relative?!? */ 198 /* Generate the inlines. NB: Against what are all settings relative?!? */
199 paralen = 0;
198 for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { 200 for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) {
199 nr_of_inlines ++; 201 nr_of_inlines ++;
200 if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { 202 if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) {
201 psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); 203 psiconv_warn(0,psiconv_buffer_length(buf),
204 "Massive memory corruption");
202 res = -PSICONV_E_OTHER; 205 res = -PSICONV_E_OTHER;
203 goto ERROR5; 206 goto ERROR5;
204 } 207 }
205 if ((res = psiconv_write_u8(buf_inlines,0x00))) 208 if ((res = psiconv_write_u8(buf_inlines,0x00)))
206 goto ERROR5; 209 goto ERROR5;
210 thislen = in_line->length;
211 paralen += thislen;
212 /* If this is the last in_line, we need to make sure that the
213 complete length of all inlines equals the text length */
214 if (j == psiconv_list_length(paragraph->in_lines)-1) {
215 if (paralen > strlen(paragraph->text)+1) {
216 res = -PSICONV_E_GENERATE;
217 goto ERROR5;
218 }
219 thislen += strlen(paragraph->text)+1-paralen;
220 }
207 if ((res = psiconv_write_u32(buf_inlines,in_line->length))) 221 if ((res = psiconv_write_u32(buf_inlines,thislen)))
208 goto ERROR5; 222 goto ERROR5;
209 if ((res = psiconv_write_character_layout_list(buf_inlines, 223 if ((res = psiconv_write_character_layout_list(buf_inlines,
210 in_line->layout, 224 in_line->layout,
211 style->character))) 225 style->character)))
212 goto ERROR5; 226 goto ERROR5;
213 } 227 }
214 } else { 228 } else {
215 /* No inline layouts, so we generate a paragraph type list */ 229 /* No inline layouts (or only 1), so we generate a paragraph type list */
216 para_type = 0; 230 para_type = 0;
231 /* Set para_charlayout to the correct character-level layout */
232 if (psiconv_list_length(paragraph->in_lines) == 0)
233 para_charlayout = paragraph->base_character;
234 else {
235 if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) {
236 psiconv_warn(0,psiconv_buffer_length(buf),
237 "Massive memory corruption");
238 res = -PSICONV_E_OTHER;
239 goto ERROR5;
240 }
241 para_charlayout = in_line->layout;
242 }
217 for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { 243 for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) {
218 if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { 244 if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) {
219 psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); 245 psiconv_warn(0,psiconv_buffer_length(buf),
246 "Massive memory corruption");
220 res = -PSICONV_E_OTHER; 247 res = -PSICONV_E_OTHER;
221 goto ERROR5; 248 goto ERROR5;
222 } 249 }
223 if ((paragraph->base_style == paragraph_type->style) && 250 if ((paragraph->base_style == paragraph_type->style) &&
224 !psiconv_compare_character_layout(paragraph->base_character, 251 !psiconv_compare_character_layout(para_charlayout,
225 paragraph_type->character) && 252 paragraph_type->character) &&
226 !psiconv_compare_paragraph_layout(paragraph->base_paragraph, 253 !psiconv_compare_paragraph_layout(paragraph->base_paragraph,
227 paragraph_type->paragraph)) { 254 paragraph_type->paragraph)) {
228 para_type = paragraph_type->nr; 255 para_type = paragraph_type->nr;
229 break; 256 break;
232 if (!para_type) { 259 if (!para_type) {
233 /* We need to add a new entry */ 260 /* We need to add a new entry */
234 para_type = new_type.nr = j+1; 261 para_type = new_type.nr = j+1;
235 /* No need to copy them, we won't change them anyway */ 262 /* No need to copy them, we won't change them anyway */
236 new_type.paragraph = paragraph->base_paragraph; 263 new_type.paragraph = paragraph->base_paragraph;
237 new_type.character = paragraph->base_character; 264 new_type.character = para_charlayout;
238 new_type.style = paragraph->base_style; 265 new_type.style = paragraph->base_style;
239 paragraph_type = &new_type; 266 paragraph_type = &new_type;
240 if ((res = psiconv_list_add(paragraph_type_list,paragraph_type))) 267 if ((res = psiconv_list_add(paragraph_type_list,paragraph_type)))
241 goto ERROR5; 268 goto ERROR5;
242 if ((res = psiconv_write_u32(buf_types,paragraph_type->nr))) 269 if ((res = psiconv_write_u32(buf_types,paragraph_type->nr)))

Legend:
Removed from v.88  
changed lines
  Added in v.89

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