use of org.apache.batik.dom.GenericCDATASection 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;
var svgOldColor = toHexString(oldColor.getRed(), oldColor.getGreen(), oldColor.getBlue());
var svgNewColor = toHexString(newColor.getRed(), newColor.getGreen(), newColor.getBlue());
var fillPattern = Pattern.compile("(?i)" + CSSConstants.CSS_FILL_PROPERTY + ":" + svgOldColor);
var strokePattern = Pattern.compile("(?i)" + CSSConstants.CSS_STROKE_PROPERTY + ":" + svgOldColor);
var fillReplace = CSSConstants.CSS_FILL_PROPERTY + ":" + svgNewColor;
var strokeReplace = CSSConstants.CSS_STROKE_PROPERTY + ":" + svgNewColor;
// Search for global style element <style type="text/css"></style>
var styleList = doc.getElementsByTagName("style");
for (var i = 0; i < styleList.getLength(); i++) {
var style = (Element) styleList.item(i);
var childList = style.getChildNodes();
if (childList != null) {
for (var j = 0; j < childList.getLength(); j++) {
var child = childList.item(j);
if (child instanceof GenericText || child instanceof GenericCDATASection) {
var cdata = (CharacterData) child;
var 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