From e5642b69764fc9ee663edca6590c1a402fccc45c Mon Sep 17 00:00:00 2001 From: morrolinux Date: Wed, 12 Dec 2018 23:49:10 +0100 Subject: [PATCH 1/9] getting the filter name for export --- src/control/jobs/BaseExportJob.cpp | 8 ++++++ src/control/jobs/BaseExportJob.h | 1 + src/control/jobs/PdfExportJob.cpp | 42 ++++++++++++++++++++++++++++++ src/control/jobs/PdfExportJob.h | 10 +++++++ 4 files changed, 61 insertions(+) diff --git a/src/control/jobs/BaseExportJob.cpp b/src/control/jobs/BaseExportJob.cpp index b937cc6e..b459b109 100644 --- a/src/control/jobs/BaseExportJob.cpp +++ b/src/control/jobs/BaseExportJob.cpp @@ -35,6 +35,14 @@ void BaseExportJob::addFileFilterToDialog(string name, string pattern) gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); } +string BaseExportJob::getFilterName() +{ + XOJ_CHECK_TYPE(BaseExportJob); + + GtkFileFilter* filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog)); + return gtk_file_filter_get_name(filter); +} + void BaseExportJob::prepareSavePath(path& path) { XOJ_CHECK_TYPE(BaseExportJob); diff --git a/src/control/jobs/BaseExportJob.h b/src/control/jobs/BaseExportJob.h index b5a8be31..42f45956 100644 --- a/src/control/jobs/BaseExportJob.h +++ b/src/control/jobs/BaseExportJob.h @@ -34,6 +34,7 @@ public: public: virtual bool showFilechooser(); + string getFilterName(); protected: void initDialog(); diff --git a/src/control/jobs/PdfExportJob.cpp b/src/control/jobs/PdfExportJob.cpp index a92fb944..39d13fa4 100644 --- a/src/control/jobs/PdfExportJob.cpp +++ b/src/control/jobs/PdfExportJob.cpp @@ -4,6 +4,7 @@ #include "pdf/base/XojPdfExportFactory.h" #include +#include PdfExportJob::PdfExportJob(Control* control) @@ -22,6 +23,7 @@ void PdfExportJob::addFilterToDialog() XOJ_CHECK_TYPE(PdfExportJob); addFileFilterToDialog(_C("PDF files"), "*.pdf"); + addFileFilterToDialog(_C("PDF Without paper style"), "*.pdf"); } void PdfExportJob::prepareSavePath(path& path) @@ -58,14 +60,52 @@ bool PdfExportJob::isUriValid(string& uri) return false; } + + std::cout<<"PdfExportJob::isUriValid\n"; + string filterName = BaseExportJob::getFilterName(); + std::cout<<"FilterName: "<getPageCount(); + + if (action == ACTION_RESET) + { + /** apply "plain" paper style to all pages before export */ + for (int i=0; igetPage(i)->getBackgroundType(); + doc->getPage(i)->setBackgroundType(PageType("plain")); + } + } + + if (action == ACTION_RESTORE) + { + /** restore each page to its original style */ + for (int i=0; igetPage(i)->setBackgroundType(pt[i]); + } + } + +} + void PdfExportJob::run() { XOJ_CHECK_TYPE(PdfExportJob); Document* doc = control->getDocument(); + + size_t count = doc->getPageCount(); + PageType pt[count]; + + resetBackgroundType(doc, pt, ACTION_RESET); + doc->lock(); XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); doc->unlock(); @@ -83,5 +123,7 @@ void PdfExportJob::run() } delete pdfe; + + resetBackgroundType(doc, pt, ACTION_RESTORE); } diff --git a/src/control/jobs/PdfExportJob.h b/src/control/jobs/PdfExportJob.h index ca3bfc05..ffc1fe23 100644 --- a/src/control/jobs/PdfExportJob.h +++ b/src/control/jobs/PdfExportJob.h @@ -13,6 +13,15 @@ #include "BaseExportJob.h" +class Document; +class PageType; + +enum ResetActionType +{ + ACTION_RESET = 0, + ACTION_RESTORE = 1 +}; + class PdfExportJob : public BaseExportJob { public: @@ -28,6 +37,7 @@ protected: virtual void addFilterToDialog(); virtual void prepareSavePath(path& path); virtual bool isUriValid(string& uri); + void resetBackgroundType(Document* doc, PageType* pt, ResetActionType action); private: XOJ_TYPE_ATTRIB; From 88928f656a6116bc9a426de486003e595e154809 Mon Sep 17 00:00:00 2001 From: morrolinux Date: Thu, 13 Dec 2018 07:52:10 +0100 Subject: [PATCH 2/9] moving custom export logic --- src/control/jobs/CustomExportJob.cpp | 16 +++++++++++++--- src/control/jobs/CustomExportJob.h | 8 ++++++++ src/control/jobs/PdfExportJob.cpp | 7 ------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/control/jobs/CustomExportJob.cpp b/src/control/jobs/CustomExportJob.cpp index 6010e9ed..549d3139 100644 --- a/src/control/jobs/CustomExportJob.cpp +++ b/src/control/jobs/CustomExportJob.cpp @@ -10,6 +10,7 @@ #include #include +#include CustomExportJob::CustomExportJob(Control* control) @@ -41,9 +42,11 @@ void CustomExportJob::addFilterToDialog() { XOJ_CHECK_TYPE(CustomExportJob); - addFileFilterToDialog(_C("PDF files"), "*.pdf"); - addFileFilterToDialog(_C("PNG graphics"), "*.png"); - addFileFilterToDialog(_C("Xournal (Compatibility)"), "*.xoj"); + addFileFilterToDialog(_C(EXPORT_PDF), "*.pdf"); + addFileFilterToDialog(_C(EXPORT_PDF_NOBG), "*.pdf"); + addFileFilterToDialog(_C(EXPORT_PNG), "*.png"); + addFileFilterToDialog(_C(EXPORT_PNG_NOBG), "*.png"); + addFileFilterToDialog(_C(EXPORT_XOJ), "*.xoj"); } bool CustomExportJob::isUriValid(string& uri) @@ -55,6 +58,13 @@ bool CustomExportJob::isUriValid(string& uri) return false; } + this->choosenFilterName = BaseExportJob::getFilterName(); + + if (this->choosenFilterName == EXPORT_PDF_NOBG) + { + std::cout<<"Exporting with plain bg \n"; + } + string ext = filename.extension().string(); if (ext != ".pdf" && ext != ".png" && ext != ".xoj") { diff --git a/src/control/jobs/CustomExportJob.h b/src/control/jobs/CustomExportJob.h index e04aca95..3fb238ec 100644 --- a/src/control/jobs/CustomExportJob.h +++ b/src/control/jobs/CustomExportJob.h @@ -17,6 +17,12 @@ #include +const string EXPORT_PDF = "PDF files"; +const string EXPORT_PDF_NOBG = "PDF with plain background"; +const string EXPORT_PNG = "PNG graphics"; +const string EXPORT_PNG_NOBG = "PNG with transparent background"; +const string EXPORT_XOJ = "Xournal (Compatibility)"; + class CustomExportJob : public BaseExportJob { public: @@ -71,4 +77,6 @@ private: bool exportTypeXoj; string lastError; + + string choosenFilterName; }; diff --git a/src/control/jobs/PdfExportJob.cpp b/src/control/jobs/PdfExportJob.cpp index 39d13fa4..f0f7b8c7 100644 --- a/src/control/jobs/PdfExportJob.cpp +++ b/src/control/jobs/PdfExportJob.cpp @@ -4,7 +4,6 @@ #include "pdf/base/XojPdfExportFactory.h" #include -#include PdfExportJob::PdfExportJob(Control* control) @@ -23,7 +22,6 @@ void PdfExportJob::addFilterToDialog() XOJ_CHECK_TYPE(PdfExportJob); addFileFilterToDialog(_C("PDF files"), "*.pdf"); - addFileFilterToDialog(_C("PDF Without paper style"), "*.pdf"); } void PdfExportJob::prepareSavePath(path& path) @@ -60,11 +58,6 @@ bool PdfExportJob::isUriValid(string& uri) return false; } - - std::cout<<"PdfExportJob::isUriValid\n"; - string filterName = BaseExportJob::getFilterName(); - std::cout<<"FilterName: "< Date: Thu, 13 Dec 2018 09:10:39 +0100 Subject: [PATCH 3/9] PDF export with plain background working --- src/control/jobs/CustomExportJob.cpp | 46 +++++++++++++++++++++++----- src/control/jobs/CustomExportJob.h | 10 ++++++ src/control/jobs/PdfExportJob.cpp | 32 ------------------- src/control/jobs/PdfExportJob.h | 10 ------ 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/control/jobs/CustomExportJob.cpp b/src/control/jobs/CustomExportJob.cpp index 549d3139..2531c546 100644 --- a/src/control/jobs/CustomExportJob.cpp +++ b/src/control/jobs/CustomExportJob.cpp @@ -60,11 +60,6 @@ bool CustomExportJob::isUriValid(string& uri) this->choosenFilterName = BaseExportJob::getFilterName(); - if (this->choosenFilterName == EXPORT_PDF_NOBG) - { - std::cout<<"Exporting with plain bg \n"; - } - string ext = filename.extension().string(); if (ext != ".pdf" && ext != ".png" && ext != ".xoj") { @@ -279,20 +274,25 @@ void CustomExportJob::run() // the ui is blocked, so there should be no changes... Document* doc = control->getDocument(); + size_t count = doc->getPageCount(); + PageType pt[count]; + resetBackgroundType(doc, pt, ACTION_RESET); + XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); - #ifdef ADVANCED_PDF_EXPORT_POPPLER // Not working with ADVANCED_PDF_EXPORT_POPPLER if (!pdfe->createPdf(this->filename)) #else - if (!pdfe->createPdf(this->filename, exportRange)) + if (!pdfe->createPdf(this->filename/*, exportRange*/)) //export range is called anyways #endif { this->errorMsg = pdfe->getLastError(); } delete pdfe; + + resetBackgroundType(doc, pt, ACTION_RESTORE); } else { @@ -300,6 +300,38 @@ void CustomExportJob::run() } } +void CustomExportJob::resetBackgroundType(Document* doc, PageType* pt, ResetActionType action) +{ + XOJ_CHECK_TYPE(CustomExportJob); + + if (this->choosenFilterName != EXPORT_PDF_NOBG) + { + return; + } + + size_t count = doc->getPageCount(); + + if (action == ACTION_RESET) + { + /** apply "plain" paper style to all pages before export */ + for (int i=0; igetPage(i)->getBackgroundType(); + doc->getPage(i)->setBackgroundType(PageType("plain")); + } + } + + if (action == ACTION_RESTORE) + { + /** restore each page to its original style */ + for (int i=0; igetPage(i)->setBackgroundType(pt[i]); + } + } + +} + void CustomExportJob::afterRun() { XOJ_CHECK_TYPE(CustomExportJob); diff --git a/src/control/jobs/CustomExportJob.h b/src/control/jobs/CustomExportJob.h index 3fb238ec..bab15251 100644 --- a/src/control/jobs/CustomExportJob.h +++ b/src/control/jobs/CustomExportJob.h @@ -17,12 +17,21 @@ #include +class Document; +class PageType; + const string EXPORT_PDF = "PDF files"; const string EXPORT_PDF_NOBG = "PDF with plain background"; const string EXPORT_PNG = "PNG graphics"; const string EXPORT_PNG_NOBG = "PNG with transparent background"; const string EXPORT_XOJ = "Xournal (Compatibility)"; +enum ResetActionType +{ + ACTION_RESET = 0, + ACTION_RESTORE = 1 +}; + class CustomExportJob : public BaseExportJob { public: @@ -56,6 +65,7 @@ protected: bool freeSurface(int id); string getFilenameWithNumber(int no); virtual bool isUriValid(string& uri); + void resetBackgroundType(Document* doc, PageType* pt, ResetActionType action); private: XOJ_TYPE_ATTRIB; diff --git a/src/control/jobs/PdfExportJob.cpp b/src/control/jobs/PdfExportJob.cpp index f0f7b8c7..a23e5cdf 100644 --- a/src/control/jobs/PdfExportJob.cpp +++ b/src/control/jobs/PdfExportJob.cpp @@ -61,32 +61,7 @@ bool PdfExportJob::isUriValid(string& uri) return true; } -void PdfExportJob::resetBackgroundType(Document* doc, PageType* pt, ResetActionType action) -{ - XOJ_CHECK_TYPE(PdfExportJob); - - size_t count = doc->getPageCount(); - - if (action == ACTION_RESET) - { - /** apply "plain" paper style to all pages before export */ - for (int i=0; igetPage(i)->getBackgroundType(); - doc->getPage(i)->setBackgroundType(PageType("plain")); - } - } - if (action == ACTION_RESTORE) - { - /** restore each page to its original style */ - for (int i=0; igetPage(i)->setBackgroundType(pt[i]); - } - } - -} void PdfExportJob::run() { @@ -94,11 +69,6 @@ void PdfExportJob::run() Document* doc = control->getDocument(); - size_t count = doc->getPageCount(); - PageType pt[count]; - - resetBackgroundType(doc, pt, ACTION_RESET); - doc->lock(); XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); doc->unlock(); @@ -116,7 +86,5 @@ void PdfExportJob::run() } delete pdfe; - - resetBackgroundType(doc, pt, ACTION_RESTORE); } diff --git a/src/control/jobs/PdfExportJob.h b/src/control/jobs/PdfExportJob.h index ffc1fe23..ca3bfc05 100644 --- a/src/control/jobs/PdfExportJob.h +++ b/src/control/jobs/PdfExportJob.h @@ -13,15 +13,6 @@ #include "BaseExportJob.h" -class Document; -class PageType; - -enum ResetActionType -{ - ACTION_RESET = 0, - ACTION_RESTORE = 1 -}; - class PdfExportJob : public BaseExportJob { public: @@ -37,7 +28,6 @@ protected: virtual void addFilterToDialog(); virtual void prepareSavePath(path& path); virtual bool isUriValid(string& uri); - void resetBackgroundType(Document* doc, PageType* pt, ResetActionType action); private: XOJ_TYPE_ATTRIB; From 89d3b0617203490e2b0ce28aa636c7b31548d63a Mon Sep 17 00:00:00 2001 From: morro Date: Thu, 13 Dec 2018 10:40:53 +0100 Subject: [PATCH 4/9] modularity --- src/control/jobs/CustomExportJob.cpp | 29 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/control/jobs/CustomExportJob.cpp b/src/control/jobs/CustomExportJob.cpp index 2531c546..9fb1cfb4 100644 --- a/src/control/jobs/CustomExportJob.cpp +++ b/src/control/jobs/CustomExportJob.cpp @@ -274,9 +274,13 @@ void CustomExportJob::run() // the ui is blocked, so there should be no changes... Document* doc = control->getDocument(); - size_t count = doc->getPageCount(); - PageType pt[count]; - resetBackgroundType(doc, pt, ACTION_RESET); + PageType pt[doc->getPageCount()]; + + if (this->choosenFilterName == EXPORT_PDF_NOBG) + { + pt[0] = PageType("plain"); + resetBackgroundType(doc, pt, ACTION_RESET); + } XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); @@ -292,7 +296,11 @@ void CustomExportJob::run() delete pdfe; - resetBackgroundType(doc, pt, ACTION_RESTORE); + if (this->choosenFilterName == EXPORT_PDF_NOBG) + { + resetBackgroundType(doc, pt, ACTION_RESTORE); + } + } else { @@ -304,20 +312,19 @@ void CustomExportJob::resetBackgroundType(Document* doc, PageType* pt, ResetActi { XOJ_CHECK_TYPE(CustomExportJob); - if (this->choosenFilterName != EXPORT_PDF_NOBG) - { - return; - } - size_t count = doc->getPageCount(); if (action == ACTION_RESET) { - /** apply "plain" paper style to all pages before export */ + /** + * backup the current and apply the passed + * paper style to all pages before export + */ + PageType tmp = pt[0]; for (int i=0; igetPage(i)->getBackgroundType(); - doc->getPage(i)->setBackgroundType(PageType("plain")); + doc->getPage(i)->setBackgroundType(tmp); } } From 093e3834fa2d18dcc1e3a7a4b35f883ff7d5912f Mon Sep 17 00:00:00 2001 From: morro Date: Thu, 13 Dec 2018 11:24:46 +0100 Subject: [PATCH 5/9] PNG export with transparent background --- src/control/jobs/CustomExportJob.cpp | 16 +++++++- src/control/jobs/CustomExportJob.h | 2 +- src/util/XournalTypeList.h | 2 +- src/view/background/MainBackgroundPainter.cpp | 2 + .../TransparentBackgroundPainter.cpp | 39 +++++++++++++++++++ .../background/TransparentBackgroundPainter.h | 35 +++++++++++++++++ 6 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/view/background/TransparentBackgroundPainter.cpp create mode 100644 src/view/background/TransparentBackgroundPainter.h diff --git a/src/control/jobs/CustomExportJob.cpp b/src/control/jobs/CustomExportJob.cpp index 9fb1cfb4..c3e1e8f1 100644 --- a/src/control/jobs/CustomExportJob.cpp +++ b/src/control/jobs/CustomExportJob.cpp @@ -206,6 +206,13 @@ void CustomExportJob::exportPng() Document* doc = control->getDocument(); int count = doc->getPageCount(); + PageType pt[count]; + + if (this->choosenFilterName == EXPORT_PNG_NOBG) + { + pt[0] = PageType("transparent"); + resetBackgroundType(doc, pt, ACTION_SET); + } bool onePage = ((this->exportRange.size() == 1) && (this->exportRange[0]->getFirst() == this->exportRange[0]->getLast())); @@ -244,6 +251,11 @@ void CustomExportJob::exportPng() exportPngPage(i, id, zoom, view); } } + + if (this->choosenFilterName == EXPORT_PNG_NOBG) + { + resetBackgroundType(doc, pt, ACTION_RESTORE); + } } void CustomExportJob::run() @@ -279,7 +291,7 @@ void CustomExportJob::run() if (this->choosenFilterName == EXPORT_PDF_NOBG) { pt[0] = PageType("plain"); - resetBackgroundType(doc, pt, ACTION_RESET); + resetBackgroundType(doc, pt, ACTION_SET); } XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); @@ -314,7 +326,7 @@ void CustomExportJob::resetBackgroundType(Document* doc, PageType* pt, ResetActi size_t count = doc->getPageCount(); - if (action == ACTION_RESET) + if (action == ACTION_SET) { /** * backup the current and apply the passed diff --git a/src/control/jobs/CustomExportJob.h b/src/control/jobs/CustomExportJob.h index bab15251..46e2cfef 100644 --- a/src/control/jobs/CustomExportJob.h +++ b/src/control/jobs/CustomExportJob.h @@ -28,7 +28,7 @@ const string EXPORT_XOJ = "Xournal (Compatibility)"; enum ResetActionType { - ACTION_RESET = 0, + ACTION_SET = 0, ACTION_RESTORE = 1 }; diff --git a/src/util/XournalTypeList.h b/src/util/XournalTypeList.h index f43f799a..f1901918 100644 --- a/src/util/XournalTypeList.h +++ b/src/util/XournalTypeList.h @@ -257,6 +257,6 @@ XOJ_DECLARE_TYPE(PopplerGlibPage, 245); XOJ_DECLARE_TYPE(PopplerGlibPageBookmarkIterator, 246); XOJ_DECLARE_TYPE(PopplerGlibAction, 247); XOJ_DECLARE_TYPE(XojCairoPdfExport, 248); - +XOJ_DECLARE_TYPE(TransparentBackgroundPainter, 249); diff --git a/src/view/background/MainBackgroundPainter.cpp b/src/view/background/MainBackgroundPainter.cpp index e4d604b9..3f523bb8 100644 --- a/src/view/background/MainBackgroundPainter.cpp +++ b/src/view/background/MainBackgroundPainter.cpp @@ -5,6 +5,7 @@ #include "DottedBackgroundPainter.h" #include "GraphBackgroundPainter.h" #include "LineBackgroundPainter.h" +#include "TransparentBackgroundPainter.h" #include using std::vector; @@ -20,6 +21,7 @@ MainBackgroundPainter::MainBackgroundPainter() painter["ruled"] = new LineBackgroundPainter(true); painter["graph"] = new GraphBackgroundPainter(); painter["dotted"] = new DottedBackgroundPainter(); + painter["transparent"] = new TransparentBackgroundPainter(); } MainBackgroundPainter::~MainBackgroundPainter() diff --git a/src/view/background/TransparentBackgroundPainter.cpp b/src/view/background/TransparentBackgroundPainter.cpp new file mode 100644 index 00000000..db0204b4 --- /dev/null +++ b/src/view/background/TransparentBackgroundPainter.cpp @@ -0,0 +1,39 @@ +#include "TransparentBackgroundPainter.h" + +#include + +TransparentBackgroundPainter::TransparentBackgroundPainter() +{ + XOJ_INIT_TYPE(TransparentBackgroundPainter); + +} + +TransparentBackgroundPainter::~TransparentBackgroundPainter() +{ + XOJ_CHECK_TYPE(TransparentBackgroundPainter); + + XOJ_RELEASE_TYPE(TransparentBackgroundPainter); +} + +void TransparentBackgroundPainter::resetConfig() +{ + XOJ_CHECK_TYPE(TransparentBackgroundPainter); + + this->foregroundColor1 = 0xBDBDBD; + this->lineWidth = 1.5; + this->drawRaster1 = 14.17; +} + +void TransparentBackgroundPainter::paint() +{ + XOJ_CHECK_TYPE(TransparentBackgroundPainter); + + //paintBackgroundColor(); + //paintBackgroundDotted(); +} + +void TransparentBackgroundPainter::paintBackgroundTransparent() +{ + XOJ_CHECK_TYPE(TransparentBackgroundPainter); + +} diff --git a/src/view/background/TransparentBackgroundPainter.h b/src/view/background/TransparentBackgroundPainter.h new file mode 100644 index 00000000..85c12730 --- /dev/null +++ b/src/view/background/TransparentBackgroundPainter.h @@ -0,0 +1,35 @@ +/* + * Xournal++ + * + * Draws transparent background + * + * @author Xournal++ Team + * https://github.com/xournalpp/xournalpp + * + * @license GNU GPLv2 or later + */ + +#pragma once + +#include "BaseBackgroundPainter.h" + +#include + +class TransparentBackgroundPainter : public BaseBackgroundPainter +{ +public: + TransparentBackgroundPainter(); + virtual ~TransparentBackgroundPainter(); + +public: + virtual void paint(); + void paintBackgroundTransparent(); + + /** + * Reset all used configuration values + */ + virtual void resetConfig(); + +private: + XOJ_TYPE_ATTRIB; +}; From 5aa458d31e7b6da77a3924e996956ad76389e75f Mon Sep 17 00:00:00 2001 From: morrolinux Date: Thu, 13 Dec 2018 18:19:54 +0100 Subject: [PATCH 6/9] PDF export with plain background done right --- src/control/jobs/CustomExportJob.cpp | 57 ++----------------- src/control/jobs/CustomExportJob.h | 7 --- src/util/XournalTypeList.h | 1 - src/view/background/MainBackgroundPainter.cpp | 2 - .../TransparentBackgroundPainter.cpp | 39 ------------- .../background/TransparentBackgroundPainter.h | 35 ------------ 6 files changed, 5 insertions(+), 136 deletions(-) delete mode 100644 src/view/background/TransparentBackgroundPainter.cpp delete mode 100644 src/view/background/TransparentBackgroundPainter.h diff --git a/src/control/jobs/CustomExportJob.cpp b/src/control/jobs/CustomExportJob.cpp index c3e1e8f1..fa33182a 100644 --- a/src/control/jobs/CustomExportJob.cpp +++ b/src/control/jobs/CustomExportJob.cpp @@ -206,12 +206,10 @@ void CustomExportJob::exportPng() Document* doc = control->getDocument(); int count = doc->getPageCount(); - PageType pt[count]; if (this->choosenFilterName == EXPORT_PNG_NOBG) { - pt[0] = PageType("transparent"); - resetBackgroundType(doc, pt, ACTION_SET); + //Set no background here } bool onePage = ((this->exportRange.size() == 1) && (this->exportRange[0]->getFirst() == this->exportRange[0]->getLast())); @@ -251,11 +249,6 @@ void CustomExportJob::exportPng() exportPngPage(i, id, zoom, view); } } - - if (this->choosenFilterName == EXPORT_PNG_NOBG) - { - resetBackgroundType(doc, pt, ACTION_RESTORE); - } } void CustomExportJob::run() @@ -285,16 +278,13 @@ void CustomExportJob::run() // don't lock the page here for the whole flow, else we get a dead lock... // the ui is blocked, so there should be no changes... Document* doc = control->getDocument(); - - PageType pt[doc->getPageCount()]; - + + XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); + if (this->choosenFilterName == EXPORT_PDF_NOBG) { - pt[0] = PageType("plain"); - resetBackgroundType(doc, pt, ACTION_SET); + pdfe->setNoBackgroundExport(true); } - - XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); #ifdef ADVANCED_PDF_EXPORT_POPPLER // Not working with ADVANCED_PDF_EXPORT_POPPLER @@ -307,12 +297,6 @@ void CustomExportJob::run() } delete pdfe; - - if (this->choosenFilterName == EXPORT_PDF_NOBG) - { - resetBackgroundType(doc, pt, ACTION_RESTORE); - } - } else { @@ -320,37 +304,6 @@ void CustomExportJob::run() } } -void CustomExportJob::resetBackgroundType(Document* doc, PageType* pt, ResetActionType action) -{ - XOJ_CHECK_TYPE(CustomExportJob); - - size_t count = doc->getPageCount(); - - if (action == ACTION_SET) - { - /** - * backup the current and apply the passed - * paper style to all pages before export - */ - PageType tmp = pt[0]; - for (int i=0; igetPage(i)->getBackgroundType(); - doc->getPage(i)->setBackgroundType(tmp); - } - } - - if (action == ACTION_RESTORE) - { - /** restore each page to its original style */ - for (int i=0; igetPage(i)->setBackgroundType(pt[i]); - } - } - -} - void CustomExportJob::afterRun() { XOJ_CHECK_TYPE(CustomExportJob); diff --git a/src/control/jobs/CustomExportJob.h b/src/control/jobs/CustomExportJob.h index 46e2cfef..4ea52195 100644 --- a/src/control/jobs/CustomExportJob.h +++ b/src/control/jobs/CustomExportJob.h @@ -26,12 +26,6 @@ const string EXPORT_PNG = "PNG graphics"; const string EXPORT_PNG_NOBG = "PNG with transparent background"; const string EXPORT_XOJ = "Xournal (Compatibility)"; -enum ResetActionType -{ - ACTION_SET = 0, - ACTION_RESTORE = 1 -}; - class CustomExportJob : public BaseExportJob { public: @@ -65,7 +59,6 @@ protected: bool freeSurface(int id); string getFilenameWithNumber(int no); virtual bool isUriValid(string& uri); - void resetBackgroundType(Document* doc, PageType* pt, ResetActionType action); private: XOJ_TYPE_ATTRIB; diff --git a/src/util/XournalTypeList.h b/src/util/XournalTypeList.h index f1901918..a4dd1ac7 100644 --- a/src/util/XournalTypeList.h +++ b/src/util/XournalTypeList.h @@ -257,6 +257,5 @@ XOJ_DECLARE_TYPE(PopplerGlibPage, 245); XOJ_DECLARE_TYPE(PopplerGlibPageBookmarkIterator, 246); XOJ_DECLARE_TYPE(PopplerGlibAction, 247); XOJ_DECLARE_TYPE(XojCairoPdfExport, 248); -XOJ_DECLARE_TYPE(TransparentBackgroundPainter, 249); diff --git a/src/view/background/MainBackgroundPainter.cpp b/src/view/background/MainBackgroundPainter.cpp index 3f523bb8..e4d604b9 100644 --- a/src/view/background/MainBackgroundPainter.cpp +++ b/src/view/background/MainBackgroundPainter.cpp @@ -5,7 +5,6 @@ #include "DottedBackgroundPainter.h" #include "GraphBackgroundPainter.h" #include "LineBackgroundPainter.h" -#include "TransparentBackgroundPainter.h" #include using std::vector; @@ -21,7 +20,6 @@ MainBackgroundPainter::MainBackgroundPainter() painter["ruled"] = new LineBackgroundPainter(true); painter["graph"] = new GraphBackgroundPainter(); painter["dotted"] = new DottedBackgroundPainter(); - painter["transparent"] = new TransparentBackgroundPainter(); } MainBackgroundPainter::~MainBackgroundPainter() diff --git a/src/view/background/TransparentBackgroundPainter.cpp b/src/view/background/TransparentBackgroundPainter.cpp deleted file mode 100644 index db0204b4..00000000 --- a/src/view/background/TransparentBackgroundPainter.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "TransparentBackgroundPainter.h" - -#include - -TransparentBackgroundPainter::TransparentBackgroundPainter() -{ - XOJ_INIT_TYPE(TransparentBackgroundPainter); - -} - -TransparentBackgroundPainter::~TransparentBackgroundPainter() -{ - XOJ_CHECK_TYPE(TransparentBackgroundPainter); - - XOJ_RELEASE_TYPE(TransparentBackgroundPainter); -} - -void TransparentBackgroundPainter::resetConfig() -{ - XOJ_CHECK_TYPE(TransparentBackgroundPainter); - - this->foregroundColor1 = 0xBDBDBD; - this->lineWidth = 1.5; - this->drawRaster1 = 14.17; -} - -void TransparentBackgroundPainter::paint() -{ - XOJ_CHECK_TYPE(TransparentBackgroundPainter); - - //paintBackgroundColor(); - //paintBackgroundDotted(); -} - -void TransparentBackgroundPainter::paintBackgroundTransparent() -{ - XOJ_CHECK_TYPE(TransparentBackgroundPainter); - -} diff --git a/src/view/background/TransparentBackgroundPainter.h b/src/view/background/TransparentBackgroundPainter.h deleted file mode 100644 index 85c12730..00000000 --- a/src/view/background/TransparentBackgroundPainter.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Xournal++ - * - * Draws transparent background - * - * @author Xournal++ Team - * https://github.com/xournalpp/xournalpp - * - * @license GNU GPLv2 or later - */ - -#pragma once - -#include "BaseBackgroundPainter.h" - -#include - -class TransparentBackgroundPainter : public BaseBackgroundPainter -{ -public: - TransparentBackgroundPainter(); - virtual ~TransparentBackgroundPainter(); - -public: - virtual void paint(); - void paintBackgroundTransparent(); - - /** - * Reset all used configuration values - */ - virtual void resetConfig(); - -private: - XOJ_TYPE_ATTRIB; -}; From 87ee420a8c7899df0263d45a608e9caafeeac875 Mon Sep 17 00:00:00 2001 From: morrolinux Date: Thu, 13 Dec 2018 18:34:19 +0100 Subject: [PATCH 7/9] PNG export with transparent background --- .gitignore | 3 +++ src/control/jobs/CustomExportJob.cpp | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3767371d..593e3625 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .deps .dirstamp .libs +*.DS_Store *.o *.lo *.la @@ -48,3 +49,5 @@ cmake-build-release doc/html doc/latex +src/view/.DS_Store +src/view/background/.DS_Store diff --git a/src/control/jobs/CustomExportJob.cpp b/src/control/jobs/CustomExportJob.cpp index fa33182a..45bf0bc8 100644 --- a/src/control/jobs/CustomExportJob.cpp +++ b/src/control/jobs/CustomExportJob.cpp @@ -180,11 +180,18 @@ void CustomExportJob::exportPngPage(int pageId, int id, double zoom, DocumentVie { int pgNo = page->getPdfPageNr(); XojPdfPageSPtr popplerPage = doc->getPdfPage(pgNo); - + PdfView::drawPage(NULL, popplerPage, cr, zoom, page->getWidth(), page->getHeight()); } - view.drawPage(page, this->cr, true); + if (this->choosenFilterName == EXPORT_PNG_NOBG) + { + view.drawPage(page, this->cr, true, true); + } + else + { + view.drawPage(page, this->cr, true); + } if (!freeSurface(id)) { @@ -207,11 +214,6 @@ void CustomExportJob::exportPng() int count = doc->getPageCount(); - if (this->choosenFilterName == EXPORT_PNG_NOBG) - { - //Set no background here - } - bool onePage = ((this->exportRange.size() == 1) && (this->exportRange[0]->getFirst() == this->exportRange[0]->getLast())); char selectedPages[count]; From b709187ae6d8bf0c942926978bd6c39828ef619e Mon Sep 17 00:00:00 2001 From: morrolinux Date: Thu, 13 Dec 2018 19:34:06 +0100 Subject: [PATCH 8/9] fixed translation entries --- src/control/jobs/CustomExportJob.cpp | 12 ++++++------ src/control/jobs/CustomExportJob.h | 14 ++++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/control/jobs/CustomExportJob.cpp b/src/control/jobs/CustomExportJob.cpp index 45bf0bc8..fd153554 100644 --- a/src/control/jobs/CustomExportJob.cpp +++ b/src/control/jobs/CustomExportJob.cpp @@ -42,11 +42,11 @@ void CustomExportJob::addFilterToDialog() { XOJ_CHECK_TYPE(CustomExportJob); - addFileFilterToDialog(_C(EXPORT_PDF), "*.pdf"); - addFileFilterToDialog(_C(EXPORT_PDF_NOBG), "*.pdf"); - addFileFilterToDialog(_C(EXPORT_PNG), "*.png"); - addFileFilterToDialog(_C(EXPORT_PNG_NOBG), "*.png"); - addFileFilterToDialog(_C(EXPORT_XOJ), "*.xoj"); + addFileFilterToDialog(EXPORT_PDF, "*.pdf"); + addFileFilterToDialog(EXPORT_PDF_NOBG, "*.pdf"); + addFileFilterToDialog(EXPORT_PNG, "*.png"); + addFileFilterToDialog(EXPORT_PNG_NOBG, "*.png"); + addFileFilterToDialog(EXPORT_XOJ, "*.xoj"); } bool CustomExportJob::isUriValid(string& uri) @@ -292,7 +292,7 @@ void CustomExportJob::run() // Not working with ADVANCED_PDF_EXPORT_POPPLER if (!pdfe->createPdf(this->filename)) #else - if (!pdfe->createPdf(this->filename/*, exportRange*/)) //export range is called anyways + if (!pdfe->createPdf(this->filename, exportRange)) #endif { this->errorMsg = pdfe->getLastError(); diff --git a/src/control/jobs/CustomExportJob.h b/src/control/jobs/CustomExportJob.h index 4ea52195..2343aeaa 100644 --- a/src/control/jobs/CustomExportJob.h +++ b/src/control/jobs/CustomExportJob.h @@ -16,15 +16,13 @@ #include "view/DocumentView.h" #include +#include -class Document; -class PageType; - -const string EXPORT_PDF = "PDF files"; -const string EXPORT_PDF_NOBG = "PDF with plain background"; -const string EXPORT_PNG = "PNG graphics"; -const string EXPORT_PNG_NOBG = "PNG with transparent background"; -const string EXPORT_XOJ = "Xournal (Compatibility)"; +const string EXPORT_PDF = _C("PDF files"); +const string EXPORT_PDF_NOBG = _C("PDF with plain background"); +const string EXPORT_PNG = _C("PNG graphics"); +const string EXPORT_PNG_NOBG = _C("PNG with transparent background"); +const string EXPORT_XOJ = _C("Xournal (Compatibility)"); class CustomExportJob : public BaseExportJob { From cfee96a3355433338e8afb618a6c5ea1f7b56abd Mon Sep 17 00:00:00 2001 From: morrolinux Date: Thu, 13 Dec 2018 20:00:26 +0100 Subject: [PATCH 9/9] typos and stuff --- src/control/jobs/CustomExportJob.cpp | 12 +++++------- src/control/jobs/CustomExportJob.h | 2 +- src/control/jobs/PdfExportJob.cpp | 3 +-- src/pdf/base/XojCairoPdfExport.cpp | 3 +-- src/pdf/popplerdirect/PdfExport.cpp | 3 +-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/control/jobs/CustomExportJob.cpp b/src/control/jobs/CustomExportJob.cpp index fd153554..6714b4d1 100644 --- a/src/control/jobs/CustomExportJob.cpp +++ b/src/control/jobs/CustomExportJob.cpp @@ -10,8 +10,6 @@ #include #include -#include - CustomExportJob::CustomExportJob(Control* control) : BaseExportJob(control, _("Custom Export")), @@ -58,7 +56,7 @@ bool CustomExportJob::isUriValid(string& uri) return false; } - this->choosenFilterName = BaseExportJob::getFilterName(); + this->chosenFilterName = BaseExportJob::getFilterName(); string ext = filename.extension().string(); if (ext != ".pdf" && ext != ".png" && ext != ".xoj") @@ -180,11 +178,11 @@ void CustomExportJob::exportPngPage(int pageId, int id, double zoom, DocumentVie { int pgNo = page->getPdfPageNr(); XojPdfPageSPtr popplerPage = doc->getPdfPage(pgNo); - + PdfView::drawPage(NULL, popplerPage, cr, zoom, page->getWidth(), page->getHeight()); } - if (this->choosenFilterName == EXPORT_PNG_NOBG) + if (this->chosenFilterName == EXPORT_PNG_NOBG) { view.drawPage(page, this->cr, true, true); } @@ -280,10 +278,10 @@ void CustomExportJob::run() // don't lock the page here for the whole flow, else we get a dead lock... // the ui is blocked, so there should be no changes... Document* doc = control->getDocument(); - + XojPdfExport* pdfe = XojPdfExportFactory::createExport(doc, control); - if (this->choosenFilterName == EXPORT_PDF_NOBG) + if (this->chosenFilterName == EXPORT_PDF_NOBG) { pdfe->setNoBackgroundExport(true); } diff --git a/src/control/jobs/CustomExportJob.h b/src/control/jobs/CustomExportJob.h index 2343aeaa..21d16122 100644 --- a/src/control/jobs/CustomExportJob.h +++ b/src/control/jobs/CustomExportJob.h @@ -79,5 +79,5 @@ private: string lastError; - string choosenFilterName; + string chosenFilterName; }; diff --git a/src/control/jobs/PdfExportJob.cpp b/src/control/jobs/PdfExportJob.cpp index a23e5cdf..841086d9 100644 --- a/src/control/jobs/PdfExportJob.cpp +++ b/src/control/jobs/PdfExportJob.cpp @@ -57,12 +57,11 @@ bool PdfExportJob::isUriValid(string& uri) Util::showErrorToUser(control->getGtkWindow(), msg); return false; } - + return true; } - void PdfExportJob::run() { XOJ_CHECK_TYPE(PdfExportJob); diff --git a/src/pdf/base/XojCairoPdfExport.cpp b/src/pdf/base/XojCairoPdfExport.cpp index 87f59642..5a68d4ed 100644 --- a/src/pdf/base/XojCairoPdfExport.cpp +++ b/src/pdf/base/XojCairoPdfExport.cpp @@ -118,8 +118,7 @@ bool XojCairoPdfExport::createPdf(path file, PageRangeVector& range) { for (int i = e->getFirst(); i <= e->getLast(); i++) { - int p = i - 1; - if (p < 0 || p >= (int)doc->getPageCount()) + if (i < 0 || i > (int)doc->getPageCount()) { continue; } diff --git a/src/pdf/popplerdirect/PdfExport.cpp b/src/pdf/popplerdirect/PdfExport.cpp index 1483d08a..ad313dea 100644 --- a/src/pdf/popplerdirect/PdfExport.cpp +++ b/src/pdf/popplerdirect/PdfExport.cpp @@ -669,8 +669,7 @@ bool PdfExport::createPdf(path file, PageRangeVector& range) { for (int i = e->getFirst(); i <= e->getLast(); i++) { - int p = i - 1; - if (p < 0 || p >= doc->getPageCount()) + if (i < 0 || i > doc->getPageCount()) { continue; }