Question about catch more detail of error Macaw.SVGParserError.invalidContentMode
Opened this issue · 2 comments
Hello, thank you for sharing this library.
I try to parse a Svg from another program via Rust and C bridge via one String. This part is ok, I'm sure @ 100%
But I can't find one simple example SwiftUi (X Code 11.6) working for Svg-text-parse with Macaw and SwiftUi.
My question is about try/catch. I don't find in the debugger how I can catch debug information about my error (after compile with success) :
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Macaw.SVGParserError.invalidContentMode
This is my code :
import SwiftUI
import Macaw
class MacawTextView: MacawView {
// Nothing go here in the debuger
required init?(coder aDecoder: NSCoder) {
let s = String.init(cString: svg_test_chart()) as String
let text = Text(text: s, place: .move(dx: 145, dy: 100))
super.init(frame: CGRect.zero)
node = text
}
// My problem is here
init() {
let s = String.init(cString: svg_test_chart()) as String
let rect = CGRect(x: 100, y: 20, width: 100, height: 100)
let _text = Text(text: s, place: .move(dx: 145, dy: 100))
//super.init(frame: rect)
//node = text
super.init(frame: rect)
node = try! SVGParser.parse(text: s) // The program go out here with: Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Macaw.SVGParserError.invalidContentMode
}
}
struct TextsViewController: UIViewRepresentable {
func makeUIView(context: Context) -> MacawTextView {
return MacawTextView()
}
func updateUIView(_ activityIndicator: MacawTextView, context: Context) {
}
}
struct ContentView: View {
var body: some View {
VStack {
TextsViewController()
}}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
The svg :
<svg class="chord-chart" font-size="16" preserveAspectRatio="xMidYMid mee t" style="background: white;" height="190" width="136" viewBox="0 0 136 190" xmlns="http://www.w3.org/2000/svg">
<g class="grid" style="background: white; stroke: black; stroke-linecap: round;">
<path class="frets" d="M15.5,85 h105,0 M15.5,110 h105,0 M15.5,135 h105,0 M15.5,160 h105,0"/>
<path class="strings" d="M15.5,60 v100,0 M36.5,60 v100,0 M57.5,60 v100,0 M78.5,60 v100,0 M99.5,60 v100,0 M120.5,60 v100,0"/>
</g>
<g>
<circle cx="57.5" cy="97.5" r="9.5"/>
<circle cx="78.5" cy="97.5" r="9.5"/>
<circle cx="99.5" cy="72.5" r="9.5"/>
</g>
<g class="text" style="font-family: Verdana" text-anchor="middle">
<text class="header" x="15.5" y="48">
x
</text>
<text class="header" x="36.5" y="48">
o
</text>
<text class="header" x="120.5" y="48">
o
</text>
<text class="footer" x="15.5" y="178">
</text>
<text class="footer" x="36.5" y="178">
A
</text>
<text class="footer" x="57.5" y="178">
E
</text>
<text class="footer" x="78.5" y="178">
A
</text>
<text class="footer" x="99.5" y="178">
C
</text>
<text class="footer" x="120.5" y="178">
E
</text>
<text class="labels" style="fill: white;" x="57.5" y="103">
2
</text>
<text class="labels" style="fill: white;" x="78.5" y="103">
3
</text>
<text class="labels" style="fill: white;" x="99.5" y="78">
1
</text>
<text class="title" style="font-size:150%;" x="68" y="30">
Am
</text>
</g>
<path class="nut" d="M15.5,60 h-2.5,0 a2.5,2.5,0,0,1,0,-5 h110,0 a2.5,2.5,0,0,1,0,5 z"/>
</svg>
Thanks in advance for your help
Sorry I posted this message late last night, it's only my 3nd day on swift ui
I found the problem in debugger
in SVGParser.swift @ line 235
preserveAspectRatio="xMidYMid mee t"
is not supported now, I have to think my svg generation in rust in another way
Hi Stephane,
If you don't mind I will reopen this issue. If this is correct value in SVG specification then we need to support it as well.