Skip to content

Commit

Permalink
Merge pull request #4716 from cwisniew/fix-4706
Browse files Browse the repository at this point in the history
Correctly centre map labels and fix colors for some old labels that had wrong coloring.
  • Loading branch information
cwisniew authored Mar 15, 2024
2 parents 8c8fdc2 + 28fa281 commit 7327ee7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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);
}
}

0 comments on commit 7327ee7

Please sign in to comment.