Is there a way of doing specific vertical text alignment or do I just have to 
use an appropriate Displacement?
The problem for me with the displacement solution is that I want to rotate the 
text.
If I rotate with the text not centered on the point then the text will rotate 
AROUND the point rather than through it.
Note: This is an assumption that I've not tested.

Simon


-----Original Message-----
From: Jody Garnett [mailto:[email protected]] 
Sent: 24 April 2010 06:00
To: Simon Hartley
Cc: [email protected]
Subject: Re: [Geotools-gt2-users] TextSymbolizer without PointSymbolizer does 
not obey AnchorPoint correctly

I think you are doing it correctly; the anchorpoint is just that ... the point 
at which the text starts to render.
You may wish to play with the vertical text alignment; I am used to text 
staring to render on the font baseline (ie at the bottom of the "O") which 
would result in the "O" appearing higher then you may assume?

Jody

On 23/04/2010, at 7:29 PM, Simon Hartley wrote:

> In the code below, the 'O' character as far as I can work out should be 
> rendered in the middle of the rendered square.
> This should be true since the AnchorPoint is defined as 0.5, 0.5.
> However this isn't what actually happens. The 'O' gets rendered higher than 
> this.
> Is this a bug or is there something I'm doing wrong or misunderstanding?
> 
> Simon
> 
>       public static void main(String[] args) throws IOException {
>               MapLayer layer = new DefaultMapLayer(createPointFeature(), 
> createPointStyle());
>               MapContext map = new DefaultMapContext(new MapLayer[] {layer}, 
> DefaultGeographicCRS.WGS84);
>               map.setAreaOfInterest(new ReferencedEnvelope(-10, 10, -10, 10, 
> DefaultGeographicCRS.WGS84));
>               
>               GTRenderer draw = new StreamingRenderer();
>               draw.setContext(map);
>               
>               Rectangle paintArea = new Rectangle(60, 60);
>               
>               BufferedImage bi = new BufferedImage(paintArea.width, 
> paintArea.height, BufferedImage.TYPE_INT_ARGB);
>               Graphics2D graphics = bi.createGraphics();
>               graphics.setColor(Color.WHITE);
>               graphics.fillRect(0, 0, bi.getWidth(), bi.getHeight());
>               draw.paint(graphics, paintArea, map.getAreaOfInterest());
>               graphics.dispose();
>               
>               ImageIO.write(bi, "png", new File("", "output.png"));
>       }
>       
>       private static FeatureCollection<SimpleFeatureType, SimpleFeature> 
> createPointFeature() {
>               SimpleFeatureTypeBuilder typeBuilder = new 
> SimpleFeatureTypeBuilder();
>               typeBuilder.setName("pointlabel");
>               typeBuilder.add("point", Point.class, 
> DefaultGeographicCRS.WGS84);
>               typeBuilder.add("label", String.class);
>               SimpleFeatureType featureType = typeBuilder.buildFeatureType();
>               
>               double longitude = 0.0;
>               double latitude  = 0.0;
>               Point point = JTSFactoryFinder.getGeometryFactory(null)
>                               .createPoint( new Coordinate(longitude, 
> latitude) );
>               
>               SimpleFeatureBuilder featureBuilder = new 
> SimpleFeatureBuilder(featureType);
>               featureBuilder.add(point);
>               featureBuilder.add("O");
>               SimpleFeature feature = featureBuilder.buildFeature(null);
>               
>               return DataUtilities.collection(feature);
>       }
>       
>       private static Style createPointStyle() {
>               StyleFactory  sf = 
> CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
>               FilterFactory ff = 
> CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
>               
>               Font font = sf.getDefaultFont();
>               font.setSize(ff.literal(40.0));
>               
>               Displacement disp  = sf.createDisplacement(ff.literal(0), 
> ff.literal(0));
>               AnchorPoint anchor = sf.createAnchorPoint(ff.literal(0.5), 
> ff.literal(0.5));
>               LabelPlacement placement = sf.createPointPlacement(anchor, 
> disp, ff.literal(0));
> 
>               TextSymbolizer sym = sf.createTextSymbolizer(
>                               sf.createFill(BLACK), new Font[]{font},
>                               null, ff.property("label"), placement, null);
>               
>               return SLD.wrapSymbolizers(sym);
>       }




*** This communication has been sent from World Fuel Services 
Corporation or its subsidiaries or its affiliates for the intended recipient 
only and may contain proprietary, confidential or privileged information. 
If you are not the intended recipient, any review, disclosure, copying, 
use, or distribution of the information included in this communication 
and any attachments is strictly prohibited. If you have received this 
communication in error, please notify us immediately by replying to this 
communication and delete the communication, including any 
attachments, from your computer. Electronic communications sent to or 
from World Fuel Services Corporation or its subsidiaries or its affiliates 
may be monitored for quality assurance and compliance purposes.***



------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to