Merge lp:~schwieni/inkscape/inkscape into lp:~inkscape.dev/inkscape/trunk

Proposed by schwieni
Status: Merged
Merged at revision: 12348
Proposed branch: lp:~schwieni/inkscape/inkscape
Merge into: lp:~inkscape.dev/inkscape/trunk
Diff against target: 275 lines (+122/-1)
8 files modified
inkscape.pod (+8/-0)
src/extension/extension.cpp (+22/-0)
src/extension/extension.h (+10/-0)
src/extension/param/enum.cpp (+18/-0)
src/extension/param/enum.h (+5/-0)
src/extension/param/parameter.cpp (+18/-0)
src/extension/param/parameter.h (+5/-1)
src/main.cpp (+36/-0)
To merge this branch: bzr merge lp:~schwieni/inkscape/inkscape
Reviewer Review Type Date Requested Status
Inkscape Developers Pending
Review via email: mp+161225@code.launchpad.net

Commit message

Updates bug #669748

Add a command-line switch to specify PDF Export level.

Description of the change

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).

To post a comment you must log in.
lp:~schwieni/inkscape/inkscape updated
12306. By schwieni

edited inkscape.pod for the --export-pdf-version command line option

12307. By schwieni

Fixed the false warning for the --pdf-export-version
Added functions to test if a given string is listed in the ComboBox.

12308. By schwieni

The command line option for --pdf-export-version is now unquouted e.g. --pdf-export-version=1.4
Default pdf export version now PDF 1.4

Revision history for this message
Vinipsmaker (vinipsmaker) wrote :

Why does ParamComboBox::contains receive doc and node arguments if they aren't used?

Revision history for this message
schwieni (schwieni) wrote :

You are right. I just followed the interface definition of the ::get
method, which doesn't use those arguments neither (but possibly for
future use/ usage in the past, I don't know). However, since I have no
personal preference to it, this can be changed. Should I change it?
Am 02.06.2013 23:05, schrieb Vinipsmaker:
> Why does ParamComboBox::contains receive doc and node arguments if they aren't used?

Revision history for this message
Vinipsmaker (vinipsmaker) wrote :

> You are right. I just followed the interface definition of the ::get
method, which doesn't use those arguments neither (but possibly for
future use/ usage in the past, I don't know). However, since I have no
personal preference to it, this can be changed. Should I change it?

Never mind. I just looked in the Inkscape source code and all code is written exactly that way. You are maintaing the consistent and that is good.

A separate patch (unrelated with yours) should be provided by somebody else to refactor these classes. I bet it's this code was inherited from the ancient C source code.

Your patch looks fine. Just one note: Shouldn't Extension::get_param_enum_contains be const?

Revision history for this message
schwieni (schwieni) wrote :

Extension::get_param_enum_contains(...) might be made const. Again, i just followed the other existing functions, which also might be made const. However, I did not test that and just assume that they can be made const.
cf. e.g. int get_param_int(...) etc.

Revision history for this message
Vinipsmaker (vinipsmaker) wrote :

Branch merged.

Patched code fixed in r12350:
http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/12350/src/main.cpp (line 1673).

Revision history for this message
schwieni (schwieni) wrote :

I don't understand exactly why line 1673 in main.cpp was changed in this
patch!? The original version is meant to set the default PDF version to
1.4 in *any* case, even if no explicit (and possibly wrong) pdf-version
string was provided. So, by adding the test if(sp_export_pdf_version &&
...) is IMHO not as intended. There was the wish to have a *predictable*
behavior in PDF-export by command line (cf. Bug #1110549:
https://bugs.launchpad.net/inkscape/+bug/1110549). However, in the
modified code, if no "--pdf-export-version ..." command line is given,
the last option set in the GUI is used (which is not predictable from
CLI). Furthermore, help and man-pages must be changed too with this
modification.

Therefore, I suggest to change line 1673 back as it was.

Am 05.06.2013 23:15, schrieb Vinipsmaker:
> Branch merged.
>
> Patched code fixed in r12350:
> http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/12350/src/main.cpp (line 1673).

Revision history for this message
Vinipsmaker (vinipsmaker) wrote :

> I don't understand exactly why line 1673 in main.cpp was changed in this
> patch!? The original version is meant to set the default PDF version to
> 1.4 in *any* case, even if no explicit (and possibly wrong) pdf-version
> string was provided. So, by adding the test if(sp_export_pdf_version &&
> ...) is IMHO not as intended. There was the wish to have a *predictable*
> behavior in PDF-export by command line (cf. Bug #1110549:
> https://bugs.launchpad.net/inkscape/+bug/1110549). However, in the
> modified code, if no "--pdf-export-version ..." command line is given,
> the last option set in the GUI is used (which is not predictable from
> CLI). Furthermore, help and man-pages must be changed too with this
> modification.
>
> Therefore, I suggest to change line 1673 back as it was.

I'm sorry. I used the wrong variable.

The first patch makes Inkscape crash when someone try to export a PS file (the affected function is used to export (E)PS and PDF files). r12352 have the right correction:

http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/12352

I'll try to discuss the patch more next time.

Revision history for this message
schwieni (schwieni) wrote :

In this case I would enclose line 1652 to 1676 from main.cpp with
"if(sp_export_pdf) { ... }" rather than only the last lines

Am 06.06.2013 10:52, schrieb Vinipsmaker:
> The first patch makes Inkscape crash when someone try to export a PS file (the affected function is used to export (E)PS and PDF files). r12352 have the right correction:
>
> http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/12352
>
> I'll try to discuss the patch more next time.

Revision history for this message
Vinipsmaker (vinipsmaker) wrote :

> In this case I would enclose line 1652 to 1676 from main.cpp with
> "if(sp_export_pdf) { ... }" rather than only the last lines

Provide another patch please. I can only code Inkscape when I get home (my netbook is too slow to Inkscape code base).

Revision history for this message
Vinipsmaker (vinipsmaker) wrote :

> In this case I would enclose line 1652 to 1676 from main.cpp with
> "if(sp_export_pdf) { ... }" rather than only the last lines

I'm home now. Looked at the source code and used a third option.

If the user try to export the pdf and ps versions at one run, the sp_export_pdf detection would fail. A better detection approach is to check the mime argument.

Change done in r12354.

Revision history for this message
schwieni (schwieni) wrote :

I'm sorry where can I find r12354. Is it possible that you forgot to
push the changes?

> I'm home now. Looked at the source code and used a third option.
>
> If the user try to export the pdf and ps versions at one run, the sp_export_pdf detection would fail. A better detection approach is to check the mime argument.
>
> Change done in r12354.

Revision history for this message
Vinipsmaker (vinipsmaker) wrote :

> I'm sorry where can I find r12354. Is it possible that you forgot to
> push the changes?

My mistake. I forgot to push. r12359:
http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/12359

Revision history for this message
schwieni (schwieni) wrote :

OK, perfect. Thank you very much for transferring my modifications into
inkscape.dev! I assume the feature will be there in the next inkscape
version (0.49), so I can delete my own branch on launchpad, right?
> My mistake. I forgot to push. r12359:

Revision history for this message
Vinipsmaker (vinipsmaker) wrote :

> OK, perfect. Thank you very much for transferring my modifications into
> inkscape.dev! I assume the feature will be there in the next inkscape
> version (0.49), so I can delete my own branch on launchpad, right?

Yes, your changes were integrated in Inkscape source code and it's safe to delete your own branch on launchpad.

I'm sorry for my poor social skills. Thanks for the patience.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'inkscape.pod'
--- inkscape.pod 2012-10-09 11:36:06 +0000
+++ inkscape.pod 2013-04-30 18:52:28 +0000
@@ -32,6 +32,7 @@
32 -P, --export-ps=FILENAME32 -P, --export-ps=FILENAME
33 -E, --export-eps=FILENAME33 -E, --export-eps=FILENAME
34 -A, --export-pdf=FILENAME34 -A, --export-pdf=FILENAME
35 --export-pdf-version=VERSION-STRING
35 --export-latex36 --export-latex
3637
37 -T, --export-text-to-path38 -T, --export-text-to-path
@@ -268,6 +269,13 @@
268specify --export-id to export a single object (all other are hidden); in that case 269specify --export-id to export a single object (all other are hidden); in that case
269export area is that object's bounding box, but can be set to page by --export-area-page.270export area is that object's bounding box, but can be set to page by --export-area-page.
270271
272=item B<--export-pdf-version>=I<PDF-VERSION>
273
274Select the PDF version of the exported PDF file. This option basically
275exposes the PDF version selector found in the PDF-export dialog of the
276GUI. You must provide one of the versions from that combo-box,
277e.g. "1.4". The default pdf export version is "1.4".
278
271=item B<--export-latex>279=item B<--export-latex>
272280
273(for PS, EPS, and PDF export)281(for PS, EPS, and PDF export)
274282
=== modified file 'src/extension/extension.cpp'
--- src/extension/extension.cpp 2013-03-25 17:42:31 +0000
+++ src/extension/extension.cpp 2013-04-30 18:52:28 +0000
@@ -427,6 +427,21 @@
427 return param->get_enum(doc, node);427 return param->get_enum(doc, node);
428}428}
429429
430/**
431 * This is useful to find out, if a given string \c value is selectable in a ComboBox named \cname.
432 *
433 * @param name The name of the enum parameter to get.
434 * @param doc The document to look in for document specific parameters.
435 * @param node The node to look in for a specific parameter.
436 * @return true if value exists, false if not
437 */
438bool
439Extension::get_param_enum_contains(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node)
440{
441 Parameter * param = get_param(name);
442 return param->get_enum_contains(value, doc, node);
443}
444
430gchar const *445gchar const *
431Extension::get_param_optiongroup( gchar const * name, SPDocument const * doc, Inkscape::XML::Node const * node)446Extension::get_param_optiongroup( gchar const * name, SPDocument const * doc, Inkscape::XML::Node const * node)
432{447{
@@ -597,6 +612,13 @@
597 return param->set_optiongroup(value, doc, node);612 return param->set_optiongroup(value, doc, node);
598}613}
599614
615gchar const *
616Extension::set_param_enum(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node)
617{
618 Parameter * param = get_param(name);
619 return param->set_enum(value, doc, node);
620}
621
600622
601/**623/**
602 \return The passed in value624 \return The passed in value
603625
=== modified file 'src/extension/extension.h'
--- src/extension/extension.h 2013-03-14 01:33:10 +0000
+++ src/extension/extension.h 2013-04-30 18:52:28 +0000
@@ -244,6 +244,11 @@
244 SPDocument const * doc = 0,244 SPDocument const * doc = 0,
245 Inkscape::XML::Node const * node = 0);245 Inkscape::XML::Node const * node = 0);
246246
247 bool get_param_enum_contains(gchar const * name,
248 gchar const * value,
249 SPDocument * doc = 0x0,
250 Inkscape::XML::Node * node = 0x0);
251
247 bool set_param_bool (const gchar * name,252 bool set_param_bool (const gchar * name,
248 bool value,253 bool value,
249 SPDocument * doc = NULL,254 SPDocument * doc = NULL,
@@ -269,6 +274,11 @@
269 SPDocument * doc = 0,274 SPDocument * doc = 0,
270 Inkscape::XML::Node * node = 0);275 Inkscape::XML::Node * node = 0);
271276
277 gchar const * set_param_enum (gchar const * name,
278 gchar const * value,
279 SPDocument * doc = 0x0,
280 Inkscape::XML::Node * node = 0x0);
281
272 guint32 set_param_color (const gchar * name,282 guint32 set_param_color (const gchar * name,
273 guint32 color,283 guint32 color,
274 SPDocument * doc = NULL,284 SPDocument * doc = NULL,
275285
=== modified file 'src/extension/param/enum.cpp'
--- src/extension/param/enum.cpp 2012-11-26 10:33:19 +0000
+++ src/extension/param/enum.cpp 2013-04-30 18:52:28 +0000
@@ -173,6 +173,24 @@
173 return _value;173 return _value;
174}174}
175175
176/**
177 * function to test if \c guitext is selectable
178 */
179bool ParamComboBox::contains(const gchar * guitext, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const
180{
181 if (guitext == NULL) {
182 return false; /* Can't have NULL string */
183 }
184
185 for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {
186 enumentry * entr = reinterpret_cast<enumentry *>(list->data);
187 if ( !entr->guitext.compare(guitext) )
188 return true;
189 }
190 // if we did not find the guitext in this ParamComboBox:
191 return false;
192}
193
176void194void
177ParamComboBox::changed (void) {195ParamComboBox::changed (void) {
178196
179197
=== modified file 'src/extension/param/enum.h'
--- src/extension/param/enum.h 2012-02-29 01:16:51 +0000
+++ src/extension/param/enum.h 2013-04-30 18:52:28 +0000
@@ -51,6 +51,11 @@
5151
52 const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node);52 const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node);
5353
54 /**
55 * @returns true if guitext is part of this enum
56 */
57 bool contains(const gchar * guitext, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const;
58
54 void changed (void);59 void changed (void);
55}; /* class ParamComboBox */60}; /* class ParamComboBox */
5661
5762
=== modified file 'src/extension/param/parameter.cpp'
--- src/extension/param/parameter.cpp 2012-02-29 01:16:51 +0000
+++ src/extension/param/parameter.cpp 2013-04-30 18:52:28 +0000
@@ -183,6 +183,15 @@
183 return param->get(doc, node);183 return param->get(doc, node);
184}184}
185185
186bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const
187{
188 ParamComboBox const *param = dynamic_cast<ParamComboBox const *>(this);
189 if (!param) {
190 throw Extension::param_not_enum_param();
191 }
192 return param->contains(value, doc, node);
193}
194
186gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const195gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const
187{196{
188 ParamRadioButton const *param = dynamic_cast<ParamRadioButton const *>(this);197 ParamRadioButton const *param = dynamic_cast<ParamRadioButton const *>(this);
@@ -247,6 +256,15 @@
247 return param->set(in, doc, node);256 return param->set(in, doc, node);
248}257}
249258
259gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node )
260{
261 ParamComboBox *param = dynamic_cast<ParamComboBox *>(this);
262 if (!param) {
263 throw Extension::param_not_enum_param();
264 }
265 return param->set(in, doc, node);
266}
267
250268
251/** Wrapper to cast to the object and use it's function. */269/** Wrapper to cast to the object and use it's function. */
252guint32270guint32
253271
=== modified file 'src/extension/param/parameter.h'
--- src/extension/param/parameter.h 2012-02-29 01:16:51 +0000
+++ src/extension/param/parameter.h 2013-04-30 18:52:28 +0000
@@ -88,9 +88,11 @@
88 gchar const *get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const;88 gchar const *get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const;
8989
90 /** Wrapper to cast to the object and use it's function. */90 /** Wrapper to cast to the object and use it's function. */
91 bool get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const;
92
93 /** Wrapper to cast to the object and use it's function. */
91 gchar const *get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const *node) const;94 gchar const *get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const *node) const;
9295
93
94 /** Wrapper to cast to the object and use it's function. */96 /** Wrapper to cast to the object and use it's function. */
95 bool set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node);97 bool set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node);
9698
@@ -101,6 +103,8 @@
101103
102 gchar const *set_optiongroup(gchar const *in, SPDocument * doc, Inkscape::XML::Node *node);104 gchar const *set_optiongroup(gchar const *in, SPDocument * doc, Inkscape::XML::Node *node);
103105
106 gchar const *set_enum(gchar const * in, SPDocument * doc, Inkscape::XML::Node *node);
107
104 gchar const *set_string(gchar const * in, SPDocument * doc, Inkscape::XML::Node * node);108 gchar const *set_string(gchar const * in, SPDocument * doc, Inkscape::XML::Node * node);
105109
106 guint32 set_color(guint32 in, SPDocument * doc, Inkscape::XML::Node * node);110 guint32 set_color(guint32 in, SPDocument * doc, Inkscape::XML::Node * node);
107111
=== modified file 'src/main.cpp'
--- src/main.cpp 2013-04-06 14:17:29 +0000
+++ src/main.cpp 2013-04-30 18:52:28 +0000
@@ -148,6 +148,7 @@
148 SP_ARG_EXPORT_PS,148 SP_ARG_EXPORT_PS,
149 SP_ARG_EXPORT_EPS,149 SP_ARG_EXPORT_EPS,
150 SP_ARG_EXPORT_PDF,150 SP_ARG_EXPORT_PDF,
151 SP_ARG_EXPORT_PDF_VERSION,
151 SP_ARG_EXPORT_LATEX,152 SP_ARG_EXPORT_LATEX,
152#ifdef WIN32153#ifdef WIN32
153 SP_ARG_EXPORT_EMF,154 SP_ARG_EXPORT_EMF,
@@ -201,6 +202,7 @@
201static gchar *sp_export_ps = NULL;202static gchar *sp_export_ps = NULL;
202static gchar *sp_export_eps = NULL;203static gchar *sp_export_eps = NULL;
203static gchar *sp_export_pdf = NULL;204static gchar *sp_export_pdf = NULL;
205static gchar *sp_export_pdf_version = NULL;
204#ifdef WIN32206#ifdef WIN32
205static gchar *sp_export_emf = NULL;207static gchar *sp_export_emf = NULL;
206#endif //WIN32208#endif //WIN32
@@ -245,6 +247,7 @@
245 sp_export_ps = NULL;247 sp_export_ps = NULL;
246 sp_export_eps = NULL;248 sp_export_eps = NULL;
247 sp_export_pdf = NULL;249 sp_export_pdf = NULL;
250 sp_export_pdf_version = NULL;
248#ifdef WIN32251#ifdef WIN32
249 sp_export_emf = NULL;252 sp_export_emf = NULL;
250#endif //WIN32253#endif //WIN32
@@ -386,6 +389,12 @@
386 N_("Export document to a PDF file"),389 N_("Export document to a PDF file"),
387 N_("FILENAME")},390 N_("FILENAME")},
388391
392 {"export-pdf-version", 0,
393 POPT_ARG_STRING, &sp_export_pdf_version, SP_ARG_EXPORT_PDF_VERSION,
394 // TRANSLATORS: "--export-pdf-version" is an Inkscape command line option; see "inkscape --help"
395 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)"),
396 N_("PDF_VERSION")},
397
389 {"export-latex", 0,398 {"export-latex", 0,
390 POPT_ARG_NONE, &sp_export_latex, SP_ARG_EXPORT_LATEX,399 POPT_ARG_NONE, &sp_export_latex, SP_ARG_EXPORT_LATEX,
391 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}"),400 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 @@
1638 }1647 }
1639 (*i)->set_param_float("bleed", margin);1648 (*i)->set_param_float("bleed", margin);
16401649
1650 // handle --export-pdf-version
1651 bool set_export_pdf_version_fail=true;
1652 const gchar *pdfver_param_name="PDFversion";
1653 if(sp_export_pdf_version) {
1654 // combine "PDF " and the given command line
1655 std::string version_gui_string=std::string("PDF ")+sp_export_pdf_version;
1656 try{
1657 // first, check if the given pdf version is selectable in the ComboBox
1658 if((*i)->get_param_enum_contains("PDFversion", version_gui_string.c_str())) {
1659 (*i)->set_param_enum(pdfver_param_name, version_gui_string.c_str());
1660 set_export_pdf_version_fail=false;
1661 } else {
1662 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\".",
1663 sp_export_pdf_version);
1664 }
1665 } catch (...) {
1666 // can be thrown along the way:
1667 // throw Extension::param_not_exist();
1668 // throw Extension::param_not_enum_param();
1669 g_warning("Parameter or Enum \"%s\" might not exist",pdfver_param_name);
1670 }
1671 }
1672 // set default pdf export version to 1.4, also if something went wrong
1673 if(set_export_pdf_version_fail) {
1674 (*i)->set_param_enum(pdfver_param_name, "PDF 1.4");
1675 }
1676
1641 //check if specified directory exists1677 //check if specified directory exists
1642 if (!Inkscape::IO::file_directory_exists(uri)) {1678 if (!Inkscape::IO::file_directory_exists(uri)) {
1643 g_warning("File path \"%s\" includes directory that doesn't exist.\n", uri);1679 g_warning("File path \"%s\" includes directory that doesn't exist.\n", uri);