This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtabstop.c
212 lines (190 loc) · 5 KB
/
tabstop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* tabstops.c
* Copyright (C) 1999-2004 A.J. van Os; Released under GNU GPL
*
* Description:
* Read the tab stop information from a MS Word file
*/
#include <stdio.h>
#include "antiword.h"
#define HALF_INCH 36000L /* In millipoints */
static long lDefaultTabWidth = HALF_INCH;
/*
* vSet0DefaultTabWidth -
*/
static void
vSet0DefaultTabWidth(const UCHAR *aucHeader)
{
USHORT usTmp;
fail(aucHeader == NULL);
usTmp = usGetWord(0x70, aucHeader); /* dxaTab */
DBG_DEC(usTmp);
lDefaultTabWidth = usTmp == 0 ? HALF_INCH : lTwips2MilliPoints(usTmp);
DBG_DEC(lDefaultTabWidth);
} /* end of vSet0DefaultTabWidth */
/*
* vSet2DefaultTabWidth -
*/
static void
vSet2DefaultTabWidth(FILE *pFile, const UCHAR *aucHeader)
{
UCHAR *aucBuffer;
ULONG ulBeginDocpInfo;
size_t tDocpInfoLen;
USHORT usTmp;
fail(pFile == NULL || aucHeader == NULL);
ulBeginDocpInfo = ulGetLong(0x112, aucHeader); /* fcDop */
DBG_HEX(ulBeginDocpInfo);
tDocpInfoLen = (size_t)usGetWord(0x116, aucHeader); /* cbDop */
DBG_DEC(tDocpInfoLen);
if (tDocpInfoLen < 12) {
DBG_MSG("No TAB information");
return;
}
aucBuffer = xmalloc(tDocpInfoLen);
if (!bReadBytes(aucBuffer, tDocpInfoLen, ulBeginDocpInfo, pFile)) {
aucBuffer = xfree(aucBuffer);
return;
}
usTmp = usGetWord(0x0a, aucBuffer); /* dxaTab */
lDefaultTabWidth = usTmp == 0 ? HALF_INCH : lTwips2MilliPoints(usTmp);
DBG_DEC(lDefaultTabWidth);
aucBuffer = xfree(aucBuffer);
} /* end of vSet2DefaultTabWidth */
/*
* vSet6DefaultTabWidth -
*/
static void
vSet6DefaultTabWidth(FILE *pFile, ULONG ulStartBlock,
const ULONG *aulBBD, size_t tBBDLen, const UCHAR *aucHeader)
{
UCHAR *aucBuffer;
ULONG ulBeginDocpInfo;
size_t tDocpInfoLen;
USHORT usTmp;
ulBeginDocpInfo = ulGetLong(0x150, aucHeader); /* fcDop */
DBG_HEX(ulBeginDocpInfo);
tDocpInfoLen = (size_t)ulGetLong(0x154, aucHeader); /* lcbDop */
DBG_DEC(tDocpInfoLen);
if (tDocpInfoLen < 12) {
DBG_MSG("No TAB information");
return;
}
aucBuffer = xmalloc(tDocpInfoLen);
if (!bReadBuffer(pFile, ulStartBlock,
aulBBD, tBBDLen, BIG_BLOCK_SIZE,
aucBuffer, ulBeginDocpInfo, tDocpInfoLen)) {
aucBuffer = xfree(aucBuffer);
return;
}
usTmp = usGetWord(0x0a, aucBuffer); /* dxaTab */
lDefaultTabWidth = usTmp == 0 ? HALF_INCH : lTwips2MilliPoints(usTmp);
DBG_DEC(lDefaultTabWidth);
aucBuffer = xfree(aucBuffer);
} /* end of vSet6DefaultTabWidth */
/*
* vSet8DefaultTabWidth -
*/
static void
vSet8DefaultTabWidth(FILE *pFile, const pps_info_type *pPPS,
const ULONG *aulBBD, size_t tBBDLen,
const ULONG *aulSBD, size_t tSBDLen,
const UCHAR *aucHeader)
{
const ULONG *aulBlockDepot;
UCHAR *aucBuffer;
ULONG ulBeginDocpInfo;
size_t tDocpInfoLen, tBlockDepotLen, tBlockSize;
USHORT usTmp;
ulBeginDocpInfo = ulGetLong(0x192, aucHeader); /* fcDop */
DBG_HEX(ulBeginDocpInfo);
tDocpInfoLen = (size_t)ulGetLong(0x196, aucHeader); /* lcbDop */
DBG_DEC(tDocpInfoLen);
if (tDocpInfoLen < 12) {
DBG_MSG("No TAB information");
return;
}
DBG_DEC(pPPS->tTable.ulSB);
DBG_HEX(pPPS->tTable.ulSize);
if (pPPS->tTable.ulSize == 0) {
DBG_MSG("No TAB information");
return;
}
if (pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE) {
/* Use the Small Block Depot */
aulBlockDepot = aulSBD;
tBlockDepotLen = tSBDLen;
tBlockSize = SMALL_BLOCK_SIZE;
} else {
/* Use the Big Block Depot */
aulBlockDepot = aulBBD;
tBlockDepotLen = tBBDLen;
tBlockSize = BIG_BLOCK_SIZE;
}
aucBuffer = xmalloc(tDocpInfoLen);
if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
aulBlockDepot, tBlockDepotLen, tBlockSize,
aucBuffer, ulBeginDocpInfo, tDocpInfoLen)) {
aucBuffer = xfree(aucBuffer);
return;
}
usTmp = usGetWord(0x0a, aucBuffer); /* dxaTab */
lDefaultTabWidth = usTmp == 0 ? HALF_INCH : lTwips2MilliPoints(usTmp);
DBG_DEC(lDefaultTabWidth);
aucBuffer = xfree(aucBuffer);
} /* end of vSet8DefaultTabWidth */
/*
* vSetDefaultTabWidth -
*/
void
vSetDefaultTabWidth(FILE *pFile, const pps_info_type *pPPS,
const ULONG *aulBBD, size_t tBBDLen,
const ULONG *aulSBD, size_t tSBDLen,
const UCHAR *aucHeader, int iWordVersion)
{
fail(pFile == NULL && iWordVersion >= 1);
fail(pPPS == NULL && iWordVersion >= 6);
fail(aulBBD == NULL && tBBDLen != 0);
fail(aulSBD == NULL && tSBDLen != 0);
fail(aucHeader == NULL);
/* Reset to the default default value */
lDefaultTabWidth = HALF_INCH;
switch (iWordVersion) {
case 0:
vSet0DefaultTabWidth(aucHeader);
break;
case 1:
case 2:
vSet2DefaultTabWidth(pFile, aucHeader);
break;
case 4:
case 5:
break;
case 6:
case 7:
vSet6DefaultTabWidth(pFile, pPPS->tWordDocument.ulSB,
aulBBD, tBBDLen, aucHeader);
break;
case 8:
vSet8DefaultTabWidth(pFile, pPPS,
aulBBD, tBBDLen, aulSBD, tSBDLen, aucHeader);
break;
default:
werr(0, "Sorry, no TAB information");
break;
}
} /* end of vSetDefaultTabWidth */
#if 0
/*
* lGetDefaultTabWidth - Get the default tabwidth in millipoints
*/
long
lGetDefaultTabWidth(void)
{
if (lDefaultTabWidth <= 0) {
DBG_DEC(lDefaultTabWidth);
return lTwips2MilliPoints(1);
}
return lDefaultTabWidth;
} /* end of lGetDefaultTabWidth */
#endif