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 <iostream>
21 : #include <dbgoutsw.hxx>
22 : #include "WW8Sttbf.hxx"
23 : #include "ww8scan.hxx"
24 : #include <cstdio>
25 : #include <osl/endian.h>
26 : #include <rtl/ustrbuf.hxx>
27 :
28 : #if OSL_DEBUG_LEVEL > 1
29 : #include <stdio.h>
30 : #endif
31 :
32 : namespace ww8
33 : {
34 37 : WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize)
35 37 : : mn_offset(0), mn_size(0)
36 : {
37 37 : if (checkSeek(rSt, nPos))
38 : {
39 37 : mp_data.reset(new sal_uInt8[nSize]);
40 37 : mn_size = rSt.Read(mp_data.get(), nSize);
41 : }
42 : OSL_ENSURE(mn_size == nSize, "short read in WW8Struct::WW8Struct");
43 37 : }
44 :
45 0 : WW8Struct::WW8Struct(WW8Struct * pStruct, sal_uInt32 nPos, sal_uInt32 nSize)
46 : : mp_data(pStruct->mp_data), mn_offset(pStruct->mn_offset + nPos)
47 0 : , mn_size(nSize)
48 : {
49 0 : }
50 :
51 28 : WW8Struct::~WW8Struct()
52 : {
53 28 : }
54 :
55 1302 : sal_uInt8 WW8Struct::getU8(sal_uInt32 nOffset)
56 : {
57 1302 : sal_uInt8 nResult = 0;
58 :
59 1302 : if (nOffset < mn_size)
60 : {
61 1272 : nResult = mp_data[mn_offset + nOffset];
62 : }
63 :
64 1302 : return nResult;
65 : }
66 :
67 540 : ::rtl::OUString WW8Struct::getUString(sal_uInt32 nOffset,
68 : sal_uInt32 nCount)
69 : {
70 540 : ::rtl::OUString aResult;
71 :
72 540 : if (nCount > 0)
73 : {
74 : //clip to available
75 73 : sal_uInt32 nStartOff = mn_offset + nOffset;
76 73 : if (nStartOff >= mn_size)
77 0 : return aResult;
78 73 : sal_uInt32 nAvailable = (mn_size - nStartOff)/sizeof(sal_Unicode);
79 73 : if (nCount > nAvailable)
80 0 : nCount = nAvailable;
81 : #if defined OSL_LITENDIAN
82 : aResult = rtl::OUString(reinterpret_cast<const sal_Unicode *>(
83 73 : mp_data.get() + nStartOff), nCount);
84 : #else
85 : rtl::OUStringBuffer aBuf;
86 : for (sal_uInt32 i = 0; i < nCount; ++i)
87 : aBuf.append(static_cast<sal_Unicode>(getU16(nStartOff+i*2)));
88 : aResult = aBuf.makeStringAndClear();
89 : #endif
90 : }
91 :
92 : SAL_INFO( "sw.ww8.level2", "<WW8Struct-getUString" << " offset=\"" << nOffset
93 : << "\" count=\"" << nCount << "\"" << ">" << aResult << "</WW8Struct-getUString>" );
94 :
95 540 : return aResult;
96 :
97 : }
98 18 : }
99 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|