Allow quotes in PDF text properties

PDF properties (Author, Title...) need to be quoted properly when writing (normal operation and tex2lyx). Also, reading them requires to use Lexer::getString() directly, because >> uses next(), which does not handle escapes.

Fixes bug #9830.
This commit is contained in:
Jean-Marc Lasgouttes 2015-11-02 16:23:28 +01:00
parent 2fea3b7200
commit 1f177fed77
3 changed files with 32 additions and 15 deletions

View File

@ -61,13 +61,13 @@ void PDFOptions::writeFile(ostream & os) const
return;
if (!title.empty() )
os << "\\pdf_title \"" << title << "\"\n";
os << "\\pdf_title " << Lexer::quoteString(title) << '\n';
if (!author.empty())
os << "\\pdf_author \"" << author << "\"\n";
os << "\\pdf_author " << Lexer::quoteString(author) << '\n';
if (!subject.empty())
os << "\\pdf_subject \"" << subject << "\"\n";
os << "\\pdf_subject " << Lexer::quoteString(subject) << '\n';
if (!keywords.empty())
os << "\\pdf_keywords \"" << keywords << "\"\n";
os << "\\pdf_keywords " << Lexer::quoteString(keywords) << '\n';
os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
@ -85,7 +85,7 @@ void PDFOptions::writeFile(ostream & os) const
os << "\\pdf_pagemode " << pagemode << '\n';
if (!quoted_options.empty())
os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
os << "\\pdf_quoted_options " << Lexer::quoteString(quoted_options) << '\n';
}
@ -206,13 +206,25 @@ string PDFOptions::readToken(Lexer &lex, string const & token)
if (token == "\\use_hyperref") {
lex >> use_hyperref;
} else if (token == "\\pdf_title") {
lex >> title;
if (lex.isOK()) {
lex.next(true);
title = lex.getString();
}
} else if (token == "\\pdf_author") {
lex >> author;
if (lex.isOK()) {
lex.next(true);
author = lex.getString();
}
} else if (token == "\\pdf_subject") {
lex >> subject;
if (lex.isOK()) {
lex.next(true);
subject = lex.getString();
}
} else if (token == "\\pdf_keywords") {
lex >> keywords;
if (lex.isOK()) {
lex.next(true);
keywords = lex.getString();
}
} else if (token == "\\pdf_bookmarks") {
lex >> bookmarks;
} else if (token == "\\pdf_bookmarksnumbered") {
@ -234,7 +246,10 @@ string PDFOptions::readToken(Lexer &lex, string const & token)
} else if (token == "\\pdf_pagemode") {
lex >> pagemode;
} else if (token == "\\pdf_quoted_options") {
lex >> quoted_options;
if (lex.isOK()) {
lex.next(true);
quoted_options = lex.getString();
}
} else {
return token;
}

View File

@ -1151,13 +1151,13 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
<< "\\use_hyperref " << h_use_hyperref << '\n';
if (h_use_hyperref == "true") {
if (!h_pdf_title.empty())
os << "\\pdf_title \"" << h_pdf_title << "\"\n";
os << "\\pdf_title " << Lexer::quoteString(h_pdf_title) << '\n';
if (!h_pdf_author.empty())
os << "\\pdf_author \"" << h_pdf_author << "\"\n";
os << "\\pdf_author " << Lexer::quoteString(h_pdf_author) << '\n';
if (!h_pdf_subject.empty())
os << "\\pdf_subject \"" << h_pdf_subject << "\"\n";
os << "\\pdf_subject " << Lexer::quoteString(h_pdf_subject) << '\n';
if (!h_pdf_keywords.empty())
os << "\\pdf_keywords \"" << h_pdf_keywords << "\"\n";
os << "\\pdf_keywords " << Lexer::quoteString(h_pdf_keywords) << '\n';
os << "\\pdf_bookmarks " << h_pdf_bookmarks << "\n"
"\\pdf_bookmarksnumbered " << h_pdf_bookmarksnumbered << "\n"
"\\pdf_bookmarksopen " << h_pdf_bookmarksopen << "\n"
@ -1170,7 +1170,7 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
if (!h_pdf_pagemode.empty())
os << "\\pdf_pagemode " << h_pdf_pagemode << '\n';
if (!h_pdf_quoted_options.empty())
os << "\\pdf_quoted_options \"" << h_pdf_quoted_options << "\"\n";
os << "\\pdf_quoted_options " << Lexer::quoteString(h_pdf_quoted_options) << '\n';
}
os << "\\papersize " << h_papersize << "\n"
<< "\\use_geometry " << h_use_geometry << '\n';

View File

@ -105,6 +105,8 @@ What's new
- Another attempt to fix NSAutoreleasePool related crashes within LinkBack
driver. Now there is no global static pool used anymore (bug 8637).
- Allow quotes in PDF text properties (bug 9830).
* DOCUMENTATION AND LOCALIZATION