1 /* wvWare
2  * Copyright (C) Caolan McNamara, Dom Lachowicz, and others
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include "wv.h"
27 
28 
29 float
wvRelativeWidth(S16 width,SEP * asep)30 wvRelativeWidth (S16 width, SEP * asep)
31 {
32     float fwidth;
33     if (asep == NULL)
34 	return (100.00);
35     fwidth = (float) (asep->xaPage - asep->dxaLeft - asep->dxaRight);
36     fwidth = width / fwidth * 100;
37     if (fwidth > 100.00)
38 	fwidth = 100.00;
39     return (fwidth);
40 }
41 
42 float
wvRelativeHeight(S16 height,SEP * asep)43 wvRelativeHeight (S16 height, SEP * asep)
44 {
45     float fheight;
46     if (asep == NULL)
47 	return (100.00);
48     fheight = (float) (asep->yaPage - asep->dyaTop - asep->dyaBottom);
49     fheight = height / fheight * 100;
50     if (fheight > 100.00)
51 	fheight = 100.00;
52     return (fheight);
53 }
54 
55 /*
56 The standard SEP is all zeros except as follows:
57  bkc           2 (new page)
58  dyaPgn        720 twips (equivalent to .5 in)
59  dxaPgn        720 twips
60  fEndnote      1 (True)
61  fEvenlySpaced 1 (True)
62  xaPage        12240 twips
63  yaPage        15840 twips
64  xaPageNUp     12240 twips
65  yaPageNUp     15840 twips
66  dyaHdrTop     720 twips
67  dyaHdrBottom  720 twips
68  dmOrientPage  1 (portrait orientation)
69  dxaColumns    720 twips
70  dyaTop        1440 twips
71  dxaLeft       1800 twips
72  dyaBottom     1440 twips
73  dxaRight      1800 twips
74  pgnStart      1
75 cbSEP (count of bytes of SEP) is 704(decimal), 2C0(hex).
76 */
77 
78 void
wvInitSEP(SEP * item)79 wvInitSEP (SEP * item)
80 {
81     U8 i;
82     item->bkc = 2;
83     item->fTitlePage = 0;
84     item->fAutoPgn = 0;
85     item->nfcPgn = 0;
86     item->fUnlocked = 0;
87     item->cnsPgn = 0;
88     item->fPgnRestart = 0;
89     item->fEndNote = 1;
90     item->lnc = 0;
91     item->grpfIhdt = 0;
92     item->nLnnMod = 0;
93     item->dxaLnn = 0;
94     item->dxaPgn = 720;
95     item->dyaPgn = 720;
96     item->fLBetween = 0;
97     item->vjc = 0;
98     item->dmBinFirst = 0;
99     item->dmBinOther = 0;
100     item->dmPaperReq = 0;
101 
102     wvInitBRC (&item->brcTop);
103     wvInitBRC (&item->brcLeft);
104     wvInitBRC (&item->brcBottom);
105     wvInitBRC (&item->brcRight);
106 
107     item->fPropRMark = 0;
108     item->ibstPropRMark = 0;
109 
110     wvInitDTTM (&item->dttmPropRMark);
111 
112     item->dxtCharSpace = 0;
113     item->dyaLinePitch = 0;
114     item->clm = 0;
115     item->reserved1 = 0;
116     item->dmOrientPage = 0;
117     item->iHeadingPgn = 0;
118     item->pgnStart = 1;
119     item->lnnMin = 0;
120     item->wTextFlow = 0;
121     item->reserved2 = 0;
122     item->pgbProp = 0;
123     item->pgbApplyTo = 0;
124     item->pgbPageDepth = 0;
125     item->pgbOffsetFrom = 0;
126     item->reserved = 0;
127     item->xaPage = 12240;
128     item->yaPage = 15840;
129     item->xaPageNUp = 12240;
130     item->yaPageNUp = 15840;
131     item->dxaLeft = 1800;
132     item->dxaRight = 1800;
133     item->dyaTop = 1440;
134     item->dyaBottom = 1440;
135     item->dzaGutter = 0;
136     item->dyaHdrTop = 720;
137     item->dyaHdrBottom = 720;
138     item->ccolM1 = 0;
139     item->fEvenlySpaced = 1;
140     item->reserved3 = 0;
141     item->dxaColumns = 720;
142     for (i = 0; i < 89; i++)
143 	item->rgdxaColumnWidthSpacing[i] = 0;
144     item->dxaColumnWidth = 0;
145     item->dmOrientFirst = 0;
146     item->fLayout = 0;
147     item->reserved4 = 0;
148     wvInitOLST (&item->olstAnm);
149 	item->fBidi = 0;
150 }
151 
152 void
wvGetSEPX(wvVersion ver,SEPX * item,wvStream * fd)153 wvGetSEPX (wvVersion ver, SEPX * item, wvStream * fd)
154 {
155     U16 i;
156     item->cb = read_16ubit (fd);
157 
158     if (item->cb)
159 	item->grpprl = (U8 *) wvMalloc (item->cb);
160     else
161 	item->grpprl = NULL;
162 
163     for (i = 0; i < item->cb; i++)
164       {
165 	  item->grpprl[i] = read_8ubit (fd);
166 	  wvTrace (("sep is %x\n", item->grpprl[i]));
167       }
168 }
169 
170 void
wvReleaseSEPX(SEPX * item)171 wvReleaseSEPX (SEPX * item)
172 {
173     wvFree (item->grpprl);
174 }
175 
176 
177 int
wvAddSEPXFromBucket(SEP * asep,SEPX * item,STSH * stsh)178 wvAddSEPXFromBucket (SEP * asep, SEPX * item, STSH * stsh)
179 {
180     U8 *pointer;
181     U16 i = 0;
182     U16 sprm;
183     int ret = 0;
184     Sprm RetSprm;
185 #ifdef SPRMTEST
186     fprintf (stderr, "\n");
187     while (i < item->cb)
188       {
189 	  fprintf (stderr, "%x (%d) ", *(item->grpprl + i),
190 		   *(item->grpprl + i));
191 	  i++;
192       }
193     fprintf (stderr, "\n");
194     i = 0;
195 #endif
196     while (i < item->cb - 2)
197       {
198 	  sprm = bread_16ubit (item->grpprl + i, &i);
199 	  pointer = item->grpprl + i;
200 	  RetSprm =
201 	      wvApplySprmFromBucket (WORD8, sprm, NULL, NULL, asep, stsh,
202 				     pointer, &i, NULL);
203 	  if (RetSprm.sgc == sgcSep)
204 	      ret = 1;
205       }
206     return (ret);
207 }
208 
209 int
wvAddSEPXFromBucket6(SEP * asep,SEPX * item,STSH * stsh)210 wvAddSEPXFromBucket6 (SEP * asep, SEPX * item, STSH * stsh)
211 {
212     U8 *pointer;
213     U16 i = 0;
214     int ret = 0;
215     U8 sprm8;
216     U16 sprm;
217     Sprm RetSprm;
218 #ifdef SPRMTEST
219     fprintf (stderr, "\n");
220     while (i < item->cb)
221       {
222 	  fprintf (stderr, "%x (%d) ", *(item->grpprl + i),
223 		   *(item->grpprl + i));
224 	  i++;
225       }
226     fprintf (stderr, "\n");
227     i = 0;
228 #endif
229     while (i < item->cb)
230       {
231 	  sprm8 = bread_8ubit (item->grpprl + i, &i);
232 #ifdef SPRMTEST
233 	  wvError (("sep word 6 sprm is %x (%d)\n", sprm8, sprm8));
234 #endif
235 	  sprm = (U16) wvGetrgsprmWord6 (sprm8);
236 #ifdef SPRMTEST
237 	  wvTrace (("sep word 6 sprm is converted to %x\n", sprm));
238 #endif
239 	  pointer = item->grpprl + i;
240 	  RetSprm =
241 	      wvApplySprmFromBucket (WORD6, sprm, NULL, NULL, asep, stsh,
242 				     pointer, &i, NULL);
243 	  if (RetSprm.sgc == sgcSep)
244 	      ret = 1;
245       }
246     return (ret);
247 }
248