LibreOffice Module sw (master)  1
WW8Sttbf.cxx
Go to the documentation of this file.
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 <sal/config.h>
21 
22 #include <algorithm>
23 #include <iostream>
24 #include "WW8Sttbf.hxx"
25 #include <osl/endian.h>
26 #include <o3tl/make_shared.hxx>
27 #include <tools/stream.hxx>
28 #include <sal/log.hxx>
29 #include <osl/diagnose.h>
30 
31 namespace ww8
32 {
33  WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize)
34  : mn_offset(0), mn_size(0)
35  {
36  if (checkSeek(rSt, nPos))
37  {
38  std::size_t nRemainingSize = rSt.remainingSize();
39  nSize = std::min<sal_uInt32>(nRemainingSize, nSize);
40  m_pData = o3tl::make_shared_array<sal_uInt8>(nSize);
41  mn_size = rSt.ReadBytes(m_pData.get(), nSize);
42  }
43  OSL_ENSURE(mn_size == nSize, "short read in WW8Struct::WW8Struct");
44  }
45 
46  WW8Struct::WW8Struct(WW8Struct const * pStruct, sal_uInt32 nPos, sal_uInt32 nSize)
47  : m_pData(pStruct->m_pData), mn_offset(pStruct->mn_offset + nPos)
48  , mn_size(nSize)
49  {
50  }
51 
53  {
54  }
55 
56  sal_uInt8 WW8Struct::getU8(sal_uInt32 nOffset)
57  {
58  sal_uInt8 nResult = 0;
59 
60  if (nOffset < mn_size)
61  {
62  nResult = m_pData.get()[mn_offset + nOffset];
63  }
64 
65  return nResult;
66  }
67 
68  OUString WW8Struct::getUString(sal_uInt32 nOffset,
69  sal_uInt32 nCount)
70  {
71  OUString aResult;
72 
73  if (nCount > 0)
74  {
75  //clip to available
76  sal_uInt32 nStartOff = mn_offset + nOffset;
77  if (nStartOff >= mn_size)
78  return aResult;
79  sal_uInt32 nAvailable = (mn_size - nStartOff)/sizeof(sal_Unicode);
80  if (nCount > nAvailable)
81  nCount = nAvailable;
82 #if defined OSL_LITENDIAN
83  aResult = OUString(reinterpret_cast<const sal_Unicode *>(
84  m_pData.get() + nStartOff), nCount);
85 #else
86  OUStringBuffer aBuf;
87  for (sal_uInt32 i = 0; i < nCount; ++i)
88  aBuf.append(static_cast<sal_Unicode>(getU16(nStartOff+i*2)));
89  aResult = aBuf.makeStringAndClear();
90 #endif
91  }
92 
93  SAL_INFO( "sw.ww8.level2", "<WW8Struct-getUString offset=\"" << nOffset
94  << "\" count=\"" << nCount << "\">" << aResult << "</WW8Struct-getUString>" );
95 
96  return aResult;
97 
98  }
99 }
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getUString(sal_uInt32 nOffset, sal_uInt32 nCount)
Definition: WW8Sttbf.cxx:68
std::shared_ptr< sal_uInt8 > m_pData
Definition: WW8Sttbf.hxx:36
aBuf
WW8Struct(SvStream &rSt, sal_uInt32 nPos, sal_uInt32 nSize)
Definition: WW8Sttbf.cxx:33
sal_uInt16 sal_Unicode
FmFilterData * m_pData
sal_uInt64 remainingSize()
bool checkSeek(SvStream &rSt, sal_uInt64 nOffset)
int i
std::size_t ReadBytes(void *pData, std::size_t nSize)
unsigned char sal_uInt8
#define SAL_INFO(area, stream)
sal_uInt16 getU16(sal_uInt32 nOffset)
Definition: WW8Sttbf.hxx:47
sal_uInt32 mn_offset
Definition: WW8Sttbf.hxx:37
sal_uInt8 getU8(sal_uInt32 nOffset)
Definition: WW8Sttbf.cxx:56
virtual ~WW8Struct() override
Definition: WW8Sttbf.cxx:52
sal_uInt32 mn_size
Definition: WW8Sttbf.hxx:38