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 <vector> 25 #include <boost/shared_ptr.hpp> 26 #include <boost/shared_array.hpp> 27 #include <tools/solar.h> 28 #include <rtl/ustring.hxx> 29 #include <tools/stream.hxx> 30 #include <IDocumentExternalData.hxx> 31 32 namespace ww8 33 { 34 typedef boost::shared_array<sal_uInt8> DataArray_t; 35 36 class WW8Struct : public ::sw::ExternalData 37 { 38 DataArray_t mp_data; 39 sal_uInt32 mn_offset; 40 sal_uInt32 mn_size; 41 42 public: 43 WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize); 44 WW8Struct(WW8Struct * pStruct, sal_uInt32 nPos, sal_uInt32 nSize); 45 virtual ~WW8Struct(); 46 47 sal_uInt8 getU8(sal_uInt32 nOffset); 48 getU16(sal_uInt32 nOffset)49 sal_uInt16 getU16(sal_uInt32 nOffset) 50 { return getU8(nOffset) + (getU8(nOffset + 1) << 8); } 51 getU32(sal_uInt32 nOffset)52 sal_uInt32 getU32(sal_uInt32 nOffset) 53 { return getU16(nOffset) + (getU16(nOffset + 1) << 16); } 54 55 ::rtl::OUString getUString(sal_uInt32 nOffset, sal_uInt32 nCount); 56 57 ::rtl::OUString getString(sal_uInt32 nOffset, sal_uInt32 nCount); 58 }; 59 60 typedef ::std::vector<rtl::OUString> StringVector_t; 61 template <class T> 62 class WW8Sttb : public WW8Struct 63 { 64 typedef ::boost::shared_ptr< void > ExtraPointer_t; 65 typedef ::std::vector< ExtraPointer_t > ExtrasVector_t; 66 bool bDoubleByteCharacters; 67 StringVector_t m_Strings; 68 ExtrasVector_t m_Extras; 69 70 public: 71 WW8Sttb(SvStream& rSt, sal_Int32 nPos, sal_uInt32 nSize); 72 virtual ~WW8Sttb(); 73 74 sal_uInt32 getCount() const; getEntry(sal_uInt32 nEntry) const75 ::rtl::OUString getEntry(sal_uInt32 nEntry) const 76 { 77 return m_Strings[nEntry]; 78 } 79 getStrings()80 StringVector_t & getStrings() 81 { 82 return m_Strings; 83 } 84 getExtra(sal_uInt32 nEntry) const85 const T * getExtra(sal_uInt32 nEntry) const 86 { 87 return dynamic_cast<const T *> (m_Extras[nEntry].get()); 88 } 89 }; 90 91 template <class T> WW8Sttb(SvStream & rSt,sal_Int32 nPos,sal_uInt32 nSize)92 WW8Sttb<T>::WW8Sttb(SvStream& rSt, sal_Int32 nPos, sal_uInt32 nSize) 93 : WW8Struct(rSt, nPos, nSize), bDoubleByteCharacters(false) 94 { 95 sal_uInt32 nOffset = 0; 96 97 if (getU16(nOffset) == 0xffff) 98 { 99 bDoubleByteCharacters = true; 100 nOffset += 2; 101 } 102 103 sal_uInt16 nCount = getU16(nOffset); 104 sal_uInt16 ncbExtra = getU16(nOffset + 2); 105 106 nOffset += 4; 107 for (sal_uInt16 i = 0; i < nCount; i++) 108 { 109 if (bDoubleByteCharacters) 110 { 111 sal_uInt16 nStrLen = getU16(nOffset); 112 113 m_Strings.push_back(getUString(nOffset +2, nStrLen)); 114 115 nOffset += 2 + 2 * nStrLen; 116 } 117 else 118 { 119 sal_uInt8 nStrLen = getU8(nOffset); 120 121 m_Strings.push_back(getUString(nOffset, nStrLen)); 122 123 nOffset += 1 + nStrLen; 124 } 125 126 if (ncbExtra > 0) 127 { 128 ExtraPointer_t pExtra(new T(this, nOffset, ncbExtra)); 129 m_Extras.push_back(pExtra); 130 131 nOffset += ncbExtra; 132 } 133 } 134 } 135 136 template <class T> ~WW8Sttb()137 WW8Sttb<T>::~WW8Sttb() 138 { 139 } 140 } 141