From ff4be60bfdcc7d6be721276a2523daf22a878fd5 Mon Sep 17 00:00:00 2001
From: Jun Mizutani <mizutani.jun@nifty.ne.jp>
Date: Fri, 8 Sep 2023 13:25:56 +0200
Subject: [PATCH] Is key Free: Adjust character width for East Asian languages

Because East Asian languages use wide characters,
adjust the number of "-" to match the page width

Pull Request: https://projects.blender.org/blender/blender-addons/pulls/104848
---
 development_iskeyfree.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/development_iskeyfree.py b/development_iskeyfree.py
index 82defb8ff..c93e10385 100644
--- a/development_iskeyfree.py
+++ b/development_iskeyfree.py
@@ -7,7 +7,7 @@
 bl_info = {
     "name": "Is key Free",
     "author": "Antonio Vazquez (antonioya)",
-    "version": (1, 1, 2),
+    "version": (1, 1, 3),
     "blender": (2, 80, 0),
     "location": "Text Editor > Sidebar > Dev Tab",
     "description": "Find free shortcuts, inform about used and print a key list",
@@ -16,6 +16,7 @@ bl_info = {
 }
 
 import bpy
+
 from bpy.props import (
     BoolProperty,
     EnumProperty,
@@ -28,6 +29,7 @@ from bpy.types import (
     PropertyGroup,
 )
 
+import unicodedata
 
 # ------------------------------------------------------
 # Class to find keymaps
@@ -498,6 +500,15 @@ class IsKeyFreeRunExportKeys(Operator):
         except:
             return None
 
+    def unicodelen(self, string):
+        n = 0
+        for c in string:
+            if unicodedata.east_asian_width(c) in 'FWA':
+                n += 2
+            else:
+                n += 1
+        return n
+
     def execute(self, context):
         wm = bpy.context.window_manager
         from collections import defaultdict
@@ -536,7 +547,7 @@ class IsKeyFreeRunExportKeys(Operator):
             textblock.write("\n[%s]\nEntries: %s\n\n" % (ctx, len(mykeys[ctx])))
             line_k = sorted(mykeys[ctx])
             for keys in line_k:
-                add_ticks = "-" * (max_line - (len(keys[0]) + len(keys[1])))
+                add_ticks = "-" * (max_line - (self.unicodelen(keys[0]) + len(keys[1])))
                 entries = "{ticks} {entry}".format(ticks=add_ticks, entry=keys[1])
                 textblock.write("{name} {entry}\n".format(name=keys[0], entry=entries))
 
-- 
GitLab