diff --git a/route/question/share.go b/route/question/share.go index c8f57a9..c02e3e7 100644 --- a/route/question/share.go +++ b/route/question/share.go @@ -68,14 +68,15 @@ const ( // 右侧二维码卡片尺寸 const ( QRCardW = 270 - QRCardH = 315 + QRCardH = 335 QRCardX = ContentX + ContentW - QRCardW - 15 QRCardY = ContentY + (ContentH-QRCardH)/2 ) -// 二维码尺寸 +// 二维码尺寸。190 在 37 模块(High 纠错、55 字符链接)下取整为 5px/模块: +// 实测 5px/模块的卡缩到 480、320 宽仍可解码,4px 时 480 就解不出。 const ( - QRCodeSize = 165 + QRCodeSize = 190 ) // 社交信息 diff --git a/route/question/share_layout_test.go b/route/question/share_layout_test.go index 5766c7d..a40133f 100644 --- a/route/question/share_layout_test.go +++ b/route/question/share_layout_test.go @@ -228,6 +228,31 @@ func TestGenerateQRIsModuleAligned(t *testing.T) { } } +// 模块像素是扫码能力的唯一硬指标:实测 5px/模块的卡缩到 320 宽仍可解码, +// 4px 时缩到 480 就解不出。这里锁住常见链接长度下的模块尺寸。 +func TestGenerateQRModuleSizeAtLeast5(t *testing.T) { + for _, url := range []string{ + "https://box.shiroko.one/_/tamakyi", + "https://box-dev-api.337845818.best/_/tbunread1022181904", + "https://box.shiroko.one/_/a-rather-long-handle-name", + } { + img, err := generateQR(url, nil, QRCodeSize) + if err != nil { + t.Fatal(err) + } + probe, err := qrcode.New(url, qrcode.High) + if err != nil { + t.Fatal(err) + } + probe.DisableBorder = true + mods := len(probe.Bitmap()) + if per := img.Bounds().Dx() / mods; per < 5 { + t.Errorf("%s: %d modules in %dpx -> %dpx/module, want >=5", + url, mods, img.Bounds().Dx(), per) + } + } +} + // 视觉自检:TEST_PREVIEW=1 时把链接区渲成 PNG,人工确认断行与对齐。 func TestShareCardLinkPreview(t *testing.T) { if os.Getenv("TEST_PREVIEW") == "" {