# Etiket taslagi iskeleti: yuvarlatilmis poligon sekil + 3 mm tasma + kesim cizgisi. # Kullanim: W,H, SHAPE noktalarini, svg_body ve html_body'yi doldur; python3 label_gen.py # Sonra browser_exec ile file:// ac ve Page.printToPDF(preferCSSPageSize=True, printBackground=True). import math, os W, H, B = 105.0, 80.0, 3.0 # kesim olcusu mm, tasma def offset_poly(pts, d): n = len(pts); lines = [] for i in range(n): (x1, y1), (x2, y2) = pts[i], pts[(i + 1) % n] dx, dy = x2 - x1, y2 - y1; L = math.hypot(dx, dy) nx, ny = dy / L, -dx / L lines.append(((x1 + nx * d, y1 + ny * d), (x2 + nx * d, y2 + ny * d))) out = [] for i in range(n): (x1, y1), (x2, y2) = lines[i - 1]; (x3, y3), (x4, y4) = lines[i] den = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4) t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den out.append((x1 + t * (x2 - x1), y1 + t * (y2 - y1))) return out def area_sign(p): return sum(p[i][0] * p[(i + 1) % len(p)][1] - p[(i + 1) % len(p)][0] * p[i][1] for i in range(len(p))) def rounded(pts, radii): n = len(pts); segs = [] for i in range(n): p0, p1, p2 = pts[i - 1], pts[i], pts[(i + 1) % n] def tw(a, b, r): dx, dy = b[0] - a[0], b[1] - a[1]; L = math.hypot(dx, dy); r = min(r, L / 2.2) return (a[0] + dx / L * r, a[1] + dy / L * r) segs.append((tw(p1, p0, radii[i]), p1, tw(p1, p2, radii[i]))) d = f"M{segs[0][2][0]:.3f},{segs[0][2][1]:.3f} " for i in range(1, n + 1): a, c, b = segs[i % n] d += f"L{a[0]:.3f},{a[1]:.3f} Q{c[0]:.3f},{c[1]:.3f} {b[0]:.3f},{b[1]:.3f} " return d + "Z" def T(x, y, html, cls="", style=""): return f'
{html}
' def page(svg_body, html_body, poly, radii, cid, dieline=True): trim = rounded(poly, radii) bl = rounded(offset_poly(poly, B if area_sign(poly) > 0 else -B), [r + B for r in radii]) dl = f'' if dieline else "" return (f'
' f'' f'{svg_body}{dl}' f'
{html_body}
') CSS = f'''@font-face {{ font-family:"SFR"; src:url("file:///System/Library/Fonts/SFNSRounded.ttf"); font-weight:100 1000; }} @page {{ size:{W+2*B}mm {H+2*B}mm; margin:0; }} html,body {{ margin:0; }} .pg {{ position:relative; width:{W+2*B}mm; height:{H+2*B}mm; overflow:hidden; page-break-after:always; }} .art,.ov {{ position:absolute; left:0; top:0; }} .ov {{ width:100%; height:100%; }} .t {{ position:absolute; white-space:nowrap; }}''' if __name__ == "__main__": SHAPE = [(0, 80), (0, 62), (56, 2), (78, 2), (105, 58), (105, 80)] # ornek ucgen on yuz RAD = [5, 7, 9, 9, 7, 5] body = page('', T(8, 72, "ORNEK", "", "font-family:SFR;font-weight:900;color:#fff;font-size:5mm"), SHAPE, RAD, "c1") out = os.path.join(os.path.dirname(os.path.abspath(__file__)), "label.html") open(out, "w", encoding="utf-8").write(f'{body}') print(out)