Changeset 12966 in josm for trunk/test/functional
- Timestamp:
- 2017-10-09T17:14:50+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/functional/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java
r12965 r12966 5 5 import static org.junit.Assert.fail; 6 6 7 import java.awt.Graphics2D;8 7 import java.awt.GraphicsEnvironment; 9 8 import java.awt.Point; 10 import java.awt.RenderingHints;11 9 import java.awt.image.BufferedImage; 12 10 import java.io.File; … … 18 16 import java.util.Arrays; 19 17 import java.util.Collection; 18 import java.util.Collections; 20 19 import java.util.List; 21 20 import java.util.stream.Collectors; … … 38 37 import org.openstreetmap.josm.data.osm.OsmPrimitive; 39 38 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 40 import org.openstreetmap.josm.data.preferences.sources.SourceEntry;41 import org.openstreetmap.josm.data.preferences.sources.SourceType;42 import org.openstreetmap.josm.gui.NavigatableComponent;43 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;44 39 import org.openstreetmap.josm.io.IllegalDataException; 45 40 import org.openstreetmap.josm.io.OsmReader; … … 163 158 // load the data 164 159 DataSet dataSet = testConfig.getOsmDataSet(); 165 166 // load the style 167 MapCSSStyleSource.STYLE_SOURCE_LOCK.writeLock().lock(); 168 try { 169 MapPaintStyles.getStyles().clear(); 170 171 MapCSSStyleSource source = new MapCSSStyleSource(testConfig.getStyleSourceEntry()); 172 source.loadStyleSource(); 173 if (!source.getErrors().isEmpty()) { 174 fail("Failed to load style file. Errors: " + source.getErrors()); 175 } 176 MapPaintStyles.getStyles().setStyleSources(Arrays.asList(source)); 177 MapPaintStyles.fireMapPaintSylesUpdated(); 178 MapPaintStyles.getStyles().clearCached(); 179 180 } finally { 181 MapCSSStyleSource.STYLE_SOURCE_LOCK.writeLock().unlock(); 182 } 183 184 // create the renderer 185 BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB); 186 NavigatableComponent nc = new NavigatableComponent() { 187 { 188 setBounds(0, 0, IMAGE_SIZE, IMAGE_SIZE); 189 updateLocationState(); 190 } 191 192 @Override 193 protected boolean isVisibleOnScreen() { 194 return true; 195 } 196 197 @Override 198 public Point getLocationOnScreen() { 199 return new Point(0, 0); 200 } 201 }; 160 dataSet.allPrimitives().stream().forEach(this::loadPrimitiveStyle); 161 dataSet.setSelected(dataSet.allPrimitives().stream().filter(n -> n.isKeyTrue("selected")).collect(Collectors.toList())); 162 202 163 ProjectionBounds pb = new ProjectionBounds(); 203 164 pb.extend(Main.getProjection().latlon2eastNorth(testConfig.testArea.getMin())); 204 165 pb.extend(Main.getProjection().latlon2eastNorth(testConfig.testArea.getMax())); 205 166 double scale = (pb.maxEast - pb.minEast) / IMAGE_SIZE; 206 nc.zoomTo(pb.getCenter(), scale); 207 208 dataSet.allPrimitives().stream().forEach(this::loadPrimitiveStyle); 209 dataSet.setSelected(dataSet.allPrimitives().stream().filter(n -> n.isKeyTrue("selected")).collect(Collectors.toList())); 210 211 Graphics2D g = image.createGraphics(); 212 // Force all render hints to be defaults - do not use platform values 213 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 214 g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); 215 g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); 216 g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); 217 g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); 218 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 219 g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 220 g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); 221 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 222 new StyledMapRenderer(g, nc, false).render(dataSet, false, testConfig.testArea); 167 168 RenderingHelper.StyleData sd = new RenderingHelper.StyleData(); 169 sd.styleUrl = testConfig.getStyleSourceUrl(); 170 RenderingHelper rh = new RenderingHelper(dataSet, testConfig.testArea, scale, Collections.singleton(sd)); 171 rh.setFillBackground(false); 172 BufferedImage image = rh.render(); 223 173 224 174 if (UPDATE_ALL) { … … 317 267 } 318 268 319 public SourceEntry getStyleSourceEntry() { 320 return new SourceEntry(SourceType.MAP_PAINT_STYLE, getTestDirectory() + "/style.mapcss", 321 "test style", "a test style", true // active 322 ); 269 public String getStyleSourceUrl() { 270 return getTestDirectory() + "/style.mapcss"; 323 271 } 324 272
Note:
See TracChangeset
for help on using the changeset viewer.