MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / recover_bbox_quad

Function recover_bbox_quad

src_classic/utils.py:4978–5025  ·  view source on GitHub ↗

Compute the quad located inside the bbox. The bbox may be any of the resp. tuples occurring inside the given span. Args: line_dir: (tuple) 'line["dir"]' of the owning line or None. span: (dict) the span. May be from get_texttrace() method. bbox: (tuple) the bbox of

(line_dir: tuple, span: dict, bbox: tuple)

Source from the content-addressed store, hash-verified

4976# Functions to recover the quad contained in a text extraction bbox
4977# -------------------------------------------------------------------
4978def recover_bbox_quad(line_dir: tuple, span: dict, bbox: tuple) -> Quad:
4979 """Compute the quad located inside the bbox.
4980
4981 The bbox may be any of the resp. tuples occurring inside the given span.
4982
4983 Args:
4984 line_dir: (tuple) 'line["dir"]' of the owning line or None.
4985 span: (dict) the span. May be from get_texttrace() method.
4986 bbox: (tuple) the bbox of the span or any of its characters.
4987 Returns:
4988 The quad which is wrapped by the bbox.
4989 """
4990 if line_dir == None:
4991 line_dir = span["dir"]
4992 cos, sin = line_dir
4993 bbox = Rect(bbox) # make it a rect
4994 if TOOLS.set_small_glyph_heights(): # ==> just fontsize as height
4995 d = 1
4996 else:
4997 d = span["ascender"] - span["descender"]
4998
4999 height = d * span["size"] # the quad's rectangle height
5000 # The following are distances from the bbox corners, at wich we find the
5001 # respective quad points. The computation depends on in which quadrant
5002 # the text writing angle is located.
5003 hs = height * sin
5004 hc = height * cos
5005 if hc >= 0 and hs <= 0: # quadrant 1
5006 ul = bbox.bl - (0, hc)
5007 ur = bbox.tr + (hs, 0)
5008 ll = bbox.bl - (hs, 0)
5009 lr = bbox.tr + (0, hc)
5010 elif hc <= 0 and hs <= 0: # quadrant 2
5011 ul = bbox.br + (hs, 0)
5012 ur = bbox.tl - (0, hc)
5013 ll = bbox.br + (0, hc)
5014 lr = bbox.tl - (hs, 0)
5015 elif hc <= 0 and hs >= 0: # quadrant 3
5016 ul = bbox.tr - (0, hc)
5017 ur = bbox.bl + (hs, 0)
5018 ll = bbox.tr - (hs, 0)
5019 lr = bbox.bl + (0, hc)
5020 else: # quadrant 4
5021 ul = bbox.tl + (hs, 0)
5022 ur = bbox.br - (0, hc)
5023 ll = bbox.tl + (0, hc)
5024 lr = bbox.br - (hs, 0)
5025 return Quad(ul, ur, ll, lr)
5026
5027
5028def recover_quad(line_dir: tuple, span: dict) -> Quad:

Callers 2

recover_quadFunction · 0.70
recover_char_quadFunction · 0.70

Calls 3

RectClass · 0.85
QuadClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…