ivanceras / svgbob

Convert your ascii diagram scribbles into happy little SVG
http://ivanceras.github.io/svgbob-editor/
Apache License 2.0
3.88k stars 109 forks source link

CSS styling of text inside boxes #73

Open mbrannstrom opened 3 years ago

mbrannstrom commented 3 years ago

I love the new CSS styling feature. It would be great if it was possible to apply styling to text inside boxes (or other shapes).

In the following example, it would be nice to set the text color to e.g. white. (the filter works best in chrome)

+---------+
| Box {a} |
+---------+

# Legend:
a = {
  fill: darkred;
  filter: drop-shadow( 3px 3px 2px rgba(0, 0, 0, .7));
}

E.g. with the syntax:

a:text = { fill: white; }

Or, perhaps even better, make the entire styling block into pure CSS:

# CSS:
.a { fill: darkred; filter: drop-shadow( 3px 3px 2px rgba(0, 0, 0, .7)); }
text.a { fill: white; filter: none; }
text { /* styling of any other text */ }

The <text> element would thus have the class="a" applied, if it is inside a box with that class.

See the current output below:

Skärmavbild 2021-06-07 kl  13 43 05
mdg-utility commented 1 year ago

I'd like to add, that if all text had a text class, we'd be able to set default styles. Piggy backing on this issue request, if the text is within an object, you could add a class called text_object_name in addition to the default text class.

So by default, it would look like so: <text x="42" y="3628" class="text">Statistical</text>

Then, using the example from @mbrannstrom above, the text element would look like so: <text x="18" y="7100" class="text text_a">Box</text>

The legend would look like:

# Legend:
a = {
  fill: darkred;
  filter: drop-shadow( 3px 3px 2px rgba(0, 0, 0, .7));
}
text_a = {
  fill: white;
}

You could use the same/similar logic that you use to add the shape classes to the text elements within the shape.

If I wanted to style all text in the graphic, I'd use the following:

# Legend:
text = {
  fill: crimson;
}
avivace commented 1 year ago

Agree, this unfortunately breaks every rendered SVG on dark themes :/

mdg-utility commented 1 year ago

It just gives the capability to style rendered SVGs. It would be up to the user to add the appropriate CSS, but adding the class itself shouldn't break anything.