Browse Source

Merge branch 'ye/fix-option-image-rendering'

yemeishu 3 weeks ago
parent
commit
57cefa7747

+ 4 - 0
app/Services/ExamPdfExportService.php

@@ -2761,6 +2761,10 @@ class ExamPdfExportService
                 if ($fullTag === '' || $src === '' || str_starts_with($src, 'data:')) {
                     return $fullTag;
                 }
+                // 选项区图片使用独立规则,不参与全局宽图放大,避免 4 列选项被撑出边界
+                if (stripos($fullTag, 'data-option-image="1"') !== false || stripos($fullTag, "data-option-image='1'") !== false) {
+                    return $fullTag;
+                }
                 if (! $this->shouldApplyAdaptiveSizingToSrc($src)) {
                     return $fullTag;
                 }

+ 7 - 0
resources/views/components/exam/paper-body.blade.php

@@ -235,6 +235,13 @@
                                     $encodedOpt = htmlspecialchars($normalizedOpt, ENT_QUOTES | ENT_HTML5, 'UTF-8');
                                     $renderedOpt = \App\Services\MathFormulaProcessor::processFormulas($encodedOpt);
                                 }
+                                // 仅针对“选项图片”覆盖公式处理器默认的题干尺寸,避免四列布局被 220px 宽图撑出边界
+                                $renderedOpt = preg_replace('/max-width\s*:\s*220px\s*;?/iu', 'max-width:100%;', (string) $renderedOpt);
+                                $renderedOpt = preg_replace('/max-height\s*:\s*60mm\s*;?/iu', 'max-height:28mm;', (string) $renderedOpt);
+                                // 标记选项内图片,供 PDF 全局宽图放大逻辑识别并跳过
+                                $renderedOpt = preg_replace('/<img\b(?![^>]*\bdata-option-image=)/iu', '<img data-option-image="1"', (string) $renderedOpt);
+                                // 兼容未来选项直接使用 <svg> 的场景,同样打标走选项专用规则
+                                $renderedOpt = preg_replace('/<svg\b(?![^>]*\bdata-option-image=)/iu', '<svg data-option-image="1"', (string) $renderedOpt);
 
                                 // 细粒度控制:短选项(如 1/2、-1/3、x、-x)尽量单行展示,长选项允许换行
                                 $rawOptText = html_entity_decode(strip_tags((string) $opt), ENT_QUOTES | ENT_HTML5, 'UTF-8');

+ 1 - 46
resources/views/pdf/exam-paper.blade.php

@@ -133,53 +133,8 @@
             font-family: "NotoSansMonoCJKjp", monospace;
             letter-spacing: 1px;
         }
-        /* 选项容器:不分页 */
-        .options {
-            display: grid;
-            row-gap: 8px;
-            margin-top: 8px;
-            page-break-inside: avoid;
-            break-inside: avoid;
-        }
-        .options-grid-4 {
-            display: grid;
-            grid-template-columns: repeat(4, 1fr);
-            gap: 8px 12px;
-            page-break-inside: avoid;
-            break-inside: avoid;
-        }
-        .options-grid-2 {
-            display: grid;
-            grid-template-columns: 1fr 1fr;
-            gap: 8px 20px;
-            page-break-inside: avoid;
-            break-inside: avoid;
-        }
-        .options-grid-1 {
-            display: grid;
-            grid-template-columns: 1fr;
-            gap: 8px;
-            page-break-inside: avoid;
-            break-inside: avoid;
-        }
-        /* 单个选项:不分页 */
-        .option {
-            width: 100%;
-            font-size: 13.2px;
-            line-height: 1.6;
-            word-wrap: break-word;
-            display: flex;
-            align-items: baseline;
-            page-break-inside: avoid;
-            break-inside: avoid;
-        }
-        .option strong { margin-right: 4px; flex: 0 0 auto; line-height: 1.6; }
-        .option-value { display: inline; }
-        .option-short { white-space: nowrap; }
-        .option-long { white-space: normal; word-break: break-word; }
-        .option-inline { display: inline-flex; align-items: baseline; margin-right: 20px; }
+        /* 选项网格与图片尺寸统一复用 paper-body-core-styles,避免此处覆盖造成4列溢出 */
         .option-compact { line-height: inherit; }
-        .option p, .option div { margin: 0; display: inline; }
         .option .katex {
             font-size: 1em !important;
             vertical-align: 0;

+ 13 - 3
resources/views/pdf/partials/paper-body-core-styles.blade.php

@@ -107,12 +107,22 @@
 }
 .options-grid-4 .option-value {
     display: block;
-    width: 100%;
-    max-width: 100%;
+    flex: 1 1 0;
+    min-width: 0;
+    max-width: calc(100% - 24px);
 }
 .options-grid-4 .option img {
-    max-width: 120px !important;
+    width: 100% !important;
+    max-width: 100% !important;
     max-height: 28mm !important;
+    height: auto !important;
+}
+.options-grid-4 .option svg {
+    width: 100% !important;
+    max-width: 100% !important;
+    max-height: 28mm !important;
+    height: auto !important;
+    display: block;
 }
 .option-short { white-space: nowrap; }
 .option-long { white-space: normal; word-break: break-word; }

+ 9 - 0
resources/views/pdf/partials/paper-exam-shared-image-styles.blade.php

@@ -57,3 +57,12 @@
     margin: 2px 0;
     vertical-align: top;
 }
+.option svg {
+    display: block;
+    max-width: 100%;
+    max-height: 42mm;
+    width: 100%;
+    height: auto;
+    margin: 2px 0;
+    vertical-align: top;
+}