]> git.lyx.org Git - lyx.git/blobdiff - src/PDFOptions.cpp
adjust
[lyx.git] / src / PDFOptions.cpp
index e25dd0710ebdb9235ef085d1070c4632ae75cbbc..22b8ff310c36440de905b59daee434bc526a0dcc 100644 (file)
@@ -47,14 +47,14 @@ bool PDFOptions::empty() const
                && pdfborder == x.pdfborder
                && colorlinks == x.colorlinks
                && backref == x.backref
-               && pagebackref == x.pagebackref ;
+               && pagebackref == x.pagebackref
+               && pdfusetitle == x.pdfusetitle;
 }
 
 void PDFOptions::writeFile(ostream & os) const
 {
        os << "\\use_hyperref " << convert<string>(use_hyperref) << '\n';
-       os << "\\pdf_store_options " << convert<string>(store_options) << '\n';
-       if (!use_hyperref && !store_options)
+       if (!use_hyperref && empty())
                return;
        
        if (!title.empty() )
@@ -70,13 +70,14 @@ void PDFOptions::writeFile(ostream & os) const
        os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
        os << "\\pdf_bookmarksnumbered " << convert<string>(bookmarksnumbered) << '\n';
        os << "\\pdf_bookmarksopen " << convert<string>(bookmarksopen) << '\n';
-       os << "\\pdf_bookmarksopenlevel \"" << bookmarksopenlevel << "\"\n";
+       os << "\\pdf_bookmarksopenlevel " << bookmarksopenlevel << '\n';
        
        os << "\\pdf_breaklinks "  << convert<string>(breaklinks)  << '\n';
        os << "\\pdf_pdfborder "   << convert<string>(pdfborder)   << '\n';
        os << "\\pdf_colorlinks "  << convert<string>(colorlinks)  << '\n';
        os << "\\pdf_backref "     << convert<string>(backref)     << '\n';
        os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
+       os << "\\pdf_pdfusetitle " << convert<string>(pdfusetitle) << '\n';
        
        if (!pagemode.empty())
                os << "\\pdf_pagemode " << pagemode << '\n';
@@ -85,27 +86,28 @@ void PDFOptions::writeFile(ostream & os) const
                os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
 }
 
-void PDFOptions::writeLaTeX(odocstringstream &os) const
+void PDFOptions::writeLaTeX(odocstringstream &os, bool hyper_required) const
 {
-       if (!use_hyperref)
+       if (!use_hyperref && !hyper_required)
                return;
        
        string opt;
        
        opt = "\\usepackage[";
-       if (!title.empty())
-               opt += "pdftitle={"   + title + "},\n ";
-       if (!author.empty())
-               opt += "pdfauthor={"  + author + "},\n ";
-       if (!subject.empty())
-               opt += "pdfsubject={" + subject + "},\n ";
-       if (!keywords.empty())
-               opt += "pdfkeywords={" + keywords + "},\n ";
+       // since LyX uses unicode, also set the PDF strings to unicode strings with the
+       // hyperref option "unicode"
+       opt += "unicode=true, ";
+       
+       // try to extract author and title from document when none is
+       // explicitely given
+       if (pdfusetitle && title.empty() && author.empty())
+               opt += "pdfusetitle,";
+       opt += "\n ";
+
        opt += "bookmarks=" + convert<string>(bookmarks) + ',';
        if (bookmarks) {
                opt += "bookmarksnumbered=" + convert<string>(bookmarksnumbered) + ',';
                opt += "bookmarksopen=" + convert<string>(bookmarksopen) + ',';
-       
                if (bookmarksopen)
                        opt += "bookmarksopenlevel=" + convert<string>(bookmarksopenlevel) + ',';
        }
@@ -122,12 +124,28 @@ void PDFOptions::writeLaTeX(odocstringstream &os) const
        opt += "colorlinks="     + convert<string>(colorlinks) + ',';
        if (!pagemode.empty())
                opt += "pdfpagemode=" + pagemode + ',';
-       if (!quoted_options.empty()){
-               opt += "\n ";
-               opt += quoted_options_get();
-       }
+       
        opt = support::rtrim(opt,",");
        opt += "]\n {hyperref}\n";
+
+       // load the pdftitle etc. as hypersetup, otherwise you'll get
+       // LaTeX-errors when using non-latin characters
+       string hyperset;
+       if (!title.empty())
+               hyperset += "pdftitle={"   + title + "},";
+       if (!author.empty())
+               hyperset += "\n pdfauthor={"  + author + "},";
+       if (!subject.empty())
+               hyperset += "\n pdfsubject={" + subject + "},";
+       if (!keywords.empty())
+               hyperset += "\n pdfkeywords={" + keywords + "},";
+       if (!quoted_options.empty()){
+               hyperset += "\n ";
+               hyperset += quoted_options_get();
+       }
+       hyperset = support::rtrim(hyperset,",");
+       if (!hyperset.empty())
+               opt += "\\hypersetup{" + hyperset + "}\n ";
        
        // FIXME UNICODE
        os << from_utf8(opt);
@@ -164,12 +182,12 @@ string PDFOptions::readToken(Lexer &lex, string const & token)
                lex >> backref;
        } else if (token == "\\pdf_pagebackref") {
                lex >> pagebackref;
+       } else if (token == "\\pdf_pdfusetitle") {
+               lex >> pdfusetitle;
        } else if (token == "\\pdf_pagemode") {
                lex >> pagemode;
        } else if (token == "\\pdf_quoted_options") {
                lex >> quoted_options;
-       } else if (token == "\\pdf_store_options") {
-               lex >> store_options;
        } else {
                return token;
        }
@@ -177,13 +195,13 @@ string PDFOptions::readToken(Lexer &lex, string const & token)
 }
 
 
-//prepared for check
+// prepared for check
 string PDFOptions::quoted_options_get() const
 {
        return quoted_options;
 }
 
-// Keep implicit hyperref settings
+// set implicit settings for hyperref
 void PDFOptions::clear()
 {
        use_hyperref            = false;
@@ -202,7 +220,7 @@ void PDFOptions::clear()
        pagebackref             = false;
        pagemode.clear();
        quoted_options.clear();
-       store_options           = false;
+       pdfusetitle             = true;  //in contrast with hyperref
 }
 
 } // namespace lyx