-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(primitives): SVG parser/renderer #893
Conversation
@@ -23,7 +23,7 @@ module Sample = { | |||
<View style=containerStyle> | |||
<Canvas | |||
style=outerBox | |||
render={canvasContext => { | |||
render={(canvasContext, _dimensions) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking change: The dimensions of the Canvas
element is now passed into the render function.
| `pc(_) => failwith("TODO - userCoord") | ||
| `percentage(_) => failwith("TODO - userCoord percentage") | ||
| `auto => failwith("TODO - userCoord auto"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of cases in the parser and renderer currently raise Failure
s. This is very useful during development to catch unsupported features, and it's often also not obvious what a reasonable default would be. These exceptions are also caught in the SVGString
component and logged, so they shouldn't crash the app at least. The final implementation should ideally not raise any exceptions though.
type arcSize = | ||
| Small | ||
| Large; | ||
type arcSize = [ | `small | `large]; | ||
|
||
let arcSize = | ||
let arcSize: T.typ(arcSize) = | ||
skiaCEnum( | ||
"sk_path_arc_size_t", | ||
[ | ||
(Small, "SMALL_SK_PATH_ARC_SIZE"), | ||
(Large, "LARGE_SK_PATH_ARC_SIZE"), | ||
(`small, "SMALL_SK_PATH_ARC_SIZE"), | ||
(`large, "LARGE_SK_PATH_ARC_SIZE"), | ||
], | ||
); | ||
|
||
type pathDirection = | ||
| Clockwise | ||
| CounterClockwise; | ||
type pathDirection = [ | `cw | `ccw]; | ||
|
||
let pathDirection = | ||
let pathDirection: T.typ(pathDirection) = | ||
skiaCEnum( | ||
"sk_path_direction_t", | ||
[ | ||
(Clockwise, "CW_SK_PATH_DIRECTION"), | ||
(CounterClockwise, "CCW_SK_PATH_DIRECTION"), | ||
], | ||
[(`cw, "CW_SK_PATH_DIRECTION"), (`ccw, "CCW_SK_PATH_DIRECTION")], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note these breaking changes to the Skia API, because I couldn't figure out how to access the variant constructors without relying on type inference. I also think polymorphic variants are more convenient and natural for variants that are just used as flag/enum arguments.
86c3cb3
to
cec4b5b
Compare
cec4b5b
to
ac71b5c
Compare
Could someone approve this so I can get it merged to keep it from going stale again? It doesn't really interfere with much else, so it's very low risk. |
The TODO list isn't completed ? DO you want I review it ? |
It's not really a TODO list, but rather a list of what's been implemented and what's not. If you'd like to review it that'd be great! |
Co-authored-by: Et7f3 <cadeaudeelie@gmail.com>
Co-authored-by: Et7f3 <cadeaudeelie@gmail.com>
This adds a new
SVG
project that implements parser and renderer for a decent part of the SVG spec. It also adds anSVGString
component and anSVG Example
with a bunch of SVG examples to demo and test. Not all of them work, and some have been duplicated and tweaked a bit to work around missing features, but these are good test cases for future development.Here's a selective list of features that have been implemented, and that IMO would be good additions to have, for anyone wanting to contribute:
<circle>
<ellipse>
<line>
<path>
M
(Move To, absolute)m
(Move To, relative)L
(Line To, absolute)l
(Line To, relative)H
(Horizontal Line, absolute)h
(Horizontal Line, relative)V
(Vertical Line, absolute)v
(Vertical Line, relative)C
(Cubic Bezier Curve, absolute)c
(Cubic Bezier Curve, relative)S
(Cubic Bezier Curve, implied start control point, absolute)C
c
S
s
s
(Cubic Bezier Curve, implied start control point, relative)C
c
S
s
Q
(Quadratic Bezier Curve, absolute)q
(Quadratic Bezier Curve, relative)T
(Quadratic Bezier Curve, implied control point, absolute)Q
q
T
t
t
(Quadratic Bezier Curve, implied control point, relative)Q
q
T
t
A
(Elliptical Arc Curve, absolute)a
(Elliptical Arc Curve, relative)Z
,z
(Close Path)<polygon>
<polyline>
<rect>
<g>
<defs>
<use>
rgb(...)
)currentColor
fill
stroke
stroke-width
stroke-*
fill-*
opacity
em
ex
px
in
cm
mm
pt
pc
%
auto
(element-specific behaviour, partly implemented)viewBox
preserveAspectRatio