Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: langpack icons don't have transparent background #709 #710

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified org.eclipse.tm4e.language_pack/syntaxes/git-base/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified org.eclipse.tm4e.language_pack/syntaxes/git-base/icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified org.eclipse.tm4e.language_pack/syntaxes/markdown-math/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified org.eclipse.tm4e.language_pack/syntaxes/markdown-math/icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified org.eclipse.tm4e.language_pack/syntaxes/search-result/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified org.eclipse.tm4e.language_pack/syntaxes/search-result/icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions org.eclipse.tm4e.language_pack/updater/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,5 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- for icon resizing -->
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.20</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -28,7 +27,6 @@

import javax.imageio.ImageIO;

import net.coobird.thumbnailator.Thumbnails;
import updater.Updater.Config;
import updater.Updater.State.ExtensionState;
import updater.Updater.State.LanguageState;
Expand Down Expand Up @@ -107,8 +105,8 @@ void handle() throws IOException {
final var targetIcon = targetSyntaxDir.resolve("icon.png");
logInfo("Copying file [icon.png]...");
final var sourceIcon = ImageIO.read(sourceExtensionDir.resolve(pkgJson.icon()).toFile());
Thumbnails.of(sourceIcon).size(16, 16).outputFormat("png").toFile(targetIcon.toFile());
Thumbnails.of(sourceIcon).size(32, 32).outputFormat("png").toFile(targetSyntaxDir.resolve("icon@2x.png").toFile());
ImageIO.write(resizeImage(sourceIcon, 16, 16), "png", targetIcon.toFile());
ImageIO.write(resizeImage(sourceIcon, 32, 32), "png", targetSyntaxDir.resolve("icon@2x.png").toFile());
}

for (final Entry<String, Contributions.Language> lang : pkgJsonLangs.entrySet()) {
Expand Down Expand Up @@ -149,9 +147,8 @@ void handle() throws IOException {
logInfo("Copying image [" + langCfg.icon().light() + "] -> [" + targetIcon.getFileName() + "]...", false);
try {
final var sourceIcon = ImageIO.read(sourceExtensionDir.resolve(langCfg.icon().light()).toFile());
Thumbnails.of(sourceIcon).size(16, 16).outputFormat("png").toFile(targetIcon.toFile());
Thumbnails.of(sourceIcon).size(32, 32).outputFormat("png")
.toFile(ctx.targetDir().resolve(langId + "@2x.png").toFile());
ImageIO.write(resizeImage(sourceIcon, 16, 16), "png", targetIcon.toFile());
ImageIO.write(resizeImage(sourceIcon, 32, 32), "png", ctx.targetDir().resolve(langId + "@2x.png").toFile());
logInfo(" OK", true, false);
} catch (final Exception ex) {
logInfo(" ERROR [" + ex.getMessage().replace("\n", " | ") + "]", true, false);
Expand Down Expand Up @@ -184,8 +181,8 @@ void handle() throws IOException {
final var grammarOverrides = defaultIfNull(source.inlineGrammars.get(scopeName), Config.InlineGrammarIgnoreable::new);

if (!isBlank(grammarOverrides.ignoredReason) && !"false".equals(grammarOverrides.ignoredReason)) {
logInfo("Ignoring inline grammar contribution [" + scopeName + "] as per user config" + ("true".equals(
grammarOverrides.ignoredReason) ? "." : ": " + grammarOverrides.ignoredReason));
logInfo("Ignoring inline grammar contribution [" + scopeName + "] as per user config"
+ ("true".equals(grammarOverrides.ignoredReason) ? "." : ": " + grammarOverrides.ignoredReason));
continue;
}
final var grammarCfg = inlineGrammar.getValue();
Expand All @@ -197,10 +194,10 @@ void handle() throws IOException {
}

BufferedImage resizeImage(final BufferedImage originalImage, final int targetWidth, final int targetHeight) {
final BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, Transparency.TRANSLUCENT);
final var resizedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = resizedImage.createGraphics();

// Use RenderingHints to improve image quality
// use RenderingHints to improve image quality
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null);
g2d.dispose();
Expand Down
Loading