Skip to content

Commit 862a678

Browse files
committed
raqm_set_language.
1 parent efc4a28 commit 862a678

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ next
1111
- Control vector output version with the ``MaxVersion`` special metadata
1212
entry.
1313
- Add HARD_LIGHT operator, which was previously missing.
14+
- Support setting OpenType language tag.
1415

1516
v0.4 (2021-04-02)
1617
=================

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,17 @@ faces in a single file), the *n*\th font (*n*\≥0) can be selected by appending
448448

449449
OpenType font features can be selected by appending ``|feature,...``
450450
to the filename, followed by a `HarfBuzz feature string`_ (e.g.,
451-
``"/path/to/font.otf|frac,onum"``); see `examples/opentype_features.py`_.
451+
``"/path/to/font.otf|frac,onum"``); see `examples/opentype_features.py`_. A
452+
language_ tag can likewise be set with ``|language=...``; currently, this
453+
always applies to the whole buffer, but a PR adding support for slicing syntax
454+
(similar to font features) would be considered.
452455

453456
.. _HarfBuzz feature string: https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-feature-from-string
457+
.. _language: https://host-oman.github.io/libraqm/raqm-Raqm.html#raqm-set-language
454458

455-
The syntaxes for selecting TTC subfonts and OpenType font features are
456-
**experimental** and may change, especially if such features are implemented in
457-
Matplotlib itself.
459+
The syntaxes for selecting TTC subfonts and OpenType font features and language
460+
tags are **experimental** and may change, especially if such features are
461+
implemented in Matplotlib itself.
458462

459463
Color fonts (e.g. emojis) are handled.
460464

src/_raqm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern "C" { // Support raqm<=0.2.
1313
_(get_glyphs) \
1414
_(layout) \
1515
_(set_freetype_face) \
16+
_(set_language) \
1617
_(set_text_utf8) \
1718
_(version_string) \
1819
_(version_atleast)

src/_util.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,13 @@ GlyphsAndClusters text_to_glyphs_and_clusters(cairo_t* cr, std::string s)
797797
*static_cast<std::vector<std::string>*>(
798798
cairo_font_face_get_user_data(
799799
cairo_get_font_face(cr), &detail::FEATURES_KEY))) {
800-
TRUE_CHECK(raqm::add_font_feature, rq, feature.c_str(), -1);
800+
auto lang_tag = "language="s;
801+
if (feature.substr(0, lang_tag.size()) == lang_tag) {
802+
TRUE_CHECK(raqm::set_language,
803+
rq, feature.c_str() + lang_tag.size(), 0, s.size());
804+
} else {
805+
TRUE_CHECK(raqm::add_font_feature, rq, feature.c_str(), -1);
806+
}
801807
}
802808
TRUE_CHECK(raqm::layout, rq);
803809
auto num_glyphs = size_t{};

0 commit comments

Comments
 (0)