private void scaleIntOption(Map<String, String> options, String optionName, Unit<Length> uom) { if (options.containsKey(optionName)) { String rescaled = rescale(options.get(optionName), uom); options.put(optionName, toInt(rescaled)); } }
/** * Used to rescaleDashArray the provided stroke. * * @param stroke the unscaled stroke, which will be modified in-place. * @param mapScale the mapScale in pixels per meter. * @param uom the unit of measure that will be used to scale. */ protected void rescaleStroke(Stroke stroke, Unit<Length> uom) { if (stroke != null) { stroke.setWidth(rescale(stroke.getWidth(), uom)); stroke.setDashArray(rescaleDashArray(stroke.dashArray(), uom)); stroke.setDashOffset(rescale(stroke.getDashOffset(), uom)); rescale(stroke.getGraphicFill(), uom); rescale(stroke.getGraphicStroke(), uom); } }
@Override public void visit(LineSymbolizer line) { super.visit(line); LineSymbolizer copy = (LineSymbolizer) pages.peek(); Unit<Length> uom = copy.getUnitOfMeasure(); Stroke copyStroke = copy.getStroke(); rescaleStroke(copyStroke, uom); copy.setPerpendicularOffset(rescale(copy.getPerpendicularOffset(), uom)); copy.setUnitOfMeasure(Units.PIXEL); }
private void rescale(Graphic graphic, Unit<Length> unit) { if (graphic != null) { graphic.setSize(rescale(graphic.getSize(), unit)); graphic.setGap(rescale(graphic.getGap(), unit)); Displacement disp = graphic.getDisplacement(); if (disp != null) { disp.setDisplacementX(rescale(disp.getDisplacementX(), unit)); disp.setDisplacementY(rescale(disp.getDisplacementY(), unit)); graphic.setDisplacement(disp); } if (graphic.graphicalSymbols() != null) { for (GraphicalSymbol gs : graphic.graphicalSymbols()) { if (gs instanceof Mark) { Mark mark = (Mark) gs; rescaleStroke(mark.getStroke(), unit); rescaleFill(mark.getFill(), unit); } } } } }
private void rescale(Graphic graphic, double mapScale, Unit<Length> unit) { if(graphic != null) { graphic.setSize(rescale(graphic.getSize(), mapScale, unit)); graphic.setGap(rescale(graphic.getGap(), mapScale, unit)); Displacement disp = graphic.getDisplacement(); if (disp != null) { disp.setDisplacementX(rescale(disp.getDisplacementX(), mapScale, unit)); disp.setDisplacementY(rescale(disp.getDisplacementY(), mapScale, unit)); graphic.setDisplacement(disp); } if (graphic.graphicalSymbols() != null) { for (GraphicalSymbol gs : graphic.graphicalSymbols()) { if(gs instanceof Mark) { Mark mark = (Mark) gs; rescaleStroke(mark.getStroke(), mapScale, unit); rescaleFill(mark.getFill(), mapScale, unit); } } } } }
private void rescaleFill(Fill copyFill, Unit<Length> unit) { // rescale the graphic fill, if any if (copyFill != null) { rescale(copyFill.getGraphicFill(), unit); } }
private void scaleIntArrayOption( Map<String, String> options, String optionName, Unit<Length> uom) { if (options.containsKey(optionName)) { String strValue = options.get(optionName); String[] splitted = strValue.split("\\s+"); StringBuilder sb = new StringBuilder(); for (String value : splitted) { String rescaled = rescale(value, uom); sb.append(toInt(rescaled)).append(" "); } sb.setLength(sb.length() - 1); options.put(optionName, sb.toString()); } }
/** Rescale a list of expressions, can handle null. */ protected List<Expression> rescaleDashArray(List<Expression> expressions, Unit<Length> uom) { if (expressions == null || expressions.isEmpty()) { return expressions; } List<Expression> rescaled = new ArrayList<>(expressions.size()); final Expression scale = rescale(ff.literal(1), uom); for (Expression expression : expressions) { Expression rescale = ff.function("listMultiply", scale, expression); if (expression instanceof Literal) { rescaled.add(ff.literal(rescale.evaluate(null))); } else { rescaled.add(rescale); } } return rescaled; }
@Override public void visit(PointSymbolizer ps) { super.visit(ps); PointSymbolizer copy = (PointSymbolizer) pages.peek(); Unit<Length> uom = copy.getUnitOfMeasure(); Graphic copyGraphic = copy.getGraphic(); rescale(copyGraphic, uom); copy.setUnitOfMeasure(Units.PIXEL); }
font.setSize(rescale(font.getSize(), uom)); Displacement disp = pointPlacement.getDisplacement(); if (disp != null) { disp.setDisplacementX(rescale(disp.getDisplacementX(), uom)); disp.setDisplacementY(rescale(disp.getDisplacementY(), uom)); pointPlacement.setDisplacement(disp); linePlacement.setGap(rescale(linePlacement.getGap(), uom)); linePlacement.setInitialGap(rescale(linePlacement.getInitialGap(), uom)); linePlacement.setPerpendicularOffset( rescale(linePlacement.getPerpendicularOffset(), uom)); copy.getHalo().setRadius(rescale(copy.getHalo().getRadius(), uom)); TextSymbolizer2 copy2 = (TextSymbolizer2) copy; rescale(copy2.getGraphic(), uom);
private void scaleIntOption(Map<String, String> options, String optionName, Unit<Length> uom) { if (options.containsKey(optionName)) { double v = rescale(Double.parseDouble(options.get(optionName)), mapScale, uom); options.put(optionName, Integer.toString((int) v)); } }
private void rescaleFill(Fill copyFill, double mapScale, Unit<Length> unit) { // rescale the graphic fill, if any if (copyFill != null) { rescale(copyFill.getGraphicFill(), mapScale, unit); } }
private void scaleIntArrayOption(Map<String, String> options, String optionName, Unit<Length> uom) { if (options.containsKey(optionName)) { String strValue = options.get(optionName); String[] splitted = strValue.split("\\s+"); StringBuilder sb = new StringBuilder(); for (String value : splitted) { double rescaled = rescale(Double.parseDouble(value), mapScale, uom); sb.append((int) rescaled).append(" "); } sb.setLength(sb.length() - 1); options.put(optionName, sb.toString()); } } }
/** * Used to rescale the provided dash array. * * @param dashArray * the unscaled dash array. If null, the method returns null. * @param mapScale * the mapScale in pixels per meter. * @param uom * the unit of measure that will be used to scale. * @return the rescaled dash array */ protected float[] rescale(float[] dashArray, double mapScale, Unit<Length> unitOfMeasure) { if (dashArray == null) return null; if (unitOfMeasure == null || unitOfMeasure.equals(NonSI.PIXEL)) return dashArray; float[] rescaledDashArray = new float[dashArray.length]; for (int i = 0; i < rescaledDashArray.length; i++) { rescaledDashArray[i] = (float) rescale((double) dashArray[i], mapScale, unitOfMeasure); } return rescaledDashArray; }
/** * Used to rescale the provided stroke. * * @param stroke * the unscaled stroke, which will be modified in-place. * @param mapScale * the mapScale in pixels per meter. * @param uom * the unit of measure that will be used to scale. */ protected void rescaleStroke(Stroke stroke, double mapScale, Unit<Length> uom) { if (stroke != null) { stroke.setWidth(rescale(stroke.getWidth(), mapScale, uom)); stroke.setDashArray(rescale(stroke.getDashArray(), mapScale, uom)); stroke.setDashOffset(rescale(stroke.getDashOffset(), mapScale, uom)); rescale(stroke.getGraphicFill(), mapScale, uom); rescale(stroke.getGraphicStroke(), mapScale, uom); } }
@Override public void visit(PointSymbolizer ps) { super.visit(ps); PointSymbolizer copy = (PointSymbolizer) pages.peek(); Unit<Length> uom = copy.getUnitOfMeasure(); if(uom == null || uom.equals(NonSI.PIXEL)) { return; } Graphic copyGraphic = copy.getGraphic(); rescale(copyGraphic, mapScale, uom); copy.setUnitOfMeasure(NonSI.PIXEL); }
/** * Used to rescale the provided unscaled value. * * @param unscaled * the unscaled value. * @param mapScale * the mapScale in pixels per meter. * @param uom * the unit of measure that will be used to scale. * @return the expression multiplied by the provided scale. */ protected Expression rescale(Expression unscaled, double mapScale, Unit<Length> uom) { if (unscaled == null || unscaled.equals(Expression.NIL)) return unscaled; if (unscaled instanceof Literal && unscaled.evaluate(null, Double.class) != null) { // if given Expression is a literal, we can return a literal double rescaled = rescale(unscaled.evaluate(null, Double.class), mapScale, uom); return ff.literal(rescaled); } else { // otherwise, we return a Multiply expression with the rescaling multiplier double rescaleMultiplier = computeRescaleMultiplier(mapScale, uom); return ff.multiply(unscaled, ff.literal(rescaleMultiplier)); } }
font.setSize(rescale(font.getSize(), mapScale, uom)); copy.setFonts(fonts); Displacement disp = pointPlacement.getDisplacement(); if (disp != null) { disp.setDisplacementX(rescale(disp.getDisplacementX(), mapScale, uom)); disp.setDisplacementY(rescale(disp.getDisplacementY(), mapScale, uom)); pointPlacement.setDisplacement(disp); linePlacement.setGap(rescale(linePlacement.getGap(), mapScale, uom)); linePlacement.setInitialGap(rescale(linePlacement.getInitialGap(), mapScale, uom)); linePlacement.setPerpendicularOffset(rescale(linePlacement.getPerpendicularOffset(), mapScale, uom)); copy.getHalo().setRadius(rescale(copy.getHalo().getRadius(), mapScale, uom)); TextSymbolizer2 copy2 = (TextSymbolizer2) copy; rescale(copy2.getGraphic(), mapScale, uom);