Skip to content

Commit

Permalink
CSSTUDIO-2749 Add configuration option 'org.csstudio.display.builder.…
Browse files Browse the repository at this point in the history
…representation/svg_rendering_resolution_factor'.
  • Loading branch information
abrahamwolk committed Nov 22, 2024
1 parent bac3f06 commit 6029e4d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import javafx.scene.image.Image;
import org.csstudio.display.builder.model.util.ModelResourceUtil;
import org.csstudio.display.builder.representation.Preferences;
import org.phoebus.ui.javafx.ImageCache;
import org.phoebus.ui.javafx.svg.SVGTranscoder;

Expand Down Expand Up @@ -53,11 +54,20 @@ public class SVGHelper {
*/
public static Image loadSVG(String imageFileName, double width, double height) {
String cachedSVGFileName = imageFileName + "_" + width + "_" + height;

double svg_rendering_resolution_factor;
if (!Double.isNaN(Preferences.svg_rendering_resolution_factor) && Preferences.svg_rendering_resolution_factor > 0) {
svg_rendering_resolution_factor = Preferences.svg_rendering_resolution_factor;
}
else {
logger.log(Level.WARNING, "The option 'org.csstudio.display.builder.representation/svg_rendering_resolution_factor' is set to an invalid value. Setting svg_rendering_resolution_factor to 1.");
svg_rendering_resolution_factor = 1.0;
}
return ImageCache.cache(cachedSVGFileName, () ->
{
// Open the image from the stream created from the resource file.
try (InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)) {
return SVGTranscoder.loadSVG(inputStream, width, height);
return SVGTranscoder.loadSVG(inputStream, width*svg_rendering_resolution_factor, height*svg_rendering_resolution_factor);
} catch (Exception ex) {
logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class Preferences
update_accumulation_time, update_delay, plot_update_delay, image_update_delay,
tooltip_length, embedded_timeout;

@Preference
public static double svg_rendering_resolution_factor;

static
{
AnnotatedPreferences.initialize(Preferences.class, "/display_representation_preferences.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,21 @@ tooltip_length=200

# Timeout for load / unload of Embedded Widget content [ms]
embedded_timeout=5000

# 'svg_rendering_resolution_factor' determines a factor
# to multiply the rendering resolution of SVGs with.
# E.g., to render SVGs at double the default resolution
# both horizontally and vertically, the option can be
# set to svg_rendering_resolution_factor=2.0. This option
# can be useful to enable sharper rendering when zooming
# in. However, the additional sharpness comes at the
# cost of a significant increase in memory consumption,
# as described in the next paragraph.
#
# IMPORTANT: The memory consumption scales as the square of
# the value of 'svg_rendering_resolution_factor'! E.g.,
# when svg_rendering_resolution_factor=2.0, then rendered SVGs
# consume 4 times the memory compared to rendered SVGs when
# svg_rendering_resolution_factor=1.0. For this reason,
# this option should almost certainly be a very low number.
svg_rendering_resolution_factor=1.0

0 comments on commit 6029e4d

Please sign in to comment.