Skip to content

Commit b9384e4

Browse files
committed
Document module functions
1 parent 522dcd4 commit b9384e4

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

src/uharfbuzz/_harfbuzz.pyx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ cdef int msgcallback(hb_buffer_t *buffer, hb_font_t *font, const char* message,
3030

3131

3232
def version_string() -> str:
33+
"""Returns library version as a string with three components.
34+
35+
:returns: Library version string.
36+
37+
Wraps `hb_version_string()
38+
<https://harfbuzz.github.io/harfbuzz-hb-version.html#hb-version-string>`_.
39+
"""
3340
cdef const char* cstr = hb_version_string()
3441
cdef bytes packed = cstr
3542
return packed.decode()
@@ -89,6 +96,35 @@ include "_generated_docs.pxi"
8996
def shape(font: Font, buffer: Buffer,
9097
features: Dict[str,Union[int,bool,Sequence[Tuple[int,int,Union[int,bool]]]]] | None = None,
9198
shapers: List[str] | None = None):
99+
"""Shapes ``buffer`` using ``font`` turning its Unicode characters content
100+
to positioned glyphs. If ``features`` is not ``None``, it will be used to
101+
control the features applied during shaping. If two features have the
102+
same tag but overlapping ranges the value of the feature with the higher
103+
index takes precedence.
104+
105+
If ``shapers`` is not ``None``, the specified shapers will be used in the
106+
given order, otherwise the default shapers list will be used.
107+
108+
:param font: A :class:`Font` to use for shaping.
109+
:param buffer: A :class:`Buffer` to shape.
110+
:param features: A mapping whose keys are feature tags (or feature
111+
strings as accepted by ``hb_feature_from_string`` when the value is
112+
an ``int``/``bool``), and whose values are either an ``int``/``bool``
113+
applied globally, or a sequence of ``(start, end, value)`` triples
114+
applying the feature to a specific cluster range.
115+
:param shapers: Ordered list of shaper names to try, or ``None`` for the
116+
default list.
117+
118+
:raises RuntimeError: If all shapers failed (only when ``shapers`` is
119+
provided).
120+
:raises MemoryError: If memory allocation fails.
121+
122+
Wraps `hb_shape()
123+
<https://harfbuzz.github.io/harfbuzz-hb-shape.html#hb-shape>`_
124+
or `hb_shape_full()
125+
<https://harfbuzz.github.io/harfbuzz-hb-shape.html#hb-shape-full>`_
126+
when ``shapers`` is given.
127+
"""
92128
cdef unsigned int size
93129
cdef hb_feature_t* hb_features
94130
cdef bytes packed
@@ -139,6 +175,15 @@ def shape(font: Font, buffer: Buffer,
139175

140176

141177
def ot_tag_to_script(tag: str) -> str:
178+
"""Converts a script tag to a script.
179+
180+
:param tag: A script tag.
181+
182+
:returns: The script corresponding to ``tag``.
183+
184+
Wraps `hb_ot_tag_to_script()
185+
<https://harfbuzz.github.io/harfbuzz-hb-ot-layout.html#hb-ot-tag-to-script>`_.
186+
"""
142187
cdef bytes packed = tag.encode()
143188
cdef hb_tag_t hb_tag = hb_tag_from_string(<char*>packed, -1)
144189
cdef hb_script_t hb_script = hb_ot_tag_to_script(hb_tag)
@@ -150,6 +195,15 @@ def ot_tag_to_script(tag: str) -> str:
150195

151196

152197
def ot_tag_to_language(tag: str) -> str:
198+
"""Converts a language tag to a language.
199+
200+
:param tag: A language tag.
201+
202+
:returns: The language corresponding to ``tag``, or ``None``.
203+
204+
Wraps `hb_ot_tag_to_language()
205+
<https://harfbuzz.github.io/harfbuzz-hb-ot-layout.html#hb-ot-tag-to-language>`_.
206+
"""
153207
cdef bytes packed = tag.encode()
154208
cdef hb_tag_t hb_tag = hb_tag_from_string(<char*>packed, -1)
155209
cdef hb_language_t hb_language = hb_ot_tag_to_language(hb_tag)
@@ -325,4 +379,11 @@ def ot_math_get_glyph_assembly(font: Font,
325379

326380

327381
def ot_font_set_funcs(font: Font):
382+
"""Sets the font functions to use when working with ``font`` to the
383+
HarfBuzz's native implementation. This is the default for fonts newly
384+
created.
385+
386+
Wraps `hb_ot_font_set_funcs()
387+
<https://harfbuzz.github.io/harfbuzz-hb-ot-font.html#hb-ot-font-set-funcs>`_.
388+
"""
328389
hb_ot_font_set_funcs(font._hb_font)

0 commit comments

Comments
 (0)