From 23637cabc722a973d0c27555cc36276ad51bdd49 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Sat, 28 Feb 2026 16:56:43 +0900 Subject: [PATCH] Select correct Noto Sans CJK font variant in stargraphic writer Use the profile's cjk_encoding to select the language-appropriate Noto Sans variant (JP, SC, TC, KR) for Pango text rasterization. This ensures correct glyph rendering for Han-unified codepoints where the same Unicode character has different visual forms per locale. Replaces the old fc-list-based font detection singleton with a locale-driven lookup from the existing CJK encoding configuration. Co-Authored-By: Claude Opus 4.6 --- lib/thermal/stargraphic/writer.rb | 33 +++++++++---------------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/lib/thermal/stargraphic/writer.rb b/lib/thermal/stargraphic/writer.rb index ea0023b..73c3316 100644 --- a/lib/thermal/stargraphic/writer.rb +++ b/lib/thermal/stargraphic/writer.rb @@ -190,35 +190,20 @@ def seq_exec_em append_raw [27, 12, 25] end + CJK_FONTS = { + 'shift_jis' => 'Noto Sans JP', + 'gb18030' => 'Noto Sans SC', + 'big5' => 'Noto Sans TC', + 'ksc5601' => 'Noto Sans KR' + }.freeze + def font - self.class.font - end - - class << self - # Persists font as singleton - def font - @font ||= if OS.windows? - 'Sans' - else - font_list = begin - `fc-list` - rescue StandardError - '' - end - case font_list - when /NotoSans/ then 'NotoSans' - else 'Sans' - end - end - end + CJK_FONTS[@profile.cjk_encoding&.key] || 'Noto Sans' end - def text_image(markup, width: @width, align: :left, font: 'Sans', delete: true) + def text_image(markup, width: @width, align: :left, font: self.font, delete: true) tmp_path = ::Thermal.tmp_path("#{SecureRandom.uuid}.png") - # TODO: Fix font loading - # font ||= self.class.font - begin configure = proc do |i| i << '+antialias'