LibreOffice Module sw (master)  1
txatritr.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 <txatritr.hxx>
21 
22 #include <com/sun/star/i18n/ScriptType.hpp>
23 #include <com/sun/star/i18n/XBreakIterator.hpp>
24 #include <fchrfmt.hxx>
25 #include <charfmt.hxx>
26 #include <breakit.hxx>
27 #include <ndtxt.hxx>
28 #include <txatbase.hxx>
29 
30 using namespace ::com::sun::star;
31 
33  const OUString& rStr, sal_Int32 nStt, bool const bFrwrd)
34  : m_rText(rStr)
35  , m_nChgPos(rStr.getLength())
36  , nCurScript(i18n::ScriptType::WEAK)
37  , bForward(bFrwrd)
38 {
39  assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
40  if ( ! bFrwrd && nStt )
41  --nStt;
42 
43  sal_Int32 nPos = nStt;
44  nCurScript = g_pBreakIt->GetBreakIter()->getScriptType(m_rText, nPos);
45  if( i18n::ScriptType::WEAK == nCurScript )
46  {
47  if( nPos )
48  {
49  nPos = g_pBreakIt->GetBreakIter()->beginOfScript(
50  m_rText, nPos, nCurScript);
51  if (nPos > 0 && nPos < m_rText.getLength())
52  {
53  nStt = --nPos;
54  nCurScript =
55  g_pBreakIt->GetBreakIter()->getScriptType(m_rText,nPos);
56  }
57  }
58  }
59 
61  ? g_pBreakIt->GetBreakIter()->endOfScript(
62  m_rText, nStt, nCurScript)
63  : g_pBreakIt->GetBreakIter()->beginOfScript(
64  m_rText, nStt, nCurScript);
65 }
66 
68 {
69  assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
70  if (bForward && m_nChgPos >= 0 && m_nChgPos < m_rText.getLength())
71  {
72  nCurScript =
73  g_pBreakIt->GetBreakIter()->getScriptType(m_rText, m_nChgPos);
74  m_nChgPos = g_pBreakIt->GetBreakIter()->endOfScript(
76  }
77  else if (!bForward && m_nChgPos > 0)
78  {
79  --m_nChgPos;
80  nCurScript =
81  g_pBreakIt->GetBreakIter()->getScriptType(m_rText, m_nChgPos);
82  m_nChgPos = g_pBreakIt->GetBreakIter()->beginOfScript(
84  }
85 }
86 
88  sal_Int32 nStt )
89  : aSIter( rTNd.GetText(), nStt ),
90  rTextNd( rTNd ),
91  pParaItem( nullptr ),
92  nAttrPos( 0 ),
93  nChgPos( nStt )
94 {
95  SearchNextChg();
96 }
97 
99 {
100  bool bRet = false;
101  if (nChgPos < aSIter.GetText().getLength())
102  {
103  bRet = true;
104  if( !aStack.empty() )
105  {
106  do {
107  const SwTextAttr* pHt = aStack.front();
108  const sal_Int32 nEndPos = *pHt->End();
109  if( nChgPos >= nEndPos )
110  aStack.pop_front();
111  else
112  break;
113  } while( !aStack.empty() );
114  }
115 
116  if( !aStack.empty() )
117  {
118  const size_t nSavePos = nAttrPos;
119  SearchNextChg();
120  if( !aStack.empty() )
121  {
122  const SwTextAttr* pHt = aStack.front();
123  const sal_Int32 nEndPos = *pHt->End();
124  if( nChgPos >= nEndPos )
125  {
126  nChgPos = nEndPos;
127  nAttrPos = nSavePos;
128 
129  if( RES_TXTATR_CHARFMT == pHt->Which() )
130  {
131  const sal_uInt16 nWId = GetWhichOfScript( RES_CHRATR_LANGUAGE, aSIter.GetCurrScript() );
133  }
134  else
135  pCurItem = &pHt->GetAttr();
136 
137  aStack.pop_front();
138  }
139  }
140  }
141  else
142  SearchNextChg();
143  }
144  return bRet;
145 }
146 
148 {
149  size_t nIns = 0;
150  const sal_Int32 nEndPos = *rAttr.End();
151  for( ; nIns < aStack.size(); ++nIns )
152  if( *aStack[ nIns ]->End() > nEndPos )
153  break;
154 
155  aStack.insert( aStack.begin() + nIns, &rAttr );
156 }
157 
159 {
160  sal_uInt16 nWh = 0;
161  if( nChgPos == aSIter.GetScriptChgPos() )
162  {
163  aSIter.Next();
164  pParaItem = nullptr;
165  nAttrPos = 0; // must be restart at the beginning, because
166  // some attributes can start before or inside
167  // the current scripttype!
168  aStack.clear();
169  }
170  if( !pParaItem )
171  {
173  pParaItem = &rTextNd.GetSwAttrSet().Get( nWh );
174  }
175 
176  sal_Int32 nStt = nChgPos;
179 
180  const SwpHints* pHts = rTextNd.GetpSwpHints();
181  if( pHts )
182  {
183  if( !nWh )
184  {
186  }
187 
188  const SfxPoolItem* pItem = nullptr;
189  for( ; nAttrPos < pHts->Count(); ++nAttrPos )
190  {
191  const SwTextAttr* pHt = pHts->Get( nAttrPos );
192  const sal_Int32* pEnd = pHt->End();
193  const sal_Int32 nHtStt = pHt->GetStart();
194  if( nHtStt < nStt && ( !pEnd || *pEnd <= nStt ))
195  continue;
196 
197  if( nHtStt >= nChgPos )
198  break;
199 
200  pItem = CharFormat::GetItem( *pHt, nWh );
201  if ( pItem )
202  {
203  if( nHtStt > nStt )
204  {
205  if( nChgPos > nHtStt )
206  nChgPos = nHtStt;
207  break;
208  }
209  AddToStack( *pHt );
210  pCurItem = pItem;
211  if( *pEnd < nChgPos )
212  nChgPos = *pEnd;
213  }
214  }
215  }
216 }
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 & GetStart()
start position
Definition: txatbase.hxx:77
const OUString & GetText() const
Definition: txatritr.hxx:46
#define RES_CHRATR_LANGUAGE
Definition: hintids.hxx:78
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:219
sal_Int32 GetScriptChgPos() const
Definition: txatritr.hxx:45
const SfxPoolItem * pCurItem
Definition: txatritr.hxx:56
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
Extracts pool item of type nWhich from rAttr.
Definition: atrstck.cxx:159
SwLanguageIterator(const SwTextNode &rTextNd, sal_Int32 nStart)
Definition: txatritr.cxx:87
#define RES_TXTATR_CHARFMT
Definition: hintids.hxx:142
sal_uInt16 Which() const
Definition: txatbase.hxx:105
sal_Int32 m_nChgPos
Definition: txatritr.hxx:34
SwScriptIterator(const OUString &rStr, sal_Int32 nStart, bool bFrwrd=true)
Definition: txatritr.cxx:32
sal_uInt16 GetCurrScript() const
Definition: txatritr.hxx:44
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:34
std::deque< const SwTextAttr * > aStack
Definition: txatritr.hxx:53
const SwTextNode & rTextNd
Definition: txatritr.hxx:54
size_t Count() const
Definition: ndhints.hxx:152
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:154
sal_Int32 nChgPos
Definition: txatritr.hxx:58
sal_uInt16 GetWhichOfScript(sal_uInt16 nWhich, sal_uInt16 nScript)
Definition: hints.cxx:195
const OUString & m_rText
Definition: txatritr.hxx:33
bool const bForward
Definition: txatritr.hxx:36
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
sal_uInt16 nCurScript
Definition: txatritr.hxx:35
SwCharFormat * GetCharFormat() const
Definition: fchrfmt.hxx:70
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:76
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const sal_Int32 * End() const
Definition: txatbase.hxx:142
const SfxPoolItem & GetFormatAttr(sal_uInt16 nWhich, bool bInParents=true) const
If bInParents is FALSE, search only in this format for attribute.
Definition: format.cxx:379
double getLength(const B2DPolygon &rCandidate)
SwScriptIterator aSIter
Definition: txatritr.hxx:51
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:723
void AddToStack(const SwTextAttr &rAttr)
Definition: txatritr.cxx:147
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter()
Definition: breakit.hxx:62
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:153
ScriptType
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:173
sal_Int32 nPos
const SfxPoolItem * pParaItem
Definition: txatritr.hxx:55