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