LibreOffice Module sw (master) 1
ww8glsy.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 <memory>
21#include <tools/urlobj.hxx>
22#include <svl/urihelper.hxx>
23#include <osl/diagnose.h>
24#include <ndtxt.hxx>
25#include <pam.hxx>
26#include <poolfmt.hxx>
27#include <shellio.hxx>
28#include <docsh.hxx>
29#include <fmtanchr.hxx>
30#include <frmfmt.hxx>
31#include <doc.hxx>
33#include <frameformats.hxx>
34#include "ww8glsy.hxx"
35#include "ww8par.hxx"
36
38 : m_rStrm(refStrm)
39 , m_xStg(pStg)
40 , m_nStrings(0)
41{
42 refStrm->SetEndian(SvStreamEndian::LITTLE);
43 WW8Fib aWwFib(*refStrm, nVersion);
44
45 if (aWwFib.m_nFibBack >= 0x6A) //Word97
46 {
48 aWwFib.m_fWhichTableStm ? OUString(SL::a1Table) : OUString(SL::a0Table),
49 StreamMode::STD_READ);
50
51 if (m_xTableStream.is() && ERRCODE_NONE == m_xTableStream->GetError())
52 {
53 m_xTableStream->SetEndian(SvStreamEndian::LITTLE);
54 m_xGlossary = std::make_shared<WW8GlossaryFib>(*refStrm, nVersion, aWwFib);
55 }
56 }
57}
58
60{
61 bool bRet=false;
62 for( sal_uInt16 nCnt = pDoc->GetSpzFrameFormats()->size(); nCnt; )
63 {
64 const SwFrameFormat* pFrameFormat = (*pDoc->GetSpzFrameFormats())[ --nCnt ];
65 if ( RES_FLYFRMFMT != pFrameFormat->Which() &&
66 RES_DRAWFRMFMT != pFrameFormat->Which() )
67 continue;
68 const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor();
69 SwNode const*const pAnchorNode = rAnchor.GetAnchorNode();
70 if (pAnchorNode &&
71 ((RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId()) ||
72 (RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId())) &&
73 rIdx == *pAnchorNode )
74 {
75 bRet=true;
76 break;
77 }
78 }
79 return bRet;
80}
81
83 bool bSaveRelFile, const std::vector<OUString>& rStrings,
84 const std::vector<ww::bytes>& rExtra)
85{
86 // this code will be called after reading all text into the
87 // empty sections
88 const OUString aOldURL( rBlocks.GetBaseURL() );
89 bool bRet=false;
90 if( bSaveRelFile )
91 {
92 rBlocks.SetBaseURL(
94 INetURLObject(), rBlocks.GetFileName(),
96 }
97 else
98 rBlocks.SetBaseURL( OUString() );
99
100 SwNodeIndex aDocEnd( pD->GetNodes().GetEndOfContent() );
101 SwNodeIndex aStart( *aDocEnd.GetNode().StartOfSectionNode(), 1 );
102
103 // search the first NormalStartNode
104 while( !( aStart.GetNode().IsStartNode() && SwNormalStartNode ==
105 aStart.GetNode().GetStartNode()->GetStartNodeType()) &&
106 aStart < aDocEnd )
107 ++aStart;
108
109 if( aStart < aDocEnd )
110 {
112 (RES_POOLCOLL_STANDARD, false);
113 sal_uInt16 nGlosEntry = 0;
114 SwContentNode* pCNd = nullptr;
115 do {
116 SwPaM aPam( aStart );
117 {
118 SwPosition& rPos = *aPam.GetPoint();
119 rPos.Adjust(SwNodeOffset(1));
120 pCNd = rPos.GetNode().GetTextNode();
121 if( nullptr == pCNd )
122 {
123 pCNd = pD->GetNodes().MakeTextNode( rPos.GetNode(), pColl );
124 rPos.Assign(*pCNd);
125 }
126 }
127 aPam.SetMark();
128 {
129 SwPosition& rPos = *aPam.GetPoint();
130 rPos.Assign(aStart.GetNode().EndOfSectionIndex() - 1);
131 if(( nullptr == ( pCNd = rPos.GetNode().GetContentNode() ) )
132 || HasBareGraphicEnd(pD,rPos.GetNode()))
133 {
134 rPos.Adjust(SwNodeOffset(1));
135 pCNd = pD->GetNodes().MakeTextNode( rPos.GetNode(), pColl );
136 rPos.Assign(*pCNd);
137 }
138 }
139 aPam.GetPoint()->SetContent( pCNd->Len() );
140
141 // now we have the right selection for one entry. Copy this to
142 // the defined TextBlock, but only if it is not an autocorrection
143 // entry (== -1) otherwise the group indicates the group in the
144 // sttbfglsystyle list that this entry belongs to. Unused at the
145 // moment
146 const ww::bytes &rData = rExtra[nGlosEntry];
147 sal_uInt16 n = SVBT16ToUInt16( &(rData[2]) );
148 if(n != 0xFFFF)
149 {
150 rBlocks.ClearDoc();
151 const OUString &rLNm = rStrings[nGlosEntry];
152
153 OUString sShortcut = rLNm;
154
155 // Need to check make sure the shortcut is not already being used
156 sal_Int32 nStart = 0;
157 sal_uInt16 nCurPos = rBlocks.GetIndex( sShortcut );
158 while( sal_uInt16(-1) != nCurPos )
159 {
160 sShortcut = rLNm + OUString::number(++nStart); // add a Number to it
161 nCurPos = rBlocks.GetIndex( sShortcut );
162 }
163
164 if( rBlocks.BeginPutDoc( sShortcut, sShortcut )) // Make the shortcut and the name the same
165
166 {
167 SwDoc* pGlDoc = rBlocks.GetDoc();
168 SwNodeIndex aIdx( pGlDoc->GetNodes().GetEndOfContent(),
169 -1 );
170 pCNd = aIdx.GetNode().GetContentNode();
171 SwPosition aPos(aIdx, pCNd, pCNd ? pCNd->Len() : 0);
173 rBlocks.PutDoc();
174 }
175 }
176 aStart = aStart.GetNode().EndOfSectionIndex() + 1;
177 ++nGlosEntry;
178 } while( aStart.GetNode().IsStartNode() &&
179 SwNormalStartNode == aStart.GetNode().
180 GetStartNode()->GetStartNodeType());
181 bRet=true;
182 }
183
184// this code will be called after reading all text into the empty sections
185
186 rBlocks.SetBaseURL( aOldURL );
187 return bRet;
188}
189
190bool WW8Glossary::Load( SwTextBlocks &rBlocks, bool bSaveRelFile )
191{
192 bool bRet=false;
193 if (m_xGlossary && m_xGlossary->IsGlossaryFib() && rBlocks.StartPutMuchBlockEntries())
194 {
195 //read the names of the autotext entries
196 std::vector<OUString> aStrings;
197 std::vector<ww::bytes> aData;
198
199 rtl_TextEncoding eStructCharSet =
200 WW8Fib::GetFIBCharset(m_xGlossary->m_chseTables, m_xGlossary->m_lid);
201
202 WW8ReadSTTBF(true, *m_xTableStream, m_xGlossary->m_fcSttbfglsy,
203 m_xGlossary->m_lcbSttbfglsy, 0, eStructCharSet, aStrings, &aData );
204
205 m_rStrm->Seek(0);
206
207 m_nStrings = static_cast< sal_uInt16 >(aStrings.size());
208 if ( 0 != m_nStrings )
209 {
210 SfxObjectShellLock xDocSh(new SwDocShell(SfxObjectCreateMode::INTERNAL));
211 if (xDocSh->DoInitNew())
212 {
213 SwDoc *pD = static_cast<SwDocShell*>((&xDocSh))->GetDoc();
214
215 SwNodeIndex aIdx(
217 if( !aIdx.GetNode().IsTextNode() )
218 {
219 OSL_ENSURE( false, "Where is the TextNode?" );
220 pD->GetNodes().GoNext( &aIdx );
221 }
222 SwPaM aPamo( aIdx );
223 std::unique_ptr<SwWW8ImplReader> xRdr(new SwWW8ImplReader(
224 m_xGlossary->m_nVersion, m_xStg.get(), m_rStrm.get(), *pD, rBlocks.GetBaseURL(),
225 true, false, *aPamo.GetPoint()));
226 xRdr->LoadDoc(this);
227 bRet = MakeEntries(pD, rBlocks, bSaveRelFile, aStrings, aData);
228 }
229 xDocSh->DoClose();
230 rBlocks.EndPutMuchBlockEntries();
231 }
232 }
233 return bRet;
234}
235
237{
238 sal_uInt32 nGlossaryFibOffset = 0;
239 if ( rFib.m_fDot ) // it's a template
240 {
241 if ( rFib.m_pnNext )
242 nGlossaryFibOffset = ( rFib.m_pnNext * 512 );
243 }
244 return nGlossaryFibOffset;
245}
246
247/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ CheckPosInFly
check if target position is in fly anchored at source range
virtual bool CopyRange(SwPaM &rPam, SwPosition &rPos, SwCopyFlags flags) const =0
Copy a selected content range to a position.
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
tools::SvRef< SotStorageStream > OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
virtual sal_Int32 Len() const
Definition: node.cxx:1256
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
Definition: doc.hxx:197
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:329
SwNodes & GetNodes()
Definition: doc.hxx:422
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:440
const sw::FrameFormats< sw::SpzFrameFormat * > * GetSpzFrameFormats() const
Definition: doc.hxx:759
FlyAnchors.
Definition: fmtanchr.hxx:37
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:67
SwNode * GetAnchorNode() const
Definition: atrfrm.cxx:1614
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:88
Style of a layout element.
Definition: frmfmt.hxx:72
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:123
Base class of the Writer document model elements.
Definition: node.hxx:98
SwStartNode * GetStartNode()
Definition: node.hxx:642
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:901
bool IsStartNode() const
Definition: node.hxx:187
bool IsTextNode() const
Definition: node.hxx:190
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:153
SwNodeOffset EndOfSectionIndex() const
Definition: node.hxx:691
SwContentNode * GetContentNode()
Definition: node.hxx:666
SwTextNode * MakeTextNode(SwNode &rWhere, SwTextFormatColl *pColl, bool bNewFrames=true)
Implementations of "Make...Node" are in the given .cxx-files.
Definition: ndtxt.cxx:121
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:165
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1299
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
const SwPosition * GetPoint() const
Definition: pam.hxx:253
SwStartNodeType GetStartNodeType() const
Definition: node.hxx:364
bool BeginPutDoc(const OUString &, const OUString &)
Definition: swblocks.cxx:385
void EndPutMuchBlockEntries()
Definition: swblocks.cxx:563
SwDoc * GetDoc()
Definition: swblocks.cxx:481
OUString const & GetFileName() const
Definition: swblocks.cxx:497
void ClearDoc()
Definition: swblocks.cxx:488
OUString GetBaseURL() const
Definition: swblocks.cxx:569
bool StartPutMuchBlockEntries()
Definition: swblocks.cxx:555
sal_uInt16 PutDoc()
Definition: swblocks.cxx:409
sal_uInt16 GetIndex(const OUString &) const
Definition: swblocks.cxx:261
void SetBaseURL(const OUString &rURL)
Definition: swblocks.cxx:576
Represents the style of a paragraph.
Definition: fmtcol.hxx:61
FIB - the File Information Block.
Definition: ww8scan.hxx:1106
bool m_fWhichTableStm
Definition: ww8scan.hxx:1154
WW8_PN m_pnNext
Definition: ww8scan.hxx:1146
static rtl_TextEncoding GetFIBCharset(sal_uInt16 chs, LanguageType nLidLocale)
Definition: ww8scan.cxx:6671
sal_uInt16 m_nFibBack
Definition: ww8scan.hxx:1169
bool m_fDot
Definition: ww8scan.hxx:1148
static sal_uInt32 FindGlossaryFibOffset(const WW8Fib &rFib)
Definition: ww8glsy.cxx:236
tools::SvRef< SotStorage > m_xStg
Definition: ww8glsy.hxx:78
WW8Glossary(tools::SvRef< SotStorageStream > &refStrm, sal_uInt8 nVersion, SotStorage *pStg)
Definition: ww8glsy.cxx:37
static bool MakeEntries(SwDoc *pD, SwTextBlocks &rBlocks, bool bSaveRelFile, const std::vector< OUString > &rStrings, const std::vector< ww::bytes > &rExtra)
Definition: ww8glsy.cxx:82
tools::SvRef< SotStorageStream > & m_rStrm
Definition: ww8glsy.hxx:77
tools::SvRef< SotStorageStream > m_xTableStream
Definition: ww8glsy.hxx:76
bool Load(SwTextBlocks &rBlocks, bool bSaveRelFile)
Definition: ww8glsy.cxx:190
static bool HasBareGraphicEnd(SwDoc *pD, SwNode const &rIdx)
Definition: ww8glsy.cxx:59
std::shared_ptr< WW8GlossaryFib > m_xGlossary
Definition: ww8glsy.hxx:75
sal_uInt16 m_nStrings
Definition: ww8glsy.hxx:79
T * get() const
bool is() const
static SwNode * GetStartNode(SwOutlineNodes const *pOutlNds, int nOutlineLevel, SwOutlineNodes::size_type *nOutl)
Definition: docglbl.cxx:89
#define ERRCODE_NONE
sal_Int16 nVersion
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(162)
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(165)
sal_Int64 n
constexpr OUStringLiteral a0Table
Definition: ww8scan.hxx:47
constexpr OUStringLiteral aData
Definition: ww8scan.hxx:48
constexpr OUStringLiteral a1Table
Definition: ww8scan.hxx:46
SVL_DLLPUBLIC Link< OUString *, bool > const & GetMaybeFileHdl()
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
std::vector< sal_uInt8 > bytes
Definition: types.hxx:29
@ SwNormalStartNode
Definition: ndtyp.hxx:52
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
@ RES_POOLCOLL_STANDARD
Standard.
Definition: poolfmt.hxx:250
Marks a position in the document model.
Definition: pam.hxx:38
void Adjust(SwNodeOffset nDelta)
Adjust node position, and resets content position to zero.
Definition: pam.cxx:257
SwNode & GetNode() const
Definition: pam.hxx:81
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:231
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:267
unsigned char sal_uInt8
void WW8ReadSTTBF(bool bVer8, SvStream &rStrm, sal_uInt32 nStart, sal_Int32 nLen, sal_uInt16 nExtraLen, rtl_TextEncoding eCS, std::vector< OUString > &rArray, std::vector< ww::bytes > *pExtraArray, std::vector< OUString > *pValueArray)
reads array of strings (see MS documentation: String Table stored in File) returns NOT the original p...
Definition: ww8scan.cxx:4152