Hello community,

here is the log from the commit of package swappy for openSUSE:Factory checked 
in at 2020-07-14 08:00:06
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/swappy (Old)
 and      /work/SRC/openSUSE:Factory/.swappy.new.3060 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "swappy"

Tue Jul 14 08:00:06 2020 rev:2 rq:820629 version:1.2.1

Changes:
--------
--- /work/SRC/openSUSE:Factory/swappy/swappy.changes    2020-07-06 
16:37:10.816617401 +0200
+++ /work/SRC/openSUSE:Factory/.swappy.new.3060/swappy.changes  2020-07-14 
08:01:04.822137536 +0200
@@ -1,0 +2,7 @@
+Mon Jul 13 06:15:12 UTC 2020 - Michael Vetter <[email protected]>
+
+- Update to 1.2.1:
+  Bug Fixes:
+  * text: properly handle utf-8 chars (717ab0c), closes #43
+
+-------------------------------------------------------------------

Old:
----
  swappy-1.2.0.tar.gz.asc
  v1.2.0.tar.gz

New:
----
  swappy-1.2.1.tar.gz.sig
  v1.2.1.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ swappy.spec ++++++
--- /var/tmp/diff_new_pack.GzNUeq/_old  2020-07-14 08:01:06.666143507 +0200
+++ /var/tmp/diff_new_pack.GzNUeq/_new  2020-07-14 08:01:06.670143520 +0200
@@ -1,6 +1,7 @@
+#
 # spec file for package swappy
 #
-# Copyright (c) 2020 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2020 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -16,14 +17,14 @@
 
 
 Name:           swappy
-Version:        1.2.0
+Version:        1.2.1
 Release:        0
 Summary:        Wayland compositor screenshot editor
 License:        MIT
 Group:          Productivity/Graphics/Other
 URL:            https://github.com/jtheoof/swappy
 Source:         https://github.com/jtheoof/swappy/archive/v%{version}.tar.gz
-Source1:        
https://github.com/jtheoof/swappy/releases/download/v%{version}/swappy-%{version}.tar.gz.asc
+Source1:        
https://github.com/jtheoof/swappy/releases/download/v%{version}/swappy-%{version}.tar.gz.sig
 Patch0:         swappy-desktopfile.patch
 Requires:       fontawesome-fonts
 Requires:       wl-clipboard

++++++ v1.2.0.tar.gz -> v1.2.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/CHANGELOG.md 
new/swappy-1.2.1/CHANGELOG.md
--- old/swappy-1.2.0/CHANGELOG.md       2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/CHANGELOG.md       2020-07-11 18:17:09.000000000 +0200
@@ -2,6 +2,13 @@
 
 All notable changes to this project will be documented in this file. See 
[standard-version](https://github.com/conventional-changelog/standard-version) 
for commit guidelines.
 
+### [1.2.1](https://github.com/jtheoof/swappy/compare/v1.2.0...v1.2.1) 
(2020-07-11)
+
+
+### Bug Fixes
+
+* **text:** properly handle utf-8 chars 
([717ab0c](https://github.com/jtheoof/swappy/commit/717ab0c2d1757e10bb4eef17d35ccd6a991705c4)),
 closes [#43](https://github.com/jtheoof/swappy/issues/43)
+
 ## [1.2.0](https://github.com/jtheoof/swappy/compare/v1.1.0...v1.2.0) 
(2020-07-05)
 
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/LICENSE new/swappy-1.2.1/LICENSE
--- old/swappy-1.2.0/LICENSE    2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/LICENSE    2020-07-11 18:17:09.000000000 +0200
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2019 Jeremy Attali
+Copyright (c) 2020 Jeremy Attali
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/README.md new/swappy-1.2.1/README.md
--- old/swappy-1.2.0/README.md  2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/README.md  2020-07-11 18:17:09.000000000 +0200
@@ -97,6 +97,7 @@
 - [Arch Linux](https://aur.archlinux.org/packages/swappy)
 - [Arch Linux (git)](https://aur.archlinux.org/packages/swappy-git)
 - [Fedora 31/32](https://copr.fedorainfracloud.org/coprs/wef/swappy)
+- [openSUSE](https://build.opensuse.org/package/show/X11:Wayland/swappy)
 
 ## Building from source
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/include/swappy.h 
new/swappy-1.2.1/include/swappy.h
--- old/swappy-1.2.0/include/swappy.h   2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/include/swappy.h   2020-07-11 18:17:09.000000000 +0200
@@ -41,7 +41,7 @@
   double s;
   gchar *font;
   gchar *text;
-  size_t cursor;
+  glong cursor;
   struct swappy_point from;
   struct swappy_point to;
   enum swappy_text_mode mode;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/include/util.h 
new/swappy-1.2.1/include/util.h
--- old/swappy-1.2.0/include/util.h     2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/include/util.h     2020-07-11 18:17:09.000000000 +0200
@@ -3,6 +3,7 @@
 
 #include <glib.h>
 
-void string_remove_at(char *str, size_t pos);
-gchar *string_insert_chars_at(gchar *str, gchar *chars, size_t pos);
+glong string_get_nb_bytes_until(gchar *str, glong until);
+gchar *string_remove_at(char *str, glong pos);
+gchar *string_insert_chars_at(gchar *str, gchar *chars, glong pos);
 void pixel_data_print(guint32 pixel);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/meson.build new/swappy-1.2.1/meson.build
--- old/swappy-1.2.0/meson.build        2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/meson.build        2020-07-11 18:17:09.000000000 +0200
@@ -1,7 +1,7 @@
 project(
        'swappy',
        'c',
-       version: '1.2.0',
+       version: '1.2.1',
        license: 'MIT',
        meson_version: '>=0.48.0',
        default_options: [
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/src/paint.c new/swappy-1.2.1/src/paint.c
--- old/swappy-1.2.0/src/paint.c        2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/src/paint.c        2020-07-11 18:17:09.000000000 +0200
@@ -11,7 +11,7 @@
 }
 
 static void cursor_move_forward(struct swappy_paint_text *text) {
-  if (text->cursor < strlen(text->text)) {
+  if (text->cursor < g_utf8_strlen(text->text, -1)) {
     text->cursor++;
   }
 }
@@ -194,6 +194,7 @@
                                  GdkEventKey *event) {
   struct swappy_paint *paint = state->temp_paint;
   struct swappy_paint_text *text;
+  char *new_text;
   char buffer[32];
   guint32 unicode;
 
@@ -209,14 +210,18 @@
       paint_commit_temporary(state);
       break;
     case GDK_KEY_BackSpace:
-      if (strlen(text->text) > 0) {
-        string_remove_at(text->text, text->cursor - 1);
+      if (g_utf8_strlen(text->text, -1) > 0) {
+        new_text = string_remove_at(text->text, text->cursor - 1);
+        g_free(text->text);
+        text->text = new_text;
         cursor_move_backward(text);
       }
       break;
     case GDK_KEY_Delete:
-      if (strlen(text->text) > 0) {
-        string_remove_at(text->text, text->cursor);
+      if (g_utf8_strlen(text->text, -1) > 0) {
+        new_text = string_remove_at(text->text, text->cursor);
+        g_free(text->text);
+        text->text = new_text;
       }
       break;
     case GDK_KEY_Left:
@@ -264,7 +269,7 @@
 
   switch (paint->type) {
     case SWAPPY_PAINT_MODE_TEXT:
-      if (strlen(paint->content.text.text) == 0) {
+      if (g_utf8_strlen(paint->content.text.text, -1) == 0) {
         paint->can_draw = false;
       }
       paint->content.text.mode = SWAPPY_TEXT_MODE_DONE;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/src/render.c 
new/swappy-1.2.1/src/render.c
--- old/swappy-1.2.0/src/render.c       2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/src/render.c       2020-07-11 18:17:09.000000000 +0200
@@ -5,6 +5,7 @@
 
 #include "algebra.h"
 #include "swappy.h"
+#include "util.h"
 
 #define pango_layout_t PangoLayout
 #define pango_font_description_t PangoFontDescription
@@ -201,13 +202,13 @@
 
   if (text.mode == SWAPPY_TEXT_MODE_EDIT) {
     pango_rectangle_t strong_pos;
-    pango_rectangle_t weak_pos;
     struct swappy_box cursor_box;
     cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 0.3);
     cairo_set_line_width(cr, 5);
     cairo_rectangle(cr, x, y, w, h);
     cairo_stroke(cr);
-    pango_layout_get_cursor_pos(layout, text.cursor, &strong_pos, &weak_pos);
+    glong bytes_til_cursor = string_get_nb_bytes_until(text.text, text.cursor);
+    pango_layout_get_cursor_pos(layout, bytes_til_cursor, &strong_pos, NULL);
     convert_pango_rectangle_to_swappy_box(strong_pos, &cursor_box);
     cairo_move_to(crt, cursor_box.x, cursor_box.y);
     cairo_set_source_rgba(crt, 0.3, 0.3, 0.3, 1);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/src/util.c new/swappy-1.2.1/src/util.c
--- old/swappy-1.2.0/src/util.c 2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/src/util.c 2020-07-11 18:17:09.000000000 +0200
@@ -3,40 +3,60 @@
 #include <glib.h>
 #include <string.h>
 
-void string_remove_at(gchar *str, size_t pos) {
-  if (str && strlen(str) > pos) {
-    memmove(&str[pos], &str[pos + 1], strlen(str) - pos);
+gchar *string_remove_at(gchar *str, glong pos) {
+  glong str_len = strlen(str);
+  gchar *new_str = g_new0(gchar, MAX(str_len, 1));
+  gchar *buffer_source = str;
+  gchar *buffer_copy = new_str;
+  glong i = 0;
+  gint bytes;
+  gunichar c;
+
+  if (pos <= str_len && g_utf8_validate(str, -1, NULL)) {
+    while (*buffer_source != '\0') {
+      c = g_utf8_get_char(buffer_source);
+      buffer_source = g_utf8_next_char(buffer_source);
+      if (i != pos) {
+        bytes = g_unichar_to_utf8(c, buffer_copy);
+        buffer_copy += bytes;
+      }
+      i++;
+    }
   }
+
+  return new_str;
 }
 
-gchar *string_insert_chars_at(gchar *str, gchar *chars, size_t pos) {
-  gchar *new_str;
+gchar *string_insert_chars_at(gchar *str, gchar *chars, glong pos) {
+  gchar *new_str = NULL;
 
-  if (str && chars) {
-    size_t n = strlen(str);
-    size_t m = strlen(chars);
-    size_t i = 0, j = 0;
-
-    new_str = g_new(gchar, n + m + 1);
-
-    while (j < n + m) {
-      if (j == pos) {
-        for (size_t k = 0; k < m; k++) {
-          new_str[j++] = chars[k];
-        }
-      } else {
-        new_str[j++] = str[i++];
-      }
-    }
+  if (g_utf8_validate(str, -1, NULL) && g_utf8_validate(chars, -1, NULL) &&
+      pos >= 0 && pos <= g_utf8_strlen(str, -1)) {
+    gchar *from = g_utf8_substring(str, 0, pos);
+    gchar *end = g_utf8_offset_to_pointer(str, pos);
+
+    new_str = g_strconcat(from, chars, end, NULL);
+
+    g_free(from);
 
-    new_str[j] = '\0';
   } else {
-    new_str = NULL;
+    new_str = g_new0(gchar, 1);
   }
 
   return new_str;
 }
 
+glong string_get_nb_bytes_until(gchar *str, glong until) {
+  glong ret = 0;
+  if (str) {
+    gchar *sub = g_utf8_substring(str, 0, until);
+    ret = strlen(sub);
+    g_free(sub);
+  }
+
+  return ret;
+}
+
 void pixel_data_print(guint32 pixel) {
   const guint32 r = pixel >> 24 & 0xff;
   const guint32 g = pixel >> 16 & 0xff;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/swappy-1.2.0/swappy.1.scd 
new/swappy-1.2.1/swappy.1.scd
--- old/swappy-1.2.0/swappy.1.scd       2020-07-05 20:54:03.000000000 +0200
+++ new/swappy-1.2.1/swappy.1.scd       2020-07-11 18:17:09.000000000 +0200
@@ -4,11 +4,11 @@
 
 swappy - grab and edit on the fly snapshots of a Wayland compositor
 
-# DESCRIPTION
+# SYNOPSIS
 
 *swappy* [options...]
 
-# SYNOPSIS
+# DESCRIPTION
 
 swappy is a command-line utility to take and edit screenshots of Wayland
 desktops. Works great with grim, slurp and sway. But can easily work with
@@ -41,7 +41,7 @@
        If set to *-*, prints the final surface to *stdout*.
 
        Note that the *Save* button will save the image to the config *save_dir*
-       parameter, as described in the SYNOPSIS section.
+       parameter, as described in the DESCRIPTION section.
 
 # CONFIG FILE
 


Reply via email to