-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_slide_generation.swift
More file actions
262 lines (236 loc) Β· 8.77 KB
/
debug_slide_generation.swift
File metadata and controls
262 lines (236 loc) Β· 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/env swift
import Foundation
// Debug exactly what the NativePowerPointGenerator should be producing
struct MockExportSettings {
var slideBackgroundColor = ColorOption.color("7B2D8E") // Purple
var headerBackgroundColor = ColorOption.none // Clear
var headerFontColor = ColorOption.color("FFFFFF") // White
var headerFontSize = 12
var headerFontStyle = FontStyle.bold
var rowBackgroundColor = ColorOption.none // Clear
var alternatingRowColor = ColorOption.color("D9E2F3")
var useAlternatingRows = true
var cellFontColor = ColorOption.color("FFFFFF") // White
var cellFontSize = 10
var cellFontStyle = FontStyle.regular
enum ColorOption {
case none
case color(String)
var hexValue: String? {
switch self {
case .none: return nil
case .color(let hex): return hex
}
}
}
enum FontStyle {
case regular, bold, italic, boldItalic
var isBold: Bool { self == .bold || self == .boldItalic }
var isItalic: Bool { self == .italic || self == .boldItalic }
}
}
let settings = MockExportSettings()
// Test data - just like what the app should receive
let tableData = [
["Company", "Revenue", "Growth"], // Header
["Apple", "394.3B", "5.4%"], // Row 1
["Microsoft", "211.9B", "17.5%"] // Row 2
]
// Simulate the exact logic from createSlideXML
let numCols = tableData.first?.count ?? 0
let slideWidth = 9144000
let slideHeight = 5143500
let margin = 457200
let titleHeight = 500000
let titleGap = 100000
let tableY = margin + titleHeight + titleGap
let tableWidth = slideWidth - (2 * margin)
let colWidth = tableWidth / numCols
print("π DEBUGGING SLIDE GENERATION")
print("Settings check:")
print(" slideBackgroundColor.hexValue: \(settings.slideBackgroundColor.hexValue ?? "nil")")
print(" headerBackgroundColor.hexValue: \(settings.headerBackgroundColor.hexValue ?? "nil")")
print(" rowBackgroundColor.hexValue: \(settings.rowBackgroundColor.hexValue ?? "nil")")
print("")
// Generate rows exactly like NativePowerPointGenerator
let rows = tableData.enumerated().map { rowIndex, rowData in
let isHeader = rowIndex == 0
let bgColor: String?
let textColor: String?
let fontSize: Int
let fontStyle: MockExportSettings.FontStyle
if isHeader {
bgColor = settings.headerBackgroundColor.hexValue
textColor = settings.headerFontColor.hexValue
fontSize = settings.headerFontSize
fontStyle = settings.headerFontStyle
} else {
if settings.useAlternatingRows && rowIndex % 2 == 0 {
bgColor = settings.alternatingRowColor.hexValue
} else {
bgColor = settings.rowBackgroundColor.hexValue
}
textColor = settings.cellFontColor.hexValue
fontSize = settings.cellFontSize
fontStyle = settings.cellFontStyle
}
print("Row \(rowIndex) (\(isHeader ? "header" : "data")):")
print(" bgColor: \(bgColor ?? "nil")")
print(" textColor: \(textColor ?? "nil")")
print(" data: \(rowData)")
let cells = rowData.enumerated().map { _, cellData in
let cellBgXML: String
if let bg = bgColor {
cellBgXML = "<a:solidFill><a:srgbClr val=\"\(bg)\"/></a:solidFill>"
} else {
cellBgXML = "<a:noFill/>"
}
return """
<a:tc>
<a:txBody>
<a:bodyPr/>
<a:lstStyle/>
<a:p>
<a:r>
<a:rPr lang="en-US" sz="\(fontSize * 100)" \(fontStyle.isBold ? "b=\"1\"" : "")>
<a:solidFill>
<a:srgbClr val="\(textColor ?? "000000")"/>
</a:solidFill>
</a:rPr>
<a:t>\(cellData)</a:t>
</a:r>
</a:p>
</a:txBody>
<a:tcPr>
\(cellBgXML)
</a:tcPr>
</a:tc>
"""
}.joined()
return """
<a:tr h="600000">
\(cells)
</a:tr>
"""
}.joined()
// Generate slide XML exactly like NativePowerPointGenerator
let slideBackgroundXML = settings.slideBackgroundColor.hexValue != nil ? """
<p:bg>
<p:bgPr>
<a:solidFill>
<a:srgbClr val="\(settings.slideBackgroundColor.hexValue!)"/>
</a:solidFill>
<a:effectLst/>
</p:bgPr>
</p:bg>
""" : ""
let slideXML = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
<p:cSld>
\(slideBackgroundXML)
<p:spTree>
<p:nvGrpSpPr>
<p:cNvPr id="1" name=""/>
<p:cNvGrpSpPr/>
<p:nvPr/>
</p:nvGrpSpPr>
<p:grpSpPr>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="9144000" cy="5143500"/>
<a:chOff x="0" y="0"/>
<a:chExt cx="9144000" cy="5143500"/>
</a:xfrm>
</p:grpSpPr>
<!-- Title -->
<p:sp>
<p:nvSpPr>
<p:cNvPr id="2" name="Title"/>
<p:cNvSpPr>
<a:spLocks noGrp="1"/>
</p:cNvSpPr>
<p:nvPr>
<p:ph type="title"/>
</p:nvPr>
</p:nvSpPr>
<p:spPr>
<a:xfrm>
<a:off x="\(margin)" y="\(margin)"/>
<a:ext cx="\(tableWidth)" cy="\(titleHeight)"/>
</a:xfrm>
</p:spPr>
<p:txBody>
<a:bodyPr/>
<a:lstStyle/>
<a:p>
<a:r>
<a:rPr lang="en-US" sz="3200" b="1">
<a:solidFill>
<a:srgbClr val="FFFFFF"/>
</a:solidFill>
</a:rPr>
<a:t>DEBUG: Slide Generation Test</a:t>
</a:r>
</a:p>
</p:txBody>
</p:sp>
<!-- Table -->
<p:graphicFrame>
<p:nvGraphicFramePr>
<p:cNvPr id="3" name="Table"/>
<p:cNvGraphicFramePr>
<a:graphicFrameLocks noGrp="1"/>
</p:cNvGraphicFramePr>
<p:nvPr/>
</p:nvGraphicFramePr>
<p:xfrm>
<a:off x="\(margin)" y="\(tableY)"/>
<a:ext cx="\(tableWidth)" cy="3000000"/>
</p:xfrm>
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">
<a:tbl>
<a:tblPr/>
<a:tblGrid>
\((0..<numCols).map { _ in "<a:gridCol w=\"\(colWidth)\"/>" }.joined())
</a:tblGrid>
\(rows)
</a:tbl>
</a:graphicData>
</a:graphic>
</p:graphicFrame>
</p:spTree>
</p:cSld>
<p:clrMapOvr>
<a:masterClrMapping/>
</p:clrMapOvr>
</p:sld>
"""
print("")
print("π― SLIDE BACKGROUND XML:")
if !slideBackgroundXML.isEmpty {
print("β
Background will be applied:")
print(slideBackgroundXML)
} else {
print("β NO BACKGROUND - slideBackgroundColor.hexValue is nil")
}
print("")
print("π Generated slide XML length: \(slideXML.count) characters")
print("π Background check: \(slideXML.contains("7B2D8E") ? "β
Contains purple" : "β Missing purple")")
print("π Table check: \(slideXML.contains("<a:tbl>") ? "β
Contains table" : "β Missing table")")
print("π Clear cells check: \(slideXML.contains("<a:noFill/>") ? "β
Contains clear cells" : "β Missing clear cells")")
// Quick validation
let lines = slideXML.components(separatedBy: .newlines)
print("")
print("π XML structure check:")
print(" Lines: \(lines.count)")
print(" Has p:bg: \(slideXML.contains("<p:bg>"))")
print(" Has table: \(slideXML.contains("<a:tbl>"))")
print(" Has title: \(slideXML.contains("DEBUG: Slide Generation Test"))")
print("")
print("β
This XML structure should produce a working slide with:")
print(" - Purple background (7B2D8E)")
print(" - White title text")
print(" - Clear header/cell backgrounds")
print(" - White text throughout")