[graphics/krita] /: win: Set activeCodePage to UTF-8

Alvin Wong null at kde.org
Fri May 20 11:05:51 BST 2022


Git commit 0d7259f83d021278f9f560f676fc6b96b5a0d9c0 by Alvin Wong.
Committed on 20/05/2022 at 09:30.
Pushed by alvinwong into branch 'master'.

win: Set activeCodePage to UTF-8

This should enable impex plugins of all file formats to access files
containing Unicode characters in their paths on Windows.

Historically, Windows has used the ANSI code page (ACP) as the encoding
for char strings, which can only represent a limited range of
characters. Windows also provides wide versions of the APIs using
`wchar_t`, which is 2-byte chars for strings encoded in UTF-16 (or UCS-2
in some cases). For libraries to support Unicode filenames on Windows,
they have to go out of the way to implement it with the wide API. They
don't do it consistently either -- some choose to implement wide
variants for their API, while some choose to interpret char* paths in
UTF-8 (which led to confusion when the caller assumed the API takes the
local 8-bit char encoding).

Now, by setting the activeCodePage to UTF-8, this changes the code page
for our process to UTF-8. This effectively means that, all -A variants
of WinAPI calls now accept UTF-8 strings instead of strings in the
system ACP. By extension, C and C++ functions for accessing files that
are not the 'wide' variant will now also accept UTF-8 file paths.

With regards to the impex plugins, this changes their behaviour around
file paths:

* If the external library already accepts `wchar_t *` there should be no
  change in behaviour.
* If the external library accepts `char *` and treats them as UTF-8:
  * If we correctly use `QString::toUtf8()`, there should be no change
    in behaviour.
  * If we use `QString::toLocal8Bit()` or `QFile::encodeName()` by
    mistake, having activeCodePage in UTF-8 will render it a non-issue.
* If the external library accepts `char *` and uses C or C++ library
  functions to open them directly:
  * If we correctly use `QString::toLocal8Bit()` or
    `QFile::encodeName()`, they would not have been able to open files
    with names containing Unicode chars outside of the system ACP in the
    past, but will now be able to do so.
  * If we use `QString::toUtf8()` by mistake, having activeCodePage in
    UTF-8 will render it a non-issue.

As illustrated above, the result is a net improvement.

Potential side effect: If a Python plugin expects to be using the system
ACP to interact with an external process via IPC, this can cause the
encoding to become mismatch.

Note that this only works starting from Windows 10 Version 1903.

Reference: https://docs.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page

CCMAIL: kimageshop at kde.org

M  +15   -3    krita/CMakeLists.txt
A  +9    -0    krita/krita.exe.manifest.in
M  +7    -0    plugins/extensions/pykrita/kritarunner/CMakeLists.txt
A  +9    -0    plugins/extensions/pykrita/kritarunner/kritarunner.exe.manifest.in

https://invent.kde.org/graphics/krita/commit/0d7259f83d021278f9f560f676fc6b96b5a0d9c0

diff --git a/krita/CMakeLists.txt b/krita/CMakeLists.txt
index 4a26534052..00436b9e1e 100644
--- a/krita/CMakeLists.txt
+++ b/krita/CMakeLists.txt
@@ -156,8 +156,16 @@ install(DIRECTORY DESTINATION ${DATA_INSTALL_DIR}/krita/shortcuts)
 
 if (WIN32)
     configure_file(versioninfo.rc.in ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc)
-
-    add_executable(krita_windows_stub_exe windows_stub_main.cpp ${krita_windows_stub_ICONS_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc)
+    configure_file(krita.exe.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/krita.exe.manifest)
+    # CMake does not know how to embed manifest on mingw, so we create our own RC file to be included
+    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/krita.exe.manifest.rc "1 24 \"krita.exe.manifest\"\n")
+
+    add_executable(krita_windows_stub_exe
+        windows_stub_main.cpp
+        ${krita_windows_stub_ICONS_SRCS}
+        ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc
+        ${CMAKE_CURRENT_BINARY_DIR}/krita.exe.manifest.rc
+    )
     target_link_libraries(krita_windows_stub_exe PRIVATE krita Qt5::WinMain)
     set_target_properties(krita_windows_stub_exe
         PROPERTIES
@@ -168,7 +176,11 @@ if (WIN32)
     endif()
     install(TARGETS krita_windows_stub_exe ${INSTALL_TARGETS_DEFAULT_ARGS})
 
-    add_executable(krita_windows_stub_com windows_stub_main.cpp ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc)
+    add_executable(krita_windows_stub_com
+        windows_stub_main.cpp
+        ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc
+        ${CMAKE_CURRENT_BINARY_DIR}/krita.exe.manifest.rc
+    )
     target_link_libraries(krita_windows_stub_com PRIVATE krita)
     set_target_properties(krita_windows_stub_com
         PROPERTIES
diff --git a/krita/krita.exe.manifest.in b/krita/krita.exe.manifest.in
new file mode 100644
index 0000000000..be16a7d30d
--- /dev/null
+++ b/krita/krita.exe.manifest.in
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <assemblyIdentity type="win32" name="KritaFoundation.Krita.krita" version="${KRITA_STABLE_VERSION_MAJOR}.${KRITA_STABLE_VERSION_MINOR}.${KRITA_VERSION_RELEASE}.${KRITA_VERSION_REVISION}"/>
+  <application>
+    <windowsSettings>
+      <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
+    </windowsSettings>
+  </application>
+</assembly>
diff --git a/plugins/extensions/pykrita/kritarunner/CMakeLists.txt b/plugins/extensions/pykrita/kritarunner/CMakeLists.txt
index 9f5cd9a966..1a3d9ac0dc 100644
--- a/plugins/extensions/pykrita/kritarunner/CMakeLists.txt
+++ b/plugins/extensions/pykrita/kritarunner/CMakeLists.txt
@@ -19,6 +19,13 @@ set(kritarunner_PRIVATE_LINK_LIBS
     Qt5::Concurrent
 )
 
+if(WIN32)
+    configure_file(kritarunner.exe.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/kritarunner.exe.manifest)
+    # CMake does not know how to embed manifest on mingw, so we create our own RC file to be included
+    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/kritarunner.exe.manifest.rc "1 24 \"kritarunner.exe.manifest\"\n")
+    set(kritarunner_SRCS ${kritarunner_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/kritarunner.exe.manifest.rc)
+endif()
+
 add_executable(kritarunner ${kritarunner_SRCS})
 target_include_directories(kritarunner SYSTEM PUBLIC "${PYTHON_INCLUDE_DIRS}")
 target_link_libraries(kritarunner PRIVATE ${kritarunner_PRIVATE_LINK_LIBS})
diff --git a/plugins/extensions/pykrita/kritarunner/kritarunner.exe.manifest.in b/plugins/extensions/pykrita/kritarunner/kritarunner.exe.manifest.in
new file mode 100644
index 0000000000..44ec50fc46
--- /dev/null
+++ b/plugins/extensions/pykrita/kritarunner/kritarunner.exe.manifest.in
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <assemblyIdentity type="win32" name="KritaFoundation.Krita.kritarunner" version="${KRITA_STABLE_VERSION_MAJOR}.${KRITA_STABLE_VERSION_MINOR}.${KRITA_VERSION_RELEASE}.${KRITA_VERSION_REVISION}"/>
+  <application>
+    <windowsSettings>
+      <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
+    </windowsSettings>
+  </application>
+</assembly>


More information about the kimageshop mailing list