Rework layout engine around exact-glyph collision, add tests and docs sync
Replace the old bbox/heuristic placement (scale search rounds, large-font capping, stratified sampling, fill-retry ladders) with an area-model font sizing pass feeding a C++ exact-glyph collision engine (centroid-biased spiral + random probing, HD clearance refinement, density/hole optimization). Simplify the frontend advanced-params panel and JobParams type to match the surviving config surface, add a layout-constraints test suite and a repeatable benchmark tool, and bring docs/*.md back in sync with current code (plus new TESTING.md and DEPLOYMENT.md). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+11
-7
@@ -40,15 +40,12 @@ def normalize_mask_for_fill(mask):
|
||||
|
||||
|
||||
def calculate_dynamic_dimensions(base_w, base_h, num_words, avg_len=3, mask_stats=None):
|
||||
if not config.AUTO_EXPAND_CANVAS:
|
||||
return base_w, base_h
|
||||
|
||||
effective_fill = config.TARGET_FILL_RATIO if config.TARGET_FILL_RATIO > 0 else max(config.MIN_ACCEPT_FILL_RATIO, 0.82)
|
||||
effective_fill = config.TARGET_FILL_RATIO if config.TARGET_FILL_RATIO > 0 else 0.45
|
||||
mask_fill_ratio = 0.5
|
||||
if mask_stats is not None:
|
||||
mask_fill_ratio = max(0.05, mask_stats["free_ratio"])
|
||||
|
||||
area_per_word = (config.MIN_READABLE_HEIGHT_PX ** 2) * max(1.0, avg_len) * 1.2
|
||||
area_per_word = (config.MIN_READABLE_HEIGHT_PX ** 2) * max(1.0, avg_len) * 1.05
|
||||
required_fillable_area = (num_words * area_per_word * max(1, config.N_REPETITIONS)) / max(effective_fill, 0.1)
|
||||
required_canvas_area = required_fillable_area / mask_fill_ratio
|
||||
current_area = base_w * base_h
|
||||
@@ -56,8 +53,15 @@ def calculate_dynamic_dimensions(base_w, base_h, num_words, avg_len=3, mask_stat
|
||||
scale_factor = (required_canvas_area / current_area) ** 0.5
|
||||
new_w = int(base_w * scale_factor)
|
||||
new_h = int(base_h * scale_factor)
|
||||
new_w = ((new_w // 100) + 1) * 100
|
||||
new_h = ((new_h // 100) + 1) * 100
|
||||
# Cap HD canvas to keep render/export under the speed budget.
|
||||
# 6000px 边长对激光/打印足够,再大收益很小但 SVG/PNG 成本陡增。
|
||||
max_edge = 6000
|
||||
if max(new_w, new_h) > max_edge:
|
||||
s = max_edge / max(new_w, new_h)
|
||||
new_w = int(new_w * s)
|
||||
new_h = int(new_h * s)
|
||||
new_w = max(100, ((new_w // 100) + 1) * 100)
|
||||
new_h = max(100, ((new_h // 100) + 1) * 100)
|
||||
print(f"[Auto-Size] 扩展画布: {base_w}x{base_h} -> {new_w}x{new_h}")
|
||||
return new_w, new_h
|
||||
return base_w, base_h
|
||||
|
||||
Reference in New Issue
Block a user