Package org.geotools.renderer.style

Examples of org.geotools.renderer.style.TextStyle2D


                } else {
                    Iterator<TextSymbolizer> iter = labelStyles.iterator();
                    while (iter.hasNext()) {
                        TextSymbolizer sym = (TextSymbolizer) iter.next();
                        try {
                            TextStyle2D style = (TextStyle2D) styleFactory
                                .createStyle(feature, sym, scaleRange);
                            encodeTextStyle(feature, style, sym);
                        } catch (IllegalArgumentException iae) {
                            LOGGER.fine(iae.getMessage() + " for "
                                    + sym.toString());
View Full Code Here


        graphics = Mockito.mock(Graphics2D.class);
        Mockito.when(graphics.getFontRenderContext()).thenReturn(
                new FontRenderContext(new AffineTransform(),
                        RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT,
                        RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT));
        style = new TextStyle2D();
        style.setFont(new Font("Serif", Font.PLAIN, 10));
        shape = new LiteShape2(
                geometryFactory.createPoint(new Coordinate(10, 10)),
                ProjectiveTransform.create(new AffineTransform()), null, false);
        symbolizer = styleFactory.createTextSymbolizer();
View Full Code Here

     * characters such as a,m,e, and not centering on d,g whose center is
     * affected by the full ascent or the full descent. This method tries to
     * computes the y anchor taking into account those.
     */
    public double getLinePlacementYAnchor() {
        TextStyle2D textStyle = getLabel().getTextStyle();
        LineMetrics lm = textStyle.getFont().getLineMetrics(textStyle.getLabel(),
                graphics.getFontRenderContext());
       
        // gracefully handle font size = 0
        if (lm.getHeight() > 0) {
            return (Math.abs(lm.getStrikethroughOffset()) + lm.getDescent() + lm.getLeading())
View Full Code Here

    }
   
    private LabelCacheItem buildLabelCacheItem(String layerId, TextSymbolizer symbolizer,
            Feature feature, LiteShape2 shape, NumberRange scaleRange, String label,
            double priorityValue) {
        TextStyle2D textStyle = (TextStyle2D) styleFactory.createStyle(feature, symbolizer,
                scaleRange);

        LabelCacheItem item = new LabelCacheItem(layerId, textStyle, shape, label, symbolizer);
        item.setPriority(priorityValue);
        item.setSpaceAround(voParser.getIntOption(symbolizer, SPACE_AROUND_KEY, DEFAULT_SPACE_AROUND));
View Full Code Here

     */
    private void setupLineTransform(LabelPainter painter, LineStringCursor cursor,
            Coordinate centroid, AffineTransform tempTransform, boolean followLine) {
        tempTransform.translate(centroid.x, centroid.y);

        TextStyle2D textStyle = painter.getLabel().getTextStyle();
        double anchorX = textStyle.getAnchorX();
        double anchorY = textStyle.getAnchorY();

        // undo the above if its point placement!
        double rotation;
        double displacementX = 0;
        double displacementY = 0;
        Rectangle2D textBounds = painter.getLabelBounds();
        if (textStyle.isPointPlacement() && !followLine) {
            // use the one the user supplied!
            rotation = textStyle.getRotation();
        } else { // lineplacement
            if(painter.getLabel().isForceLeftToRightEnabled()) {
                rotation = cursor.getLabelOrientation();
            } else {
                rotation = cursor.getCurrentAngle();
            }
            // move it off the line
            displacementY -= textStyle.getPerpendicularOffset() + (painter.getLineCount() - 1)
                    * (textBounds.getHeight() / painter.getLineCount());
            anchorX = 0.5; // centered
            anchorY = painter.getLinePlacementYAnchor();
        }


        displacementX = (anchorX * (-textBounds.getWidth())) + textStyle.getDisplacementX();
        displacementY += (anchorY * (textBounds.getHeight())) - textStyle.getDisplacementY();

        if (Double.isNaN(rotation) || Double.isInfinite(rotation))
            rotation = 0.0;
        tempTransform.rotate(rotation);
        tempTransform.translate(displacementX, displacementY);
View Full Code Here

                displayArea, labelItem.isPartialsEnabled());
        if (point == null)
            return false;

        // prepare for the search loop
        TextStyle2D ts = labelItem.getTextStyle();
        // ... use at least a 2 pixel step, no matter what the label length is
        final double step = painter.getAscent() > 2 ? painter.getAscent() : 2;
        double radius = Math.sqrt(ts.getDisplacementX() * ts.getDisplacementX()
            + ts.getDisplacementY() * ts.getDisplacementY());
        AffineTransform tx = new AffineTransform(tempTransform);
       
        // if straight paint works we're good
        if(paintPointLabelInternal(painter, tx, displayArea, glyphs, labelItem, point, ts)) {
            return true;
        }
       
        // see if we have a search radius
        if(labelItem.maxDisplacement <= 0) {
            return false;
        }
       
        // get a cloned text style that we can modify without issues
        TextStyle2D cloned = new TextStyle2D(ts);
        // ... and the closest quadrant angle that we'll use to start the search from
        int startAngle = getClosestStandardAngle(ts.getDisplacementX(), ts.getDisplacementY());
        int angle = startAngle;
        while(radius <= labelItem.maxDisplacement) {
            // the offset is used to generate a x, -x, 2x, -2x, 3x, -3x sequence
            for (int offset = 45; offset <= 360; offset = offset + 45) {
                double dx = radius * Math.cos(Math.toRadians(angle));
                double dy = radius * Math.sin(Math.toRadians(angle));
               
                // using dx and dy would be easy but due to numeric approximations,
                // it's actually very hard to get it right so we use the angle
                double[] anchorPointCandidates;
                // normalize the angle so that it's between 0 and 360
                int normAngle = angle % 360;
                if(normAngle < 0)
                    normAngle = 360 + normAngle;
                if(normAngle < 90 || normAngle > 270) {
                    anchorPointCandidates = RIGHT_ANCHOR_CANDIDATES;
                } else if(normAngle > 90 && normAngle < 270) {
                    anchorPointCandidates = LEFT_ANCHOR_CANDIDATES;
                } else {
                    anchorPointCandidates = MID_ANCHOR_CANDIDATES;
                }
               
                // try out various anchor point positions
                for (int i = 0; i < anchorPointCandidates.length; i +=2) {
                    double ax = anchorPointCandidates[i];
                    double ay = anchorPointCandidates[i + 1];
                    cloned.setAnchorX(ax);
                    cloned.setAnchorY(ay);
                    cloned.setDisplacementX(dx);
                    cloned.setDisplacementY(dy);
                   
                    tx = new AffineTransform(tempTransform);
                    if(paintPointLabelInternal(painter, tx, displayArea, glyphs, labelItem, point, cloned))
                        return true;
                }
View Full Code Here

                } else {
                    Iterator<TextSymbolizer> iter = labelStyles.iterator();
                    while (iter.hasNext()) {
                        TextSymbolizer sym = (TextSymbolizer) iter.next();
                        try {
                            TextStyle2D style = (TextStyle2D) styleFactory.createStyle(feature,
                                    sym, scaleRange);
                            encodeTextStyle(feature, style, sym);
                        } catch (IllegalArgumentException iae) {
                            LOGGER.fine(iae.getMessage() + " for " + sym.toString());
                        }
View Full Code Here

                } else {
                    Iterator<TextSymbolizer> iter = labelStyles.iterator();
                    while (iter.hasNext()) {
                        TextSymbolizer sym = (TextSymbolizer) iter.next();
                        try {
                            TextStyle2D style = (TextStyle2D) styleFactory
                                .createStyle(feature, sym, scaleRange);
                            encodeTextStyle(feature, style, sym);
                        } catch (IllegalArgumentException iae) {
                            LOGGER.fine(iae.getMessage() + " for "
                                    + sym.toString());
View Full Code Here

TOP

Related Classes of org.geotools.renderer.style.TextStyle2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.