-
Notifications
You must be signed in to change notification settings - Fork 900
Draft: Transformable elements proposal #5596
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
base: master
Are you sure you want to change the base?
Conversation
@xournalpp/core we need to discuss what we want to do with the file format.
But this will be again a lot of work. |
automatical handling of attributes may decrease readability: No good default, therefore using 'Leave'
- added some constexpr to Rectangle and Point - made CairoWrapper `[[nodiscard]]`, its a guard and must not be discarded
- similar to c++23 out_ptr
- seperation of changes, which do not belong to xournalpp#5596 - increases readability of xournalpp#5596
This PR tends to implement one of the most desired enhancements (xournalpp#918), to rotate Images, Text and Latex. For this, I replaced every explicit position, scale and rotation state in the Elements with affine transformations. They are never applied to the data, instead the affine transformation is handled to cairo, which itself applies an affine transformation anyway. This has the advantage, - that we get rotation support out of the box via cairo and - that we can reduce computing power, since only one transformation is applied to each Shape - when cairo drawing uses hardware acceleration, strokes now also will use hardware acceleration for the transformation
6ac6868
to
85b5193
Compare
That sounds reasonable. How would you export a rotated images/text/TeXImages though to an older version? |
Does it though? I do not think so. For hardware acceleration one has to use the Snapshot/Render Nodes approach in Gtk 4. I have created an example of that in Workbench (the Snapshot demo). |
My idea is, to render the rotated PDFs onto a PDF surface and put it as binary data into the xournalpp file. |
I am totally not sure. I've read something about, that this is implementation defined. Could be, that it only works on Linux with OpenGL or that I misinterpreted the section I've read. But nevertheless this approach is also somewhat we definitely should do, when we want to switch to render nodes. It can also simplify, the selection handling in general, since the selection just has to apply its transformation. |
The OpenGL support was removed and has basically unmaintained for a long time before. See e.g. https://news.ycombinator.com/item?id=39442886 I just wanted to argue about this fact about Cairo hardware acceleration, not about the general approach (which makes sense). Yes, in the Snapshot/RenderNodes world using a One thing that looked troublesome to me with the transformation matrix approach is scaling strokes, since the stroke segments get distorted when the transformation is not a similarity. This makes a difference when scaling just in one direction. How do you plan to deal with that? |
Right, I have this on my list. @bhennion has the approach, to add an extra parameter in his transformation matrix (don't have his branch on the hand right now). My approach for strokes would be, to also add a transformation matrix for the stroke size, and to scale it like:
|
|
Yes, you have to checkout my branch and build xournalpp yourself. It's a proposal not a final implementation. So general Feedback about the look and feel is enough. E.g. a feature is missing. Rotating and scaling behaves unexpected. Developers and maintainers should check build warnings and console/debug warnings themself before they merge. This is nothing a user should take care of. |
BuildingSo I build xournalpp from your repo on debian testing, which was inside gnome-boxes (a vm).
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=install
cmake --build .
cmake --build . --target install
./install/bin/xournalpp
TestingTested inserting and rotating…
Log of writing text into xournalpp document (rotation not tested, since it's impossible)
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.297: pango_layout_set_attributes: assertion 'layout != NULL' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.297: pango_layout_set_text: assertion 'layout != NULL' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.297: pango_layout_index_to_pos: assertion 'layout != NULL' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.304: pango_cairo_update_layout: assertion 'PANGO_IS_LAYOUT (layout)' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.304: pango_layout_get_context: assertion 'layout != NULL' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.304: pango_context_set_matrix: assertion 'PANGO_IS_CONTEXT (context)' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.304: pango_cairo_show_layout: assertion 'PANGO_IS_LAYOUT (layout)' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.857: pango_cairo_update_layout: assertion 'PANGO_IS_LAYOUT (layout)' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.857: pango_layout_get_context: assertion 'layout != NULL' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.857: pango_context_set_matrix: assertion 'PANGO_IS_CONTEXT (context)' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.857: pango_cairo_show_layout: assertion 'PANGO_IS_LAYOUT (layout)' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.955: pango_cairo_update_layout: assertion 'PANGO_IS_LAYOUT (layout)' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.955: pango_layout_get_context: assertion 'layout != NULL' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.955: pango_context_set_matrix: assertion 'PANGO_IS_CONTEXT (context)' failed
(com.github.xournalpp.xournalpp:8871): Pango-CRITICAL **: 10:25:25.955: pango_cairo_show_layout: assertion 'PANGO_IS_LAYOUT (layout)' failed –––> Rotation works fine, except for text which cannot be typed and the problem with pen strokes (see xournalpp_rotated.png). Pen Strokes not RotatableSteps to reproduce:
Loading file after saving it.I know you said the following (but I still tested it):
Testing loading saved file after insertion of rotated latex and pictures…
Log (loading saved file which includes rotated objects)
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkXournal': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkViewport': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkScrolledWindow': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkBox': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkPaned': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkBox': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkBox': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkBox': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkOverlay': out of memory
(com.github.xournalpp.xournalpp:9070): Gtk-WARNING **: 10:32:09.340: drawing failure for widget 'GtkApplicationWindow': out of memory –––> loading fails with out of memory error (but multiple gb of memory are available and free) Interessting enough this doesn't happen on my debian oldstable, which is running xournalpp v1.2.3 (gtk 3.24.24, compiled: mar 2 2024, 08:02:26) (see xournalpp_debian_oldstable.png). Files and checksumssha512sum
771c9c5c3bdbaa50a7c3622884025b025d41d567017fcef68e1866f352bfda04e541ffedb71fcb0fc713bc6e8222a67d009c703be2084706081a1d5d270c49cc ./xournalpp_pull_5596.zip sha256sum
66dbd4ff5ae7f5d3fe39ec9f9fa1c2b7ee0815db5c2b5f5ebfbd28cdacecfcbd ./xournalpp_pull_5596.zip |
This PR tends to implement one of the most desired enhancements (#918), to rotate Images, Text and Latex.
For this, I replaced every explicit position, scale and rotation state in the Elements with affine transformations.
They are never applied to the data, instead the affine transformation is handled to cairo, which itself applies an affine transformation anyway.
This has the advantage,
Currently, this is not ready to merge, since several code changes added bugs, which are not fixed yet.
But testers and interested people can test it out and give feedback.
Also, it's not possible, to store the transformations.
fixes #918
fixes #2040
fixes #3622
fixes #4899
It will require changes to #3931 and will simplify the implementation.
Only a mirror matrix must be applied to the selection with a pivot point/dimension.
E.g. Matrix(pivot) * mirrorMatrix * Matrix(-pivot)