use of com.loohp.interactivechat.libs.net.kyori.adventure.text.format.TextColor in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class TrueTypeFont method printCharacter.
@SuppressWarnings("rawtypes")
@Override
public FontRenderResult printCharacter(BufferedImage image, String character, int x, int y, float fontSize, int lastItalicExtraWidth, TextColor color, List<TextDecoration> decorations) {
if (character.equals(" ")) {
return printSpace(image, x, y, fontSize, lastItalicExtraWidth, color, decorations);
}
float scale = fontSize / 16;
fontSize = fontSize - (13 - this.size);
decorations = sortDecorations(decorations);
Graphics2D g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setFont(font.deriveFont(this.size));
int w = g.getFontMetrics().stringWidth(character);
Font fontToPrint = font.deriveFont(fontSize);
BufferedImage[] magicCharImages = null;
boolean bold = false;
boolean italic = false;
for (TextDecoration decoration : decorations) {
switch(decoration) {
case OBFUSCATED:
magicCharImages = new BufferedImage[OBFUSCATE_OVERLAP_COUNT];
for (int i = 0; i < magicCharImages.length; i++) {
String magicCharacter = ComponentStringUtils.toMagic(provider, character);
magicCharImages[i] = provider.forCharacter(magicCharacter).getCharacterImage(magicCharacter, fontSize, color).orElse(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB));
}
break;
case BOLD:
bold = true;
break;
case ITALIC:
fontToPrint = fontToPrint.deriveFont(Font.ITALIC);
italic = true;
break;
case STRIKETHROUGH:
Map attributes = fontToPrint.getAttributes();
attributes.put(TextAttribute.STRIKETHROUGH, true);
fontToPrint = new Font(attributes);
break;
case UNDERLINED:
attributes = fontToPrint.getAttributes();
attributes.put(TextAttribute.UNDERLINE, true);
fontToPrint = new Font(attributes);
break;
default:
break;
}
}
g.setColor(new Color(color.value()));
g.setFont(fontToPrint);
int height = g.getFontMetrics().getHeight() / 2;
int newW = g.getFontMetrics().stringWidth(character);
int finalWidth = newW;
int extraWidth = italic ? 0 : lastItalicExtraWidth;
if (magicCharImages == null) {
g.drawString(character, x, y + height);
if (bold) {
g.drawString(character, x + (scale * 2) + extraWidth, y + height);
finalWidth += scale * 2;
}
} else {
for (BufferedImage magicCharImage : magicCharImages) {
g.drawImage(magicCharImage, x + extraWidth, y, newW, height, null);
}
if (bold) {
for (BufferedImage magicCharImage : magicCharImages) {
g.drawImage(magicCharImage, (int) (x + (scale * 2)) + extraWidth, y, newW, height, null);
}
finalWidth += scale * 2;
}
}
g.dispose();
float spaceWidth = (float) newW / (float) w;
return new FontRenderResult(image, finalWidth + extraWidth, height + (int) Math.round(shift.getTranslateY()), (int) Math.round(spaceWidth + shift.getTranslateX()), 0);
}
use of com.loohp.interactivechat.libs.net.kyori.adventure.text.format.TextColor in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class BitmapFont method getCharacterImage.
@Override
public Optional<BufferedImage> getCharacterImage(String character, float fontSize, TextColor color) {
if (character.equals(" ")) {
return Optional.of(getSpaceImage(fontSize));
}
Color awtColor = new Color(color.value());
BufferedImage charImage = charImages.get(character.codePointAt(0)).getFontImage();
float descent = height - this.ascent - 1;
charImage = ImageUtils.resizeImageFillHeight(charImage, Math.abs(Math.round(fontSize + (ascent + descent) * scale)));
charImage = ImageUtils.multiply(charImage, ImageUtils.changeColorTo(ImageUtils.copyImage(charImage), awtColor));
return Optional.of(charImage);
}
use of com.loohp.interactivechat.libs.net.kyori.adventure.text.format.TextColor in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class LegacyUnicodeFont method getCharacterImage.
@Override
public Optional<BufferedImage> getCharacterImage(String character, float fontSize, TextColor color) {
if (character.equals(" ")) {
return Optional.of(getSpaceImage(fontSize));
}
Color awtColor = new Color(color.value());
Optional<FontTextureResource> optCharImage = charImages.get(character.codePointAt(0));
if (optCharImage == null) {
optCharImage = MISSING_CHARACTER;
}
if (optCharImage.isPresent()) {
BufferedImage charImage = optCharImage.get().getFontImage();
charImage = ImageUtils.resizeImageFillHeight(charImage, Math.round(fontSize));
charImage = ImageUtils.multiply(charImage, ImageUtils.changeColorTo(ImageUtils.copyImage(charImage), awtColor));
return Optional.of(charImage);
} else {
return Optional.empty();
}
}
Aggregations