Improve SVG layout

This commit is contained in:
Christoph Hagen 2022-12-27 09:57:34 +01:00
parent 5ecfc0d51d
commit 67a0da13bd
2 changed files with 7 additions and 10 deletions

View File

@ -4,10 +4,6 @@ typealias SVGSelection = (x: Int, y: Int, width: Int, height: Int)
struct HTMLElementsGenerator { struct HTMLElementsGenerator {
init() {
}
func make(title: String, suffix: String) -> String { func make(title: String, suffix: String) -> String {
"\(title)<span class=\"suffix\">\(suffix)</span>" "\(title)<span class=\"suffix\">\(suffix)</span>"
} }
@ -40,16 +36,17 @@ struct HTMLElementsGenerator {
} }
func image(file: String, width: Int, height: Int, altText: String) -> String { func image(file: String, width: Int, height: Int, altText: String) -> String {
""" let ratio = Float(width) / Float(height)
return """
<span class="image"> <span class="image">
<img src="\(file)" loading="lazy" width="\(width)" height="\(height)" alt="\(altText)"/> <img src="\(file)" loading="lazy" style="aspect-ratio:\(ratio)" alt="\(altText)"/>
</span> </span>
""" """
} }
func svgImage(file: String, part: SVGSelection, width: Int, height: Int, altText: String) -> String { func svgImage(file: String, part: SVGSelection, altText: String) -> String {
let path = "\(file)#svgView(viewBox(\(part.x),\(part.y),\(part.width),\(part.height))" let path = "\(file)#svgView(viewBox(\(part.x), \(part.y), \(part.width), \(part.height)))"
return image(file: path, width: width, height: height, altText: altText) return image(file: path, width: part.width, height: part.height, altText: altText)
} }
func downloadButtons(_ buttons: [(file: String, text: String, downloadName: String?)]) -> String { func downloadButtons(_ buttons: [(file: String, text: String, downloadName: String?)]) -> String {

View File

@ -236,7 +236,7 @@ struct PageContentGenerator {
return factory.html.image(file: file, width: width, height: height, altText: altText) return factory.html.image(file: file, width: width, height: height, altText: altText)
} }
let part = SVGSelection(x, y, partWidth, partHeight) let part = SVGSelection(x, y, partWidth, partHeight)
return factory.html.svgImage(file: file, part: part, width: width, height: height, altText: altText) return factory.html.svgImage(file: file, part: part, altText: altText)
} }
private func handleFile(page: Element, file: String, fileExtension: String) -> String { private func handleFile(page: Element, file: String, fileExtension: String) -> String {