Skip to content

Commit b037a65

Browse files
committed
Add separate draw_glyph_or_fail()/paint_glyph_or_fail()
So clients can op in or out for fallback mechanism.
1 parent 29d1e96 commit b037a65

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/uharfbuzz/_raster.pxi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ cdef class RasterDraw:
139139
c_extents.height = extents.height
140140
return hb_raster_draw_set_glyph_extents(self._hb_raster_draw, &c_extents)
141141

142-
def draw_glyph(self, font: Font, glyph: int) -> bool:
142+
def draw_glyph(self, font: Font, glyph: int):
143+
hb_raster_draw_glyph(self._hb_raster_draw, font._hb_font, glyph)
144+
145+
def draw_glyph_or_fail(self, font: Font, glyph: int) -> bool:
143146
return hb_raster_draw_glyph_or_fail(self._hb_raster_draw, font._hb_font, glyph)
144147

145148
def render(self) -> RasterImage | None:
@@ -250,7 +253,10 @@ cdef class RasterPaint:
250253
def clear_custom_palette_colors(self):
251254
hb_raster_paint_clear_custom_palette_colors(self._hb_raster_paint)
252255

253-
def paint_glyph(self, font: Font, glyph: int) -> bool:
256+
def paint_glyph(self, font: Font, glyph: int):
257+
hb_raster_paint_glyph(self._hb_raster_paint, font._hb_font, glyph)
258+
259+
def paint_glyph_or_fail(self, font: Font, glyph: int) -> bool:
254260
return hb_raster_paint_glyph_or_fail(self._hb_raster_paint, font._hb_font, glyph)
255261

256262
def render(self) -> RasterImage | None:

tests/test_raster.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,17 @@ def test_custom_palette_color(self):
115115
paint = hb.RasterPaint()
116116
assert paint.set_custom_palette_color(0, hb.Color(255, 0, 0, 255))
117117
paint.clear_custom_palette_colors()
118+
119+
def test_paint_glyph_or_fail(self, font):
120+
# OpenSans glyphs are monochrome
121+
gid = 1
122+
paint = hb.RasterPaint()
123+
paint.scale_factor = (1.0, 1.0)
124+
paint.set_glyph_extents(font.get_glyph_extents(gid))
125+
# _or_fail variant signals "no color paint data" via False
126+
assert not paint.paint_glyph_or_fail(font, gid)
127+
# plain variant falls back to outline drawing
128+
paint.paint_glyph(font, gid)
129+
image = paint.render()
130+
assert image is not None
131+
assert image.format is hb.RasterFormat.BGRA32

0 commit comments

Comments
 (0)