1616from typing import Any , Optional , Sequence
1717
1818from .deprecation import get_stack_level
19- from .enums import WrapMode
19+ from .enums import WrapMode , XPos , YPos
2020from .errors import FPDFException
2121from .fpdf import FPDF
2222
@@ -432,11 +432,10 @@ def _text(
432432 width = w if w is not None else x2 - (x1 if x1 is not None else pdf .get_x ())
433433 height = h if h is not None else y2 - (y1 if y1 is not None else pdf .get_y ())
434434
435- cell_kwargs = {}
436- if new_x is not None :
437- cell_kwargs ["new_x" ] = new_x
438- if new_y is not None :
439- cell_kwargs ["new_y" ] = new_y
435+ # set default values, because cell() does not know how to
436+ # treat None as value for new_x, new_y
437+ new_xx = XPos .RIGHT if new_x is None else new_x
438+ new_yy = YPos .TOP if new_y is None else new_y
440439
441440 if multiline is None : # write without wrapping/trimming (default)
442441 pdf .cell (
@@ -446,7 +445,8 @@ def _text(
446445 border = 0 ,
447446 align = align ,
448447 fill = fill ,
449- ** cell_kwargs ,
448+ new_x = new_xx ,
449+ new_y = new_yy ,
450450 )
451451 elif multiline : # automatic word - warp
452452 pdf .multi_cell (
@@ -457,7 +457,8 @@ def _text(
457457 align = align ,
458458 fill = fill ,
459459 wrapmode = WrapMode .coerce (wrapmode ),
460- ** cell_kwargs ,
460+ new_x = new_xx ,
461+ new_y = new_yy ,
461462 )
462463 else : # trim to fit exactly the space defined
463464 text = pdf .multi_cell ( # type: ignore[index,assignment]
@@ -476,7 +477,8 @@ def _text(
476477 border = 0 ,
477478 align = align ,
478479 fill = fill ,
479- ** cell_kwargs ,
480+ new_x = new_xx ,
481+ new_y = new_yy ,
480482 )
481483
482484 def _line (
0 commit comments