Skip to content

Commit 1f9bd36

Browse files
committed
Support setting language on a slice.
1 parent cac82d6 commit 1f9bd36

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/_util.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ cairo_font_face_t* font_face_from_path(std::string pathspec)
670670
"Failed to parse pathspec {}"_format(pathspec).cast<std::string>()};
671671
}
672672
auto const& path = match.str(1);
673-
auto const& face_index = match.str(3).empty() ? 0 : std::stoi(match.str(3));
673+
auto const& face_index = std::atoi(match.str(3).c_str()); // 0 if absent.
674674
auto const& features_s = match.str(5);
675675
FT_Face ft_face;
676676
FT_CHECK(
@@ -806,10 +806,15 @@ GlyphsAndClusters text_to_glyphs_and_clusters(cairo_t* cr, std::string s)
806806
*static_cast<std::vector<std::string>*>(
807807
cairo_font_face_get_user_data(
808808
cairo_get_font_face(cr), &detail::FEATURES_KEY))) {
809-
auto lang_tag = "language="s;
810-
if (feature.substr(0, lang_tag.size()) == lang_tag) {
811-
TRUE_CHECK(raqm::set_language,
812-
rq, feature.c_str() + lang_tag.size(), 0, s.size());
809+
auto match = std::smatch{};
810+
if (std::regex_match(
811+
feature, match,
812+
std::regex{"^language(?:\\[(\\d+)?(?::(\\d+))?\\])?=(.*)$"})) {
813+
auto const& start = std::atoi(match.str(1).c_str()); // 0 if absent.
814+
auto const& stop = match[2].matched
815+
? std::atoi(match.str(2).c_str()) : s.size();
816+
auto const& lang = match.str(3);
817+
TRUE_CHECK(raqm::set_language, rq, lang.c_str(), start, stop - start);
813818
} else {
814819
TRUE_CHECK(raqm::add_font_feature, rq, feature.c_str(), -1);
815820
}

0 commit comments

Comments
 (0)