|
|
|
@ -31,10 +31,19 @@ class HtmlGenerator: ObservableObject { |
|
|
|
@Published var height: CGFloat = 0 |
|
|
|
@Published var height: CGFloat = 0 |
|
|
|
private var webView: WKWebView = WKWebView() |
|
|
|
private var webView: WKWebView = WKWebView() |
|
|
|
private var groupStageDone: Int = 0 |
|
|
|
private var groupStageDone: Int = 0 |
|
|
|
|
|
|
|
@Published var landscape: Bool = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var baseWidth: CGFloat { |
|
|
|
|
|
|
|
landscape ? 842 : 595 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var baseHeight: CGFloat { |
|
|
|
|
|
|
|
landscape ? 595 : 842 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var estimatedPageCount: Int { |
|
|
|
var estimatedPageCount: Int { |
|
|
|
if let zoomLevel { |
|
|
|
if let zoomLevel { |
|
|
|
let pageSize = CGSize(width: 595 * (1 + zoomLevel), height: 812 * (1 + zoomLevel)) |
|
|
|
let pageSize = CGSize(width: baseWidth * (1 + zoomLevel), height: baseHeight * (1 + zoomLevel)) |
|
|
|
let numberOfPageInWidth = Int(width / pageSize.width) + 1 |
|
|
|
let numberOfPageInWidth = Int(width / pageSize.width) + 1 |
|
|
|
let numberOfPageInHeight = Int(height / pageSize.height) + 1 |
|
|
|
let numberOfPageInHeight = Int(height / pageSize.height) + 1 |
|
|
|
return numberOfPageInWidth * numberOfPageInHeight |
|
|
|
return numberOfPageInWidth * numberOfPageInHeight |
|
|
|
@ -50,17 +59,19 @@ class HtmlGenerator: ObservableObject { |
|
|
|
func generateWebView(webView: WKWebView) { |
|
|
|
func generateWebView(webView: WKWebView) { |
|
|
|
self.webView = webView |
|
|
|
self.webView = webView |
|
|
|
self.webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in |
|
|
|
self.webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in |
|
|
|
|
|
|
|
print("evaluateJavaScript", "readystage", complete, error) |
|
|
|
if complete != nil { |
|
|
|
if complete != nil { |
|
|
|
self.webView.evaluateJavaScript("document.documentElement.scrollHeight", completionHandler: { (height, error) in |
|
|
|
self.webView.evaluateJavaScript("document.documentElement.scrollHeight", completionHandler: { (height, error) in |
|
|
|
|
|
|
|
print("evaluateJavaScript", "height", height, error) |
|
|
|
self.height = height as! CGFloat |
|
|
|
self.height = height as! CGFloat |
|
|
|
|
|
|
|
self.webView.evaluateJavaScript("document.documentElement.scrollWidth", completionHandler: { (width, error) in |
|
|
|
|
|
|
|
print("evaluateJavaScript", "width", width, error) |
|
|
|
|
|
|
|
self.width = width as! CGFloat |
|
|
|
|
|
|
|
if self.completionHandler != nil { |
|
|
|
|
|
|
|
self.buildPDF() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
self.webView.evaluateJavaScript("document.documentElement.scrollWidth", completionHandler: { (width, error) in |
|
|
|
|
|
|
|
self.width = width as! CGFloat |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.completionHandler != nil { |
|
|
|
|
|
|
|
self.buildPDF() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -75,7 +86,7 @@ class HtmlGenerator: ObservableObject { |
|
|
|
|
|
|
|
|
|
|
|
print("bracket", width, height) |
|
|
|
print("bracket", width, height) |
|
|
|
let config = WKPDFConfiguration() |
|
|
|
let config = WKPDFConfiguration() |
|
|
|
config.rect = CGRect(origin: .zero, size: CGSize(width: Int(width), height: Int(width))) |
|
|
|
config.rect = CGRect(origin: .zero, size: CGSize(width: Int(width), height: Int(height))) |
|
|
|
webView.createPDF(configuration: config){ result in |
|
|
|
webView.createPDF(configuration: config){ result in |
|
|
|
switch result{ |
|
|
|
switch result{ |
|
|
|
case .success(let data): |
|
|
|
case .success(let data): |
|
|
|
@ -111,7 +122,7 @@ class HtmlGenerator: ObservableObject { |
|
|
|
try? FileManager.default.removeItem(at: pdfURL!) |
|
|
|
try? FileManager.default.removeItem(at: pdfURL!) |
|
|
|
print("buildPDF", width, height, zoomLevel ?? 0) |
|
|
|
print("buildPDF", width, height, zoomLevel ?? 0) |
|
|
|
if let zoomLevel { |
|
|
|
if let zoomLevel { |
|
|
|
let pageSize = CGSize(width: 595 * (1 + zoomLevel), height: 812 * (1 + zoomLevel)) |
|
|
|
let pageSize = CGSize(width: baseWidth * (1 + zoomLevel), height: baseHeight * (1 + zoomLevel)) |
|
|
|
let numberOfPageInWidth = Int(width / pageSize.width) + 1 |
|
|
|
let numberOfPageInWidth = Int(width / pageSize.width) + 1 |
|
|
|
let numberOfPageInHeight = Int(height / pageSize.height) + 1 |
|
|
|
let numberOfPageInHeight = Int(height / pageSize.height) + 1 |
|
|
|
for w in 0..<numberOfPageInWidth { |
|
|
|
for w in 0..<numberOfPageInWidth { |
|
|
|
@ -159,6 +170,11 @@ class HtmlGenerator: ObservableObject { |
|
|
|
HtmlService.template(tournament: tournament).html(headName: displayHeads, withRank: displayRank, withScore: false) |
|
|
|
HtmlService.template(tournament: tournament).html(headName: displayHeads, withRank: displayRank, withScore: false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func generateLoserBracketHtml(upperRound: Round) -> String { |
|
|
|
|
|
|
|
//HtmlService.groupstage(bracket: tournament.orderedBrackets.first!).html() |
|
|
|
|
|
|
|
HtmlService.loserBracket(upperRound: upperRound).html(headName: displayHeads, withRank: displayRank, withScore: false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var pdfURL: URL? { |
|
|
|
var pdfURL: URL? { |
|
|
|
guard let pdfFolderURL = getFilePath() else { |
|
|
|
guard let pdfFolderURL = getFilePath() else { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
|