mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-22 21:15:09 +00:00
Pass a StringBounder into DriverTextG2d & DriverTextAsPathG2d
This commit is contained in:
parent
102a7ccf64
commit
102d67271c
@ -48,7 +48,6 @@ import java.awt.geom.Rectangle2D;
|
||||
|
||||
import net.sourceforge.plantuml.Dimension2DDouble;
|
||||
import net.sourceforge.plantuml.EnsureVisible;
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.Log;
|
||||
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
||||
import net.sourceforge.plantuml.graphic.FontStyle;
|
||||
@ -64,9 +63,11 @@ import net.sourceforge.plantuml.ugraphic.color.HColor;
|
||||
public class DriverTextAsPathG2d implements UDriver<Graphics2D> {
|
||||
|
||||
private final EnsureVisible visible;
|
||||
private final StringBounder stringBounder;
|
||||
|
||||
public DriverTextAsPathG2d(EnsureVisible visible) {
|
||||
public DriverTextAsPathG2d(EnsureVisible visible, StringBounder stringBounder) {
|
||||
this.visible = visible;
|
||||
this.stringBounder = stringBounder;
|
||||
}
|
||||
|
||||
private static void printFont() {
|
||||
@ -83,7 +84,7 @@ public class DriverTextAsPathG2d implements UDriver<Graphics2D> {
|
||||
final FontConfiguration fontConfiguration = shape.getFontConfiguration();
|
||||
|
||||
final UFont font = fontConfiguration.getFont().scaled(param.getScale());
|
||||
final Dimension2D dimBack = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, shape.getText());
|
||||
final Dimension2D dimBack = calculateDimension(font, shape.getText());
|
||||
if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) {
|
||||
final Color extended = mapper.toColor(fontConfiguration.getExtendedColor());
|
||||
if (extended != null) {
|
||||
@ -108,14 +109,14 @@ public class DriverTextAsPathG2d implements UDriver<Graphics2D> {
|
||||
if (extended != null) {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
}
|
||||
final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, shape.getText());
|
||||
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.setStroke(new BasicStroke());
|
||||
}
|
||||
if (fontConfiguration.containsStyle(FontStyle.WAVE)) {
|
||||
final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, shape.getText());
|
||||
final Dimension2D dim = calculateDimension(font, shape.getText());
|
||||
final int ypos = (int) (y + 2.5) - 1;
|
||||
final HColor extended = fontConfiguration.getExtendedColor();
|
||||
if (extended != null) {
|
||||
@ -127,7 +128,7 @@ public class DriverTextAsPathG2d implements UDriver<Graphics2D> {
|
||||
}
|
||||
}
|
||||
if (fontConfiguration.containsStyle(FontStyle.STRIKE)) {
|
||||
final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, shape.getText());
|
||||
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();
|
||||
@ -140,7 +141,7 @@ public class DriverTextAsPathG2d implements UDriver<Graphics2D> {
|
||||
}
|
||||
}
|
||||
|
||||
static public Dimension2D calculateDimension(StringBounder stringBounder, UFont font, String text) {
|
||||
public Dimension2D calculateDimension(UFont font, String text) {
|
||||
final Dimension2D rect = stringBounder.calculateDimension(font, text);
|
||||
double h = rect.getHeight();
|
||||
if (h < 10) {
|
||||
|
@ -48,7 +48,6 @@ import java.util.List;
|
||||
|
||||
import net.sourceforge.plantuml.Dimension2DDouble;
|
||||
import net.sourceforge.plantuml.EnsureVisible;
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
||||
import net.sourceforge.plantuml.graphic.FontStyle;
|
||||
import net.sourceforge.plantuml.graphic.StringBounder;
|
||||
@ -66,9 +65,11 @@ import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
|
||||
public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
|
||||
private final EnsureVisible visible;
|
||||
private final StringBounder stringBounder;
|
||||
|
||||
public DriverTextG2d(EnsureVisible visible) {
|
||||
public DriverTextG2d(EnsureVisible visible, StringBounder stringBounder) {
|
||||
this.visible = visible;
|
||||
this.stringBounder = stringBounder;
|
||||
}
|
||||
|
||||
public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) {
|
||||
@ -87,8 +88,7 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
for (StyledString styledString : strings) {
|
||||
final FontConfiguration fc = styledString.getStyle() == FontStyle.BOLD ? fontConfiguration.bold()
|
||||
: fontConfiguration;
|
||||
final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), fc.getFont(),
|
||||
styledString.getText());
|
||||
final Dimension2D dim = calculateDimension(fc.getFont(), styledString.getText());
|
||||
printSingleText(g2d, fc, styledString.getText(), x, y, mapper, param);
|
||||
x += dim.getWidth();
|
||||
}
|
||||
@ -113,7 +113,7 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
|
||||
} else if (orientation == 0) {
|
||||
|
||||
final Dimension2D dimBack = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, text);
|
||||
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());
|
||||
@ -143,14 +143,14 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
if (extended != null) {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
}
|
||||
final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, text);
|
||||
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.setStroke(new BasicStroke());
|
||||
}
|
||||
if (fontConfiguration.containsStyle(FontStyle.WAVE)) {
|
||||
final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, text);
|
||||
final Dimension2D dim = calculateDimension(font, text);
|
||||
final int ypos = (int) (y + 2.5) - 1;
|
||||
if (extended != null) {
|
||||
g2d.setColor(mapper.toColor(extended));
|
||||
@ -161,7 +161,7 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
}
|
||||
}
|
||||
if (fontConfiguration.containsStyle(FontStyle.STRIKE)) {
|
||||
final Dimension2D dim = calculateDimension(FileFormat.PNG.getDefaultStringBounder(), font, text);
|
||||
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) {
|
||||
@ -174,7 +174,7 @@ public class DriverTextG2d implements UDriver<Graphics2D> {
|
||||
}
|
||||
}
|
||||
|
||||
static public Dimension2D calculateDimension(StringBounder stringBounder, UFont font, String text) {
|
||||
public Dimension2D calculateDimension(UFont font, String text) {
|
||||
final Dimension2D rect = stringBounder.calculateDimension(font, text);
|
||||
double h = rect.getHeight();
|
||||
if (h < 10) {
|
||||
|
@ -140,9 +140,9 @@ public class UGraphicG2d extends AbstractUGraphic<Graphics2D> implements EnsureV
|
||||
private void register(double dpiFactor) {
|
||||
registerDriver(URectangle.class, new DriverRectangleG2d(dpiFactor, this));
|
||||
if (this.hasAffineTransform || dpiFactor != 1.0) {
|
||||
registerDriver(UText.class, new DriverTextAsPathG2d(this));
|
||||
registerDriver(UText.class, new DriverTextAsPathG2d(this, getStringBounder()));
|
||||
} else {
|
||||
registerDriver(UText.class, new DriverTextG2d(this));
|
||||
registerDriver(UText.class, new DriverTextG2d(this, getStringBounder()));
|
||||
}
|
||||
registerDriver(ULine.class, new DriverLineG2d(dpiFactor));
|
||||
registerDriver(UPixel.class, new DriverPixelG2d());
|
||||
|
Loading…
Reference in New Issue
Block a user