LibreOffice Module sw (master)  1
scriptinfo.hxx
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 #ifndef INCLUDED_SW_SOURCE_CORE_INC_SCRIPTINFO_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_SCRIPTINFO_HXX
22 
23 #include <vector>
24 #include <deque>
25 #include <unordered_set>
26 #include <rtl/ustrbuf.hxx>
27 #include <i18nlangtag/lang.h>
28 #include "TextFrameIndex.hxx"
29 
30 class SwTextNode;
31 class SwTextFrame;
32 class Point;
33 class MultiSelection;
34 enum class SwFontScript;
35 namespace sw { struct MergedPara; }
36 
37 #define SPACING_PRECISION_FACTOR 100
38 
39 // encapsulates information about script changes
41 {
42 public:
44 
45 private:
48  {
51  ScriptChangeInfo(TextFrameIndex pos, sal_uInt8 typ) : position(pos), type(typ) {};
52  };
53  //TODO - This is sorted, so should probably be a std::set rather than vector.
54  // But we also use random access (probably unnecessarily).
55  std::vector<ScriptChangeInfo> m_ScriptChanges;
58  {
60  sal_uInt8 const type;
61  DirectionChangeInfo(TextFrameIndex pos, sal_uInt8 typ) : position(pos), type(typ) {};
62  };
63  std::vector<DirectionChangeInfo> m_DirectionChanges;
64  std::deque<TextFrameIndex> m_Kashida;
66  std::unordered_set<size_t> m_KashidaInvalid;
67  std::deque<TextFrameIndex> m_NoKashidaLine;
68  std::deque<TextFrameIndex> m_NoKashidaLineEnd;
69  std::vector<TextFrameIndex> m_HiddenChg;
72  {
76  CompressionChangeInfo(TextFrameIndex pos, TextFrameIndex len, CompType typ) : position(pos), length(len), type(typ) {};
77  };
78  std::vector<CompressionChangeInfo> m_CompressionChanges;
79 #ifdef DBG_UTIL
80  CompType DbgCompType(const TextFrameIndex nPos) const;
81 #endif
82 
85 
86  void UpdateBidiInfo( const OUString& rText );
87  bool IsKashidaValid(size_t nKashPos) const;
88  // returns true if nKashPos is newly marked invalid
89  bool MarkKashidaInvalid(size_t nKashPos);
90  void ClearKashidaInvalid(size_t nKashPos);
92  bool bMark, sal_Int32 nMarkCount);
93  bool IsKashidaLine(TextFrameIndex nCharIdx) const;
94  // examines the range [ nStart, nStart + nEnd ] if there are kanas
95  // returns start index of kana entry in array, otherwise SAL_MAX_SIZE
96  size_t HasKana(TextFrameIndex nStart, TextFrameIndex nEnd) const;
97 
98 public:
99 
100  SwScriptInfo();
101  ~SwScriptInfo();
102 
103  // determines script changes
104  void InitScriptInfo(const SwTextNode& rNode, sw::MergedPara const* pMerged, bool bRTL);
105  void InitScriptInfo(const SwTextNode& rNode, sw::MergedPara const* pMerged);
106 
107  // set/get position from which data is invalid
109  {
110  if (nPos < m_nInvalidityPos)
111  m_nInvalidityPos = nPos;
112  }
114  {
115  return m_nInvalidityPos;
116  }
117 
118  // get default direction for paragraph
119  sal_uInt8 GetDefaultDir() const { return m_nDefaultDir; };
120 
121  // array operations, nCnt refers to array position
122  size_t CountScriptChg() const { return m_ScriptChanges.size(); }
123  TextFrameIndex GetScriptChg(const size_t nCnt) const
124  {
125  assert(nCnt < m_ScriptChanges.size());
126  return m_ScriptChanges[nCnt].position;
127  }
128  sal_uInt8 GetScriptType( const size_t nCnt ) const
129  {
130  assert( nCnt < m_ScriptChanges.size());
131  return m_ScriptChanges[nCnt].type;
132  }
133 
134  size_t CountDirChg() const { return m_DirectionChanges.size(); }
135  TextFrameIndex GetDirChg(const size_t nCnt) const
136  {
137  assert(nCnt < m_DirectionChanges.size());
138  return m_DirectionChanges[ nCnt ].position;
139  }
140  sal_uInt8 GetDirType( const size_t nCnt ) const
141  {
142  assert(nCnt < m_DirectionChanges.size());
143  return m_DirectionChanges[ nCnt ].type;
144  }
145 
146  size_t CountKashida() const
147  {
148  return m_Kashida.size();
149  }
150 
151  TextFrameIndex GetKashida(const size_t nCnt) const
152  {
153  assert(nCnt < m_Kashida.size());
154  return m_Kashida[nCnt];
155  }
156 
157  size_t CountCompChg() const { return m_CompressionChanges.size(); };
158  TextFrameIndex GetCompStart(const size_t nCnt) const
159  {
160  assert(nCnt < m_CompressionChanges.size());
161  return m_CompressionChanges[ nCnt ].position;
162  }
163  TextFrameIndex GetCompLen(const size_t nCnt) const
164  {
165  assert(nCnt < m_CompressionChanges.size());
166  return m_CompressionChanges[ nCnt ].length;
167  }
168  CompType GetCompType( const size_t nCnt ) const
169  {
170  assert(nCnt < m_CompressionChanges.size());
171  return m_CompressionChanges[ nCnt ].type;
172  }
173 
174  size_t CountHiddenChg() const { return m_HiddenChg.size(); };
175  TextFrameIndex GetHiddenChg(const size_t nCnt) const
176  {
177  assert(nCnt < m_HiddenChg.size());
178  return m_HiddenChg[ nCnt ];
179  }
181  static void CalcHiddenRanges(const SwTextNode& rNode, MultiSelection& rHiddenMulti);
182  static void selectHiddenTextProperty(const SwTextNode& rNode, MultiSelection &rHiddenMulti);
183  static void selectRedLineDeleted(const SwTextNode& rNode, MultiSelection &rHiddenMulti, bool bSelect=true);
184 
185  // "high" level operations, nPos refers to string position
187  sal_Int16 ScriptType(const TextFrameIndex nPos) const;
188 
189  // Returns the position of the next direction level change.
190  // If bLevel is set, the position of the next level which is smaller
191  // than the level at position nPos is returned. This is required to
192  // obtain the end of a SwBidiPortion
194  const sal_uInt8* pLevel = nullptr) const;
195  sal_uInt8 DirType(const TextFrameIndex nPos) const;
196 
197  // HIDDEN TEXT STUFF START
198 
223  static bool GetBoundsOfHiddenRange( const SwTextNode& rNode, sal_Int32 nPos,
224  sal_Int32& rnStartPos, sal_Int32& rnEndPos,
225  std::vector<sal_Int32>* pList = nullptr );
226  bool GetBoundsOfHiddenRange(TextFrameIndex nPos, TextFrameIndex & rnStartPos,
227  TextFrameIndex & rnEndPos) const;
228 
229  static bool IsInHiddenRange( const SwTextNode& rNode, sal_Int32 nPos );
230 
245  static sal_Int32 MaskHiddenRanges(
246  const SwTextNode& rNode, OUStringBuffer& rText,
247  const sal_Int32 nStt, const sal_Int32 nEnd,
248  const sal_Unicode cChar );
249 
257  static void DeleteHiddenRanges( SwTextNode& rNode );
258 
259  // HIDDEN TEXT STUFF END
260 
261  // modifies the kerning array according to a given compress value
262  long Compress( long* pKernArray, TextFrameIndex nIdx, TextFrameIndex nLen,
263  const sal_uInt16 nCompress, const sal_uInt16 nFontHeight,
264  const bool bCentered,
265  Point* pPoint = nullptr ) const;
266 
283  sal_Int32 KashidaJustify( long* pKernArray, long* pScrArray,
284  TextFrameIndex nStt, TextFrameIndex nLen, long nSpaceAdd = 0) const;
285 
288  void ClearKashidaInvalid(TextFrameIndex const nStt, TextFrameIndex const nLen)
289  {
290  MarkOrClearKashidaInvalid(nStt, nLen, false, 0);
291  }
292 
296  void MarkKashidasInvalid(sal_Int32 nCnt, const TextFrameIndex* pKashidaPositions);
297 
301  bool MarkKashidasInvalid(sal_Int32 const nCnt,
302  TextFrameIndex const nStt, TextFrameIndex const nLen)
303  {
304  return MarkOrClearKashidaInvalid(nStt, nLen, true, nCnt);
305  }
306 
313  std::vector<TextFrameIndex>& rKashidaPosition);
314 
320 
326 
336  static bool IsArabicText(const OUString& rText, TextFrameIndex nStt, TextFrameIndex nLen);
337 
356  static TextFrameIndex ThaiJustify( const OUString& rText, long* pKernArray,
357  long* pScrArray, TextFrameIndex nIdx,
358  TextFrameIndex nLen,
359  TextFrameIndex nNumberOfBlanks = TextFrameIndex(0),
360  long nSpaceAdd = 0 );
361 
362  static TextFrameIndex CountCJKCharacters(const OUString &rText,
363  TextFrameIndex nPos, TextFrameIndex nEnd, LanguageType aLang);
364 
365  static void CJKJustify( const OUString& rText, long* pKernArray,
366  long* pScrArray, TextFrameIndex nStt,
367  TextFrameIndex nLen, LanguageType aLang,
368  long nSpaceAdd, bool bIsSpaceStop );
369 
372  static SwScriptInfo* GetScriptInfo( const SwTextNode& rNode,
373  SwTextFrame const** o_pFrame = nullptr,
374  bool bAllowInvalid = false);
375 
377  static SwFontScript WhichFont(sal_Int32 nIdx, OUString const & rText);
378 };
379 
380 #endif
381 
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
SwFontScript WhichFont(TextFrameIndex nIdx) const
Definition: porlay.cxx:723
Records a single change in compression.
Definition: scriptinfo.hxx:71
TextFrameIndex length
Length of the segment.
Definition: scriptinfo.hxx:74
TextFrameIndex GetInvalidityA() const
Definition: scriptinfo.hxx:113
TextFrameIndex NextScriptChg(TextFrameIndex nPos) const
Definition: porlay.cxx:1425
TextFrameIndex const position
Character position at which we change direction.
Definition: scriptinfo.hxx:59
sal_uInt8 GetDirType(const size_t nCnt) const
Definition: scriptinfo.hxx:140
sal_uInt8 const type
Direction that we change to.
Definition: scriptinfo.hxx:60
sal_uInt8 type
Script type (Latin/Asian/Complex) that we change to.
Definition: scriptinfo.hxx:50
TextFrameIndex NextHiddenChg(TextFrameIndex nPos) const
Definition: porlay.cxx:1478
void SetInvalidityA(const TextFrameIndex nPos)
Definition: scriptinfo.hxx:108
CompType GetCompType(const size_t nCnt) const
Definition: scriptinfo.hxx:168
void MarkKashidasInvalid(sal_Int32 nCnt, const TextFrameIndex *pKashidaPositions)
Marks nCnt kashida positions as invalid pKashidaPositions: array of char indices relative to the para...
Definition: porlay.cxx:2060
static SwScriptInfo * GetScriptInfo(const SwTextNode &rNode, SwTextFrame const **o_pFrame=nullptr, bool bAllowInvalid=false)
return a frame for the node, ScriptInfo is its member...
Definition: porlay.cxx:2123
std::vector< CompressionChangeInfo > m_CompressionChanges
Definition: scriptinfo.hxx:78
std::deque< TextFrameIndex > m_NoKashidaLine
Definition: scriptinfo.hxx:67
bool IsKashidaLine(TextFrameIndex nCharIdx) const
Definition: porlay.cxx:2034
std::vector< ScriptChangeInfo > m_ScriptChanges
Definition: scriptinfo.hxx:55
Dialog to specify the properties of drop-down form field.
Definition: accframe.hxx:34
static void CJKJustify(const OUString &rText, long *pKernArray, long *pScrArray, TextFrameIndex nStt, TextFrameIndex nLen, LanguageType aLang, long nSpaceAdd, bool bIsSpaceStop)
Definition: porlay.cxx:2381
sal_uInt8 DirType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1466
Records a single change in direction.
Definition: scriptinfo.hxx:57
size_t CountCompChg() const
Definition: scriptinfo.hxx:157
void SetNoKashidaLine(TextFrameIndex nStt, TextFrameIndex nLen)
Use regular blank justification instead of kashdida justification for the given line of text...
Definition: porlay.cxx:2027
sal_uInt16 sal_Unicode
static sal_Int32 MaskHiddenRanges(const SwTextNode &rNode, OUStringBuffer &rText, const sal_Int32 nStt, const sal_Int32 nEnd, const sal_Unicode cChar)
Hidden text attribute handling.
Definition: porlay.cxx:1491
std::vector< DirectionChangeInfo > m_DirectionChanges
Definition: scriptinfo.hxx:63
TextFrameIndex GetKashida(const size_t nCnt) const
Definition: scriptinfo.hxx:151
bool MarkOrClearKashidaInvalid(TextFrameIndex nStt, TextFrameIndex nLen, bool bMark, sal_Int32 nMarkCount)
Definition: porlay.cxx:1961
void UpdateBidiInfo(const OUString &rText)
Definition: porlay.cxx:1390
long Compress(long *pKernArray, TextFrameIndex nIdx, TextFrameIndex nLen, const sal_uInt16 nCompress, const sal_uInt16 nFontHeight, const bool bCentered, Point *pPoint=nullptr) const
Definition: porlay.cxx:1708
void InitScriptInfo(const SwTextNode &rNode, sw::MergedPara const *pMerged, bool bRTL)
Definition: porlay.cxx:742
Describes parts of multiple text nodes, which will form a text frame, even when redlines are hidden a...
Definition: txtfrm.hxx:952
static bool IsArabicText(const OUString &rText, TextFrameIndex nStt, TextFrameIndex nLen)
Checks if text is Arabic text.
Definition: porlay.cxx:1910
TextFrameIndex NextDirChg(const TextFrameIndex nPos, const sal_uInt8 *pLevel=nullptr) const
Definition: porlay.cxx:1451
static void CalcHiddenRanges(const SwTextNode &rNode, MultiSelection &rHiddenMulti)
Definition: porlay.cxx:2335
static void selectRedLineDeleted(const SwTextNode &rNode, MultiSelection &rHiddenMulti, bool bSelect=true)
Definition: porlay.cxx:2300
size_t CountHiddenChg() const
Definition: scriptinfo.hxx:174
CompType type
Type of compression that we change to.
Definition: scriptinfo.hxx:75
Records a single change in script type.
Definition: scriptinfo.hxx:47
sal_uInt8 m_nDefaultDir
Definition: scriptinfo.hxx:84
bool IsKashidaValid(size_t nKashPos) const
Definition: porlay.cxx:1947
size_t HasKana(TextFrameIndex nStart, TextFrameIndex nEnd) const
Definition: porlay.cxx:1688
CompressionChangeInfo(TextFrameIndex pos, TextFrameIndex len, CompType typ)
Definition: scriptinfo.hxx:76
TextFrameIndex GetCompLen(const size_t nCnt) const
Definition: scriptinfo.hxx:163
std::deque< TextFrameIndex > m_NoKashidaLineEnd
Definition: scriptinfo.hxx:68
CompType DbgCompType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1669
TextFrameIndex GetDirChg(const size_t nCnt) const
Definition: scriptinfo.hxx:135
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void ClearNoKashidaLine(TextFrameIndex nStt, TextFrameIndex nLen)
Clear forced blank justification for a given line.
Definition: porlay.cxx:2044
std::vector< TextFrameIndex > m_HiddenChg
Definition: scriptinfo.hxx:69
sal_Int16 ScriptType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1438
unsigned char sal_uInt8
TextFrameIndex GetHiddenChg(const size_t nCnt) const
Definition: scriptinfo.hxx:175
size_t CountDirChg() const
Definition: scriptinfo.hxx:134
TextFrameIndex m_nInvalidityPos
Definition: scriptinfo.hxx:83
sal_uInt8 GetScriptType(const size_t nCnt) const
Definition: scriptinfo.hxx:128
static TextFrameIndex ThaiJustify(const OUString &rText, long *pKernArray, long *pScrArray, TextFrameIndex nIdx, TextFrameIndex nLen, TextFrameIndex nNumberOfBlanks=TextFrameIndex(0), long nSpaceAdd=0)
Performs a thai justification on the kerning array.
Definition: porlay.cxx:2084
void ClearKashidaInvalid(TextFrameIndex const nStt, TextFrameIndex const nLen)
Clears array of kashidas marked as invalid.
Definition: scriptinfo.hxx:288
std::unordered_set< size_t > m_KashidaInvalid
indexes into m_Kashida
Definition: scriptinfo.hxx:66
bool MarkKashidasInvalid(sal_Int32 const nCnt, TextFrameIndex const nStt, TextFrameIndex const nLen)
Marks nCnt kashida positions as invalid in the given text range.
Definition: scriptinfo.hxx:301
void ClearKashidaInvalid(size_t nKashPos)
Definition: porlay.cxx:1952
SwFontScript
Definition: swfont.hxx:119
static void DeleteHiddenRanges(SwTextNode &rNode)
Hidden text attribute handling.
Definition: porlay.cxx:1527
static bool GetBoundsOfHiddenRange(const SwTextNode &rNode, sal_Int32 nPos, sal_Int32 &rnStartPos, sal_Int32 &rnEndPos, std::vector< sal_Int32 > *pList=nullptr)
Hidden text range information - static and non-version.
Definition: porlay.cxx:1545
size_t CountKashida() const
Definition: scriptinfo.hxx:146
TextFrameIndex GetCompStart(const size_t nCnt) const
Definition: scriptinfo.hxx:158
static bool IsInHiddenRange(const SwTextNode &rNode, sal_Int32 nPos)
Definition: porlay.cxx:1659
TextFrameIndex GetScriptChg(const size_t nCnt) const
Definition: scriptinfo.hxx:123
size_t CountScriptChg() const
Definition: scriptinfo.hxx:122
sal_uInt8 GetDefaultDir() const
Definition: scriptinfo.hxx:119
void GetKashidaPositions(TextFrameIndex nStt, TextFrameIndex nLen, std::vector< TextFrameIndex > &rKashidaPosition)
retrieves kashida opportunities for a given text range.
Definition: porlay.cxx:2003
static TextFrameIndex CountCJKCharacters(const OUString &rText, TextFrameIndex nPos, TextFrameIndex nEnd, LanguageType aLang)
Definition: porlay.cxx:2358
bool MarkKashidaInvalid(size_t nKashPos)
Definition: porlay.cxx:1997
sal_Int32 KashidaJustify(long *pKernArray, long *pScrArray, TextFrameIndex nStt, TextFrameIndex nLen, long nSpaceAdd=0) const
Performs a kashida justification on the kerning array.
Definition: porlay.cxx:1825
TextFrameIndex position
Character position where the change occurs.
Definition: scriptinfo.hxx:73
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
TextFrameIndex position
Character position at which we change script.
Definition: scriptinfo.hxx:49
static void selectHiddenTextProperty(const SwTextNode &rNode, MultiSelection &rHiddenMulti)
Definition: porlay.cxx:2247
ScriptChangeInfo(TextFrameIndex pos, sal_uInt8 typ)
Definition: scriptinfo.hxx:51
std::deque< TextFrameIndex > m_Kashida
Definition: scriptinfo.hxx:64
DirectionChangeInfo(TextFrameIndex pos, sal_uInt8 typ)
Definition: scriptinfo.hxx:61