CatPtain commited on
Commit
ea732e6
·
verified ·
1 Parent(s): 01a8b48

Upload public.js

Browse files
Files changed (1) hide show
  1. backend/src/routes/public.js +37 -10
backend/src/routes/public.js CHANGED
@@ -19,9 +19,19 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
19
  const slide = pptData.slides[slideIndex];
20
  const theme = pptData.theme || {};
21
 
22
- // 精确计算PPT内容的真实尺寸 - 优先使用预设尺寸,然后基于元素计算
23
  const calculatePptDimensions = (slide) => {
24
- // 1. 优先使用PPT数据中的预设尺寸
 
 
 
 
 
 
 
 
 
 
25
  if (pptData.slideSize && pptData.slideSize.width && pptData.slideSize.height) {
26
  const result = {
27
  width: Math.ceil(pptData.slideSize.width),
@@ -31,7 +41,17 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
31
  return result;
32
  }
33
 
34
- // 2. 使用slide级别的尺寸设置
 
 
 
 
 
 
 
 
 
 
35
  if (slide.width && slide.height) {
36
  const result = {
37
  width: Math.ceil(slide.width),
@@ -41,11 +61,11 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
41
  return result;
42
  }
43
 
44
- // 3. 根据元素分布计算合适的尺寸
45
  if (!slide.elements || slide.elements.length === 0) {
46
- // 如果没有元素,使用标准PPT尺寸
47
- const result = { width: 960, height: 720 }; // 4:3标准比例
48
- console.log(`使用默认尺寸: ${result.width}x${result.height}`);
49
  return result;
50
  }
51
 
@@ -82,9 +102,16 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
82
  const paddingX = Math.max(40, Math.abs(minLeft));
83
  const paddingY = Math.max(40, Math.abs(minTop));
84
 
85
- // 计算最终的PPT尺寸
86
- let finalWidth = Math.max(contentWidth + paddingX * 2, 800);
87
- let finalHeight = Math.max(contentHeight + paddingY * 2, 600);
 
 
 
 
 
 
 
88
 
89
  // 确保尺寸为偶数(避免半像素问题)
90
  finalWidth = Math.ceil(finalWidth / 2) * 2;
 
19
  const slide = pptData.slides[slideIndex];
20
  const theme = pptData.theme || {};
21
 
22
+ // 精确计算PPT内容的真实尺寸 - 使用编辑器的实际尺寸数据
23
  const calculatePptDimensions = (slide) => {
24
+ // 1. 优先使用PPT数据中的viewportSize和viewportRatio(编辑器的真实尺寸)
25
+ if (pptData.viewportSize && pptData.viewportRatio) {
26
+ const result = {
27
+ width: Math.ceil(pptData.viewportSize),
28
+ height: Math.ceil(pptData.viewportSize * pptData.viewportRatio)
29
+ };
30
+ console.log(`使用编辑器真实尺寸: ${result.width}x${result.height} (viewportSize: ${pptData.viewportSize}, viewportRatio: ${pptData.viewportRatio})`);
31
+ return result;
32
+ }
33
+
34
+ // 2. 使用PPT数据中的预设尺寸
35
  if (pptData.slideSize && pptData.slideSize.width && pptData.slideSize.height) {
36
  const result = {
37
  width: Math.ceil(pptData.slideSize.width),
 
41
  return result;
42
  }
43
 
44
+ // 3. 如果PPT数据中有width和height
45
+ if (pptData.width && pptData.height) {
46
+ const result = {
47
+ width: Math.ceil(pptData.width),
48
+ height: Math.ceil(pptData.height)
49
+ };
50
+ console.log(`使用PPT根级尺寸: ${result.width}x${result.height}`);
51
+ return result;
52
+ }
53
+
54
+ // 4. 使用slide级别的尺寸设置
55
  if (slide.width && slide.height) {
56
  const result = {
57
  width: Math.ceil(slide.width),
 
61
  return result;
62
  }
63
 
64
+ // 5. 根据元素分布计算合适的尺寸
65
  if (!slide.elements || slide.elements.length === 0) {
66
+ // 如果没有元素,使用标准PPT尺寸 - 使用PPTist默认尺寸
67
+ const result = { width: 900, height: 506 }; // 16:9标准比例 (viewportSize: 900, viewportRatio: 0.5625)
68
+ console.log(`使用默认尺寸: ${result.width}x${result.height} (16:9比例)`);
69
  return result;
70
  }
71
 
 
102
  const paddingX = Math.max(40, Math.abs(minLeft));
103
  const paddingY = Math.max(40, Math.abs(minTop));
104
 
105
+ // 计算最终的PPT尺寸,但限制在合理范围内
106
+ let finalWidth = Math.max(contentWidth + paddingX * 2, 900);
107
+ let finalHeight = Math.max(contentHeight + paddingY * 2, 506);
108
+
109
+ // 如果计算出的尺寸过大,使用标准比例缩放
110
+ if (finalWidth > 1920 || finalHeight > 1080) {
111
+ const scale = Math.min(1920 / finalWidth, 1080 / finalHeight);
112
+ finalWidth = Math.ceil(finalWidth * scale);
113
+ finalHeight = Math.ceil(finalHeight * scale);
114
+ }
115
 
116
  // 确保尺寸为偶数(避免半像素问题)
117
  finalWidth = Math.ceil(finalWidth / 2) * 2;