Exceptions during export with color gradients

0 votes
asked Sep 25 in bug by Dresaan (700 points)

My style contains some color gradients as background colors. When I try to export it as pdf or latex it throws the following exception.
The export as png does work correctly. Also the pdf/latex export works if I change the color to a solid color.
My example code ist also listed below.

skinparam class { BackgroundColor #c3d8f4-#6192d1 BorderColor #505050 FontColor #505050 } class Class{ Dummy }

java.lang.ClassCastException: net.sourceforge.plantuml.graphic.HtmlColorGradient cannot be cast to net.sourceforge.plantuml.graphic.HtmlColorSimple at net.sourceforge.plantuml.ugraphic.ColorMapperIdentity.getMappedColor(ColorMapperIdentity.java:58) at net.sourceforge.plantuml.ugraphic.ColorMapperTransparentWrapper.getMappedColor(ColorMapperTransparentWrapper.java:61) at net.sourceforge.plantuml.ugraphic.tikz.DriverRectangleTikz.draw(DriverRectangleTikz.java:54) at net.sourceforge.plantuml.ugraphic.tikz.DriverRectangleTikz.draw(DriverRectangleTikz.java:45) at net.sourceforge.plantuml.ugraphic.AbstractUGraphic.draw(AbstractUGraphic.java:89) at net.sourceforge.plantuml.svek.image.EntityImageClass.drawInternal(EntityImageClass.java:159) at net.sourceforge.plantuml.svek.image.EntityImageClass.drawU(EntityImageClass.java:128) at net.sourceforge.plantuml.svek.SvekResult.drawU(SvekResult.java:83) at net.sourceforge.plantuml.ugraphic.ImageBuilder.writeImageInternal(ImageBuilder.java:248) at net.sourceforge.plantuml.ugraphic.ImageBuilder.writeImageTOBEMOVED(ImageBuilder.java:172) at net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek.createFileInternal(CucaDiagramFileMakerSvek.java:124) at net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek.createFile(CucaDiagramFileMakerSvek.java:70) at net.sourceforge.plantuml.cucadiagram.CucaDiagram.exportDiagramInternal(CucaDiagram.java:339) at net.sourceforge.plantuml.classdiagram.ClassDiagram.exportDiagramInternal(ClassDiagram.java:207) at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:236) at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:134) at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:154) at net.sourceforge.plantuml.Pipe.managePipe(Pipe.java:95) at net.sourceforge.plantuml.Run.managePipe(Run.java:285) at net.sourceforge.plantuml.Run.main(Run.java:136)

1 Answer

0 votes
answered Sep 25 by plantuml (131,770 points)
selected Oct 5 by Dresaan
Best answer

We have partially solved this issue in last beta:

PlantUML does not crash anymore *but* do not print gradient in that case.

We are not tikz expert here, so some help is somehow needed.

The tikz code generated to print a filled rectangle is the following:

\draw[color=plantucolor0001,fill=plantucolor0000,line width=1.5pt] (6pt,8pt) rectangle (71pt,69.8359pt);

It would be great if someone could change this to gradient, so that we could reuse it in our code.



commented Sep 26 by Dresaan (700 points)
I am also not an tikz expert but I already made some diagrams with it.
Based on https://tex.stackexchange.com/a/8126 I tried the following:

I changed:
\draw[color=plantucolor0001,line width=2.0pt] (6pt,8pt) -- (38pt,8pt) -- (45pt,31.6094pt) -- (52pt,31.6094pt) -- (52pt,63.2188pt) -- (6pt,63.2188pt) -- (6pt,8pt) -- cycle;


\shade[draw=plantucolor0001,line width=2.0pt,bottom color=plantucolor0000,top color=yellow] (6pt,8pt) -- (38pt,8pt) -- (45pt,31.6094pt) -- (52pt,31.6094pt) -- (52pt,63.2188pt) -- (6pt,63.2188pt) -- (6pt,8pt) -- cycle;

What I did was to replaced \draw with \shade, color with draw and fill with bottom color and top color.

Since I am new to PlantUML I don't know all gradient capabilities of PlantUML but in TikZ it is also possible to define an gradient angle or (what you can see pretty often) use a color with percentage transparence. You can see that in the link. They use black and 10% black for the gradient. (Just in case you have similar options.)
commented Sep 28 by plantuml (131,770 points)
Many thanks for your tikz code, it definitively helps!
So we have built a new beta:

This beta exports gradient like this:

\shade[color=plantucolor0002,shading=axis,shading angle=0,bottom color=plantucolor0000,top color=plantucolor0001,line width=1.5pt] (6pt,8pt) rectangle (71pt,69.8359pt);

I must say that we did not test this on LaTeX, so feedback is welcome!

Another point: right now, we have hardcoded "shading=axis,shading angle=0" in our Java code, which probably is not good.
Concerning gradient in PlantUML, there are 4 ways of defining it:

BackgroundColor #c3d8f4-#6192d1
BackgroundColor #c3d8f4|#6192d1
BackgroundColor #c3d8f4\#6192d1
BackgroundColor #c3d8f4/#6192d1

The character -|\/ defines the axis of the gradient.
You'll see the change in PNG output, but not with tikz output, since "angle=0" is hardcoded.
So we need yet another contribution from you :-)
It'll be nice if you could manually change the generated tikz code to tell us which angle value we should use for each -|\/ character.

commented Sep 28 by Dresaan (700 points)
I tested the new version and got some points:
1.    You forgot to change “color” to “draw” for the lines. Therefore, the line color will be ignored and gets transparent.
2.    You inverted the colors. The PlantUML top color becomes the LaTeX bottom color and vice versa.
3.    The shades seem to render a bit different compared to PlantUML. That might be fixable but in my opinion, it does not matter. I just mention it for the “log”

The angles have to be the following (with the assumption that the first color becomes top):
- 0
| 90
/ 45
\ -45
commented Sep 28 by plantuml (131,770 points)
Many thanks for your tests! It really helps and save us a lot of time.

Here is yet another beta:

Except point 3) everything should be ok. Tell us if it's not the case.
Thanks again
commented Sep 29 by Dresaan (700 points)
Sorry, I missed an important detail. TikZ only uses the angle if it comes after the colors. But you write the angle first. When I move it by hand, the angle works.
With the new version, I am unable to test the \ angle. Even png has some problems with that angle and ignores it.
btw: Thanks for the quick response. It’s wonderful to see that something happens :-)
commented Oct 5 by Dresaan (700 points)
Just tested it again and it works. I think I am running beta 20 atm.