From 6a1ac28cebc554f91530dc4bd5c9d5a7d41b7616 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 13 Aug 2026 17:11:53 -0600 Subject: [PATCH] [ot] Support legacy Hebrew cmap mappings Use the OS/2 Windows 3.1 Hebrew font-page marker to fall back from Unicode characters to legacy F0xx cmap slots. Apply remapping for both symbol and Unicode-labeled Windows cmaps in the OpenType and FreeType font-function paths. Add 3/0 and 3/1 regression fonts, and preserve direct Unicode cmap entries ahead of remapping. Fixes: https://github.com/harfbuzz/harfbuzz/issues/6159 Assisted-by: OpenAI Codex --- src/hb-ft.cc | 17 +++---- src/hb-ot-cmap-table.hh | 45 ++++++++++++------ src/hb-ot-shaper-hebrew-pua.hh | 45 ++++++++++++++++++ src/meson.build | 1 + .../data/in-house/fonts/LegacyHebrew3-0.ttf | Bin 0 -> 1864 bytes .../data/in-house/fonts/LegacyHebrew3-1.ttf | Bin 0 -> 1864 bytes test/shape/data/in-house/meson.build | 1 + .../data/in-house/tests/hebrew-legacy.tests | 3 ++ 8 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 src/hb-ot-shaper-hebrew-pua.hh create mode 100644 test/shape/data/in-house/fonts/LegacyHebrew3-0.ttf create mode 100644 test/shape/data/in-house/fonts/LegacyHebrew3-1.ttf create mode 100644 test/shape/data/in-house/tests/hebrew-legacy.tests diff --git a/src/hb-ft.cc b/src/hb-ft.cc index b8c0c8519..e1cac3fd9 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -39,6 +39,7 @@ #include "hb-machinery.hh" #include "hb-ot-os2-table.hh" #include "hb-ot-shaper-arabic-pua.hh" +#include "hb-ot-shaper-hebrew-pua.hh" #include "hb-paint.hh" #include FT_MODULE_H @@ -397,11 +398,9 @@ hb_ft_get_nominal_glyph (hb_font_t *font, if (unlikely (!g)) { - if (unlikely (ft_font->symbol)) - { - switch ((unsigned) font->face->table.OS2->get_font_page ()) { + switch ((unsigned) font->face->table.OS2->get_font_page ()) { case OT::OS2::font_page_t::FONT_PAGE_NONE: - if (unicode <= 0x00FFu) + if (unlikely (ft_font->symbol) && unicode <= 0x00FFu) /* For symbol-encoded OpenType fonts, we duplicate the * U+F000..F0FF range at U+0000..U+00FF. That's what * Windows seems to do, and that's hinted about at: @@ -409,6 +408,11 @@ hb_ft_get_nominal_glyph (hb_font_t *font, * under "Non-Standard (Symbol) Fonts". */ g = FT_Get_Char_Index (ft_font->ft_face, 0xF000u + unicode); break; +#ifndef HB_NO_OT_SHAPER_HEBREW_FALLBACK + case OT::OS2::font_page_t::FONT_PAGE_HEBREW: + g = FT_Get_Char_Index (ft_font->ft_face, _hb_hebrew_pua_map (unicode)); + break; +#endif #ifndef HB_NO_OT_SHAPER_ARABIC_FALLBACK case OT::OS2::font_page_t::FONT_PAGE_SIMP_ARABIC: g = FT_Get_Char_Index (ft_font->ft_face, _hb_arabic_pua_simp_map (unicode)); @@ -419,11 +423,8 @@ hb_ft_get_nominal_glyph (hb_font_t *font, #endif default: break; - } - if (!g) - return false; } - else + if (!g) return false; } diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 91be90fe5..6aa9a0062 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -29,6 +29,7 @@ #include "hb-ot-os2-table.hh" #include "hb-ot-shaper-arabic-pua.hh" +#include "hb-ot-shaper-hebrew-pua.hh" #include "hb-open-type.hh" #include "hb-set.hh" #include "hb-cache.hh" @@ -2083,29 +2084,43 @@ struct cmap this->get_glyph_data = &this->format4_accel; this->get_glyph_funcZ = func; }; + auto font_page = face->table.OS2->get_font_page (); +#ifndef HB_NO_OT_SHAPER_HEBREW_FALLBACK + if (unlikely (font_page == OS2::font_page_t::FONT_PAGE_HEBREW)) + { + if (is_format4) + set_format4_getter (get_glyph_from_symbol); + else + this->get_glyph_funcZ = get_glyph_from_symbol; + } + else +#endif +#ifndef HB_NO_OT_SHAPER_ARABIC_FALLBACK + if (unlikely (font_page == OS2::font_page_t::FONT_PAGE_SIMP_ARABIC)) + { + if (is_format4) + set_format4_getter (get_glyph_from_symbol); + else + this->get_glyph_funcZ = get_glyph_from_symbol; + } + else if (unlikely (font_page == OS2::font_page_t::FONT_PAGE_TRAD_ARABIC)) + { + if (is_format4) + set_format4_getter (get_glyph_from_symbol); + else + this->get_glyph_funcZ = get_glyph_from_symbol; + } + else +#endif if (unlikely (symbol)) { - switch ((unsigned) face->table.OS2->get_font_page ()) { + switch ((unsigned) font_page) { case OS2::font_page_t::FONT_PAGE_NONE: if (is_format4) set_format4_getter (get_glyph_from_symbol); else this->get_glyph_funcZ = get_glyph_from_symbol; break; -#ifndef HB_NO_OT_SHAPER_ARABIC_FALLBACK - case OS2::font_page_t::FONT_PAGE_SIMP_ARABIC: - if (is_format4) - set_format4_getter (get_glyph_from_symbol); - else - this->get_glyph_funcZ = get_glyph_from_symbol; - break; - case OS2::font_page_t::FONT_PAGE_TRAD_ARABIC: - if (is_format4) - set_format4_getter (get_glyph_from_symbol); - else - this->get_glyph_funcZ = get_glyph_from_symbol; - break; -#endif default: if (is_format4) set_format4_getter (get_glyph_from); diff --git a/src/hb-ot-shaper-hebrew-pua.hh b/src/hb-ot-shaper-hebrew-pua.hh new file mode 100644 index 000000000..a9e3b648e --- /dev/null +++ b/src/hb-ot-shaper-hebrew-pua.hh @@ -0,0 +1,45 @@ +#ifndef HB_OT_SHAPER_HEBREW_PUA_HH +#define HB_OT_SHAPER_HEBREW_PUA_HH + +#include "hb.hh" + + +static inline uint16_t +_hb_hebrew_pua_map (unsigned u) +{ + if ((u >= 0x0020u && u <= 0x0040u) || + (u >= 0x005Bu && u <= 0x005Fu) || + (u >= 0x007Bu && u <= 0x007Eu)) + return 0xF000u + u; + + if ((u >= 0x05B0u && u <= 0x05C3u) || + (u >= 0x05D0u && u <= 0x05EAu)) + return 0xEB10u + u; + + if (u >= 0x2074u && u <= 0x2079u) + return 0xD010u + u; + + switch (u) + { + case 0x00A3u: return 0xF0A3u; + case 0x00A7u: return 0xF0A7u; + case 0x00B0u: return 0xF0B0u; + case 0x00B2u: return 0xF082u; + case 0x00B3u: return 0xF083u; + case 0x00B7u: return 0xF0B7u; + case 0x00B9u: return 0xF081u; + case 0x00BCu: return 0xF0BCu; + case 0x00BDu: return 0xF0BDu; + case 0x00BEu: return 0xF0BEu; + case 0x00D7u: return 0xF0AAu; + case 0x00F7u: return 0xF0BAu; + case 0x200Eu: return 0xF0FDu; + case 0x200Fu: return 0xF0FEu; + case 0x2070u: return 0xF080u; + case 0x20AAu: return 0xF0A4u; + default: return 0; + } +} + + +#endif /* HB_OT_SHAPER_HEBREW_PUA_HH */ diff --git a/src/meson.build b/src/meson.build index 035bed87b..1ca7bde60 100644 --- a/src/meson.build +++ b/src/meson.build @@ -217,6 +217,7 @@ hb_base_sources = files( 'hb-ot-shaper-arabic.hh', 'hb-ot-shaper-default.cc', 'hb-ot-shaper-hangul.cc', + 'hb-ot-shaper-hebrew-pua.hh', 'hb-ot-shaper-hebrew.cc', 'hb-ot-shaper-indic-table.cc', 'hb-ot-shaper-indic.cc', diff --git a/test/shape/data/in-house/fonts/LegacyHebrew3-0.ttf b/test/shape/data/in-house/fonts/LegacyHebrew3-0.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a1e848260b5da7c0d5f401ab77b340aff44351a5 GIT binary patch literal 1864 zcmeHIU5HIl6#mvd=iZq+X6zY6X-tQNV#fTS3HeDv3C%E+q%-&K`%~xKbLZT9%#0WE zS9l;viU&pcN%=`gl6c{P#4{mDp7z6_l)2V9_s}UyUOd^iz1Ldb_w9Ao-DkHB2tXZn zLxZutcW!6Tkxx$nn#Jh4lx-G^2d`b=_y))4ves}$dwk{!5IfHEP)?fZwhc?_n7hn# zL5>0aIvr#G9na}GyF5fA?16@OS!g*aGx;Rh!F#v(v26|&(Sii?wHzA-)0X++Nw0vo z!Pu&zQ!2mcK5-gIecX*wEY3aD_Q0BMFEGCy`kG&I8d;;i`Ns6}H$vy{iRW%1`~v|58^;89pfMD>?0 z@%!>eJ=b%R?KBwd#rP>x)joAlom1!4C3RKZQg_rnbzi+uZ`D^dTB-2aK39g?&6=|j z&D}urnl;}lm9J~W8?jgH5*d*e{bHNgEH;UaqE{>z^F@nj{^j(7Qhr$)(16L9iFsI# zb=Zm=JnX>{oW@1m#6vv8OMJu^(y57BXf|~Rzm=Sa@Z&A=zwBz7+SEx$X=JqiKlA?# z{_Q>RFLgamgg2frF}R&R8bb|7en;Zw62bL|AIBI>2{j3f$1GNoo@8VW7KMHcW04Jg zErRP2Kh8P5P?Nw699}E4W@^}2E&E+LX!w2F=xS~6ky+0&-9G7-@=n3%Xlt+PszCzZ(KB1Kd0Sdq+1#O7uC2M2-QX4SDJLzf%y(WRZ@K^g literal 0 HcmV?d00001 diff --git a/test/shape/data/in-house/fonts/LegacyHebrew3-1.ttf b/test/shape/data/in-house/fonts/LegacyHebrew3-1.ttf new file mode 100644 index 0000000000000000000000000000000000000000..9b853a0c6f7eedb1d984d631f33cdd471e83a301 GIT binary patch literal 1864 zcmeHIU5HIl6#mvd=iZq+W@Z~CX-tQNVum||CgdjxB{Y6Z(wTer{mD7^+&T9iGvkH) z6&^^E;z3a&~3XoRlq38R~2#1DvUz{0#9Q7C(;Vj~Db#eTe8m{G_8F(0G5@G$N zO8mb3YBX{_Cs|H{!CH(@nW*-ugX)|*uP&-9>ZZD_?y7t0xq73%sNrgrYx_(YYBzJv zMmTo@&MW48tyaIR6tBfzu}fq{M)ZoUVw2b)){AvwiI^kWMC&ir`+f3FXu^0*#cV9W zYHUFs9`@h}PU8Y@-~pcE1wP<2>C{4PG@ZJGXBh`0e1D4?(A6@rrIU`*&~W2_&;J_y z+k4>O>_(gjZ#-daa65f8hB~(VZ;+cy1lJ>a93wCxO$ zi{N@hk8?~fSh79kXh@8f_`F zn1of3e4vRm2DxdhV5=7{ul;PLVY8>iS{K@pLQlZ;U@_`qBU>)YD8NCHIVp5t)=%-G z(Uyj>YLR~Q;-Fx^Sz3cS>J%f5J3^ciREPciUpN4Ty_Cc)YM>GLM2*x$%_L|fca2dr zn#RUq=3 y#@V&QtS>v+l3DipbkmYqtyfl(CC_Zn6>Mo~6?2DXxwht7c9T~uq@9ecdA