Search in sources :

Example 1 with TextStroke

use of org.geotoolkit.display2d.style.j2d.TextStroke in project geotoolkit by Geomatys.

the class LinearLabelCandidateRenderer method render.

@Override
public void render(final Candidate candidate) {
    if (!(candidate instanceof LinearCandidate))
        return;
    LinearCandidate linearCandidate = (LinearCandidate) candidate;
    LinearLabelDescriptor label = linearCandidate.getDescriptor();
    context.switchToDisplayCRS();
    final TextStroke stroke = new TextStroke(label.getText(), label.getTextFont(), label.isRepeated(), label.getOffSet(), label.getInitialGap(), label.getGap(), context.getCanvasDisplayBounds());
    Shape shp = linearCandidate.getShape();
    if (shp == null) {
        return;
    }
    final Shape shape = stroke.createStrokedShape(shp);
    // paint halo
    if (label.getHaloWidth() > 0) {
        g2.setStroke(new BasicStroke(label.getHaloWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g2.setPaint(label.getHaloPaint());
        g2.draw(shape);
    }
    // paint text
    g2.setStroke(new BasicStroke(0));
    g2.setPaint(label.getTextPaint());
    g2.fill(shape);
}
Also used : LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) BasicStroke(java.awt.BasicStroke) LinearLabelDescriptor(org.geotoolkit.display2d.style.labeling.LinearLabelDescriptor) Shape(java.awt.Shape) TextStroke(org.geotoolkit.display2d.style.j2d.TextStroke)

Example 2 with TextStroke

use of org.geotoolkit.display2d.style.j2d.TextStroke in project geotoolkit by Geomatys.

the class DefaultLabelRenderer method portray.

private void portray(final Graphics2D g2, final LinearLabelDescriptor label) {
    context.switchToDisplayCRS();
    final TextStroke stroke = new TextStroke(label.getText(), label.getTextFont(), label.isRepeated(), label.getOffSet(), label.getInitialGap(), label.getGap(), context.getCanvasDisplayBounds());
    final Shape[] geoms;
    try {
        geoms = label.getGeometry().getDisplayShape();
    } catch (TransformException ex) {
        Logger.getLogger("org.geotoolkit.display2d.style.labeling").log(Level.WARNING, null, ex);
        return;
    }
    for (Shape geom : geoms) {
        final Shape shape = stroke.createStrokedShape(geom);
        // paint halo
        if (label.getHaloWidth() > 0) {
            g2.setStroke(new BasicStroke(label.getHaloWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            g2.setPaint(label.getHaloPaint());
            g2.draw(shape);
        }
        // paint text
        g2.setStroke(new BasicStroke(0));
        g2.setPaint(label.getTextPaint());
        g2.fill(shape);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) TextStroke(org.geotoolkit.display2d.style.j2d.TextStroke) TransformException(org.opengis.referencing.operation.TransformException)

Aggregations

BasicStroke (java.awt.BasicStroke)2 Shape (java.awt.Shape)2 TextStroke (org.geotoolkit.display2d.style.j2d.TextStroke)2 LinearLabelDescriptor (org.geotoolkit.display2d.style.labeling.LinearLabelDescriptor)1 LinearCandidate (org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate)1 TransformException (org.opengis.referencing.operation.TransformException)1