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

Annotation of /psiconv/trunk/lib/psiconv/generate_page.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: 5278 byte(s)
(Frodo) Update copyright year in all source files

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

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