Insert text with optional HTML tags and stylings into a rectangle. Args: rect: (rect-like) rectangle into which the text should be placed. text: (str) text with optional HTML tags and stylings. css: (str) CSS styling commands. scale_low: (floa
(
page,
rect,
text,
*,
css=None,
scale_low=0,
archive=None,
rotate=0,
oc=0,
opacity=1,
overlay=True,
_scale_word_width=True,
_verbose=False,
)
| 12282 | return xref |
| 12283 | |
| 12284 | def insert_htmlbox( |
| 12285 | page, |
| 12286 | rect, |
| 12287 | text, |
| 12288 | *, |
| 12289 | css=None, |
| 12290 | scale_low=0, |
| 12291 | archive=None, |
| 12292 | rotate=0, |
| 12293 | oc=0, |
| 12294 | opacity=1, |
| 12295 | overlay=True, |
| 12296 | _scale_word_width=True, |
| 12297 | _verbose=False, |
| 12298 | ) -> tuple: |
| 12299 | """Insert text with optional HTML tags and stylings into a rectangle. |
| 12300 | |
| 12301 | Args: |
| 12302 | rect: (rect-like) rectangle into which the text should be placed. |
| 12303 | text: (str) text with optional HTML tags and stylings. |
| 12304 | css: (str) CSS styling commands. |
| 12305 | scale_low: (float) force-fit content by scaling it down. Must be in |
| 12306 | range [0, 1]. If 1, no scaling will take place. If 0, arbitrary |
| 12307 | down-scaling is acceptable. A value of 0.1 would mean that content |
| 12308 | may be scaled down by at most 90%. |
| 12309 | archive: Archive object pointing to locations of used fonts or images |
| 12310 | rotate: (int) rotate the text in the box by a multiple of 90 degrees. |
| 12311 | oc: (int) the xref of an OCG / OCMD (Optional Content). |
| 12312 | opacity: (float) set opacity of inserted content. |
| 12313 | overlay: (bool) put text on top of page content. |
| 12314 | _scale_word_width: internal, for testing only. |
| 12315 | _verbose: internal, for testing only. |
| 12316 | Returns: |
| 12317 | A tuple of floats (spare_height, scale). |
| 12318 | spare_height: |
| 12319 | The height of the remaining space in <rect> below the |
| 12320 | text, or -1 if we failed to fit. |
| 12321 | scale: |
| 12322 | The scaling required; `0 < scale <= 1`. |
| 12323 | Will be less than `scale_low` if we failed to fit. |
| 12324 | """ |
| 12325 | # normalize rotation angle |
| 12326 | if not rotate % 90 == 0: |
| 12327 | raise ValueError("bad rotation angle") |
| 12328 | while rotate < 0: |
| 12329 | rotate += 360 |
| 12330 | while rotate >= 360: |
| 12331 | rotate -= 360 |
| 12332 | |
| 12333 | if not 0 <= scale_low <= 1: |
| 12334 | raise ValueError("'scale_low' must be in [0, 1]") |
| 12335 | |
| 12336 | if css is None: |
| 12337 | css = "" |
| 12338 | |
| 12339 | rect = Rect(rect) |
| 12340 | if rotate in (90, 270): |
| 12341 | temp_rect = Rect(0, 0, rect.height, rect.width) |