@@ -104,13 +104,9 @@ def from_text_annotation(
104104 else :
105105 default_appearance = default_appearance .get_object ()
106106
107- # Use regex to capture the font name and font size with the re.MULTILINE flag
107+ # Get font name and font size from default appearance
108108 pattern = r"(/.*?)\s+(\S+)\s+Tf"
109109 font_match = re .search (pattern , default_appearance , re .MULTILINE )
110-
111- font_name = ""
112- font_size = 0.0
113-
114110 if font_match :
115111 font_name = font_match .group (1 )
116112 font_size = float (font_match .group (2 ))
@@ -123,24 +119,16 @@ def from_text_annotation(
123119 else :
124120 # Handle the case where a font pattern isn't found
125121 font_name = "/Helv"
126- if field .get (FieldDictionaryAttributes .Ff , 0 ) & FieldDictionaryAttributes .FfBits .Multiline :
127- font_size = DEFAULT_FONT_HEIGHT_IN_MULTILINE
128- else :
129- font_size = rect .height - 2
130-
131122 # If font_size is 0, apply the logic for multiline or large-as-possible font
132123 if font_size == 0 :
133124 if field .get (FieldDictionaryAttributes .Ff , 0 ) & FieldDictionaryAttributes .FfBits .Multiline :
134125 font_size = DEFAULT_FONT_HEIGHT_IN_MULTILINE
135126 else :
136127 font_size = rect .height - 2
137-
138128 # Replace the old font name and size with the new ones using re.sub
139129 if font_match :
140130 # The replacement string uses captured groups from the match
141131 replacement = f"{ font_name } { font_size } Tf"
142-
143- # Pass the re.MULTILINE flag to re.sub as well
144132 default_appearance = re .sub (pattern , replacement , default_appearance , flags = re .MULTILINE )
145133 else :
146134 # If no font was found, we need to create the new DA string from scratch
@@ -209,7 +197,7 @@ def from_text_annotation(
209197
210198 # Create the TextStreamAppearance instance
211199 new_appearance_stream = cls (
212- text , selection , default_appearance , font_glyph_byte_map , rect , font_size , y_offset
200+ text , selection , default_appearance , font_glyph_byte_map , rect , font_size
213201 )
214202
215203 if AnnotationDictionaryAttributes .AP in annotation :
0 commit comments