From 2c72e0ecaaf865dbd297652b27bf151011e987c6 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 3 Oct 2006 08:34:59 +0000 Subject: [PATCH] Fix bug 2868 * src/insets/insetgraphics.C (findTargetFormat): return pdf for vector graphics * src/format.h (Flags): new enum describing format flags (flags_): new member variable for format flags (vectorFormat): new, tell whether a format can contain vector graphics * src/format.C: adjust to flags changes * src/frontends/qt[34]/QPrefsDialog.C (QPrefsDialog::QPrefsDialog): handle new vector flag (QPrefsDialog::switch_format): ditto (QPrefsDialog::updateFormatsButtons): ditto (QPrefsDialog::new_format): ditto (QPrefsDialog::modify_format): ditto * src/frontends/qt3/ui/QPrefFileformatsModule.ui * src/frontends/qt4/ui/QPrefFileformatsUi.ui (vectorCB): new checkbox for vector flag * src/lyxrc.C (LyXRC::read): read vector flag (LyXRC::write): write vector flag * lib/doc/Customization.lyx: document format flags * lib/configure.py (checkFormatEntries): Add vector flag to some formats git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15205 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/configure.py | 28 ++--- lib/doc/Customization.lyx | 109 +++++++++++++++++- src/format.C | 15 +-- src/format.h | 26 ++++- src/frontends/qt3/QPrefsDialog.C | 23 +++- .../qt3/ui/QPrefFileformatsModule.ui | 12 ++ src/frontends/qt4/QPrefsDialog.C | 23 +++- src/frontends/qt4/ui/QPrefFileformatsUi.ui | 14 +++ src/insets/insetgraphics.C | 7 +- src/lyxrc.C | 35 +++--- 10 files changed, 236 insertions(+), 56 deletions(-) diff --git a/lib/configure.py b/lib/configure.py index 3599b98ae0..f841da3798 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -220,13 +220,13 @@ def checkLatex(): def checkFormatEntries(): ''' Check all formats (\Format entries) ''' checkViewer('a Tgif viewer and editor', ['tgif'], - rc_entry = [r'\Format tgif obj Tgif "" "%%" "%%" ""']) + rc_entry = [r'\Format tgif obj Tgif "" "%%" "%%" "vector"']) # checkViewer('a FIG viewer and editor', ['xfig'], - rc_entry = [r'\Format fig fig FIG "" "%%" "%%" ""']) + rc_entry = [r'\Format fig fig FIG "" "%%" "%%" "vector"']) # checkViewer('a Grace viewer and editor', ['xmgrace'], - rc_entry = [r'\Format agr agr Grace "" "%%" "%%" ""']) + rc_entry = [r'\Format agr agr Grace "" "%%" "%%" "vector"']) # checkViewer('a FEN viewer and editor', ['xboard -lpf $$i -mode EditPosition'], rc_entry = [r'\Format fen fen FEN "" "%%" "%%" ""']) @@ -266,22 +266,22 @@ def checkFormatEntries(): #checkProg('a Postscript interpreter', ['gs'], # rc_entry = [ r'\ps_command "%%"' ]) checkViewer('a Postscript previewer', ['gv', 'ghostview -swap', 'kghostview'], - rc_entry = [r'''\Format eps eps EPS "" "%%" "" "" -\Format ps ps Postscript t "%%" "" "document"''']) + rc_entry = [r'''\Format eps eps EPS "" "%%" "" "vector" +\Format ps ps Postscript t "%%" "" "document,vector"''']) # checkViewer('a PDF previewer', ['acrobat', 'acroread', 'gv', 'ghostview', \ 'xpdf', 'kpdf', 'kghostview'], - rc_entry = [r'''\Format pdf pdf "PDF (ps2pdf)" P "%%" "" "document" -\Format pdf2 pdf "PDF (pdflatex)" F "%%" "" "document" -\Format pdf3 pdf "PDF (dvipdfm)" m "%%" "" "document"''']) + rc_entry = [r'''\Format pdf pdf "PDF (ps2pdf)" P "%%" "" "document,vector" +\Format pdf2 pdf "PDF (pdflatex)" F "%%" "" "document,vector" +\Format pdf3 pdf "PDF (dvipdfm)" m "%%" "" "document,vector"''']) # checkViewer('a DVI previewer', ['xdvi', 'kdvi'], - rc_entry = [r'\Format dvi dvi DVI D "%%" "" "document"']) + rc_entry = [r'\Format dvi dvi DVI D "%%" "" "document,vector"']) if ((os.name == 'nt' or sys.platform == 'cygwin') and checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']): # Windows only: DraftDVI - addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document"') + addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document,vector"') # checkViewer('a HTML previewer', ['mozilla file://$$p$$i', 'netscape'], rc_entry = [r'\Format html html HTML H "%%" "" "document"']) @@ -295,10 +295,10 @@ def checkFormatEntries(): \Format pdftex pdftex_t PDFTEX "" "" "" "" \Format program "" Program "" "" "" "" \Format pstex pstex_t PSTEX "" "" "" "" -\Format rtf rtf "Rich Text Format" "" "" "" "document" -\Format sxw sxw "OpenOffice.Org Writer" O "" "" "document" -\Format wmf wmf "Windows Meta File" "" "" "" "" -\Format word doc "MS Word" W "" "" "document" +\Format rtf rtf "Rich Text Format" "" "" "" "document,vector" +\Format sxw sxw "OpenOffice.Org Writer" O "" "" "document,vector" +\Format wmf wmf "Windows Meta File" "" "" "" "vector" +\Format word doc "MS Word" W "" "" "document,vector" \Format wordhtml html "MS Word (HTML)" "" "" "" "document" ''') diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index 683fbaf12b..5202987a29 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -1791,8 +1791,9 @@ P references:Conversion \family default dialog. - This does currently only work in the Windows® port of LyX, but it is planned - to implement this feature on all other ports that can support it, too. + This does currently only work in the Windows® and Mac OS X ports of LyX, + but it is planned to implement this feature on all other ports that can + support it, too. \end_layout \begin_layout Standard @@ -1848,6 +1849,110 @@ For example, the file may reference other files with relative filenames, directory and may modify it in the process. \end_layout +\begin_layout Standard +Sometimes LyX needs to know a bit more about the properties of a format. + These bits can be specified with flags. + Currently there are two of them: +\end_layout + +\begin_layout Standard +The +\family typewriter +document +\family default + flag tells LyX that a format is suitable for document export. + If this flag is set for a format, and if a suitable conversion route exists, + then the format will appear in the +\family sans +\bar under +F +\bar default +ile\SpecialChar \menuseparator + +\bar under +E +\bar default +xport +\family default + menu. + The format will also appear in the +\family sans +\bar under +V +\bar default +iew +\family default + menu if it has a viewer associated to it. + Pure image formats (e.g.\InsetSpace ~ + +\family typewriter +png +\family default +) do not have this flag set, formats that can both represent images and + documents (e.g.\InsetSpace ~ + +\family typewriter +pdf +\family default +) do have it set. +\end_layout + +\begin_layout Standard +The +\family typewriter +vector +\family default + flag tells LyX whether a format can contain vector graphics. + This information is used to determine the target format of included graphics + for +\family typewriter +pdflatex +\family default + export. + Included graphics may need to be converted to either +\family typewriter +pdf +\family default +, +\family typewriter +png +\family default + or +\family typewriter +jpg +\family default +, since +\family typewriter +pdflatex +\family default + can not handle other image formats. + If an included graphic is not already in +\family typewriter +pdf +\family default +, +\family typewriter +png +\family default + or +\family typewriter +jpg +\family default + format it is converted to +\family typewriter +pdf +\family default + if the +\family typewriter +vector +\family default + flag of the format is set, and otherwise to +\family typewriter +png +\family default +. +\end_layout + \begin_layout Section BibTeX and makeindex \end_layout diff --git a/src/format.C b/src/format.C index 147ba7e6fb..58d0e38f4a 100644 --- a/src/format.C +++ b/src/format.C @@ -93,9 +93,9 @@ bool operator<(Format const & a, Format const & b) Format::Format(string const & n, string const & e, string const & p, string const & s, string const & v, string const & ed, - bool d) + int flags) : name_(n), extension_(e), prettyname_(p), shortcut_(s), viewer_(v), - editor_(ed), document_(d) + editor_(ed), flags_(flags) {} @@ -209,24 +209,25 @@ int Formats::getNumber(string const & name) const void Formats::add(string const & name) { if (!getFormat(name)) - add(name, name, name, string(), string(), string(), true); + add(name, name, name, string(), string(), string(), + Format::document); } void Formats::add(string const & name, string const & extension, string const & prettyname, string const & shortcut, - string const & viewer, string const & editor, bool document) + string const & viewer, string const & editor, + int flags) { FormatList::iterator it = find_if(formatlist.begin(), formatlist.end(), FormatNamesEqual(name)); if (it == formatlist.end()) formatlist.push_back(Format(name, extension, prettyname, - shortcut, viewer, editor, - document)); + shortcut, viewer, editor, flags)); else *it = Format(name, extension, prettyname, shortcut, viewer, - editor, document); + editor, flags); } diff --git a/src/format.h b/src/format.h index 8a888e4431..c12ff0ed67 100644 --- a/src/format.h +++ b/src/format.h @@ -21,10 +21,20 @@ class Buffer; class Format { public: + /// Flags for some format properties + enum Flags { + none = 0, + /// Set if this format is a document format (as opposed to + /// e.g. image formats). + /// Some formats are both (e.g. pdf), they have this flag set. + document = 1, + /// Set if this format can contain vector graphics. + vector = 2, + }; /// Format(std::string const & n, std::string const & e, std::string const & p, std::string const & s, std::string const & v, std::string const & ed, - bool ex); + int); /// bool dummy() const; /// Tell whether this format is a child format. @@ -66,7 +76,11 @@ public: } /// bool documentFormat() const { - return document_; + return flags_ & document; + } + /// + bool vectorFormat() const { + return flags_ & vector; } private: /// Internal name. Needs to be unique. @@ -87,14 +101,14 @@ private: std::string viewer_; /// Editor for this format. \sa viewer_. std::string editor_; - /// Is this format a document format? (as opposed to e.g. image formats) - /// Some formats are both (e.g. pdf), they have this flag set. - bool document_; + /// + int flags_; }; bool operator<(Format const & a, Format const & b); + /// class Formats { public: @@ -126,7 +140,7 @@ public: void add(std::string const & name, std::string const & extension, std::string const & prettyname, std::string const & shortcut, std::string const & viewer, std::string const & editor, - bool document); + int flags); /// void erase(std::string const & name); /// diff --git a/src/frontends/qt3/QPrefsDialog.C b/src/frontends/qt3/QPrefsDialog.C index 695d69f693..6e1367a157 100644 --- a/src/frontends/qt3/QPrefsDialog.C +++ b/src/frontends/qt3/QPrefsDialog.C @@ -188,6 +188,7 @@ QPrefsDialog::QPrefsDialog(QPrefs * form) connect(fileformatsModule->viewerED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed())); connect(fileformatsModule->editorED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed())); connect(fileformatsModule->documentCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed())); + connect(fileformatsModule->vectorCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed())); connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(new_converter())); connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(remove_converter())); @@ -735,6 +736,7 @@ void QPrefsDialog::switch_format(int nr) fileformatsModule->viewerED->setText(toqstr(f.viewer())); fileformatsModule->editorED->setText(toqstr(f.editor())); fileformatsModule->documentCB->setChecked(f.documentFormat()); + fileformatsModule->vectorCB->setChecked(f.vectorFormat()); fileformatsModule->formatRemovePB->setEnabled( !form_->converters().formatIsUsed(f.name())); @@ -777,6 +779,7 @@ void QPrefsDialog::updateFormatsButtons() string const old_viewer(f.viewer()); string const old_editor(f.editor()); bool const old_document(f.documentFormat()); + bool const old_vector(f.vectorFormat()); string const new_pretty(fromqstr(gui_name)); string const new_shortcut(fromqstr(fileformatsModule->shortcutED->text())); @@ -784,10 +787,12 @@ void QPrefsDialog::updateFormatsButtons() string const new_viewer(fromqstr(fileformatsModule->viewerED->text())); string const new_editor(fromqstr(fileformatsModule->editorED->text())); bool const new_document(fileformatsModule->documentCB->isChecked()); + bool const new_vector(fileformatsModule->vectorCB->isChecked()); bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut) || (old_extension != new_extension) || (old_viewer != new_viewer) - || (old_editor != new_editor)) || old_document != new_document; + || old_editor != new_editor || old_document != new_document + || old_vector != new_vector); fileformatsModule->formatModifyPB->setEnabled( valid && known && modified && !known_otherwise); @@ -804,10 +809,14 @@ void QPrefsDialog::new_format() string const shortcut = fromqstr(fileformatsModule->shortcutED->text()); string const viewer = fromqstr(fileformatsModule->viewerED->text()); string const editor = fromqstr(fileformatsModule->editorED->text()); - bool const document = fileformatsModule->documentCB->isChecked(); + int flags = Format::none; + if (fileformatsModule->documentCB->isChecked()) + flags |= Format::document; + if (fileformatsModule->vectorCB->isChecked()) + flags |= Format::vector; form_->formats().add(name, extension, prettyname, shortcut, viewer, - editor, document); + editor, flags); form_->formats().sort(); updateFormats(); fileformatsModule->formatsLB->setCurrentItem(form_->formats().getNumber(name)); @@ -835,10 +844,14 @@ void QPrefsDialog::modify_format() string const shortcut = fromqstr(fileformatsModule->shortcutED->text()); string const viewer = fromqstr(fileformatsModule->viewerED->text()); string const editor = fromqstr(fileformatsModule->editorED->text()); - bool const document = fileformatsModule->documentCB->isChecked(); + int flags = Format::none; + if (fileformatsModule->documentCB->isChecked()) + flags |= Format::document; + if (fileformatsModule->vectorCB->isChecked()) + flags |= Format::vector; form_->formats().add(name, extension, prettyname, shortcut, viewer, - editor, document); + editor, flags); form_->formats().sort(); fileformatsModule->formatsLB->setUpdatesEnabled(false); diff --git a/src/frontends/qt3/ui/QPrefFileformatsModule.ui b/src/frontends/qt3/ui/QPrefFileformatsModule.ui index bfbe41bba5..f07247c06e 100644 --- a/src/frontends/qt3/ui/QPrefFileformatsModule.ui +++ b/src/frontends/qt3/ui/QPrefFileformatsModule.ui @@ -60,6 +60,17 @@ Tell whether this format is a document format. A document can not be exported to or viewed in a non-document format. + + + vectorCB + + + Vector graphi&cs format + + + Tell whether this format can contain vector graphics. + + shortcutED @@ -336,6 +347,7 @@ viewerED editorED documentCB + vectorCB config.h diff --git a/src/frontends/qt4/QPrefsDialog.C b/src/frontends/qt4/QPrefsDialog.C index d3b5104b7d..aabedba14f 100644 --- a/src/frontends/qt4/QPrefsDialog.C +++ b/src/frontends/qt4/QPrefsDialog.C @@ -1293,6 +1293,7 @@ PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent) connect(viewerED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed())); connect(editorED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed())); connect(documentCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed())); + connect(vectorCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed())); connect(formatNewPB, SIGNAL(clicked()), this, SIGNAL(changed())); connect(formatRemovePB, SIGNAL(clicked()), @@ -1356,6 +1357,7 @@ void PrefFileformats::switch_format(int nr) viewerED->setText(toqstr(f.viewer())); editorED->setText(toqstr(f.editor())); documentCB->setChecked((f.documentFormat())); + vectorCB->setChecked((f.vectorFormat())); formatRemovePB->setEnabled( !form_->converters().formatIsUsed(f.name())); @@ -1398,6 +1400,7 @@ void PrefFileformats::updateButtons() string const old_viewer(f.viewer()); string const old_editor(f.editor()); bool const old_document(f.documentFormat()); + bool const old_vector(f.vectorFormat()); string const new_pretty(fromqstr(gui_name)); string const new_shortcut(fromqstr(shortcutED->text())); @@ -1405,10 +1408,12 @@ void PrefFileformats::updateButtons() string const new_viewer(fromqstr(viewerED->text())); string const new_editor(fromqstr(editorED->text())); bool const new_document(documentCB->isChecked()); + bool const new_vector(vectorCB->isChecked()); bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut) || (old_extension != new_extension) || (old_viewer != new_viewer) - || (old_editor != new_editor) || old_document != new_document); + || old_editor != new_editor || old_document != new_document + || old_vector != new_vector); formatModifyPB->setEnabled( valid && known && modified && !known_otherwise); @@ -1429,10 +1434,14 @@ void PrefFileformats::new_format() string const shortcut = fromqstr(shortcutED->text()); string const viewer = fromqstr(viewerED->text()); string const editor = fromqstr(editorED->text()); - bool const document = documentCB->isChecked(); + int flags = Format::none; + if (documentCB->isChecked()) + flags |= Format::document; + if (vectorCB->isChecked()) + flags |= Format::vector; form_->formats().add(name, extension, prettyname, shortcut, viewer, - editor, document); + editor, flags); form_->formats().sort(); update(); @@ -1464,10 +1473,14 @@ void PrefFileformats::modify_format() string const shortcut = fromqstr(shortcutED->text()); string const viewer = fromqstr(viewerED->text()); string const editor = fromqstr(editorED->text()); - bool const document = documentCB->isChecked(); + int flags = Format::none; + if (documentCB->isChecked()) + flags |= Format::document; + if (vectorCB->isChecked()) + flags |= Format::vector; form_->formats().add(name, extension, prettyname, shortcut, viewer, - editor, document); + editor, flags); form_->formats().sort(); formatsLW->setUpdatesEnabled(false); diff --git a/src/frontends/qt4/ui/QPrefFileformatsUi.ui b/src/frontends/qt4/ui/QPrefFileformatsUi.ui index a86d90120e..f65386f8cc 100644 --- a/src/frontends/qt4/ui/QPrefFileformatsUi.ui +++ b/src/frontends/qt4/ui/QPrefFileformatsUi.ui @@ -180,6 +180,19 @@ + + + + true + + + Tell whether this format can contain vector graphics. + + + Vector graphi&cs format + + + @@ -240,6 +253,7 @@ viewerED editorED documentCB + vectorCB formatNewPB formatModifyPB formatRemovePB diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 31be4abb9a..6620a9451a 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -126,11 +126,12 @@ string findTargetFormat(string const & format, OutputParams const & runparams) // Are we using latex or pdflatex? if (runparams.flavor == OutputParams::PDFLATEX) { lyxerr[Debug::GRAPHICS] << "findTargetFormat: PDF mode" << endl; - // Convert postscript to pdf - if (format == "eps" || format == "ps") + Format const * const f = formats.getFormat(format); + // Convert vector graphics to pdf + if (f && f->vectorFormat()) return "pdf"; // pdflatex can use jpeg, png and pdf directly - if (format == "jpg" || format == "pdf") + if (format == "jpg") return format; // Convert everything else to png return "png"; diff --git a/src/lyxrc.C b/src/lyxrc.C index 9ac9724453..0364321ec6 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -49,7 +49,6 @@ using lyx::support::expandPath; using lyx::support::getEnv; using lyx::support::libFileSearch; using lyx::support::token; -using lyx::support::tokenPos; using std::cout; using std::endl; @@ -1083,9 +1082,6 @@ int LyXRC::read(LyXLex & lexrc) viewer = lexrc.getString(); if (lexrc.next()) editor = lexrc.getString(); - // The only supported flag for now is "document". - // More flags could be added in the future. - // Therefore we use tokenPos below to read the flag. string flags; // Hack to ensure compatibility with versions older // than 1.5.0 @@ -1101,13 +1097,19 @@ int LyXRC::read(LyXLex & lexrc) flags.erase(); } } - bool const document = - (tokenPos(flags, ',', "document") >= 0); - if (!flags.empty() && flags != "document") - lyxerr << "Ignoring flags other than " - "`document' in `" << flags - << "' for format `" << format << "'." - << endl; + int flgs = Format::none; + while (!flags.empty()) { + string flag; + flags = lyx::support::split(flags, flag, ','); + if (flag == "document") + flgs |= Format::document; + else if (flag == "vector") + flgs |= Format::vector; + else + lyxerr << "Ignoring unknown flag `" + << flag << "' for format `" + << format << "'." << endl; + } if (prettyname.empty()) { if (converters.formatIsUsed(format)) { lyxerr << "Can't delete format " @@ -1117,7 +1119,7 @@ int LyXRC::read(LyXLex & lexrc) } } else { formats.add(format, extension, prettyname, - shortcut, viewer, editor, document); + shortcut, viewer, editor, flgs); } break; } @@ -2017,15 +2019,20 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const format->shortcut() != cit->shortcut() || format->viewer() != cit->viewer() || format->editor() != cit->editor() || - format->documentFormat() != cit->documentFormat()) { + format->documentFormat() != cit->documentFormat() || + format->vectorFormat() != cit->vectorFormat()) { os << "\\format \"" << cit->name() << "\" \"" << cit->extension() << "\" \"" << cit->prettyname() << "\" \"" << cit->shortcut() << "\" \"" << cit->viewer() << "\" \"" << cit->editor() << "\" \""; + std::vector flags; if (cit->documentFormat()) - os << "document"; + flags.push_back("document"); + if (cit->vectorFormat()) + flags.push_back("vector"); + os << lyx::support::getStringFromVector(flags); os << "\"\n"; } }