1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scriptinfo.hxx,v $
10 * $Revision: 1.21.112.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SCRIPTINFO_HXX
31 #define _SCRIPTINFO_HXX
33 #define _SVSTDARR_SHORTS
34 #define _SVSTDARR_BYTES
35 #define _SVSTDARR_USHORTS
36 #define _SVSTDARR_XUB_STRLEN
37 #include <svtools/svstdarr.hxx>
39 #include <i18npool/lang.h>
41 #include <modeltoviewhelper.hxx>
49 typedef std::list
< xub_StrLen
> PositionList
;
51 #define SPACING_PRECISION_FACTOR 100
53 /*************************************************************************
55 * Hilfsklasse, die beim Spellen die Worte im gewuenschten Bereich
56 * nacheinander zur Verfuegung stellt.
57 *************************************************************************/
62 const SwTxtNode
& rNode
;
64 const LanguageType
* pLanguage
;
65 const ModelToViewHelper::ConversionMap
* pConversionMap
;
70 LanguageType aCurrLang
;
75 SwScanner( const SwTxtNode
& rNd
, const String
& rTxt
, const LanguageType
* pLang
,
76 const ModelToViewHelper::ConversionMap
* pConvMap
,
78 xub_StrLen nStart
, xub_StrLen nEnde
, BOOL bClip
= FALSE
);
81 // This next word function tries to find the language for the next word
82 // It should currently _not_ be used for spell checking, and works only for
86 const XubString
& GetWord() const { return aWord
; }
88 xub_StrLen
GetBegin() const { return nBegin
; }
89 xub_StrLen
GetEnd() const { return nBegin
+ nLen
; }
90 xub_StrLen
GetLen() const { return nLen
; }
92 LanguageType
GetCurrentLanguage() const {return aCurrLang
;}
95 /*************************************************************************
98 * encapsultes information about script changes
99 *************************************************************************/
104 SvXub_StrLens aScriptChg
;
106 SvXub_StrLens aDirChg
;
108 SvXub_StrLens aKashida
;
109 SvXub_StrLens aKashidaInvalid
;
110 SvXub_StrLens aNoKashidaLine
;
111 SvXub_StrLens aNoKashidaLineEnd
;
112 SvXub_StrLens aCompChg
;
113 SvXub_StrLens aCompLen
;
114 SvXub_StrLens aHiddenChg
;
116 xub_StrLen nInvalidityPos
;
119 void UpdateBidiInfo( const String
& rTxt
);
121 sal_Bool
IsKashidaValid ( xub_StrLen nKashPos
) const;
122 void MarkKashidaInvalid ( xub_StrLen nKashPos
);
123 void ClearKashidaInvalid ( xub_StrLen nKashPos
);
124 bool MarkOrClearKashidaInvalid( xub_StrLen nStt
, xub_StrLen nLen
, bool bMark
, xub_StrLen nMarkCount
);
125 bool IsKashidaLine ( xub_StrLen nCharIdx
) const;
128 enum CompType
{ KANA
, SPECIAL_LEFT
, SPECIAL_RIGHT
, NONE
};
133 // determines script changes
134 void InitScriptInfo( const SwTxtNode
& rNode
, sal_Bool bRTL
);
135 void InitScriptInfo( const SwTxtNode
& rNode
);
137 // set/get position from which data is invalid
138 inline void SetInvalidity( const xub_StrLen nPos
);
139 inline xub_StrLen
GetInvalidity() const { return nInvalidityPos
; };
141 // get default direction for paragraph
142 inline BYTE
GetDefaultDir() const { return nDefaultDir
; };
144 // array operations, nCnt refers to array position
145 inline USHORT
CountScriptChg() const;
146 inline xub_StrLen
GetScriptChg( const USHORT nCnt
) const;
147 inline BYTE
GetScriptType( const USHORT nCnt
) const;
149 inline USHORT
CountDirChg() const;
150 inline xub_StrLen
GetDirChg( const USHORT nCnt
) const;
151 inline BYTE
GetDirType( const USHORT nCnt
) const;
153 inline USHORT
CountKashida() const;
154 inline xub_StrLen
GetKashida( const USHORT nCnt
) const;
156 inline USHORT
CountCompChg() const;
157 inline xub_StrLen
GetCompStart( const USHORT nCnt
) const;
158 inline xub_StrLen
GetCompLen( const USHORT nCnt
) const;
159 inline BYTE
GetCompType( const USHORT nCnt
) const;
161 inline USHORT
CountHiddenChg() const;
162 inline xub_StrLen
GetHiddenChg( const USHORT nCnt
) const;
163 static void CalcHiddenRanges( const SwTxtNode
& rNode
,
164 MultiSelection
& rHiddenMulti
);
166 // "high" level operations, nPos refers to string position
167 xub_StrLen
NextScriptChg( const xub_StrLen nPos
) const;
168 BYTE
ScriptType( const xub_StrLen nPos
) const;
170 // Returns the position of the next direction level change.
171 // If bLevel is set, the position of the next level which is smaller
172 // than the level at position nPos is returned. This is required to
173 // obtain the end of a SwBidiPortion
174 xub_StrLen
NextDirChg( const xub_StrLen nPos
,
175 const BYTE
* pLevel
= 0 ) const;
176 BYTE
DirType( const xub_StrLen nPos
) const;
178 #if OSL_DEBUG_LEVEL > 1
179 BYTE
CompType( const xub_StrLen nPos
) const;
183 // HIDDEN TEXT STUFF START
186 /** Hidden text range information - static and non-version
188 @descr Determines if a given position is inside a hidden text range. The
189 static version tries to obtain a valid SwScriptInfo object
190 via the SwTxtNode, otherwise it calculates the values from scratch.
191 The non-static version uses the internally cached informatio
197 The given position that should be checked.
199 Return parameter for the start position of the hidden range.
200 STRING_LEN if nPos is not inside a hidden range.
202 Return parameter for the end position of the hidden range.
203 0 if nPos is not inside a hidden range.
205 Return parameter that contains all the hidden text ranges. Optional.
207 returns true if there are any hidden characters in this paragraph.
210 static bool GetBoundsOfHiddenRange( const SwTxtNode
& rNode
, xub_StrLen nPos
,
211 xub_StrLen
& rnStartPos
, xub_StrLen
& rnEndPos
,
212 PositionList
* pList
= 0 );
213 bool GetBoundsOfHiddenRange( xub_StrLen nPos
, xub_StrLen
& rnStartPos
,
214 xub_StrLen
& rnEndPos
, PositionList
* pList
= 0 ) const;
216 static bool IsInHiddenRange( const SwTxtNode
& rNode
, xub_StrLen nPos
);
218 /** Hidden text attribute handling
220 @descr Takes a string and either deletes the hidden ranges or sets
221 a given character in place of the hidden characters.
226 The string to modify.
228 The character that should replace the hidden characters.
230 If set, the hidden ranges will be deleted from the text node.
232 static USHORT
MaskHiddenRanges( const SwTxtNode
& rNode
, XubString
& rText
,
233 const xub_StrLen nStt
, const xub_StrLen nEnd
,
234 const xub_Unicode cChar
);
236 /** Hidden text attribute handling
238 @descr Takes a SwTxtNode and deletes the hidden ranges from the node.
243 static void DeleteHiddenRanges( SwTxtNode
& rNode
);
246 // HIDDEN TEXT STUFF END
249 // examines the range [ nStart, nStart + nEnd ] if there are kanas
250 // returns start index of kana entry in array, otherwise USHRT_MAX
251 USHORT
HasKana( xub_StrLen nStart
, const xub_StrLen nEnd
) const;
253 // modifies the kerning array according to a given compress value
254 long Compress( sal_Int32
* pKernArray
, xub_StrLen nIdx
, xub_StrLen nLen
,
255 const USHORT nCompress
, const USHORT nFontHeight
,
256 Point
* pPoint
= NULL
) const;
258 /** Performes a kashida justification on the kerning array
260 @descr Add some extra space for kashida justification to the
261 positions in the kerning array.
263 The printers kerning array. Optional.
265 The screen kerning array. Optional.
267 Start referring to the paragraph.
269 The number of characters to be considered.
271 The value which has to be added to a kashida opportunity.
272 @return The number of kashida opportunities in the given range
274 USHORT
KashidaJustify( sal_Int32
* pKernArray
, sal_Int32
* pScrArray
,
275 xub_StrLen nStt
, xub_StrLen nLen
,
276 long nSpaceAdd
= 0) const;
278 /** Clears array of kashidas marked as invalid
280 inline void ClearKashidaInvalid ( xub_StrLen nStt
, xub_StrLen nLen
) { MarkOrClearKashidaInvalid( nStt
, nLen
, false, 0 ); }
282 /** Marks nCnt kashida positions as invalid
283 pKashidaPositions: array of char indices relative to the paragraph
285 bool MarkKashidasInvalid ( xub_StrLen nCnt
, xub_StrLen
* pKashidaPositions
);
287 /** Marks nCnt kashida positions as invalid
288 in the given text range
290 inline bool MarkKashidasInvalid ( xub_StrLen nCnt
, xub_StrLen nStt
, xub_StrLen nLen
)
291 { return MarkOrClearKashidaInvalid( nStt
, nLen
, true, nCnt
); }
293 /** retrieves kashida opportunities for a given text range.
294 returns the number of kashida positions in the given text range
296 pKashidaPositions: buffer to reveive the char indices of the
297 kashida opportunties relative to the paragraph
299 USHORT
GetKashidaPositions ( xub_StrLen nStt
, xub_StrLen nLen
,
300 xub_StrLen
* pKashidaPosition
);
305 /** Use regular blank justification instead of kashdida justification for the given line of text.
306 nStt Start char index of the line referring to the paragraph.
307 nLen Number of characters in the line
309 void SetNoKashidaLine ( xub_StrLen nStt
, xub_StrLen nLen
);
311 /** Clear forced blank justification for a given line.
312 nStt Start char index of the line referring to the paragraph.
313 nLen Number of characters in the line
315 void ClearNoKashidaLine ( xub_StrLen nStt
, xub_StrLen nLen
);
317 /** Checks if text is Arabic text.
319 @descr Checks if text is Arabic text.
323 Start index of the text
324 @return Returns if the language is an Arabic language
326 static sal_Bool
IsArabicText( const XubString
& rTxt
, xub_StrLen nStt
, xub_StrLen nLen
);
328 /** Performes a thai justification on the kerning array
330 @descr Add some extra space for thai justification to the
331 positions in the kerning array.
335 The printers kerning array. Optional.
337 The screen kerning array. Optional.
339 Start referring to the paragraph.
341 The number of characters to be considered.
343 The value which has to be added to the cells.
344 @return The number of extra spaces in the given range
346 static USHORT
ThaiJustify( const XubString
& rTxt
, sal_Int32
* pKernArray
,
347 sal_Int32
* pScrArray
, xub_StrLen nIdx
,
348 xub_StrLen nLen
, xub_StrLen nNumberOfBlanks
= 0,
349 long nSpaceAdd
= 0 );
351 static SwScriptInfo
* GetScriptInfo( const SwTxtNode
& rNode
,
352 sal_Bool bAllowInvalid
= sal_False
);
354 static BYTE
WhichFont( xub_StrLen nIdx
, const String
* pTxt
, const SwScriptInfo
* pSI
);
357 inline void SwScriptInfo::SetInvalidity( const xub_StrLen nPos
)
359 if ( nPos
< nInvalidityPos
)
360 nInvalidityPos
= nPos
;
362 inline USHORT
SwScriptInfo::CountScriptChg() const { return aScriptChg
.Count(); }
363 inline xub_StrLen
SwScriptInfo::GetScriptChg( const USHORT nCnt
) const
365 ASSERT( nCnt
< aScriptChg
.Count(),"No ScriptChange today!");
366 return aScriptChg
[ nCnt
];
368 inline BYTE
SwScriptInfo::GetScriptType( const xub_StrLen nCnt
) const
370 ASSERT( nCnt
< aScriptChg
.Count(),"No ScriptType today!");
371 return aScriptType
[ nCnt
];
374 inline USHORT
SwScriptInfo::CountDirChg() const { return aDirChg
.Count(); }
375 inline xub_StrLen
SwScriptInfo::GetDirChg( const USHORT nCnt
) const
377 ASSERT( nCnt
< aDirChg
.Count(),"No DirChange today!");
378 return aDirChg
[ nCnt
];
380 inline BYTE
SwScriptInfo::GetDirType( const xub_StrLen nCnt
) const
382 ASSERT( nCnt
< aDirChg
.Count(),"No DirType today!");
383 return aDirType
[ nCnt
];
386 inline USHORT
SwScriptInfo::CountKashida() const { return aKashida
.Count(); }
387 inline xub_StrLen
SwScriptInfo::GetKashida( const USHORT nCnt
) const
389 ASSERT( nCnt
< aKashida
.Count(),"No Kashidas today!");
390 return aKashida
[ nCnt
];
393 inline USHORT
SwScriptInfo::CountCompChg() const { return aCompChg
.Count(); };
394 inline xub_StrLen
SwScriptInfo::GetCompStart( const USHORT nCnt
) const
396 ASSERT( nCnt
< aCompChg
.Count(),"No CompressionStart today!");
397 return aCompChg
[ nCnt
];
399 inline xub_StrLen
SwScriptInfo::GetCompLen( const USHORT nCnt
) const
401 ASSERT( nCnt
< aCompChg
.Count(),"No CompressionLen today!");
402 return aCompLen
[ nCnt
];
405 inline BYTE
SwScriptInfo::GetCompType( const USHORT nCnt
) const
407 ASSERT( nCnt
< aCompChg
.Count(),"No CompressionType today!");
408 return aCompType
[ nCnt
];
411 inline USHORT
SwScriptInfo::CountHiddenChg() const { return aHiddenChg
.Count(); };
412 inline xub_StrLen
SwScriptInfo::GetHiddenChg( const USHORT nCnt
) const
414 ASSERT( nCnt
< aHiddenChg
.Count(),"No HiddenChg today!");
415 return aHiddenChg
[ nCnt
];