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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 168 - (show annotations)
Tue Nov 25 17:57:05 2003 UTC (20 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 4481 byte(s)
(Frodo) config stuff and image generation stuff

* All parse and generate functions have a new config parameter
* New files configuration.[ch] in the psiconv lib
* Some image generation stuff (not ready, but won't do any harm)

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

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