Пример #1
0
void ScFace_ttf::RawData(QByteArray & bb) const {
	if (formatCode == ScFace::TTCF) {
		QByteArray coll;
		FtFace::RawData(coll);
		// access table for faceIndex
		if (faceIndex >= static_cast<int>(sfnt::word(coll, 8)))
		{
			bb.resize(0);
			return;
		}
		static const uint OFFSET_TABLE_LEN = 12;
		static const uint   TDIR_ENTRY_LEN = 16;
        uint faceOffset = sfnt::word(coll, 12 + 4 * faceIndex);
		uint nTables    = sfnt::word16(coll, faceOffset + 4);
		sDebug(QObject::tr("extracting face %1 from font %2 (offset=%3, nTables=%4)").arg(faceIndex).arg(fontFile).arg(faceOffset).arg(nTables));
		uint headerLength = OFFSET_TABLE_LEN + TDIR_ENTRY_LEN * nTables;
		uint tableLengths = 0;
		// sum table lengths incl padding
		for (uint i=0; i < nTables; ++i)
		{
			tableLengths += sfnt::word(coll, faceOffset + OFFSET_TABLE_LEN + TDIR_ENTRY_LEN * i + 12);
			tableLengths = (tableLengths+3) & ~3;
		}
		bb.resize(headerLength + tableLengths);
		if (! bb.data())
			return;
		// write header
//		sDebug(QObject::tr("memcpy header: %1 %2 %3").arg(0).arg(faceOffset).arg(headerLength));
		if (!sfnt::copy(bb, 0, coll, faceOffset, headerLength))
			return;

		uint pos = headerLength;
		for (uint i=0; i < nTables; ++i)
		{
            uint dirEntry = faceOffset + OFFSET_TABLE_LEN + TDIR_ENTRY_LEN * i;
			uint tableSize  = sfnt::word(coll,  dirEntry + 12);
			uint tableStart = sfnt::word(coll, dirEntry + 8);
//            sDebug(QObject::tr("table '%1' %2. %3 ...").arg(QString(sfnt::tag(coll, dirEntry)))
//                   .arg(QString::number(sfnt::word16(coll,tableStart),16))
//                   .arg(QString::number(sfnt::word16(coll,tableStart+2),16)));
//			sDebug(QObject::tr("memcpy table: %1 %2 %3").arg(pos).arg(tableStart).arg(tableSize));
			if (!sfnt::copy(bb, pos, coll, tableStart, tableSize)) break;
			// write new offset to table entry
//			sDebug(QObject::tr("memcpy offset: %1 %2 %3").arg(OFFSET_TABLE_LEN + TDIR_ENTRY_LEN*i + 8).arg(pos).arg(4));
			// buggy: not endian aware: memcpy(bb.data() + OFFSET_TABLE_LEN + TDIR_ENTRY_LEN * i + 8, &pos, 4);
            sfnt::putWord(bb, OFFSET_TABLE_LEN + TDIR_ENTRY_LEN * i + 8, pos);
			pos += tableSize;
			// pad
			while ((pos & 3) != 0)
				bb.data()[pos++] = '\0';
		}
	}
	else if (formatCode == ScFace::TYPE42) {
		FtFace::RawData(bb);
	}
	else {
		FtFace::RawData(bb);
	}
}
Пример #2
0
SIpcServer::SIpcServer(QObject *parent)
    : QLocalServer(parent)
{
    // remove stale file just in caase
    QLocalServer::removeServer(QLatin1String("sipcserver"));
    this->listen(QLatin1String("sipcserver"));
#ifdef SIPCSERVER_DEBUG
    sDebug() << "Established myself as the server";
#endif
}
Пример #3
0
void SIpcServer::onClientDisconnected()
{
#ifdef SIPCSERVER_DEBUG
    sDebug() << "Connection closed";
#endif
    SIpcConnection *s = qobject_cast<SIpcConnection *>(sender());
    if (S_VERIFY(s, "no QLocalSocket instance"))
        return;
        
    mPeers.removeAll(s);
    s->deleteLater();
}
Пример #4
0
void SIpcServer::incomingConnection(quintptr socketDescriptor)
{
    SIpcConnection *s = new SIpcConnection(this);
    s->setSocketDescriptor(socketDescriptor);
    connect(s, SIGNAL(messageArrived(const QString &, const QByteArray &)),
               SLOT(onClientMessage(const QString &, const QByteArray &)));
    connect(s, SIGNAL(disconnected()), SLOT(onClientDisconnected()));
    mPeers.append(s);
#ifdef SIPCSERVER_DEBUG
    sDebug() << "Registered connection " << s << ", total peers: " << mPeers.count();
#endif
}
Пример #5
0
void SObjectRemoveRequest::Private::start(SObjectManager *manager)
{
    QSqlDatabase db = manager->d->connection();
    QSqlQuery query(db);
    QString uuidList;

    db.transaction();

    // XXX: TODO: this is bad for memory use/perf and inefficient
    for (int i = 0; i != mObjectIds.count(); ++i) {
        uuidList += QLatin1Char('\'');
        uuidList += mObjectIds.at(i).toString();
        uuidList += QLatin1Char('\'');
        
        if (i < mObjectIds.count() - 1)
            uuidList += QLatin1Char(',');

        query.prepare("INSERT INTO deletelist (key, timestamp) VALUES (:key, :timestamp)");
        query.bindValue("key", mObjectIds.at(i).toString());
        query.bindValue("timestamp", QDateTime::currentMSecsSinceEpoch());
        query.exec();
    }

    // TODO: switch to integer keys and figure out a way to make this suck less
    query.exec("DELETE FROM objects WHERE key IN (" + uuidList + ")");

    bool atLeastOne = false;
    if (query.numRowsAffected() > 0) {
        atLeastOne = true;
    }
    sDebug() << "Deleting " << mObjectIds.count() << "; " << query.numRowsAffected() << " really deleted";

    db.commit();

    // TODO: we really should not emit ids we didn't actually remove.'
    if (atLeastOne) {
        emit manager->objectsRemoved(mObjectIds);

        QByteArray ba;
        QDataStream ds(&ba, QIODevice::WriteOnly);
        ds << mObjectIds;
        manager->d->mIpcChannel.sendMessage(QLatin1String("removed(QList<SObjectLocalId>)"), ba);
    }

    emit q->finished();
}
Пример #6
0
//CB TODO Does NOT handle rebuilding with widgets
bool ScrPopupMenu::repopulateLocalMenu()
{
	localPopupMenu->clear();
	QList< QPointer<QObject> >::Iterator menuItemListIt = menuItemList.begin();
	while (menuItemListIt!=menuItemList.end())
	{
		QObject *listObj=(*menuItemListIt);
		if (listObj==NULL)
		{
			QList< QPointer<QObject> >::Iterator menuItemListItToDelete = menuItemListIt;
			++menuItemListIt;
			menuItemList.removeAll(*menuItemListItToDelete);
			continue;
		}
		
		QString menuItemListClassName=listObj->metaObject()->className();
		if (menuItemListClassName=="ScrAction")
		{
			ScrAction * act = dynamic_cast<ScrAction *>(listObj);
			if (act!=NULL)
				localPopupMenu->addAction(act);
		}
		else 
		{
			if (menuItemListClassName=="ScrPopupMenu")
			{
				ScrPopupMenu * men = dynamic_cast<ScrPopupMenu *>(listObj);
				if (men!=NULL)
				{
// 					localPopupMenu->insertItem(men->getMenuIcon(), men->getMenuText(), men->getLocalPopupMenu());
					QAction *m=localPopupMenu->addMenu(men->getLocalPopupMenu());
					if (m)
						m->setText(men->getMenuText());
				}
			}
			else
				sDebug(QString("Alien found: %1").arg((*menuItemListIt)->metaObject()->className()));
		}
		++menuItemListIt;
	}
	return true;
}
Пример #7
0
void MainWindow::setSingnals()
{
    connect(fileMenuNew, SIGNAL(triggered()), this, SLOT( sNew() ));
    connect(fileMenuOpen, SIGNAL(triggered()), this, SLOT( sOpen() ));
    connect(fileMenuSave, SIGNAL(triggered()), this, SLOT( sSave() ));
    connect(fileMenuQuit, SIGNAL(triggered()), qApp, SLOT(quit() ));
    connect(fileMenuSaveAs, SIGNAL(triggered()), this, SLOT( sSaveAs() ));
    connect(this->ui->send_button, SIGNAL(clicked()), this, SLOT(sSend()));
    //connect(przyklad, SIGNAL(triggered()), this, SLOT( sEg((QString)"przyklad") ));
    connect(Run, SIGNAL(triggered()), this, SLOT( sRun() ));
    connect(Debug, SIGNAL(triggered()), this, SLOT( sDebug() ));
    connect(Stop, SIGNAL(triggered()), this, SLOT( sStop() ));

    connect(Undo, SIGNAL(triggered()), this, SLOT( sUndo() ));
    connect(Redo, SIGNAL(triggered()), this, SLOT( sRedo() ));

    connect(Copy, SIGNAL(triggered()), this, SLOT(sCopy()));
    connect(Cut, SIGNAL(triggered()), this, SLOT(sCut()));
    connect(Paste, SIGNAL(triggered()), this, SLOT(sPaste()));
    connect(toC, SIGNAL(triggered()), this, SLOT(sToC()));
    connect(toJava, SIGNAL(triggered()), this, SLOT(sToJava()));

}
Пример #8
0
bool ScFace_ttf::EmbedFont(QByteArray &str) const
{
    QByteArray bb;
    FtFace::RawData(bb);
	if (formatCode == ScFace::TYPE42) {
		//easy:
		str = bb;
		return true;
	}
    
	QString tmp4;
	QString tmp2 = "";
	QString tmp3 = "";
	int counter = 0;
	char *buf[50];
	FT_ULong  charcode;
	FT_UInt   gindex;
	FT_Face face = ftFace();
	if (!face) {
		return false;
	}
	const FT_Stream fts = face->stream;
	if (ftIOFunc(fts, 0L, NULL, 0)) {
		return(false);
	}
	str+="%!PS-TrueTypeFont\n";
	str+="11 dict begin\n";
	str+="/FontName /" + psName + " def\n";
	str+="/Encoding /ISOLatin1Encoding where {pop ISOLatin1Encoding} {StandardEncoding} ifelse def\n";
	str+="/PaintType 0 def\n/FontMatrix [1 0 0 1 0 0] def\n";
	str+="/FontBBox ["+m_pdfFontBBox+"] def\n";
	str+="/FontType 42 def\n";
	str+="/FontInfo 8 dict dup begin\n";
	str+="/FamilyName (" + psName + ") def\n";
	str+="end readonly def\n";
	unsigned char *tmp = new unsigned char[65535];
	int length;
	char linebuf[80];
	str += "/sfnts [";
	int poso=0;
	do {
		int posi=0;
		length= fts->size - fts->pos;
		if (length > 65534) {
			length = 65534;
		}
		if (!ftIOFunc(fts, 0L, tmp, length))
		{
			str+="\n<\n";
			for (int j = 0; j < length; j++)
			{
				unsigned char u=tmp[posi];
				linebuf[poso]=((u >> 4) & 15) + '0';
				if (u>0x9f) linebuf[poso]+='a'-':';
				++poso;
				u&=15; linebuf[poso]=u + '0';
				if (u>0x9) linebuf[poso]+='a'-':';
				++posi;
				++poso;
				if (poso > 70)
				{
					linebuf[poso++]='\n';
					linebuf[poso++]=0;
					str += linebuf;
					poso = 0;
				}
			}
			linebuf[poso++]=0;
			str += linebuf;
			poso = 0;
			str += "00\n>";
		}
		else {
			sDebug(QObject::tr("Font %1 is broken (read stream), no embedding").arg(fontFile));
			str += "\n] def\n";
			status = qMax(status,ScFace::BROKENGLYPHS);
			return false;
		}
	} while (length==65534);
Пример #9
0
void HelpBrowser::loadMenu()
{
//	QString baseHelpDir = ScPaths::instance().docDir();
//	QString altHelpDir  = ScPaths::instance().getApplicationDataDir();
	QString baseHelpDir = ScPaths::instance().getUserHelpFilesDir(false);
	QString installHelpDir  = ScPaths::instance().docDir();

	QString baseHelpMenuFile = QDir::toNativeSeparators(baseHelpDir + language + "/menu.xml");
	QString installHelpMenuFile = QDir::toNativeSeparators(installHelpDir + language + "/menu.xml");
	QFileInfo baseFi = QFileInfo(baseHelpMenuFile);
	QFileInfo installFi = QFileInfo(installHelpMenuFile);
	QString toLoad = baseHelpMenuFile;
	if (!baseFi.exists())
	{
		if (installFi.exists())
		{
			toLoad=installHelpMenuFile;
			baseFi=installFi;
		}
		else		
		{
			if (!language.isEmpty())
			{
				//Check if we can load, eg "de" when "de_CH" docs don't exist
				QString baseHelpMenuFile3 = QDir::toNativeSeparators(baseHelpDir + language.left(2) + "/menu.xml");
				QString altHelpMenuFile3 = QDir::toNativeSeparators(installHelpDir + language.left(2) + "/menu.xml");
				QFileInfo fi3 = QFileInfo(baseHelpMenuFile3);
				QFileInfo altfi3 = QFileInfo(altHelpMenuFile3);
				if (fi3.exists())
				{
					language=language.left(2);
					toLoad = QDir::toNativeSeparators(baseHelpMenuFile3);
				}
				else if (altfi3.exists())
				{
					language=language.left(2);
					toLoad = QDir::toNativeSeparators(altHelpMenuFile3);
				}
				else
				{
					//Fall back to English
					sDebug("Scribus help in your selected language does not exist, trying English. Otherwise, please visit http://docs.scribus.net.");
					language="en";
					if (QFile::exists(baseHelpDir + language + "/menu.xml"))
						toLoad = QDir::toNativeSeparators(baseHelpDir + language + "/menu.xml");
					else
						toLoad = QDir::toNativeSeparators(installHelpDir + language + "/menu.xml");
				}
			}
			else
			{
				language="en";
				toLoad = QDir::toNativeSeparators(baseHelpDir + language + "/menu.xml");
			}
			baseFi = QFileInfo(toLoad);
		}
	}
	else
	{
		if (installFi.exists())
			baseFi=installFi;
	}
	//Set our final location for loading the help files
	finalBaseDir=baseFi.path();
	textBrowser->setSearchPaths(QStringList(finalBaseDir));
	if (baseFi.exists())
	{
		if (menuModel!=NULL)
			delete menuModel;
		menuModel=new ScHelpTreeModel(toLoad, "Topic", "Location", &quickHelpIndex);
	
		helpNav->listView->setModel(menuModel);
		helpNav->listView->setSelectionMode(QAbstractItemView::SingleSelection);
		QItemSelectionModel *selectionModel = new QItemSelectionModel(menuModel);
		helpNav->listView->setSelectionModel(selectionModel);
		connect(helpNav->listView->selectionModel(), SIGNAL(selectionChanged( const QItemSelection &, const QItemSelection &)), this, SLOT(itemSelected( const QItemSelection &, const QItemSelection &)));
	
		helpNav->listView->setColumnHidden(1,true);
	}
	else
Пример #10
0
void ScribusCore::getCMSProfilesDir(QString pfad, bool showInfo, bool recursive)
{
	QString profileName;
	QList<ScColorProfileInfo> profileInfos = defaultEngine.getAvailableProfileInfo(pfad, recursive);
	for (int i = 0; i < profileInfos.count(); ++i)
	{
		const ScColorProfileInfo& profInfo = profileInfos.at(i);
		profileName = profInfo.description;
		if (profileName.isEmpty())
		{
			if (showInfo)
				sDebug(QString("Color profile %1 is broken : no valid description").arg(profInfo.file));
			continue;
		}
		if (!profInfo.debug.isEmpty())
		{
			if (showInfo)
				sDebug(profInfo.debug);
			continue;
		}
		switch (static_cast<int>(profInfo.deviceClass))
		{
		case Class_Input:
			if (profInfo.colorSpace == ColorSpace_Rgb)
			{
				if (!InputProfiles.contains(profileName))
					InputProfiles.insert(profileName, profInfo.file);
			}
			break;
		case Class_ColorSpace:
			if (profInfo.colorSpace == ColorSpace_Rgb)
			{
				if (!InputProfiles.contains(profileName))
					InputProfiles.insert(profileName, profInfo.file);
			}
			if (profInfo.colorSpace == ColorSpace_Cmyk)
			{
				if (!InputProfilesCMYK.contains(profileName))
					InputProfilesCMYK.insert(profileName, profInfo.file);
			}
			break;
		case Class_Display:
			if (profInfo.colorSpace == ColorSpace_Rgb)
			{
				if (!MonitorProfiles.contains(profileName))
					MonitorProfiles.insert(profileName, profInfo.file);
				if (!InputProfiles.contains(profileName))
					InputProfiles.insert(profileName, profInfo.file);
			}
			if (profInfo.colorSpace == ColorSpace_Cmyk)
			{
				if (!InputProfilesCMYK.contains(profileName))
					InputProfilesCMYK.insert(profileName, profInfo.file);
			}
			break;
		case Class_Output:
			// Disable rgb printer profile detection until effective support
			// PrinterProfiles.insert(nam, pfad + d[dc], false);
			if (profInfo.colorSpace == ColorSpace_Cmyk)
			{
				if (!PDFXProfiles.contains(profileName))
					PDFXProfiles.insert(profileName, profInfo.file);
				if (!InputProfilesCMYK.contains(profileName))
					InputProfilesCMYK.insert(profileName, profInfo.file);
				if (!PrinterProfiles.contains(profileName))
					PrinterProfiles.insert(profileName, profInfo.file);
			}
			break;
		}
		if (showInfo)
			sDebug( QString("Color profile %1 loaded from %2").arg(profileName).arg(profInfo.file) );
	}
}
Пример #11
0
QSqlDatabase SObjectManager::Private::connection()
{
    if (!mConnection.isValid()) {
        QString databasePath;
        QCoreApplication *a = QCoreApplication::instance();

        QString orgName = a->organizationName();
        QString appName = a->applicationName();

        a->setOrganizationName(QLatin1String("saesu"));
        a->setApplicationName(QLatin1String("clouds"));

        databasePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);

        QDir dirPath(databasePath);
        if (!dirPath.exists())
            dirPath.mkpath(databasePath);


        // restore app name/org details
        a->setOrganizationName(orgName);
        a->setApplicationName(appName);

        mConnection = QSqlDatabase::addDatabase("QSQLITE", QLatin1String("saesu-cloud://") + mTableName);
        mConnection.setDatabaseName(databasePath + "/" + mTableName);
        if (!mConnection.open()) {
            // TODO: error handling
            sWarning() << "Couldn't open database";
            return mConnection;
        }

        const int currentDbVersion = 3;

        // TODO: make this work with multiple ObjectManagers
        if (!mConnection.tables().contains("_saesu")) {
            QSqlQuery q(mConnection);
            mConnection.transaction();

            // create table(s)
            sDebug() << "Creating tables";

            q.exec("CREATE TABLE _saesu (version integer)");
            q.exec("INSERT INTO _saesu VALUES (" + QString::number(currentDbVersion) + ")");
            q.exec("CREATE TABLE objects (key primary key, timestamp integer, hash blob, object blob)");
            q.exec("CREATE TABLE deletelist (key primary key, timestamp integer)");

            mConnection.commit();
        } else {
            QSqlQuery q(mConnection);
            mConnection.transaction();

            sDebug() << "Checking for migration";
            q.exec("SELECT version FROM _saesu");
            q.next();
            qint64 dbVersion = q.value(0).toLongLong();
            
            switch (dbVersion) {
                case currentDbVersion:
                    sDebug() << "Database up to date";
                    break;
                case 1:
                case 2:
                    // need to add a 'deletelist' table.
                    q.exec("CREATE TABLE deletelist (key primary key, timestamp integer)");
                    sDebug() << "Migrated successfully from schema v1";
                    break;
                default:
                    qCritical("I don't understand schema version!");
                    
            }

            q.exec("UPDATE _saesu SET version = '" + QString::number(currentDbVersion) + "'");

            mConnection.commit();
        }
    }

    return mConnection;
}