|
|
|
|
@ -21,12 +21,12 @@ CustomExportJob::CustomExportJob(Control* control) |
|
|
|
|
{ |
|
|
|
|
XOJ_INIT_TYPE(CustomExportJob); |
|
|
|
|
|
|
|
|
|
// Static vars are not translated, they are loaded before the translation is ready
|
|
|
|
|
EXPORT_PDF = _("PDF files"); |
|
|
|
|
EXPORT_PDF_NOBG = _("PDF with plain background"); |
|
|
|
|
EXPORT_PNG = _("PNG graphics"); |
|
|
|
|
EXPORT_PNG_NOBG = _("PNG with transparent background"); |
|
|
|
|
EXPORT_XOJ = _("Xournal (Compatibility)"); |
|
|
|
|
// Supported filters
|
|
|
|
|
filters[_("PDF files")] = new ExportType(".pdf", false);
|
|
|
|
|
filters[_("PDF with plain background")] = new ExportType(".pdf", true); |
|
|
|
|
filters[_("PNG graphics")] = new ExportType(".png", false); |
|
|
|
|
filters[_("PNG with transparent background")] = new ExportType(".png", true); |
|
|
|
|
filters[_("Xournal (Compatibility)")] = new ExportType(".xoj", false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CustomExportJob::~CustomExportJob() |
|
|
|
|
@ -39,6 +39,11 @@ CustomExportJob::~CustomExportJob() |
|
|
|
|
} |
|
|
|
|
exportRange.clear(); |
|
|
|
|
|
|
|
|
|
for(auto& filter : filters) |
|
|
|
|
{ |
|
|
|
|
delete filter.second; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XOJ_RELEASE_TYPE(CustomExportJob); |
|
|
|
|
} |
|
|
|
|
@ -47,11 +52,11 @@ void CustomExportJob::addFilterToDialog() |
|
|
|
|
{ |
|
|
|
|
XOJ_CHECK_TYPE(CustomExportJob); |
|
|
|
|
|
|
|
|
|
addFileFilterToDialog(EXPORT_PDF, "*.pdf"); |
|
|
|
|
addFileFilterToDialog(EXPORT_PDF_NOBG, "*.pdf"); |
|
|
|
|
addFileFilterToDialog(EXPORT_PNG, "*.png"); |
|
|
|
|
addFileFilterToDialog(EXPORT_PNG_NOBG, "*.png"); |
|
|
|
|
addFileFilterToDialog(EXPORT_XOJ, "*.xoj"); |
|
|
|
|
// Runs on every filter inside the filters map
|
|
|
|
|
for (auto& filter : filters) |
|
|
|
|
{ |
|
|
|
|
addFileFilterToDialog(filter.first, "*" + filter.second->extension); // Adds * for the pattern
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CustomExportJob::isUriValid(string& uri) |
|
|
|
|
@ -63,17 +68,14 @@ bool CustomExportJob::isUriValid(string& uri) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Extract the file filter selected
|
|
|
|
|
this->chosenFilterName = BaseExportJob::getFilterName(); |
|
|
|
|
|
|
|
|
|
// Remove any pre-existing extension and adds the chosen one
|
|
|
|
|
clearExtensions(filename); |
|
|
|
|
filename.replace_extension(filters[this->chosenFilterName]->extension); |
|
|
|
|
|
|
|
|
|
string ext = filename.extension().string(); |
|
|
|
|
if (ext != ".pdf" && ext != ".png" && ext != ".xoj") |
|
|
|
|
{ |
|
|
|
|
string msg = _("File name needs to end with .pdf, .png or .xoj"); |
|
|
|
|
Util::showErrorToUser(control->getGtkWindow(), msg); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
return checkOverwriteBackgroundPDF(filename); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CustomExportJob::showFilechooser() |
|
|
|
|
@ -189,14 +191,9 @@ void CustomExportJob::exportPngPage(int pageId, int id, double zoom, DocumentVie |
|
|
|
|
PdfView::drawPage(NULL, popplerPage, cr, zoom, page->getWidth(), page->getHeight()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this->chosenFilterName == EXPORT_PNG_NOBG) |
|
|
|
|
{ |
|
|
|
|
view.drawPage(page, this->cr, true, true); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
view.drawPage(page, this->cr, true); |
|
|
|
|
} |
|
|
|
|
bool hideBackground = filters[this->chosenFilterName]->withoutBackground; |
|
|
|
|
|
|
|
|
|
view.drawPage(page, this->cr, true, hideBackground); |
|
|
|
|
|
|
|
|
|
if (!freeSurface(id)) |
|
|
|
|
{ |
|
|
|
|
@ -287,12 +284,9 @@ void CustomExportJob::run() |
|
|
|
|
Document* doc = control->getDocument(); |
|
|
|
|
|
|
|
|
|
XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); |
|
|
|
|
|
|
|
|
|
if (this->chosenFilterName == EXPORT_PDF_NOBG) |
|
|
|
|
{ |
|
|
|
|
pdfe->setNoBackgroundExport(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pdfe->setNoBackgroundExport(filters[this->chosenFilterName]->withoutBackground); |
|
|
|
|
|
|
|
|
|
if (!pdfe->createPdf(this->filename, exportRange)) |
|
|
|
|
{ |
|
|
|
|
this->errorMsg = pdfe->getLastError(); |
|
|
|
|
|