/[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 168 - (hide annotations)
Tue Nov 25 17:57:05 2003 UTC (20 years, 5 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 frodo 73 /*
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 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     psiconv_buffer buf,
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     if (!value) {
45 frodo 168 psiconv_warn(config,0,psiconv_buffer_length(buf),"Null page header");
46 frodo 73 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 frodo 168 if ((res = psiconv_write_u8(config,buf,0x01)))
61 frodo 73 goto ERROR3;
62 frodo 168 if ((res = psiconv_write_bool(config,buf,value->on_first_page)))
63 frodo 73 goto ERROR3;
64 frodo 76 /* Three unknown bytes */
65 frodo 168 if ((res = psiconv_write_u8(config,buf,0x00)))
66 frodo 76 goto ERROR3;
67 frodo 168 if ((res = psiconv_write_u8(config,buf,0x00)))
68 frodo 76 goto ERROR3;
69 frodo 168 if ((res = psiconv_write_u8(config,buf,0x00)))
70 frodo 76 goto ERROR3;
71 frodo 168 if ((res = psiconv_write_paragraph_layout_list(config,buf,
72 frodo 73 value->base_paragraph_layout,basepara)))
73     goto ERROR3;
74 frodo 168 if ((res = psiconv_write_character_layout_list(config,buf,
75 frodo 73 value->base_character_layout,basechar)))
76     goto ERROR3;
77 frodo 168 res = psiconv_write_texted_section(config,buf,value->text,
78 frodo 73 value->base_character_layout,
79 frodo 80 value->base_paragraph_layout,extra_buf);
80 frodo 73 ERROR3:
81     psiconv_free_character_layout(basechar);
82     ERROR2:
83     psiconv_free_paragraph_layout(basepara);
84     ERROR1:
85     return res;
86     }
87    
88 frodo 168 int psiconv_write_page_layout_section(const psiconv_config config,
89     psiconv_buffer buf,
90 frodo 73 const psiconv_page_layout_section value)
91     {
92     int res;
93 frodo 80 psiconv_buffer header_buf,footer_buf;
94 frodo 73
95     if (!value) {
96 frodo 168 psiconv_warn(config,0,psiconv_buffer_length(buf),"Null page section");
97 frodo 80 res = -PSICONV_E_GENERATE;
98     goto ERROR1;
99 frodo 73 }
100    
101 frodo 168 if ((res = psiconv_write_u32(config,buf,value->first_page_nr)))
102 frodo 80 goto ERROR1;
103 frodo 168 if ((res = psiconv_write_length(config,buf,value->header_dist)))
104 frodo 80 goto ERROR1;
105 frodo 168 if ((res = psiconv_write_length(config,buf,value->footer_dist)))
106 frodo 80 goto ERROR1;
107 frodo 168 if ((res = psiconv_write_length(config,buf,value->left_margin)))
108 frodo 80 goto ERROR1;
109 frodo 168 if ((res = psiconv_write_length(config,buf,value->right_margin)))
110 frodo 80 goto ERROR1;
111 frodo 168 if ((res = psiconv_write_length(config,buf,value->top_margin)))
112 frodo 80 goto ERROR1;
113 frodo 168 if ((res = psiconv_write_length(config,buf,value->bottom_margin)))
114 frodo 80 goto ERROR1;
115 frodo 168 if ((res = psiconv_write_page_header(config,buf,value->header,&header_buf)))
116 frodo 80 goto ERROR1;
117 frodo 168 if ((res = psiconv_write_page_header(config,buf,value->footer,&footer_buf)))
118 frodo 80 goto ERROR2;
119 frodo 168 if ((res = psiconv_write_u32(config,buf,PSICONV_ID_PAGE_DIMENSIONS2)))
120 frodo 80 goto ERROR3;
121 frodo 168 if ((res = psiconv_write_length(config,buf,value->page_width)))
122 frodo 80 goto ERROR3;
123 frodo 168 if ((res = psiconv_write_length(config,buf,value->page_height)))
124 frodo 80 goto ERROR3;
125 frodo 168 if ((res = psiconv_write_bool(config,buf,value->landscape)))
126 frodo 80 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 73 }

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