Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
stiglers-eponym committed Aug 22, 2024
2 parents 4b2da68 + db2ee3c commit a9f4457
Show file tree
Hide file tree
Showing 61 changed files with 416 additions and 279 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/package-ubuntu-20.04-qt5-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ jobs:
- name: Configure
run: >
cmake -B build_dir
cmake
-B build_dir
-DUBUNTU_VERSION=20.04
-DUSE_MUPDF=ON
-DUSE_POPPLER=ON
-DUSE_QTPDF=OFF
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/package-ubuntu-20.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
workflow_dispatch:

env:
MUPDF_VERSION: 1.24.6
MUPDF_SHA256SUM: acbdbdc7c0f598aad1ef0fb29313cfe12200147b9ff3616f016370a9b63e9ea7
MUPDF_VERSION: 1.24.8
MUPDF_SHA256SUM: d1a54fcf8de02a8accc3950053f11575f97eb8e206f9385e07b8ff91149775ee

jobs:
package:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-ubuntu-22.04-qt6-mupdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
run: >
cmake
-B build_dir
-DUBUNTU_VERSION=22.04
-DUSE_MUPDF=ON
-DUSE_POPPLER=OFF
-DUSE_QTPDF=OFF
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/package-ubuntu-22.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
workflow_dispatch:

env:
MUPDF_VERSION: 1.24.6
MUPDF_SHA256SUM: acbdbdc7c0f598aad1ef0fb29313cfe12200147b9ff3616f016370a9b63e9ea7
MUPDF_VERSION: 1.24.8
MUPDF_SHA256SUM: d1a54fcf8de02a8accc3950053f11575f97eb8e206f9385e07b8ff91149775ee

jobs:
package:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/package-ubuntu-24.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
workflow_dispatch:

env:
MUPDF_VERSION: 1.24.6
MUPDF_SHA256SUM: acbdbdc7c0f598aad1ef0fb29313cfe12200147b9ff3616f016370a9b63e9ea7
MUPDF_VERSION: 1.24.8
MUPDF_SHA256SUM: d1a54fcf8de02a8accc3950053f11575f97eb8e206f9385e07b8ff91149775ee

jobs:
package:
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ When compiling with Poppler:
* `poppler-qt6`

When compiling with MuPDF:
* `libmupdf` (tested versions: 1.16.1 – 1.24.6)
* `libmupdf` (tested versions: 1.16.1 – 1.24.8)
* `jbig2dec`
* `openjpeg2`
* `gumbo-parser`
Expand Down
4 changes: 2 additions & 2 deletions packaging/io.github.stiglers_eponym.BeamerPresenter-qt5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ modules:
- "/bin"
sources:
- type: archive
url: https://poppler.freedesktop.org/poppler-24.07.0.tar.xz
sha256: 19eb4f49198e4ae3fd9e5a6cf24d0fc7e674e8802046a7de14baab1e40cc2f1d
url: https://poppler.freedesktop.org/poppler-24.08.0.tar.xz
sha256: 97453fbddf0c9a9eafa0ea45ac710d3d49bcf23a62e864585385d3c0b4403174
- name: beamerpresenter
buildsystem: cmake-ninja
config-opts:
Expand Down
4 changes: 2 additions & 2 deletions packaging/io.github.stiglers_eponym.BeamerPresenter-qt6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ modules:
- "/bin"
sources:
- type: archive
url: https://poppler.freedesktop.org/poppler-24.07.0.tar.xz
sha256: 19eb4f49198e4ae3fd9e5a6cf24d0fc7e674e8802046a7de14baab1e40cc2f1d
url: https://poppler.freedesktop.org/poppler-24.08.0.tar.xz
sha256: 97453fbddf0c9a9eafa0ea45ac710d3d49bcf23a62e864585385d3c0b4403174
- name: beamerpresenter
buildsystem: cmake-ninja
config-opts:
Expand Down
2 changes: 1 addition & 1 deletion src/drawing/basicgraphicspath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void BasicGraphicsPath::changeTool(const DrawTool &newtool) noexcept
qWarning() << "Cannot change draw tool to non-drawing base tool.";
return;
}
if (std::abs(newtool.pen().widthF() - _tool.tool()) > 0.01)
if (std::abs(newtool.pen().widthF() - _tool.tool()) > width_tolerance)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
shape_cache.clear();
#else
Expand Down
3 changes: 3 additions & 0 deletions src/drawing/basicgraphicspath.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class QStyleOptionGraphicsItem;
*/
class BasicGraphicsPath : public AbstractGraphicsPath
{
protected:
static constexpr qreal width_tolerance = 0.01;

public:
/// Custom type of QGraphicsItem.
enum { Type = UserType + BasicGraphicsPathType };
Expand Down
12 changes: 12 additions & 0 deletions src/drawing/drawtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ static const QMap<Qt::PenStyle, std::string> pen_style_codes{
{Qt::DashDotLine, "dashdot"}, {Qt::DashDotDotLine, "dashdotdot"},
};

static const QMap<QPainter::CompositionMode, std::string>
composition_mode_codes{
{QPainter::CompositionMode_SourceOver, "source over"},
{QPainter::CompositionMode_Darken, "darken"},
{QPainter::CompositionMode_Lighten, "lighten"},
{QPainter::CompositionMode_Difference, "difference"},
{QPainter::CompositionMode_Plus, "plus"},
{QPainter::CompositionMode_Multiply, "multiply"},
{QPainter::CompositionMode_Screen, "screen"},
{QPainter::CompositionMode_Overlay, "overlay"},
};

static const QList<QPair<Qt::PenStyle, std::string>> pen_style_names{
{Qt::NoPen, QT_TRANSLATE_NOOP("DrawTool", "no pen")},
{Qt::SolidLine, QT_TRANSLATE_NOOP("DrawTool", "solid")},
Expand Down
7 changes: 5 additions & 2 deletions src/drawing/fullgraphicspath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ FullGraphicsPath::FullGraphicsPath(const DrawTool &tool,
}
pressures[i++] = w;
}
max_weight *= 1.05;
max_weight *= tool_width_prefactor;
_tool.setWidth(max_weight);
finalize();
}
Expand All @@ -103,6 +103,7 @@ void FullGraphicsPath::paint(QPainter *painter,
QWidget *widget)
{
if (coordinates.isEmpty()) return;
painter->setCompositionMode(_tool.compositionMode());
QPen pen = _tool.pen();
if (coordinates.length() == 1) {
pen.setWidthF(pressures.first());
Expand Down Expand Up @@ -214,6 +215,7 @@ void FullGraphicsPath::changeWidth(const float newwidth) noexcept
shape_cache = QPainterPath();
#endif
const float scale = newwidth / _tool.width();
_tool.setWidth(newwidth);
auto it = pressures.begin();
while (++it != pressures.end()) *it *= scale;
// cache shape
Expand All @@ -226,9 +228,10 @@ void FullGraphicsPath::changeTool(const DrawTool &newtool) noexcept
qWarning() << "Cannot change draw tool to non-drawing base tool.";
return;
}
_tool.setPen(newtool.pen());
debug_msg(DebugDrawing, "change tool" << newtool.pen() << newtool.width());
const float newwidth = newtool.width();
if (newwidth != _tool.width()) changeWidth(newwidth);
_tool.setPen(newtool.pen());
_tool.brush() = newtool.brush();
_tool.setCompositionMode(newtool.compositionMode());
// cache shape
Expand Down
2 changes: 2 additions & 0 deletions src/drawing/fullgraphicspath.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class QStyleOptionGraphicsItem;
class FullGraphicsPath : public AbstractGraphicsPath
{
private:
static constexpr qreal tool_width_prefactor = 1.05;

/// Vector of pressures (for each stroke segment).
/// coordinates and pressures must always have the same length.
QVector<float> pressures;
Expand Down
37 changes: 24 additions & 13 deletions src/drawing/pathcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ void PathContainer::writeXml(QXmlStreamWriter &writer) const
writer.writeAttribute("width", path->stringWidth());
if (tool.pen().style() != Qt::SolidLine)
writer.writeAttribute(
"style", pen_style_codes.value(tool.pen().style()).c_str());
"style", pen_style_codes.value(tool.pen().style()).c_str(),
"solid");
if (tool.brush().style() != Qt::NoBrush) {
// Compare brush and stroke color.
const QColor &fill = tool.brush().color(),
Expand All @@ -594,8 +595,14 @@ void PathContainer::writeXml(QXmlStreamWriter &writer) const
if (tool.brush().style() != Qt::SolidPattern)
writer.writeAttribute(
"brushstyle",
brush_style_codes.value(tool.brush().style()).c_str());
brush_style_codes.value(tool.brush().style(), "unknown")
.c_str());
}
if (tool.compositionMode() != QPainter::CompositionMode_SourceOver)
writer.writeAttribute(
"composition",
composition_mode_codes.value(tool.compositionMode(), "unknown")
.c_str());
writer.writeCharacters(path->stringCoordinates());
writer.writeEndElement();
break;
Expand All @@ -606,28 +613,26 @@ void PathContainer::writeXml(QXmlStreamWriter &writer) const

AbstractGraphicsPath *loadPath(QXmlStreamReader &reader)
{
const auto attr = reader.attributes();
Tool::BasicTool basic_tool =
string_to_tool.value(reader.attributes().value("tool").toString());
string_to_tool.value(attr.value("tool").toString(), Tool::InvalidTool);
if (!(basic_tool & Tool::AnyDrawTool)) return nullptr;
const QString width_str = reader.attributes().value("width").toString();
const QString width_str = attr.value("width").toString();
if (basic_tool == Tool::Pen && !width_str.contains(' '))
basic_tool = Tool::FixedWidthPen;
QPen pen(rgba_to_color(reader.attributes().value("color").toString()),
QPen pen(rgba_to_color(attr.value("color").toString()),
basic_tool == Tool::Pen ? 1. : width_str.toDouble(),
pen_style_codes.key(
reader.attributes().value("style").toString().toStdString(),
Qt::SolidLine),
pen_style_codes.key(attr.value("style").toString().toStdString(),
Qt::SolidLine),
Qt::RoundCap, Qt::RoundJoin);
if (pen.widthF() <= 0) pen.setWidthF(1.);
// "fill" is the Xournal++ way of storing filling colors. However, it only
// allows one to add transparency to the stroke color.
int fill_xopp = reader.attributes().value("fill").toInt();
int fill_xopp = attr.value("fill").toInt();
// "brushcolor" is a BeamerPresenter extension of the Xournal++ file format
Qt::BrushStyle brush_style = brush_style_codes.key(
reader.attributes().value("brushstyle").toString().toStdString(),
Qt::SolidPattern);
QColor fill_color =
rgba_to_color(reader.attributes().value("brushcolor").toString());
attr.value("brushstyle").toString().toStdString(), Qt::SolidPattern);
QColor fill_color = rgba_to_color(attr.value("brushcolor").toString());
if (!fill_color.isValid()) {
fill_color = pen.color();
if (fill_xopp > 0 && fill_xopp < 256)
Expand All @@ -639,6 +644,12 @@ AbstractGraphicsPath *loadPath(QXmlStreamReader &reader)
basic_tool, Tool::AnyNormalDevice, pen, QBrush(fill_color, brush_style),
basic_tool == Tool::Highlighter ? QPainter::CompositionMode_Darken
: QPainter::CompositionMode_SourceOver);
if (attr.hasAttribute("composition")) {
const QPainter::CompositionMode composition = composition_mode_codes.key(
attr.value("composition").toString().toStdString(),
tool.compositionMode());
tool.setCompositionMode(composition);
}
if (basic_tool == Tool::Pen)
return new FullGraphicsPath(tool, reader.readElementText(), width_str);
else
Expand Down
35 changes: 19 additions & 16 deletions src/drawing/pixmapgraphicsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ constexpr int RANDOM_INT = 42;
/// Generate a random array for glitter transitions.
/// Once shuffled, this array contains the numbers between 0 and GLITTER_NUMBER
/// in random order.
static std::array<unsigned int, GLITTER_NUMBER> &shuffled_array()
static std::array<unsigned int, PixmapGraphicsItem::glitter_number> &
shuffled_array()
{
static std::array<unsigned int, GLITTER_NUMBER> array = {GLITTER_NUMBER + 1};
if (array[0] == GLITTER_NUMBER + 1) {
unsigned int i = 0;
static std::array<unsigned int, PixmapGraphicsItem::glitter_number> array = {
PixmapGraphicsItem::glitter_number + 1};
if (array[0] == PixmapGraphicsItem::glitter_number + 1) {
int i = 0;
do array[i] = i;
while (++i < GLITTER_NUMBER);
while (++i < PixmapGraphicsItem::glitter_number);
}
return array;
}
Expand All @@ -34,14 +36,15 @@ static void reshuffle_array(const int seed = 42)
{
static std::random_device rd;
static std::default_random_engine re(rd());
std::array<unsigned int, GLITTER_NUMBER> &array = shuffled_array();
std::array<unsigned int, PixmapGraphicsItem::glitter_number> &array =
shuffled_array();
std::shuffle(array.begin(), array.end(), re);
}

/// Get random value between 0 and GLITTER_NUMBER from shuffled array.
inline static int shuffled(const unsigned int i)
inline static int shuffled(const int i)
{
return shuffled_array()[i % GLITTER_NUMBER];
return shuffled_array()[i % PixmapGraphicsItem::glitter_number];
}

void PixmapGraphicsItem::paint(QPainter *painter,
Expand Down Expand Up @@ -84,9 +87,9 @@ void PixmapGraphicsItem::paint(QPainter *painter,
QRectF rect_bl(_mask);
path.addRect(rect_bl);
int i = 0;
while (++i < BLINDS_NUMBER_V) {
while (++i < blinds_number_v) {
rect_bl.moveLeft(rect_bl.left() +
bounding_rect.width() / BLINDS_NUMBER_V);
bounding_rect.width() / blinds_number_v);
path.addRect(rect_bl);
}
painter->setClipPath(path);
Expand All @@ -97,9 +100,9 @@ void PixmapGraphicsItem::paint(QPainter *painter,
QRectF rect_bl(_mask);
path.addRect(rect_bl);
int i = 0;
while (++i < BLINDS_NUMBER_H) {
while (++i < blinds_number_h) {
rect_bl.moveTop(rect_bl.top() +
bounding_rect.height() / BLINDS_NUMBER_H);
bounding_rect.height() / blinds_number_h);
path.addRect(rect_bl);
}
painter->setClipPath(path);
Expand All @@ -109,11 +112,11 @@ void PixmapGraphicsItem::paint(QPainter *painter,
}
painter->resetTransform();
if (mask_type == Glitter && animation_progress != UINT_MAX) {
const unsigned int glitter_pixel = pixmap.width() / GLITTER_ROW,
const unsigned int glitter_pixel = pixmap.width() / glitter_row,
n = ref_width * target_rect.height() / glitter_pixel,
w = ref_width / glitter_pixel + 1;
for (unsigned int j = 0; j < animation_progress; j++) {
for (unsigned int i = shuffled(j); i < n; i += GLITTER_NUMBER) {
for (unsigned int i = shuffled(j); i < n; i += glitter_number) {
painter->drawPixmap(target_rect.x() + glitter_pixel * (i % w),
target_rect.y() + glitter_pixel * (i / w), pixmap,
glitter_pixel * (i % w), glitter_pixel * (i / w),
Expand Down Expand Up @@ -190,8 +193,8 @@ bool PixmapGraphicsItem::hasWidth(const unsigned int width) const noexcept
bool PixmapGraphicsItem::hasWidth(const qreal width) const noexcept
{
for (const auto &pix : pixmaps) {
if (pix.width() > width + 0.6) return false;
if (pix.width() > width - 0.6) return true;
if (pix.width() > width + max_width_tolerance) return false;
if (pix.width() > width - max_width_tolerance) return true;
}
return false;
}
11 changes: 6 additions & 5 deletions src/drawing/pixmapgraphicsitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
#include "src/config.h"
#include "src/enumerates.h"

constexpr int BLINDS_NUMBER_H = 6;
constexpr int BLINDS_NUMBER_V = 8;
constexpr int GLITTER_ROW = 71;
constexpr int GLITTER_NUMBER = 137;

class QPainter;
class QWidget;
class QStyleOptionGraphicsItem;
Expand Down Expand Up @@ -55,6 +50,12 @@ class PixmapGraphicsItem : public QGraphicsObject
Glitter,
};

static constexpr int blinds_number_h = 6;
static constexpr int blinds_number_v = 8;
static constexpr int glitter_row = 71;
static constexpr int glitter_number = 137;
static constexpr qreal max_width_tolerance = 0.6;

private:
/// List of pixmaps
QList<QPixmap> pixmaps;
Expand Down
10 changes: 3 additions & 7 deletions src/drawing/pointingtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include <QRadialGradient>
#include <QtConfig>

constexpr qreal POINTER_INNER_RADIUS = 0.1;
constexpr qreal POINTER_OUTER_RADIUS = 0.9;
constexpr int POINTER_OUTER_ALPHA = 12;

void PointingTool::initPointerBrush() noexcept
{
QRadialGradient grad(.5, .5, .5);
Expand All @@ -19,10 +15,10 @@ void PointingTool::initPointerBrush() noexcept
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
#endif
const QColor color = _brush.color();
grad.setColorAt(POINTER_INNER_RADIUS, color);
grad.setColorAt(pointer_inner_radius, color);
QColor semitransparent = color;
semitransparent.setAlpha(POINTER_OUTER_ALPHA);
grad.setColorAt(POINTER_OUTER_RADIUS, semitransparent);
semitransparent.setAlpha(pointer_outer_alpha);
grad.setColorAt(pointer_outer_radius, semitransparent);
semitransparent.setAlpha(0);
grad.setColorAt(1, semitransparent);
_brush = QBrush(grad);
Expand Down
4 changes: 4 additions & 0 deletions src/drawing/pointingtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*/
class PointingTool : public Tool
{
static constexpr qreal pointer_inner_radius = 0.1;
static constexpr qreal pointer_outer_radius = 0.9;
static constexpr int pointer_outer_alpha = 12;

protected:
/// Pointing positions in scene (i.e. page) coordinates.
/// Multiple positions are possible since some input devices can have
Expand Down
Loading

0 comments on commit a9f4457

Please sign in to comment.