Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <vector>
21 : #include <boost/shared_ptr.hpp>
22 : #include <boost/shared_array.hpp>
23 : #include <tools/solar.h>
24 : #include <rtl/ustring.hxx>
25 : #include <tools/stream.hxx>
26 : #include <IDocumentExternalData.hxx>
27 :
28 : namespace ww8
29 : {
30 : typedef boost::shared_array<sal_uInt8> DataArray_t;
31 :
32 : class WW8Struct : public ::sw::ExternalData
33 : {
34 : DataArray_t mp_data;
35 : sal_uInt32 mn_offset;
36 : sal_uInt32 mn_size;
37 :
38 : public:
39 : WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize);
40 : WW8Struct(WW8Struct * pStruct, sal_uInt32 nPos, sal_uInt32 nSize);
41 : virtual ~WW8Struct();
42 :
43 : sal_uInt8 getU8(sal_uInt32 nOffset);
44 :
45 1245 : sal_uInt16 getU16(sal_uInt32 nOffset)
46 1245 : { return getU8(nOffset) + (getU8(nOffset + 1) << 8); }
47 :
48 : sal_uInt32 getU32(sal_uInt32 nOffset)
49 : { return getU16(nOffset) + (getU16(nOffset + 1) << 16); }
50 :
51 : OUString getUString(sal_uInt32 nOffset, sal_uInt32 nCount);
52 :
53 : OUString getString(sal_uInt32 nOffset, sal_uInt32 nCount);
54 : };
55 :
56 : typedef ::std::vector<OUString> StringVector_t;
57 : template <class T>
58 : class WW8Sttb : public WW8Struct
59 : {
60 : typedef ::boost::shared_ptr< void > ExtraPointer_t;
61 : typedef ::std::vector< ExtraPointer_t > ExtrasVector_t;
62 : bool bDoubleByteCharacters;
63 : StringVector_t m_Strings;
64 : ExtrasVector_t m_Extras;
65 :
66 : public:
67 : WW8Sttb(SvStream& rSt, sal_Int32 nPos, sal_uInt32 nSize);
68 : virtual ~WW8Sttb();
69 :
70 : sal_uInt32 getCount() const;
71 : OUString getEntry(sal_uInt32 nEntry) const
72 : {
73 : return m_Strings[nEntry];
74 : }
75 :
76 7 : StringVector_t & getStrings()
77 : {
78 7 : return m_Strings;
79 : }
80 :
81 : const T * getExtra(sal_uInt32 nEntry) const
82 : {
83 : return dynamic_cast<const T *> (m_Extras[nEntry].get());
84 : }
85 : };
86 :
87 : template <class T>
88 73 : WW8Sttb<T>::WW8Sttb(SvStream& rSt, sal_Int32 nPos, sal_uInt32 nSize)
89 73 : : WW8Struct(rSt, nPos, nSize), bDoubleByteCharacters(false)
90 : {
91 73 : sal_uInt32 nOffset = 0;
92 :
93 73 : if (getU16(nOffset) == 0xffff)
94 : {
95 57 : bDoubleByteCharacters = true;
96 57 : nOffset += 2;
97 : }
98 :
99 73 : sal_uInt16 nCount = getU16(nOffset);
100 73 : sal_uInt16 ncbExtra = getU16(nOffset + 2);
101 :
102 73 : nOffset += 4;
103 26028 : for (sal_uInt16 i = 0; i < nCount; i++)
104 : {
105 25955 : if (bDoubleByteCharacters)
106 : {
107 1026 : sal_uInt16 nStrLen = getU16(nOffset);
108 :
109 1026 : m_Strings.push_back(getUString(nOffset +2, nStrLen));
110 :
111 1026 : nOffset += 2 + 2 * nStrLen;
112 : }
113 : else
114 : {
115 24929 : sal_uInt8 nStrLen = getU8(nOffset);
116 :
117 24929 : m_Strings.push_back(getUString(nOffset, nStrLen));
118 :
119 24929 : nOffset += 1 + nStrLen;
120 : }
121 :
122 25955 : if (ncbExtra > 0)
123 : {
124 24929 : ExtraPointer_t pExtra(new T(this, nOffset, ncbExtra));
125 24929 : m_Extras.push_back(pExtra);
126 :
127 24929 : nOffset += ncbExtra;
128 : }
129 : }
130 73 : }
131 :
132 : template <class T>
133 146 : WW8Sttb<T>::~WW8Sttb()
134 : {
135 146 : }
136 : }
137 :
138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|