mirror of
https://github.com/github/awesome-copilot.git
synced 2026-07-14 01:51:02 +00:00
Fix line-height calc in image-annotations annotate.py (#2266)
font.getbbox() returns (left, top, right, bottom), so text line height must be bottom - top (bbox[3] - bbox[1]). The label placement code used bbox[3] - bbox[0] (bottom - left), mixing an x-coordinate into a height and producing a slightly wrong label-box height (empirically off by 0-4px depending on font). The debug heatmap labeling in the same module already uses the correct bbox[3] - bbox[1], so this brings placement in line.
This commit is contained in:
@@ -416,7 +416,8 @@ def annotate_image(image_path, annotations, *,
|
|||||||
cyan = (eb[0] - em_pad, eb[1] - em_pad, eb[2] + em_pad, eb[3] + em_pad)
|
cyan = (eb[0] - em_pad, eb[1] - em_pad, eb[2] + em_pad, eb[3] + em_pad)
|
||||||
lines = spec['label'].split('\n')
|
lines = spec['label'].split('\n')
|
||||||
tw = max(font.getbbox(line)[2] - font.getbbox(line)[0] for line in lines)
|
tw = max(font.getbbox(line)[2] - font.getbbox(line)[0] for line in lines)
|
||||||
line_h = font.getbbox('Ay')[3] - font.getbbox('Ay')[0]
|
bbox = font.getbbox('Ay')
|
||||||
|
line_h = bbox[3] - bbox[1]
|
||||||
th = line_h * len(lines) + 4 * (len(lines) - 1)
|
th = line_h * len(lines) + 4 * (len(lines) - 1)
|
||||||
pw, ph = tw + 2 * TEXT_PAD, th + 2 * TEXT_PAD
|
pw, ph = tw + 2 * TEXT_PAD, th + 2 * TEXT_PAD
|
||||||
cands = _find_candidates(pixels, W, H, cyan, pw, ph, font)
|
cands = _find_candidates(pixels, W, H, cyan, pw, ph, font)
|
||||||
|
|||||||
Reference in New Issue
Block a user