/** * 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 of a text shape for better readability. It is faster because instead of * tracing an outline, we duplicate the text 4x and shift each one in a different direction. Only * works when TextRenderMethod is set to NATIVE * * @param originalText * @param thickness - how thick the outline should be * @return */ public static ArrayList<ShapeInfo> createTextOutlineQuick(ShapeInfo originalText, int thickness) { ShapeInfo siOutline1 = null; ShapeInfo siOutline2 = null; ShapeInfo siOutline3 = null; ShapeInfo siOutline4 = null; AffineTransform afx1 = null; AffineTransform afx2 = null; AffineTransform afx3 = null; AffineTransform afx4 = null; ArrayList<ShapeInfo> outlineShapes = null; // int outlineSize = RendererSettings.getInstance().getTextOutlineWidth(); Color textColor = null; Color backgroundColor = null; try { int offset = 0; if (originalText.getTextLayout() != null) { textColor = originalText.getLineColor(); // textlayout if (originalText.getTextBackgroundColor() != null) { backgroundColor = originalText.getTextBackgroundColor(); } else backgroundColor = getIdealTextBackgroundColor(textColor); outlineShapes = new ArrayList<ShapeInfo>(); for (int i = 1; i <= thickness; i++) { offset = i; Point2D textPosition = null; if (originalText.getModifierStringPosition() != null) textPosition = new Point2D.Double( originalText.getModifierStringPosition().getX(), originalText.getModifierStringPosition().getY()); else textPosition = new Point2D.Double(0, 0); if (i % 2 != 0) { siOutline1 = new ShapeInfo( originalText.getTextLayout(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY() - offset)); siOutline2 = new ShapeInfo( originalText.getTextLayout(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY() - offset)); siOutline3 = new ShapeInfo( originalText.getTextLayout(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY() + offset)); siOutline4 = new ShapeInfo( originalText.getTextLayout(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY() + offset)); } else { siOutline1 = new ShapeInfo( originalText.getTextLayout(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY())); siOutline2 = new ShapeInfo( originalText.getTextLayout(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY())); siOutline3 = new ShapeInfo( originalText.getTextLayout(), new Point2D.Double(textPosition.getX(), textPosition.getY() + offset)); siOutline4 = new ShapeInfo( originalText.getTextLayout(), new Point2D.Double(textPosition.getX(), textPosition.getY() - offset)); } siOutline1.setLineColor(backgroundColor); siOutline2.setLineColor(backgroundColor); siOutline3.setLineColor(backgroundColor); siOutline4.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); if (originalText.getAffineTransform() != null) { siOutline1.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); siOutline2.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); siOutline3.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); siOutline4.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); } outlineShapes.add(siOutline1); outlineShapes.add(siOutline2); outlineShapes.add(siOutline3); outlineShapes.add(siOutline4); } // end for } // end if else if (originalText.getGlyphVector() != null) { textColor = originalText.getLineColor(); // textlayout backgroundColor = getIdealTextBackgroundColor(textColor); outlineShapes = new ArrayList<ShapeInfo>(); for (int j = 1; j <= thickness; j++) { offset = j; Point2D textPosition = new Point2D.Double( originalText.getGlyphPosition().getX(), originalText.getGlyphPosition().getY()); if (j % 2 != 0) { siOutline1 = new ShapeInfo( originalText.getGlyphVector(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY() - offset)); siOutline2 = new ShapeInfo( originalText.getGlyphVector(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY() - offset)); siOutline3 = new ShapeInfo( originalText.getGlyphVector(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY() + offset)); siOutline4 = new ShapeInfo( originalText.getGlyphVector(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY() + offset)); } else { siOutline1 = new ShapeInfo( originalText.getGlyphVector(), new Point2D.Double(textPosition.getX() - offset, textPosition.getY())); siOutline2 = new ShapeInfo( originalText.getGlyphVector(), new Point2D.Double(textPosition.getX() + offset, textPosition.getY())); siOutline3 = new ShapeInfo( originalText.getGlyphVector(), new Point2D.Double(textPosition.getX(), textPosition.getY() + offset)); siOutline4 = new ShapeInfo( originalText.getGlyphVector(), new Point2D.Double(textPosition.getX(), textPosition.getY() - offset)); } siOutline1.setLineColor(backgroundColor); siOutline2.setLineColor(backgroundColor); siOutline3.setLineColor(backgroundColor); siOutline4.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); if (originalText.getAffineTransform() != null) { siOutline1.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); siOutline2.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); siOutline3.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); siOutline4.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); } outlineShapes.add(siOutline1); outlineShapes.add(siOutline2); outlineShapes.add(siOutline3); outlineShapes.add(siOutline4); } // end for } else if (originalText.getShape() != null) { textColor = originalText.getLineColor(); // textlayout backgroundColor = getIdealTextBackgroundColor(textColor); outlineShapes = new ArrayList<ShapeInfo>(); for (int k = 1; k <= thickness; k++) { offset = k; siOutline1 = new ShapeInfo(originalText.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline2 = new ShapeInfo(originalText.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline3 = new ShapeInfo(originalText.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline4 = new ShapeInfo(originalText.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE); siOutline1.setLineColor(backgroundColor); siOutline2.setLineColor(backgroundColor); siOutline3.setLineColor(backgroundColor); siOutline4.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); if (originalText.getAffineTransform() == null) { afx1 = new AffineTransform(); afx2 = new AffineTransform(); afx3 = new AffineTransform(); afx4 = new AffineTransform(); } else { afx1 = new AffineTransform(originalText.getAffineTransform()); afx2 = new AffineTransform(originalText.getAffineTransform()); afx3 = new AffineTransform(originalText.getAffineTransform()); afx4 = new AffineTransform(originalText.getAffineTransform()); } if (k % 2 != 0) { afx1.translate(-offset, -offset); afx2.translate(+offset, -offset); afx3.translate(-offset, +offset); afx4.translate(+offset, +offset); } else { afx1.translate(-offset, 0); afx2.translate(+offset, 0); afx3.translate(0, +offset); afx4.translate(0, -offset); } siOutline1.setAffineTransform(afx1); siOutline2.setAffineTransform(afx2); siOutline3.setAffineTransform(afx3); siOutline4.setAffineTransform(afx4); outlineShapes.add(siOutline1); outlineShapes.add(siOutline2); outlineShapes.add(siOutline3); outlineShapes.add(siOutline4); } // 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; }