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