Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2387233

Browse files
committed
TST: Add tests for FT2Font.clear
Also, ensure some internals are initialized/cleared.
1 parent a1b4498 commit 2387233

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/matplotlib/tests/test_ft2font.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ def test_ft2font_invalid_args(tmp_path):
160160
ft2font.FT2Font(file, _kerning_factor=1.3)
161161

162162

163+
def test_ft2font_clear():
164+
file = fm.findfont('DejaVu Sans')
165+
font = ft2font.FT2Font(file)
166+
assert font.get_num_glyphs() == 0
167+
assert font.get_width_height() == (0, 0)
168+
assert font.get_bitmap_offset() == (0, 0)
169+
font.set_text('ABabCDcd')
170+
assert font.get_num_glyphs() == 8
171+
assert font.get_width_height() != (0, 0)
172+
assert font.get_bitmap_offset() != (0, 0)
173+
font.clear()
174+
assert font.get_num_glyphs() == 0
175+
assert font.get_width_height() == (0, 0)
176+
assert font.get_bitmap_offset() == (0, 0)
177+
178+
163179
@pytest.mark.parametrize('family_name, file_name',
164180
[("WenQuanYi Zen Hei", "wqy-zenhei.ttc"),
165181
("Noto Sans CJK JP", "NotoSansCJK.ttc"),

src/ft2font.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ FT2Font::~FT2Font()
304304

305305
void FT2Font::clear()
306306
{
307-
pen.x = 0;
308-
pen.y = 0;
307+
pen.x = pen.y = 0;
308+
bbox.xMin = bbox.yMin = bbox.xMax = bbox.yMax = 0;
309+
advance = 0;
309310

310311
for (size_t i = 0; i < glyphs.size(); i++) {
311312
FT_Done_Glyph(glyphs[i]);

0 commit comments

Comments
 (0)