File: test_multi_cell.py

package info (click to toggle)
fpdf2 2.8.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 114,352 kB
  • sloc: python: 50,410; sh: 133; makefile: 12
file content (656 lines) | stat: -rw-r--r-- 20,912 bytes parent folder | download
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
from pathlib import Path

import pytest

from fpdf import FPDF, FPDFException
from fpdf.enums import MethodReturnValue, YPos

from test.conftest import assert_pdf_equal, LOREM_IPSUM, assert_same_file

HERE = Path(__file__).resolve().parent
FONTS_DIR = HERE.parent / "fonts"

TEXT_SIZE, SPACING = 36, 1.15
LINE_HEIGHT = TEXT_SIZE * SPACING

TABLE_DATA = (
    ("First name", "Last name", "Age", "City"),
    ("Jules", "Smith", "34", "San Juan"),
    ("Mary", "Ramos", "45", "Orlando"),
    ("Carlson", "Banks", "19", "Los Angeles"),
    ("Lucas", "Cimon", "31", "Angers"),
)

LONG_TEXT = (
    "\nProfessor: (Eric Idle) It's an entirely new strain of sheep, a killer sheep that can not only hold a rifle but is also a first-class shot.\n"
    "Assistant: But where are they coming from, professor?\n"
    "Professor: That I don't know. I just don't know. I really just don't know. I'm afraid I really just don't know. I'm afraid even I really just"
    " don't know. I have to tell you I'm afraid even I really just don't know. I'm afraid I have to tell you... (she hands him a glass of water"
    " which she had been busy getting as soon as he started into this speech) ... thank you ... (resuming normal breezy voice) ... I don't know."
    " Our only clue is this portion of wolf's clothing which the killer sheep ..."
)


def test_multi_cell_page_break_with_fill(tmp_path):
    # Tests condition from issue #1471
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("times")
    pdf.set_fill_color(240)

    pdf.multi_cell(
        fill=True,
        w=0,
        text=LOREM_IPSUM * 7,
        padding=[2, 0, 0, 0],  # top, right, bottom, left
    )

    assert pdf.page_no() > 1, "Must be more than one page to test page break"
    assert_pdf_equal(pdf, HERE / "multi_cell_page_break_with_fill.pdf", tmp_path)


def test_multi_cell_without_any_font_set():
    pdf = FPDF()
    pdf.add_page()
    with pytest.raises(FPDFException) as error:
        pdf.multi_cell(text="Hello world!", w=pdf.epw)
    assert str(error.value) == "No font set, you need to call set_font() beforehand"


def test_ln_positioning_and_page_breaking_for_multicell(tmp_path):
    doc = FPDF(format="letter", unit="pt")
    doc.add_page()
    doc.set_font("helvetica", size=TEXT_SIZE)

    doc.multi_cell(
        w=144,
        h=LINE_HEIGHT,
        border=1,
        text=LOREM_IPSUM[:29],
        new_x="RIGHT",
        new_y="NEXT",
    )
    doc.multi_cell(
        w=180,
        h=LINE_HEIGHT,
        border=1,
        text=LOREM_IPSUM[29:60],
        new_x="LEFT",
        new_y="NEXT",
    )
    doc.multi_cell(
        w=144,
        h=LINE_HEIGHT,
        border=1,
        text=LOREM_IPSUM[60:90],
        new_x="LMARGIN",
        new_y="NEXT",
    )
    doc.cell(
        w=72 * 5,
        h=LINE_HEIGHT,
        border=1,
        text=LOREM_IPSUM[0:30],
        new_x="LMARGIN",
        new_y="NEXT",
    )
    doc.cell(
        w=72 * 5,
        h=LINE_HEIGHT,
        border=1,
        text=LOREM_IPSUM[31:60],
        new_x="LMARGIN",
        new_y="NEXT",
    )
    doc.cell(
        w=72 * 5,
        h=LINE_HEIGHT,
        border=1,
        text=LOREM_IPSUM[61:90],
        new_x="LMARGIN",
        new_y="NEXT",
    )
    doc.cell(
        w=72 * 5,
        h=LINE_HEIGHT,
        border=1,
        text=LOREM_IPSUM[91:120],
        new_x="LMARGIN",
        new_y="NEXT",
    )
    doc.cell(w=72 * 5, h=LINE_HEIGHT, border=1)
    doc.cell(w=1, h=LINE_HEIGHT, new_x="LEFT", new_y="NEXT")
    doc.multi_cell(
        w=144,
        h=LINE_HEIGHT,
        border=1,
        text=LOREM_IPSUM[30:90],
        new_x="LEFT",
        new_y="NEXT",
    )
    doc.cell(
        w=72 * 2,
        h=LINE_HEIGHT,
        border=1,
        text="Lorem ipsum",
        new_x="LEFT",
        new_y="NEXT",
    )
    doc.cell(
        w=72 * 2,
        h=LINE_HEIGHT,
        border=1,
        text="Lorem ipsum",
        new_x="LEFT",
        new_y="NEXT",
    )

    assert_pdf_equal(
        doc, HERE / "ln_positioning_and_page_breaking_for_multicell.pdf", tmp_path
    )


def test_multi_cell_border_thickness(tmp_path):
    doc = FPDF()
    doc.add_page()
    doc.set_font("helvetica", size=TEXT_SIZE)
    doc.set_line_width(3)
    doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="Lorem")
    doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="ipsum")
    doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="Ut")
    doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="nostrud")
    assert_pdf_equal(doc, HERE / "multi_cell_border_thickness.pdf", tmp_path)


def test_multi_cell_ln_1(tmp_path):
    doc = FPDF()
    doc.add_page()
    doc.set_font("helvetica", size=TEXT_SIZE)
    doc.multi_cell(
        w=100,
        h=LINE_HEIGHT,
        border=1,
        text="Lorem ipsum",
        new_x="LMARGIN",
        new_y="NEXT",
    )
    doc.multi_cell(w=100, h=LINE_HEIGHT, border=1, text="Ut nostrud irure")
    assert_pdf_equal(doc, HERE / "multi_cell_ln_1.pdf", tmp_path)


def test_multi_cell_ln_3(tmp_path):
    doc = FPDF()
    doc.add_page()
    doc.set_font("helvetica", size=TEXT_SIZE)
    doc.multi_cell(
        w=45, h=LINE_HEIGHT, border=1, text="Lorem", new_x="RIGHT", new_y="TOP"
    )
    doc.multi_cell(
        w=45, h=LINE_HEIGHT, border=1, text="ipsum", new_x="RIGHT", new_y="TOP"
    )
    doc.multi_cell(w=45, h=LINE_HEIGHT, border=1, text="Ut", new_x="RIGHT", new_y="TOP")
    doc.multi_cell(
        w=45, h=LINE_HEIGHT, border=1, text="nostrud", new_x="RIGHT", new_y="TOP"
    )
    assert_pdf_equal(doc, HERE / "multi_cell_ln_3.pdf", tmp_path)


def test_multi_cell_ln_3_table(tmp_path):
    """
    Test rendering of a table with multi-lines cell contents
    cf. https://github.com/py-pdf/fpdf2/issues/63
    """
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=10)
    line_height = pdf.font_size * 2.5
    # Set column width to 1/4 of effective page width to distribute content
    # evenly across table and page
    col_width = pdf.epw / 4
    for row in TABLE_DATA:
        for datum in row:
            pdf.multi_cell(
                col_width,
                line_height,
                str(datum),
                border=1,
                new_x="RIGHT",
                new_y="TOP",
                max_line_height=pdf.font_size,
            )
        pdf.ln(line_height)
    assert_pdf_equal(pdf, HERE / "multi_cell_ln_3_table.pdf", tmp_path)


def test_multi_cell_table_with_automatic_page_break(tmp_path):  # issue 120
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)
    line_height = pdf.font_size * 2
    col_width = pdf.epw / 4  # distribute content evenly
    for _ in range(5):  # repeat table 5 times
        for row in TABLE_DATA:
            for datum in row:
                pdf.multi_cell(
                    col_width,
                    line_height,
                    datum,
                    border=1,
                    new_x="RIGHT",
                    new_y="TOP",
                    max_line_height=pdf.font_size,
                )
            pdf.ln(line_height)
    assert_pdf_equal(
        pdf, HERE / "multi_cell_table_with_automatic_page_break.pdf", tmp_path
    )


def test_multi_cell_table_with_max_line_height(tmp_path):  # issue 589
    """
    When using multi_cell() with max_line_height to render multiline text,
    the last line should be rendered like all the others
    """
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("helvetica")
    text = (
        "Discard the water and serve the boiled gaozis."
        " Tip: If you love spicy dishes, add a bit of our Red Silk Chili"
        " (not included) with the gaozis"
    )
    pdf.multi_cell(w=120, h=50, text=text, max_line_height=6, border=True)
    pdf.ln()
    pdf.multi_cell(w=120, h=18, text=text, max_line_height=6, border=True)
    assert_pdf_equal(pdf, HERE / "multi_cell_table_with_max_line_height.pdf", tmp_path)


def test_multi_cell_justified_with_unicode_font(tmp_path):  # issue 118
    pdf = FPDF()
    pdf.add_page()
    pdf.add_font(fname=FONTS_DIR / "DejaVuSans.ttf")
    pdf.set_font("DejaVuSans", size=14)
    text = 'Justified line containing "()" that is long enough to trigger wrapping and a line jump'
    pdf.multi_cell(w=0, h=8, text=text, new_x="LMARGIN", new_y="NEXT")
    assert_pdf_equal(pdf, HERE / "multi_cell_justified_with_unicode_font.pdf", tmp_path)


def test_multi_cell_split_only():  # discussion 314
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Helvetica", size=TEXT_SIZE)
    text = "Lorem ipsum Ut nostrud irure reprehenderit anim nostrud dolore sed ut"
    expected = [
        "Lorem ipsum Ut nostrud irure",
        "reprehenderit anim nostrud",
        "dolore sed ut",
    ]
    with pytest.warns(
        DeprecationWarning, match='The parameter "split_only" is deprecated.'
    ) as record:
        assert (
            pdf.multi_cell(w=0, h=LINE_HEIGHT, text=text, split_only=True) == expected
        )
    assert len(record) == 1
    assert_same_file(record[0].filename, __file__)


def test_multi_cell_with_empty_contents(tmp_path):  # issue 349
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("helvetica", size=10)
    for i in range(1, 5):
        pdf.multi_cell(20, new_x="RIGHT", new_y="TOP", text=str(i))
    pdf.ln(10)
    for i in range(1, 5):
        pdf.multi_cell(20, new_x="RIGHT", new_y="TOP", text=str(i) if i > 2 else "")
    assert_pdf_equal(pdf, HERE / "multi_cell_with_empty_contents.pdf", tmp_path)


def test_multicell_badinput():
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)
    with pytest.raises(ValueError):
        pdf.multi_cell(0, ln=5)
    with pytest.raises(TypeError):
        pdf.multi_cell(0, new_x=5)
    with pytest.raises(TypeError):
        pdf.multi_cell(0, new_y=None)
    with pytest.raises(ValueError):
        # w as string instead of float
        pdf.multi_cell("width")
    with pytest.raises(ValueError):
        # h as string instead of float
        pdf.multi_cell(0, "height")


def test_multi_cell_j_paragraphs(tmp_path):  # issue 364
    pdf = FPDF(format="A5")
    pdf.add_page()
    pdf.add_font(fname=FONTS_DIR / "DejaVuSans.ttf")
    pdf.set_font("DejaVuSans", size=14)
    pdf.set_margins(34, 55, 34)
    pdf.set_auto_page_break(auto=True, margin=55)
    # pylint: disable=line-too-long
    text = """« Jadis, si je me souviens bien, ma vie était un festin où s’ouvraient tous les cœurs, où tous les vins coulaient.

Un soir, j’ai assis la Beauté sur mes genoux. — Et je l’ai trouvée amère. — Et je l’ai injuriée.

Je me suis armé contre la justice.

Je me suis enfui. Ô sorcières, ô misère, ô haine, c’est à vous que mon trésor a été confié !

Je parvins à faire s’évanouir dans mon esprit toute l’espérance humaine. Sur toute joie pour l’étrangler j’ai fait le bond sourd de la bête féroce.

J’ai appelé les bourreaux pour, en périssant, mordre la crosse de leurs fusils. J’ai appelé les fléaux, pour m’étouffer avec le sable, le sang. Le malheur a été mon dieu. Je me suis allongé dans la boue. Je me suis séché à l’air du crime. Et j’ai joué de bons tours à la folie."""

    pdf.multi_cell(w=0, h=None, text=text, align="J")
    assert_pdf_equal(pdf, HERE / "multi_cell_j_paragraphs.pdf", tmp_path)


def test_multi_cell_font_leakage(tmp_path):  # Issue #359
    pdf = FPDF()
    pdf.add_page()
    pdf.add_font("Roboto", fname=FONTS_DIR / "Roboto-Regular.ttf")
    pdf.add_font("Roboto", style="B", fname=FONTS_DIR / "Roboto-Bold.ttf")
    pdf.set_font("Roboto", size=12)

    pdf.multi_cell(0, text="xyz **abcde**", markdown=True)
    pdf.ln()
    pdf.set_font("Roboto", size=12)
    pdf.multi_cell(0, text="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
    pdf.ln()
    pdf.ln()
    pdf.multi_cell(0, text="xyz **abcde** ", markdown=True)
    pdf.ln()
    pdf.set_font("Roboto", size=12)
    pdf.multi_cell(0, text="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
    assert_pdf_equal(pdf, HERE / "multi_cell_font_leakage.pdf", tmp_path)


def test_multi_cell_with_zero_horizontal_space():  # issue #389
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Helvetica", size=10)
    pdf.multi_cell(w=0, h=5, text="test")
    with pytest.raises(FPDFException):
        pdf.multi_cell(w=0, h=5, text="test")


def test_multi_cell_with_limited_horizontal_space():  # issue #389
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Helvetica", size=10)
    pdf.multi_cell(w=pdf.epw - 2 * pdf.c_margin - 1, h=5, text="test")
    assert pdf.x == pdf.l_margin + pdf.epw - 2 * pdf.c_margin - 1
    with pytest.raises(FPDFException):
        pdf.multi_cell(w=0, h=5, text="test")


def test_multi_cell_trailing_nl(tmp_path):  # issue #455
    """Each multi_line() call triggers a line break at the end."""
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)
    lines = ["Hello\n", "Sweet\n", "World\n"]
    for line in lines:
        pdf.multi_cell(200, text=line)
    pdf.cell(text="end_mmc")
    pdf.ln(50)
    pdf.multi_cell(200, text="".join(lines))
    pdf.cell(text="end_mc")
    assert_pdf_equal(pdf, HERE / "multi_cell_trailing_nl.pdf", tmp_path)


def test_multi_cell_font_stretching(tmp_path):  # issue #478
    pdf = FPDF()
    pdf.add_page()
    # built-in font
    pdf.set_font("Helvetica", size=8)
    pdf.set_fill_color(255, 255, 0)
    pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True)
    pdf.ln()
    pdf.set_stretching(150)
    pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True)
    pdf.ln()
    # unicode font
    pdf.set_stretching(100)
    pdf.add_font(fname=FONTS_DIR / "DroidSansFallback.ttf")
    pdf.set_font("DroidSansFallback", size=8)
    pdf.set_fill_color(255, 255, 0)
    pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True)
    pdf.ln()
    pdf.set_stretching(150)
    pdf.multi_cell(w=50, text=LOREM_IPSUM[:100], new_x="LEFT", fill=True)
    assert_pdf_equal(pdf, HERE / "multi_cell_font_stretching.pdf", tmp_path)


def test_multi_cell_char_spacing(tmp_path):  # issue #489
    pdf = FPDF()
    pdf.add_page()
    # built-in font
    pdf.set_font("Helvetica", size=8)
    pdf.set_fill_color(255, 255, 0)
    pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True)
    pdf.ln()
    pdf.set_char_spacing(10)
    pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True)
    pdf.ln()
    # unicode font
    pdf.set_char_spacing(0)
    pdf.add_font(fname=FONTS_DIR / "DroidSansFallback.ttf")
    pdf.set_font("DroidSansFallback", size=8)
    pdf.set_fill_color(255, 255, 0)
    pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True)
    pdf.ln()
    pdf.set_char_spacing(10)
    pdf.multi_cell(w=150, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True)
    assert_pdf_equal(pdf, HERE / "multi_cell_char_spacing.pdf", tmp_path)


def test_multi_cell_char_wrap(tmp_path):  # issue #649
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Helvetica", size=10)
    pdf.set_fill_color(255, 255, 0)
    pdf.multi_cell(w=50, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True)
    pdf.ln()
    pdf.multi_cell(
        w=50, text=LOREM_IPSUM[:200], new_x="LEFT", fill=True, wrapmode="CHAR"
    )
    pdf.ln()
    pdf.set_font("Courier", size=10)
    txt = "     " + "abcdefghijklmnopqrstuvwxyz" * 3
    pdf.multi_cell(w=50, text=txt, new_x="LEFT", fill=True, align="L")
    pdf.ln()
    pdf.multi_cell(w=50, text=txt, new_x="LEFT", fill=True, align="L", wrapmode="CHAR")
    assert_pdf_equal(pdf, HERE / "multi_cell_char_wrap.pdf", tmp_path)


def test_multi_cell_centering(tmp_path):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)
    pdf.multi_cell(w=120, text=LOREM_IPSUM, border=1, center=True)
    assert_pdf_equal(pdf, HERE / "multi_cell_centering.pdf", tmp_path)


def test_multi_cell_align_x(tmp_path):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)
    pdf.set_x(140)
    pdf.multi_cell(w=120, text=LOREM_IPSUM, border=1, align="X")
    pdf.set_draw_color(r=0, g=255, b=0)
    pdf.line(140, 0, 140, pdf.h)
    assert_pdf_equal(pdf, HERE / "multi_cell_align_x.pdf", tmp_path)


def test_multi_cell_centering_and_align_x(tmp_path):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)
    pdf.multi_cell(w=120, text=LOREM_IPSUM, border=1, center=True, align="X")
    pdf.set_draw_color(r=0, g=255, b=0)
    pdf.line(pdf.w / 2, 0, pdf.w / 2, pdf.h)
    assert_pdf_equal(pdf, HERE / "multi_cell_centering_and_align_x.pdf", tmp_path)


def test_multi_cell_deprecated_txt_arg():
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Helvetica", size=TEXT_SIZE)
    with pytest.warns(
        DeprecationWarning, match='The parameter "txt" has been renamed to "text"'
    ):
        # pylint: disable=unexpected-keyword-arg
        pdf.multi_cell(w=0, txt="Lorem ipsum Ut nostrud irure")


def test_multi_cell_align_with_padding(tmp_path):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Helvetica", size=10)
    pdf.set_fill_color(222)

    # show alignment markers
    with pdf.local_context(draw_color=(0, 255, 0)):
        pdf.line(pdf.l_margin, 0, pdf.l_margin, pdf.h)
        pdf.line(pdf.w / 2, 0, pdf.w / 2, pdf.h)

    def create_boxes(new_x, new_y, align, padding=2):
        w = (pdf.w - pdf.l_margin - pdf.r_margin) / 6
        for ch in "ABC":
            text = f"{ch}1\n{ch}{ch}2\n{ch}{ch}{ch}3"
            pdf.multi_cell(
                w=w,
                text=text,
                fill=True,
                border=True,
                padding=padding,
                new_x=new_x,
                new_y=new_y,
                align=align,
            )

    create_boxes("LMARGIN", "NEXT", "JUSTIFY")
    create_boxes("RIGHT", "TOP", "CENTER")
    create_boxes("LEFT", "NEXT", "RIGHT")
    create_boxes("CENTER", "NEXT", "X")
    pdf.ln()
    create_boxes("START", "NEXT", "LEFT")
    create_boxes("END", "NEXT", "RIGHT")
    assert_pdf_equal(pdf, HERE / "multi_cell_align_with_padding.pdf", tmp_path)


def test_multi_cell_with_padding(tmp_path):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)
    pdf.multi_cell(0, 5, LONG_TEXT, border=1, padding=(10, 20, 30, 40))

    assert_pdf_equal(pdf, HERE / "multi_cell_with_padding.pdf", tmp_path)


def test_multi_cell_with_padding_check_input():
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)

    with pytest.raises(ValueError):
        pdf.multi_cell(0, 5, LONG_TEXT, border=1, padding=(5, 5, 5, 5, 5, 5))


def test_multi_cell_return_value(tmp_path):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=16)

    pdf.x = 5

    out = pdf.multi_cell(
        0,
        5,
        "Monty Python\nKiller Sheep",
        border=1,
        padding=0,
        output=MethodReturnValue.PAGE_BREAK | MethodReturnValue.HEIGHT,
    )
    height_without_padding = out[1]

    pdf.x = 5
    # pdf.y += 50

    # try again
    out = pdf.multi_cell(
        0,
        5,
        "Monty Python\nKiller Sheep",
        border=1,
        padding=0,
        output=MethodReturnValue.PAGE_BREAK | MethodReturnValue.HEIGHT,
    )

    height_without_padding2 = out[1]

    pdf.x = 5
    # pdf.y += 50

    # try again
    out = pdf.multi_cell(
        0,
        5,
        "Monty Python\nKiller Sheep",
        border=1,
        padding=10,
        output=MethodReturnValue.PAGE_BREAK | MethodReturnValue.HEIGHT,
    )

    height_with_padding = out[1]

    assert height_without_padding == height_without_padding2
    assert height_without_padding + 20 == height_with_padding

    pdf.x = 5
    pdf.y += 10

    out = pdf.multi_cell(
        0,
        5,
        "Monty Python\nKiller Sheep",
        border=1,
        padding=10,
        output=MethodReturnValue.PAGE_BREAK | MethodReturnValue.HEIGHT,
        new_y=YPos.NEXT,
    )

    assert_pdf_equal(pdf, HERE / "multi_cell_return_value.pdf", tmp_path)


def test_multi_cell_markdown_bleeding(tmp_path):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Times", size=60)
    pdf.multi_cell(
        w=0, text="**Lorem Ipsum dolor**", markdown=True, new_x="LMARGIN", new_y="NEXT"
    )
    assert pdf.font_style == ""
    pdf.multi_cell(
        w=0, text="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT"
    )
    pdf.multi_cell(
        w=0, text="--Lorem Ipsum dolor--", markdown=True, new_x="LMARGIN", new_y="NEXT"
    )
    assert pdf.font_style == ""
    pdf.multi_cell(
        w=0, text="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT"
    )
    pdf.multi_cell(
        w=0, text="__Lorem Ipsum dolor__", markdown=True, new_x="LMARGIN", new_y="NEXT"
    )
    assert pdf.font_style == ""
    pdf.multi_cell(
        w=0, text="No Markdown", markdown=False, new_x="LMARGIN", new_y="NEXT"
    )
    assert_pdf_equal(pdf, HERE / "multi_cell_markdown_bleeding.pdf", tmp_path)