Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set classic locale for PDF export link attributes #3551

Merged
merged 4 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/control/XournalMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ void initLocalisation() {
"xournalpp with msvc",
e.what());
}
/**
* Force numbers to be printed out and parsed by C libraries (cairo) in the "classic" locale.
* This avoids issue with tags when exporting to PDF, see #3551
*/
setlocale(LC_NUMERIC, "C");

std::cout.imbue(std::locale());
}

Expand Down
3 changes: 1 addition & 2 deletions src/control/jobs/PdfExportJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ void PdfExportJob::run() {
doc->unlock();

if (!pdfe->createPdf(this->filepath, false)) {
this->errorMsg = pdfe->getLastError();
if (control->getWindow()) {
callAfterRun();
} else {
this->errorMsg = pdfe->getLastError();
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/pdf/base/XojCairoPdfExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ auto XojCairoPdfExport::startPdf(const fs::path& file) -> bool {
this->populatePdfOutline(tocModel);
#endif

return true;
return cairo_surface_status(this->surface) == CAIRO_STATUS_SUCCESS;
}

#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0)
Expand Down Expand Up @@ -68,6 +68,7 @@ void XojCairoPdfExport::populatePdfOutline(GtkTreeModel* tocModel) {
auto pageDest = pdfBgPage == npos ? npos : doc->findPdfPage(pdfBgPage); // Destination in document
if (pageDest != npos) {
std::ostringstream linkAttrBuf;
linkAttrBuf.imbue(std::locale::classic());
linkAttrBuf << "page=" << pageDest + 1;
if (dest->shouldChangeLeft() && dest->shouldChangeTop()) {
linkAttrBuf << " pos=[" << dest->getLeft() << " " << dest->getTop() << "]";
Expand Down Expand Up @@ -150,6 +151,9 @@ auto XojCairoPdfExport::createPdf(fs::path const& file, PageRangeVector& range,
}

if (!startPdf(file)) {
this->lastError = _("Failed to initialize PDF Cairo surface");
this->lastError += "\nCairo error: ";
this->lastError += cairo_status_to_string(cairo_surface_status(this->surface));
return false;
}

Expand Down Expand Up @@ -192,6 +196,9 @@ auto XojCairoPdfExport::createPdf(fs::path const& file, bool progressiveMode) ->
}

if (!startPdf(file)) {
this->lastError = _("Failed to initialize PDF Cairo surface");
this->lastError += "\nCairo error: ";
this->lastError += cairo_status_to_string(cairo_surface_status(this->surface));
return false;
}

Expand Down