/[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 80 - (hide annotations)
Wed Dec 27 02:12:23 2000 UTC (23 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 4149 byte(s)
(Frodo) Many changes. Layout sections now work!

* Added list_empty, list_replace
* Added relocation to buffers, removed base address
* Added buffer_resolve, buffer_add_reference, buffer_add_target,
  psiconv_unique_id functions
* Modifified other buffer functions to work with references
* Added comments to buffer.h
* Added write_offset function
* Added reference support in functions where needed
* Corrected extra/rewrite error message
* Corrected numerous bugs to make layouts work.

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

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