Skip to content

Commit

Permalink
Merge branch 'release-1.2' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
bhennion committed Jan 9, 2024
2 parents 2cc386f + 592b276 commit ab2fb62
Show file tree
Hide file tree
Showing 29 changed files with 223 additions and 132 deletions.
3 changes: 3 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ override_dh_auto_build:

override_dh_dwz:
dh_dwz --no-dwz-multifile

override_dh_auto_configure:
dh_auto_configure -- -DCMAKE_BUILD_TYPE=RelWithDebInfo
9 changes: 8 additions & 1 deletion resources/default_template.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
% This template uses the scontents package, which is only available on relatively recent TeX distributions. In case it is not available on your system, use the legacy_template.tex
\documentclass[varwidth=true, crop, border=5pt]{standalone}
\documentclass[varwidth=0.999\maxdimen, crop, border=5pt]{standalone}
% The upper limit value of 'varwidth' can be referenced by \hsize.
\newcommand*{\setTextWidthReference}{%
\setlength{\textwidth}{345.0pt}% Same value when you use 'varwidth=true'.
\setlength{\linewidth}{\textwidth}%
\setlength{\columnwidth}{\textwidth}%
}

% Packages
\usepackage{amsmath}
Expand All @@ -25,6 +31,7 @@
\end{scontents}

\begin{document}
\setTextWidthReference
% Check if the formula is empty
\settoheight{\pheight}{\getstored[1]{preview}}%
\ifthenelse{\pheight=0}{\GenericError{}{xournalpp:blankformula}{}{}}
Expand Down
9 changes: 8 additions & 1 deletion resources/legacy_template.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
% This template avoids the scontents package, which is only available on relatively recent TeX distributions
\documentclass[varwidth=true, crop, border=5pt]{standalone}
\documentclass[varwidth=0.999\maxdimen, crop, border=5pt]{standalone}
% The upper limit value of 'varwidth' can be referenced by \hsize.
\newcommand*{\setTextWidthReference}{%
\setlength{\textwidth}{345.0pt}% Same value when you use 'varwidth=true'.
\setlength{\linewidth}{\textwidth}%
\setlength{\columnwidth}{\textwidth}%
}

% Packages
\usepackage{amsmath}
Expand All @@ -21,6 +27,7 @@
}

\begin{document}
\setTextWidthReference
% Check if the formula is empty
\settoheight{\pheight}{\preview}
\ifthenelse{\pheight=0}{\GenericError{}{xournalpp:blankformula}{}{}}
Expand Down
2 changes: 1 addition & 1 deletion src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ constexpr auto PROJECT_STRING = "@PROJECT_NAME@ @PROJECT_VERSION@";
/**
* Project URL
*/
constexpr auto PROJECT_URL = "@PROJECT_URL@";
constexpr auto PROJECT_HOMEPAGE_URL = "@PROJECT_HOMEPAGE_URL@";

/**
* File format version
Expand Down
68 changes: 19 additions & 49 deletions src/core/control/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Control::~Control() {
g_source_remove(this->changeTimout);
this->enableAutosave(false);

deleteLastAutosaveFile("");
deleteLastAutosaveFile();
this->scheduler->stop();
this->changedPages.clear(); // can be removed, will be done by implicit destructor

Expand Down Expand Up @@ -208,55 +208,29 @@ Control::~Control() {
this->layerController = nullptr;
}


void Control::renameLastAutosaveFile() {
if (this->lastAutosaveFilename.empty()) {
return;
}

auto const& filename = this->lastAutosaveFilename;
auto renamed = Util::getAutosaveFilepath();
Util::clearExtensions(renamed);
if (!filename.empty() && filename.string().front() != '.') {
// This file must be a fresh, unsaved document. Since this file is
// already in the autosave directory, we need to change the renamed filename.
renamed += ".old.autosave.xopp";
} else {
// The file is a saved document with the form ".<filename>.autosave.xopp"
renamed += filename.filename();
}

g_message("%s", FS(_F("Autosave renamed from {1} to {2}") % this->lastAutosaveFilename.string() % renamed.string())
.c_str());

if (!fs::exists(filename)) {
this->save(false);
}

std::vector<string> errors;
void Control::setLastAutosaveFile(fs::path newAutosaveFile) {
try {
Util::safeRenameFile(filename, renamed);
if (!fs::equivalent(newAutosaveFile, this->lastAutosaveFilename) && fs::exists(newAutosaveFile)) {
deleteLastAutosaveFile();
}
} catch (const fs::filesystem_error& e) {
auto fmtstr = _F("Could not rename autosave file from \"{1}\" to \"{2}\": {3}");
errors.emplace_back(FS(fmtstr % filename.u8string() % renamed.u8string() % e.what()));
}


if (!errors.empty()) {
string error = std::accumulate(errors.begin() + 1, errors.end(), *errors.begin(),
[](const string& e1, const string& e2) { return e1 + "\n" + e2; });
Util::execInUiThread([=]() {
string msg = FS(_F("Autosave failed with an error: {1}") % error);
XojMsgBox::showErrorToUser(getGtkWindow(), msg);
});
auto fmtstr = FS(_F("Filesystem error: {2}") % e.what());
Util::execInUiThread([fmtstr, win = getGtkWindow()]() { XojMsgBox::showErrorToUser(win, fmtstr); });
}
this->lastAutosaveFilename = std::move(newAutosaveFile);
}

void Control::setLastAutosaveFile(fs::path newAutosaveFile) { this->lastAutosaveFilename = std::move(newAutosaveFile); }

void Control::deleteLastAutosaveFile(fs::path newAutosaveFile) {
fs::remove(this->lastAutosaveFilename);
this->lastAutosaveFilename = std::move(newAutosaveFile);
void Control::deleteLastAutosaveFile() {
try {
if (fs::exists(this->lastAutosaveFilename)) {
fs::remove(this->lastAutosaveFilename);
}
} catch (const fs::filesystem_error& e) {
auto fmtstr = FS(_F("Could not remove old autosave file \"{1}\": {2}") % this->lastAutosaveFilename.string() %
e.what());
Util::execInUiThread([fmtstr, win = getGtkWindow()]() { XojMsgBox::showErrorToUser(win, fmtstr); });
}
this->lastAutosaveFilename.clear();
}

auto Control::checkChangedDocument(Control* control) -> bool {
Expand Down Expand Up @@ -337,10 +311,6 @@ auto Control::autosaveCallback(Control* control) -> bool {
return true;
}


g_message("Info: autosave document...");


auto* job = new AutosaveJob(control);
control->scheduler->addJob(job, JOB_PRIORITY_NONE);
job->unref();
Expand Down
3 changes: 1 addition & 2 deletions src/core/control/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ class Control:
void block(const std::string& name);
void unblock();

void renameLastAutosaveFile();
void setLastAutosaveFile(fs::path newAutosaveFile);
void deleteLastAutosaveFile(fs::path newAutosaveFile);
void deleteLastAutosaveFile();
void setClipboardHandlerSelection(EditSelection* selection);

void addChangedDocumentListener(DocumentListener* dl);
Expand Down
2 changes: 1 addition & 1 deletion src/core/control/CrashHandlerUnix.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void crashHandler(int sig) {

free(messages);

fp << "\n\nTry to get a better stracktrace...\n";
fp << "\n\nTry to get a better stacktrace...\n";

Stacktrace::printStracktrace(fp);

Expand Down
8 changes: 8 additions & 0 deletions src/core/control/ToolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,14 @@ auto ToolHandler::isSinglePageTool() const -> bool {
toolType == TOOL_SELECT_PDF_TEXT_RECT;
}

auto ToolHandler::acceptsOutOfPageEvents() const -> bool {
ToolType toolType = this->getToolType();
DrawingType drawingType = this->getDrawingType();

return ((toolType == TOOL_PEN || toolType == TOOL_HIGHLIGHTER) && (drawingType == DRAWING_TYPE_SPLINE)) ||
(toolType == TOOL_DRAW_SPLINE);
}

auto ToolHandler::supportsTapFilter() const -> bool {
ToolType toolType = this->getToolType();

Expand Down
6 changes: 6 additions & 0 deletions src/core/control/ToolHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ class ToolHandler {
*/
bool isSinglePageTool() const;

/**
* Returns whether the current tool accepts events from outside the page input started in (i.e. events
* should not be clamped to the page)
*/
bool acceptsOutOfPageEvents() const;

/**
* @brief Whether the tool supports short taps filtering (for floating toolbox or selection)
* see Preferences->Drawing Area->Action on Tool tap
Expand Down
24 changes: 19 additions & 5 deletions src/core/control/jobs/AutosaveJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,32 @@ void AutosaveJob::run() {
Util::clearExtensions(filepath);
filepath += ".autosave.xopp";

control->renameLastAutosaveFile();

g_message("%s", FS(_F("Autosaving to {1}") % filepath.string()).c_str());

handler.saveTo(filepath);
fs::path tempfile = filepath;
tempfile += u8"~";
handler.saveTo(tempfile);

this->error = handler.getErrorMessage();
if (!this->error.empty()) {
callAfterRun();
} else {
// control->deleteLastAutosaveFile(filepath);
control->setLastAutosaveFile(filepath);
try {
if (fs::exists(filepath)) {
fs::path swaptmpfile = filepath;
swaptmpfile += u8".swap";
Util::safeRenameFile(filepath, swaptmpfile);
Util::safeRenameFile(tempfile, filepath);
// All went well, we can delete the old autosave file
fs::remove(swaptmpfile);
} else {
Util::safeRenameFile(tempfile, filepath);
}
control->setLastAutosaveFile(filepath);
} catch (const fs::filesystem_error& e) {
auto fmtstr = _F("Could not rename autosave file from \"{1}\" to \"{2}\": {3}");
this->error = FS(fmtstr % tempfile.u8string() % filepath.u8string() % e.what());
}
}
}

Expand Down
11 changes: 2 additions & 9 deletions src/core/control/latex/LatexGenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "LatexGenerator.h"

#include <iomanip> // for operator<<, setfill, setw
#include <regex> // for smatch, sregex_iterator
#include <sstream> // for ostringstream, basic_ost...
#include <regex> // for smatch, sregex_iterator

#include <glib.h> // for GError, gchar, g_error_free
#include <poppler.h> // for g_object_unref
Expand All @@ -15,7 +13,6 @@
#include "util/raii/GLibGuards.h" // for GErrorGuard, GStrvGuard
#include "util/raii/GObjectSPtr.h" // for GObjectSptr
#include "util/safe_casts.h" // for as_signed
#include "util/serdesstream.h" // for serdes_stream


using namespace xoj::util;
Expand All @@ -36,11 +33,7 @@ auto LatexGenerator::templateSub(const std::string& input, const std::string& te
if (matchStr == "TOOL_INPUT") {
repl = input;
} else if (matchStr == "TEXT_COLOR") {
auto s = serdes_stream<std::ostringstream>();
auto tmp_color = textColor;
tmp_color.alpha = 0;
s << std::hex << std::setfill('0') << std::setw(6) << std::right << tmp_color;
repl = s.str();
repl = Util::rgb_to_hex_string(textColor).substr(1);
}
output.append(templ, templatePos, as_unsigned(match.position()) - templatePos);
output.append(repl);
Expand Down
9 changes: 2 additions & 7 deletions src/core/control/settings/PageTemplateSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "PageTemplateSettings.h"

#include <cinttypes> // for PRIx32
#include <cstdint> // for uint32_t
#include <cstdio> // for snprintf, size_t
#include <sstream> // for basic_istream, strings...
#include <sstream> // for basic_istream, strings...

#include "control/pagetype/PageTypeHandler.h" // for PageTypeHandler

Expand Down Expand Up @@ -116,9 +113,7 @@ auto PageTemplateSettings::toString() const -> string {
str += string("backgroundTypeConfig=") + backgroundType.config + "\n";
}

char buffer[64];
snprintf(buffer, sizeof(buffer), "#%06" PRIx32, uint32_t{this->backgroundColor});
str += string("backgroundColor=") + buffer + "\n";
str += string("backgroundColor=") + Util::rgb_to_hex_string(this->backgroundColor) + "\n";

return str;
}
8 changes: 7 additions & 1 deletion src/core/control/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,13 @@ auto Settings::getMainWndHeight() const -> int { return this->mainWndHeight; }

auto Settings::isMainWndMaximized() const -> bool { return this->maximized; }

void Settings::setMainWndMaximized(bool max) { this->maximized = max; }
void Settings::setMainWndMaximized(bool max) {
if (this->maximized == max) {
return;
}
this->maximized = max;
save();
}

void Settings::setSelectedToolbar(const string& name) {
if (this->selectedToolbar == name) {
Expand Down
8 changes: 6 additions & 2 deletions src/core/control/tools/PdfElemSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ auto PdfElemSelection::finalizeSelectionAndRepaint(XojPdfPageSelectionStyle styl
Range rg = getRegionBbox();
bool result = this->finalizeSelection(style);
rg = rg.unite(getRegionBbox());
this->viewPool->dispatch(xoj::view::PdfElementSelectionView::FLAG_DIRTY_REGION_REQUEST, rg);
if (!rg.empty()) {
this->viewPool->dispatch(xoj::view::PdfElementSelectionView::FLAG_DIRTY_REGION_REQUEST, rg);
}
return result;
}

Expand Down Expand Up @@ -110,7 +112,9 @@ void PdfElemSelection::currentPos(double x, double y, XojPdfPageSelectionStyle s
xoj_assert(this->selectedTextRegion);

rg = rg.unite(getRegionBbox());
this->viewPool->dispatch(xoj::view::PdfElementSelectionView::FLAG_DIRTY_REGION_REQUEST, rg);
if (!rg.empty()) {
this->viewPool->dispatch(xoj::view::PdfElementSelectionView::FLAG_DIRTY_REGION_REQUEST, rg);
}
}

auto PdfElemSelection::contains(double x, double y) -> bool {
Expand Down
10 changes: 6 additions & 4 deletions src/core/control/xojfile/SaveHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void SaveHandler::prepareSave(Document* doc) {
void SaveHandler::writeHeader() {
this->root->setAttrib("creator", PROJECT_STRING);
this->root->setAttrib("fileversion", FILE_FORMAT_VERSION);
this->root->addChild(new XmlTextNode("title", std::string{"Xournal++ document - see "} + PROJECT_URL));
this->root->addChild(new XmlTextNode("title", std::string{"Xournal++ document - see "} + PROJECT_HOMEPAGE_URL));
}

auto SaveHandler::getColorStr(Color c, unsigned char alpha) -> std::string {
Expand All @@ -89,9 +89,11 @@ auto SaveHandler::getColorStr(Color c, unsigned char alpha) -> std::string {
}

void SaveHandler::writeTimestamp(AudioElement* audioElement, XmlAudioNode* xmlAudioNode) {
/** set stroke timestamp value to the XmlPointNode */
xmlAudioNode->setAttrib("ts", audioElement->getTimestamp());
xmlAudioNode->setAttrib("fn", audioElement->getAudioFilename().u8string());
if (!audioElement->getAudioFilename().empty()) {
/** set stroke timestamp value to the XmlPointNode */
xmlAudioNode->setAttrib("ts", audioElement->getTimestamp());
xmlAudioNode->setAttrib("fn", audioElement->getAudioFilename().u8string());
}
}

void SaveHandler::visitStroke(XmlPointNode* stroke, Stroke* s) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/control/xojfile/XojExportHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void XojExportHandler::writeHeader() {
// Keep this version on 2, as this is anyway not read by Xournal
this->root->setAttrib("fileversion", "2");
this->root->addChild(
new XmlTextNode("title", std::string{"Xournal document (Compatibility) - see "} + PROJECT_URL));
new XmlTextNode("title", std::string{"Xournal document (Compatibility) - see "} + PROJECT_HOMEPAGE_URL));
}

void XojExportHandler::writeSolidBackground(XmlNode* background, PageRef p) {
Expand Down
11 changes: 7 additions & 4 deletions src/core/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ MainWindow::MainWindow(GladeSearchpath* gladeSearchPath, Control* control, GtkAp
// Window handler
g_signal_connect(this->window, "delete-event", xoj::util::wrap_for_g_callback_v<deleteEventCallback>,
this->control);
g_signal_connect(this->window, "window_state_event", xoj::util::wrap_for_g_callback_v<windowStateEventCallback>,
#if GTK_MAJOR_VERSION == 3
g_signal_connect(this->window, "notify::is-maximized", xoj::util::wrap_for_g_callback_v<windowMaximizedCallback>,
this);
#else
g_signal_connect(this->window, "notify::maximized", xoj::util::wrap_for_g_callback_v<windowMaximizedCallback>,
this);
#endif

// "watch over" all key events
g_signal_connect(this->window, "key-press-event", G_CALLBACK(gtk_window_propagate_key_event), nullptr);
Expand Down Expand Up @@ -407,10 +412,8 @@ auto MainWindow::setFullscreen(bool enabled) const -> void {

auto MainWindow::getXournal() const -> XournalView* { return xournal.get(); }

auto MainWindow::windowStateEventCallback(GtkWidget* window, GdkEventWindowState* event, MainWindow* win) -> bool {
auto MainWindow::windowMaximizedCallback(GObject* window, GParamSpec*, MainWindow* win) -> void {
win->setMaximized(gtk_window_is_maximized(GTK_WINDOW(window)));

return false;
}

void MainWindow::toolbarSelected(const std::string& id) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class MainWindow: public GladeGui {
static bool deleteEventCallback(GtkWidget* widget, GdkEvent* event, Control* control);

/**
* Callback fro window states, we ned to know if the window is fullscreen
* Window is maximized/minimized
*/
static bool windowStateEventCallback(GtkWidget* window, GdkEventWindowState* event, MainWindow* win);
static void windowMaximizedCallback(GObject* window, GParamSpec*, MainWindow* win);

/**
* Callback for drag & drop files
Expand Down

0 comments on commit ab2fb62

Please sign in to comment.