/[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 184 - (show annotations)
Tue Jan 6 20:15:01 2004 UTC (20 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 4747 byte(s)
(Frodo) Unicode transition

Note: this commit breaks psiconv. The programs in the extra directory should
work properly.

  * Change all datastructures to use unicode for character encodings
  * Added psiconv_error function
  * Called psiconv_error at places where a warning was stupid
  * Added psiconv_progress in all generate functions
  * Added lev parameter to all generate functions
  * Removed general.h from CVS (we have general.h.in, after all)
  * Probably other stuff I forgot

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, int lev,
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 psiconv_progress(config,lev,0,"Writing page header");
45
46 if (!value) {
47 psiconv_error(config,0,psiconv_buffer_length(buf),"Null page header");
48 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 if ((res = psiconv_write_u8(config,buf,lev+1,0x01)))
63 goto ERROR3;
64 if ((res = psiconv_write_bool(config,buf,lev+1,value->on_first_page)))
65 goto ERROR3;
66 /* Three unknown bytes */
67 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
68 goto ERROR3;
69 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
70 goto ERROR3;
71 if ((res = psiconv_write_u8(config,buf,lev+1,0x00)))
72 goto ERROR3;
73 if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1,
74 value->base_paragraph_layout,basepara)))
75 goto ERROR3;
76 if ((res = psiconv_write_character_layout_list(config,buf,lev+1,
77 value->base_character_layout,basechar)))
78 goto ERROR3;
79 res = psiconv_write_texted_section(config,buf,lev+1,value->text,
80 value->base_character_layout,
81 value->base_paragraph_layout,extra_buf);
82 ERROR3:
83 psiconv_free_character_layout(basechar);
84 ERROR2:
85 psiconv_free_paragraph_layout(basepara);
86 ERROR1:
87 return res;
88 }
89
90 int psiconv_write_page_layout_section(const psiconv_config config,
91 psiconv_buffer buf, int lev,
92 const psiconv_page_layout_section value)
93 {
94 int res;
95 psiconv_buffer header_buf,footer_buf;
96
97 psiconv_progress(config,lev,0,"Writing page layout section");
98
99 if (!value) {
100 psiconv_error(config,0,psiconv_buffer_length(buf),"Null page section");
101 res = -PSICONV_E_GENERATE;
102 goto ERROR1;
103 }
104
105 if ((res = psiconv_write_u32(config,buf,lev+1,value->first_page_nr)))
106 goto ERROR1;
107 if ((res = psiconv_write_length(config,buf,lev+1,value->header_dist)))
108 goto ERROR1;
109 if ((res = psiconv_write_length(config,buf,lev+1,value->footer_dist)))
110 goto ERROR1;
111 if ((res = psiconv_write_length(config,buf,lev+1,value->left_margin)))
112 goto ERROR1;
113 if ((res = psiconv_write_length(config,buf,lev+1,value->right_margin)))
114 goto ERROR1;
115 if ((res = psiconv_write_length(config,buf,lev+1,value->top_margin)))
116 goto ERROR1;
117 if ((res = psiconv_write_length(config,buf,lev+1,value->bottom_margin)))
118 goto ERROR1;
119 if ((res = psiconv_write_page_header(config,buf,lev+1,value->header,&header_buf)))
120 goto ERROR1;
121 if ((res = psiconv_write_page_header(config,buf,lev+1,value->footer,&footer_buf)))
122 goto ERROR2;
123 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_PAGE_DIMENSIONS2)))
124 goto ERROR3;
125 if ((res = psiconv_write_length(config,buf,lev+1,value->page_width)))
126 goto ERROR3;
127 if ((res = psiconv_write_length(config,buf,lev+1,value->page_height)))
128 goto ERROR3;
129 if ((res = psiconv_write_bool(config,buf,lev+1,value->landscape)))
130 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@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26