diff --git a/src/net/sourceforge/plantuml/PSystemUtils.java b/src/net/sourceforge/plantuml/PSystemUtils.java index 9babbd75a..83e0a0ae5 100644 --- a/src/net/sourceforge/plantuml/PSystemUtils.java +++ b/src/net/sourceforge/plantuml/PSystemUtils.java @@ -243,9 +243,10 @@ public class PSystemUtils { } if (fileFormat.getFileFormat() == FileFormat.PNG) { + final int dpi = system.getSkinParam().getDpi(); result = new PngSplitter(suggestedFile, system.getHorizontalPages(), system.getVerticalPages(), - system.getMetadata(), (int) (system.getScaleCoef(fileFormat) * 96), fileFormat.isWithMetadata(), - system.getSkinParam().getSplitParam()).getFiles(); + system.getMetadata(), dpi, fileFormat.isWithMetadata(), system.getSkinParam().getSplitParam()) + .getFiles(); } final List result2 = new ArrayList(); for (SFile f : result) { @@ -255,29 +256,6 @@ public class PSystemUtils { } - // static private List exportDiagramsGantt1(GanttDiagram system, - // SuggestedFile suggestedFile, - // FileFormatOption fileFormat) throws IOException { - // if (suggestedFile.getFile(0).exists() && - // suggestedFile.getFile(0).isDirectory()) { - // throw new IllegalArgumentException("File is a directory " + suggestedFile); - // } - // OutputStream os = null; - // ImageData imageData = null; - // try { - // if (PSystemUtils.canFileBeWritten(suggestedFile.getFile(0)) == false) { - // return Collections.emptyList(); - // } - // os = SecurityUtils.BufferedOutputStream(suggestedFile.getFile(0))); - // imageData = system.exportDiagram(os, 0, fileFormat); - // } finally { - // if (os != null) { - // os.close(); - // } - // } - // return Arrays.asList(new FileImageData(suggestedFile.getFile(0), imageData)); - // } - static private List exportDiagramsGantt2(GanttDiagram system, SuggestedFile suggestedFile, FileFormatOption fileFormat) throws IOException { if (suggestedFile.getFile(0).exists() && suggestedFile.getFile(0).isDirectory()) { diff --git a/src/net/sourceforge/plantuml/TitledDiagram.java b/src/net/sourceforge/plantuml/TitledDiagram.java index f52043cbb..93d9f5314 100644 --- a/src/net/sourceforge/plantuml/TitledDiagram.java +++ b/src/net/sourceforge/plantuml/TitledDiagram.java @@ -37,6 +37,8 @@ package net.sourceforge.plantuml; import java.io.IOException; +import javax.script.ScriptException; + import net.sourceforge.plantuml.anim.Animation; import net.sourceforge.plantuml.anim.AnimationDecoder; import net.sourceforge.plantuml.command.CommandExecutionResult; @@ -50,8 +52,6 @@ import net.sourceforge.plantuml.sprite.Sprite; import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft; import net.sourceforge.plantuml.style.StyleBuilder; -import javax.script.ScriptException; - public abstract class TitledDiagram extends AbstractPSystem implements Diagram, Annotated { public static final boolean FORCE_SMETANA = false; @@ -212,15 +212,6 @@ public abstract class TitledDiagram extends AbstractPSystem implements Diagram, return useSmetana; } - @Deprecated - // TODO Well I think it's deprecated - whatever uses it should be looked at closely - public final double getScaleCoef(FileFormatOption fileFormatOption) { - if (getSkinParam().getDpi() == 96) { - return fileFormatOption.getScaleCoef(); - } - return getSkinParam().getDpi() * fileFormatOption.getScaleCoef() / 96.0; - } - // This is for backwards compatibility with earlier default margins public ClockwiseTopRightBottomLeft getDefaultMargins() { return ClockwiseTopRightBottomLeft.same(10); diff --git a/src/net/sourceforge/plantuml/project/GanttDiagram.java b/src/net/sourceforge/plantuml/project/GanttDiagram.java index 96e02e05f..db7321735 100644 --- a/src/net/sourceforge/plantuml/project/GanttDiagram.java +++ b/src/net/sourceforge/plantuml/project/GanttDiagram.java @@ -241,11 +241,9 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit if (openClose.getCalendar() == null) { return new TimeHeaderSimple(min, max); } else if (printScale == PrintScale.WEEKLY) { - return new TimeHeaderWeekly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, - nameDays); + return new TimeHeaderWeekly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek); } else if (printScale == PrintScale.MONTHLY) { - return new TimeHeaderMonthly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, - nameDays); + return new TimeHeaderMonthly(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek); } else { return new TimeHeaderDaily(openClose.getCalendar(), min, max, openClose, colorDays, colorDaysOfWeek, nameDays, printStart, printEnd); diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderCalendar.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderCalendar.java new file mode 100644 index 000000000..636063ceb --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderCalendar.java @@ -0,0 +1,112 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * http://plantuml.com/patreon (only 1$ per month!) + * http://plantuml.com/paypal + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * + * Original Author: Arnaud Roques + * + * + */ +package net.sourceforge.plantuml.project.draw; + +import java.util.Map; + +import net.sourceforge.plantuml.project.LoadPlanable; +import net.sourceforge.plantuml.project.time.Day; +import net.sourceforge.plantuml.project.time.DayOfWeek; +import net.sourceforge.plantuml.project.timescale.TimeScale; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.color.HColor; + +public abstract class TimeHeaderCalendar extends TimeHeader { + + protected final LoadPlanable defaultPlan; + protected final Map colorDays; + protected final Map colorDaysOfWeek; + + public TimeHeaderCalendar(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map colorDays, + Map colorDaysOfWeek, TimeScale timeScale) { + super(min, max, timeScale); + this.defaultPlan = defaultPlan; + this.colorDays = colorDays; + this.colorDaysOfWeek = colorDaysOfWeek; + } + + class Pending { + final double x1; + double x2; + final HColor color; + + Pending(HColor color, double x1, double x2) { + this.x1 = x1; + this.x2 = x2; + this.color = color; + } + + public void draw(UGraphic ug, double height) { + drawRectangle(ug.apply(color.bg()), height, x1, x2); + } + } + + protected final void drawTextsBackground(UGraphic ug, double totalHeightWithoutFooter) { + + final double height = totalHeightWithoutFooter - getFullHeaderHeight(); + Pending pending = null; + + for (Day wink = min; wink.compareTo(max) <= 0; wink = wink.increment()) { + final double x1 = getTimeScale().getStartingPosition(wink); + final double x2 = getTimeScale().getEndingPosition(wink); + HColor back = colorDays.get(wink); + // Day of week should be stronger than period of time (back color). + final HColor backDoW = colorDaysOfWeek.get(wink.getDayOfWeek()); + if (backDoW != null) { + back = backDoW; + } + if (back == null && defaultPlan.getLoadAt(wink) == 0) { + back = veryLightGray; + } + if (back == null) { + if (pending != null) + pending.draw(ug, height); + pending = null; + } else { + if (pending != null && pending.color.equals(back) == false) { + pending.draw(ug, height); + pending = null; + } + if (pending == null) { + pending = new Pending(back, x1, x2); + } else { + pending.x2 = x2; + } + } + } + } + +} diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderDaily.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderDaily.java index dc24abe9d..b8acdcfb7 100644 --- a/src/net/sourceforge/plantuml/project/draw/TimeHeaderDaily.java +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderDaily.java @@ -49,7 +49,7 @@ import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColorUtils; -public class TimeHeaderDaily extends TimeHeader { +public class TimeHeaderDaily extends TimeHeaderCalendar { protected double getTimeHeaderHeight() { return Y_POS_ROW28() + 13; @@ -60,17 +60,11 @@ public class TimeHeaderDaily extends TimeHeader { return 24 + 14; } - private final LoadPlanable defaultPlan; - private final Map colorDays; - private final Map colorDaysOfWeek; private final Map nameDays; public TimeHeaderDaily(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map colorDays, Map colorDaysOfWeek, Map nameDays, Day printStart, Day printEnd) { - super(min, max, new TimeScaleDaily(calendar, printStart)); - this.defaultPlan = defaultPlan; - this.colorDays = colorDays; - this.colorDaysOfWeek = colorDaysOfWeek; + super(calendar, min, max, defaultPlan, colorDays, colorDaysOfWeek, new TimeScaleDaily(calendar, printStart)); this.nameDays = nameDays; } @@ -81,7 +75,8 @@ public class TimeHeaderDaily extends TimeHeader { drawTextDayOfMonth(ug.apply(UTranslate.dy(Y_POS_ROW28()))); drawMonths(ug); drawVBars(ug, totalHeightWithoutFooter); - drawVbar(ug, getTimeScale().getStartingPosition(max.increment()), 0, totalHeightWithoutFooter + getTimeFooterHeight()); + drawVbar(ug, getTimeScale().getStartingPosition(max.increment()), 0, + totalHeightWithoutFooter + getTimeFooterHeight()); printNamedDays(ug); drawHline(ug, 0); drawHline(ug, getFullHeaderHeight()); @@ -96,26 +91,6 @@ public class TimeHeaderDaily extends TimeHeader { drawHline(ug, getTimeFooterHeight()); } - private void drawTextsBackground(UGraphic ug, double totalHeightWithoutFooter) { - final double height = totalHeightWithoutFooter - getFullHeaderHeight(); - for (Day wink = min; wink.compareTo(max) <= 0; wink = wink.increment()) { - final double x1 = getTimeScale().getStartingPosition(wink); - final double x2 = getTimeScale().getEndingPosition(wink); - HColor back = colorDays.get(wink); - // Day of week should be stronger than period of time (back color). - final HColor backDoW = colorDaysOfWeek.get(wink.getDayOfWeek()); - if (backDoW != null) { - back = backDoW; - } - if (back == null && defaultPlan.getLoadAt(wink) == 0) { - back = veryLightGray; - } - if (back != null) { - drawRectangle(ug.apply(back.bg()), height, x1 + 1, x2); - } - } - } - private void drawTextsDayOfWeek(UGraphic ug) { for (Day wink = min; wink.compareTo(max) <= 0; wink = wink.increment()) { final double x1 = getTimeScale().getStartingPosition(wink); diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderMonthly.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderMonthly.java index bc4a3433a..a24c26035 100644 --- a/src/net/sourceforge/plantuml/project/draw/TimeHeaderMonthly.java +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderMonthly.java @@ -50,12 +50,7 @@ import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColorUtils; -public class TimeHeaderMonthly extends TimeHeader { - - private final LoadPlanable defaultPlan; - private final Map colorDays; - private final Map colorDaysOfWeek; - +public class TimeHeaderMonthly extends TimeHeaderCalendar { protected double getTimeHeaderHeight() { return 16 + 13; @@ -66,62 +61,9 @@ public class TimeHeaderMonthly extends TimeHeader { } public TimeHeaderMonthly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map colorDays, - Map colorDaysOfWeek, Map nameDays) { - super(min, max, new TimeScaleCompressed(calendar, PrintScale.MONTHLY.getCompress())); - this.defaultPlan = defaultPlan; - this.colorDays = colorDays; - this.colorDaysOfWeek = colorDaysOfWeek; - } - - class Pending { - final double x1; - double x2; - final HColor color; - - Pending(HColor color, double x1, double x2) { - this.x1 = x1; - this.x2 = x2; - this.color = color; - } - - public void draw(UGraphic ug, double height) { - drawRectangle(ug.apply(color.bg()), height, x1, x2); - } - } - - private void drawTextsBackground(UGraphic ug, double totalHeightWithoutFooter) { - - final double height = totalHeightWithoutFooter - getFullHeaderHeight(); - Pending pending = null; - - for (Day wink = min; wink.compareTo(max) <= 0; wink = wink.increment()) { - final double x1 = getTimeScale().getStartingPosition(wink); - final double x2 = getTimeScale().getEndingPosition(wink); - HColor back = colorDays.get(wink); - // Day of week should be stronger than period of time (back color). - final HColor backDoW = colorDaysOfWeek.get(wink.getDayOfWeek()); - if (backDoW != null) { - back = backDoW; - } - if (back == null && defaultPlan.getLoadAt(wink) == 0) { - back = veryLightGray; - } - if (back == null) { - if (pending != null) - pending.draw(ug, height); - pending = null; - } else { - if (pending != null && pending.color.equals(back) == false) { - pending.draw(ug, height); - pending = null; - } - if (pending == null) { - pending = new Pending(back, x1, x2); - } else { - pending.x2 = x2; - } - } - } + Map colorDaysOfWeek) { + super(calendar, min, max, defaultPlan, colorDays, colorDaysOfWeek, + new TimeScaleCompressed(calendar, PrintScale.MONTHLY.getCompress())); } @Override diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java index 3416fdb64..cf606757c 100644 --- a/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java @@ -50,11 +50,7 @@ import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColorUtils; -public class TimeHeaderWeekly extends TimeHeader { - - private final LoadPlanable defaultPlan; - private final Map colorDays; - private final Map colorDaysOfWeek; +public class TimeHeaderWeekly extends TimeHeaderCalendar { protected double getTimeHeaderHeight() { return 16 + 13; @@ -65,11 +61,9 @@ public class TimeHeaderWeekly extends TimeHeader { } public TimeHeaderWeekly(Day calendar, Day min, Day max, LoadPlanable defaultPlan, Map colorDays, - Map colorDaysOfWeek, Map nameDays) { - super(min, max, new TimeScaleCompressed(calendar, PrintScale.WEEKLY.getCompress())); - this.defaultPlan = defaultPlan; - this.colorDays = colorDays; - this.colorDaysOfWeek = colorDaysOfWeek; + Map colorDaysOfWeek) { + super(calendar, min, max, defaultPlan, colorDays, colorDaysOfWeek, + new TimeScaleCompressed(calendar, PrintScale.WEEKLY.getCompress())); } @Override @@ -81,57 +75,6 @@ public class TimeHeaderWeekly extends TimeHeader { drawHline(ug, getFullHeaderHeight()); } - class Pending { - final double x1; - double x2; - final HColor color; - - Pending(HColor color, double x1, double x2) { - this.x1 = x1; - this.x2 = x2; - this.color = color; - } - - public void draw(UGraphic ug, double height) { - drawRectangle(ug.apply(color.bg()), height, x1, x2); - } - } - - private void drawTextsBackground(UGraphic ug, double totalHeightWithoutFooter) { - - final double height = totalHeightWithoutFooter - getFullHeaderHeight(); - Pending pending = null; - - for (Day wink = min; wink.compareTo(max) <= 0; wink = wink.increment()) { - final double x1 = getTimeScale().getStartingPosition(wink); - final double x2 = getTimeScale().getEndingPosition(wink); - HColor back = colorDays.get(wink); - // Day of week should be stronger than period of time (back color). - final HColor backDoW = colorDaysOfWeek.get(wink.getDayOfWeek()); - if (backDoW != null) { - back = backDoW; - } - if (back == null && defaultPlan.getLoadAt(wink) == 0) { - back = veryLightGray; - } - if (back == null) { - if (pending != null) - pending.draw(ug, height); - pending = null; - } else { - if (pending != null && pending.color.equals(back) == false) { - pending.draw(ug, height); - pending = null; - } - if (pending == null) { - pending = new Pending(back, x1, x2); - } else { - pending.x2 = x2; - } - } - } - } - @Override public void drawTimeFooter(UGraphic ug) { drawHline(ug, 0); @@ -145,12 +88,6 @@ public class TimeHeaderWeekly extends TimeHeader { printMonths(ug); } - private void drawBack(UGraphic ug, Day start, Day end, double height) { - final double x1 = getTimeScale().getStartingPosition(start); - final double x2 = getTimeScale().getStartingPosition(end); - drawRectangle(ug, height, x1, x2); - } - private void printMonths(final UGraphic ug) { MonthYear last = null; double lastChangeMonth = -1; diff --git a/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek.java b/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek.java index f8ff9fedc..a8d6a62c4 100644 --- a/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek.java +++ b/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek.java @@ -117,6 +117,8 @@ public final class CucaDiagramFileMakerSvek implements CucaDiagramFileMaker { if (widthwarning != null && widthwarning.matches("\\d+")) { warningOrError = svek2.getWarningOrError(Integer.parseInt(widthwarning)); } + + // Sorry about this hack. There is a side effect in SvekResult::calculateDimension() result.calculateDimension(stringBounder); // Ensure text near the margins is not cut off final HColor backcolor = result.getBackcolor();