private void drawPoint( PdfContext context, Rectangle iconRect, Color fillColor, Color strokeColor) { float baseWidth = iconRect.getWidth() / 10; SymbolInfo symbol = styleInfo.getSymbol(); if (symbol.getImage() != null) { try { Image pointImage = Image.getInstance(symbol.getImage().getHref()); context.drawImage(pointImage, iconRect, iconRect); } catch (Exception ex) { // NOSONAR log.error("Not able to create image for POINT Symbol", ex); } } else if (symbol.getRect() != null) { context.fillRectangle(iconRect, fillColor); context.strokeRectangle(iconRect, strokeColor, baseWidth / 2); } else { context.fillEllipse(iconRect, fillColor); context.strokeEllipse(iconRect, strokeColor, baseWidth / 2); } }
private void drawLine( PdfContext context, Rectangle iconRect, Color strokeColor, float[] dashArray) { float baseWidth = iconRect.getWidth() / 10; context.drawRelativePath( new float[] {0f, 0.75f, 0.25f, 1f}, new float[] {0f, 0.25f, 0.75f, 1f}, iconRect, strokeColor, baseWidth * 2, dashArray); }
@SuppressWarnings("deprecation") @Override public void calculateSize(PdfContext context) { LegendComponent legendComponent = getLegend(); assert (null != legendComponent) : "LegendGraphicComponent must be a descendant of a LegendComponent"; Rectangle textSize = context.getTextSize(label, legendComponent.getFont()); float margin = 0.25f * legendComponent.getFont().getSize(); if (getConstraint().getMarginX() <= 0.0) { getConstraint().setMarginX(margin); } if (getConstraint().getMarginY() <= 0.0) { getConstraint().setMarginY(margin); } setBounds(new Rectangle(textSize.getHeight(), textSize.getHeight())); }
@Override public void render(PdfContext context) { @SuppressWarnings("deprecation") float w = getSize().getWidth(); @SuppressWarnings("deprecation") float h = getSize().getHeight(); Rectangle iconRect = new Rectangle(0, 0, w, h); Color fillColor = Color.white; Color strokeColor = Color.black; float[] dashArray = null; if (styleInfo != null) { fillColor = context.getColor(styleInfo.getFillColor(), styleInfo.getFillOpacity(), Color.white); strokeColor = context.getColor(styleInfo.getStrokeColor(), styleInfo.getStrokeOpacity(), Color.black); dashArray = context.getDashArray(styleInfo.getDashArray()); } float baseWidth = iconRect.getWidth() / 10; // draw symbol switch (layerType) { case RASTER: Image img = context.getImage("/images/layer-raster.png"); context.drawImage(img, iconRect, null); break; case POINT: case MULTIPOINT: drawPoint(context, iconRect, fillColor, strokeColor); break; case LINESTRING: case MULTILINESTRING: drawLine(context, iconRect, strokeColor, dashArray); break; case POLYGON: case MULTIPOLYGON: context.fillRectangle(iconRect, fillColor); context.strokeRectangle(iconRect, strokeColor, baseWidth, dashArray); break; case GEOMETRY: drawPoint(context, iconRect, fillColor, strokeColor); drawLine(context, iconRect, strokeColor, dashArray); break; default: log.warn("Cannot draw unknown layerType " + layerType); } }