/** * Creates an outline of a text shape for better readability * * @param originalText * @param outlineSize desired width of the outline. Overrides the value in the RendererSettings * object. * @return */ public static ShapeInfo createTextOutline(ShapeInfo originalText, int outlineSize) { Shape outline = null; ShapeInfo siOutline = null; // int outlineSize = RendererSettings.getInstance().getTextOutlineWidth(); outlineSize = Math.abs(outlineSize); Color textColor = null; try { if (originalText.getShape() != null) outline = new GeneralPath(originalText.getShape()); else if (originalText.getTextLayout() != null) { outline = originalText .getTextLayout() .getOutline( AffineTransform.getTranslateInstance( originalText.getGlyphPosition().getX(), originalText.getGlyphPosition().getY())); } siOutline = new ShapeInfo(outline); if (originalText.getFillColor() != null) textColor = originalText.getFillColor(); // shape else if (originalText.getLineColor() != null) // vs textColor = originalText.getLineColor(); // textlayout // if(textColor.getRed() == 255 && // textColor.getGreen() == 255 && // textColor.getBlue() == 255) // siOutline.setLineColor(Color.BLACK); // else // siOutline.setLineColor(Color.WHITE); if (originalText.getAffineTransform() != null) siOutline.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); if (originalText.getTextBackgroundColor() != null) { siOutline.setLineColor(originalText.getTextBackgroundColor()); } else siOutline.setLineColor(getIdealTextBackgroundColor(textColor)); // siOutline.setStroke(new BasicStroke(2)); siOutline.setStroke( new BasicStroke(outlineSize, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3)); } catch (Exception exc) { ErrorLogger.LogException("SymbolDraw", "createTextOuline", exc); } return siOutline; }
/** * Creates a filled rectangle backdrop for the text * * @param originalText * @return */ public static ShapeInfo createTextBackgroundFill(ShapeInfo originalText) { Rectangle tempRect = null; ShapeInfo background = null; ShapeInfo returnVal = null; try { // tempRect = temp.getBounds(); tempRect = originalText .getTextLayout() .getPixelBounds( null, (float) originalText.getGlyphPosition().getX(), (float) originalText.getGlyphPosition().getY()); // tempRect.setRect(temp.getTextLayout().getBounds()); background = new ShapeInfo( new Rectangle( tempRect.x - 2, tempRect.y - 2, tempRect.width + 4, tempRect.height + 4)); if (originalText.getTextBackgroundColor() != null) { background.setFillColor(originalText.getTextBackgroundColor()); } else if (RendererSettings.getInstance().getLabelBackgroundColor() != null) { background.setFillColor(RendererSettings.getInstance().getLabelBackgroundColor()); } else { Color bgColor = null; if (originalText.getLineColor() != null) bgColor = getIdealTextBackgroundColor(originalText.getLineColor()); else if (originalText.getFillColor() != null) bgColor = getIdealTextBackgroundColor(originalText.getFillColor()); else bgColor = Color.white; background.setFillColor(bgColor); } if (originalText.getAffineTransform() != null) background.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); returnVal = background; } catch (Exception exc) { ErrorLogger.LogException("SymbolDraw", "CreateTextBackgroundFill", exc); } return returnVal; }
/** * Does the actual drawing of the Symbol. MilstdSymbol need to be properly populated via the * Render call first. Not for client use. They should Use IJavaRenderer.Draw or * IJavaRenderer.DrawDB * * @param symbols * @param destination surface to draw to * @param offsetX usually a negative value. if your clip.X is 40, offsetX should be -40 * @param offsetY usually a negative value. if your clip.Y is 40, offsetY should be -40 * @throws RendererException */ public static void Draw( ArrayList<MilStdSymbol> symbols, Graphics2D destination, int offsetX, int offsetY) throws RendererException { Logger loggy = Logger.getLogger(ErrorLogger.LoggerName); try { if (symbols != null && destination != null) { destination.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Stroke oldStroke = destination.getStroke(); AffineTransform oldTransform = destination.getTransform(); // loop through symbols and draw MilStdSymbol symbol; int unitCount = symbols.size(); for (int lcv = 0; lcv < unitCount; lcv++) { symbol = symbols.get(lcv); // synchronized(destination) // { ArrayList<ShapeInfo> shapes = symbol.getSymbolShapes(); if (shapes != null) { ShapeInfo siTemp; for (int i = 0; i < shapes.size(); i++) { siTemp = shapes.get(i); if (siTemp.getAffineTransform() != null) { AffineTransform atTemp = (AffineTransform) siTemp.getAffineTransform().clone(); atTemp.preConcatenate(AffineTransform.getTranslateInstance(offsetX, offsetY)); destination.setTransform(atTemp); // destination.setTransform(siTemp.getAffineTransform()); } else destination.translate(offsetX, offsetY); if (siTemp.getStroke() != null) destination.setStroke(siTemp.getStroke()); if (siTemp.getTexturePaint() != null) { TexturePaint tp = siTemp.getTexturePaint(); destination.setPaint(tp); destination.fill(siTemp.getShape()); } else if (siTemp.getFillColor() != null) { destination.setColor(siTemp.getFillColor()); if (siTemp.getShape() != null) destination.fill(siTemp.getShape()); } if (siTemp.getLineColor() != null) { destination.setColor(siTemp.getLineColor()); Point2D point = null; if (siTemp.getShape() != null) destination.draw(siTemp.getShape()); else if (siTemp.getGlyphVector() != null) { point = siTemp.getGlyphPosition(); destination.drawGlyphVector( siTemp.getGlyphVector(), (float) point.getX(), (float) point.getY()); } else if (siTemp.getTextLayout() != null) { point = siTemp.getGlyphPosition(); siTemp .getTextLayout() .draw(destination, (float) point.getX(), (float) point.getY()); } } destination.setTransform(oldTransform); destination.setStroke(oldStroke); } // draw modifiers shapes = symbol.getModifierShapes(); if (shapes != null) { for (int i = 0; i < shapes.size(); i++) { siTemp = shapes.get(i); if (siTemp.getAffineTransform() != null) { AffineTransform atTemp = (AffineTransform) siTemp.getAffineTransform().clone(); atTemp.preConcatenate(AffineTransform.getTranslateInstance(offsetX, offsetY)); destination.setTransform(atTemp); // destination.setTransform(siTemp.getAffineTransform()); } else destination.translate(offsetX, offsetY); if (siTemp.getStroke() != null) destination.setStroke(siTemp.getStroke()); if (siTemp.getFillColor() != null) { destination.setColor(siTemp.getFillColor()); if (siTemp.getShape() != null) destination.fill(siTemp.getShape()); else // for deutch. needs to set line color for text { siTemp.setLineColor(siTemp.getFillColor()); siTemp.setFillColor(null); } } if (siTemp.getLineColor() != null) // change to else if when Deutch fixes above { destination.setColor(siTemp.getLineColor()); Point2D point = null; if (siTemp.getShape() != null) destination.draw(siTemp.getShape()); else if (siTemp.getGlyphVector() != null) { point = siTemp.getGlyphPosition(); destination.drawGlyphVector( siTemp.getGlyphVector(), (float) point.getX(), (float) point.getY()); } else if (siTemp.getTextLayout() != null) { point = siTemp.getGlyphPosition(); siTemp .getTextLayout() .draw(destination, (float) point.getX(), (float) point.getY()); } } destination.setTransform(oldTransform); } } } // } } destination.setTransform(oldTransform); destination.setStroke(oldStroke); } else { // parameters are bad, throw exception String badValues = "Bad parameters passed: "; if (symbols == null) badValues += " symbols"; if (destination == null) badValues += " destination"; RendererException re = new RendererException(badValues, null); loggy.logp(Level.INFO, "SymbolDraw", "Draw()", "draw failure", re); throw re; } } catch (Exception exc) { RendererException re2 = new RendererException("Draw Operation Failed", exc); loggy.logp(Level.INFO, "SymbolDraw", "Draw()", "draw failure", re2); throw re2; } }