forked from HinTak/skia-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_paragraph.py
63 lines (45 loc) · 2.16 KB
/
test_paragraph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import skia
import pytest
@pytest.fixture(scope='session')
def textlayout_font_collection():
return skia.textlayout.FontCollection()
def test_FontCollection_init0(textlayout_font_collection):
assert isinstance(textlayout_font_collection, skia.textlayout_FontCollection)
@pytest.fixture(scope='session')
def paragraph_style():
return skia.textlayout.ParagraphStyle()
def test_ParagraphStyle_init0(paragraph_style):
assert isinstance(paragraph_style, skia.textlayout_ParagraphStyle)
@pytest.fixture(scope='session')
def textlayout_text_style():
return skia.textlayout.TextStyle()
def test_TextStyle_init0(textlayout_text_style):
assert isinstance(textlayout_text_style, skia.textlayout_TextStyle)
@pytest.fixture(scope='session')
def paragraph_builder():
return skia.textlayout.ParagraphBuilder.make(skia.textlayout.ParagraphStyle(),
skia.textlayout.FontCollection(),
skia.Unicodes.ICU.Make())
def test_ParagraphBuilder_init0(paragraph_builder):
assert isinstance(paragraph_builder, skia.textlayout_ParagraphBuilder)
def test_Paragraph_init0(paragraph_builder):
paragraph_builder.addText("")
paragraph = paragraph_builder.Build()
assert isinstance(paragraph, skia.textlayout_Paragraph)
# Adapted from #278, to make sure that "\n" results in a line break (rather that .notdef).
# Height is larger than twice width, if a break happens.
def test_Paragraph_linebreak(paragraph_builder, textlayout_text_style, textlayout_font_collection, paragraph_style):
paint = skia.Paint()
paint.setColor(skia.ColorBLACK)
paint.setAntiAlias(True)
textlayout_text_style.setFontSize(50)
textlayout_text_style.setForegroundPaint(paint)
textlayout_font_collection.setDefaultFontManager(skia.FontMgr())
builder = skia.textlayout.ParagraphBuilder.make(
paragraph_style, textlayout_font_collection, skia.Unicodes.ICU.Make()
)
builder.pushStyle(textlayout_text_style)
builder.addText("o\no")
paragraph = builder.Build()
paragraph.layout(300)
assert (paragraph.Height > 0) and (paragraph.Height > paragraph.LongestLine * 2)