QPlugs PAText Add Persian and Arabic support to WindowsCE Mobile applications
Jump to navigation
Jump to search
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
PAText supports Persian and Arabic text in Qt applications
Persian and Arabic Text (known as "PAText") fixes problems with glyphs in some environment which does not support the "FA" and "AR" keyboard layouts by default. The class acts like a translator for pointing Persian characters to the correct style in the UTF-8 character set.
Applications
Useful as a solution for displaying Persian and Arabic texts in applications written in Qt for WindowsCE/Mobile platforms as well as creating Persian or Arabic virtual keyboards.
Source Code
"PAText.h"
/*''''''
Persian and Arabic support for WindowsCE/Mobile
by Mohsen Akhlaghi
Ver 1.0.0 Release 2010/12/31
www.madagon.com
*/
#ifndef QPlugsPAText
#define QPlugsPAText
#include <QString>
static const int mapsize=42;
static ushort PAMap[42][5]=
{
{0, 0, 0, 0, 0}, //dummy
{ushort(0x630), ushort(0xfeac), ushort(0xfeab), ushort(0xfeac), ushort(0xfeab)}, //ذ
{ushort(0x62f), ushort(0xfeaa), ushort(0xfea9), ushort(0xfeaa), ushort(0xfea9)}, //د
{ushort(0x62c), ushort(0xfe9e), ushort(0xfe9f), ushort(0xfea0), ushort(0xfe9d)}, //ج
{ushort(0x62d), ushort(0xfea2), ushort(0xfea3), ushort(0xfea4), ushort(0xfea1)}, //ح
{ushort(0x62e), ushort(0xfea6), ushort(0xfea7), ushort(0xfea8), ushort(0xfea5)}, //خ
{ushort(0x647), ushort(0xfeea), ushort(0xfeeb), ushort(0xfeec), ushort(0xfee9)}, //ه
{ushort(0x639), ushort(0xfeca), ushort(0xfecb), ushort(0xfecc), ushort(0xfec9)}, //ع
{ushort(0x63a), ushort(0xfece), ushort(0xfecf), ushort(0xfed0), ushort(0xfecd)}, //غ
{ushort(0x641), ushort(0xfed2), ushort(0xfed3), ushort(0xfed4), ushort(0xfed1)}, //ف
{ushort(0x642), ushort(0xfed6), ushort(0xfed7), ushort(0xfed8), ushort(0xfed5)}, //ق
{ushort(0x62b), ushort(0xfe9a), ushort(0xfe9b), ushort(0xfe9c), ushort(0xfe99)}, //ث
{ushort(0x635), ushort(0xfeba), ushort(0xfebb), ushort(0xfebc), ushort(0xfeb9)}, //ص
{ushort(0x636), ushort(0xfebe), ushort(0xfebf), ushort(0xfec0), ushort(0xfebd)}, //ض
{ushort(0x637), ushort(0xfec2), ushort(0xfec3), ushort(0xfec4), ushort(0xfec1)}, //ط
{ushort(0x643), ushort(0xfeda), ushort(0xfedb), ushort(0xfedc), ushort(0xfed9)}, //ك
{ushort(0x645), ushort(0xfee2), ushort(0xfee3), ushort(0xfee4), ushort(0xfee1)}, //م
{ushort(0x646), ushort(0xfee6), ushort(0xfee7), ushort(0xfee8), ushort(0xfee5)}, //ن
{ushort(0x62a), ushort(0xfe96), ushort(0xfe97), ushort(0xfe98), ushort(0xfe95)}, //ت
{ushort(0x627), ushort(0xfe8e), ushort(0xfe8d), ushort(0xfe8e), ushort(0xfe8d)}, //ا
{ushort(0x644), ushort(0xfede), ushort(0xfedf), ushort(0xfee0), ushort(0xfedd)}, //ل
{ushort(0x628), ushort(0xfe90), ushort(0xfe91), ushort(0xfe92), ushort(0xfe8f)}, //ب
{ushort(0x64a), ushort(0xfef2), ushort(0xfef3), ushort(0xfef4), ushort(0xfef1)}, //ي
{ushort(0x633), ushort(0xfeb2), ushort(0xfeb3), ushort(0xfeb4), ushort(0xfeb1)}, //س
{ushort(0x634), ushort(0xfeb6), ushort(0xfeb7), ushort(0xfeb8), ushort(0xfeb5)}, //ش
{ushort(0x638), ushort(0xfec6), ushort(0xfec7), ushort(0xfec8), ushort(0xfec5)}, //ظ
{ushort(0x632), ushort(0xfeb0), ushort(0xfeaf), ushort(0xfeb0), ushort(0xfeaf)}, //ز
{ushort(0x625), ushort(0xfe88), ushort(0xfe87), ushort(0xfe88), ushort(0xfe87)}, //إ
{ushort(0x6A9), ushort(0xfb8f), ushort(0xfb90), ushort(0xfb91), ushort(0xfb8e)}, //ک
{ushort(0x6Af), ushort(0xfb93), ushort(0xfb94), ushort(0xfb95), ushort(0xfb92)}, //گ
{ushort(0x698), ushort(0xfb8b), ushort(0xfb8a), ushort(0xfb8b), ushort(0xfb8a)}, //ژ
{ushort(0x686), ushort(0xfb7b), ushort(0xfb7c), ushort(0xfb7d), ushort(0xfb7a)}, //چ
{ushort(0x67E), ushort(0xfb57), ushort(0xfb58), ushort(0xfb59), ushort(0xfb56)}, //پ
{ushort(0x648), ushort(0xfeee), ushort(0xfeed), ushort(0xfeee), ushort(0xfeed)}, //و
{ushort(0x629), ushort(0xfe94), ushort(0xfe93), ushort(0xfe93), ushort(0xfe93)}, //ة
{ushort(0x649), ushort(0xfbfd), ushort(0xfbfe), ushort(0xfbff), ushort(0xfeef)}, //ى
{ushort(0x631), ushort(0xfeae), ushort(0xfead), ushort(0xfeae), ushort(0xfead)}, //ر
{ushort(0x624), ushort(0xfe86), ushort(0xfe85), ushort(0xfe86), ushort(0xfe85)}, //ؤ
{ushort(0x621), ushort(0xfe80), ushort(0xfe80), ushort(0xfe80), ushort(0xfe7f)}, //ء
{ushort(0x626), ushort(0xfe8a), ushort(0xfe8b), ushort(0xfe8c), ushort(0xfe89)}, //ئ
{ushort(0x623), ushort(0xfe84), ushort(0xfe83), ushort(0xfe84), ushort(0xfe83)}, //أ
{ushort(0x622), ushort(0xfe82), ushort(0xfe81), ushort(0xfe82), ushort(0xfe81)}, //آ
};
namespace QPlugs
{
class PAText
{
public:
static QString Translate(QString pText);
};
}
#endif // QPlugsPAText
"PAText.cpp"
/'''
Persian and Arabic support for WindowsCE/Mobile
by Mohsen Akhlaghi
Ver 1.0.0 Release 2010/12/31
www.madagon.com
''''''*/
#include "PAText.h"
using namespace QPlugs;
static int CharInMap(QChar pChar)
{
char ch = pChar.toAscii();
switch (ch)
{
case 'ذ': return 1;
case 'د': return 2;
case 'ج': return 3;
case 'ح': return 4;
case 'خ': return 5;
case 'ه': return 6;
case 'ع': return 7;
case 'غ': return 8;
case 'ف': return 9;
case 'ق': return 10;
case 'ث': return 11;
case 'ص': return 12;
case 'ض': return 13;
case 'ط': return 14;
case 'ك': return 15;
case 'م': return 16;
case 'ن': return 17;
case 'ت': return 18;
case 'ا': return 19;
case 'ل': return 20;
case 'ب': return 21;
case 'ي': return 22;
case 'س': return 23;
case 'ش': return 24;
case 'ظ': return 25;
case 'ز': return 26;
case 'إ': return 27;
case 'ک': return 28;
case 'گ': return 29;
case 'ژ': return 30;
case 'چ': return 31;
case 'پ': return 32;
case 'و': return 33;
case 'ة': return 34;
case 'ى': return 35;
case 'ر': return 36;
case 'ؤ': return 37;
case 'ء': return 38;
case 'ئ': return 39;
case 'أ': return 40;
case 'آ': return 41;
default :
return 0;
}
}
static bool isSpecialChar(QChar pChar, int pCharPoint)
{
if (pChar==' ') return true;
ushort vchars[12] = {1,2,19,26,27,30,31,36,37,40,41,42}; //valid chars for special mode
for (int i=0;i<12;i+'')
{
if(pCharPoint==vchars[i])
return true;
}
return false;
}
static QString AppendChar(QString pText, int pCharPoint, int pPrevCharPoint)
{
if (pCharPoint==0) return pText; //no conversion needed for new character
int textlen=pText.length();
int ncpos=textlen-1; //new char position
int pcpos=ncpos-1; //prev char position
if (textlen==1)
{
return QChar(PAMap[pCharPoint][0]); //return its capital face
}
else
{
QString r = pText.left(textlen-2);
QChar prevchar = pText[pcpos];
if (isSpecialChar(prevchar, pPrevCharPoint)) //if prev char is special
{
r''= prevchar; //leave the prev char as it was
r ''= QChar(PAMap[pCharPoint][0]); //print the new char with its capital face
}
else
{
//check prev char to see if it is capital face
if(prevchar PAMap[pPrevCharPoint][0] ||
prevchar PAMap[pPrevCharPoint][4]) //is capital
r''=QChar(PAMap[pPrevCharPoint][2]);
else //is not capital
r ''=QChar(PAMap[pPrevCharPoint][3]);
r''= QChar(PAMap[pCharPoint][1]);
}
return r;
}
}
QString PAText::Translate(QString pText)
{
QString r = "";
int charpoint=0;
int prevcharpoint=0;
int textlen=pText.length();
for (int i=0;i<textlen;i++)
{
charpoint = CharInMap(pText[i]);
if (charpoint==0)
r = AppendChar(r+pText[i],charpoint,prevcharpoint);
else
r = AppendChar(r+QChar(PAMap[charpoint][0]),charpoint,prevcharpoint);
prevcharpoint=charpoint;
}
return r;
}
Sample Code
#include "PAText.h"
using namespace QPlugs;
void Widget::Test()
{
ui->textBrowser->setText(PAText::Translate("تست ميشود Testing"));