Skip to content

Commit f45a3f9

Browse files
committed
added default values to parameters
#949
1 parent f232461 commit f45a3f9

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

fpdf/fpdf.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -2238,26 +2238,38 @@ def text_annotation(
22382238
@check_page
22392239
def free_text_annotation(
22402240
self,
2241-
x,
2242-
y,
22432241
text,
2244-
w=1,
2245-
h=1,
2242+
x=None,
2243+
y=None,
2244+
w=None,
2245+
h=None,
22462246
flags=DEFAULT_ANNOT_FLAGS,
22472247
):
22482248
"""
22492249
Puts a free text annotation on a rectangular area of the page.
22502250
22512251
Args:
2252-
x (float): horizontal position (from the left) to the left side of the link rectangle
2253-
y (float): vertical position (from the top) to the bottom side of the link rectangle
22542252
text (str): text to display
2255-
w (float): optional width of the link rectangle
2256-
h (float): optional height of the link rectangle
2253+
x (float): optional horizontal position (from the left) to the left side of the link rectangle.
2254+
Default value: None, meaning the current abscissa is used
2255+
y (float): vertical position (from the top) to the bottom side of the link rectangle.
2256+
Default value: None, meaning the current ordinate is used
2257+
w (float): optional width of the link rectangle. Default value: None, meaning the length of text in user unit
2258+
h (float): optional height of the link rectangle. Default value: None, meaning an height equal
2259+
to the current font size
22572260
flags (Tuple[fpdf.enums.AnnotationFlag], Tuple[str]): optional list of flags defining annotation properties
22582261
"""
22592262
if not self.font_family:
22602263
raise FPDFException("No font set, you need to call set_font() beforehand")
2264+
if x is None:
2265+
x = self.x
2266+
if y is None:
2267+
y = self.y
2268+
if h is None:
2269+
h = self.font_size
2270+
if w is None:
2271+
w = self.get_string_width(text, normalized=True, markdown=False)
2272+
22612273
annotation = AnnotationDict(
22622274
"FreeText",
22632275
x * self.k,

0 commit comments

Comments
 (0)