Giter VIP home page Giter VIP logo

Comments (4)

0x4a616e avatar 0x4a616e commented on August 16, 2024

Hi! Sorry for the late reply, unfortunately i don't get notified when new issues are created.... do you by any chance still have a code sample for me to try this out? Is this on high dpi displays?

from javafxsvg.

plata avatar plata commented on August 16, 2024

I've tested this on a 2560x1440 monitor. As you can see in the linked pull request, the only thing I did is something like:

final String iconPath = "/icons/icon.svg";
Button testButton = new Button("Press");
testButton.setStyle("-fx-background-image: url('" + MyClass.class.getResource(iconPath).toExternalForm() + "');");

As I've described in the pull request, the issue might be related to some system dependent library installation.

If you have any idea what could cause this, I can try to add javafxsvg to our application again.

from javafxsvg.

0x4a616e avatar 0x4a616e commented on August 16, 2024

Is it possible that you use other styles to set the size of the background image, like -fx-background-size: cover;? I think the issue here is, that javafxsvg just cannot determine the actual size of the target svg to be displayed and thus falls back to a default size (wich is 400x400) for rendering and then, the image is scaled down by javafx in order to make it fit into the button making it look rather blurry.

Unfortunately, I don't really have a good solution to this because i don't think there is any means for javafxsvg to determine the size to the target element when embedding it as a css background image.

There might however be a workaround: If the SVG has the correct size stored in attributes, this might be used by javafxsvg to render the image in the correct size. To use this, make sure you have width and height attribute defined in your svg and then enable svg support like this:

		SvgImageLoaderFactory.install(new AttributeDimensionProvider());

Now, attributes from the svg will be used as the default size if no size is explicitly requested by javafx (e.g. if you have an image control with a given size). You can also create your own dimension provider by implementing DimensionProvider. It'll always be used, when javafx does not request images in a specific size. I have no idea why javafx does not provide image dimensions when using css background images, even if -fx-background-size is set...

I hope this helps!

from javafxsvg.

plata avatar plata commented on August 16, 2024

The thing is that our GUI can be scaled (e.g. for UHD resolutions). This and the fact that we provide the image as part of a theme required us to set it as background image in CSS (at least we could not find a better solution). Therefore your analysis might very well be true.

I don't think we can store the size in the SVG attributes because we need different sizes depending on the GUI scaling.

While implementing a custom DimensionProvider could work, it seems a bit too complicated for the result (we currently use .png and those look nice).

So if this is something in javafx which you cannot work around, feel free to close the issue.

from javafxsvg.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.