display ToolTipMarkTags in card renders in blue instead of leaving the closing </font> tag in the text

This commit is contained in:
SpeedProg 2020-05-01 17:47:00 +02:00
parent a91b210456
commit 325d96f6db
2 changed files with 26 additions and 0 deletions

View file

@ -7,6 +7,7 @@ package org.mage.card.arcane;
import java.awt.Font;
import java.awt.Image;
import java.awt.Paint;
import java.awt.font.GraphicAttribute;
import java.awt.font.ImageGraphicAttribute;
import java.awt.font.TextAttribute;
@ -47,6 +48,25 @@ public class TextboxRule {
}
}
public static class ColorRegion implements AttributeRegion {
ColorRegion(int start, int end, Paint color) {
this.start = start;
this.end = end;
this.color = color;
}
private final int start;
private final int end;
private final Paint color;
@Override
public void applyToAttributedString(AttributedString str, Font normal, Font italic) {
if (end > start + 1) {
str.addAttribute(TextAttribute.FOREGROUND, color, start, end);
}
}
}
// A special symbol embedded at some point in a string
public static class EmbeddedSymbol implements AttributeRegion {

View file

@ -23,6 +23,7 @@ public final class TextboxRuleParser {
private static final Pattern LevelAbilityPattern = Pattern.compile("Level (\\d+)-?(\\d*)(\\+?)");
private static final Pattern LoyaltyAbilityPattern = Pattern.compile("^(\\+|\\-)(\\d+|X): ");
private static final Pattern SimpleKeywordPattern = Pattern.compile("^(\\w+( \\w+)?)\\s*(\\([^\\)]*\\))?\\s*$");
private static final Pattern FontColorValuePattern = Pattern.compile("color\\s*=\\s*[\"'](\\w+)[\"']");
// Parse a given rule (given as a string) into a TextboxRule, replacing
// symbol annotations, italics, etc, parsing out information such as
@ -200,6 +201,11 @@ public final class TextboxRuleParser {
}
}
break;
case "/font":
// Font it is an additional info of a card
// lets make it blue like it is in tooltip
regions.add(new TextboxRule.ColorRegion(openingIndex, outputIndex, Color.BLUE));
break;
default:
// Unknown
build.append('<').append(tag).append('>');