Spaces:
Sleeping
Sleeping
Upload app.py
Browse files1672 unmodified lines1673167416751676167716761677167816791680168016811682168316845 unmodified lines1690169116921692169316941695169616961697169816991700248 unmodified lines1949195019511952195319541955125 unmodified lines208120822083208420852086208736 unmodified lines212421252126212421272128212921303 unmodified lines21342135213621372138213921402141214221431672 unmodified lines from pptx.dml.color import RGBColor return RGBColor.from_string(hex_str.lstrip("#").upper())
def _pp_fill_text(tf, lines, size, bold=False, color="#111827", align="c", anchor="m", margins=(0, 0, 0, 0)): """把文字寫進 text_frame(每行一個段落)。align: l/c/r;anchor: t/m/b;margins 為英吋 (左, 上, 右, 下)。"""def _pp_fill_text(tf, lines, size, bold=False, color="#111827", align="c", anchor="m", margins=(0, 0, 0, 0), wrap=False): """把文字寫進 text_frame(每行一個段落)。align: l/c/r;anchor: t/m/b;margins 為英吋 (左, 上, 右, 下)。 wrap=True 時交給 PowerPoint 自動換行(字寬估算略偏時會自己折,不會衝出框外)。""" from pptx.util import Pt, Inches from pptx.enum.text import PP_ALIGN, MSO_ANCHOR tf.word_wrap = False tf.word_wrap = bool(wrap) tf.margin_left, tf.margin_top, tf.margin_right, tf.margin_bottom = (Inches(m) for m in margins) tf.vertical_anchor = {"t": MSO_ANCHOR.TOP, "m": MSO_ANCHOR.MIDDLE, "b": MSO_ANCHOR.BOTTOM}[anchor] lines = [lines] if isinstance(lines, str) else list(lines)5 unmodified lines run.font.size, run.font.bold, run.font.name = Pt(size), bold, PPT_FONT run.font.color.rgb = _pp_rgb(color)
def _pp_text(shapes, x, y, w, h, lines, size, bold=False, color="#111827", align="c", anchor="m", name=None):def _pp_text(shapes, x, y, w, h, lines, size, bold=False, color="#111827", align="c", anchor="m", name=None, wrap=False): from pptx.util import Inches tb = shapes.add_textbox(Inches(x), Inches(y), Inches(w), Inches(h)) if name: tb.name = name _pp_fill_text(tb.text_frame, lines, size, bold, color, align, anchor) _pp_fill_text(tb.text_frame, lines, size, bold, color, align, anchor, wrap=wrap) return tb
def _pp_shape(shapes, kind, x, y, w, h, fill=None, line=None, line_pt=1.0, name=None, radius=0.5):248 unmodified lines pt = row.geometry.representative_point() items.append({"name": str(row["label_name"]), "full": str(row["name"]), "lines": lines, "lon": pt.x, "lat": pt.y}) dropped = max(0, len(items) - max(int(max_items), 1)) items = items[:max(int(max_items), 1)] for it in items: it["x"], it["y"] = to_slide([(it["lon"], it["lat"])])[0]125 unmodified lines "y": top + (len(title_lines) * title_pt * 1.26 / 72 + 0.13 if title_lines else 0), "w": ANNO_BOX_W, "h": len(sub_lines) * sub_pt * 1.42 / 72}, "note": {"text": note, "x": ANNO_PAD, "y": bottom + 0.12, "w": ANNO_W - 2 * ANNO_PAD, "pt": 8.5} if note else None, "dropped": dropped, "max_items": int(max_items), "bottom": bottom, "fit": fit, "pt": pt}
36 unmodified lines fill="#FFFFFF", line=_hex_mix(main, "#FFFFFF", 0.62), line_pt=0.75, name=f"說明框 {b['name']}") _pp_text(slide.shapes, b["x"] + 0.11, b["y"] + b["header"] + 0.03 + 0.04, ANNO_BOX_W - 0.22, b["body"] - 0.06, b["lines"], b["pt"], False, "#1F2937", "l", "t", name=f"說明 {b['name']}") name=f"說明 {b['name']}", wrap=True)
t = plan["title"] if t["lines"]:3 unmodified lines if s["lines"]: _pp_text(slide.shapes, s["x"], s["y"], s["w"], s["h"], s["lines"], s["pt"], True, main, "l", "t", name="副標") if plan.get("dropped"): _pp_text(slide.shapes, ANNO_W - ANNO_PAD - 4.2, plan["bottom"] + 0.12, 4.2, 0.24, f"另有 {plan['dropped']} 個地區未顯示(最多 {plan['max_items']} 個)", 8.5, False, "#9CA3AF", "r", "t", name="省略提示") n = plan["note"] if n: _pp_line(slide.shapes, (n["x"], n["y"] - 0.04), (n["x"] + n["w"], n["y"] - 0.04), "#E5E7EB", 0.75)app.py+13-6