/** * 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; }
/** * Creates an outline for single point graphics * * @param symbolFrame * @param thickness * @return */ public static ArrayList<ShapeInfo> createSinglePointOutline( ShapeInfo symbolFrame, int thickness, Color outlineColor) { ShapeInfo siOutline1 = null; ShapeInfo siOutline2 = null; ShapeInfo siOutline3 = null; ShapeInfo siOutline4 = null; ShapeInfo siOutline5 = null; ShapeInfo siOutline6 = null; ShapeInfo siOutline7 = null; ShapeInfo siOutline8 = null; AffineTransform afx1 = null; AffineTransform afx2 = null; AffineTransform afx3 = null; AffineTransform afx4 = null; AffineTransform afx5 = null; AffineTransform afx6 = null; AffineTransform afx7 = null; AffineTransform afx8 = null; ArrayList<ShapeInfo> outlineShapes = null; // int outlineSize = RendererSettings.getInstance().getTextOutlineWidth(); Color lineColor = null; Color backgroundColor = null; try { int offset = 0; if (outlineColor == null) { backgroundColor = getIdealTextBackgroundColor(lineColor); } else { backgroundColor = outlineColor; } outlineShapes = new ArrayList<ShapeInfo>(); if (symbolFrame.getTextLayout() != null) { outlineShapes = new ArrayList<ShapeInfo>(); for (int i = 1; i <= thickness; i++) { offset = i; Point2D textPosition = null; if (symbolFrame.getModifierStringPosition() != null) textPosition = new Point2D.Double( symbolFrame.getModifierStringPosition().getX(), symbolFrame.getModifierStringPosition().getY()); else textPosition = new Point2D.Double(0, 0); siOutline1 = new ShapeInfo( symbolFrame.getTextLayout(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY() - offset)); siOutline2 = new ShapeInfo( symbolFrame.getTextLayout(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY() - offset)); siOutline3 = new ShapeInfo( symbolFrame.getTextLayout(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY() + offset)); siOutline4 = new ShapeInfo( symbolFrame.getTextLayout(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY() + offset)); siOutline5 = new ShapeInfo( symbolFrame.getTextLayout(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY())); siOutline6 = new ShapeInfo( symbolFrame.getTextLayout(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY())); siOutline7 = new ShapeInfo( symbolFrame.getTextLayout(), new Point2D.Double(textPosition.getX(), textPosition.getY() + offset)); siOutline8 = new ShapeInfo( symbolFrame.getTextLayout(), new Point2D.Double(textPosition.getX(), textPosition.getY() - offset)); siOutline1.setLineColor(backgroundColor); siOutline2.setLineColor(backgroundColor); siOutline3.setLineColor(backgroundColor); siOutline4.setLineColor(backgroundColor); siOutline5.setLineColor(backgroundColor); siOutline6.setLineColor(backgroundColor); siOutline7.setLineColor(backgroundColor); siOutline8.setLineColor(backgroundColor); Stroke tempStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3); siOutline1.setStroke(tempStroke); siOutline2.setStroke(tempStroke); siOutline3.setStroke(tempStroke); siOutline4.setStroke(tempStroke); siOutline5.setStroke(tempStroke); siOutline6.setStroke(tempStroke); siOutline7.setStroke(tempStroke); siOutline8.setStroke(tempStroke); if (symbolFrame.getAffineTransform() != null) { siOutline1.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline2.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline3.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline4.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline5.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline6.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline7.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline8.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); } outlineShapes.add(siOutline1); outlineShapes.add(siOutline2); outlineShapes.add(siOutline3); outlineShapes.add(siOutline4); outlineShapes.add(siOutline5); outlineShapes.add(siOutline6); outlineShapes.add(siOutline7); outlineShapes.add(siOutline8); } // end for } // end if else if (symbolFrame.getGlyphVector() != null) { outlineShapes = new ArrayList<ShapeInfo>(); for (int j = 1; j <= thickness; j++) { offset = j; Point2D textPosition = new Point2D.Double( symbolFrame.getGlyphPosition().getX(), symbolFrame.getGlyphPosition().getY()); siOutline1 = new ShapeInfo( symbolFrame.getGlyphVector(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY() - offset)); siOutline2 = new ShapeInfo( symbolFrame.getGlyphVector(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY() - offset)); siOutline3 = new ShapeInfo( symbolFrame.getGlyphVector(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY() + offset)); siOutline4 = new ShapeInfo( symbolFrame.getGlyphVector(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY() + offset)); siOutline5 = new ShapeInfo( symbolFrame.getGlyphVector(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY())); siOutline6 = new ShapeInfo( symbolFrame.getGlyphVector(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY())); siOutline7 = new ShapeInfo( symbolFrame.getGlyphVector(), new Point2D.Double(textPosition.getX(), textPosition.getY() + offset)); siOutline8 = new ShapeInfo( symbolFrame.getGlyphVector(), new Point2D.Double(textPosition.getX(), textPosition.getY() - offset)); if (symbolFrame.getShapeType() == ShapeInfo.SHAPE_TYPE_TG_SP_FRAME) { siOutline1.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE); siOutline2.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE); siOutline3.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE); siOutline4.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE); siOutline5.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE); siOutline6.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE); siOutline7.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE); siOutline8.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE); } siOutline1.setLineColor(backgroundColor); siOutline2.setLineColor(backgroundColor); siOutline3.setLineColor(backgroundColor); siOutline4.setLineColor(backgroundColor); siOutline5.setLineColor(backgroundColor); siOutline6.setLineColor(backgroundColor); siOutline7.setLineColor(backgroundColor); siOutline8.setLineColor(backgroundColor); Stroke tempStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3); siOutline1.setStroke(tempStroke); siOutline2.setStroke(tempStroke); siOutline3.setStroke(tempStroke); siOutline4.setStroke(tempStroke); siOutline5.setStroke(tempStroke); siOutline6.setStroke(tempStroke); siOutline7.setStroke(tempStroke); siOutline8.setStroke(tempStroke); if (symbolFrame.getAffineTransform() != null) { siOutline1.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline2.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline3.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline4.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline5.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline6.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline7.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); siOutline8.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform())); } outlineShapes.add(siOutline1); outlineShapes.add(siOutline2); outlineShapes.add(siOutline3); outlineShapes.add(siOutline4); outlineShapes.add(siOutline5); outlineShapes.add(siOutline6); outlineShapes.add(siOutline7); outlineShapes.add(siOutline8); } // end for } else if (symbolFrame.getShape() != null) { outlineShapes = new ArrayList<ShapeInfo>(); for (int k = 1; k <= thickness; k++) { offset = k; siOutline1 = new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline2 = new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline3 = new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline4 = new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline5 = new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline6 = new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline7 = new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline8 = new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline1.setLineColor(backgroundColor); siOutline2.setLineColor(backgroundColor); siOutline3.setLineColor(backgroundColor); siOutline4.setLineColor(backgroundColor); siOutline5.setLineColor(backgroundColor); siOutline6.setLineColor(backgroundColor); siOutline7.setLineColor(backgroundColor); siOutline8.setLineColor(backgroundColor); Stroke tempStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3); siOutline1.setStroke(tempStroke); siOutline2.setStroke(tempStroke); siOutline3.setStroke(tempStroke); siOutline4.setStroke(tempStroke); siOutline5.setStroke(tempStroke); siOutline6.setStroke(tempStroke); siOutline7.setStroke(tempStroke); siOutline8.setStroke(tempStroke); if (symbolFrame.getAffineTransform() == null) { afx1 = new AffineTransform(); afx2 = new AffineTransform(); afx3 = new AffineTransform(); afx4 = new AffineTransform(); afx5 = new AffineTransform(); afx6 = new AffineTransform(); afx7 = new AffineTransform(); afx8 = new AffineTransform(); } else { afx1 = new AffineTransform(symbolFrame.getAffineTransform()); afx2 = new AffineTransform(symbolFrame.getAffineTransform()); afx3 = new AffineTransform(symbolFrame.getAffineTransform()); afx4 = new AffineTransform(symbolFrame.getAffineTransform()); afx5 = new AffineTransform(symbolFrame.getAffineTransform()); afx6 = new AffineTransform(symbolFrame.getAffineTransform()); afx7 = new AffineTransform(symbolFrame.getAffineTransform()); afx8 = new AffineTransform(symbolFrame.getAffineTransform()); } afx1.translate(-offset, -offset); afx2.translate(+offset, -offset); afx3.translate(-offset, +offset); afx4.translate(+offset, +offset); afx5.translate(-offset, 0); afx6.translate(+offset, 0); afx7.translate(0, +offset); afx8.translate(0, -offset); siOutline1.setAffineTransform(afx1); siOutline2.setAffineTransform(afx2); siOutline3.setAffineTransform(afx3); siOutline4.setAffineTransform(afx4); siOutline5.setAffineTransform(afx5); siOutline6.setAffineTransform(afx6); siOutline7.setAffineTransform(afx7); siOutline8.setAffineTransform(afx8); outlineShapes.add(siOutline1); outlineShapes.add(siOutline2); outlineShapes.add(siOutline3); outlineShapes.add(siOutline4); outlineShapes.add(siOutline5); outlineShapes.add(siOutline6); outlineShapes.add(siOutline7); outlineShapes.add(siOutline8); } // end for } else { String message = "ShapeInfo wasn't a TextLayout or a GlyphVector, returning null"; ErrorLogger.LogMessage("SymbolDraw", "createTextOutlineQuick()", message, Level.FINEST); return null; } return outlineShapes; } catch (Exception exc) { ErrorLogger.LogException("SymbolDraw", "createTextOuline", exc); } return null; }