@@ -368,21 +368,6 @@ export function createImagePreviewModal(htmlData, service) {
368
368
width: 750px !important;
369
369
box-sizing: border-box !important;
370
370
}
371
- .xiaohongshu-page {
372
- height: auto !important;
373
- min-height: 100% !important;
374
- overflow: visible !important;
375
- padding: 12px !important;
376
- width: 750px !important;
377
- box-sizing: border-box !important;
378
- transform: none !important;
379
- max-width: 100% !important;
380
- margin: 0 auto !important;
381
- background-color: white !important;
382
- position: relative !important;
383
- z-index: 1 !important;
384
- display: block !important;
385
- }
386
371
.chat-container {
387
372
overflow: visible !important;
388
373
padding: 12px !important;
@@ -625,7 +610,7 @@ export function createImagePreviewModal(htmlData, service) {
625
610
allowTaint : true ,
626
611
useCORS : true ,
627
612
logging : false ,
628
- scale : isXiaohongshuPage ? 3 : 2 , // 小红书页面使用更高清的3倍图
613
+ scale : 2 , // 提高缩放比例到3倍以获得更高清晰度
629
614
backgroundColor : '#FFFFFF' ,
630
615
windowWidth : 750 ,
631
616
windowHeight : contentHeight ,
@@ -634,39 +619,29 @@ export function createImagePreviewModal(htmlData, service) {
634
619
scrollY : 0 ,
635
620
scrollX : 0 ,
636
621
removeContainer : true ,
637
- // 尝试更好的文本渲染
622
+ // 优化文本渲染
638
623
letterRendering : true ,
624
+ textRendering : 'geometricPrecision' , // 使用几何精度文本渲染
625
+ fontDisplay : 'swap' , // 字体加载策略
639
626
useCORS : true ,
640
627
allowTaint : true ,
641
- foreignObjectRendering : isXiaohongshuPage , // 对小红书页面尝试启用foreignObject渲染
642
- ignoreElements : ( element ) => {
643
- return element . classList &&
644
- ( element . classList . contains ( 'ignore-for-screenshot' ) ||
645
- element . classList . contains ( 'scroll-indicator' ) ) ;
646
- } ,
647
- // 针对小红书页面的特殊优化
648
- imageTimeout : 0 , // 不设置图像加载超时
649
- onclone : ( clonedDoc ) => {
650
- if ( isXiaohongshuPage ) {
651
- // 确保克隆文档中的小红书页面样式正确
652
- const xiaohongshuPages = clonedDoc . querySelectorAll ( '.xiaohongshu-page' ) ;
653
- xiaohongshuPages . forEach ( page => {
654
- page . style . width = '750px' ;
655
- page . style . margin = '0 auto' ;
656
- page . style . boxSizing = 'border-box' ;
657
- page . style . transform = 'none' ;
658
- page . style . maxWidth = '100%' ;
659
- page . style . height = 'auto' ;
660
- } ) ;
661
- }
662
- }
628
+ foreignObjectRendering : true , // 启用foreignObject渲染以获得更好的文本质量
629
+ imageTimeout : 0 ,
630
+ // 抗锯齿和平滑设置
631
+ imageSmoothing : true ,
632
+ imageSmoothingEnabled : true ,
633
+ imageSmoothingQuality : 'high' ,
634
+ // Canvas上下文属性
635
+ alpha : true , // 启用alpha通道
636
+ antialias : true , // 启用抗锯齿
637
+ willReadFrequently : true // 优化频繁读取
663
638
} ;
664
639
665
640
html2canvas ( iframeBody , options )
666
641
. then ( canvas => {
667
642
// 小红书页面保持原始尺寸
668
643
const finalCanvas = document . createElement ( 'canvas' ) ;
669
- const originalHeight = canvas . height / options . scale ;
644
+ // const originalHeight = canvas.height / options.scale;
670
645
671
646
// 设置画布尺寸,保留完整内容
672
647
finalCanvas . width = 750 ;
@@ -678,7 +653,7 @@ export function createImagePreviewModal(htmlData, service) {
678
653
const ctx = finalCanvas . getContext ( '2d' ) ;
679
654
680
655
// 填充白色背景
681
- ctx . fillStyle = '#FFFFFF' ;
656
+ // ctx.fillStyle = '#FFFFFF';
682
657
ctx . fillRect ( 0 , 0 , finalCanvas . width , finalCanvas . height ) ;
683
658
684
659
// 关闭图像平滑以获得更清晰的文字
0 commit comments