Skip to content

Commit ed75b68

Browse files
committed
additional typography tests
1 parent c7ad150 commit ed75b68

9 files changed

Lines changed: 67 additions & 13 deletions
26.2 KB
Loading
59.6 KB
Loading
36.9 KB
Loading
15.3 KB
Loading
43.1 KB
Loading
44.4 KB
Loading
40.7 KB
Loading
18.1 KB
Loading

tests/typography.py

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ def test_typography_layout_find(self):
230230
font('Palatino', 23)
231231
t = text(20, 40, 250, str="The frog in the fog bares its fangs in good humor")
232232

233-
for match in t.find('good'):
233+
for match in t.find('good'): # simple
234234
rect(match.bounds, stroke='steelblue', fill=None)
235235

236-
for match in t.find(r'f\w+'):
236+
for match in t.find(r'f\w+'): # regex
237237
rect(match.bounds, stroke='firebrick', fill=None)
238238

239239
@reference('typography/typography-layout-select.png')
@@ -263,9 +263,63 @@ def test_typography_layout_select2(self):
263263
note.append(fn.text, vpos=1)
264264
note.append(' '+fn.attrs['note'])
265265

266-
@reference('typography/typography-layout-flow.png')
267-
def test_typography_layout_flow(self):
266+
@reference('typography/typography-advanced-indent.png')
267+
def test_typography_advanced_indent(self):
268268
# tut/Typography (21)
269+
size(300, 320)
270+
txt="The first paragraph extends to the first carriage return character and will never be indented by default.\nThe second paragraph follows the first and will be indented according to the current layout settings.\nThe third paragraph is just like the second. It is also indented.\n\nA final paragraph, preceded by a blank line, represents the beginning of a new ‘section’ and suppresses any indentation.\n"
271+
272+
layout(indent=1.4)
273+
font('Georgia', 16)
274+
text(30,40, width=250, str=txt)
275+
276+
@reference('typography/typography-advanced-outdent.png')
277+
def test_typography_advanced_outdent(self):
278+
# tut/Typography (22)
279+
size(300, 300)
280+
txt="The first paragraph extends to the first carriage return character and will be outdented by the negative indentation value.\nThe second paragraph follows the first and will be outdented too.\nThe third paragraph is outdented just like the prior two.\n\nA final paragraph, preceded by a blank line, represents the beginning of a new ‘section’ but is outdented all the same.\n"
281+
282+
layout(indent=-1.4)
283+
font('Georgia', 16)
284+
text(30,40, width=250, str=txt)
285+
286+
@reference('typography/typography-advanced-margin.png')
287+
def test_typography_advanced_margin(self):
288+
# tut/Typography (23)
289+
size(300, 300)
290+
dickens = "London. Michaelmas term lately over, and the Lord Chancellor sitting in Lincoln's Inn Hall. Implacable November weather. As much mud in the streets as if the waters had but newly retired from the face of the earth, and it would not be wonderful to meet a Megalosaurus, forty feet long or so, waddling like an elephantine lizard up Holborn Hill. Smoke lowering down from chimney-pots, making a soft black drizzle, with flakes of soot in it as big as full-grown snowflakes—gone into mourning, one might imagine, for the death of the sun. Dogs, undistinguishable in mire. Horses, scarcely better; splashed to their very blinkers. Foot passengers, jostling one another's umbrellas in a general infection of ill temper, and losing their foot-hold at street-corners, where tens of thousands of other foot passengers have been slipping and sliding since the day broke (if this day ever broke), adding new deposits to the crust upon crust of mud, sticking at those points tenaciously to the pavement, and accumulating at compound interest."
291+
292+
font('Baskerville', 13)
293+
x, y = 0, 20
294+
w, h = 300, 90
295+
296+
layout(margin=0) # the default
297+
text(x,y, w,h, str=dickens)
298+
y += 100
299+
300+
layout(margin=40) # left-side margin
301+
text(x,y, w,h, str=dickens)
302+
y+=100
303+
304+
layout(margin=(80,40)) # both-sides margin
305+
text(x,y, w,h, str=dickens)
306+
307+
@reference('typography/typography-advanced-spacing.png')
308+
def test_typography_advanced_spacing(self):
309+
# tut/Typography (24)
310+
size(300, 200)
311+
txt = "Paragraph one has five words.\nParagraph two is shorter.\nParagraph three is followed by a snowman.\n☃ "
312+
font(13)
313+
314+
layout(spacing=0) # the default
315+
text(20,30, 100, str=txt)
316+
317+
layout(spacing=1) # add 1 lineheight of extra space
318+
text(150,30, 120, str=txt)
319+
320+
@reference('typography/typography-advanced-flow.png')
321+
def test_typography_advanced_flow(self):
322+
# tut/Typography (25)
269323
size(300, 150)
270324
kafka = 'Someone must have been telling lies about Josef K., he knew he had done nothing wrong but, one morning, he was arrested. Every day at eight in the morning he was brought his breakfast by Mrs. Grubach’s cook. Mrs. Gru-bach was his landlady but today she didn’t come. That had never happened before. K. waited a little while, looked from his pillow at the old woman who lived opposite and who was watching him with an inquisitiveness quite unusual for her, and finally, both hungry and disconcerted, rang the bell. There was immediately a knock at the door and a man entered.'
271325

@@ -275,9 +329,9 @@ def test_typography_layout_flow(self):
275329
for block in t.flow(2):
276330
block.x += block.width + 20
277331

278-
@reference('typography/typography-layout-flow2.png')
279-
def test_typography_layout_flow2(self):
280-
# tut/Typography (22)
332+
@reference('typography/typography-advanced-flow2.png')
333+
def test_typography_advanced_flow2(self):
334+
# tut/Typography (26)
281335
size(300, 330)
282336
kafka = 'and a man entered. He had never seen the man in this house before. He was slim but firmly built, his clothes were black and close-fitting, with many folds and pockets, buckles and buttons and a belt, all of which gave the impression of being very practical but without making it very clear what they were actually for. “Who are you?” asked K., sitting half upright in his bed. The man, however, ignored the question as if his arrival simply had to be accepted, and merely replied, “You rang?” “Anna should have brought me my breakfast,” said K. He tried to work out who the man actually was, first in silence, just through observation and by thinking about it, but the man didn’t stay still to be looked at for very long. Instead he went over to the door, opened it slightly, and said to someone who was clearly standing immediately behind it, “He wants Anna to bring him his breakfast.” There was a little laughter in the neighbouring room, it was not clear from the sound of it whether there were several people laughing. The strange man could not have learned anything from it that he hadn’t known already, but now he said to K., as if making his report “It is not possible.” “It would be the first time that’s happened,” said K., as he jumped out of bed and quickly pulled on his trousers. “I want to see who that is in the next room, and why it is that Mrs. Grubach has let me be disturbed in this way.” It immediately occurred to him that he needn’t have said this out loud, and that he must to some extent have acknowledged their authority by doing so, but that ...'
283337

@@ -294,9 +348,9 @@ def leftright(block):
294348
t = text(20,24, 120,120, str=kafka)
295349
t.flow(all, leftright)
296350

297-
@reference('typography/typography-layout-flow3.png')
298-
def test_typography_layout_flow3(self):
299-
# tut/Typography (23)
351+
@reference('typography/typography-advanced-flow3.png')
352+
def test_typography_advanced_flow3(self):
353+
# tut/Typography (27)
300354
size(300, 240)
301355
welles = 'Before the law, there stands a guard. A man comes from the country, begging admittance to the law. But the guard cannot admit him. May he hope to enter at a later time? That is possible, said the guard. The man tries to peer through the entrance. He’d been taught that the law was to be accessible to every man. “Do not attempt to enter without my permission”, says the guard. I am very powerful. Yet I am the least of all the guards. From hall to hall, door after door, each guard is more powerful than the last. By the guard’s permission, the man sits by the side of the door, and there he waits. For years, he waits. Everything he has, he gives away in the hope of bribing the guard, who never fails to say to him “I take what you give me only so that you will not feel that you left something undone.” Keeping his watch during the long years, the man has come to know even the fleas on the guard’s fur collar. Growing childish in old age, he begs the fleas to persuade the guard to change his mind and allow him to enter. His sight has dimmed, but in the darkness he perceives a radiance streaming immortally from the door of the law. And now, before he dies, all he’s experienced condenses into one question, a question he’s never asked. He beckons the guard. Says the guard, “You are insatiable! What is it now?” Says the man, “Every man strives to attain the law. How is it then that in all these years, no one else has ever come here, seeking admittance?” His hearing has failed, so the guard yells into his ear. “Nobody else but you could ever have obtained admittance. No one else could enter this door! This door was intended only for you! And now, I’m going to close it.” This tale is told during the story called “The Trial”. It’s been said that the logic of this story is the logic of a dream... a nightmare.'
302356

@@ -311,9 +365,9 @@ def test_typography_layout_flow3(self):
311365
for block in t.blocks:
312366
rect(block.bounds, stroke='red', dash=4)
313367

314-
@reference('typography/typography-layout-flow4.png')
315-
def test_typography_layout_flow4(self):
316-
# tut/Typography (24)
368+
@reference('typography/typography-advanced-flow4.png')
369+
def test_typography_advanced_flow4(self):
370+
# tut/Typography (28)
317371
size(300, 180)
318372
fake_id = "NAME\fJean d’Eau\fEYES\fViolet\fHEIGHT\f3'5\"\fAGE\f137\fADDRESS\f123 Fake St.\nSpringfield, IL 62705"
319373

0 commit comments

Comments
 (0)