com.plantuml.api.cheerpj.StringBounderCanvas Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package com.plantuml.api.cheerpj;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import net.sourceforge.plantuml.klimt.font.StringBounderRaw;
import net.sourceforge.plantuml.klimt.font.UFont;
import net.sourceforge.plantuml.klimt.font.UFontContext;
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
public class StringBounderCanvas extends StringBounderRaw {
private final Graphics2D g2d;
public StringBounderCanvas(Graphics2D g2d) {
super(g2d.getFontRenderContext());
this.g2d = g2d;
}
@Override
public boolean matchesProperty(String propertyName) {
return false;
}
@Override
protected XDimension2D calculateDimensionInternal(UFont font, String text) {
final Font javaFont = font.getUnderlayingFont(UFontContext.G2D);
final FontMetrics fm = g2d.getFontMetrics(javaFont);
final Rectangle2D rect = fm.getStringBounds(text, g2d);
return new XDimension2D(rect.getWidth(), rect.getHeight());
}
}