util.cpp File Reference
#include <QBitmap>#include <QByteArray>#include <QCheckBox>#include <QDomElement>#include <QFile>#include <QFileInfo>#include <QImageReader>#include <QList>#include <QPixmap>#include <QWidget>#include <QDir>#include <QCryptographicHash>#include <cmath>#include <algorithm>#include "util.h"#include "scpainter.h"#include "scconfig.h"#include "pageitem_textframe.h"#include "commonstrings.h"#include "prefsmanager.h"#include <QProcess>#include "scmessagebox.h"#include "scpixmapcache.h"#include "scpaths.h"#include <jpeglib.h>#include <jerror.h>#include "pageitem.h"#include "scribus.h"#include "scribusdoc.h"#include "scribusview.h"#include <zlib.h>

Go to the source code of this file.
Defines | |
| #define | XMD_H |
Functions | |
| void | sDebug (QString message) |
| int | System (const QString exename, const QStringList &args, const QString fileStdErr, const QString fileStdOut) |
| Synchronously execute a new process, optionally saving its output. | |
| QString | getShortPathName (QString longPath) |
| On Windows, return short path name, else return longPath;. | |
| int | copyFile (QString source, QString target) |
| int | moveFile (QString source, QString target) |
| QString | GetAttr (QDomElement *el, QString at, QString def) |
| bool | loadText (QString filename, QString *Buffer) |
| WARNING: loadText is INCORRECT - use loadRawText instead! | |
| bool | loadRawText (const QString &filename, QByteArray &buf) |
| Replacement version of loadText that returns a QCString as an out parameter. The QCString is filled with the contents of the specified file. The return byte string is of unknown encoding; the caller must handle encoding issues. There is no need to preallocate the buffer, and the new data replaces any old contents. | |
| bool | loadRawBytes (const QString &filename, QByteArray &buf) |
| QString | CompressStr (QString *in) |
| QByteArray | CompressArray (const QByteArray &in) |
| char * | toAscii85 (quint32 value, bool &allZero) |
| char * | toHex (uchar u) |
| QString | String2Hex (QString *in, bool lang) |
| QByteArray | ComputeMD5Sum (QByteArray *in) |
| QString | Path2Relative (QString Path, const QString &baseDir) |
| QString | Relative2Path (QString File, const QString &baseDir) |
| bool | overwrite (QWidget *parent, QString filename) |
| void | WordAndPara (PageItem *currItem, int *w, int *p, int *c, int *wN, int *pN, int *cN) |
| void | ReOrderText (ScribusDoc *currentDoc, ScribusView *view) |
| bool | compareQStrings (QString s1, QString s2) |
| Helper function for sorting in sortQStringList. | |
| QStringList | sortQStringList (QStringList aList) |
| Returns a sorted list of QStrings - sorted by locale specific rules! Uses compareQStrings() as rule. There is STL used! | |
| QString | checkFileExtension (const QString &currName, const QString &extension) |
| A quick function to make sure a filename has the correct extension and add it if not. | |
| QString | getFileNameByPage (ScribusDoc *currDoc, uint pageNo, QString extension) |
| Creates a common name for page exports (SVG, bitmap, EPS). Output format is: documentname-page01.extension. | |
| const QString | getStringFromSequence (DocumentSectionType type, uint position) |
| const QString | numberToLetterSequence (uint i) |
| const QString | arabicToRoman (uint i) |
| void | parsePagesString (QString pages, std::vector< int > *pageNs, int sourcePageCount) |
| int | findParagraphStyle (ScribusDoc *doc, const ParagraphStyle &parStyle) |
| int | findParagraphStyle (ScribusDoc *doc, const QString &name) |
| void | tDebug (QString message) |
| performance measurements. It prints given message with it current timestamp. Useful for duration holes finding. | |
| QString | readLinefromDataStream (QDataStream &s) |
| void | setCurrentComboItem (QComboBox *box, QString text) |
| QString | getDashString (int dashtype, double linewidth) |
| void | getDashArray (int dashtype, double linewidth, QList< double > &m_array) |
Define Documentation
Function Documentation
| const QString arabicToRoman | ( | uint | i | ) |
| QString checkFileExtension | ( | const QString & | currName, | |
| const QString & | extension | |||
| ) |
A quick function to make sure a filename has the correct extension and add it if not.
- Parameters:
-
currName Current filename extension File extension to ensure exists
Definition at line 554 of file util.cpp.
Referenced by PDFExportDialog::fileNameChanged().
| bool compareQStrings | ( | QString | s1, | |
| QString | s2 | |||
| ) |
Helper function for sorting in sortQStringList.
- Parameters:
-
s1 first string s2 second string
- Return values:
-
bool t/f related s1>s2
Definition at line 534 of file util.cpp.
Referenced by sortQStringList().
| QByteArray CompressArray | ( | const QByteArray & | in | ) |
Definition at line 303 of file util.cpp.
References uLong().
Referenced by PDFLibCore::PDF_Begin_Doc(), PDFLibCore::PDF_Begin_Page(), PDFLibCore::PDF_End_Doc(), and PDFLibCore::PDF_Image().
| QString CompressStr | ( | QString * | in | ) |
Definition at line 262 of file util.cpp.
References uLong().
Referenced by PDFLibCore::PDF_Begin_Doc(), PDFLibCore::PDF_DoLinGradient(), PDFLibCore::PDF_Gradient(), PDFLibCore::PDF_ProcessPage(), PDFLibCore::PDF_TemplatePage(), PDFLibCore::Write_TransparencyGroup(), and PDFLibCore::WritePDFStream().
| QByteArray ComputeMD5Sum | ( | QByteArray * | in | ) |
Definition at line 372 of file util.cpp.
Referenced by PDFLibCore::CalcOwnerKey(), PDFLibCore::CalcUserKey(), PDFLibCore::ComputeMD5(), PDFLibCore::EncodeArrayToStream(), PDFLibCore::EncStream(), PDFLibCore::EncStreamArray(), PDFLibCore::EncString(), and PDFLibCore::EncStringUTF16().
| int copyFile | ( | QString | source, | |
| QString | target | |||
| ) |
Definition at line 131 of file util.cpp.
Referenced by BibView::checkAndChange(), CollectForOutput::collectFile(), CollectForOutput::collectFonts(), CollectForOutput::collectProfiles(), Biblio::copyObj(), PrefsManager::copyOldPreferences(), and moveFile().
| int findParagraphStyle | ( | ScribusDoc * | doc, | |
| const QString & | name | |||
| ) |
Definition at line 818 of file util.cpp.
References StyleSet< STYLE >::count(), and ScribusDoc::paragraphStyles().
| int findParagraphStyle | ( | ScribusDoc * | doc, | |
| const ParagraphStyle & | parStyle | |||
| ) |
Definition at line 798 of file util.cpp.
References StyleSet< STYLE >::count(), Style::name(), and ScribusDoc::paragraphStyles().
Referenced by SearchReplace::clear(), SearchReplace::readPrefs(), SearchReplace::SearchReplace(), and Scribus13Format::WriteObjects().
| QString GetAttr | ( | QDomElement * | el, | |
| QString | at, | |||
| QString | def | |||
| ) |
Definition at line 175 of file util.cpp.
Referenced by ScPreview::createPreview(), and BibView::ReadOldContents().
| void getDashArray | ( | int | dashtype, | |
| double | linewidth, | |||
| QList< double > & | m_array | |||
| ) |
Definition at line 994 of file util.cpp.
References getDashString().
Referenced by LineCombo::createIcon(), ScPainter::drawVPath(), PropertiesPalette::NewLSty(), LineFormatItemDelegate::redraw(), PathStrokerPlugin::run(), ScPainterEx_GDIPlus::setPen(), ScPainterEx_GDI::setPen(), ScPainter::setPen(), and SMLineStyle::updatePreview().
| QString getDashString | ( | int | dashtype, | |
| double | linewidth | |||
| ) |
Definition at line 869 of file util.cpp.
Referenced by getDashArray(), SVGExPlug::GetMultiStroke(), PDFLibCore::PDF_ProcessItem(), PDFLibCore::PDF_ProcessTableItem(), PDFLibCore::PDF_TemplatePage(), SVGExPlug::ProcessPage(), and PSLib::PS_setdash().
| QString getFileNameByPage | ( | ScribusDoc * | currDoc, | |
| uint | pageNo, | |||
| QString | extension | |||
| ) |
Creates a common name for page exports (SVG, bitmap, EPS). Output format is: documentname-page01.extension.
- Parameters:
-
pageNo number of the exported page (begins from 1) extension "svg" or e.g. "png" etc.
- Return values:
-
QString standardized filename
Definition at line 570 of file util.cpp.
References ScribusDoc::DocName, ScribusDoc::FirstPnum, and tr().
Referenced by ExportBitmap::getFileName(), and SVGExportPlugin::run().
| QString getShortPathName | ( | QString | longPath | ) |
On Windows, return short path name, else return longPath;.
Definition at line 112 of file util.cpp.
Referenced by callGS(), EPSPlug::convert(), convertPS2PS(), AIPlug::decompressAIData(), getGSVersion(), EPSPlug::Image(), AIPlug::import(), PPreview::RenderPreview(), PPreview::RenderPreviewSep(), testGSAvailability(), and testGSDeviceAvailability().
| const QString getStringFromSequence | ( | DocumentSectionType | type, | |
| uint | position | |||
| ) |
Definition at line 584 of file util.cpp.
References arabicToRoman(), numberToLetterSequence(), Type_1_2_3, Type_a_b_c, Type_A_B_C, Type_i_ii_iii, Type_I_II_III, and Type_None.
Referenced by ScribusDoc::getSectionPageNumberForPageIndex().
| bool loadRawBytes | ( | const QString & | filename, | |
| QByteArray & | buf | |||
| ) |
Definition at line 240 of file util.cpp.
Referenced by PDFLibCore::PDF_Begin_Doc(), PDFLibCore::PDF_End_Doc(), and PDFLibCore::PDF_Image().
| bool loadRawText | ( | const QString & | filename, | |
| QByteArray & | buf | |||
| ) |
Replacement version of loadText that returns a QCString as an out parameter. The QCString is filled with the contents of the specified file. The return byte string is of unknown encoding; the caller must handle encoding issues. There is no need to preallocate the buffer, and the new data replaces any old contents.
| bool loadText | ( | QString | filename, | |
| QString * | Buffer | |||
| ) |
WARNING: loadText is INCORRECT - use loadRawText instead!
Definition at line 186 of file util.cpp.
Referenced by ScribusView::contentsDropEvent(), ScribusMainWindow::doPasteRecent(), FDialogPreview::GenPreview(), PrinterUtil::getPrinterNames(), OODPlug::import(), LegacyMode::importToPage(), SVGPlug::loadData(), and PatternDialog::loadVectors().
| int moveFile | ( | QString | source, | |
| QString | target | |||
| ) |
Definition at line 164 of file util.cpp.
References copyFile().
Referenced by AIPlug::decompressAIData(), ScPrintEngine_PS::print(), Printer_print(), PrefsManager::setupPreferencesLocation(), and ScribusWin::slotAutoSave().
| const QString numberToLetterSequence | ( | uint | i | ) |
| bool overwrite | ( | QWidget * | parent, | |
| QString | filename | |||
| ) |
Definition at line 411 of file util.cpp.
References tr().
Referenced by CollectForOutput::collectDocument(), PDFExportDialog::DoExport(), ScribusMainWindow::doPrint(), CurveWidget::doSave(), TabKeyboardShortcutsWidget::exportKeySet(), ScPrintEngine_GDI::print(), ScribusMainWindow::slotFileSaveAs(), and CharSelect::uniSaveButton_clicked().
| void parsePagesString | ( | QString | pages, | |
| std::vector< int > * | pageNs, | |||
| int | sourcePageCount | |||
| ) |
Definition at line 740 of file util.cpp.
Referenced by ScribusDoc::itemAddUserFrame(), PixmapExportPlugin::run(), ScribusMainWindow::slotPageImport(), and ScribusMainWindow::slotReallyPrint().
| QString Path2Relative | ( | QString | Path, | |
| const QString & | baseDir | |||
| ) |
Definition at line 380 of file util.cpp.
Referenced by PageItemXMLAttributes(), PDFLibCore::PDF_Annotation(), Annotation::saxx(), ScriXmlDoc::SetItemProps(), and Scribus134Format::SetItemProps().
| QString readLinefromDataStream | ( | QDataStream & | s | ) |
Definition at line 838 of file util.cpp.
Referenced by AIPlug::convert(), PrinterUtil::getPrinterNames(), EPSPlug::import(), ColorManager::importColors(), ScImgDataLoader_PS::loadEmbeddedProfile(), ScImgDataLoader_PS::loadPhotoshopBinary(), ScImgDataLoader_PS::parseData(), AIPlug::parseHeader(), PDFLibCore::PDF_Image(), AIPlug::processComment(), AIPlug::processPattern(), AIPlug::processRaster(), and ScImgDataLoader_PS::scanForFonts().
| QString Relative2Path | ( | QString | File, | |
| const QString & | baseDir | |||
| ) |
Definition at line 386 of file util.cpp.
Referenced by Scribus12Format::GetItemProps(), Scribus13Format::PasteItem(), and Scribus134Format::PasteItem().
| void ReOrderText | ( | ScribusDoc * | currentDoc, | |
| ScribusView * | view | |||
| ) |
Definition at line 502 of file util.cpp.
References PageItem::DrawObj(), ScribusDoc::Items, PageItem::itemType, PageItem::layout(), ScribusDoc::MasterItems, PageItem::PathText, ScribusDoc::RePos, ScribusView::scale(), and ScribusView::setScale().
Referenced by PDFfile_save(), and ScribusMainWindow::slotReallyPrint().
| void sDebug | ( | QString | message | ) |
Definition at line 87 of file util.cpp.
Referenced by SCFonts::AddScalableFont(), StoryEditor::buildGUI(), ScFace_ttf::EmbedFont(), FtFace::ftFace(), FtFace::FtFace(), ScribusCore::getCMSProfilesDir(), FtFace::glyphKerning(), FtFace::load(), FtFace::loadGlyph(), HelpBrowser::loadMenu(), ScFace_ttf::RawData(), FtFace::RawData(), ScrPopupMenu::repopulateLocalMenu(), and FPointArray::resize().
| void setCurrentComboItem | ( | QComboBox * | box, | |
| QString | text | |||
| ) |
Definition at line 860 of file util.cpp.
Referenced by AspellPluginImpl::AspellPluginImpl(), CheckDocument::buildErrorList(), SearchReplace::clear(), ColorManager::ColorManager(), Annot::DecodeNum(), TabCheckDoc::delProf(), ExportForm::ExportForm(), ExtImageProps::ExtImageProps(), FontComboH::familySelected(), FontReplaceDialog::FontReplaceDialog(), PageSelector::GotoPg(), TOCIndexPrefs::init(), InsPage::InsPage(), PageSelector::languageChange(), ColorManager::loadDefaults(), ScribusMainWindow::loadDoc(), Scribus12Format::loadFile(), MissingFont::MissingFont(), SearchReplace::readPrefs(), FontPrefs::rebuildDialog(), TabPDFOptions::restoreDefaults(), TabGeneral::restoreDefaults(), TabDocument::restoreDefaults(), TabCheckDoc::restoreDefaults(), HySettings::restoreDefaults(), ColorManager::saveDefaults(), tfDia::saveTextChanged(), SearchReplace::SearchReplace(), EffectsDialog::selectEffect(), TOCIndexPrefs::selectToC(), ExtImageProps::selLayer(), PrintDialog::SelPrinter(), FontComboH::setCurrentFont(), SMColorCombo::setCurrentText(), CharSelect::setDoc(), Tabruler::setFillChar(), SToolBFont::SetFont(), CharStyleComboBox::setFormat(), ParaStyleComboBox::setFormat(), ScribusView::setLayerMenuText(), PageSelector::setMaximum(), Tabruler::setTabFillChar(), TOCIndexPrefs::setupItemAttrs(), SMCStyleWidget::showLanguage(), SMLineStyleWidget::slotEditNewLine(), tfFilter::tfFilter(), and FontPrefs::UpdateFliste().
| QStringList sortQStringList | ( | QStringList | aList | ) |
Returns a sorted list of QStrings - sorted by locale specific rules! Uses compareQStrings() as rule. There is STL used!
- Parameters:
-
aList unsorted string list
- Return values:
-
QStringList sorted string list
Definition at line 541 of file util.cpp.
References compareQStrings().
Referenced by SMCStyleWidget::fillLangCombo(), and PropertiesPalette::fillLangCombo().
| QString String2Hex | ( | QString * | in, | |
| bool | lang | |||
| ) |
Definition at line 354 of file util.cpp.
References toHex().
Referenced by PDFLibCore::EncString(), PDFLibCore::EncStringUTF16(), PDFLibCore::PDF_Begin_Doc(), and PDFLibCore::PDF_End_Doc().
| int System | ( | const QString | exename, | |
| const QStringList & | args, | |||
| const QString | fileStdErr = "", |
|||
| const QString | fileStdOut = "" | |||
| ) |
Synchronously execute a new process, optionally saving its output.
Create a new process via QProcess and wait until finished. Return the process exit code. Exit code 1 is returned if the process could not be started or terminated abnormally.
Note that the argument list is handled exactly as documented by QProcess. In particular, no shell metacharacter expansion is performed (so you can't use $HOME for example, and no quoting is required or appropriate), and each list entry is one argument.
If output file paths are provided, any existing file will be truncated and overwritten.
- Parameters:
-
args Arguments, as per QProcess documentation. fileStdErr Path to save error output to, or "" to discard. fileStdOut Path to save normal output to, or "" to discard.
- Returns:
- Program exit code, or 1 on failure.
Definition at line 92 of file util.cpp.
Referenced by callGS(), EPSPlug::convert(), convertPS2PS(), EPSPlug::Image(), UrlLauncher::launchUrlExt(), PPreview::RenderPreview(), and PPreview::RenderPreviewSep().
| void tDebug | ( | QString | message | ) |
| char* toAscii85 | ( | quint32 | value, | |
| bool & | allZero | |||
| ) |
Definition at line 319 of file util.cpp.
Referenced by ScASCII85EncodeFilter::closeFilter(), ScPainterEx_Ps2::writeCMYKImageToStream_Ascii85(), ScASCII85EncodeFilter::writeData(), and ScPainterEx_Ps2::writeRGBImageToStream_Ascii85().
| char* toHex | ( | uchar | u | ) |
Definition at line 336 of file util.cpp.
Referenced by PDFLibCore::setTextCh(), String2Hex(), ScPainterEx_Ps2::writeCMYKImageToStream_AsciiHex(), ScPainterEx_Ps2::writeMaskToStream(), PDFLibCore::WritePDFString(), and ScPainterEx_Ps2::writeRGBImageToStream_AsciiHex().
| void WordAndPara | ( | PageItem * | currItem, | |
| int * | w, | |||
| int * | p, | |||
| int * | c, | |||
| int * | wN, | |||
| int * | pN, | |||
| int * | cN | |||
| ) |
Definition at line 427 of file util.cpp.
References PageItem::firstInFrame(), PageItem::frameOverflows(), PageItem::itemText, PageItem::lastInFrame(), StoryText::length(), PageItem::nextInChain(), SpecialChars::PARSEP, PageItem::prevInChain(), and StoryText::text().
Referenced by PageItem_TextFrame::createInfoGroup(), and PageItem_PathText::createInfoGroup().
