components: use common Text.removeTags

This was only removing color tags before, however neither text component
nor line component can correctly handle the other tags anyway, so remove
all tags
This commit is contained in:
Adam
2020-03-14 12:52:20 -04:00
parent 7c8095785f
commit dd18626d15
2 changed files with 5 additions and 9 deletions

View File

@@ -35,6 +35,7 @@ import java.awt.Rectangle;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.runelite.client.util.Text;
@Setter
@Builder
@@ -146,7 +147,7 @@ public class LineComponent implements LayoutableRenderableEntity
private static int getLineWidth(final String line, final FontMetrics metrics)
{
return metrics.stringWidth(TextComponent.textWithoutColTags(line));
return metrics.stringWidth(Text.removeTags(line));
}
private static String[] lineBreakText(String text, int maxWidth, FontMetrics metrics)

View File

@@ -32,36 +32,31 @@ import java.awt.Point;
import java.util.regex.Pattern;
import lombok.Setter;
import net.runelite.client.ui.overlay.RenderableEntity;
import net.runelite.client.util.Text;
@Setter
public class TextComponent implements RenderableEntity
{
private static final String COL_TAG_REGEX = "(<col=([0-9a-fA-F]){2,6}>)";
private static final Pattern COL_TAG_PATTERN_W_LOOKAHEAD = Pattern.compile("(?=" + COL_TAG_REGEX + ")");
private static final Pattern COL_TAG_PATTERN = Pattern.compile(COL_TAG_REGEX);
private String text;
private Point position = new Point();
private Color color = Color.WHITE;
public static String textWithoutColTags(String text)
{
return COL_TAG_PATTERN.matcher(text).replaceAll("");
}
@Override
public Dimension render(Graphics2D graphics)
{
final FontMetrics fontMetrics = graphics.getFontMetrics();
if (COL_TAG_PATTERN.matcher(text).find())
if (COL_TAG_PATTERN_W_LOOKAHEAD.matcher(text).find())
{
final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text);
int x = position.x;
for (String textSplitOnCol : parts)
{
final String textWithoutCol = textWithoutColTags(textSplitOnCol);
final String textWithoutCol = Text.removeTags(textSplitOnCol);
final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">"));
// shadow