3 * Copyright (C) 1999-2004 A.J. van Os; Released under GNU GPL
6 * Read the tab stop information from a MS Word file
12 #define HALF_INCH 36000L /* In millipoints */
14 static long lDefaultTabWidth
= HALF_INCH
;
18 * vSet0DefaultTabWidth -
21 vSet0DefaultTabWidth(const UCHAR
*aucHeader
)
25 fail(aucHeader
== NULL
);
27 usTmp
= usGetWord(0x70, aucHeader
); /* dxaTab */
29 lDefaultTabWidth
= usTmp
== 0 ? HALF_INCH
: lTwips2MilliPoints(usTmp
);
30 DBG_DEC(lDefaultTabWidth
);
31 } /* end of vSet0DefaultTabWidth */
34 * vSet2DefaultTabWidth -
37 vSet2DefaultTabWidth(FILE *pFile
, const UCHAR
*aucHeader
)
40 ULONG ulBeginDocpInfo
;
44 fail(pFile
== NULL
|| aucHeader
== NULL
);
46 ulBeginDocpInfo
= ulGetLong(0x112, aucHeader
); /* fcDop */
47 DBG_HEX(ulBeginDocpInfo
);
48 tDocpInfoLen
= (size_t)usGetWord(0x116, aucHeader
); /* cbDop */
49 DBG_DEC(tDocpInfoLen
);
50 if (tDocpInfoLen
< 12) {
51 DBG_MSG("No TAB information");
55 aucBuffer
= xmalloc(tDocpInfoLen
);
56 if (!bReadBytes(aucBuffer
, tDocpInfoLen
, ulBeginDocpInfo
, pFile
)) {
57 aucBuffer
= xfree(aucBuffer
);
60 usTmp
= usGetWord(0x0a, aucBuffer
); /* dxaTab */
61 lDefaultTabWidth
= usTmp
== 0 ? HALF_INCH
: lTwips2MilliPoints(usTmp
);
62 DBG_DEC(lDefaultTabWidth
);
63 aucBuffer
= xfree(aucBuffer
);
64 } /* end of vSet2DefaultTabWidth */
67 * vSet6DefaultTabWidth -
70 vSet6DefaultTabWidth(FILE *pFile
, ULONG ulStartBlock
,
71 const ULONG
*aulBBD
, size_t tBBDLen
, const UCHAR
*aucHeader
)
74 ULONG ulBeginDocpInfo
;
78 ulBeginDocpInfo
= ulGetLong(0x150, aucHeader
); /* fcDop */
79 DBG_HEX(ulBeginDocpInfo
);
80 tDocpInfoLen
= (size_t)ulGetLong(0x154, aucHeader
); /* lcbDop */
81 DBG_DEC(tDocpInfoLen
);
82 if (tDocpInfoLen
< 12) {
83 DBG_MSG("No TAB information");
87 aucBuffer
= xmalloc(tDocpInfoLen
);
88 if (!bReadBuffer(pFile
, ulStartBlock
,
89 aulBBD
, tBBDLen
, BIG_BLOCK_SIZE
,
90 aucBuffer
, ulBeginDocpInfo
, tDocpInfoLen
)) {
91 aucBuffer
= xfree(aucBuffer
);
94 usTmp
= usGetWord(0x0a, aucBuffer
); /* dxaTab */
95 lDefaultTabWidth
= usTmp
== 0 ? HALF_INCH
: lTwips2MilliPoints(usTmp
);
96 DBG_DEC(lDefaultTabWidth
);
97 aucBuffer
= xfree(aucBuffer
);
98 } /* end of vSet6DefaultTabWidth */
101 * vSet8DefaultTabWidth -
104 vSet8DefaultTabWidth(FILE *pFile
, const pps_info_type
*pPPS
,
105 const ULONG
*aulBBD
, size_t tBBDLen
,
106 const ULONG
*aulSBD
, size_t tSBDLen
,
107 const UCHAR
*aucHeader
)
109 const ULONG
*aulBlockDepot
;
111 ULONG ulBeginDocpInfo
;
112 size_t tDocpInfoLen
, tBlockDepotLen
, tBlockSize
;
115 ulBeginDocpInfo
= ulGetLong(0x192, aucHeader
); /* fcDop */
116 DBG_HEX(ulBeginDocpInfo
);
117 tDocpInfoLen
= (size_t)ulGetLong(0x196, aucHeader
); /* lcbDop */
118 DBG_DEC(tDocpInfoLen
);
119 if (tDocpInfoLen
< 12) {
120 DBG_MSG("No TAB information");
124 DBG_DEC(pPPS
->tTable
.ulSB
);
125 DBG_HEX(pPPS
->tTable
.ulSize
);
126 if (pPPS
->tTable
.ulSize
== 0) {
127 DBG_MSG("No TAB information");
131 if (pPPS
->tTable
.ulSize
< MIN_SIZE_FOR_BBD_USE
) {
132 /* Use the Small Block Depot */
133 aulBlockDepot
= aulSBD
;
134 tBlockDepotLen
= tSBDLen
;
135 tBlockSize
= SMALL_BLOCK_SIZE
;
137 /* Use the Big Block Depot */
138 aulBlockDepot
= aulBBD
;
139 tBlockDepotLen
= tBBDLen
;
140 tBlockSize
= BIG_BLOCK_SIZE
;
142 aucBuffer
= xmalloc(tDocpInfoLen
);
143 if (!bReadBuffer(pFile
, pPPS
->tTable
.ulSB
,
144 aulBlockDepot
, tBlockDepotLen
, tBlockSize
,
145 aucBuffer
, ulBeginDocpInfo
, tDocpInfoLen
)) {
146 aucBuffer
= xfree(aucBuffer
);
149 usTmp
= usGetWord(0x0a, aucBuffer
); /* dxaTab */
150 lDefaultTabWidth
= usTmp
== 0 ? HALF_INCH
: lTwips2MilliPoints(usTmp
);
151 DBG_DEC(lDefaultTabWidth
);
152 aucBuffer
= xfree(aucBuffer
);
153 } /* end of vSet8DefaultTabWidth */
156 * vSetDefaultTabWidth -
159 vSetDefaultTabWidth(FILE *pFile
, const pps_info_type
*pPPS
,
160 const ULONG
*aulBBD
, size_t tBBDLen
,
161 const ULONG
*aulSBD
, size_t tSBDLen
,
162 const UCHAR
*aucHeader
, int iWordVersion
)
164 fail(pFile
== NULL
&& iWordVersion
>= 1);
165 fail(pPPS
== NULL
&& iWordVersion
>= 6);
166 fail(aulBBD
== NULL
&& tBBDLen
!= 0);
167 fail(aulSBD
== NULL
&& tSBDLen
!= 0);
168 fail(aucHeader
== NULL
);
170 /* Reset to the default default value */
171 lDefaultTabWidth
= HALF_INCH
;
173 switch (iWordVersion
) {
175 vSet0DefaultTabWidth(aucHeader
);
179 vSet2DefaultTabWidth(pFile
, aucHeader
);
186 vSet6DefaultTabWidth(pFile
, pPPS
->tWordDocument
.ulSB
,
187 aulBBD
, tBBDLen
, aucHeader
);
190 vSet8DefaultTabWidth(pFile
, pPPS
,
191 aulBBD
, tBBDLen
, aulSBD
, tSBDLen
, aucHeader
);
194 werr(0, "Sorry, no TAB information");
197 } /* end of vSetDefaultTabWidth */
201 * lGetDefaultTabWidth - Get the default tabwidth in millipoints
204 lGetDefaultTabWidth(void)
206 if (lDefaultTabWidth
<= 0) {
207 DBG_DEC(lDefaultTabWidth
);
208 return lTwips2MilliPoints(1);
210 return lDefaultTabWidth
;
211 } /* end of lGetDefaultTabWidth */