Add default font

pull/35/head
James Ball 2020-11-21 17:03:56 +00:00
rodzic 8379c7ffa3
commit b2b63df91c
2 zmienionych plików z 13 dodań i 4 usunięć

Wyświetl plik

@ -24,7 +24,8 @@ final class AudioArgs {
filePath = args[0];
optionalArgs = new float[args.length - 1];
if (filePath.matches(".*\\.txt")) {
/* Second argument is a path to a font .svg if the first argument is a .txt file. */
if (filePath.matches(".*\\.txt") && args.length > 1) {
fontPath = args[1];
return;
}
@ -42,7 +43,7 @@ final class AudioArgs {
} else if (filePath.matches(".*\\.svg")) {
return new SvgParser(filePath);
} else if (filePath.matches(".*\\.txt")) {
return new TextParser(filePath, fontPath);
return fontPath.isEmpty() ? new TextParser(filePath) : new TextParser(filePath, fontPath);
} else {
throw new IllegalArgumentException(
"Provided file extension in file " + filePath + " not supported.");
@ -79,8 +80,9 @@ final class AudioArgs {
private static class IllegalAudioArgumentException extends IllegalArgumentException {
private static final String USAGE = "Incorrect usage.\nUsage: osci-render objFilePath "
+ "[rotateSpeed] [focalLength] [cameraX] [cameraY] [cameraZ]";
private static final String USAGE = "Incorrect usage.\nUsage: osci-render filePath "
+ "[rotateSpeed] [focalLength] [cameraX] [cameraY] [cameraZ]\nOR: osci-render textFilePath "
+ "[fontFilePath]";
public IllegalAudioArgumentException() {
super(USAGE);

Wyświetl plik

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.table.DefaultTableCellRenderer;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import shapes.Shape;
@ -17,6 +18,7 @@ public class TextParser extends FileParser{
private static final char WIDE_CHAR = 'W';
private static final double HEIGHT_SCALAR = 1.6;
private static final String DEFAULT_FONT = "fonts/SourceCodePro-ExtraLight.svg";
private final Map<Character, List<Shape>> charToShape;
private final List<String> text;
@ -31,6 +33,11 @@ public class TextParser extends FileParser{
parseFile(font);
}
public TextParser(String path)
throws IOException, SAXException, ParserConfigurationException {
this(path, DEFAULT_FONT);
}
@Override
protected String getFileExtension() {
return ".txt";