fix: improve SVG text alignment and positioning support in AssetManager
This commit is contained in:
+21
-2
@@ -519,7 +519,7 @@ public final class AssetManager {
|
||||
double x = parseDouble(el.getAttribute("x"), 0);
|
||||
double y = parseDouble(el.getAttribute("y"), 0);
|
||||
String content = el.getTextContent();
|
||||
Text t = new Text(x, y, content != null ? content.trim() : "");
|
||||
Text t = new Text(content != null ? content.trim() : "");
|
||||
double fs = parseDouble(el.getAttribute("font-size"), 12);
|
||||
String fw = el.getAttribute("font-weight");
|
||||
t.setFont(Font.font("Segoe UI", "bold".equalsIgnoreCase(fw) ? FontWeight.BOLD : FontWeight.NORMAL, fs));
|
||||
@@ -529,9 +529,28 @@ public final class AssetManager {
|
||||
if (fillVal != null) {
|
||||
t.setFill(parsePaint(fillVal, defsMap, Color.BLACK));
|
||||
}
|
||||
if ("middle".equalsIgnoreCase(el.getAttribute("text-anchor"))) {
|
||||
|
||||
String anchor = inlineStyle.getOrDefault("text-anchor", el.getAttribute("text-anchor"));
|
||||
String baseline = inlineStyle.getOrDefault("dominant-baseline", el.getAttribute("dominant-baseline"));
|
||||
|
||||
boolean isCenterBaseline = "central".equalsIgnoreCase(baseline) || "middle".equalsIgnoreCase(baseline);
|
||||
if (isCenterBaseline) {
|
||||
t.setTextOrigin(javafx.geometry.VPos.CENTER);
|
||||
} else {
|
||||
t.setTextOrigin(javafx.geometry.VPos.BASELINE);
|
||||
}
|
||||
|
||||
double textWidth = t.getLayoutBounds().getWidth();
|
||||
double finalX = x;
|
||||
if ("middle".equalsIgnoreCase(anchor)) {
|
||||
finalX = x - (textWidth / 2.0);
|
||||
} else if ("end".equalsIgnoreCase(anchor)) {
|
||||
finalX = x - textWidth;
|
||||
}
|
||||
|
||||
t.setX(finalX);
|
||||
t.setY(y);
|
||||
|
||||
return t;
|
||||
}
|
||||
case "g" -> {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<line x1="13" y1="18" x2="27" y2="18" stroke="#b0bec5" stroke-width="2" stroke-linecap="round"/>
|
||||
<line x1="13" y1="22" x2="35" y2="22" stroke="#b0bec5" stroke-width="2" stroke-linecap="round"/>
|
||||
<line x1="13" y1="26" x2="35" y2="26" stroke="#b0bec5" stroke-width="2" stroke-linecap="round"/>
|
||||
<!-- Etiqueta vermelha com sigla PDF -->
|
||||
<!-- Etiqueta vermelha com sigla PDF perfeitamente centralizada -->
|
||||
<rect x="11" y="31" width="28" height="11" rx="3" fill="#d32f2f"/>
|
||||
<text x="25" y="39" font-family="'Segoe UI', Arial, sans-serif" font-size="8.5" font-weight="bold" fill="#ffffff" text-anchor="middle">PDF</text>
|
||||
<text x="25" y="36.5" font-family="'Segoe UI', Arial, sans-serif" font-size="8.5px" font-weight="bold" fill="#ffffff" text-anchor="middle" dominant-baseline="central">PDF</text>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 996 B After Width: | Height: | Size: 1.0 KiB |
@@ -7,7 +7,7 @@
|
||||
<line x1="13" y1="18" x2="27" y2="18" stroke="#b0bec5" stroke-width="2" stroke-linecap="round"/>
|
||||
<line x1="13" y1="22" x2="35" y2="22" stroke="#b0bec5" stroke-width="2" stroke-linecap="round"/>
|
||||
<line x1="13" y1="26" x2="35" y2="26" stroke="#b0bec5" stroke-width="2" stroke-linecap="round"/>
|
||||
<!-- Etiqueta azul com sigla XML -->
|
||||
<!-- Etiqueta azul com sigla XML perfeitamente centralizada -->
|
||||
<rect x="11" y="31" width="28" height="11" rx="3" fill="#0288d1"/>
|
||||
<text x="25" y="39" font-family="'Segoe UI', Arial, sans-serif" font-size="8px" font-weight="bold" fill="#ffffff" text-anchor="middle"><XML></text>
|
||||
<text x="25" y="36.5" font-family="'Segoe UI', Arial, sans-serif" font-size="8px" font-weight="bold" fill="#ffffff" text-anchor="middle" dominant-baseline="central"><XML></text>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 1000 B After Width: | Height: | Size: 1.0 KiB |
Reference in New Issue
Block a user