Skip to content

Commit

Permalink
Fix format and compille error in lua_application.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Febbe committed Apr 2, 2024
1 parent f32fac7 commit 6ac6868
Show file tree
Hide file tree
Showing 27 changed files with 90 additions and 82 deletions.
24 changes: 13 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,23 @@ endif()

find_package(ZLIB REQUIRED)
find_package(Threads REQUIRED)

set(CMAKE_FIND_DEBUG_MODE TRUE)
option(ENABLE_PLUGINS "Compile with plugin support" ON)
find_package(Lua) # Lua 5.4 is only supported with cmake >=3.18
find_package(Lua REQUIRED) # Lua 5.4 is only supported with cmake >=3.18
set(CMAKE_FIND_DEBUG_MODE FALSE)
message(STATUS "Found Lua: ${Lua_FOUND}")
if (Lua_FOUND AND ENABLE_PLUGINS)
#if (Lua_FOUND AND ENABLE_PLUGINS)
# currently not fully supported by cmake
message(STATUS "Enable Xournal++ Plugins")
add_library(lua INTERFACE)
target_link_libraries(lua INTERFACE ${LUA_LIBRARIES})
target_include_directories(lua INTERFACE ${LUA_INCLUDE_DIR})
add_library(Lua::lua ALIAS lua)
else ()
message(STATUS "Disable Xournal++ Plugins")
set(ENABLE_PLUGINS OFF)
endif ()
add_library(lua-if INTERFACE)
target_link_libraries(lua-if INTERFACE ${LUA_LIBRARIES})
target_include_directories(lua-if INTERFACE ${LUA_INCLUDE_DIR})
target_compile_definitions(lua-if INTERFACE ENABLE_PLUGINS)
add_library(Lua::lua ALIAS lua-if)
#else ()
# message(STATUS "Disable Xournal++ Plugins")
# set(ENABLE_PLUGINS OFF)
#endif ()

if (GtkSourceView_FOUND)
message("Enable GtkSourceView TeX syntax highlighting")
Expand Down
3 changes: 2 additions & 1 deletion src/core/control/CompassController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ void CompassController::updateOutlineStroke(double x) {
stroke->deletePointsFrom(0);
const auto h = view->getXournal()->getControl()->getToolHandler();
const bool filled = (h->getFill() != -1);
const xoj::util::Point<double> c = xoj::util::Point<double>{geometryTool->getTranslationX(), geometryTool->getTranslationY()};
const xoj::util::Point<double> c =
xoj::util::Point<double>{geometryTool->getTranslationX(), geometryTool->getTranslationY()};

if (filled && angleMax < angleMin + 2 * M_PI) {
stroke->addPoint(Point(c.x, c.y));
Expand Down
2 changes: 1 addition & 1 deletion src/core/control/LatexController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ auto LatexController::loadRendered(string renderedTex) -> std::unique_ptr<TexIma
img->setText(std::move(renderedTex));
img->setX(posx);
img->setY(posy);

if (imgheight > 1024 * std::numeric_limits<double>::epsilon()) {
double ratio = img->getElementWidth() / img->getElementHeight();
img->scale({posx, posy}, ratio, ratio, true);
Expand Down
6 changes: 4 additions & 2 deletions src/core/control/SetsquareController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ auto SetsquareController::posRelToSide(Leg leg, double x, double y) const -> xoj
case HYPOTENUSE:
return xoj::util::Point<double>(x, -y);
case LEFT_LEG:
return xoj::util::Point<double>((y + x) / std::sqrt(2.), (y - x - geometryTool->getHeight()) / std::sqrt(2.));
return xoj::util::Point<double>((y + x) / std::sqrt(2.),
(y - x - geometryTool->getHeight()) / std::sqrt(2.));
case RIGHT_LEG:
return xoj::util::Point<double>((y - x) / std::sqrt(2.), (y + x - geometryTool->getHeight()) / std::sqrt(2.));
return xoj::util::Point<double>((y - x) / std::sqrt(2.),
(y + x - geometryTool->getHeight()) / std::sqrt(2.));
default:
g_error("Invalid enum value: %d", leg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/control/latex/LatexGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ auto LatexGenerator::asyncRun(const fs::path& texDir, const std::string& texFile
return {proc};
}
std::ostringstream ss;
for (char** iter = argv.get(); iter != nullptr && *iter != nullptr ; ++iter) {
for (char** iter = argv.get(); iter != nullptr && *iter != nullptr; ++iter) {
ss << std::string_view(*iter) << ", ";
}
return GenError({FS(_F("Could not start {1}: {2} (exit code: {3}, {4})") % ss.str() % err->message % err->code %
Expand Down
2 changes: 1 addition & 1 deletion src/core/control/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ void Settings::parseItem2(xmlChar* name, xmlChar* value) {
}

void Settings::parseItem(xmlDocPtr doc, xmlNodePtr cur) {
// Parse data map
// Parse data map
if (!xmlStrcmp(cur->name, reinterpret_cast<const xmlChar*>("data"))) {
xmlChar* name = xmlGetProp(cur, reinterpret_cast<const xmlChar*>("name"));
if (name == nullptr) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/control/tools/EditSelectionContents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ InsertionOrder EditSelectionContents::makeMoveEffective(const xoj::util::Rectang
}
if (rotate) {
e->rotate({snappedBounds.x + this->lastSnappedBounds.width / 2,
snappedBounds.y + this->lastSnappedBounds.height / 2}, this->rotation);
snappedBounds.y + this->lastSnappedBounds.height / 2},
this->rotation);
}
}
this->selected.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/core/control/tools/StrokeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ void StrokeHandler::paintTo(Point point) {
void StrokeHandler::drawSegmentTo(const Point& point) {

this->stroke->addPoint(this->hasPressure ? point : Point(point.x, point.y));
this->viewPool->dispatch(xoj::view::StrokeToolView::ADD_POINT_REQUEST, this->stroke->getPointVectorReviewPls().back());
this->viewPool->dispatch(xoj::view::StrokeToolView::ADD_POINT_REQUEST,
this->stroke->getPointVectorReviewPls().back());
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/control/xojfile/LoadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,8 @@ void LoadHandler::fixNullPressureValues() {
strokeOwn->setTransformation(stroke->getTransformation());
strokeOwn->applyStyleFrom(stroke);
strokeOwn->setPointVector(std::move(points));
// stroke = strokeOwn.get(); // Removed: Either all or none of the strokes should be handled after this point
// stroke = strokeOwn.get(); // Removed: Either all or none of the strokes should be handled after this
// point
layer->addElement(std::move(strokeOwn));
});

Expand Down
1 change: 1 addition & 0 deletions src/core/model/AudioElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include <cstddef> // for size_t

#include "util/Point.h"

#include "Element.h" // for Element, ElementType
Expand Down
10 changes: 6 additions & 4 deletions src/core/model/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void Image::readSerialized(ObjectInputStream& in) {

this->Element::readSerialized(in);

imageSize.first = in.readDouble(); // Todo:

imageSize.first = in.readDouble(); // Todo:
imageSize.second = in.readDouble(); // Todo:

if (this->image) {
Expand All @@ -180,15 +180,17 @@ void Image::readSerialized(ObjectInputStream& in) {
this->internalUpdateBounds();
}

auto Image::internalUpdateBounds() const -> std::pair<xoj::util::Rectangle<double>, xoj::util::Rectangle<double>>{
auto Image::internalUpdateBounds() const -> std::pair<xoj::util::Rectangle<double>, xoj::util::Rectangle<double>> {
auto sizes = getImageSize();
auto rect = Rectangle<double>(0, 0, sizes.first, sizes.second);
return {rect, rect};
}

auto Image::hasData() const -> bool { return !this->data.empty(); }

auto Image::getRawData() const -> const unsigned char* { return reinterpret_cast<const unsigned char*>(this->data.data()); }
auto Image::getRawData() const -> const unsigned char* {
return reinterpret_cast<const unsigned char*>(this->data.data());
}

auto Image::getRawDataLength() const -> size_t { return this->data.size(); }

Expand Down
4 changes: 2 additions & 2 deletions src/core/model/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Image final: public Element {
Image(Image const&) = delete;
auto operator=(Image&&) -> Image& = delete;
auto operator=(Image const&) -> Image& = delete;
~Image() override;
~Image() override;

public:
/// Set the image data by copying the data from the provided string_view.
Expand Down Expand Up @@ -93,7 +93,7 @@ class Image final: public Element {

/// Image format information.
mutable GdkPixbufFormat* format = nullptr;
mutable std::pair<int, int> imageSize = {0,0};
mutable std::pair<int, int> imageSize = {0, 0};

std::string data;
};
21 changes: 11 additions & 10 deletions src/core/model/Stroke.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ class Stroke final: public AudioElement {
* @brief Create a partial clone whose points are those of parameters between lowerBound and upperBound
* Assumes both lowerBound and upperBound are valid parameters of the stroke, and lowerBound <= upperBound
*/
auto cloneSection(const PathParameter& lowerBound, const PathParameter& upperBound) const -> std::unique_ptr<Stroke>;
auto cloneSection(const PathParameter& lowerBound, const PathParameter& upperBound) const
-> std::unique_ptr<Stroke>;

/**
* @brief Create a partial clone of a closed stroke (i.e. points.front() == points.back()) with points
* getPoint(startParam) -- ... -- points.back() == points.front() -- ... -- getPoint(endParam)
* Assumes both startParam and endParam are valid parameters of the stroke, and endParam.index < startParam.index
*/
auto cloneCircularSectionOfClosedStroke(const PathParameter& startParam,
const PathParameter& endParam) const -> std::unique_ptr<Stroke>;
auto cloneCircularSectionOfClosedStroke(const PathParameter& startParam, const PathParameter& endParam) const
-> std::unique_ptr<Stroke>;

/**
* Clone style attributes, but not the data (position, width etc.)
Expand Down Expand Up @@ -116,13 +117,13 @@ class Stroke final: public AudioElement {
/// Function should be used with caution, mostly the transformation matrix is required
/// Returns original untranslated points
auto getPointVector() const -> std::vector<Point> const&;
//auto getPointVectorFail() const -> std::pair<xoj::util::Matrix, std::vector<Point> const&>;
// auto getPointVectorFail() const -> std::pair<xoj::util::Matrix, std::vector<Point> const&>;
/// Function should be used with caution, mostly the transformation matrix is required
/// Curious, if this is still correct, pls review ALL occurences
auto getPointVectorReviewPls() const -> std::vector<Point> const& {return getPointVector();}
/// Curious, if this is still correct, pls review ALL occurences
auto getPointVectorReviewPls() const -> std::vector<Point> const& { return getPointVector(); }
/// Known to be an issue, but not fixed yet !!!Todo!!!
auto getPointVectorTodo() const -> std::vector<Point> const& {return getPointVector();}
auto getPointVectorTodo() const -> std::vector<Point> const& { return getPointVector(); }

auto getPoint(size_t index) const -> Point;
auto getPoint(PathParameter parameter) const -> Point;
auto getPoints() const -> const Point*;
Expand Down Expand Up @@ -161,8 +162,8 @@ class Stroke final: public AudioElement {
* Warning: this function does not test if the box intersects the stroke's bounding box.
* For optimization purposes, this test should be performed beforehand by the caller.
*/
auto intersectWithPaddedBox(const PaddedBox& box, size_t firstIndex,
size_t lastIndex) const -> IntersectionParametersContainer;
auto intersectWithPaddedBox(const PaddedBox& box, size_t firstIndex, size_t lastIndex) const
-> IntersectionParametersContainer;

auto intersectWithPaddedBox(const PaddedBox& box) const -> IntersectionParametersContainer;

Expand Down
6 changes: 3 additions & 3 deletions src/core/model/TexImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class TexImage: public Element {
private:
// cache:
xoj::util::Rectangle<double> bounds{};
std::string binaryData; ///< PDF Documents binary data, must stay alive as long as the PDF is used
xoj::util::GObjectSPtr<PopplerDocument> pdf; ///<
std::string binaryData; ///< PDF Documents binary data, must stay alive as long as the PDF is used
xoj::util::GObjectSPtr<PopplerDocument> pdf; ///<

// data:
std::string text; ///< tex expression
std::string text; ///< tex expression
};
6 changes: 3 additions & 3 deletions src/core/model/Text.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ class Text: public AudioElement {
auto findText(const std::string& search) const -> std::vector<XojPdfRectangle>;

private:
// cache:
// cache:
xoj::util::GObjectSPtr<PangoLayout> layout;
// data:
// data:
std::string text;
std::pair<double, double> sizes{0, 0};

XojFont font{"Sans", 12};

bool inEditing = false;
Expand Down
22 changes: 10 additions & 12 deletions src/core/plugin/Plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
#ifdef ENABLE_PLUGINS

#include "Plugin.h"

#include <algorithm> // for max
#include <array> // for array
#include <utility> // for move, pair

#include <gdk/gdk.h> // for GdkModifierType
#include <glib-object.h> // for G_CALLBACK, g_signal_connect
#include <glib.h> // for g_key_file_free, g_warning, g_free

#include "util/Assert.h" // for xoj_assert
#include "util/PathUtil.h" // for toGFilename
#include "util/XojMsgBox.h" // for XojMsgBox

#include "config-features.h" // for ENABLE_PLUGINS

#ifdef ENABLE_PLUGINS

#include <utility> // for move, pair

#include "gui/toolbarMenubar/ToolMenuHandler.h" // for ToolMenuHandler
#include "util/Assert.h" // for xoj_assert
#include "util/PathUtil.h" // for toGFilename
#include "util/XojMsgBox.h" // for XojMsgBox
#include "util/i18n.h" // for _
#include "util/raii/GObjectSPtr.h"

#include "config.h" // for PROJECT_VERSION
#include "config-features.h" // for ENABLE_PLUGINS
#include "config.h" // for PROJECT_VERSION

extern "C" {
#include <lauxlib.h> // for luaL_Reg, luaL_newstate, luaL_requiref
Expand Down Expand Up @@ -250,7 +247,8 @@ void Plugin::loadScript() {
XojMsgBox::showPluginMessage(name, errMsg, true);

// Error out if file can't be read
g_warning("Could not load plugin Lua file. Error: \"%s\", error code: %d (syntax error: %s)", errMsg, status, status == LUA_ERRSYNTAX ? "true" : "false");
g_warning("Could not load plugin Lua file. Error: \"%s\", error code: %d (syntax error: %s)", errMsg, status,
status == LUA_ERRSYNTAX ? "true" : "false");
this->valid = false;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugin/luapi_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,7 @@ static int applib_scaleTextElements(lua_State* L) {
for (auto const& e: elements) {
if (e->getType() == ELEMENT_TEXT) {
Text* t = static_cast<Text*>(e.get());
t->scale(t->getX(), t->getY(), f, f, 0.0, false);
t->scale({t->getX(), t->getY()}, f, f, false);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/core/view/ElementView.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <memory> // for make_unique, unique_ptr

#include <cairo.h>

#include "model/Element.h" // for Element, ELEMENT_IMAGE, ELEMENT_STROKE
Expand Down Expand Up @@ -33,14 +34,12 @@ auto ElementView::createFromElement(const Element* e) -> std::unique_ptr<Element
}
}

auto toCairo(xoj::util::Matrix const& mtx) -> cairo_matrix_t{
return {mtx.a, mtx.c, mtx.b, mtx.d, mtx.tx, mtx.ty};
}
auto toCairo(xoj::util::Matrix const& mtx) -> cairo_matrix_t { return {mtx.a, mtx.c, mtx.b, mtx.d, mtx.tx, mtx.ty}; }

auto ElementView::applyTransform(cairo_t* cr, const Element* e) -> void{
auto ElementView::applyTransform(cairo_t* cr, const Element* e) -> void {
cairo_matrix_t matrix;
cairo_get_matrix(cr, &matrix);
cairo_matrix_t elementMatrix = toCairo(e->getTransformation());
cairo_matrix_multiply(&matrix, &elementMatrix , &matrix);
cairo_matrix_multiply(&matrix, &elementMatrix, &matrix);
cairo_set_matrix(cr, &matrix);
}
5 changes: 3 additions & 2 deletions src/core/view/ErasableStrokeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iterator> // for next
#include <memory> // for allocator_traits<>::value_type
#include <vector> // for vector

#include <cairo.h>

#include "model/LineStyle.h" // for LineStyle
Expand Down Expand Up @@ -44,7 +45,7 @@ void ErasableStrokeView::draw(cairo_t* cr) const {
xoj::util::CairoSaveGuard guard(cr);
cairo_matrix_t matrix2{tm.a, tm.b, tm.c, tm.d, tm.tx, tm.ty};
cairo_matrix_t matrix;
cairo_get_matrix(cr, &matrix);
cairo_get_matrix(cr, &matrix);
cairo_matrix_multiply(&matrix, &matrix, &matrix2);
cairo_set_matrix(cr, &matrix);

Expand Down Expand Up @@ -78,7 +79,7 @@ void ErasableStrokeView::draw(cairo_t* cr) const {
cairo_line_to(cr, q.x, q.y);
cairo_stroke(cr);
}
} else { // Todo: pressure is still scaled by the transformation matrix
} else { // Todo: pressure is still scaled by the transformation matrix
cairo_set_line_width(cr, stroke.getWidth());
Util::cairo_set_dash_from_vector(cr, dashes, 0);

Expand Down
2 changes: 1 addition & 1 deletion src/core/view/ImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void ImageView::draw(const Context& ctx) const {
util::CairoSaveGuard saveGuard(cr);
applyTransform(cr, image);
auto pattern = cairo_pattern_create_for_surface(image->getImage());
cairo_set_source (cr, pattern);
cairo_set_source(cr, pattern);
// make images translucent when highlighting elements with audio, as they can not have audio
if (ctx.fadeOutNonAudio) {
cairo_paint_with_alpha(cr, OPACITY_NO_AUDIO);
Expand Down
1 change: 1 addition & 0 deletions src/core/view/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <cairo.h>
#include <gtk/gtk.h>

#include "util/raii/CairoWrappers.h"

class Element;
Expand Down
6 changes: 4 additions & 2 deletions src/core/view/overlays/StrokeToolView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
using namespace xoj::view;

StrokeToolView::StrokeToolView(const StrokeHandler* strokeHandler, const Stroke& stroke, Repaintable* parent):
BaseStrokeToolView(parent, stroke), strokeHandler(strokeHandler), pointBuffer(stroke.getPointVectorReviewPls()) {
BaseStrokeToolView(parent, stroke),
strokeHandler(strokeHandler),
pointBuffer(stroke.getPointVectorReviewPls()) {
this->registerToPool(strokeHandler->getViewPool());
parent->flagDirtyRegion(Range(stroke.boundingRect()));
}
Expand Down Expand Up @@ -84,7 +86,7 @@ void StrokeToolView::on(StrokeToolView::AddPointRequest, const Point& p) {
xoj_assert(!this->pointBuffer.empty()); // front() is the last point we painted on the mask (see flushBuffer())
Point lastPoint = matrix * this->pointBuffer.back();
this->pointBuffer.emplace_back(p);
this->parent->flagDirtyRegion(this->getRepaintRange(lastPoint, matrix*p));
this->parent->flagDirtyRegion(this->getRepaintRange(lastPoint, matrix * p));
}

void StrokeToolView::on(StrokeToolView::ThickenFirstPointRequest, double newWidth) {
Expand Down

0 comments on commit 6ac6868

Please sign in to comment.