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 <resources.hxx>
25 
26 namespace writerfilter {
27 namespace doctok {
28 
initPayload()29 void WW8StyleSheet::initPayload()
30 {
31     sal_uInt32 nCount = getEntryCount();
32 
33     sal_uInt32 nOffset = get_size() + 2;
34     for (sal_uInt32 n = 0; n < nCount; ++n)
35     {
36         entryOffsets.push_back(nOffset);
37 
38         sal_uInt32 cbStd = getU16(nOffset);
39         nOffset += cbStd + 2;
40     }
41 
42     entryOffsets.push_back(nOffset);
43 }
44 
calcSize()45 sal_uInt32 WW8StyleSheet::calcSize()
46 {
47     return getCount();
48 }
49 
getEntryCount()50 sal_uInt32 WW8StyleSheet::getEntryCount()
51 {
52     return get_cstd();
53 }
54 
55 writerfilter::Reference<Properties>::Pointer_t
getEntry(sal_uInt32 nIndex)56 WW8StyleSheet::getEntry(sal_uInt32 nIndex)
57 {
58     writerfilter::Reference<Properties>::Pointer_t pResult;
59 
60     sal_uInt32 nCount = entryOffsets[nIndex + 1] - entryOffsets[nIndex];
61 
62     if (nCount > get_cbSTDBaseInFile() + 2U)
63     {
64         WW8Style * pStyle = new WW8Style(this, entryOffsets[nIndex], nCount);
65 
66         pStyle->setIndex(nIndex);
67 
68         pResult = writerfilter::Reference<Properties>::Pointer_t(pStyle);
69     }
70 
71     return pResult;
72 }
73 
get_xstzName()74 rtl::OUString WW8Style::get_xstzName()
75 {
76     sal_uInt32 nCount = getU8(0xc);
77 
78     if (nCount > 0)
79     {
80         Sequence aSeq(mSequence, 0xe, nCount * 2);
81 
82         rtl_uString * pNew = 0;
83         rtl_uString_newFromStr
84             (&pNew, reinterpret_cast<const sal_Unicode *>(&aSeq[0]));
85 
86         return rtl::OUString(pNew);
87 
88     }
89 
90     return get_xstzName1();
91 }
92 
get_xstzName1()93 rtl::OUString WW8Style::get_xstzName1()
94 {
95     WW8StyleSheet * pParentStyleSheet = dynamic_cast<WW8StyleSheet *>(mpParent);
96 
97     if (mpParent != NULL)
98     {
99         sal_uInt32 nOffset = pParentStyleSheet->get_cbSTDBaseInFile() + 2;
100 
101         if (nOffset < getCount())
102         {
103             sal_uInt32 nCount = getU16(nOffset);
104 
105             if (nCount > 0)
106             {
107                 Sequence aSeq(mSequence, nOffset + 2, nCount * 2);
108 
109                 rtl_uString * pNew = 0;
110                 rtl_uString_newFromStr
111                     (&pNew, reinterpret_cast<const sal_Unicode *>(&aSeq[0]));
112 
113                 return rtl::OUString(pNew);
114 
115             }
116         }
117     }
118 
119     return rtl::OUString();
120 }
121 
get_upxstart()122 sal_uInt32 WW8Style::get_upxstart()
123 {
124     sal_uInt32 nResult = 0;
125     sal_uInt32 nCount = getU8(0xc);
126 
127     if (nCount > 0)
128     {
129         nResult = 0xc + 1 + nCount * 2;
130 
131         nResult += nResult % 2;
132     }
133     else
134     {
135         WW8StyleSheet * pParentStyleSheet =
136             dynamic_cast<WW8StyleSheet *>(mpParent);
137 
138         nResult = pParentStyleSheet->get_cbSTDBaseInFile() + 2;
139 
140         if (nResult < getCount())
141         {
142             sal_uInt32 nCountTmp = getU16(nResult);
143 
144             nResult += 4 + nCountTmp * 2;
145         }
146     }
147 
148     return nResult;
149 }
150 
get_upx_count()151 sal_uInt32 WW8Style::get_upx_count()
152 {
153     return get_cupx();
154 }
155 
get_upx(sal_uInt32 nIndex)156 writerfilter::Reference<Properties>::Pointer_t WW8Style::get_upx
157 (sal_uInt32 nIndex)
158 {
159     writerfilter::Reference<Properties>::Pointer_t pResult;
160 
161     WW8StructBaseTmpOffset aOffset(this);
162 
163     aOffset.set(get_upxstart());
164 
165     if (aOffset.get() > 0 )
166     {
167         sal_uInt32 nCount;
168 
169         for (sal_uInt32 n = 0; n < nIndex; ++n)
170         {
171             nCount = getU16(aOffset);
172 
173             aOffset.inc(nCount + 2);
174             aOffset.inc(aOffset.get() % 2);
175         }
176 
177         nCount = getU16(aOffset);
178 
179         if (nCount > 0)
180         {
181             aOffset.inc(2);
182 
183             bool bIsPap = get_cupx() == 2 && nIndex == 0;
184             WW8PropertySet::Pointer_t
185                 pProps(new WW8PropertySetImpl(*this, aOffset.get(), nCount,
186                                               bIsPap));
187 
188             WW8PropertiesReference * pRef =
189                 new WW8PropertiesReference(pProps);
190 
191             pResult = writerfilter::Reference<Properties>::Pointer_t(pRef);
192         }
193     }
194 
195     return pResult;
196 }
197 
resolveNoAuto(Properties &)198 void WW8Style::resolveNoAuto(Properties & /*rHandler*/)
199 {
200 }
201 
202 }}
203