Fixed a bug that the mana symbols for monocolored hybrid mana were not shown.

This commit is contained in:
LevelX2 2018-03-11 13:03:58 +01:00
parent 2fb8926432
commit fe5743b29e
2 changed files with 82 additions and 83 deletions

View file

@ -1,6 +1,14 @@
package org.mage.card.arcane;
import java.awt.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageProducer;
@ -18,13 +26,18 @@ import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.swing.*;
import mage.cards.repository.ExpansionRepository;
import mage.client.constants.Constants;
import mage.client.constants.Constants.ResourceSetSize;
import mage.client.constants.Constants.ResourceSymbolSize;
import mage.client.util.GUISizeHelper;
import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder;
@ -36,13 +49,6 @@ import org.apache.batik.transcoder.TranscodingHints;
import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.util.SVGConstants;
import org.apache.log4j.Logger;
import mage.client.constants.Constants;
import mage.client.constants.Constants.ResourceSymbolSize;
import mage.client.constants.Constants.ResourceSetSize;
import org.jdesktop.swingx.graphics.ShadowRenderer;
import org.jdesktop.swingx.graphics.GraphicsUtilities;
import org.mage.plugins.card.utils.CardImageUtils;
public final class ManaSymbols {
@ -71,9 +77,14 @@ public final class ManaSymbols {
private static final Map<String, Dimension> setImagesExist = new HashMap<>();
private static final Pattern REPLACE_SYMBOLS_PATTERN = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
private static String cachedPath;
private static final String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9", "B", "BG",
"BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU",
"WP", "UP", "BP", "RP", "GP", "X", "C", "E"};
private static final String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9",
"B", "BG", "BR", "BP", "2B",
"G", "GU", "GW", "GP", "2G",
"R", "RG", "RW", "RP", "2R",
"S", "T",
"U", "UB", "UR", "UP", "2U",
"W", "WB", "WU", "WP", "2W",
"X", "C", "E"};
private static final JLabel labelRender = new JLabel(); // render mana text
@ -101,8 +112,7 @@ public final class ManaSymbols {
}
for (String symbol : symbols) {
try
{
try {
BufferedImage image = pngImages.get(symbol);
if (image != null) {
File newFile = new File(pngPath.getPath() + File.separator + symbol + ".png");
@ -222,7 +232,6 @@ public final class ManaSymbols {
// load SVG image
// base loader code: https://stackoverflow.com/questions/11435671/how-to-get-a-buffererimage-from-a-svg
// resize code: https://vibranttechie.wordpress.com/2015/05/15/svg-loading-to-javafx-stage-and-auto-scaling-when-stage-resize/
if (useShadow && ((resizeToWidth <= 0) || (resizeToHeight <= 0))) {
throw new IllegalArgumentException("Must use non zero sizes for shadow.");
}
@ -234,12 +243,12 @@ public final class ManaSymbols {
// These defaults emphasize quality and precision, and
// are more similar to the defaults of other SVG viewers.
// SVG documents can still override these defaults.
String css = "svg {" +
"shape-rendering: geometricPrecision;" +
"text-rendering: geometricPrecision;" +
"color-rendering: optimizeQuality;" +
"image-rendering: optimizeQuality;" +
"}";
String css = "svg {"
+ "shape-rendering: geometricPrecision;"
+ "text-rendering: geometricPrecision;"
+ "color-rendering: optimizeQuality;"
+ "image-rendering: optimizeQuality;"
+ "}";
File cssFile = File.createTempFile("batik-default-override-", ".css");
FileWriter w = new FileWriter(cssFile);
w.write(css);
@ -293,8 +302,7 @@ public final class ManaSymbols {
t.transcode(input, null);
} catch (Exception e) {
throw new IOException("Couldn't convert svg file: " + svgFile + " , reason: " + e.getMessage());
}
finally {
} finally {
cssFile.delete();
}
@ -309,11 +317,12 @@ public final class ManaSymbols {
ImageProducer prod = new FilteredImageSource(originImage.getSource(), new RGBImageFilter() {
@Override
public int filterRGB(int x, int y, int rgb) {
if (rgb == 0)
if (rgb == 0) {
return 0;
else
} else {
return 0xff000000;
}
}
});
// create whe black image
Image shadow = Toolkit.getDefaultToolkit().createImage(prod);
@ -341,7 +350,6 @@ public final class ManaSymbols {
Color.GRAY);
return renderer.createShadow(base);
*/
//imagePointer[0];
}
@ -503,8 +511,7 @@ public final class ManaSymbols {
}
// fix double separator if size folder is not set
while(path.endsWith(File.separator))
{
while (path.endsWith(File.separator)) {
path = path.substring(0, path.length() - 1);
}
@ -533,8 +540,7 @@ public final class ManaSymbols {
}
// fix double separator if size folder is not set
while(path.endsWith(File.separator))
{
while (path.endsWith(File.separator)) {
path = path.substring(0, path.length() - 1);
}
@ -593,9 +599,6 @@ public final class ManaSymbols {
manaPanel.paint(gg);
g.drawImage(image, x, y, null);
*/
// OLD version with custom draw
Map<String, BufferedImage> sizedSymbols = manaImages.get(symbolWidth);
if (manaCost.isEmpty()) {
@ -680,7 +683,6 @@ public final class ManaSymbols {
// mana cost to HTML images (urls to files)
// do not use it for new code - try to suppotr svg render
int symbolSize;
switch (type) {
case TABLE:
@ -711,13 +713,11 @@ public final class ManaSymbols {
}
// replace every {symbol} to <img> link
// ignore data backup
String replaced = value
.replace("{source}", "|source|")
.replace("{this}", "|this|");
// not need to add different images (width and height do the work)
// use best png size (generated on startup) TODO: add reload images after update
String htmlImagesPath = getResourceSymbolsPath(ResourceSymbolSize.PNG);
@ -774,4 +774,3 @@ public final class ManaSymbols {
return sizedSymbols.get(symbol);
}
}

View file

@ -9,7 +9,6 @@ import com.google.common.collect.AbstractIterator;
import java.io.File;
import static java.lang.String.format;
import java.util.Iterator;
import mage.client.constants.Constants;
import org.mage.plugins.card.dl.DownloadJob;
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
@ -76,8 +75,9 @@ public class GathererSymbols implements Iterable<DownloadJob> {
File dst = new File(dir, symbol + ".gif");
/**
* Handle a bug on Gatherer where a few symbols are missing at the large size.
* Fall back to using the medium symbol for those cases.
* Handle a bug on Gatherer where a few symbols are missing
* at the large size. Fall back to using the medium symbol
* for those cases.
*/
int modSizeIndex = sizeIndex;
if (sizeIndex == 2) {