Ejemplo n.º 1
0
QByteArray QEucJpCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
{
    char replacement = '?';
    if (state) {
        if (state->flags & ConvertInvalidToNull)
            replacement = 0;
    }
    int invalid = 0;

    int rlen = 3*len + 1;
    QByteArray rstr;
    rstr.resize(rlen);
    uchar* cursor = (uchar*)rstr.data();
    for (int i = 0; i < len; i++) {
        QChar ch = uc[i];
        uint j;
        if (ch.unicode() < 0x80) {
            // ASCII
            *cursor++ = ch.cell();
        } else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) {
            if (j < 0x80) {
                // JIS X 0201 Latin ?
                *cursor++ = j;
            } else {
                // JIS X 0201 Kana
                *cursor++ = Ss2;
                *cursor++ = j;
            }
        } else if ((j = conv->unicodeToJisx0208(ch.row(), ch.cell())) != 0) {
            // JIS X 0208
            *cursor++ = (j >> 8)   | 0x80;
            *cursor++ = (j & 0xff) | 0x80;
        } else if ((j = conv->unicodeToJisx0212(ch.row(), ch.cell())) != 0) {
Ejemplo n.º 2
0
/*! \reimp */
QCString QTsciiCodec::fromUnicode(const QString& uc, int& lenInOut) const
{
    int l = QMIN((int)uc.length(), lenInOut);
    int rlen = l+1;
    QCString rstr(rlen);
    uchar* cursor = (uchar*)rstr.data();
    for (int i = 0; i < l; i++) {
	QChar ch = uc[i];
	uchar j;
	if ( ch.row() == 0x00 && ch.cell() < 0x80 ) {
	    // ASCII
	    j = ch.cell();
	} else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
					  uc[i + 1].unicode(),
					  uc[i + 2].unicode()))) {
	    // We have to check the combined chars first!
	    i += 2;
	} else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
					  uc[i + 1].unicode(), 0))) {
	    i++;
	} else if ((j = qt_UnicodeToTSCII(uc[i].unicode(), 0, 0))) {
	} else {
	    // Error
	    j = '?';	// unknown char
	}
	*cursor++ = j;
    }
    lenInOut = cursor - (uchar*)rstr.data();
    *cursor = 0;
    return rstr;
}
Ejemplo n.º 3
0
/*
	charPos is positive position
*/
int Wt_TextEdit::wt_findPairChar(int charPos, QChar pairChar, bool findBefore) {
	QTextCursor textCursor = this->textCursor();
	textCursor.setPosition(charPos, QTextCursor::KeepAnchor);
	int charBlockPos = textCursor.positionInBlock();
	QString line = textCursor.block().text();
	QChar curChar = line[charBlockPos];
	printf("wt_findPairChar char:%c | toChar:%c \n" , curChar.cell(), pairChar.cell());
	int pair = 0;
	//int findBlockPos = -1;
	int findPositivePos = -1;
	int curPos = -1;
	QString curString = "";
	QTextCursor::MoveOperation direction = findBefore == true ? QTextCursor::PreviousCharacter : QTextCursor::NextCharacter;
	for (int i = 0 ; textCursor.movePosition(direction, QTextCursor::KeepAnchor) ; i++) {
		curPos = textCursor.positionInBlock();
		curString = textCursor.block().text();
		if(curString[curPos] == curChar) {
			pair += 1;
		}
		if(curString[curPos] == pairChar) {
			pair -= 1;
		}
		if(pair < 0) {
			//findBlockPos = curPos;
			findPositivePos =  textCursor.position();
			return findPositivePos;
		}
	}
	return -1;
}
Ejemplo n.º 4
0
/*!
  \reimp
*/
QCString QEucJpCodec::fromUnicode(const QString& uc, int& lenInOut) const
{
    int l = QMIN((int)uc.length(),lenInOut);
    int rlen = l*3+1;
    QCString rstr(rlen);
    uchar* cursor = (uchar*)rstr.data();
    for (int i=0; i<l; i++) {
	QChar ch = uc[i];
	uint j;
	if ( ch.row() == 0x00 && ch.cell() < 0x80 ) {
	    // ASCII
	    *cursor++ = ch.cell();
	} else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) {
	    if (j < 0x80) {
		// JIS X 0201 Latin ?
		*cursor++ = j;
	    } else {
		// JIS X 0201 Kana
		*cursor++ = Ss2;
		*cursor++ = j;
	    }
	} else if ((j = conv->unicodeToJisx0208(ch.row(), ch.cell())) != 0) {
	    // JIS X 0208
	    *cursor++ = (j >> 8)   | 0x80;
	    *cursor++ = (j & 0xff) | 0x80;
	} else if ((j = conv->unicodeToJisx0212(ch.row(), ch.cell())) != 0) {
Ejemplo n.º 5
0
QByteArray QSjisCodec::convertFromUnicode(const ushort* uc, int len, ConverterState *state)
{
    char replacement = '?';
    if (state) {
        if (state->flags & ConvertInvalidToNull)
            replacement = 0;
    }
    int invalid = 0;

    int rlen = 2*len + 1;
    QByteArray rstr;
    rstr.resize(rlen);
    uchar* cursor = (uchar*)rstr.data();
    for (int i = 0; i < len; i++) {
        QChar ch = uc[i];
        uint j;
        if (ch.row() == 0x00 && ch.cell() < 0x80) {
            // ASCII
            *cursor++ = ch.cell();
        } else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) {
            // JIS X 0201 Latin or JIS X 0201 Kana
            *cursor++ = j;
        } else if ((j = conv->unicodeToSjis(ch.row(), ch.cell())) != 0) {
            // JIS X 0208
            *cursor++ = (j >> 8);
            *cursor++ = (j & 0xff);
        } else if ((j = conv->unicodeToSjisibmvdc(ch.row(), ch.cell())) != 0) {
Ejemplo n.º 6
0
/*! \internal */
QCString QJisCodec::fromUnicode(const QString& uc, int& len_in_out) const
{
    int l = QMIN((int)uc.length(),len_in_out);
    QCString result;
    Iso2022State state = Ascii;
    Iso2022State prev = Ascii;
    for (int i=0; i<l; i++) {
	QChar ch = uc[i];
	uint j;
	if ( ch.row() == 0x00 && ch.cell() < 0x80 ) {
	    // Ascii
	    if (state != JISX0201_Latin ||
		ch.cell() == ReverseSolidus || ch.cell() == Tilde) {
		state = Ascii;
	    }
	    j = ch.cell();
	} else if ((j = conv->UnicodeToJisx0201(ch.row(), ch.cell())) != 0) {
	    if (j < 0x80) {
		// JIS X 0201 Latin
		if (state != Ascii ||
		    ch.cell() == YenSign || ch.cell() == Overline) {
		    state = JISX0201_Latin;
		}
	    } else {
		// JIS X 0201 Kana
		state = JISX0201_Kana;
		j &= 0x7f;
	    }
	} else if ((j = conv->UnicodeToJisx0208(ch.row(), ch.cell())) != 0) {
	    // JIS X 0208
	    state = JISX0208_1983;
	} else if ((j = conv->UnicodeToJisx0212(ch.row(), ch.cell())) != 0) {
	    // JIS X 0212
	    state = JISX0212;
	} else {
	    // Invalid
	    state = Unknown;
	    j = '?';
	}
	if (state != prev) {
	    if (state == Unknown) {
		result += Esc_Ascii;
	    } else {
		result += Esc_SEQ[state - MinState];
	    }
	    prev = state;
	}
	if (j < 0x0100) {
	    result += j & 0xff;
	} else {
	    result += (j >> 8) & 0xff;
	    result += j & 0xff;
	}
    }
    if (prev != Ascii) {
	result += Esc_Ascii;
    }
    len_in_out = result.length();
    return result;
}
Ejemplo n.º 7
0
static int hex2int( QChar hexchar )
{
    int v;
    if ( hexchar.isDigit() )
	v = hexchar.digitValue();
    else if ( hexchar >= 'A' && hexchar <= 'F' )
	v = hexchar.cell() - 'A' + 10;
    else if ( hexchar >= 'a' && hexchar <= 'f' )
	v = hexchar.cell() - 'a' + 10;
    else
	v = -1;
    return v;
}
Ejemplo n.º 8
0
static bool matchcharclass( uint *rxd, QChar c )
{
    uint *d = rxd;
    uint clcode = *d & MCD;
    bool neg = clcode == CCN;
    if ( clcode != CCL && clcode != CCN)
	qWarning("QRegExp: Internal error, please report to [email protected]");
    uint numFields = *d & MVL;
    uint cval = (((uint)(c.row())) << 8) | ((uint)c.cell());
    bool found = FALSE;
    for ( int i = 0; i < (int)numFields; i++ ) {
	d++;
	if ( *d == PWS && c.isSpace() ) {
	    found = TRUE;
	    break;
	}
	if ( *d == PDG && c.isDigit() ) {
	    found = TRUE;
	    break;
	}
	else {
	    uint from = ( *d & MCD ) >> 16;
	    uint to = *d & MVL;
	    if ( (cval >= from) && (cval <= to) ) {
		found = TRUE;
		break;
	    }
	}
    }
    return neg ? !found : found;
}
Ejemplo n.º 9
0
/*
	indent when there has nothing before the char in the block
	charPos is positive position
*/
void Wt_TextEdit::wt_indentChar(int charPos, int toCharPos)
{
	printf("wt_indentChar \n");
	QTextCursor textCursor = this->textCursor();
	textCursor.setPosition(toCharPos, QTextCursor::MoveAnchor);
	QString toLine = textCursor.block().text();

	textCursor.setPosition(charPos, QTextCursor::MoveAnchor);
	int charBlockPos = textCursor.positionInBlock();
	QString line = textCursor.block().text();

	QChar mchar = line[charBlockPos];
	// printf("mchar :	%c | line : %s | charBlockPos: %d\n", mchar.cell(), line.toStdString().c_str(), charBlockPos);
	if(line.trimmed()[0] != mchar) {
		printf("mchar return : %c\n", mchar.cell());
		return;
	}

	/*
		textCursor.setPosition(charPos, QTextCursor::KeepAnchor);
		pos between Anchor will be selected , delete will clear all selection
	*/
	for(int i = 0; i < charBlockPos ; i++) {
		printf("deleteChar\n");
		textCursor.deletePreviousChar();
	}

	for(int i = 0 ; i < toLine.length() ; i++) {
		if(toLine[i] == ' ' || toLine[i] == '\t') {
			textCursor.insertText(QString(toLine[i]));
		} else {
			break;
		}
	}
}
Ejemplo n.º 10
0
static bool to8bit(const QChar ch, QCString *rstr)
{
    bool converted = FALSE;

    if( ch.isMark() ) return TRUE; // ignore marks for conversion

    if ( ch.row() ) {
	if ( ch.row() == 0x05 ) {
	    if ( ch.cell() > 0x91 )
		converted = TRUE;
	    // 0x0591 - 0x05cf: Hebrew punctuation... dropped
	    if ( ch.cell() >= 0xD0 )
		*rstr += (char)unicode_to_heb_05[ch.cell()- 0xD0];
	} else if ( ch.row() == 0x20 ) {
	    if ( ch.cell() == 0x3E ) {
		*rstr += (char)0xAF;
		converted = TRUE;
	    } else if ( ch.cell() == 0x17 ) {
		*rstr += (char)0xCF;
		converted = TRUE;
	    }
	} else {
	    converted = FALSE;
	}
    } else {
	if ( ch.cell() < 0x80 ) {
	    *rstr += (char)ch.cell();
	    converted = TRUE;
	} else if( ch.cell() < 0xA0 ) {
	    *rstr += (char)unicode_to_heb_00[ch.cell() - 0x80];
	    converted = TRUE;
	}
    }

    if(converted) return TRUE;

    // couldn't convert the char... lets try its decomposition
    QString d = ch.decomposition();
    if(d.isNull())
	return FALSE;

    int l = d.length();
    for (int i=0; i<l; i++) {
	const QChar ch = d[i];

	if(to8bit(ch, rstr))
	    converted = TRUE;
    }

    return converted;
}
Ejemplo n.º 11
0
/*!
  \reimp
*/
QCString QSjisCodec::fromUnicode(const QString& uc, int& len_in_out) const
{
    int l = QMIN((int)uc.length(),len_in_out);
    int rlen = l*2+1;
    QCString rstr(rlen);
    uchar* cursor = (uchar*)rstr.data();
    for (int i=0; i<l; i++) {
	QChar ch = uc[i];
	uint j;
	if ( ch.row() == 0x00 && ch.cell() < 0x80 ) {
	    // ASCII
	    *cursor++ = ch.cell();
	} else if ((j = conv->UnicodeToJisx0201(ch.row(), ch.cell())) != 0) {
	    // JIS X 0201 Latin or JIS X 0201 Kana
	    *cursor++ = j;
	} else if ((j = conv->UnicodeToSjis(ch.row(), ch.cell())) != 0) {
	    // JIS X 0208
	    *cursor++ = (j >> 8);
	    *cursor++ = (j & 0xff);
	} else if ((j = conv->UnicodeToJisx0212(ch.row(), ch.cell())) != 0) {
Ejemplo n.º 12
0
/*!
    Converts the first \a len characters in \a uc from Unicode to this
    encoding, and returns the result in a byte array. The \a state contains
    some conversion flags, and is used by the codec to maintain state
    information.
*/
QByteArray QTsciiCodec::convertFromUnicode(const ushort *uc, int len, ConverterState *state)
{
    char replacement = '?';
    if (state) {
        if (state->flags & ConvertInvalidToNull)
            replacement = 0;
    }
    int invalid = 0;

    QByteArray rstr;
    rstr.resize(len);
    uchar* cursor = (uchar*)rstr.data();
    for (int i = 0; i < len; i++) {
        QChar ch = uc[i];
        uchar j;
        if (ch.row() == 0x00 && ch.cell() < 0x80) {
            // ASCII
            j = ch.cell();
        } else if ((j = qt_UnicodeToTSCII(uc[i],
                                          uc[i + 1],
                                          uc[i + 2]))) {
            // We have to check the combined chars first!
            i += 2;
        } else if ((j = qt_UnicodeToTSCII(uc[i],
                                          uc[i + 1], 0))) {
            i++;
        } else if ((j = qt_UnicodeToTSCII(uc[i], 0, 0))) {
        } else {
            // Error
            j = replacement;
            ++invalid;
        }
        *cursor++ = j;
    }
    rstr.resize(cursor - (const uchar*)rstr.constData());

    if (state) {
        state->invalidChars += invalid;
    }
    return rstr;
}
Ejemplo n.º 13
0
	void encodeFileName(QString & szPath)
	{
		QString szSrc(szPath);
		szPath = "";
		for(int i = 0; i < szSrc.length(); i++)
		{
			QChar cur = szSrc[i];
			if( ! (cur.isLetter() || cur.isDigit() || cur==' ' || cur=='_' || cur=='.' || cur=='#' || cur=='%') )
			{
				if(cur.row()!=0)
				{
					szPath += '%';
					szPath += cHexChars[cur.row() >> 4];
					szPath += cHexChars[cur.row() & 15];
				}
				szPath += '%';
				szPath += cHexChars[cur.cell() >> 4];
				szPath += cHexChars[cur.cell() & 15];
			} else if (cur=='%')
Ejemplo n.º 14
0
static uint *dump( uint *p )
{
    while ( *p != END ) {
	if ( *p & CHR ) {
	    QChar uc = (QChar)*p;
	    char c = (char)uc;
	    uint u = (((uint)(uc.row())) << 8) | ((uint)uc.cell());
	    qDebug( "\tCHR\tU%04x (%c)", u, (c ? c : ' '));
	    p++;
	}
	else if ( *p & MCC ) {
	    uint clcode = *p & MCD;
	    uint numFields = *p & MVL;
	    if ( clcode == CCL )
		qDebug( "\tCCL\t%i", numFields );
	    else if ( clcode == CCN )
		qDebug( "\tCCN\t%i", numFields );
	    else
		qDebug("coding error!");
	    for ( int i = 0; i < (int)numFields; i++ ) {
		p++;
		if ( *p == PWS )
		    qDebug( "\t\tPWS" );
		else if ( *p == PDG )
		    qDebug( "\t\tPDG" );
		else {
		    uint from = ( *p & MCD ) >> 16;
		    uint to = *p & MVL;
		    char fc = (char)QChar(from);
		    char tc = (char)QChar(to);
		    qDebug( "\t\tU%04x (%c) - U%04x (%c)", from,
			   (fc ? fc : ' '), to, (tc ? tc : ' ') );
		}
	    }
	    p++;
	}
	else switch ( *p++ ) {
Ejemplo n.º 15
0
QPixmap PixmapCache::character(const QChar &character)
{
    auto p = pixmap(QStringLiteral(":/asset/font.png"));
    return p.copy(character.cell() % 16 * 64, character.cell() / 16 * 64, 64,
                  64);
}
Ejemplo n.º 16
0
QCString QKoi8Codec::fromUnicode(const QString& uc, int& len_in_out) const
{
    int l = QMIN((int)uc.length(),len_in_out);
    int rlen = l+1;
    QCString rstr(rlen);
    uchar* cursor = (uchar*)rstr.data();
    for (int i=0; i<l; i++) {
	const QChar ch = uc[i];
	if ( ch.row() ) {
	    if ( ch.row() == 0x25 ) {
		if ( ch.cell() < n_unicode_to_koi8_25 )
		    *cursor++ = unicode_to_koi8_25[ch.cell()];
		else
		    *cursor++ = unkn;
	    } else if ( ch.row() == 0x04 ) {
		if ( ch.cell() < n_unicode_to_koi8_04 )
		    *cursor++ = unicode_to_koi8_04[ch.cell()];
		else
		    *cursor++ = unkn;
	    } else if ( ch.row() == 0x22 ) {
		if ( ch.cell() == 0x1A )
		    *cursor++ = 0x96;
		else if ( ch.cell() == 0x48 )
		    *cursor++ = 0x97;
		else if ( ch.cell() == 0x64 )
		    *cursor++ = 0x98;
		else if ( ch.cell() == 0x65 )
		    *cursor++ = 0x99;
		else
		    *cursor++ = unkn;
	    } else if ( ch.row() == 0x23 ) {
		if ( ch.cell() == 0x20 )
		    *cursor++ = 0x93;
		else if ( ch.cell() == 0x21 )
		    *cursor++ = 0x9B;
		else
		    *cursor++ = unkn;
	    } else if ( ch.row() == 0x20 ) {
		if ( ch.cell() == 0x22 )
		    *cursor++ = 0x95;
		else
		    *cursor++ = unkn;
	    } else {
		*cursor++ = unkn;
	    }
	} else {
	    if ( ch.cell() < 128 ) {
		*cursor++ = ch.cell();
	    } else {
		*cursor++ = unkn;
	    }
	}
    }
    *cursor = '\0';
    // len_in_out = cursor - result;
    return rstr;
}