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 <o3tl/typed_flags_set.hxx>
28 #include <i18nlangtag/lang.h>
29 #include "TextFrameIndex.hxx"
30 
31 class SwTextNode;
32 class SwTextFrame;
33 class Point;
34 class MultiSelection;
35 enum class SwFontScript;
36 namespace sw { struct MergedPara; }
37 namespace sw::mark { class IBookmark; }
38 
39 #define SPACING_PRECISION_FACTOR 100
40 
41 // encapsulates information about script changes
43 {
44 public:
46  enum class MarkKind { Start = (1<<0), End = (1<<1), Point = (1<<2) };
47 
48 private:
51  {
54  ScriptChangeInfo(TextFrameIndex pos, sal_uInt8 typ) : position(pos), type(typ) {};
55  };
56  //TODO - This is sorted, so should probably be a std::set rather than vector.
57  // But we also use random access (probably unnecessarily).
58  std::vector<ScriptChangeInfo> m_ScriptChanges;
61  {
64  DirectionChangeInfo(TextFrameIndex pos, sal_uInt8 typ) : position(pos), type(typ) {};
65  };
66  std::vector<DirectionChangeInfo> m_DirectionChanges;
67  std::deque<TextFrameIndex> m_Kashida;
69  std::unordered_set<size_t> m_KashidaInvalid;
70  std::deque<TextFrameIndex> m_NoKashidaLine;
71  std::deque<TextFrameIndex> m_NoKashidaLineEnd;
72  std::vector<TextFrameIndex> m_HiddenChg;
73  std::vector<std::pair<TextFrameIndex, MarkKind>> m_Bookmarks;
76  {
80  CompressionChangeInfo(TextFrameIndex pos, TextFrameIndex len, CompType typ) : position(pos), length(len), type(typ) {};
81  };
82  std::vector<CompressionChangeInfo> m_CompressionChanges;
83 #ifdef DBG_UTIL
84  CompType DbgCompType(const TextFrameIndex nPos) const;
85 #endif
86 
89 
90  void UpdateBidiInfo( const OUString& rText );
91  bool IsKashidaValid(size_t nKashPos) const;
92  // returns true if nKashPos is newly marked invalid
93  bool MarkKashidaInvalid(size_t nKashPos);
94  void ClearKashidaInvalid(size_t nKashPos);
96  bool bMark, sal_Int32 nMarkCount);
97  bool IsKashidaLine(TextFrameIndex nCharIdx) const;
98  // examines the range [ nStart, nStart + nEnd ] if there are kanas
99  // returns start index of kana entry in array, otherwise SAL_MAX_SIZE
100  size_t HasKana(TextFrameIndex nStart, TextFrameIndex nEnd) const;
101 
102 public:
103 
104  SwScriptInfo();
105  ~SwScriptInfo();
106 
107  // determines script changes
108  void InitScriptInfo(const SwTextNode& rNode, sw::MergedPara const* pMerged, bool bRTL);
109  void InitScriptInfo(const SwTextNode& rNode, sw::MergedPara const* pMerged);
110 
111  // set/get position from which data is invalid
113  {
114  if (nPos < m_nInvalidityPos)
115  m_nInvalidityPos = nPos;
116  }
118  {
119  return m_nInvalidityPos;
120  }
121 
122  // get default direction for paragraph
123  sal_uInt8 GetDefaultDir() const { return m_nDefaultDir; };
124 
125  // array operations, nCnt refers to array position
126  size_t CountScriptChg() const { return m_ScriptChanges.size(); }
127  TextFrameIndex GetScriptChg(const size_t nCnt) const
128  {
129  assert(nCnt < m_ScriptChanges.size());
130  return m_ScriptChanges[nCnt].position;
131  }
132  sal_uInt8 GetScriptType( const size_t nCnt ) const
133  {
134  assert( nCnt < m_ScriptChanges.size());
135  return m_ScriptChanges[nCnt].type;
136  }
137 
138  size_t CountDirChg() const { return m_DirectionChanges.size(); }
139  TextFrameIndex GetDirChg(const size_t nCnt) const
140  {
141  assert(nCnt < m_DirectionChanges.size());
142  return m_DirectionChanges[ nCnt ].position;
143  }
144  sal_uInt8 GetDirType( const size_t nCnt ) const
145  {
146  assert(nCnt < m_DirectionChanges.size());
147  return m_DirectionChanges[ nCnt ].type;
148  }
149 
150  size_t CountKashida() const
151  {
152  return m_Kashida.size();
153  }
154 
155  TextFrameIndex GetKashida(const size_t nCnt) const
156  {
157  assert(nCnt < m_Kashida.size());
158  return m_Kashida[nCnt];
159  }
160 
161  size_t CountCompChg() const { return m_CompressionChanges.size(); };
162  TextFrameIndex GetCompStart(const size_t nCnt) const
163  {
164  assert(nCnt < m_CompressionChanges.size());
165  return m_CompressionChanges[ nCnt ].position;
166  }
167  TextFrameIndex GetCompLen(const size_t nCnt) const
168  {
169  assert(nCnt < m_CompressionChanges.size());
170  return m_CompressionChanges[ nCnt ].length;
171  }
172  CompType GetCompType( const size_t nCnt ) const
173  {
174  assert(nCnt < m_CompressionChanges.size());
175  return m_CompressionChanges[ nCnt ].type;
176  }
177 
178  size_t CountHiddenChg() const { return m_HiddenChg.size(); };
179  TextFrameIndex GetHiddenChg(const size_t nCnt) const
180  {
181  assert(nCnt < m_HiddenChg.size());
182  return m_HiddenChg[ nCnt ];
183  }
186  MarkKind GetBookmark(TextFrameIndex nPos) const;
187  static void CalcHiddenRanges(const SwTextNode& rNode,
188  MultiSelection& rHiddenMulti,
189  std::vector<std::pair<sw::mark::IBookmark const*, MarkKind>> * pBookmarks);
190  static void selectHiddenTextProperty(const SwTextNode& rNode,
191  MultiSelection &rHiddenMulti,
192  std::vector<std::pair<sw::mark::IBookmark const*, MarkKind>> * pBookmarks);
193  static void selectRedLineDeleted(const SwTextNode& rNode, MultiSelection &rHiddenMulti, bool bSelect=true);
194 
195  // "high" level operations, nPos refers to string position
197  sal_Int16 ScriptType(const TextFrameIndex nPos) const;
198 
199  // Returns the position of the next direction level change.
200  // If bLevel is set, the position of the next level which is smaller
201  // than the level at position nPos is returned. This is required to
202  // obtain the end of a SwBidiPortion
204  const sal_uInt8* pLevel = nullptr) const;
205  sal_uInt8 DirType(const TextFrameIndex nPos) const;
206 
207  // HIDDEN TEXT STUFF START
208 
233  static bool GetBoundsOfHiddenRange( const SwTextNode& rNode, sal_Int32 nPos,
234  sal_Int32& rnStartPos, sal_Int32& rnEndPos,
235  std::vector<sal_Int32>* pList = nullptr );
236  bool GetBoundsOfHiddenRange(TextFrameIndex nPos, TextFrameIndex & rnStartPos,
237  TextFrameIndex & rnEndPos) const;
238 
239  static bool IsInHiddenRange( const SwTextNode& rNode, sal_Int32 nPos );
240 
255  static sal_Int32 MaskHiddenRanges(
256  const SwTextNode& rNode, OUStringBuffer& rText,
257  const sal_Int32 nStt, const sal_Int32 nEnd,
258  const sal_Unicode cChar );
259 
267  static void DeleteHiddenRanges( SwTextNode& rNode );
268 
269  // HIDDEN TEXT STUFF END
270 
271  // modifies the kerning array according to a given compress value
272  long Compress( long* pKernArray, TextFrameIndex nIdx, TextFrameIndex nLen,
273  const sal_uInt16 nCompress, const sal_uInt16 nFontHeight,
274  const bool bCentered,
275  Point* pPoint = nullptr ) const;
276 
293  sal_Int32 KashidaJustify( long* pKernArray, long* pScrArray,
294  TextFrameIndex nStt, TextFrameIndex nLen, long nSpaceAdd = 0) const;
295 
298  void ClearKashidaInvalid(TextFrameIndex const nStt, TextFrameIndex const nLen)
299  {
300  MarkOrClearKashidaInvalid(nStt, nLen, false, 0);
301  }
302 
306  void MarkKashidasInvalid(sal_Int32 nCnt, const TextFrameIndex* pKashidaPositions);
307 
311  bool MarkKashidasInvalid(sal_Int32 const nCnt,
312  TextFrameIndex const nStt, TextFrameIndex const nLen)
313  {
314  return MarkOrClearKashidaInvalid(nStt, nLen, true, nCnt);
315  }
316 
323  std::vector<TextFrameIndex>& rKashidaPosition);
324 
330 
336 
346  static bool IsArabicText(const OUString& rText, TextFrameIndex nStt, TextFrameIndex nLen);
347 
366  static TextFrameIndex ThaiJustify( const OUString& rText, long* pKernArray,
367  long* pScrArray, TextFrameIndex nIdx,
368  TextFrameIndex nLen,
369  TextFrameIndex nNumberOfBlanks = TextFrameIndex(0),
370  long nSpaceAdd = 0 );
371 
372  static TextFrameIndex CountCJKCharacters(const OUString &rText,
373  TextFrameIndex nPos, TextFrameIndex nEnd, LanguageType aLang);
374 
375  static void CJKJustify( const OUString& rText, long* pKernArray,
376  long* pScrArray, TextFrameIndex nStt,
377  TextFrameIndex nLen, LanguageType aLang,
378  long nSpaceAdd, bool bIsSpaceStop );
379 
382  static SwScriptInfo* GetScriptInfo( const SwTextNode& rNode,
383  SwTextFrame const** o_pFrame = nullptr,
384  bool bAllowInvalid = false);
385 
387  static SwFontScript WhichFont(sal_Int32 nIdx, OUString const & rText);
388 };
389 
390 namespace o3tl
391 {
392 
393 template<> struct typed_flags<SwScriptInfo::MarkKind> : is_typed_flags<SwScriptInfo::MarkKind, 0x07> {};
394 
395 }
396 
397 #endif
398 
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
SwFontScript WhichFont(TextFrameIndex nIdx) const
Definition: porlay.cxx:721
Records a single change in compression.
Definition: scriptinfo.hxx:75
TextFrameIndex length
Length of the segment.
Definition: scriptinfo.hxx:78
TextFrameIndex GetInvalidityA() const
Definition: scriptinfo.hxx:117
TextFrameIndex NextScriptChg(TextFrameIndex nPos) const
Definition: porlay.cxx:1614
TextFrameIndex position
Character position at which we change direction.
Definition: scriptinfo.hxx:62
sal_uInt8 GetDirType(const size_t nCnt) const
Definition: scriptinfo.hxx:144
sal_uInt8 type
Script type (Latin/Asian/Complex) that we change to.
Definition: scriptinfo.hxx:53
TextFrameIndex NextHiddenChg(TextFrameIndex nPos) const
Definition: porlay.cxx:1667
void SetInvalidityA(const TextFrameIndex nPos)
Definition: scriptinfo.hxx:112
sal_uInt8 type
Direction that we change to.
Definition: scriptinfo.hxx:63
CompType GetCompType(const size_t nCnt) const
Definition: scriptinfo.hxx:172
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:2278
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:2341
std::vector< CompressionChangeInfo > m_CompressionChanges
Definition: scriptinfo.hxx:82
std::deque< TextFrameIndex > m_NoKashidaLine
Definition: scriptinfo.hxx:70
bool IsKashidaLine(TextFrameIndex nCharIdx) const
Definition: porlay.cxx:2252
std::vector< ScriptChangeInfo > m_ScriptChanges
Definition: scriptinfo.hxx:58
Dialog to specify the properties of date form field.
static void CJKJustify(const OUString &rText, long *pKernArray, long *pScrArray, TextFrameIndex nStt, TextFrameIndex nLen, LanguageType aLang, long nSpaceAdd, bool bIsSpaceStop)
Definition: porlay.cxx:2641
sal_uInt8 DirType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1655
Records a single change in direction.
Definition: scriptinfo.hxx:60
size_t CountCompChg() const
Definition: scriptinfo.hxx:161
void SetNoKashidaLine(TextFrameIndex nStt, TextFrameIndex nLen)
Use regular blank justification instead of kashdida justification for the given line of text...
Definition: porlay.cxx:2245
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:1709
static void selectHiddenTextProperty(const SwTextNode &rNode, MultiSelection &rHiddenMulti, std::vector< std::pair< sw::mark::IBookmark const *, MarkKind >> *pBookmarks)
Definition: porlay.cxx:2465
std::vector< DirectionChangeInfo > m_DirectionChanges
Definition: scriptinfo.hxx:66
TextFrameIndex GetKashida(const size_t nCnt) const
Definition: scriptinfo.hxx:155
bool MarkOrClearKashidaInvalid(TextFrameIndex nStt, TextFrameIndex nLen, bool bMark, sal_Int32 nMarkCount)
Definition: porlay.cxx:2179
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void UpdateBidiInfo(const OUString &rText)
Definition: porlay.cxx:1579
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:1926
void InitScriptInfo(const SwTextNode &rNode, sw::MergedPara const *pMerged, bool bRTL)
Definition: porlay.cxx:907
Describes parts of multiple text nodes, which will form a text frame, even when redlines are hidden a...
Definition: txtfrm.hxx:947
MarkKind GetBookmark(TextFrameIndex nPos) const
Definition: porlay.cxx:1691
static bool IsArabicText(const OUString &rText, TextFrameIndex nStt, TextFrameIndex nLen)
Checks if text is Arabic text.
Definition: porlay.cxx:2128
TextFrameIndex NextDirChg(const TextFrameIndex nPos, const sal_uInt8 *pLevel=nullptr) const
Definition: porlay.cxx:1640
static void CalcHiddenRanges(const SwTextNode &rNode, MultiSelection &rHiddenMulti, std::vector< std::pair< sw::mark::IBookmark const *, MarkKind >> *pBookmarks)
Definition: porlay.cxx:2593
static void selectRedLineDeleted(const SwTextNode &rNode, MultiSelection &rHiddenMulti, bool bSelect=true)
Definition: porlay.cxx:2558
size_t CountHiddenChg() const
Definition: scriptinfo.hxx:178
CompType type
Type of compression that we change to.
Definition: scriptinfo.hxx:79
Records a single change in script type.
Definition: scriptinfo.hxx:50
sal_uInt8 m_nDefaultDir
Definition: scriptinfo.hxx:88
bool IsKashidaValid(size_t nKashPos) const
Definition: porlay.cxx:2165
size_t HasKana(TextFrameIndex nStart, TextFrameIndex nEnd) const
Definition: porlay.cxx:1906
CompressionChangeInfo(TextFrameIndex pos, TextFrameIndex len, CompType typ)
Definition: scriptinfo.hxx:80
TextFrameIndex GetCompLen(const size_t nCnt) const
Definition: scriptinfo.hxx:167
std::deque< TextFrameIndex > m_NoKashidaLineEnd
Definition: scriptinfo.hxx:71
CompType DbgCompType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1887
TextFrameIndex GetDirChg(const size_t nCnt) const
Definition: scriptinfo.hxx:139
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
void ClearNoKashidaLine(TextFrameIndex nStt, TextFrameIndex nLen)
Clear forced blank justification for a given line.
Definition: porlay.cxx:2262
std::vector< TextFrameIndex > m_HiddenChg
Definition: scriptinfo.hxx:72
sal_Int16 ScriptType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1627
unsigned char sal_uInt8
TextFrameIndex GetHiddenChg(const size_t nCnt) const
Definition: scriptinfo.hxx:179
size_t CountDirChg() const
Definition: scriptinfo.hxx:138
TextFrameIndex m_nInvalidityPos
Definition: scriptinfo.hxx:87
sal_uInt8 GetScriptType(const size_t nCnt) const
Definition: scriptinfo.hxx:132
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:2302
void ClearKashidaInvalid(TextFrameIndex const nStt, TextFrameIndex const nLen)
Clears array of kashidas marked as invalid.
Definition: scriptinfo.hxx:298
TextFrameIndex NextBookmark(TextFrameIndex nPos) const
Definition: porlay.cxx:1679
std::unordered_set< size_t > m_KashidaInvalid
indexes into m_Kashida
Definition: scriptinfo.hxx:69
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:311
void ClearKashidaInvalid(size_t nKashPos)
Definition: porlay.cxx:2170
std::vector< std::pair< TextFrameIndex, MarkKind > > m_Bookmarks
Definition: scriptinfo.hxx:73
SwFontScript
Definition: swfont.hxx:122
static void DeleteHiddenRanges(SwTextNode &rNode)
Hidden text attribute handling.
Definition: porlay.cxx:1745
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:1763
size_t CountKashida() const
Definition: scriptinfo.hxx:150
TextFrameIndex GetCompStart(const size_t nCnt) const
Definition: scriptinfo.hxx:162
static bool IsInHiddenRange(const SwTextNode &rNode, sal_Int32 nPos)
Definition: porlay.cxx:1877
TextFrameIndex GetScriptChg(const size_t nCnt) const
Definition: scriptinfo.hxx:127
size_t CountScriptChg() const
Definition: scriptinfo.hxx:126
sal_uInt8 GetDefaultDir() const
Definition: scriptinfo.hxx:123
void GetKashidaPositions(TextFrameIndex nStt, TextFrameIndex nLen, std::vector< TextFrameIndex > &rKashidaPosition)
retrieves kashida opportunities for a given text range.
Definition: porlay.cxx:2221
static TextFrameIndex CountCJKCharacters(const OUString &rText, TextFrameIndex nPos, TextFrameIndex nEnd, LanguageType aLang)
Definition: porlay.cxx:2618
bool MarkKashidaInvalid(size_t nKashPos)
Definition: porlay.cxx:2215
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:2043
TextFrameIndex position
Character position where the change occurs.
Definition: scriptinfo.hxx:77
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:52
ScriptChangeInfo(TextFrameIndex pos, sal_uInt8 typ)
Definition: scriptinfo.hxx:54
std::deque< TextFrameIndex > m_Kashida
Definition: scriptinfo.hxx:67
DirectionChangeInfo(TextFrameIndex pos, sal_uInt8 typ)
Definition: scriptinfo.hxx:64