Skip to content

Commit

Permalink
Merge pull request #294 from dedbox/svg-fill-rule-attribute
Browse files Browse the repository at this point in the history
Add svg fill-rule attribute
  • Loading branch information
Drup authored Jun 21, 2022
2 parents b291463 + f4232ba commit b379b73
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Add support for `type` attribute on `<script>` elements
(#293 by Ulrik @ulrikstrid Strid and Chas @cemerick Emerick)

* Add svg `fill-rule` attribute
(#294 by Eric @dedbox Griffis)

# 4.5.0

* Move all the PPXs to ppxlib
Expand Down
8 changes: 8 additions & 0 deletions lib/svg_f.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ let string_of_paint = function
(string_of_iri iri) ^" "^ (string_of_paint_whitout_icc b)
| #paint_whitout_icc as c -> string_of_paint_whitout_icc c

let string_of_fill_rule = function
| `Nonzero -> "nonzero"
| `Evenodd -> "evenodd"

module Make_with_wrapped_functions

(Xml : Xml_sigs.T)
Expand Down Expand Up @@ -535,6 +539,8 @@ struct
let a_animation_fill x =
user_attrib C.string_of_big_variant "fill" x

let a_fill_rule = user_attrib C.string_of_fill_rule "fill-rule"

let a_calcMode x =
user_attrib C.string_of_big_variant "calcMode" x

Expand Down Expand Up @@ -1106,6 +1112,8 @@ struct

let string_of_paint = string_of_paint

let string_of_fill_rule = string_of_fill_rule

let string_of_strokedasharray = function
| [] -> "none"
| l -> list string_of_length l
Expand Down
4 changes: 4 additions & 0 deletions lib/svg_sigs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ module type T = sig
val a_animation_fill : [< | `Freeze | `Remove ] wrap -> [> | `Fill_Animation ] attrib
[@@reflect.attribute "fill" ["animation"]]

val a_fill_rule : fill_rule wrap -> [> | `Fill_rule ] attrib

val a_calcMode :
[< | `Discrete | `Linear | `Paced | `Spline ] wrap -> [> | `CalcMode ] attrib

Expand Down Expand Up @@ -1105,6 +1107,8 @@ module type Wrapped_functions = sig
val string_of_orient : (Svg_types.Unit.angle option, string) Xml.W.ft

val string_of_paint : ([< Svg_types.paint], string) Xml.W.ft

val string_of_fill_rule : ([< Svg_types.fill_rule], string) Xml.W.ft

val string_of_strokedasharray : (Svg_types.lengths, string) Xml.W.ft

Expand Down
4 changes: 4 additions & 0 deletions lib/svg_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ type paint =
[ paint_whitout_icc
| `Icc of (iri * paint_whitout_icc option) ]

type fill_rule =
[ `Nonzero
| `Evenodd ]

(* Transformation *)
type transform =
[ `Matrix of (float * float * float * float * float * float)
Expand Down
11 changes: 11 additions & 0 deletions syntax/attribute_value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,17 @@ let paint ?separated_by:_ ?default:_ loc name s =
`Icc ([%e iri], Some [%e paint_without_icc loc name remainder])]
end [@metaloc loc]

let fill_rule ?separated_by:_ ?default:_ loc _name s =
begin match s with
| "nonzero" ->
Some [%expr `Nonzero]

| "evenodd" ->
Some [%expr `Evenodd]

| _ -> None
end [@metaloc loc]

let srcset_element =
let space = Re_str.regexp " +" in

Expand Down
6 changes: 6 additions & 0 deletions syntax/attribute_value.mli
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ val paint : parser
{:{https://www.w3.org/TR/SVG/painting.html#SpecifyingPaint} Specifying
paint}. *)

val fill_rule : parser
(** Parses an SVG fill-rule value.
@see <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule>
*)

val srcset_element : parser
(** Used for [a_srcset]. *)

Expand Down
10 changes: 10 additions & 0 deletions test/test_jsx.re
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ let svg = (
),
],
),
(
"fill_rule nonzero",
[<path fill_rule="nonzero" />],
[path(~a=[a_fill_rule(`Nonzero)], [])],
),
(
"fill_rule evenodd",
[<path fill_rule="evenodd" />],
[path(~a=[a_fill_rule(`Evenodd)], [])],
),
],
),
);
Expand Down
8 changes: 8 additions & 0 deletions test/test_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ let svg = "svg", SvgTests.make Svg.[
[[%svg "<animation fill='freeze' values='1 2'/>"]],
[animation ~a:[a_animation_fill `Freeze; a_animation_values ["1"; "2"]] []] ;

"fill_rule type nonzero",
[[%svg "<path fill-rule='nonzero'/>"]],
[path ~a:[a_fill_rule `Nonzero] []] ;

"fill_rule type evenodd",
[[%svg "<path fill-rule='evenodd'/>"]],
[path ~a:[a_fill_rule `Evenodd] []] ;

]

let svg_element_names = "svg element names", SvgTests.make Svg.[
Expand Down

0 comments on commit b379b73

Please sign in to comment.