Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,9 @@ private void renderLabels(Graphics2D g, PlayerView view) {
timer.start("labels-1.1");
ScreenPoint sp = ScreenPoint.fromZonePointRnd(this, zp.x, zp.y);
var dim = flabel.getDimensions(g, label.getLabel());
Rectangle bounds = flabel.render(g, (int) sp.x, (int) sp.y, label.getLabel());
Rectangle bounds =
flabel.render(
g, (int) (sp.x - dim.width / 2), (int) (sp.y - dim.height / 2), label.getLabel());
labelLocationList.add(new LabelLocation(bounds, label));
timer.stop("labels-1.1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ public class LabelFontAndBGTransform implements ModelVersionTransformation {
/** The end label tag that we want to replace. */
private static final String endLabelTag = "</net.rptools.maptool.model.Label>";

/** The pattern that we want o match for 0 foreground color. */
private static final String replace0ForegroundTags =
"<foregroundColor>0</foregroundColor>[^<]*" + endLabelTag;

/**
* The foreground color that we want to use for the label where the legacy foreground color is 0.
*/
private static final Color legacyForegroundColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);

private static final String foreground0Replacement =
"<foregroundColor>" + legacyForegroundColor.getRGB() + "</foregroundColor>\n" + endLabelTag;

/** The background color that we want to use for the new label tag. */
private static final Color legacyBackgroundColor = new Color(0.82f, 0.82f, 0.82f, 1.0f);

/** The replacement string that we want to use for the end label tag. */
/** The replacement string that we want to use for the new label tag. */
private static final String replacement =
"<backgroundColor>"
+ legacyBackgroundColor.getRGB()
Expand All @@ -54,8 +66,13 @@ public class LabelFontAndBGTransform implements ModelVersionTransformation {
/** The pattern that we want to use to match the end label tag. */
private static final Pattern pattern = Pattern.compile(endLabelTag, Pattern.DOTALL);

/** The pattern that we want to use to match the legacy foreground color of 0. */
private static final Pattern replace0Foreground =
Pattern.compile(replace0ForegroundTags, Pattern.DOTALL);

@Override
public String transform(String xml) {
return pattern.matcher(xml).replaceAll(replacement);
String replace0 = replace0Foreground.matcher(xml).replaceAll(foreground0Replacement);
return pattern.matcher(replace0).replaceAll(replacement);
}
}