@@ -2238,26 +2238,38 @@ def text_annotation(
2238
2238
@check_page
2239
2239
def free_text_annotation (
2240
2240
self ,
2241
- x ,
2242
- y ,
2243
2241
text ,
2244
- w = 1 ,
2245
- h = 1 ,
2242
+ x = None ,
2243
+ y = None ,
2244
+ w = None ,
2245
+ h = None ,
2246
2246
flags = DEFAULT_ANNOT_FLAGS ,
2247
2247
):
2248
2248
"""
2249
2249
Puts a free text annotation on a rectangular area of the page.
2250
2250
2251
2251
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
2254
2252
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
2257
2260
flags (Tuple[fpdf.enums.AnnotationFlag], Tuple[str]): optional list of flags defining annotation properties
2258
2261
"""
2259
2262
if not self .font_family :
2260
2263
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
+
2261
2273
annotation = AnnotationDict (
2262
2274
"FreeText" ,
2263
2275
x * self .k ,
0 commit comments