-rw-r--r-- | inputmethods/handwriting/qimpenchar.cpp | 13 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpenchar.h | 2 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpencombining.cpp | 1 |
3 files changed, 10 insertions, 6 deletions
diff --git a/inputmethods/handwriting/qimpenchar.cpp b/inputmethods/handwriting/qimpenchar.cpp index 152bfec..0c37e5c 100644 --- a/inputmethods/handwriting/qimpenchar.cpp +++ b/inputmethods/handwriting/qimpenchar.cpp @@ -335,79 +335,82 @@ bool QIMPenCharSet::load( const QString &fn, Domain d ) csType = Numeric; else if ( fn == "Combining" ) csType = Combining; } while ( !ds.atEnd() ) { QIMPenChar *pc = new QIMPenChar; ds >> *pc; if ( d == User ) markDeleted( pc->character() ); // override system addChar( pc ); } if ( file.status() == IO_Ok ) ok = TRUE; } return ok; } /*! Save this character set. */ bool QIMPenCharSet::save( Domain d ) { if ( filename( d ).isEmpty() ) return FALSE; bool ok = FALSE; QString fn = filename( d ); QString tmpFn = fn + ".new"; QFile file( tmpFn ); if ( file.open( IO_WriteOnly|IO_Raw ) ) { - QDataStream ds( &file ); + QByteArray buf; + QDataStream ds( buf, IO_WriteOnly ); ds << QString( "QPT 1.1" ); ds << csTitle; ds << desc; ds << (Q_INT8)csType; QIMPenCharIterator ci( chars ); for ( ; ci.current(); ++ci ) { QIMPenChar *pc = ci.current(); - if ( ( (d == System) && pc->testFlag( QIMPenChar::System ) ) || - ( (d == User) && !pc->testFlag( QIMPenChar::System ) ) ) { + if ( ( ( (d == System) && pc->testFlag( QIMPenChar::System ) ) || + ( (d == User) && !pc->testFlag( QIMPenChar::System ) ) ) && + ( !pc->testFlag (QIMPenChar::Combined ) ) ) { ds << *pc; } - if ( file.status() != IO_Ok ) - break; } + + file.writeBlock( buf ); + file.close(); if ( file.status() == IO_Ok ) ok = TRUE; } if ( ok ) { if ( ::rename( tmpFn.latin1(), fn.latin1() ) < 0 ) { qWarning( "problem renaming file %s to %s, errno: %d", tmpFn.latin1(), fn.latin1(), errno ); // remove the tmp file, otherwise, it will just lay around... QFile::remove( tmpFn.latin1() ); ok = FALSE; } } return ok; } QIMPenChar *QIMPenCharSet::at( int i ) { return chars.at(i); } void QIMPenCharSet::markDeleted( uint ch ) { QIMPenCharIterator ci( chars ); for ( ; ci.current(); ++ci ) { QIMPenChar *pc = ci.current(); if ( pc->character() == ch && pc->testFlag( QIMPenChar::System ) ) pc->setFlag( QIMPenChar::Deleted ); } } diff --git a/inputmethods/handwriting/qimpenchar.h b/inputmethods/handwriting/qimpenchar.h index 9a5f687..efd6f16 100644 --- a/inputmethods/handwriting/qimpenchar.h +++ b/inputmethods/handwriting/qimpenchar.h @@ -31,65 +31,65 @@ struct QIMPenSpecialKeys { char *name; }; extern const QIMPenSpecialKeys qimpen_specialKeys[]; class QIMPenChar { public: QIMPenChar(); QIMPenChar( const QIMPenChar & ); unsigned int character() const { return ch; } void setCharacter( unsigned int c ) { ch = c; } const QString &data() const { return d; } void setData( const QString &ba ) { d = ba; } QString name() const; bool isEmpty() const { return strokes.isEmpty(); } unsigned int strokeCount() const { return strokes.count(); } unsigned int strokeLength( int s ) const; void clear(); int match( QIMPenChar *ch ); const QIMPenStrokeList &penStrokes() { return strokes; } QPoint startingPoint() const { return strokes.getFirst()->startingPoint(); } QRect boundingRect(); void setFlag( int f ) { flags |= f; } void clearFlag( int f ) { flags &= ~f; } bool testFlag( int f ) { return flags & f; } - enum Flags { System=0x01, Deleted=0x02, CombineRight=0x04, Data=0x08 }; + enum Flags { System=0x01, Deleted=0x02, CombineRight=0x04, Data=0x08, Combined=0x10 }; // Correspond to codes in template files. Do not change values. enum Mode { ModeBase=0x4000, Caps=0x4001, Shortcut=0x4002, CapsLock=0x4003, Punctuation=0x4004, Symbol=0x4005, Extended=0x4006 }; QIMPenChar &operator=( const QIMPenChar &s ); void addStroke( QIMPenStroke * ); protected: unsigned int ch; QString d; Q_UINT8 flags; QIMPenStrokeList strokes; friend QDataStream &operator<< (QDataStream &, const QIMPenChar &); friend QDataStream &operator>> (QDataStream &, QIMPenChar &); }; typedef QList<QIMPenChar> QIMPenCharList; typedef QListIterator<QIMPenChar> QIMPenCharIterator; QDataStream & operator<< (QDataStream & s, const QIMPenChar &ws); QDataStream & operator>> (QDataStream & s, QIMPenChar &ws); struct QIMPenCharMatch { int error; QIMPenChar *penChar; bool operator>( const QIMPenCharMatch &m ); bool operator<( const QIMPenCharMatch &m ); bool operator<=( const QIMPenCharMatch &m ); diff --git a/inputmethods/handwriting/qimpencombining.cpp b/inputmethods/handwriting/qimpencombining.cpp index 30459e7..2e01ac2 100644 --- a/inputmethods/handwriting/qimpencombining.cpp +++ b/inputmethods/handwriting/qimpencombining.cpp @@ -43,64 +43,65 @@ static unsigned int combiningChars[][7] = { { 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. |