Skip to content
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

Adding support for fill-opacity #325

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

Mbodin
Copy link
Contributor

@Mbodin Mbodin commented Nov 27, 2023

I was in need of the fill-opacity attribute, so I did these changes. I haven't changed the parser yet, but I'm not sure where to start.

The attribute fill-opacity takes the same kind of argument than offset (a number or a percentage), but they mean different things: I think that it would not make sense to reuse the type offset (being either a number or a percentage), so I introduced a number_or_percentage type. Maybe we should instead declare several types for offset and fill_opacity?

@Drup
Copy link
Member

Drup commented Nov 27, 2023

we do tend to try to use semantics names for the various possible inputs, but that's to be evaluated ton a case by case basis. Remind me what are the semantics in the offset and the opacity cases ?

@Mbodin
Copy link
Contributor Author

Mbodin commented Nov 28, 2023

Right. Then it's better to define different types: I'll revert the renaming to offset and create a new type ☺

I think that offset relates to patterns: it moves the start of the pattern (for instance on dashed lines). If provided a percentage, then it's along the line for that percentage (and it can be negative or greater than 100%), if a number, it represents a distance (I don't know why one can't provide a unit there).

For fill-opacity, the percentage must be between 0% and 100% (it's just the opacity), and the number must be between 0 and 1. So it's not only used to represent different things (distance vs alpha), but also has different bounds.

I'm going to change this ☺

@Drup
Copy link
Member

Drup commented Nov 28, 2023

Given your description ... maybe we could just mandate a float between 0 and 1 for the opacity, actually. The two representations are redundant.

@Mbodin
Copy link
Contributor Author

Mbodin commented Nov 29, 2023

The attribute fill-opacity itself can be seen as redundant with style='fill-opacity:__;', but it is useful as least for parsing. Is it fine to parse both percentages and numbers, but only using number internally?

@Drup
Copy link
Member

Drup commented Nov 30, 2023

There are three things: 1) The API, 2) The representation 3) The parsing

Parsing should be complete (in this case, accepting both form), API should be convenient (In this case, avoid 15 layers of data format), and the internal representation should yield valid HTML5 (in this case, whatever works).

@Mbodin
Copy link
Contributor Author

Mbodin commented Nov 30, 2023

Great! So let's write it such that we are able to write both percentages and numbers, but only storing numbers internally, and only printing out numbers ☺

I changed things in reflect.ml to be able to use my parser. I'm really not used to this kind of things (it feels like writing Ltac definitions in Coq). I hope that I did not do anything too wrong.

By the way, I noticed that there is a fill_rule parser defined in syntax/attribute_value.ml which is unused in syntax/reflect/reflect.ml. Is it normal?

@Drup
Copy link
Member

Drup commented Nov 30, 2023

I changed things in reflect.ml to be able to use my parser. I'm really not used to this kind of things (it feels like writing Ltac definitions in Coq). I hope that I did not do anything too wrong.

Yeah, it's ... not very structured. It works surprisingly well in practice :D

By the way, I noticed that there is a fill_rule parser defined in syntax/attribute_value.ml which is unused in syntax/reflect/reflect.ml. Is it normal?

.... not sure. Probably not!

@Mbodin
Copy link
Contributor Author

Mbodin commented Dec 1, 2023

Sorry for the amount of commits: it took me some time to understand how everything works.

I'm starting to appreciate the point that I reached regarding the opacity attributes. What do you think?

Copy link
Member

@Drup Drup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks excellent 👍

I made some misc comments, and we can merge just after.

Note that the use of Re_str is not mandatory, just tends to yield quick implementation.

syntax/attribute_value.ml Show resolved Hide resolved
syntax/attribute_value.ml Outdated Show resolved Hide resolved
lib/svg_types.mli Outdated Show resolved Hide resolved
syntax/attribute_value.ml Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants