summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-write/qcomplextext.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-write/qcomplextext.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-write/qcomplextext.cpp152
1 files changed, 152 insertions, 0 deletions
diff --git a/noncore/apps/opie-write/qcomplextext.cpp b/noncore/apps/opie-write/qcomplextext.cpp
new file mode 100644
index 0000000..0fa6c2e
--- a/dev/null
+++ b/noncore/apps/opie-write/qcomplextext.cpp
@@ -0,0 +1,152 @@
1/****************************************************************************
2** $Id$
3**
4** Implementation of some internal classes
5**
6** Created :
7**
8** Copyright (C) 2001 Trolltech AS. All rights reserved.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qcomplextext_p.h"
39
40#include "qrichtext_p.h"
41#include "qfontmetrics.h"
42#include "qrect.h"
43
44#include <stdlib.h>
45
46using namespace Qt3;
47
48// -----------------------------------------------------
49
50/* a small helper class used internally to resolve Bidi embedding levels.
51 Each line of text caches the embedding level at the start of the line for faster
52 relayouting
53*/
54QBidiContext::QBidiContext( uchar l, QChar::Direction e, QBidiContext *p, bool o )
55 : level(l) , override(o), dir(e)
56{
57 if ( p )
58 p->ref();
59 parent = p;
60 count = 0;
61}
62
63QBidiContext::~QBidiContext()
64{
65 if( parent && parent->deref() )
66 delete parent;
67}
68
69static QChar *shapeBuffer = 0;
70static int shapeBufSize = 0;
71
72/*
73 Arabic shaping obeys a number of rules according to the joining classes (see Unicode book, section on
74 arabic).
75
76 Each unicode char has a joining class (right, dual (left&right), center (joincausing) or transparent).
77 transparent joining is not encoded in QChar::joining(), but applies to all combining marks and format marks.
78
79 Right join-causing: dual + center
80 Left join-causing: dual + right + center
81
82 Rules are as follows (for a string already in visual order, as we have it here):
83
84 R1 Transparent characters do not affect joining behaviour.
85 R2 A right joining character, that has a right join-causing char on the right will get form XRight
86 (R3 A left joining character, that has a left join-causing char on the left will get form XLeft)
87 Note: the above rule is meaningless, as there are no pure left joining characters defined in Unicode
88 R4 A dual joining character, that has a left join-causing char on the left and a right join-causing char on
89 the right will get form XMedial
90 R5 A dual joining character, that has a right join causing char on the right, and no left join causing char on the left
91 will get form XRight
92 R6 A dual joining character, that has a left join causing char on the left, and no right join causing char on the right
93 will get form XLeft
94 R7 Otherwise the character will get form XIsolated
95
96 Additionally we have to do the minimal ligature support for lam-alef ligatures:
97
98 L1 Transparent characters do not affect ligature behaviour.
99 L2 Any sequence of Alef(XRight) + Lam(XMedial) will form the ligature Alef.Lam(XLeft)
100 L3 Any sequence of Alef(XRight) + Lam(XLeft) will form the ligature Alef.Lam(XIsolated)
101
102 The two functions defined in this class do shaping in visual and logical order. For logical order just replace right with
103 previous and left with next in the above rules ;-)
104*/
105
106/*
107 Two small helper functions for arabic shaping. They get the next shape causing character on either
108 side of the char in question. Implements rule R1.
109
110 leftChar() returns true if the char to the left is a left join-causing char
111 rightChar() returns true if the char to the right is a right join-causing char
112*/
113static inline const QChar *prevChar( const QString &str, int pos )
114{
115 //qDebug("leftChar: pos=%d", pos);
116 pos--;
117 const QChar *ch = str.unicode() + pos;
118 while( pos > -1 ) {
119 if( !ch->isMark() )
120 return ch;
121 pos--;
122 ch--;
123 }
124 return &QChar::replacement;
125}
126
127static inline const QChar *nextChar( const QString &str, int pos)
128{
129 pos++;
130 int len = str.length();
131 const QChar *ch = str.unicode() + pos;
132 while( pos < len ) {
133 //qDebug("rightChar: %d isLetter=%d, joining=%d", pos, ch.isLetter(), ch.joining());
134 if( !ch->isMark() )
135 return ch;
136 // assume it's a transparent char, this might not be 100% correct
137 pos++;
138 ch++;
139 }
140 return &QChar::replacement;
141}
142
143static inline bool prevVisualCharJoins( const QString &str, int pos)
144{
145 return ( prevChar( str, pos )->joining() != QChar::OtherJoining );
146}
147
148static inline bool nextVisualCharJoins( const QString &str, int pos)
149{
150 QChar::Joining join = nextChar( str, pos )->joining();
151 return ( join == QChar::Dual || join == QChar::Center );
152}