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