author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /inputmethods/handwriting/qimpencombining.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'inputmethods/handwriting/qimpencombining.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/handwriting/qimpencombining.cpp | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/inputmethods/handwriting/qimpencombining.cpp b/inputmethods/handwriting/qimpencombining.cpp new file mode 100644 index 0000000..30459e7 --- a/dev/null +++ b/inputmethods/handwriting/qimpencombining.cpp | |||
@@ -0,0 +1,141 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qfile.h> | ||
22 | #include <qtl.h> | ||
23 | #include <math.h> | ||
24 | #include <limits.h> | ||
25 | #include <qdatastream.h> | ||
26 | #include "qimpencombining.h" | ||
27 | |||
28 | static unsigned int combiningSymbols[] = { '\\', '/', '^', '~', '\"', 'o' }; | ||
29 | static unsigned int combiningChars[][7] = { | ||
30 | // \ / ^ ~ " | ||
31 | { 'A', 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5 }, | ||
32 | { 'O', 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x0000 }, | ||
33 | { 'U', 0x00D9, 0x00DA, 0x00DB, 0x0000, 0x00DC, 0x0000 }, | ||
34 | { 'E', 0x00C8, 0x00C9, 0x00CA, 0x0000, 0x00CB, 0x0000 }, | ||
35 | { 'I', 0x00CC, 0x00CD, 0x00CE, 0x0000, 0x00CF, 0x0000 }, | ||
36 | { 'a', 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5 }, | ||
37 | { 'e', 0x00E8, 0x00E9, 0x00EA, 0x0000, 0x00EB, 0x0000 }, | ||
38 | { 'i', 0x00EC, 0x00ED, 0x00EE, 0x0000, 0x00EF, 0x0000 }, | ||
39 | { 'n', 0x0000, 0x0000, 0x0000, 0x00F1, 0x0000, 0x0000 }, | ||
40 | { 'o', 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x0000 }, | ||
41 | { 'u', 0x00F9, 0x00FA, 0x00FB, 0x0000, 0x00FC, 0x0000 }, | ||
42 | { 'y', 0x0000, 0x00FD, 0x0000, 0x0000, 0x00FF, 0x0000 }, | ||
43 | { 0, 0, 0, 0, 0, 0, 0 } | ||
44 | }; | ||
45 | |||
46 | |||
47 | QIMPenCombining::QIMPenCombining() | ||
48 | { | ||
49 | } | ||
50 | |||
51 | QIMPenCombining::QIMPenCombining( const QString &fn ) | ||
52 | : QIMPenCharSet( fn ) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | void QIMPenCombining::addCombined( QIMPenCharSet *cs ) | ||
57 | { | ||
58 | unsigned int count = cs->count(); | ||
59 | QIMPenCharIterator it( cs->characters() ); | ||
60 | for ( ; it.current() && count; ++it, --count ) { | ||
61 | QIMPenChar *pc = it.current(); | ||
62 | if ( pc->testFlag( QIMPenChar::Deleted ) ) | ||
63 | continue; | ||
64 | int charIdx = findCombining( pc->character() ); | ||
65 | if ( charIdx < 0 ) | ||
66 | continue; | ||
67 | for ( int i = 0; i < 6; i++ ) { | ||
68 | if ( combiningChars[charIdx][i+1] ) { | ||
69 | QIMPenCharIterator cit( chars ); | ||
70 | for ( ; cit.current(); ++cit ) { | ||
71 | QIMPenChar *accentPc = cit.current(); | ||
72 | if ( accentPc->character() == combiningSymbols[i] ) { | ||
73 | QIMPenChar *combined = combine( pc, accentPc ); | ||
74 | combined->setCharacter( combiningChars[charIdx][i+1] ); | ||
75 | cs->addChar( combined ); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | int QIMPenCombining::findCombining( unsigned int ch ) const | ||
84 | { | ||
85 | int i = 0; | ||
86 | while ( combiningChars[i][0] ) { | ||
87 | if ( combiningChars[i][0] == ch ) | ||
88 | return i; | ||
89 | i++; | ||
90 | } | ||
91 | |||
92 | return -1; | ||
93 | } | ||
94 | |||
95 | QIMPenChar *QIMPenCombining::combine( QIMPenChar *base, QIMPenChar *accent ) | ||
96 | { | ||
97 | QRect brect = base->boundingRect(); | ||
98 | QRect arect = accent->boundingRect(); | ||
99 | int offset; | ||
100 | if ( accent->testFlag( QIMPenChar::CombineRight ) ) | ||
101 | offset = brect.left() - arect.left() + brect.width() + 2; | ||
102 | else | ||
103 | offset = brect.left() - arect.left() + (brect.width() - arect.width())/2; | ||
104 | QIMPenChar *combined = 0; | ||
105 | if ( base->character() == 'i' ) { | ||
106 | // Hack to remove the dot from i's when combining. | ||
107 | if ( base->penStrokes().count() > 1 ) { | ||
108 | combined = new QIMPenChar; | ||
109 | QIMPenStrokeIterator it( base->penStrokes() ); | ||
110 | for ( unsigned int i = 0; i < base->penStrokes().count()-1; ++it, i++ ) { | ||
111 | QIMPenStroke *st = new QIMPenStroke( *(it.current()) ); | ||
112 | combined->addStroke( st ); | ||
113 | } | ||
114 | combined->setFlag( QIMPenChar::System ); | ||
115 | } | ||
116 | } | ||
117 | if ( !combined ) | ||
118 | combined = new QIMPenChar( *base ); | ||
119 | QIMPenStrokeIterator it( accent->penStrokes() ); | ||
120 | for ( ; it.current(); ++it ) { | ||
121 | QIMPenStroke *st = new QIMPenStroke( *(it.current()) ); | ||
122 | st->setStartingPoint( st->startingPoint() + QPoint(offset, 0 )); | ||
123 | combined->addStroke( st ); | ||
124 | delete st; | ||
125 | } | ||
126 | |||
127 | return combined; | ||
128 | } | ||
129 | |||
130 | QIMPenChar *QIMPenCombining::penChar( int type ) | ||
131 | { | ||
132 | QIMPenCharIterator it( chars ); | ||
133 | for ( ; it.current(); ++it ) { | ||
134 | QIMPenChar *pc = it.current(); | ||
135 | if ( pc->character() == combiningSymbols[type] ) | ||
136 | return pc; | ||
137 | } | ||
138 | |||
139 | return 0; | ||
140 | } | ||
141 | |||