1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
30 typedef boost::shared_array
<sal_uInt8
> DataArray_t
;
32 class WW8Struct
: public ::sw::ExternalData
39 WW8Struct(SvStream
& rSt
, sal_uInt32 nPos
, sal_uInt32 nSize
);
40 WW8Struct(WW8Struct
* pStruct
, sal_uInt32 nPos
, sal_uInt32 nSize
);
43 sal_uInt8
getU8(sal_uInt32 nOffset
);
45 sal_uInt16
getU16(sal_uInt32 nOffset
)
46 { return getU8(nOffset
) + (getU8(nOffset
+ 1) << 8); }
48 sal_uInt32
getU32(sal_uInt32 nOffset
)
49 { return getU16(nOffset
) + (getU16(nOffset
+ 1) << 16); }
51 OUString
getUString(sal_uInt32 nOffset
, sal_uInt32 nCount
);
53 OUString
getString(sal_uInt32 nOffset
, sal_uInt32 nCount
);
56 typedef ::std::vector
<OUString
> StringVector_t
;
58 class WW8Sttb
: public WW8Struct
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
;
67 WW8Sttb(SvStream
& rSt
, sal_Int32 nPos
, sal_uInt32 nSize
);
70 sal_uInt32
getCount() const;
71 OUString
getEntry(sal_uInt32 nEntry
) const
73 return m_Strings
[nEntry
];
76 StringVector_t
& getStrings()
81 const T
* getExtra(sal_uInt32 nEntry
) const
83 return dynamic_cast<const T
*> (m_Extras
[nEntry
].get());
88 WW8Sttb
<T
>::WW8Sttb(SvStream
& rSt
, sal_Int32 nPos
, sal_uInt32 nSize
)
89 : WW8Struct(rSt
, nPos
, nSize
), bDoubleByteCharacters(false)
91 sal_uInt32 nOffset
= 0;
93 if (getU16(nOffset
) == 0xffff)
95 bDoubleByteCharacters
= true;
99 sal_uInt16 nCount
= getU16(nOffset
);
100 sal_uInt16 ncbExtra
= getU16(nOffset
+ 2);
103 for (sal_uInt16 i
= 0; i
< nCount
; i
++)
105 if (bDoubleByteCharacters
)
107 sal_uInt16 nStrLen
= getU16(nOffset
);
109 m_Strings
.push_back(getUString(nOffset
+2, nStrLen
));
111 nOffset
+= 2 + 2 * nStrLen
;
115 sal_uInt8 nStrLen
= getU8(nOffset
);
117 m_Strings
.push_back(getUString(nOffset
, nStrLen
));
119 nOffset
+= 1 + nStrLen
;
124 ExtraPointer_t
pExtra(new T(this, nOffset
, ncbExtra
));
125 m_Extras
.push_back(pExtra
);
133 WW8Sttb
<T
>::~WW8Sttb()
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */