From 2ffa977b89f03e247d5f9ed33256df3083ccab11 Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Mon, 7 Aug 2023 15:04:37 +0200 Subject: [PATCH] Fix linear light blend mode in text recordings The name contains a space, which is not allowed for draw dabs messages. We now use an alternate name that doesn't contain a space in those cases, ORA export still uses the Krita-compatible name. --- src/drawdance/libmsg/dpmsg/blend_mode.c | 22 +++++++++++++++++++++- src/drawdance/libmsg/dpmsg/blend_mode.h | 2 ++ src/drawdance/libmsg/dpmsg/text_writer.c | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/drawdance/libmsg/dpmsg/blend_mode.c b/src/drawdance/libmsg/dpmsg/blend_mode.c index 515d44439f..ee5fa238ce 100644 --- a/src/drawdance/libmsg/dpmsg/blend_mode.c +++ b/src/drawdance/libmsg/dpmsg/blend_mode.c @@ -29,6 +29,11 @@ #define INCREASE_OPACITY (1 << 3) #define BLEND_BLANK (1 << 4) +// The Krita name for the linear light blend mode contains a space, which isn't +// supported in draw dabs messages, since they already use the curly brace body +// for the dab data. So we have to use this alternate, spaceless name instead. +#define LINEAR_LIGHT_TEXT_NAME "-dp-linear-light" + typedef struct DP_BlendModeAttributes { int flags; const char *enum_name; @@ -280,6 +285,16 @@ const char *DP_blend_mode_svg_name(int blend_mode) return get_attributes(blend_mode)->svg_name; } +const char *DP_blend_mode_text_name(int blend_mode) +{ + if (blend_mode == DP_BLEND_MODE_LINEAR_LIGHT) { + return LINEAR_LIGHT_TEXT_NAME; + } + else { + return DP_blend_mode_svg_name(blend_mode); + } +} + bool DP_blend_mode_can_increase_opacity(int blend_mode) { return get_attributes(blend_mode)->flags & INCREASE_OPACITY; @@ -307,5 +322,10 @@ DP_BlendMode DP_blend_mode_by_svg_name(const char *svg_name, mode_attributes[DP_BLEND_MODE_REPLACE].svg_name)) { return DP_BLEND_MODE_REPLACE; } - return not_found_value; + else if (DP_str_equal(svg_name, LINEAR_LIGHT_TEXT_NAME)) { + return DP_BLEND_MODE_LINEAR_LIGHT; + } + else { + return not_found_value; + } } diff --git a/src/drawdance/libmsg/dpmsg/blend_mode.h b/src/drawdance/libmsg/dpmsg/blend_mode.h index 544cc8b6e9..cc1170fd7b 100644 --- a/src/drawdance/libmsg/dpmsg/blend_mode.h +++ b/src/drawdance/libmsg/dpmsg/blend_mode.h @@ -71,6 +71,8 @@ const char *DP_blend_mode_enum_name_unprefixed(int blend_mode); const char *DP_blend_mode_svg_name(int blend_mode); +const char *DP_blend_mode_text_name(int blend_mode); + bool DP_blend_mode_can_increase_opacity(int blend_mode); bool DP_blend_mode_can_decrease_opacity(int blend_mode); diff --git a/src/drawdance/libmsg/dpmsg/text_writer.c b/src/drawdance/libmsg/dpmsg/text_writer.c index ccbb9f22bc..cda9fbdd94 100644 --- a/src/drawdance/libmsg/dpmsg/text_writer.c +++ b/src/drawdance/libmsg/dpmsg/text_writer.c @@ -297,7 +297,7 @@ bool DP_text_writer_write_blend_mode(DP_TextWriter *writer, const char *key, DP_ASSERT(writer); DP_ASSERT(key); return DP_text_writer_write_string(writer, key, - DP_blend_mode_svg_name(blend_mode)); + DP_blend_mode_text_name(blend_mode)); } static bool buffer_wrapped_argument(DP_TextWriter *writer, const char *key,