Example #1
0
int main(int argc, char **argv)
{
	QGuiApplication app(argc, argv);

	if (app.arguments().size() < 2) {
		qStdOut() << "Usage: fontinfo <family>\n";
		qStdOut() << "       fontinfo -list";
		return -1;
	}

	if (app.arguments().at(1) == "-list") {
		printFontList();
		return 0;
	}

	QFont f;
	f.setStyleHint(QFont::TypeWriter, QFont::StyleStrategy(QFont::PreferDefault | QFont::ForceIntegerMetrics));
	f.setFamily(QStringList(app.arguments().mid(1)).join(" "));
	f.setFixedPitch(true);
	f.setKerning(false);

	printFontInfo(f);
	for (int i=10; i<=18; i++) {
		qStdOut() << "Font size: " << i << endl;
		f.setPointSize(i);
		printFontMetrics(f);
	}
	return 0;
}
Example #2
0
void printFontInfo(const QFont& f)
{
	QFontInfo info(f);
	qStdOut() << "Font family: " << f.family() << endl;
	qStdOut() << "Exact match: " << info.exactMatch() << endl;
	qStdOut() << "Real family: " << info.family() << endl;
}
Example #3
0
void printFontList()
{
	QFontDatabase db;
    foreach (const QString &family, db.families()) {
		qStdOut() << family << "\n";
        foreach (const QString &style, db.styles(family)) {
			qStdOut() << "\t" << style << "\n";
		}
	}
}
Example #4
0
void printFontMetrics(const QFont& f)
{
	QFontMetrics fm(f);
	QFont fi(f);
	fi.setItalic(true);
	QFontMetrics fm_italic(fi);
	QFont fb(f);
	fb.setBold(true);
	QFontMetrics fm_bold(fb);
	QFont fbi(fb);
	fbi.setItalic(true);
	QFontMetrics fm_boldit(fbi);

	// Regular
	char err = (fm.averageCharWidth() != fm.maxWidth() ||
			fm.width("MM") != fm.maxWidth()*2) ? '!' : ' ';
	qStdOut() << err;
	qStdOut() << "  (Regular) Average char width: " << fm.averageCharWidth();
	qStdOut() << " Max char width: " << fm.maxWidth();
	qStdOut() << " Width(MM): " << fm.width("MM") << endl;

	// Italic
	err = (fm_italic.averageCharWidth() != fm_italic.maxWidth() ||
			fm_italic.width("MM") != fm_italic.maxWidth()*2 ||
			fm_italic.maxWidth() != fm.maxWidth()) ? '!' : ' ';
	qStdOut() << err;
	qStdOut() << "   (Italic) Average char width: " << fm_italic.averageCharWidth();
	qStdOut() << " Max char width: " << fm_italic.maxWidth();
	qStdOut() << " Width(MM): " << fm_italic.width("MM") << endl;

	// Bold
	err = (fm_bold.averageCharWidth() != fm_bold.maxWidth() ||
			fm_bold.width("MM") != fm_bold.maxWidth()*2 ||
			fm_bold.maxWidth() != fm.maxWidth()) ? '!' : ' ';
	qStdOut() << err;
	qStdOut() << "     (Bold) Average char width: " << fm_bold.averageCharWidth();
	qStdOut() << " Max char width: " << fm_bold.maxWidth();
	qStdOut() << " Width(MM): " << fm_bold.width("MM") << endl;

	// BoldItalic
	err = (fm_boldit.averageCharWidth() != fm_boldit.maxWidth() ||
			fm_boldit.width("MM") != fm_boldit.maxWidth()*2 ||
			fm_boldit.maxWidth() != fm.maxWidth()) ? '!' : ' ';
	qStdOut() << err;
	qStdOut() << "  (Bold+It) Average char width: " << fm_boldit.averageCharWidth();
	qStdOut() << " Max char width: " << fm_boldit.maxWidth();
	qStdOut() << " Width(MM): " << fm_boldit.width("MM") << endl;
}
Example #5
0
int main(int argc, char *argv[])
{
   int retval = 0;

   QCoreApplication::setOrganizationName("SLART");
   QCoreApplication::setOrganizationDomain("svolli.org");
   QCoreApplication::setApplicationName("TestAppXxtea");
   QCoreApplication app( argc, argv );

   QTextStream qStdOut( stdout );
   QTextStream qStdErr( stderr );
   QSettings   settings;

   QString progName( QFileInfo( QCoreApplication::arguments().at(0) ).fileName() );
   bool help = false;
   bool encrypt = false;
   bool decrypt = false;
   QString key;
   QStringList files;
   CommandLine cl;
   cl.option( "-help",    "show help",     &help,    true );
   cl.option( "-encrypt", "encrypt files", &encrypt, true );
   cl.option( "-decrypt", "decrypt files", &decrypt, true );
   cl.option( "-key",     "set key",       &key );
   cl.parse( &files );

   if( cl.check() )
   {
      qStdErr << "fail! try '-help'\n";
      return 0;
   }

   if( help )
   {
      qStdErr <<
      "\nthis program encrypts and decrypts files using the xxtea algorithm\n"
      "see http://en.wikipedia.org/wiki/XXTEA for details\n"
      "\noptions:\n" << cl.help() << "\n\nexamples:\n"
      << progName << " -key secret                # writes the key secret in the registry\n"
      << progName << " -encrypt file1 (file2 ...) # encryptes the files\n"
      << progName << " -decrypt file1 (file2 ...) # decryptes the files\n"
      << progName << " -key secret -encrypt file  # set key and encrypt in one pass\n\n"
      ;
      return 0;
   }

   if( key.isNull() )
   {
      key = settings.value( "Key" ).toByteArray();
   }
   else
   {
      if( key.isEmpty() )
      {
         settings.remove( "Key" );
         qStdOut << "deleting key\n";
      }
      else
      {
         QCryptographicHash hash( QCryptographicHash::Md5 );
         hash.addData( key.toUtf8() );
         settings.setValue( "Key", hash.result() );
         qStdOut << "setting key to: " << settings.value( "Key" ).toByteArray().toHex() << "\n";
      }

      if( !encrypt && !decrypt )
      {
         return 0;
      }
   }

   if( encrypt == decrypt )
   {
      qStdErr << "you need to specify exactly one of -encrypt or -decrypt\n";
      return 1;
   }

   QFile       file;
   QByteArray  fileData;
   Xxtea       xxtea;
   bool        success = false;

   QByteArray hashedKey( settings.value( "Key" ).toByteArray() );
   if( hashedKey.size() != 16 )
   {
      qStdOut << "key is invalid\n";
      return 1;
   }
   else
   {
      qStdOut << "key is: " << hashedKey.toHex() << "\n";
   }
   xxtea.setKey( hashedKey );
   xxtea.setData( &fileData );
   foreach( const QString &fileName, files )
   {
      qStdOut << fileName << ": ";
      file.setFileName( fileName );
      file.open( QIODevice::ReadWrite );
      qStdOut << "reading, ";
      fileData = file.readAll();
      if( encrypt )
      {
         qStdOut << "encrypting, ";
         success = xxtea.encode();
      }
      if( decrypt )
      {
         qStdOut << "decrypting, ";
         success = xxtea.decode();
      }
      if( !success )
      {
         qStdOut << "some or all data could not be processed, ";
      }
      file.seek( 0 );
      qStdOut << "writing, ";
      file.write( fileData );
      file.close();
      qStdOut << "done.\n";
   }
Example #6
0
void MSRequest::printReplyError(){

    qStdOut() << this->replyErrorText << endl;
}