Skip to content

Commit

Permalink
Fixes #194 Zooming even when scale is defined in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
krasa committed Mar 31, 2019
1 parent 6f8815c commit e5cb1cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<li>Added option to use GRAPHVIZ_DOT environment variable preferentially</li>
<li>Grouped file templates</li>
<li>Restoring scroll position after an error</li>
<li>Zooming even when scale is defined in the code</li>
</ul>
<p>2.12</p>
<ul>
Expand Down
23 changes: 19 additions & 4 deletions src/org/plantuml/idea/rendering/PlantUmlRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,38 @@ private static void zoomDiagram(Diagram diagram, int zoom) {
if (diagram instanceof UmlDiagram) {
UmlDiagram umlDiagram = (UmlDiagram) diagram;
Scale scale = umlDiagram.getScale();
if (scale == null) {
umlDiagram.setScale(new ScaleSimple(getSystemScale() * zoom / 100f));

if (scale == null || scale instanceof ScaleSimple || zoom != 100) {
umlDiagram.setScale(calculateScale(zoom, scale));
}
} else if (diagram instanceof NewpagedDiagram) {
NewpagedDiagram newpagedDiagram = (NewpagedDiagram) diagram;
for (Diagram page : newpagedDiagram.getDiagrams()) {
if (page instanceof DescriptionDiagram) {
DescriptionDiagram descriptionDiagram = (DescriptionDiagram) page;
Scale scale = descriptionDiagram.getScale();
if (scale == null) {
descriptionDiagram.setScale(new ScaleSimple(getSystemScale() * zoom / 100f));

if (scale == null || scale instanceof ScaleSimple || zoom != 100) {
descriptionDiagram.setScale(calculateScale(zoom, scale));
}
}
}
}
}

@NotNull
private static ScaleSimple calculateScale(int zoom, Scale scale) {
return new ScaleSimple(getPlantUmlScale(scale) * getSystemScale() * zoom / 100f);
}

private static double getPlantUmlScale(Scale scale) {
double plantUmlScale = 1.0;
if (scale instanceof ScaleSimple) {
plantUmlScale = scale.getScale(1, 1);
}
return plantUmlScale;
}

private static double getSystemScale() {
try {
return JBUI.ScaleContext.create().getScale(JBUI.ScaleType.SYS_SCALE); //TODO API change 2019/03/05
Expand Down

0 comments on commit e5cb1cf

Please sign in to comment.