Ticket #2193 (closed feature: fixed)
Allow line breaks/newline in SVG vector labels
| Reported by: | Lucent | Owned by: | fredj |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.11 Release |
| Component: | Renderer | Version: | 2.10 |
| Keywords: | multiline, newline, linebreak, line break | Cc: | vog@… |
| State: | Commit |
Description
Currently, the VML renderer happily displays and aligns \n contained in labels. To bring the SVG renderer up to parity may require child tspans with positions set. I've made very rudimentary changes to the end of drawText to allow this, but updating of children is required onzoom. Alignment also fails.
if (style.label.indexOf("\n") === -1)
tspan.textContent = style.label;
else
var labelLines = style.label.split("\n");
if(!label.parentNode) {
if (style.label.indexOf("\n") === -1) {
label.appendChild(tspan);
} else {
for (var line in labelLines) {
tspans[line] = this.nodeFactory("MultiLine_" + featureId + this.LABEL_ID_SUFFIX + "_tspan" + line, "tspan");
tspans[line].setAttributeNS(null, "x", x);
tspans[line].setAttributeNS(null, "dy", parseInt(style.fontSize));
tspans[line].textContent = labelLines[line];
label.appendChild(tspans[line]);
}
}
this.textRoot.appendChild(label);
}

