/[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 196 - (hide annotations)
Wed Feb 4 12:19:09 2004 UTC (20 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 4752 byte(s)
(Frodo) Copyright dates update

1 frodo 73 /*
2     generate_page.c - Part of psiconv, a PSION 5 file formats converter
3 frodo 196 Copyright (c) 2000-2004 Frodo Looijaard <frodol@dds.nl>
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 184 psiconv_error(config,0,psiconv_buffer_length(buf),"Null page header");
48 frodo 73 res = -PSICONV_E_GENERATE;
49     goto ERROR1;
50     }
51    
52     if (!(basepara=psiconv_basic_paragraph_layout())) {
53     res = -PSICONV_E_NOMEM;
54     goto ERROR1;
55     }
56     if (!(basechar=psiconv_basic_character_layout())) {
57     res = -PSICONV_E_NOMEM;
58     goto ERROR2;
59     }
60    
61     /* Unknown byte */
62 frodo 184 if ((res = psiconv_write_u8(config,buf,lev+1,0x01)))
63 frodo 73 goto ERROR3;
64 frodo 184 if ((res = psiconv_write_bool(config,buf,lev+1,value->on_first_page)))
65 frodo 73 goto ERROR3;
66 frodo 76 /* Three unknown bytes */
67 frodo 184 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
68 frodo 76 goto ERROR3;
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_paragraph_layout_list(config,buf,lev+1,
74 frodo 73 value->base_paragraph_layout,basepara)))
75     goto ERROR3;
76 frodo 184 if ((res = psiconv_write_character_layout_list(config,buf,lev+1,
77 frodo 73 value->base_character_layout,basechar)))
78     goto ERROR3;
79 frodo 184 res = psiconv_write_texted_section(config,buf,lev+1,value->text,
80 frodo 73 value->base_character_layout,
81 frodo 80 value->base_paragraph_layout,extra_buf);
82 frodo 73 ERROR3:
83     psiconv_free_character_layout(basechar);
84     ERROR2:
85     psiconv_free_paragraph_layout(basepara);
86     ERROR1:
87     return res;
88     }
89    
90 frodo 168 int psiconv_write_page_layout_section(const psiconv_config config,
91 frodo 184 psiconv_buffer buf, int lev,
92 frodo 73 const psiconv_page_layout_section value)
93     {
94     int res;
95 frodo 80 psiconv_buffer header_buf,footer_buf;
96 frodo 73
97 frodo 184 psiconv_progress(config,lev,0,"Writing page layout section");
98    
99 frodo 73 if (!value) {
100 frodo 184 psiconv_error(config,0,psiconv_buffer_length(buf),"Null page section");
101 frodo 80 res = -PSICONV_E_GENERATE;
102     goto ERROR1;
103 frodo 73 }
104    
105 frodo 184 if ((res = psiconv_write_u32(config,buf,lev+1,value->first_page_nr)))
106 frodo 80 goto ERROR1;
107 frodo 184 if ((res = psiconv_write_length(config,buf,lev+1,value->header_dist)))
108 frodo 80 goto ERROR1;
109 frodo 184 if ((res = psiconv_write_length(config,buf,lev+1,value->footer_dist)))
110 frodo 80 goto ERROR1;
111 frodo 184 if ((res = psiconv_write_length(config,buf,lev+1,value->left_margin)))
112 frodo 80 goto ERROR1;
113 frodo 184 if ((res = psiconv_write_length(config,buf,lev+1,value->right_margin)))
114 frodo 80 goto ERROR1;
115 frodo 184 if ((res = psiconv_write_length(config,buf,lev+1,value->top_margin)))
116 frodo 80 goto ERROR1;
117 frodo 184 if ((res = psiconv_write_length(config,buf,lev+1,value->bottom_margin)))
118 frodo 80 goto ERROR1;
119 frodo 184 if ((res = psiconv_write_page_header(config,buf,lev+1,value->header,&header_buf)))
120 frodo 80 goto ERROR1;
121 frodo 184 if ((res = psiconv_write_page_header(config,buf,lev+1,value->footer,&footer_buf)))
122 frodo 80 goto ERROR2;
123 frodo 184 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_PAGE_DIMENSIONS2)))
124 frodo 80 goto ERROR3;
125 frodo 184 if ((res = psiconv_write_length(config,buf,lev+1,value->page_width)))
126 frodo 80 goto ERROR3;
127 frodo 184 if ((res = psiconv_write_length(config,buf,lev+1,value->page_height)))
128 frodo 80 goto ERROR3;
129 frodo 184 if ((res = psiconv_write_bool(config,buf,lev+1,value->landscape)))
130 frodo 80 goto ERROR3;
131     if ((res = psiconv_buffer_concat(buf,header_buf)))
132     goto ERROR3;
133     res = psiconv_buffer_concat(buf,footer_buf);
134    
135    
136     ERROR3:
137     psiconv_buffer_free(footer_buf);
138     ERROR2:
139     psiconv_buffer_free(header_buf);
140     ERROR1:
141     return res;
142 frodo 73 }

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