feat: implement SText shape
This commit is contained in:
@@ -88,6 +88,42 @@ public class ShapeDraftman implements ShapeVisitor {
|
||||
drawHandlerIfSelected(tri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitText(SText text) {
|
||||
ColorAttributes colAttrs = (ColorAttributes) text.getAttributes(ColorAttributes.ID);
|
||||
|
||||
Font previousFont = g2d.getFont();
|
||||
Color previousColor = g2d.getColor();
|
||||
Font textFont = new Font(text.getFontName(), Font.PLAIN, text.getFontSize());
|
||||
g2d.setFont(textFont);
|
||||
g2d.setColor(resolveTextColor(colAttrs));
|
||||
|
||||
FontMetrics metrics = g2d.getFontMetrics(textFont);
|
||||
int width = metrics.stringWidth(text.getText());
|
||||
int height = metrics.getHeight();
|
||||
text.updateMeasuredBounds(width, height);
|
||||
|
||||
Rectangle bounds = text.getBounds();
|
||||
g2d.drawString(text.getText(), bounds.x, bounds.y + metrics.getAscent());
|
||||
|
||||
g2d.setFont(previousFont);
|
||||
g2d.setColor(previousColor);
|
||||
drawHandlerIfSelected(text);
|
||||
}
|
||||
|
||||
private Color resolveTextColor(ColorAttributes attrs) {
|
||||
if (attrs == null) {
|
||||
return Color.BLACK;
|
||||
}
|
||||
if (attrs.filledColor != null) {
|
||||
return attrs.filledColor;
|
||||
}
|
||||
if (attrs.strokedColor != null) {
|
||||
return attrs.strokedColor;
|
||||
}
|
||||
return Color.BLACK;
|
||||
}
|
||||
|
||||
private void drawHandlerIfSelected(Shape s) {
|
||||
SelectionAttributes selAttrs = (SelectionAttributes) s.getAttributes(SelectionAttributes.ID);
|
||||
if ((selAttrs != null) && (selAttrs.selected)){
|
||||
|
||||
Reference in New Issue
Block a user