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