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

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

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

Revision 79 Revision 231
1/* 1/*
2 generate_page.c - Part of psiconv, a PSION 5 file formats converter 2 generate_page.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 2000-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.
24#include <string.h> 24#include <string.h>
25 25
26#include "generate_routines.h" 26#include "generate_routines.h"
27#include "error.h" 27#include "error.h"
28 28
29#ifdef DMALLOC
30#include <dmalloc.h>
31#endif
29 32
33
34
30int psiconv_write_page_header(psiconv_buffer buf, 35int psiconv_write_page_header(const psiconv_config config,
36 psiconv_buffer buf, int lev,
31 const psiconv_page_header value) 37 const psiconv_page_header value,
38 psiconv_buffer *extra_buf)
32{ 39{
33 int res; 40 int res;
34 psiconv_paragraph_layout basepara; 41 psiconv_paragraph_layout basepara;
35 psiconv_character_layout basechar; 42 psiconv_character_layout basechar;
36 43
44 psiconv_progress(config,lev,0,"Writing page header");
45
37 if (!value) { 46 if (!value) {
38 psiconv_warn(0,psiconv_buffer_length(buf),"Null page header"); 47 psiconv_error(config,lev,0,"Null page header");
39 res = -PSICONV_E_GENERATE; 48 res = -PSICONV_E_GENERATE;
40 goto ERROR1; 49 goto ERROR1;
41 } 50 }
42 51
43 if (!(basepara=psiconv_basic_paragraph_layout())) { 52 if (!(basepara=psiconv_basic_paragraph_layout())) {
48 res = -PSICONV_E_NOMEM; 57 res = -PSICONV_E_NOMEM;
49 goto ERROR2; 58 goto ERROR2;
50 } 59 }
51 60
52 /* Unknown byte */ 61 /* Unknown byte */
53 if ((res = psiconv_write_u8(buf,0x01))) 62 if ((res = psiconv_write_u8(config,buf,lev+1,0x01)))
54 goto ERROR3; 63 goto ERROR3;
55 if ((res = psiconv_write_bool(buf,value->on_first_page))) 64 if ((res = psiconv_write_bool(config,buf,lev+1,value->on_first_page)))
56 goto ERROR3; 65 goto ERROR3;
57 /* Three unknown bytes */ 66 /* Three unknown bytes */
58 if ((res = psiconv_write_u8(buf,0x00))) 67 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
59 goto ERROR3; 68 goto ERROR3;
60 if ((res = psiconv_write_u8(buf,0x00))) 69 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
61 goto ERROR3; 70 goto ERROR3;
62 if ((res = psiconv_write_u8(buf,0x00))) 71 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
63 goto ERROR3; 72 goto ERROR3;
64 if ((res = psiconv_write_paragraph_layout_list(buf, 73 if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,
65 value->base_paragraph_layout,basepara))) 74 value->base_paragraph_layout,basepara)))
66 goto ERROR3; 75 goto ERROR3;
67 if ((res = psiconv_write_character_layout_list(buf, 76 if ((res = psiconv_write_character_layout_list(config,buf,lev+1,
68 value->base_character_layout,basechar))) 77 value->base_character_layout,basechar)))
69 goto ERROR3; 78 goto ERROR3;
70 res = psiconv_write_texted_section(buf,value->text, 79 res = psiconv_write_texted_section(config,buf,lev+1,value->text,
71 value->base_character_layout, 80 value->base_character_layout,
72 value->base_paragraph_layout); 81 value->base_paragraph_layout,extra_buf);
73ERROR3: 82ERROR3:
74 psiconv_free_character_layout(basechar); 83 psiconv_free_character_layout(basechar);
75ERROR2: 84ERROR2:
76 psiconv_free_paragraph_layout(basepara); 85 psiconv_free_paragraph_layout(basepara);
77ERROR1: 86ERROR1:
87 if (res)
88 psiconv_error(config,lev,0,"Writing of page header failed");
89 else
90 psiconv_progress(config,lev,0,"End of page header");
78 return res; 91 return res;
79} 92}
80 93
81int psiconv_write_page_layout_section(psiconv_buffer buf, 94int psiconv_write_page_layout_section(const psiconv_config config,
95 psiconv_buffer buf, int lev,
82 const psiconv_page_layout_section value) 96 const psiconv_page_layout_section value)
83{ 97{
84 int res; 98 int res;
99 psiconv_buffer header_buf,footer_buf;
100
101 psiconv_progress(config,lev,0,"Writing page layout section");
85 102
86 if (!value) { 103 if (!value) {
87 psiconv_warn(0,psiconv_buffer_length(buf),"Null page section"); 104 psiconv_error(config,lev,0,"Null page section");
88 return -PSICONV_E_GENERATE; 105 res = -PSICONV_E_GENERATE;
106 goto ERROR1;
89 } 107 }
90 108
91 if ((res = psiconv_write_u32(buf,value->first_page_nr))) 109 if ((res = psiconv_write_u32(config,buf,lev+1,value->first_page_nr)))
110 goto ERROR1;
111 if ((res = psiconv_write_length(config,buf,lev+1,value->header_dist)))
112 goto ERROR1;
113 if ((res = psiconv_write_length(config,buf,lev+1,value->footer_dist)))
114 goto ERROR1;
115 if ((res = psiconv_write_length(config,buf,lev+1,value->left_margin)))
116 goto ERROR1;
117 if ((res = psiconv_write_length(config,buf,lev+1,value->right_margin)))
118 goto ERROR1;
119 if ((res = psiconv_write_length(config,buf,lev+1,value->top_margin)))
120 goto ERROR1;
121 if ((res = psiconv_write_length(config,buf,lev+1,value->bottom_margin)))
122 goto ERROR1;
123 if ((res = psiconv_write_page_header(config,buf,lev+1,value->header,&header_buf)))
124 goto ERROR1;
125 if ((res = psiconv_write_page_header(config,buf,lev+1,value->footer,&footer_buf)))
126 goto ERROR2;
127 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_PAGE_DIMENSIONS2)))
128 goto ERROR3;
129 if ((res = psiconv_write_length(config,buf,lev+1,value->page_width)))
130 goto ERROR3;
131 if ((res = psiconv_write_length(config,buf,lev+1,value->page_height)))
132 goto ERROR3;
133 if ((res = psiconv_write_bool(config,buf,lev+1,value->landscape)))
134 goto ERROR3;
135 if ((res = psiconv_buffer_concat(buf,header_buf)))
136 goto ERROR3;
137 res = psiconv_buffer_concat(buf,footer_buf);
138
139
140ERROR3:
141 psiconv_buffer_free(footer_buf);
142ERROR2:
143 psiconv_buffer_free(header_buf);
144ERROR1:
145 if (res)
146 psiconv_error(config,lev,0,"Writing of page layout section failed");
147 else
148 psiconv_progress(config,lev,0,"End of page layout section");
92 return res; 149 return res;
93 if ((res = psiconv_write_length(buf,value->header_dist)))
94 return res;
95 if ((res = psiconv_write_length(buf,value->footer_dist)))
96 return res;
97 if ((res = psiconv_write_length(buf,value->left_margin)))
98 return res;
99 if ((res = psiconv_write_length(buf,value->right_margin)))
100 return res;
101 if ((res = psiconv_write_length(buf,value->top_margin)))
102 return res;
103 if ((res = psiconv_write_length(buf,value->bottom_margin)))
104 return res;
105 if ((res = psiconv_write_page_header(buf,value->header)))
106 return res;
107 if ((res = psiconv_write_page_header(buf,value->footer)))
108 return res;
109 if ((res = psiconv_write_u32(buf,PSICONV_ID_PAGE_DIMENSIONS2)))
110 return res;
111 if ((res = psiconv_write_length(buf,value->page_width)))
112 return res;
113 if ((res = psiconv_write_length(buf,value->page_height)))
114 return res;
115 return psiconv_write_bool(buf,value->landscape);
116} 150}

Legend:
Removed from v.79  
changed lines
  Added in v.231

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