@@ -1828,8 +1828,7 @@ void MathtextBackend::draw(
1828
1828
auto ft_face =
1829
1829
static_cast <FT_Face>(
1830
1830
cairo_font_face_get_user_data (face, &detail::FT_KEY));
1831
- auto index = FT_UInt{};
1832
- std::visit (overloaded {
1831
+ auto index = std::visit (overloaded {
1833
1832
[&](char32_t codepoint) {
1834
1833
// The last unicode charmap is the FreeType-synthesized one.
1835
1834
auto i = ft_face->num_charmaps - 1 ;
@@ -1842,41 +1841,41 @@ void MathtextBackend::draw(
1842
1841
if (i < 0 ) {
1843
1842
throw std::runtime_error{" no unicode charmap found" };
1844
1843
}
1845
- index = FT_Get_Char_Index (ft_face, codepoint);
1846
- if (!index ) {
1847
- warn_on_missing_glyph (" #" + std::to_string (index ));
1848
- }
1844
+ return FT_Get_Char_Index (ft_face, codepoint);
1849
1845
},
1850
1846
[&](std::string name) {
1851
- index = FT_Get_Name_Index (ft_face, name.data ());
1852
- if (!index ) {
1853
- warn_on_missing_glyph (name);
1854
- }
1847
+ return FT_Get_Name_Index (ft_face, name.data ());
1855
1848
},
1856
1849
[&](FT_ULong idx) {
1857
- // For the usetex case, look up the "native" font charmap,
1858
- // which typically has a TT_ENCODING_ADOBE_STANDARD or
1859
- // TT_ENCODING_ADOBE_CUSTOM encoding, unlike the FreeType-synthesized
1860
- // one which has a TT_ENCODING_UNICODE encoding.
1850
+ // For classic fonts, the index maps to the "native" font charmap,
1851
+ // which typically has an ADOBE_STANDARD or ADOBE_CUSTOM encoding,
1852
+ // unlike the FreeType-synthesized one which has a UNICODE encoding.
1861
1853
auto found = false ;
1862
1854
for (auto i = 0 ; i < ft_face->num_charmaps ; ++i) {
1863
- if (ft_face->charmaps [i]->encoding != FT_ENCODING_UNICODE) {
1855
+ auto const & cmap = ft_face->charmaps [i];
1856
+ if (cmap->encoding == FT_ENCODING_ADOBE_STANDARD
1857
+ || cmap->encoding == FT_ENCODING_ADOBE_CUSTOM) {
1864
1858
if (found) {
1865
- throw std::runtime_error{" multiple non-unicode charmaps found" };
1859
+ throw std::runtime_error{" multiple Adobe charmaps found" };
1866
1860
}
1867
- FT_CHECK (FT_Set_Charmap, ft_face, ft_face-> charmaps [i] );
1861
+ FT_CHECK (FT_Set_Charmap, ft_face, cmap );
1868
1862
found = true ;
1869
1863
}
1870
1864
}
1871
1865
if (!found) {
1872
1866
throw std::runtime_error{" no builtin charmap found" };
1873
1867
}
1874
- index = FT_Get_Char_Index (ft_face, idx);
1875
- if (!index ) {
1876
- warn_on_missing_glyph (" #" + std::to_string (index ));
1877
- }
1868
+ return FT_Get_Char_Index (ft_face, idx);
1878
1869
}
1879
1870
}, glyph.codepoint_or_name_or_index );
1871
+ if (!index ) {
1872
+ auto glyph_ref = std::visit (overloaded {
1873
+ [&](char32_t codepoint) { return " #" + std::to_string (codepoint); },
1874
+ [&](std::string name) { return name; },
1875
+ [&](FT_ULong idx) { return " #" + std::to_string (idx); }
1876
+ }, glyph.codepoint_or_name_or_index );
1877
+ warn_on_missing_glyph (glyph_ref);
1878
+ }
1880
1879
auto const & raw_glyph = cairo_glyph_t {index , glyph.x , glyph.y };
1881
1880
cairo_show_glyphs (cr, &raw_glyph, 1 );
1882
1881
}
0 commit comments