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