fix(worker): align gpu-direct title position/size with frontend preview #2095

Merged
auto-approve-bot merged 1 commits from fix/gpu-direct-title-position-alignment into develop 2026-09-29 17:04:38 +08:00

1 Commits

Author SHA1 Message Date
saas-backend-agent 20f32c576d fix(worker): align gpu-direct title position/size with frontend preview
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 55s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m40s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m31s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m6s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m43s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 4m3s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 4m20s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 5m25s
AI Code Review / AI Code Review (pull_request) Successful in 6m40s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 11m58s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 9m35s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 31s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 55s
Root cause (7 issues in GPU drawtext rendering after PR #2093):
1. margin scaled by HEIGHT*0.05 instead of WIDTH/720 baseline → 1280x720 top
   placed at y=40 (baseline) making text top edge ~0px (partially off-screen);
   1080x1920 portrait placed at 96 vs frontend preview 60px
2. margin_top field from frontend ignored entirely (default 24@720p); user
   adjustments to vertical spacing had no effect
3. position='custom' (drag-to-position from frontend) not handled → fell
   through to default 'bottom'
4. default position was 'bottom' but schema/frontend default is 'top'
5. fontsize/stroke/shadow scaled by height ratio instead of width/720
6. bold defaulted False while ASS path and frontend default True
7. faux-bold stroke width was hardcoded raw 1px (unscaled), breaking
   bold appearance at non-720p resolutions

Fix:
- All length fields (size, stroke width, shadow offset, margins, faux-bold
  border) use 720p reference width scaling via _scale_title_len() to match
  frontend titleCanvas.ts and ass_subtitle_builder._scale_len()
- top position: y = scale(PAD 16 + margin_top default 24) = scale(40) @720p
- bottom position: y = h-th - scale(PAD 16 + margin_bottom default 24)
- center position: y=(h-text_h)/2 (unchanged)
- custom position: pos_x/pos_y (0-100%) → (w-text_w)*pct, (h-text_h)*pct
- margin_top from title_config is honored (frontend default 24@720p)
- default position = 'top' (matches schema DEFAULT_TITLE_SETTINGS)
- default bold = True, faux-bold border scaled by width
- subtitle similarly scaled: default size 24@720p, bottom margin 60@720p,
  stroke width 2@720p

Tests:
- Updated existing assertions to width-scaled values (1280w: title 64/89/107,
  subtitle 43/50, borderw 2/4/7, shadow 5, margins 71/107)
- Added tests for: custom pos (pct xy), margin_top respected, bold default,
  bold=false disables faux stroke, bottom position, portrait (1080x1920)
  width-scaled sizing
- 30/30 unit tests pass; ruff check/format/py_compile clean
2026-09-29 16:51:13 +08:00