const bool AlternateCaptcha1::Generate() { if(m_fonts.size()==0) { return false; } std::string puzzlestring=GenerateRandomString(5); FreeImage::Bitmap tempchar(50,50,32); tempchar.SetTransparent(); FreeImage::Bitmap bmp(110,50,32); bmp.SetTransparent(); m_solution.clear(); m_puzzle.clear(); // draw the text if(m_fonts.size()>0) { for(int i=0; i<puzzlestring.size(); i++) { RGBQUAD black; black.rgbRed=0; black.rgbGreen=0; black.rgbBlue=0; int xoffset=(i*20)-(5+(rand()%5)); int yoffset=(rand()%20)-10; int fontnum=rand()%m_fonts.size(); FreeImage::Bitmap charbmp=m_fonts[fontnum].Char(puzzlestring[i]); tempchar.SetTransparent(); tempchar.ClearTransparent(); tempchar.BlitTrans(charbmp,25-(charbmp.Width()/2),25-(charbmp.Height()/2),0,0,charbmp.Width(),charbmp.Height()); tempchar.Rotate((rand()%60)-30,0,0,25,25); bmp.BlitTrans(tempchar,xoffset,yoffset,0,0,50,50); } } //place some random lines RGBQUAD white; white.rgbRed=255; white.rgbGreen=255; white.rgbBlue=255; white.rgbReserved=255; int numlines=(rand()%5)+5; for(int i=0; i<numlines; i++) { // draw 4 short lines very close to each other int x1[4]; int y1[4]; int x2[4]; int y2[4]; x1[0]=rand()%bmp.Width(); y1[0]=rand()%bmp.Height(); x2[0]=x1[0]+(rand()%40)-20; y2[0]=y1[0]+(rand()%40)-20; for(int i=1; i<4; i++) { x1[i]=x1[i-1]+rand()%3-1; y1[i]=y1[i-1]+rand()%3-1; x2[i]=x2[i-1]+rand()%3-1; y2[i]=y2[i-1]+rand()%3-1; } for(int i=0; i<4; i++) { bmp.Line(x1[i],y1[i],x2[i],y2[i],white); } } // make output a little wavy int offset=rand()%10000; for(int y=0; y<bmp.Height(); y++) { double shift=sin((double)(y+offset)/3.0); bmp.HorizontalOffset(y,shift); } m_solution.clear(); m_solution.insert(m_solution.end(),puzzlestring.begin(),puzzlestring.end()); m_puzzle.clear(); bmp.SaveToMemory("bmp",m_puzzle); return true; }
void QtX11KeyMapper::populateCharKeyInformation() { virtualkeyToCharKeyInformation.clear(); Display* display = X11Extras::getInstance()->display(); unsigned int total = 0; for (int i=8; i <= 255; i++) { for (int j=0; j <= 3; j++) { Qt::KeyboardModifiers dicis; if (j >= 2) { dicis |= Qt::MetaModifier; } if (j == 1 || j == 3) { dicis |= Qt::ShiftModifier; } unsigned int testsym = XkbKeycodeToKeysym(display, i, dicis & Qt::MetaModifier ? 1 : 0, dicis & Qt::ShiftModifier ? 1 : 0); if (testsym != NoSymbol) { XKeyPressedEvent tempevent; tempevent.keycode = i; tempevent.type = KeyPress; tempevent.display = display; tempevent.state = 0; if (dicis & Qt::ShiftModifier) { tempevent.state |= ShiftMask; } if (dicis & Qt::MetaModifier) { tempevent.state |= Mod1Mask; } char returnstring[256]; memset(returnstring, 0, sizeof(returnstring)); int bitestoreturn = sizeof(returnstring) - 1; int numchars = XLookupString(&tempevent, returnstring, bitestoreturn, NULL, NULL); if (numchars > 0) { returnstring[numchars] = '\0'; QString tempstring = QString::fromUtf8(returnstring); if (tempstring.length() == 1) { QChar tempchar(tempstring.at(0)); charKeyInformation testKeyInformation; testKeyInformation.modifiers = dicis; testKeyInformation.virtualkey = testsym; if (!virtualkeyToCharKeyInformation.contains(tempchar.unicode())) { virtualkeyToCharKeyInformation.insert(tempchar.unicode(), testKeyInformation); //qDebug() << "I FOUND SOMETHING: " << tempchar; total++; } } else { //qDebug() << "YOU FAIL: " << tempchar; } } } } } //qDebug() << "TOTAL: " << total; //qDebug() << ""; QChar tempa('*'); if (virtualkeyToCharKeyInformation.contains(tempa.unicode())) { charKeyInformation projects = virtualkeyToCharKeyInformation.value(tempa.unicode()); } }