mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-22 21:15:09 +00:00
Merge pull request #693 from matthew16550/remove-redundant-calculateDimension
Remove some redundant calls to StringBounder.calculateDimension()
This commit is contained in:
commit
9383a24be7
@ -35,6 +35,7 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.ugraphic.g2d;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static net.sourceforge.plantuml.graphic.TextBlockUtils.createTextLayout;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
@ -46,7 +47,6 @@ import java.awt.font.TextLayout;
|
||||
import java.awt.geom.Dimension2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import net.sourceforge.plantuml.Dimension2DDouble;
|
||||
import net.sourceforge.plantuml.EnsureVisible;
|
||||
import net.sourceforge.plantuml.Log;
|
||||
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
||||
@ -84,18 +84,20 @@ public class DriverTextAsPathG2d implements UDriver<Graphics2D> {
|
||||
final FontConfiguration fontConfiguration = shape.getFontConfiguration();
|
||||
|
||||
final UFont font = fontConfiguration.getFont();
|
||||
final Dimension2D dimBack = calculateDimension(font, shape.getText());
|
||||
final Dimension2D dim = stringBounder.calculateDimension(font, shape.getText());
|
||||
final double height = max(10, dim.getHeight());
|
||||
final double width = dim.getWidth();
|
||||
|
||||
if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) {
|
||||
final Color extended = mapper.toColor(fontConfiguration.getExtendedColor());
|
||||
if (extended != null) {
|
||||
g2d.setColor(extended);
|
||||
g2d.setBackground(extended);
|
||||
g2d.fill(new Rectangle2D.Double(x, y - dimBack.getHeight() + 1.5, dimBack.getWidth(), dimBack
|
||||
.getHeight()));
|
||||
g2d.fill(new Rectangle2D.Double(x, y - height + 1.5, width, height));
|
||||
}
|
||||
}
|
||||
visible.ensureVisible(x, y - dimBack.getHeight() + 1.5);
|
||||
visible.ensureVisible(x + dimBack.getWidth(), y + 1.5);
|
||||
visible.ensureVisible(x, y - height + 1.5);
|
||||
visible.ensureVisible(x + width, y + 1.5);
|
||||
|
||||
g2d.setFont(font.getUnderlayingFont());
|
||||
g2d.setColor(mapper.toColor(fontConfiguration.getColor()));
|
||||
@ -109,26 +111,23 @@ public class DriverTextAsPathG2d implements UDriver<Graphics2D> {
|
||||
if (extended != null) {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
}
|
||||
final Dimension2D dim = calculateDimension(font, shape.getText());
|
||||
final int ypos = (int) (y + 2.5);
|
||||
g2d.setStroke(new BasicStroke((float) 1));
|
||||
g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos);
|
||||
g2d.drawLine((int) x, ypos, (int) (x + width), ypos);
|
||||
g2d.setStroke(new BasicStroke());
|
||||
}
|
||||
if (fontConfiguration.containsStyle(FontStyle.WAVE)) {
|
||||
final Dimension2D dim = calculateDimension(font, shape.getText());
|
||||
final int ypos = (int) (y + 2.5) - 1;
|
||||
final HColor extended = fontConfiguration.getExtendedColor();
|
||||
if (extended != null) {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
}
|
||||
for (int i = (int) x; i < x + dim.getWidth() - 5; i += 6) {
|
||||
for (int i = (int) x; i < x + width - 5; i += 6) {
|
||||
g2d.drawLine(i, ypos - 0, i + 3, ypos + 1);
|
||||
g2d.drawLine(i + 3, ypos + 1, i + 6, ypos - 0);
|
||||
}
|
||||
}
|
||||
if (fontConfiguration.containsStyle(FontStyle.STRIKE)) {
|
||||
final Dimension2D dim = calculateDimension(font, shape.getText());
|
||||
final FontMetrics fm = g2d.getFontMetrics(font.getUnderlayingFont());
|
||||
final int ypos = (int) (y - fm.getDescent() - 0.5);
|
||||
final HColor extended = fontConfiguration.getExtendedColor();
|
||||
@ -136,18 +135,8 @@ public class DriverTextAsPathG2d implements UDriver<Graphics2D> {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
}
|
||||
g2d.setStroke(new BasicStroke((float) 1.5));
|
||||
g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos);
|
||||
g2d.drawLine((int) x, ypos, (int) (x + width), ypos);
|
||||
g2d.setStroke(new BasicStroke());
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension2D calculateDimension(UFont font, String text) {
|
||||
final Dimension2D rect = stringBounder.calculateDimension(font, text);
|
||||
double h = rect.getHeight();
|
||||
if (h < 10) {
|
||||
h = 10;
|
||||
}
|
||||
return new Dimension2DDouble(rect.getWidth(), h);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,8 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.ugraphic.g2d;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
@ -46,7 +48,6 @@ import java.awt.geom.Dimension2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.plantuml.Dimension2DDouble;
|
||||
import net.sourceforge.plantuml.EnsureVisible;
|
||||
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
||||
import net.sourceforge.plantuml.graphic.FontStyle;
|
||||
@ -86,16 +87,18 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
for (StyledString styledString : strings) {
|
||||
final FontConfiguration fc = styledString.getStyle() == FontStyle.BOLD ? fontConfiguration.bold()
|
||||
: fontConfiguration;
|
||||
final Dimension2D dim = calculateDimension(fc.getFont(), styledString.getText());
|
||||
printSingleText(g2d, fc, styledString.getText(), x, y, mapper);
|
||||
x += dim.getWidth();
|
||||
x += printSingleText(g2d, fc, styledString.getText(), x, y, mapper);
|
||||
}
|
||||
}
|
||||
|
||||
private void printSingleText(Graphics2D g2d, final FontConfiguration fontConfiguration, final String text, double x,
|
||||
private double printSingleText(Graphics2D g2d, final FontConfiguration fontConfiguration, final String text, double x,
|
||||
double y, ColorMapper mapper) {
|
||||
final UFont font = fontConfiguration.getFont();
|
||||
final HColor extended = fontConfiguration.getExtendedColor();
|
||||
|
||||
final Dimension2D dim = stringBounder.calculateDimension(font, text);
|
||||
final double height = max(10, dim.getHeight());
|
||||
final double width = dim.getWidth();
|
||||
|
||||
final int orientation = 0;
|
||||
|
||||
@ -111,13 +114,10 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
|
||||
} else if (orientation == 0) {
|
||||
|
||||
final Dimension2D dimBack = calculateDimension(font, text);
|
||||
if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) {
|
||||
final Rectangle2D.Double area = new Rectangle2D.Double(x, y - dimBack.getHeight() + 1.5,
|
||||
dimBack.getWidth(), dimBack.getHeight());
|
||||
final Rectangle2D.Double area = new Rectangle2D.Double(x, y - height + 1.5, width, height);
|
||||
if (extended instanceof HColorGradient) {
|
||||
final GradientPaint paint = DriverRectangleG2d.getPaintGradient(x, y, mapper, dimBack.getWidth(),
|
||||
dimBack.getHeight(), extended);
|
||||
final GradientPaint paint = DriverRectangleG2d.getPaintGradient(x, y, mapper, width, height, extended);
|
||||
g2d.setPaint(paint);
|
||||
g2d.fill(area);
|
||||
} else {
|
||||
@ -129,8 +129,8 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
}
|
||||
}
|
||||
}
|
||||
visible.ensureVisible(x, y - dimBack.getHeight() + 1.5);
|
||||
visible.ensureVisible(x + dimBack.getWidth(), y + 1.5);
|
||||
visible.ensureVisible(x, y - height + 1.5);
|
||||
visible.ensureVisible(x + width, y + 1.5);
|
||||
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g2d.setFont(font.getUnderlayingFont());
|
||||
@ -141,44 +141,33 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
if (extended != null) {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
}
|
||||
final Dimension2D dim = calculateDimension(font, text);
|
||||
final int ypos = (int) (y + 2.5);
|
||||
g2d.setStroke(new BasicStroke((float) 1));
|
||||
g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos);
|
||||
g2d.drawLine((int) x, ypos, (int) (x + width), ypos);
|
||||
g2d.setStroke(new BasicStroke());
|
||||
}
|
||||
if (fontConfiguration.containsStyle(FontStyle.WAVE)) {
|
||||
final Dimension2D dim = calculateDimension(font, text);
|
||||
final int ypos = (int) (y + 2.5) - 1;
|
||||
if (extended != null) {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
}
|
||||
for (int i = (int) x; i < x + dim.getWidth() - 5; i += 6) {
|
||||
for (int i = (int) x; i < x + width - 5; i += 6) {
|
||||
g2d.drawLine(i, ypos - 0, i + 3, ypos + 1);
|
||||
g2d.drawLine(i + 3, ypos + 1, i + 6, ypos - 0);
|
||||
}
|
||||
}
|
||||
if (fontConfiguration.containsStyle(FontStyle.STRIKE)) {
|
||||
final Dimension2D dim = calculateDimension(font, text);
|
||||
final FontMetrics fm = g2d.getFontMetrics(font.getUnderlayingFont());
|
||||
final int ypos = (int) (y - fm.getDescent() - 0.5);
|
||||
if (extended != null) {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
}
|
||||
g2d.setStroke(new BasicStroke((float) 1.5));
|
||||
g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos);
|
||||
g2d.drawLine((int) x, ypos, (int) (x + width), ypos);
|
||||
g2d.setStroke(new BasicStroke());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension2D calculateDimension(UFont font, String text) {
|
||||
final Dimension2D rect = stringBounder.calculateDimension(font, text);
|
||||
double h = rect.getHeight();
|
||||
if (h < 10) {
|
||||
h = 10;
|
||||
}
|
||||
return new Dimension2DDouble(rect.getWidth(), h);
|
||||
return width;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user