hi, i have basic working skeleton for bug 3527; now there is only minimal set of supported features, but i'll add others, when you won't opose the general construction of this code. i would like to ask :
1) is it possible to add hyperref support to 1.6 series (Jose?) 2) can somebody review this code and comment what should be done otherwise and mainly what i forgot to do. 3) what features you would like to have from hyperref ? from my point of view these things need to be resolved: 1) afaiu strings entered into gui are in utf8; now they are pasted to output .tex via from_utf8, but i'm not sure how it works with current encodings. whats the best solution for this ? 2) i know from my previous experience with hyperref, that there are options, which are just fine for pdflatex, but when i try to render it through ps2pdf, the whole compilation fails. howto treat these cases ? is it possible to generate different code for a different targets ? 3) is there something needed for lyx2lyx support ? 4) adding others things like keywords, checkboxes for working bookmarks and references. any comments welcomed pavel
diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 9115877..60abd48 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -55,6 +55,7 @@ #include "Undo.h" #include "version.h" #include "EmbeddedFiles.h" +#include "PDFOptions.h" #include "insets/InsetBibitem.h" #include "insets/InsetBibtex.h" @@ -459,6 +460,7 @@ int Buffer::readHeader(Lexer & lex) params().footskip.erase(); params().listings_params.clear(); params().clearLayoutModules(); + params().pdfoptions().clear(); for (int i = 0; i < 4; ++i) { params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i]; diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index e566cdd..cfcfa30 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -37,6 +37,7 @@ #include "Spacing.h" #include "TexRow.h" #include "VSpace.h" +#include "PDFOptions.h" #include "frontends/alert.h" #include "insets/InsetListingsParams.h" @@ -290,6 +291,7 @@ public: * and for detached paragraphs in "indented" documents. */ VSpace defskip; + PDFOptions pdfoptions; }; @@ -435,6 +437,16 @@ Spacing const & BufferParams::spacing() const return pimpl_->spacing; } +PDFOptions & BufferParams::pdfoptions() +{ + return pimpl_->pdfoptions; +} + + +PDFOptions const & BufferParams::pdfoptions() const +{ + return pimpl_->pdfoptions; +} VSpace const & BufferParams::getDefSkip() const { @@ -633,6 +645,12 @@ string const BufferParams::readToken(Lexer & lex, string const & token) spacing().set(spacetranslator().find(nspacing), tmp_val); } else if (token == "\\float_placement") { lex >> float_placement; + } else if (token == "\\pdf_author") { + lex >> pdfoptions().author; + } else if (token == "\\pdf_title") { + lex >> pdfoptions().title; + } else if (token == "\\pdf_subject") { + lex >> pdfoptions().subject; } else { lyxerr << "BufferParams::readToken(): Unknown token: " << token << endl; @@ -694,6 +712,7 @@ void BufferParams::writeFile(ostream & os) const os << "\\paperfontsize " << fontsize << '\n'; spacing().writeFile(os); + pdfoptions().writeFile(os); os << "\\papersize " << string_papersize[papersize] << "\n\\use_geometry " << convert<string>(use_geometry) @@ -939,6 +958,19 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, os << "}\n"; texrow.newline(); } + + // PDF support + if (!pdfoptions().empty()) { + os << "\\usepackage[\n"; + if (!pdfoptions().author.empty()) + os << "pdfauthor={" << from_utf8(pdfoptions().author) << "},\n"; + if (!pdfoptions().title.empty()) + os << "pdftitle={" << from_utf8(pdfoptions().title) << "},\n"; + if (!pdfoptions().subject.empty()) + os << "pdfsubject={" << from_utf8(pdfoptions().subject) << "},\n"; + os << "]{hyperref}"; + } + if (use_geometry || nonstandard_papersize) { os << "\\usepackage{geometry}\n"; texrow.newline(); diff --git a/src/BufferParams.h b/src/BufferParams.h index 620b78e..2745f66 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -42,6 +42,7 @@ class Spacing; class TexRow; class VSpace; class Language; +class PDFOptions; /** Buffer parameters. * This class contains all the parameters for this buffer's use. Some @@ -292,6 +293,10 @@ public: /// void setCiteEngine(biblio::CiteEngine const); + /// options for pdf output + PDFOptions & pdfoptions(); + PDFOptions const & pdfoptions() const; + private: /// void readPreamble(Lexer &); diff --git a/src/Makefile.am b/src/Makefile.am index bf1af93..0f30115 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -233,6 +233,8 @@ liblyxcore_la_SOURCES = \ ParagraphParameters.h \ ParIterator.cpp \ ParIterator.h \ + PDFOptions.cpp \ + PDFOptions.h \ Row.cpp \ Row.h \ rowpainter.cpp \ diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp new file mode 100644 index 0000000..d261fc3 --- /dev/null +++ b/src/PDFOptions.cpp @@ -0,0 +1,37 @@ + +#include "PDFOptions.h" + +#include <sstream> + +namespace lyx { + +using std::ostream; + +bool PDFOptions::empty() const +{ + return + author.empty() && + title.empty() && + subject.empty() ; +} + +void PDFOptions::writeFile(ostream & os) const +{ + if (empty()) return; //nezrusime celou tuhle fci ? + + if (!author.empty()) + os << "\\pdf_author \"" << author << "\"\n"; + if (!title.empty() ) + os << "\\pdf_title \"" << title << "\"\n"; + if (!subject.empty()) + os << "\\pdf_subject \"" << subject << "\"\n"; +} + +void PDFOptions::clear() +{ + author.clear(); + title.clear(); + subject.clear(); +} + +} // namespace lyx diff --git a/src/PDFOptions.h b/src/PDFOptions.h new file mode 100644 index 0000000..e5f62cd --- /dev/null +++ b/src/PDFOptions.h @@ -0,0 +1,29 @@ +#ifndef PDFOPTIONS_H +#define PDFOPTIONS_H + + +#include <string> + +namespace lyx { + +/// Options for PDF generation +class PDFOptions { +public: + /// + std::string author; + /// + std::string title; + /// + std::string subject; + /// are there any settings ? + bool empty() const; + /// output to lyx header + void writeFile(std::ostream &) const; + /// + void clear(); +}; + +} // namespace lyx + + +#endif // SPACING_H diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 6d051e3..24b1f10 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -31,6 +31,7 @@ #include "LyXRC.h" // defaultUnit #include "TextClassList.h" #include "Spacing.h" +#include "PDFOptions.h" #include "insets/InsetListingsParams.h" @@ -584,6 +585,15 @@ GuiDocumentDialog::GuiDocumentDialog(LyXView & lv) connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor())); + // PDF support + pdfSupportModule = new UiWidget<Ui::PDFSupportUi>; + + connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)), + this, SLOT(change_adaptor())); + connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)), + this, SLOT(change_adaptor())); + connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)), + this, SLOT(change_adaptor())); // float floatModule = new FloatPlacement; @@ -603,6 +613,7 @@ GuiDocumentDialog::GuiDocumentDialog(LyXView & lv) docPS->addPanel(bulletsModule, _("Bullets")); docPS->addPanel(branchesModule, _("Branches")); docPS->addPanel(preambleModule, _("LaTeX Preamble")); + docPS->addPanel(pdfSupportModule, _("PDF Support")); docPS->setCurrentPanel(_("Document Class")); // FIXME: hack to work around resizing bug in Qt >= 4.2 // bug verified with Qt 4.2.{0-3} (JSpitzm) @@ -1123,6 +1134,14 @@ void GuiDocumentDialog::apply(BufferParams & params) params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit); branchesModule->apply(params); + + // PDF support + params.pdfoptions().author = + fromqstr(pdfSupportModule->authorLE->text()); + params.pdfoptions().title = + fromqstr(pdfSupportModule->titleLE->text()); + params.pdfoptions().subject = + fromqstr(pdfSupportModule->subjectLE->text()); } @@ -1398,6 +1417,16 @@ void GuiDocumentDialog::updateParams(BufferParams const & params) params.footskip, defaultUnit); branchesModule->update(params); + + // PDF support + pdfSupportModule->authorLE->setText( + toqstr(params.pdfoptions().author)); + + pdfSupportModule->titleLE->setText( + toqstr(params.pdfoptions().title)); + + pdfSupportModule->subjectLE->setText( + toqstr(params.pdfoptions().subject)); } diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index dff7bdc..944f2f4 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -27,6 +27,7 @@ #include "ui_NumberingUi.h" #include "ui_MarginsUi.h" #include "ui_PreambleUi.h" +#include "ui_PDFSupportUi.h" #include <QDialog> @@ -103,6 +104,7 @@ private: UiWidget<Ui::BiblioUi> *biblioModule; UiWidget<Ui::MathsUi> *mathsModule; UiWidget<Ui::LaTeXUi> *latexModule; + UiWidget<Ui::PDFSupportUi> *pdfSupportModule; PreambleModule *preambleModule; GuiBranches *branchesModule; diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 6cf26d3..077cee3 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -237,6 +237,7 @@ UIFILES = \ NumberingUi.ui \ PageLayoutUi.ui \ ParagraphUi.ui \ + PDFSupportUi.ui \ PreambleUi.ui \ PrefColorsUi.ui \ PrefConvertersUi.ui \ diff --git a/src/frontends/qt4/ui/PDFSupportUi.ui b/src/frontends/qt4/ui/PDFSupportUi.ui new file mode 100644 index 0000000..4185871 --- /dev/null +++ b/src/frontends/qt4/ui/PDFSupportUi.ui @@ -0,0 +1,96 @@ +<ui version="4.0" > + <class>PDFSupportUi</class> + <widget class="QWidget" name="PDFSupportUi" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>415</width> + <height>321</height> + </rect> + </property> + <widget class="QLineEdit" name="authorLE" > + <property name="geometry" > + <rect> + <x>90</x> + <y>10</y> + <width>311</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QLabel" name="authorL" > + <property name="geometry" > + <rect> + <x>10</x> + <y>10</y> + <width>52</width> + <height>16</height> + </rect> + </property> + <property name="text" > + <string>&Author:</string> + </property> + <property name="buddy" > + <cstring>authorLE</cstring> + </property> + </widget> + <widget class="QLineEdit" name="subjectLE" > + <property name="geometry" > + <rect> + <x>90</x> + <y>40</y> + <width>311</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QLabel" name="subjectL" > + <property name="geometry" > + <rect> + <x>10</x> + <y>40</y> + <width>52</width> + <height>16</height> + </rect> + </property> + <property name="text" > + <string>&Subject</string> + </property> + <property name="buddy" > + <cstring>subjectLE</cstring> + </property> + </widget> + <widget class="QLabel" name="titleL" > + <property name="geometry" > + <rect> + <x>10</x> + <y>70</y> + <width>52</width> + <height>16</height> + </rect> + </property> + <property name="text" > + <string>&Title</string> + </property> + <property name="buddy" > + <cstring>titleLE</cstring> + </property> + </widget> + <widget class="QLineEdit" name="titleLE" > + <property name="geometry" > + <rect> + <x>90</x> + <y>70</y> + <width>311</width> + <height>22</height> + </rect> + </property> + </widget> + </widget> + <includes> + <include location="local" >qt_helpers.h</include> + </includes> + <resources/> + <connections/> +</ui> diff --git a/src/frontends/qt4/ui/compile_uic.sh b/src/frontends/qt4/ui/compile_uic.sh index 0806939..5144a7a 100644 --- a/src/frontends/qt4/ui/compile_uic.sh +++ b/src/frontends/qt4/ui/compile_uic.sh @@ -6,6 +6,7 @@ uic BibtexAddUi.ui -o BibtexAddUi.h uic BibtexUi.ui -o BibtexUi.h uic BoxUi.ui -o BoxUi.h uic BranchesUi.ui -o BranchesUi.h +uic PDFSupportUi.ui -o PDFSupportUi.h uic BranchUi.ui -o BranchUi.h uic ChangesUi.ui -o ChangesUi.h uic CharacterUi.ui -o CharacterUi.h @@ -49,7 +50,7 @@ uic PrefSpellcheckerUi.ui -o PrefSpellcheckerUi.h uic PrefsUi.ui -o PrefsUi.h uic PrefUi.ui -o PrefUi.h uic PrintUi.ui -o PrintUi.h -uic reambleUi.ui -o PreambleUi.h +uic PreambleUi.ui -o PreambleUi.h uic RefUi.ui -o RefUi.h uic SearchUi.ui -o SearchUi.h uic SendtoUi.ui -o SendtoUi.h @@ -61,7 +62,7 @@ uic TexinfoUi.ui -o TexinfoUi.h uic TextLayoutUi.ui -o TextLayoutUi.h uic ThesaurusUi.ui -o ThesaurusUi.h uic TocUi.ui -o TocUi.h -uic ulletsUi.ui -o BulletsUi.h +uic BulletsUi.ui -o BulletsUi.h uic URLUi.ui -o URLUi.h uic VSpaceUi.ui -o VSpaceUi.h uic WrapUi.ui -o WrapUi.h