Submitted By:            Douglas R. Reno <renodr at linuxfromscratch dot org>
Date:                    2024-04-01
Updated Date:            2024-05-14
Initial Package Version: 1.3.2
Origin:                  Upstream (!6209, 1798e9c13b786f3d077ba0132592c4d5c1d1fb9b, !6418)
Upstream Status:         Applied
Description:             Fixes building Inkscape with poppler-24.03.0 by adapting
                         to the poppler commit "Use an enum for Function getType."
                         This patch maintains compatibility with previous
                         versions of poppler as well for users who are using
                         previous versions.
                         Updated 2024-05-14: Updated to fix build breakage against
                         poppler-24.05.0. In poppler-24.05.0, hasUnicodeMarkerLE
                         and hasUnicodeMarker were moved to UTF.h and renamed.
                         As part of this, Inkscape is also updated to use C++20.

diff -Naurp inkscape-1.3.2_2023-11-25_091e20ef0f.orig/_clang-format inkscape-1.3.2_2023-11-25_091e20ef0f/_clang-format
--- inkscape-1.3.2_2023-11-25_091e20ef0f.orig/_clang-format	2024-05-14 13:36:42.595491728 -0500
+++ inkscape-1.3.2_2023-11-25_091e20ef0f/_clang-format	2024-05-14 14:29:05.126840764 -0500
@@ -103,7 +103,7 @@ SpacesInContainerLiterals: false
 SpacesInCStyleCastParentheses: false
 SpacesInParentheses: false
 SpacesInSquareBrackets: false
-Standard:        c++17
+Standard:        c++20
 StatementMacros: []
 TypenameMacros: []
 TabWidth: 4
diff -Naurp inkscape-1.3.2_2023-11-25_091e20ef0f.orig/CMakeLists.txt inkscape-1.3.2_2023-11-25_091e20ef0f/CMakeLists.txt
--- inkscape-1.3.2_2023-11-25_091e20ef0f.orig/CMakeLists.txt	2024-05-14 13:36:42.599491696 -0500
+++ inkscape-1.3.2_2023-11-25_091e20ef0f/CMakeLists.txt	2024-05-14 14:28:51.245956491 -0500
@@ -18,9 +18,9 @@ message("Binary Dir: ${CMAKE_CURRENT_BIN
 # -----------------------------------------------------------------------------
 # CMake Configuration
 # -----------------------------------------------------------------------------
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
-# set(CMAKE_CXX_EXTENSIONS OFF) # enforces -std=c++17 instead of -std=gnu++17
+# set(CMAKE_CXX_EXTENSIONS OFF) # enforces -std=c++20 instead of -std=gnu++20
                                 # TODO: build currently fails with it as we actually depend on GNU compiler extensions...
 
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeScripts/Modules")
diff -Naurp inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/extension/internal/pdfinput/poppler-transition-api.h inkscape-1.3.2_2023-11-25_091e20ef0f/src/extension/internal/pdfinput/poppler-transition-api.h
--- inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/extension/internal/pdfinput/poppler-transition-api.h	2024-05-14 13:36:43.045488088 -0500
+++ inkscape-1.3.2_2023-11-25_091e20ef0f/src/extension/internal/pdfinput/poppler-transition-api.h	2024-05-14 13:42:31.772537051 -0500
@@ -13,6 +13,25 @@
 #define SEEN_POPPLER_TRANSITION_API_H
 
 #include <glib/poppler-features.h>
+#include <poppler/UTF.h>
+
+#if POPPLER_CHECK_VERSION(24, 5, 0)
+#define _POPPLER_HAS_UNICODE_BOM(value) (hasUnicodeByteOrderMark(value->toStr()))
+#define _POPPLER_HAS_UNICODE_BOMLE(value) (hasUnicodeByteOrderMarkLE(value->toStr()))
+#else
+#define _POPPLER_HAS_UNICODE_BOM(value) (value->hasUnicodeMarker())
+#define _POPPLER_HAS_UNICODE_BOMLE(value) (value->hasUnicodeMarkerLE())
+#endif
+
+#if POPPLER_CHECK_VERSION(24, 3, 0)
+#define _POPPLER_FUNCTION_TYPE_SAMPLED Function::Type::Sampled
+#define _POPPLER_FUNCTION_TYPE_EXPONENTIAL Function::Type::Exponential
+#define _POPPLER_FUNCTION_TYPE_STITCHING Function::Type::Stitching
+#else
+#define _POPPLER_FUNCTION_TYPE_SAMPLED 0
+#define _POPPLER_FUNCTION_TYPE_EXPONENTIAL 2
+#define _POPPLER_FUNCTION_TYPE_STITCHING 3
+#endif
 
 #if POPPLER_CHECK_VERSION(22, 4, 0)
 #define _POPPLER_FONTPTR_TO_GFX8(font_ptr) ((Gfx8BitFont *)font_ptr.get())
diff -Naurp inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/extension/internal/pdfinput/poppler-utils.cpp inkscape-1.3.2_2023-11-25_091e20ef0f/src/extension/internal/pdfinput/poppler-utils.cpp
--- inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/extension/internal/pdfinput/poppler-utils.cpp	2024-05-14 13:36:43.045488088 -0500
+++ inkscape-1.3.2_2023-11-25_091e20ef0f/src/extension/internal/pdfinput/poppler-utils.cpp	2024-05-14 13:43:25.204047386 -0500
@@ -12,6 +12,8 @@
 
 #include "poppler-utils.h"
 
+#include <poppler/UTF.h>
+
 #include "2geom/affine.h"
 #include "GfxFont.h"
 #include "GfxState.h"
@@ -563,10 +565,10 @@ std::string getDictString(Dict *dict, co
  */
 std::string getString(const GooString *value)
 {
-    if (value->hasUnicodeMarker()) {
+    if (_POPPLER_HAS_UNICODE_BOM(value)) {
         return g_convert(value->getCString () + 2, value->getLength () - 2,
                          "UTF-8", "UTF-16BE", NULL, NULL, NULL);
-    } else if (value->hasUnicodeMarkerLE()) {
+    } else if (_POPPLER_HAS_UNICODE_BOMLE(value)) {
         return g_convert(value->getCString () + 2, value->getLength () - 2,
                          "UTF-8", "UTF-16LE", NULL, NULL, NULL);
     }
diff -Naurp inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/extension/internal/pdfinput/svg-builder.cpp inkscape-1.3.2_2023-11-25_091e20ef0f/src/extension/internal/pdfinput/svg-builder.cpp
--- inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/extension/internal/pdfinput/svg-builder.cpp	2024-05-14 13:36:43.045488088 -0500
+++ inkscape-1.3.2_2023-11-25_091e20ef0f/src/extension/internal/pdfinput/svg-builder.cpp	2024-05-14 13:36:50.574427191 -0500
@@ -1158,9 +1158,9 @@ static bool svgGetShadingColor(GfxShadin
 #define INT_EPSILON 8
 bool SvgBuilder::_addGradientStops(Inkscape::XML::Node *gradient, GfxShading *shading,
                                    _POPPLER_CONST Function *func) {
-    int type = func->getType();
+    auto type = func->getType();
     auto space = shading->getColorSpace();
-    if ( type == 0 || type == 2 ) {  // Sampled or exponential function
+    if ( type == _POPPLER_FUNCTION_TYPE_SAMPLED || type == _POPPLER_FUNCTION_TYPE_EXPONENTIAL ) {
         GfxColor stop1, stop2;
         if (!svgGetShadingColor(shading, 0.0, &stop1) || !svgGetShadingColor(shading, 1.0, &stop2)) {
             return false;
@@ -1168,7 +1168,7 @@ bool SvgBuilder::_addGradientStops(Inksc
             _addStopToGradient(gradient, 0.0, &stop1, space, 1.0);
             _addStopToGradient(gradient, 1.0, &stop2, space, 1.0);
         }
-    } else if ( type == 3 ) { // Stitching
+    } else if ( type == _POPPLER_FUNCTION_TYPE_STITCHING ) {
         auto stitchingFunc = static_cast<_POPPLER_CONST StitchingFunction*>(func);
         const double *bounds = stitchingFunc->getBounds();
         const double *encode = stitchingFunc->getEncode();
@@ -1183,7 +1183,7 @@ bool SvgBuilder::_addGradientStops(Inksc
         for ( int i = 0 ; i < num_funcs ; i++ ) {
             svgGetShadingColor(shading, bounds[i + 1], &color);
             // Add stops
-            if (stitchingFunc->getFunc(i)->getType() == 2) {    // process exponential fxn
+            if (stitchingFunc->getFunc(i)->getType() == _POPPLER_FUNCTION_TYPE_EXPONENTIAL) {
                 double expE = (static_cast<_POPPLER_CONST ExponentialFunction*>(stitchingFunc->getFunc(i)))->getE();
                 if (expE > 1.0) {
                     expE = (bounds[i + 1] - bounds[i])/expE;    // approximate exponential as a single straight line at x=1
diff -Naurp inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/ui/dialog/filter-effects-dialog.cpp inkscape-1.3.2_2023-11-25_091e20ef0f/src/ui/dialog/filter-effects-dialog.cpp
--- inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/ui/dialog/filter-effects-dialog.cpp	2024-05-14 13:36:42.996488485 -0500
+++ inkscape-1.3.2_2023-11-25_091e20ef0f/src/ui/dialog/filter-effects-dialog.cpp	2024-05-14 22:08:50.589968374 -0500
@@ -202,7 +202,7 @@ public:
 template< typename T> class ComboWithTooltip : public Gtk::EventBox
 {
 public:
-    ComboWithTooltip<T>(T default_value, const Util::EnumDataConverter<T>& c, const SPAttr a = SPAttr::INVALID, char* tip_text = nullptr)
+    ComboWithTooltip(T const default_value, Util::EnumDataConverter<T> const &c, SPAttr const a = SPAttr::INVALID, char* tip_text = nullptr)
     {
         if (tip_text) {
             set_tooltip_text(tip_text);
diff -Naurp inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/ui/knot/knot-holder-entity.cpp inkscape-1.3.2_2023-11-25_091e20ef0f/src/ui/knot/knot-holder-entity.cpp
--- inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/ui/knot/knot-holder-entity.cpp	2024-05-14 13:36:43.014488339 -0500
+++ inkscape-1.3.2_2023-11-25_091e20ef0f/src/ui/knot/knot-holder-entity.cpp	2024-05-14 14:29:55.514420757 -0500
@@ -329,7 +329,7 @@ PatternKnotHolderEntityScale::knot_set(G
     double scale_x = std::clamp(new_extent[X] / _cached_diagonal[X], _cached_min_scale, 1e9);
     double scale_y = std::clamp(new_extent[Y] / _cached_diagonal[Y], _cached_min_scale, 1e9);
 
-    Affine new_transform = (state & GDK_CONTROL_MASK) ? Scale(lerp(0.5, scale_x, scale_y))
+    Affine new_transform = (state & GDK_CONTROL_MASK) ? Scale((scale_x + scale_y) * 0.5)
                                                       : Scale(scale_x, scale_y);
 
     // 2. Calculate offset to keep pattern origin aligned
diff -Naurp inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/ui/tools/pencil-tool.cpp inkscape-1.3.2_2023-11-25_091e20ef0f/src/ui/tools/pencil-tool.cpp
--- inkscape-1.3.2_2023-11-25_091e20ef0f.orig/src/ui/tools/pencil-tool.cpp	2024-05-14 13:36:43.012488355 -0500
+++ inkscape-1.3.2_2023-11-25_091e20ef0f/src/ui/tools/pencil-tool.cpp	2024-05-14 14:30:56.846909680 -0500
@@ -17,7 +17,11 @@
  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
  */
 
+#include "pencil-tool.h"
+
+#include <cmath> // std::lerp
 #include <numeric> // For std::accumulate
+
 #include <gdk/gdkkeysyms.h>
 #include <glibmm/i18n.h>
 
@@ -26,8 +30,6 @@
 #include <2geom/sbasis-to-bezier.h>
 #include <2geom/svg-path-parser.h>
 
-#include "pencil-tool.h"
-
 #include "context-fns.h"
 #include "desktop.h"
 #include "desktop-style.h"
@@ -814,7 +816,7 @@ void PencilTool::_addFreehandPoint(Geom:
             min = max;
         }
         double dezoomify_factor = 0.05 * 1000 / _desktop->current_zoom();
-        double const pressure_shrunk = pressure * (max - min) + min; // C++20 -> use std::lerp()
+        double const pressure_shrunk = std::lerp(min, max, pressure);
         double pressure_computed = std::abs(pressure_shrunk * dezoomify_factor);
         double pressure_computed_scaled = std::abs(pressure_computed * _desktop->getDocument()->getDocumentScale().inverse()[Geom::X]);
         if (p != this->p[this->_npoints - 1]) {
