Merge pull request #6503 from SpeedProg/fix_rednering_tooltipmarktags

UI: fix for </font> in card renders at end of ToolTipMarkTags
This commit is contained in:
Oleg Agafonov 2020-05-03 09:07:17 +02:00 committed by GitHub
commit a7de11345d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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('>');