diff options
| author | VinÃcius dos Santos Oliveira <vini.ipsmaker@gmail.com> | 2013-06-05 19:03:06 +0000 |
|---|---|---|
| committer | VinÃcius dos Santos Oliveira <vini.ipsmaker@gmail.com> | 2013-06-05 19:03:06 +0000 |
| commit | 4cec6d0c7d401ed0616e91a923a7ec4caf806f3d (patch) | |
| tree | 4737bd0075f714385a55b0f3d9339211baaecbf9 /src | |
| parent | Correct to compile against recent gtkmm, including updated macports versions.... (diff) | |
| download | inkscape-4cec6d0c7d401ed0616e91a923a7ec4caf806f3d.tar.gz inkscape-4cec6d0c7d401ed0616e91a923a7ec4caf806f3d.zip | |
Add command line option to specify PDF export version. Patch from schwieni.
From the patch's author:
Additional command line option added to export to different PDF-versions
supported by cairo (currently only "PDF 1.4" and "PDF 1.5"). The user must
provide the exact string found in the PDF-export dialog of Inkscape. This
feature was previously only accessible via the GUI of Inkscape. This option is
useful for people opting for PDF-a conformance in their PDFs. Moreover, the
Extension and Parameter classes are extended by setters for enum parameters
(used in combo boxes).
(bzr r12348)
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/extension.cpp | 22 | ||||
| -rw-r--r-- | src/extension/extension.h | 10 | ||||
| -rw-r--r-- | src/extension/param/enum.cpp | 18 | ||||
| -rw-r--r-- | src/extension/param/enum.h | 5 | ||||
| -rw-r--r-- | src/extension/param/parameter.cpp | 18 | ||||
| -rw-r--r-- | src/extension/param/parameter.h | 6 | ||||
| -rw-r--r-- | src/main.cpp | 36 |
7 files changed, 114 insertions, 1 deletions
diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 0d91c7491..2f78b5397 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -429,6 +429,21 @@ Extension::get_param_enum (const gchar * name, const SPDocument * doc, const Ink return param->get_enum(doc, node); } +/** + * This is useful to find out, if a given string \c value is selectable in a ComboBox named \cname. + * + * @param name The name of the enum parameter to get. + * @param doc The document to look in for document specific parameters. + * @param node The node to look in for a specific parameter. + * @return true if value exists, false if not + */ +bool +Extension::get_param_enum_contains(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node) +{ + Parameter * param = get_param(name); + return param->get_enum_contains(value, doc, node); +} + gchar const * Extension::get_param_optiongroup( gchar const * name, SPDocument const * doc, Inkscape::XML::Node const * node) { @@ -599,6 +614,13 @@ Extension::set_param_optiongroup(gchar const * name, gchar const * value, SPDocu return param->set_optiongroup(value, doc, node); } +gchar const * +Extension::set_param_enum(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node) +{ + Parameter * param = get_param(name); + return param->set_enum(value, doc, node); +} + /** \return The passed in value diff --git a/src/extension/extension.h b/src/extension/extension.h index b6b4c51ed..23ed818ba 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -244,6 +244,11 @@ public: SPDocument const * doc = 0, Inkscape::XML::Node const * node = 0); + bool get_param_enum_contains(gchar const * name, + gchar const * value, + SPDocument * doc = 0x0, + Inkscape::XML::Node * node = 0x0); + bool set_param_bool (const gchar * name, bool value, SPDocument * doc = NULL, @@ -269,6 +274,11 @@ public: SPDocument * doc = 0, Inkscape::XML::Node * node = 0); + gchar const * set_param_enum (gchar const * name, + gchar const * value, + SPDocument * doc = 0x0, + Inkscape::XML::Node * node = 0x0); + guint32 set_param_color (const gchar * name, guint32 color, SPDocument * doc = NULL, diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index 292e677a7..9cdc05049 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -175,6 +175,24 @@ const gchar *ParamComboBox::set(const gchar * in, SPDocument * /*doc*/, Inkscape return _value; } +/** + * function to test if \c guitext is selectable + */ +bool ParamComboBox::contains(const gchar * guitext, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const +{ + if (guitext == NULL) { + return false; /* Can't have NULL string */ + } + + for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { + enumentry * entr = reinterpret_cast<enumentry *>(list->data); + if ( !entr->guitext.compare(guitext) ) + return true; + } + // if we did not find the guitext in this ParamComboBox: + return false; +} + void ParamComboBox::changed (void) { diff --git a/src/extension/param/enum.h b/src/extension/param/enum.h index ac7d72abd..52e018469 100644 --- a/src/extension/param/enum.h +++ b/src/extension/param/enum.h @@ -51,6 +51,11 @@ public: const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + /** + * @returns true if guitext is part of this enum + */ + bool contains(const gchar * guitext, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const; + void changed (void); }; /* class ParamComboBox */ diff --git a/src/extension/param/parameter.cpp b/src/extension/param/parameter.cpp index 97e4f9d8c..202b8110f 100644 --- a/src/extension/param/parameter.cpp +++ b/src/extension/param/parameter.cpp @@ -183,6 +183,15 @@ gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node cons return param->get(doc, node); } +bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamComboBox const *param = dynamic_cast<ParamComboBox const *>(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->contains(value, doc, node); +} + gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const { ParamRadioButton const *param = dynamic_cast<ParamRadioButton const *>(this); @@ -247,6 +256,15 @@ gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, In return param->set(in, doc, node); } +gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +{ + ParamComboBox *param = dynamic_cast<ParamComboBox *>(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->set(in, doc, node); +} + /** Wrapper to cast to the object and use it's function. */ guint32 diff --git a/src/extension/param/parameter.h b/src/extension/param/parameter.h index d08efc554..5e1e3897f 100644 --- a/src/extension/param/parameter.h +++ b/src/extension/param/parameter.h @@ -88,8 +88,10 @@ public: gchar const *get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const; /** Wrapper to cast to the object and use it's function. */ - gchar const *get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const *node) const; + bool get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const; + /** Wrapper to cast to the object and use it's function. */ + gchar const *get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const *node) const; /** Wrapper to cast to the object and use it's function. */ bool set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node); @@ -101,6 +103,8 @@ public: gchar const *set_optiongroup(gchar const *in, SPDocument * doc, Inkscape::XML::Node *node); + gchar const *set_enum(gchar const * in, SPDocument * doc, Inkscape::XML::Node *node); + gchar const *set_string(gchar const * in, SPDocument * doc, Inkscape::XML::Node * node); guint32 set_color(guint32 in, SPDocument * doc, Inkscape::XML::Node * node); diff --git a/src/main.cpp b/src/main.cpp index 5bb42d405..d9e731912 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -148,6 +148,7 @@ enum { SP_ARG_EXPORT_PS, SP_ARG_EXPORT_EPS, SP_ARG_EXPORT_PDF, + SP_ARG_EXPORT_PDF_VERSION, SP_ARG_EXPORT_LATEX, #ifdef WIN32 SP_ARG_EXPORT_EMF, @@ -201,6 +202,7 @@ static gchar *sp_export_svg = NULL; static gchar *sp_export_ps = NULL; static gchar *sp_export_eps = NULL; static gchar *sp_export_pdf = NULL; +static gchar *sp_export_pdf_version = NULL; #ifdef WIN32 static gchar *sp_export_emf = NULL; #endif //WIN32 @@ -245,6 +247,7 @@ static void resetCommandlineGlobals() { sp_export_ps = NULL; sp_export_eps = NULL; sp_export_pdf = NULL; + sp_export_pdf_version = NULL; #ifdef WIN32 sp_export_emf = NULL; #endif //WIN32 @@ -386,6 +389,12 @@ struct poptOption options[] = { N_("Export document to a PDF file"), N_("FILENAME")}, + {"export-pdf-version", 0, + POPT_ARG_STRING, &sp_export_pdf_version, SP_ARG_EXPORT_PDF_VERSION, + // TRANSLATORS: "--export-pdf-version" is an Inkscape command line option; see "inkscape --help" + N_("Export PDF to given version. (hint: make sure to input the exact string found in the PDF export dialog, e.g. \"PDF 1.4\" which is PDF-a conformant)"), + N_("PDF_VERSION")}, + {"export-latex", 0, POPT_ARG_NONE, &sp_export_latex, SP_ARG_EXPORT_LATEX, N_("Export PDF/PS/EPS without text. Besides the PDF/PS/EPS, a LaTeX file is exported, putting the text on top of the PDF/PS/EPS file. Include the result in LaTeX like: \\input{latexfile.tex}"), @@ -1638,6 +1647,33 @@ static int do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime) } (*i)->set_param_float("bleed", margin); + // handle --export-pdf-version + bool set_export_pdf_version_fail=true; + const gchar *pdfver_param_name="PDFversion"; + if(sp_export_pdf_version) { + // combine "PDF " and the given command line + std::string version_gui_string=std::string("PDF ")+sp_export_pdf_version; + try{ + // first, check if the given pdf version is selectable in the ComboBox + if((*i)->get_param_enum_contains("PDFversion", version_gui_string.c_str())) { + (*i)->set_param_enum(pdfver_param_name, version_gui_string.c_str()); + set_export_pdf_version_fail=false; + } else { + g_warning("Desired PDF export version \"%s\" not supported! Hint: input one of the versions found in the pdf export dialog e.g. \"1.4\".", + sp_export_pdf_version); + } + } catch (...) { + // can be thrown along the way: + // throw Extension::param_not_exist(); + // throw Extension::param_not_enum_param(); + g_warning("Parameter or Enum \"%s\" might not exist",pdfver_param_name); + } + } + // set default pdf export version to 1.4, also if something went wrong + if(set_export_pdf_version_fail) { + (*i)->set_param_enum(pdfver_param_name, "PDF 1.4"); + } + //check if specified directory exists if (!Inkscape::IO::file_directory_exists(uri)) { g_warning("File path \"%s\" includes directory that doesn't exist.\n", uri); |
