Commit Graph
19 Commits
Author SHA1 Message Date
Behdad Esfahbodandmoi15moi 30a8ab86f8 Follow up to PR 6020 [util] Fix Unicode command line arguments on Windows (#6022)
* [util] Fix Unicode command line arguments on Windows

GLib g_option_context_parse() converts argv strings from the system ACP via g_locale_to_utf8(), but Windows cmd deliver arguments encoded in the system codepage (ex: CP1252), which cannot represent most Unicode codepoints. This caused non ascii character to be corrupted

For example, for this command, it rendered garbage instead of the emoji:
```
hb-view.exe "C:\Windows\Fonts\seguiemj.ttf" "😋" --output-file=output.png
```

Fix this in all util binaries (hb-ft-raster, hb-info, hb-raster, hb-shape, hb-subset, hb-vector, hb-view) by:
1. Calling g_win32_get_command_line() to obtain correctly UTF-8-encoded arguments from GetCommandLineW().
2. Parsing with g_option_context_parse_strv() which skips the g_locale_to_utf8() conversion for G_OPTION_ARG_STRING entries.
3. Adding G_OPTION_FLAG_FILENAME to the G_OPTION_REMAINING callback entry in main-font-text.hh, so the callback path also skips the locale conversion in strv_mode (see https://gitlab.gnome.org/GNOME/glib/-/blob/8ef2f3ad402daf9fb94615ddef63ceef978fd76f/glib/goption.c#L1305).

* [util] Fix Windows UTF-8 argv parsing

On Windows, GLib's option parser treats argv as encoded in the
system codepage and converts strings with g_locale_to_utf8().  The
utilities need to parse the UTF-8 command line obtained from
GetCommandLineW() instead, otherwise non-ASCII arguments can be
corrupted before reaching the tool logic.

Add a small argv_t wrapper for utility entry points to replace argv
with g_win32_get_command_line() on Windows, and use the strv parser
there so GLib skips the top-level argv conversion.  Mark remaining
callback arguments as filenames so GLib also skips callback argument
conversion for positional text and font arguments.

Testing:
meson test -C build

Assisted-by: OpenAI Codex

* [mingw] Update instructions

---------

Co-authored-by: moi15moi <moi15moismokerlolilol@gmail.com>
2026-06-07 15:58:36 -06:00
Behdad Esfahbod aa450db1f7 [README.mingw.md] Update for newer meson
https://github.com/mesonbuild/meson/issues/14400
2025-03-24 16:35:51 -06:00
Behdad Esfahbod 10256a9fc7 [README.mingw] Reword 2025-03-24 16:13:14 -06:00
Behdad Esfahbod 6c337ddc24 [README.mingw] Add note re Apple silicon 2025-03-24 16:04:49 -06:00
Behdad Esfahbod 7599d097c9 [README.mingw] Adjust
Installing system HarfBuzz makes it override our own build.
2025-03-23 15:12:02 -06:00
Behdad Esfahbod af6b6b4828 [README] More 2025-03-23 09:54:49 -06:00
Behdad Esfahbod 4f12035e5d [README.mingw] Update as per recent changes 2025-03-23 09:52:00 -06:00
Behdad Esfahbod 6e17bd374f [README.mingw] Add a couple Ubuntu lines 2025-03-22 15:15:19 -06:00
Behdad Esfahbod a388989af4 [README.mingw.md] Final touches, hopefully 2025-03-22 12:31:21 -06:00
Behdad Esfahbod f7f9cd1296 [README.mingw.md] Review feedback 2025-03-22 11:42:32 -06:00
Behdad Esfahbod f9ad7c37b1 [README.mingw.md] Update 2025-03-22 01:20:57 -06:00
Khaled Hosny 4fd4dbb896 [doc] Restore README.mingw.md
It got deleted in cf1fdf1632 but it is
still useful. Needs to be updated to meson world, though.
2025-03-22 00:34:27 -06:00
Khaled Hosny cf1fdf1632 Drop autotools build
Fixes https://github.com/harfbuzz/harfbuzz/issues/4720
2024-06-27 15:28:38 +03:00
Behdad Esfahbod b706be540c [mingw32] Update instructions 2022-07-14 11:03:04 -06:00
Behdad Esfahbod 1f462804d1 [README.mingw.md] Add link to issue with further instructions 2022-06-23 15:35:38 -06:00
Behdad Esfahbod e05e56061c [mingw] Reinstate win32 cross-compiling with autotools instructions
Was removed in favor of meson in 6058ede3ae.
However, those fail to build for me.
2021-01-24 12:28:04 -07:00
Ebrahim Byagowi 6058ede3ae Build win32 artifacts using meson
As a part of meson migration, this builds hb-shape dependencies
using meson subprojects and removes different unrelated mingw
files we've put on source root about things that aren't really our
concern. This also simplifies all the instructions we've put in
README.mingw.md and makes it easy to build the project on
distros that no mingw libraries (such i686-win32-{freetype,glib,...}
are packaged. The known catch is however lack of hb-view as its need
for build of cairo which apparently isn't that straightforward.
2020-06-01 12:58:31 +04:30
Behdad Esfahbod 7b716cbbe6 [ming2] Update instructions
Part of https://github.com/harfbuzz/harfbuzz/issues/1728

Only left to write how to create a win32 bundle.
2019-05-25 11:37:23 -04:00
Behdad Esfahbod 77a1b6b7c3 [mingw] Rename README.wine 2019-05-25 11:18:40 -04:00