1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include <WW8Sttbf.hxx>
25 #include <resources.hxx>
26
27 namespace writerfilter {
28 namespace doctok
29 {
30
WW8Sttbf(WW8Stream & rStream,sal_uInt32 nOffset,sal_uInt32 nCount)31 WW8Sttbf::WW8Sttbf(WW8Stream & rStream, sal_uInt32 nOffset, sal_uInt32 nCount)
32 : WW8StructBase(rStream, nOffset, nCount)
33 {
34 sal_uInt32 nComplexOffset = 0;
35 if (getU16(0) == 0xffff)
36 {
37 mbComplex = true;
38 nComplexOffset = 2;
39 }
40
41 mnCount = getU16(nComplexOffset);
42 mnExtraDataCount = getU16(nComplexOffset + 2);
43
44 nOffset = (mbComplex ? 2 : 0) + 4;
45
46 for (sal_uInt32 n = 0; n < mnCount; ++n)
47 {
48 mEntryOffsets.push_back(nOffset);
49
50 sal_uInt32 nStringLength = getU16(nOffset);
51
52 nOffset += 2 + nStringLength * (mbComplex ? 2 : 1);
53
54 mExtraOffsets.push_back(nOffset);
55
56 nOffset += mnExtraDataCount;
57 }
58 }
59
getEntryOffset(sal_uInt32 nPos) const60 sal_uInt32 WW8Sttbf::getEntryOffset(sal_uInt32 nPos) const
61 {
62 return mEntryOffsets[nPos];
63 }
64
getExtraOffset(sal_uInt32 nPos) const65 sal_uInt32 WW8Sttbf::getExtraOffset(sal_uInt32 nPos) const
66 {
67 return mExtraOffsets[nPos];
68 }
69
getEntryCount() const70 sal_uInt32 WW8Sttbf::getEntryCount() const
71 {
72 return mnCount;
73 }
74
getEntry(sal_uInt32 nPos) const75 rtl::OUString WW8Sttbf::getEntry(sal_uInt32 nPos) const
76 {
77 return getString(getEntryOffset(nPos));
78 }
79
getExtraData(sal_uInt32 nPos)80 WW8StructBase::Pointer_t WW8Sttbf::getExtraData(sal_uInt32 nPos)
81 {
82 return WW8StructBase::Pointer_t
83 (new WW8StructBase(*this, getExtraOffset(nPos), mnExtraDataCount));
84 }
85
WW8SttbTableResource(WW8Sttbf::Pointer_t pSttbf)86 WW8SttbTableResource::WW8SttbTableResource(WW8Sttbf::Pointer_t pSttbf)
87 : mpSttbf(pSttbf)
88 {
89 }
90
~WW8SttbTableResource()91 WW8SttbTableResource::~WW8SttbTableResource()
92 {
93 }
94
resolve(Table & rTable)95 void WW8SttbTableResource::resolve(Table & rTable)
96 {
97 sal_uInt32 nCount = mpSttbf->getEntryCount();
98
99 for (sal_uInt32 n = 0; n < nCount; n++)
100 {
101 WW8StringValue::Pointer_t pVal(new WW8StringValue(mpSttbf->getEntry(n)));
102 ::writerfilter::Reference<Properties>::Pointer_t pProps(new WW8StringProperty(0, pVal));
103
104 rTable.entry(n, pProps);
105 }
106 }
107
getType() const108 string WW8SttbTableResource::getType() const
109 {
110 return "WW8SttbTableResource";
111 }
112
WW8StringProperty(sal_uInt32 nId,WW8StringValue::Pointer_t pValue)113 WW8StringProperty::WW8StringProperty(sal_uInt32 nId, WW8StringValue::Pointer_t pValue)
114 : mnId(nId), mpValue(pValue)
115 {
116 }
117
~WW8StringProperty()118 WW8StringProperty::~WW8StringProperty()
119 {
120 }
121
resolve(Properties & rProperties)122 void WW8StringProperty::resolve(Properties & rProperties)
123 {
124 rProperties.attribute(mnId, *mpValue);
125 }
126
getType() const127 string WW8StringProperty::getType() const
128 {
129 return "WW8StringProperty";
130 }
131
getEntryCount()132 sal_uInt32 WW8SttbRgtplc::getEntryCount()
133 {
134 return getU16(2);
135 }
136
137 ::writerfilter::Reference<Properties>::Pointer_t
getEntry(sal_uInt32 nIndex)138 WW8SttbRgtplc::getEntry(sal_uInt32 nIndex)
139 {
140 ::writerfilter::Reference<Properties>::Pointer_t pResult;
141
142 sal_uInt32 nOffset = 6;
143
144 for(; nIndex > 0; --nIndex)
145 {
146 sal_uInt16 nCount = getU16(nOffset);
147
148 nOffset = nOffset + 2 + nCount;
149 }
150
151 sal_uInt16 nCount = getU16(nOffset);
152
153 if (nCount > 0)
154 {
155 WW8Tplc * pTplc = new WW8Tplc(*this, nOffset + 2, nCount);
156
157 pResult.reset(pTplc);
158 }
159
160 return pResult;
161 }
162
163 }}
164