use of org.apache.batik.dom.GenericText in project yamcs-studio by yamcs.
the class SimpleImageTranscoder method changeColor.
private void changeColor(Document doc, Color oldColor, Color newColor) {
if (oldColor.equals(newColor))
return;
Matcher matcher = null;
String svgOldColor = toHexString(oldColor.getRed(), oldColor.getGreen(), oldColor.getBlue());
String svgNewColor = toHexString(newColor.getRed(), newColor.getGreen(), newColor.getBlue());
Pattern fillPattern = Pattern.compile("(?i)" + CSSConstants.CSS_FILL_PROPERTY + ":" + svgOldColor);
Pattern strokePattern = Pattern.compile("(?i)" + CSSConstants.CSS_STROKE_PROPERTY + ":" + svgOldColor);
String fillReplace = CSSConstants.CSS_FILL_PROPERTY + ":" + svgNewColor;
String strokeReplace = CSSConstants.CSS_STROKE_PROPERTY + ":" + svgNewColor;
// Search for global style element <style type="text/css"></style>
NodeList styleList = doc.getElementsByTagName("style");
for (int i = 0; i < styleList.getLength(); i++) {
Element style = (Element) styleList.item(i);
NodeList childList = style.getChildNodes();
if (childList != null) {
for (int j = 0; j < childList.getLength(); j++) {
Node child = childList.item(j);
if (child instanceof GenericText || child instanceof GenericCDATASection) {
CharacterData cdata = (CharacterData) child;
String data = cdata.getData();
matcher = fillPattern.matcher(data);
data = matcher.replaceAll(fillReplace);
matcher = strokePattern.matcher(data);
data = matcher.replaceAll(strokeReplace);
data = replaceRGB(oldColor, newColor, data);
cdata.setData(data);
}
}
}
}
recursiveCC(doc.getDocumentElement(), oldColor, newColor, fillPattern, strokePattern, fillReplace, strokeReplace);
}
Aggregations