void MenuSAT::RunSATPlug(ScribusDoc* doc) { QDir templates(ScPaths::getApplicationDataDir()); if (!templates.exists("templates")) { templates.mkdir("templates"); } QString currentPath(QDir::currentPath()); QString currentFile(doc->DocName); bool hasName = doc->hasName; bool isModified = doc->isModified(); QString userTemplatesDir = PrefsManager::instance()->appPrefs.pathPrefs.documentTemplates; PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString oldCollect = dirs->get("collect", "."); QString templatesDir = "."; if (userTemplatesDir.isEmpty()) templatesDir = ScPaths::getApplicationDataDir() + "templates"; else { if (userTemplatesDir.right(1) == "/") userTemplatesDir.chop(1); templatesDir = userTemplatesDir; } dirs->set("collect", templatesDir); if (doc->scMW()->fileCollect().isEmpty()) return; if (oldCollect != ".") dirs->set("collect", oldCollect); QString docPath = doc->DocName; QString docDir = docPath.left(docPath.lastIndexOf('/')); QString docName = docPath.right(docPath.length() - docPath.lastIndexOf('/') - 1); docName = docName.left(docName.lastIndexOf(".s")); if (currentFile != doc->DocName) { SATDialog* satdia = new SATDialog(doc->scMW(),docName, static_cast<int>(doc->pageWidth() + 0.5), static_cast<int>(doc->pageHeight() + 0.5)); if (satdia->exec()) { sat* s = new sat(doc, satdia, docPath.right(docPath.length() - docPath.lastIndexOf('/') - 1),docDir); s->createImages(); s->createTmplXml(); delete s; } // Restore the state that was before ScMW->Collect() doc->DocName = currentFile; doc->hasName = hasName; doc->setModified(isModified); QString newCaption=currentFile; if (isModified) newCaption.append('*'); doc->scMW()->updateActiveWindowCaption(newCaption); doc->scMW()->removeRecent(docPath); QDir::setCurrent(currentPath); delete satdia; } }
bool ScPrintEngine_GDI::print( ScribusDoc& doc, PrintOptions& options ) { bool toFile; bool success; HDC printerDC; QString diaSelection, docDir, prefsDocDir; QString printerName = options.printer; QByteArray devMode = options.devMode; QString fileName; if( options.toFile ) return false; resetData(); toFile = printerUseFilePort( options.printer ); if ( toFile ) { diaSelection = doc.DocName.right( doc.DocName.length() - doc.DocName.lastIndexOf("/") - 1 ); diaSelection = diaSelection.left( diaSelection.indexOf(".") ); diaSelection += ".prn"; PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString prefsDocDir = PrefsManager::instance()->documentDir(); if (!prefsDocDir.isEmpty()) docDir = dirs->get("winprn", prefsDocDir); else docDir = "."; CustomFDialog dia( doc.scMW()->view, docDir, QObject::tr("Save As"), "Spool Files (*.prn *.ps);;All Files (*)", fdNone); dia.setSelection( diaSelection ); if (dia.exec() == QDialog::Accepted) { QString selectedFile = dia.selectedFile(); if ( overwrite(doc.scMW()->view, selectedFile) ) { dirs->set("winprn", selectedFile.left(selectedFile.lastIndexOf("/"))); fileName = QDir::toNativeSeparators( selectedFile ); } } else return true; } // Set user options in the DEVmode structure setDeviceParams( &doc, options, (DEVMODEW*) devMode.data() ); // Create the device context printerDC = CreateDCW( NULL, (LPCWSTR) printerName.utf16(), NULL, (DEVMODEW*) devMode.data() ); if( printerDC ) { success = printPages( &doc, options, printerDC, (DEVMODEW*) devMode.data(), fileName); DeleteDC( printerDC ); } else { qWarning("doPrintPages : the device context could not be created"); success = false; } return success; }
bool WMFImportPlugin::import(QString filename, int flags) { if (!checkFlags(flags)) return false; if (m_Doc == nullptr) m_Doc = ScCore->primaryMainWindow()->doc; ScribusMainWindow* mw=(m_Doc==nullptr) ? ScCore->primaryMainWindow() : m_Doc->scMW(); if (filename.isEmpty()) { flags |= lfInteractive; PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("WMFPlugin"); QString wdir = prefs->get("wdir", "."); CustomFDialog diaf(mw, wdir, QObject::tr("Open"), FormatsManager::instance()->fileDialogFormatList(FormatsManager::WMF)); if (diaf.exec()) { filename = diaf.selectedFile(); prefs->set("wdir", filename.left(filename.lastIndexOf("/"))); } else return true; } bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); TransactionSettings trSettings; trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; trSettings.targetPixmap = Um::IImageFrame; trSettings.actionName = Um::ImportWMF; trSettings.description = filename; trSettings.actionPixmap = Um::IWMF; UndoTransaction activeTransaction; if ((m_Doc == nullptr) || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(false); if (UndoManager::undoEnabled()) activeTransaction = UndoManager::instance()->beginTransaction(trSettings); WMFImport *dia = new WMFImport(m_Doc, flags); dia->import(filename, trSettings, flags); Q_CHECK_PTR(dia); if (activeTransaction) activeTransaction.commit(); if ((m_Doc == nullptr) || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(true); if (dia->importCanceled) { if (dia->importFailed) ScMessageBox::warning(mw, CommonStrings::trWarning, tr("The file could not be imported")); else if (dia->unsupported) ScMessageBox::warning(mw, CommonStrings::trWarning, tr("WMF file contains some unsupported features")); } bool success = !dia->importFailed; delete dia; return success; }
void ScripterCore::SavePlugPrefs() { PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("scriptplugin"); if (!prefs) { qDebug("scriptplugin: Unable to load prefs"); return; } PrefsTable* prefRecentScripts = prefs->getTable("recentscripts"); if (!prefRecentScripts) { qDebug("scriptplugin: Unable to get recent scripts"); return; } for (int i = 0; i < RecentScripts.count(); i++) prefRecentScripts->set(i, 0, RecentScripts[i]); // then save more general preferences prefs->set("extensionscripts", m_enableExtPython); prefs->set("importall", m_importAllNames); prefs->set("startupscript", m_startupScript); }
void PDFExportDialog::ChangeFile() { PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString wdir = dirs->get("pdf", "."); QString d = QFileDialog::getSaveFileName(this, tr("Save As"), wdir, tr("PDF Files (*.pdf);;All Files (*)"), 0, QFileDialog::DontConfirmOverwrite); if (d.length()>0) { QString fn(QDir::fromNativeSeparators(d)); dirs->set("pdf", fn.left(fn.lastIndexOf("/"))); fileNameLineEdit->setText( d ); } }
XtgIm::XtgIm(QString fileName, QString enc, PageItem *textItem, bool textOnly) { PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("XtgIm"); bool prefix = prefs->getBool("prefix", true); bool ask = prefs->getBool("askAgain", true); encoding = enc; qDebug()<<"Encoding = "<<encoding; in_Buffer = ""; TextWriter *writer = new TextWriter(textItem->doc()); writer->open(textItem); if (!textOnly) { if (ask) { XtgDialog* xtgdia = new XtgDialog(prefix); if (xtgdia->exec()) { prefix = xtgdia->usePrefix(); prefs->set("prefix", xtgdia->usePrefix()); prefs->set("askAgain", xtgdia->askAgain()); delete xtgdia; } else { delete xtgdia; return; } } } filename = fileName; /** This will load the xtg file into a QByte Array which will be used for furthur parsing */ loadFiletoArray(); in_Buffer = toUnicode(buffer); QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1); docname = docname.left(docname.lastIndexOf(".")); XtgScanner *scanner = new XtgScanner(docname,writer,in_Buffer,textOnly,prefix); scanner->xtgParse(); writer->close(); }
void PrintDialog::SelFile() { PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString wdir = dirs->get("printdir", "."); CustomFDialog dia(this, wdir, tr("Save As"), tr("PostScript Files (*.ps);;All Files (*)"), fdNone | fdHidePreviewCheckBox); if (!LineEdit1->text().isEmpty()) dia.setSelection(LineEdit1->text()); if (dia.exec() == QDialog::Accepted) { QString selectedFile = dia.selectedFile(); dirs->set("printdir", selectedFile.left(selectedFile.lastIndexOf("/"))); LineEdit1->setText( QDir::toNativeSeparators(selectedFile) ); } }
bool ImportXfigPlugin::import(QString fileName, int flags) { if (!checkFlags(flags)) return false; if( fileName.isEmpty() ) { flags |= lfInteractive; PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importxfig"); QString wdir = prefs->get("wdir", "."); CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), tr("All Supported Formats")+" (*.fig *.FIG);;All Files (*)"); if (diaf.exec()) { fileName = diaf.selectedFile(); prefs->set("wdir", fileName.left(fileName.lastIndexOf("/"))); } else return true; } m_Doc=ScCore->primaryMainWindow()->doc; UndoTransaction* activeTransaction = NULL; bool emptyDoc = (m_Doc == NULL); bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); TransactionSettings trSettings; trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; trSettings.targetPixmap = Um::IImageFrame; trSettings.actionName = Um::ImportXfig; trSettings.description = fileName; trSettings.actionPixmap = Um::IXFIG; if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(false); if (UndoManager::undoEnabled()) activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings)); XfigPlug *dia = new XfigPlug(m_Doc, flags); Q_CHECK_PTR(dia); dia->import(fileName, trSettings, flags); if (activeTransaction) { activeTransaction->commit(); delete activeTransaction; activeTransaction = NULL; } if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(true); delete dia; return true; }
void PDFExportDialog::ChangeFile() { QString fn; PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString wdir = dirs->get("pdf", "."); CustomFDialog dia(this, wdir, tr("Save As"), tr("PDF Files (*.pdf);;All Files (*)"), fdNone); if (!fileNameLineEdit->text().isEmpty()) { QString fileName = QDir::fromNativeSeparators(fileNameLineEdit->text()); dia.setSelection(fileName); } if (dia.exec() == QDialog::Accepted) { // selectedFile() may return path with native separators fn = QDir::fromNativeSeparators(dia.selectedFile()); dirs->set("pdf", fn.left(fn.lastIndexOf("/"))); fileNameLineEdit->setText( QDir::toNativeSeparators(fn) ); } }
bool ImportPSPlugin::import(QString fileName, int flags) { if (!checkFlags(flags)) return false; if( fileName.isEmpty() ) { flags |= lfInteractive; PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importps"); QString wdir = prefs->get("wdir", "."); CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), FormatsManager::instance()->fileDialogFormatList(FormatsManager::EPS|FormatsManager::PS)); if (diaf.exec()) { fileName = diaf.selectedFile(); prefs->set("wdir", fileName.left(fileName.lastIndexOf("/"))); } else return true; } m_Doc=ScCore->primaryMainWindow()->doc; UndoTransaction activeTransaction; bool emptyDoc = (m_Doc == nullptr); bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); TransactionSettings trSettings; trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; trSettings.targetPixmap = Um::IImageFrame; trSettings.actionName = Um::ImportEPS; trSettings.description = fileName; trSettings.actionPixmap = Um::IEPS; if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(false); if (UndoManager::undoEnabled()) activeTransaction = UndoManager::instance()->beginTransaction(trSettings); EPSPlug *dia = new EPSPlug(m_Doc, flags); Q_CHECK_PTR(dia); dia->import(fileName, trSettings, flags); if (activeTransaction) activeTransaction.commit(); if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(true); delete dia; return true; }
void Annota::GetFile() { QString fn; PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString wdir = dirs->get("annot_getfile", "."); CustomFDialog dia(this, wdir, tr("Open"), tr("%1;;All Files (*)").arg(FormatsManager::instance()->extensionsForFormat(FormatsManager::PDF))); if (!Destfile->text().isEmpty()) dia.setSelection(Destfile->text()); if (dia.exec() == QDialog::Accepted) { fn = dia.selectedFile(); if (!fn.isEmpty()) { dirs->set("annot_getfile", fn.left(fn.lastIndexOf("/"))); Destfile->setText(fn); SpinBox1->setValue(1); SpinBox1->setMaximum(1000); SetPage(1); } } }
bool gtDialogs::runFileDialog(const QString& filters, const QStringList& importers) { bool accepted = false; PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString dir = dirs->get("get_text", "."); fdia = new gtFileDialog(filters, importers, dir); if (fdia->exec() == QDialog::Accepted) { fileName = fdia->selectedFile(); if (!fileName.isEmpty()) accepted = true; encoding = fdia->encodingCombo->currentText(); // if (encoding == "UTF-16") // encoding = "ISO-10646-UCS-2"; importer = fdia->importerCombo->currentIndex() - 1; dirs->set("get_text", fileName.left(fileName.lastIndexOf("/"))); } QDir::setCurrent(pwd); return accepted; }
void CurveWidget::doLoad() { QString fileName; PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString wdir = dirs->get("curves", "."); CustomFDialog dia(this, wdir, tr("Open"), tr("Curve Files (*.scu *.SCU);;All Files (*)"), fdHidePreviewCheckBox | fdExistingFiles); if (dia.exec() == QDialog::Accepted) fileName = dia.selectedFile(); else return; if (!fileName.isEmpty()) { dirs->set("curves", fileName.left(fileName.lastIndexOf("/"))); QFile f(fileName); if (f.open(QIODevice::ReadOnly)) { QTextStream fp(&f); int numVals; double xval, yval; FPointArray curve; curve.resize(0); fp >> numVals; for (int nv = 0; nv < numVals; nv++) { QString s; fp >> s; xval = ScCLocale::toDoubleC(s); fp >> s; yval = ScCLocale::toDoubleC(s); curve.addPoint(xval, yval); } cDisplay->setCurve(curve); int lin; fp >> lin; cDisplay->setLinear(lin); }
void Prefs_Printer::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const { PrefsContext* prefs = PrefsManager::instance()->prefsFile->getContext("print_options"); prefs->set("CurrentPrn", destinationComboBox->currentText()); prefs->set("OtherCom", useAltPrinterCmdCheckBox->isChecked()); prefs->set("Command", altPrinterCmdLineEdit->text()); prefs->set("PrintAll", true); prefs->set("CurrentPage", false); prefs->set("PrintRange", false); prefs->set("PageNr", ""); prefs->set("Copies", 1); prefs->set("Separations", static_cast<int>(outputComboBox->currentIndex()==1)); //FIXME: This comparison looks wrong. prefs->set("PrintColor", static_cast<int>(!(postscriptPrintToColorComboBox->currentIndex()==0))); prefs->set("SepArt", 0); prefs->set("MirrorH", pageMirrorHorizontallyCheckBox->isChecked()); prefs->set("MirrorV", pageMirrorVerticallyCheckBox->isChecked()); prefs->set("DoGCR", applyUnderColorRemovalCheckBox->isChecked()); prefs->set("Clip", clipToPrinterMarginsCheckBox->isChecked()); prefs->set("PSLevel", postscriptLevelComboBox->currentIndex() + 1); prefs->set("doDev", setMediaSizeCheckBox->isChecked()); prefs->set("doSpot", !convertSpotsToProcessCheckBox->isChecked()); prefs->set("ICCinUse", true); double unitRatio = unitGetRatioFromIndex(prefsData->docSetupPrefs.docUnitIndex); MarginStruct bleeds(bleedsWidget->margins()); prefs->set("BleedTop", bleeds.top()); prefs->set("BleedBottom", bleeds.bottom()); prefs->set("BleedRight", bleeds.right()); prefs->set("BleedLeft", bleeds.left()); prefs->set("markLength", markLengthSpinBox->value() / unitRatio); prefs->set("markOffset", markOffsetSpinBox->value() / unitRatio); prefs->set("cropMarks", cropMarksCheckBox->isChecked()); prefs->set("bleedMarks", bleedMarksCheckBox->isChecked()); prefs->set("registrationMarks", registrationMarksCheckBox->isChecked()); prefs->set("colorMarks", colorBarsCheckBox->isChecked()); prefs->set("includePDFMarks", includePDFAnnotationsCheckBox->isChecked()); }
void Hyphenator::slotHyphenate(PageItem* it) { if ((!m_usable) || !(it->asTextFrame()) || (it->itemText.length() == 0)) return; m_doc->DoDrawing = false; const char *word; char *buffer; const int BORDER = 2; QString text = ""; QString buf; QByteArray te; int startC = 0; if (it->itemText.lengthOfSelection() > 0) { startC = it->itemText.startOfSelection(); text = it->itemText.text(startC, it->itemText.lengthOfSelection()); } else { text = it->itemText.text(0, it->itemText.length()); } int firstC = 0; int lastC = 0; int Ccount = 0; QString found = ""; QString found2 = ""; rememberedWords.clear(); //uint maxC = it->itemText.length() - 1; qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); QRegExp wordBoundary("\\w"); QRegExp whiteSpace("\\s|\\W|\\d|\\n|\\r|\\t"); while ((firstC+Ccount < signed(text.length())) && (firstC != -1) && (lastC < signed(text.length()))) { firstC = text.indexOf(wordBoundary, firstC+Ccount); if (firstC < 0) break; if (firstC > 0 && text.at(firstC-1) == SpecialChars::SHYPHEN) { Ccount = 1; continue; } lastC = text.indexOf(whiteSpace, firstC); if (lastC < 0) lastC = signed(text.length()); Ccount = lastC - firstC; if (lastC < signed(text.length()) && text.at(lastC) == SpecialChars::SHYPHEN) { ++Ccount; continue; } if (Ccount > MinWordLen-1) { found = text.mid(firstC, Ccount).toLower(); found2 = text.mid(firstC, Ccount); if (found.contains(SpecialChars::SHYPHEN)) break; NewDict(it->itemText.charStyle(firstC).language()); te = m_codec->fromUnicode( found ); word = te.data(); int wordlen = strlen(word); buffer = static_cast<char*>(malloc(wordlen+BORDER+3)); if (buffer == NULL) break; char ** rep = NULL; int * pos = NULL; int * cut = NULL; if (!hnj_hyphen_hyphenate2(m_hdict, word, wordlen, buffer, NULL, &rep, &pos, &cut)) { int i = 0; buffer[wordlen] = '\0'; bool hasHyphen = false; for (i = 1; i < found.length()-1; ++i) { if(buffer[i] & 1) { hasHyphen = true; break; } } QString outs = ""; QString input = ""; outs += found2[0]; for (i = 1; i < found.length()-1; ++i) { outs += found2[i]; if(buffer[i] & 1) outs += "-"; } outs += found2.right(1); input = outs; if (!ignoredWords.contains(found2)) { if (!hasHyphen) it->itemText.hyphenateWord(startC + firstC, found.length(), NULL); else if (Automatic) { if (specialWords.contains(found2)) { outs = specialWords.value(found2); uint ii = 1; for (i = 1; i < outs.length()-1; ++i) { QChar cht = outs[i]; if (cht == '-') buffer[ii-1] = 1; else { buffer[ii] = 0; ++ii; } } } it->itemText.hyphenateWord(startC + firstC, found.length(), buffer); } else { if (specialWords.contains(found2)) { outs = specialWords.value(found2); uint ii = 1; for (i = 1; i < outs.length()-1; ++i) { QChar cht = outs[i]; if (cht == '-') buffer[ii-1] = 1; else { buffer[ii] = 0; ++ii; } } } if (rememberedWords.contains(input)) { outs = rememberedWords.value(input); uint ii = 1; for (i = 1; i < outs.length()-1; ++i) { QChar cht = outs[i]; if (cht == '-') buffer[ii-1] = 1; else { buffer[ii] = 0; ++ii; } } it->itemText.hyphenateWord(firstC, found.length(), buffer); } else { qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); PrefsContext* prefs = PrefsManager::instance()->prefsFile->getContext("hyhpen_options"); int xpos = prefs->getInt("Xposition", -9999); int ypos = prefs->getInt("Yposition", -9999); HyAsk *dia = new HyAsk((QWidget*)parent(), outs); if ((xpos != -9999) && (ypos != -9999)) dia->move(xpos, ypos); qApp->processEvents(); if (dia->exec()) { outs = dia->Wort->text(); uint ii = 1; for (i = 1; i < outs.length()-1; ++i) { QChar cht = outs[i]; if (cht == '-') buffer[ii-1] = 1; else { buffer[ii] = 0; ++ii; } } if (!rememberedWords.contains(input)) rememberedWords.insert(input, outs); if (dia->addToIgnoreList->isChecked()) { if (!ignoredWords.contains(found2)) ignoredWords.insert(found2); } if (dia->addToExceptionList->isChecked()) { if (!specialWords.contains(found2)) specialWords.insert(found2, outs); } it->itemText.hyphenateWord(firstC, found.length(), buffer); } else { free(buffer); buffer = NULL; prefs->set("Xposition", dia->xpos); prefs->set("Yposition", dia->ypos); delete dia; break; } prefs->set("Xposition", dia->xpos); prefs->set("Yposition", dia->ypos); delete dia; qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); } } } } free(buffer); if (rep) { for (int i = 0; i < wordlen - 1; ++i) if (rep[i]) free(rep[i]); free(rep); } if (pos) free(pos); if (cut) free(cut); buffer = NULL; rep = NULL; pos = NULL; cut = NULL; } if (Ccount == 0) Ccount++; } qApp->restoreOverrideCursor(); m_doc->DoDrawing = true; rememberedWords.clear(); }
void Hyphenator::slotHyphenate(PageItem* it) { if (!(it->asTextFrame()) || (it->itemText.length() == 0)) return; m_doc->DoDrawing = false; QString text = ""; int startC = 0; if (it->itemText.selectionLength() > 0) { startC = it->itemText.startOfSelection(); text = it->itemText.text(startC, it->itemText.selectionLength()); } else { text = it->itemText.text(0, it->itemText.length()); } rememberedWords.clear(); qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); BreakIterator* bi = StoryText::getWordIterator(); bi->setText((const UChar*) text.utf16()); int pos = bi->first(); while (pos != BreakIterator::DONE) { int firstC = pos; pos = bi->next(); int lastC = pos; int countC = lastC - firstC; const CharStyle& style = it->itemText.charStyle(firstC); if (countC > 0 && countC > style.hyphenWordMin() - 1) { QString word = text.mid(firstC, countC); QString wordLower = QLocale(style.language()).toLower(word); if (wordLower.contains(SpecialChars::SHYPHEN)) break; bool ok = loadDict(style.language()); if (!ok) continue; QByteArray te = m_codec->fromUnicode(wordLower); char *buffer = static_cast<char*>(malloc(te.length() + 5)); if (buffer == nullptr) break; char **rep = nullptr; int *pos = nullptr; int *cut = nullptr; // TODO: support non-standard hyphenation, see hnj_hyphen_hyphenate2 docs if (!hnj_hyphen_hyphenate2(m_hdict, te.data(), te.length(), buffer, nullptr, &rep, &pos, &cut)) { int i = 0; buffer[te.length()] = '\0'; bool hasHyphen = false; for (i = 1; i < wordLower.length()-1; ++i) { if(buffer[i] & 1) { hasHyphen = true; break; } } QString outs = ""; QString input = ""; outs += word[0]; for (i = 1; i < wordLower.length()-1; ++i) { outs += word[i]; if(buffer[i] & 1) outs += "-"; } outs += word.rightRef(1); input = outs; if (!ignoredWords.contains(word)) { if (!hasHyphen) it->itemText.hyphenateWord(startC + firstC, wordLower.length(), nullptr); else if (m_automatic) { if (specialWords.contains(word)) { outs = specialWords.value(word); uint ii = 1; for (i = 1; i < outs.length()-1; ++i) { QChar cht = outs[i]; if (cht == '-') buffer[ii-1] = 1; else { buffer[ii] = 0; ++ii; } } } it->itemText.hyphenateWord(startC + firstC, wordLower.length(), buffer); } else { if (specialWords.contains(word)) { outs = specialWords.value(word); uint ii = 1; for (i = 1; i < outs.length()-1; ++i) { QChar cht = outs[i]; if (cht == '-') buffer[ii-1] = 1; else { buffer[ii] = 0; ++ii; } } } if (rememberedWords.contains(input)) { outs = rememberedWords.value(input); uint ii = 1; for (i = 1; i < outs.length()-1; ++i) { QChar cht = outs[i]; if (cht == '-') buffer[ii-1] = 1; else { buffer[ii] = 0; ++ii; } } it->itemText.hyphenateWord(firstC, wordLower.length(), buffer); } else { qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); PrefsContext* prefs = PrefsManager::instance()->prefsFile->getContext("hyhpen_options"); int xpos = prefs->getInt("Xposition", -9999); int ypos = prefs->getInt("Yposition", -9999); HyAsk *dia = new HyAsk((QWidget*)parent(), outs); if ((xpos != -9999) && (ypos != -9999)) dia->move(xpos, ypos); qApp->processEvents(); if (dia->exec()) { outs = dia->Wort->text(); uint ii = 1; for (i = 1; i < outs.length()-1; ++i) { QChar cht = outs[i]; if (cht == '-') buffer[ii-1] = 1; else { buffer[ii] = 0; ++ii; } } if (!rememberedWords.contains(input)) rememberedWords.insert(input, outs); if (dia->addToIgnoreList->isChecked()) { if (!ignoredWords.contains(word)) ignoredWords.insert(word); } if (dia->addToExceptionList->isChecked()) { if (!specialWords.contains(word)) specialWords.insert(word, outs); } it->itemText.hyphenateWord(firstC, wordLower.length(), buffer); } else { free(buffer); buffer = nullptr; prefs->set("Xposition", dia->xpos); prefs->set("Yposition", dia->ypos); delete dia; break; } prefs->set("Xposition", dia->xpos); prefs->set("Yposition", dia->ypos); delete dia; qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); } } } } free(buffer); if (rep) { for (int i = 0; i < te.length() - 1; ++i) free(rep[i]); } free(rep); free(pos); free(cut); } } qApp->restoreOverrideCursor(); m_doc->DoDrawing = true; rememberedWords.clear(); }
bool CreateMode::doOneClick(FPoint& startPoint, FPoint& endPoint) { bool doCreate = false; double xSize, ySize; int originPoint = 0; if (QApplication::keyboardModifiers() & Qt::ControlModifier) return true; PrefsContext* sizes = PrefsManager::instance()->prefsFile->getContext("ObjectSize"); bool doRemember = sizes->getBool("Remember", true); int lmode = (createObjectMode == modeDrawLine) ? 1 : 0; if (lmode == 0) { xSize = sizes->getDouble("defWidth", 100.0); ySize = sizes->getDouble("defHeight", 100.0); originPoint = sizes->getInt("Origin", 0); } else { xSize = sizes->getDouble("defLength", 100.0); ySize = sizes->getDouble("defAngle", 0.0); originPoint = sizes->getInt("OriginL", 0); } //#12577 Remove one click dialog //#12577 OneClick *dia = new OneClick(m_view, ScribusView::tr("Enter Object Size"), m_doc->unitIndex(), xSize, ySize, doRemember, originPoint, lmode); //#12577 if (dia->exec()) { //#12577 doRemember = dia->checkRemember->isChecked(); if (lmode == 0) { //#12577 xSize = dia->spinWidth->value() / unitGetRatioFromIndex(m_doc->unitIndex()); //#12577 ySize = dia->spinHeight->value() / unitGetRatioFromIndex(m_doc->unitIndex()); //#12577 originPoint = dia->RotationGroup->checkedId(); if (doRemember) { sizes->set("defWidth", xSize); sizes->set("defHeight", ySize); sizes->set("Origin", originPoint); } endPoint.setXY(startPoint.x() + xSize, startPoint.y() + ySize); switch (originPoint) { case 0: break; case 1: startPoint.setX(startPoint.x() - xSize); endPoint.setX(endPoint.x() - xSize); break; case 2: startPoint.setXY(startPoint.x() - xSize / 2.0, startPoint.y() - ySize / 2.0); endPoint.setXY(endPoint.x() - xSize / 2.0, endPoint.y() - ySize / 2.0); break; case 3: startPoint.setY(startPoint.y() - ySize); endPoint.setY(endPoint.y() - ySize); break; case 4: startPoint.setXY(startPoint.x() - xSize, startPoint.y() - ySize); endPoint.setXY(endPoint.x() - xSize, endPoint.y() - ySize); break; } } else { FPoint oldStart = startPoint; //#12577 xSize = dia->spinWidth->value() / unitGetRatioFromIndex(m_doc->unitIndex()); //#12577 ySize = dia->spinHeight->value(); //#12577 originPoint = dia->RotationGroup->checkedId(); if (doRemember) { sizes->set("defLength", xSize); sizes->set("defAngle", ySize); sizes->set("OriginL", originPoint); } double angle = -ySize * M_PI / 180.0; switch (originPoint) { case 0: endPoint = FPoint(startPoint.x() + xSize * cos(angle), startPoint.y() + xSize * sin(angle)); break; case 1: startPoint = FPoint(oldStart.x() - xSize * cos(angle), oldStart.y() - xSize * sin(angle)); endPoint = oldStart; break; case 2: startPoint = FPoint(oldStart.x() - xSize / 2.0 * cos(angle), oldStart.y() - xSize / 2.0 * sin(angle)); endPoint = FPoint(oldStart.x() + xSize / 2.0 * cos(angle), oldStart.y() + xSize / 2.0 * sin(angle)); break; } } sizes->set("Remember", doRemember); doCreate = true; } //delete dia; return doCreate; }
bool ImportPdfPlugin::import(QString fileName, int flags) { if (!checkFlags(flags)) return false; if( fileName.isEmpty() ) { flags |= lfInteractive; PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importpdf"); QString wdir = prefs->get("wdir", "."); CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), tr("All Supported Formats")+" (*.pdf *.PDF);;All Files (*)"); if (diaf.exec()) { fileName = diaf.selectedFile(); prefs->set("wdir", fileName.left(fileName.lastIndexOf("/"))); } else return true; } m_Doc=ScCore->primaryMainWindow()->doc; UndoTransaction* activeTransaction = NULL; bool emptyDoc = (m_Doc == NULL); bool hasCurrentPage = (m_Doc && m_Doc->currentPage()); TransactionSettings trSettings; trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : ""; trSettings.targetPixmap = Um::IImageFrame; trSettings.actionName = Um::ImportXfig; trSettings.description = fileName; trSettings.actionPixmap = Um::IXFIG; if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(false); if (UndoManager::undoEnabled()) activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings)); bool isCleanedFile = false; QString cleanFile = ""; QFileInfo fi(fileName); QStringList exts = QStringList() << "eps" << "epsf" << "epsi" << "eps2" << "eps3" << "epi" << "ept" << "ps"; if (exts.contains(fi.suffix().toLower())) { if (ScCore->haveGS()) { // Destill the eps/ps with ghostscript to get a clean pdf file bool cancel = false; QString errFile = getShortPathName(ScPaths::getTempFileDir())+ "/ps.err"; cleanFile = getShortPathName(ScPaths::getTempFileDir())+ "/clean.pdf"; QStringList args; args.append( "-q" ); args.append( "-dNOPAUSE" ); args.append( "-sDEVICE=pdfwrite" ); args.append( "-dBATCH" ); args.append( "-dSAFER" ); if (extensionIndicatesEPS(fi.suffix().toLower())) args.append("-dEPSCrop"); args.append("-dCompatibilityLevel=1.4"); args.append( QString("-sOutputFile=%1").arg(QDir::toNativeSeparators(cleanFile)) ); args.append( QDir::toNativeSeparators(fileName) ); System(getShortPathName(PrefsManager::instance()->ghostscriptExecutable()), args, errFile, errFile, &cancel); args.clear(); isCleanedFile = true; } else { qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, tr("The Import plugin cannot handle Postscript files"), 1, 0, 0); qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); return false; } } PdfPlug *dia = new PdfPlug(m_Doc, flags); Q_CHECK_PTR(dia); if (isCleanedFile) dia->import(cleanFile, trSettings, flags); else dia->import(fileName, trSettings, flags); if (activeTransaction) { activeTransaction->commit(); delete activeTransaction; activeTransaction = NULL; } if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted)) UndoManager::instance()->setUndoEnabled(true); delete dia; if (isCleanedFile) QFile::remove(cleanFile); return true; }
void ShapePalette::Import() { PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); QString s = QFileDialog::getOpenFileName(this, tr("Choose a shape file to import"), dirs->get("shape_load", "."), tr("Photoshop Custom Shape (*.csh *.CSH)")); if (!s.isEmpty()) { QFileInfo fi(s); ShapeViewWidget = new ShapeView(this); int nIndex = Frame3->addItem(ShapeViewWidget, fi.baseName()); dirs->set("shape_load", s.left(s.lastIndexOf(QDir::toNativeSeparators("/")))); QFile file(s); if (!file.open(QFile::ReadOnly)) return; QApplication::setOverrideCursor(Qt::WaitCursor); QDataStream ds(&file); ds.setByteOrder(QDataStream::BigEndian); QByteArray magic; magic.resize(4); ds.readRawData(magic.data(), 4); if (magic != "cush") return; quint32 version, count, shpCounter; shpCounter = 1; ds >> version >> count; while (!ds.atEnd()) { QString string = ""; quint32 length, dummy, shpLen, paDataLen; ds >> length; for (uint i = 0; i < length; ++i) { quint16 ch; ds >> ch; if (ch > 0) string += char(ch); } if (length % 2 != 0) ds.skipRawData(2); ds >> dummy; ds >> shpLen; qint64 posi = ds.device()->pos(); ds.skipRawData(1); QByteArray uuid; uuid.resize(36); ds.readRawData(uuid.data(), 36); qint32 x, y, w, h; ds >> y >> x >> h >> w; paDataLen = shpLen - 53; QRect bounds = QRect(QPoint(x,y), QPoint(w, h)); bool first = false; bool pathOpen = false; FPoint firstPoint, firstControl; FPointArray clip2; short type; uint data; double frac1, frac2, frac3, frac4, frac5, frac6; uint offset2; offset2 = 0; clip2.resize(0); while (offset2 < paDataLen) { ds >> type; ds >> data; frac1 = decodePSDfloat(data) * bounds.height(); ds >> data; frac2 = decodePSDfloat(data) * bounds.width(); ds >> data; frac3 = decodePSDfloat(data) * bounds.height(); ds >> data; frac4 = decodePSDfloat(data) * bounds.width(); ds >> data; frac5 = decodePSDfloat(data) * bounds.height(); ds >> data; frac6 = decodePSDfloat(data) * bounds.width(); switch (type) { case 0: case 3: if (pathOpen) { clip2.addPoint(firstPoint); clip2.addPoint(firstControl); clip2.setMarker(); } pathOpen = false; first = true; break; case 1: case 2: case 4: case 5: if (first) { firstControl = FPoint(frac2, frac1); firstPoint = FPoint(frac4, frac3); clip2.addPoint(FPoint(frac4, frac3)); clip2.addPoint(FPoint(frac6, frac5)); } else { clip2.addPoint(frac4, frac3); clip2.addPoint(frac2, frac1); clip2.addPoint(frac4, frac3); clip2.addPoint(frac6, frac5); } pathOpen = true; first = false; break; case 6: first = true; break; default: break; } offset2 += 26; } clip2.addPoint(firstPoint); clip2.addPoint(firstControl); shapeData shData; shData.height = bounds.height(); shData.width = bounds.width(); shData.path = clip2.copy(); shData.name = string; ShapeViewWidget->m_Shapes.insert(QString(uuid), shData); ds.device()->seek(posi + shpLen); shpCounter++; } file.close(); Frame3->setCurrentIndex(nIndex); ShapeViewWidget->updateShapeList(); ShapeViewWidget->m_scMW = m_scMW; QApplication::restoreOverrideCursor(); }