Skip to content
Snippets Groups Projects
Commit 655e9f65 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

If no font object or filename is passed to lib, pick a font file at random

This moves the random file selection into tdfonts_lib.js

We should also pick a font index at random (when opt.random is true), but
that's not happening yet.

Also fixed up some indentation issues (when using 4 space tabstops). The
original commit of this file used spaces for indentation, so it's kind of
a mess now and should be uncrustified.
parent a1d0028c
No related branches found
No related tags found
No related merge requests found
...@@ -342,6 +342,16 @@ function reset_color() ...@@ -342,6 +342,16 @@ function reset_color()
} }
function output(str, font) { function output(str, font) {
if (!font) { // Random font file selection
var fontDir = FONT_DIR;
var files = directory(fontDir + "/*.tdf"); // Get all .tdf files
if (files.length > 0) {
var randomIndex = random((files.length)+1);
var filename = file_getname(files[randomIndex]);
font = filename.replace(/\.tdf$/i, "");
}
}
if (typeof font == "string") if (typeof font == "string")
font = loadfont(font); font = loadfont(font);
...@@ -369,7 +379,7 @@ function output(str, font) { ...@@ -369,7 +379,7 @@ function output(str, font) {
} }
// Calculate padding for justification // Calculate padding for justification
if (this.top && opt.justify === CENTER_JUSTIFY) { if (this.opt && opt.justify === CENTER_JUSTIFY) {
padding = Math.floor((opt.width - linewidth) / 2); padding = Math.floor((opt.width - linewidth) / 2);
} else if (this.opt && opt.justify === RIGHT_JUSTIFY) { } else if (this.opt && opt.justify === RIGHT_JUSTIFY) {
padding = opt.width - linewidth; padding = opt.width - linewidth;
......
...@@ -96,17 +96,7 @@ while (i < args.length) { ...@@ -96,17 +96,7 @@ while (i < args.length) {
} }
// Handle random font selection if (!fontfile && !opt.random)
if (!fontfile && opt.random) {
var fontDir = FONT_DIR;
var files = directory(fontDir + "/*.tdf"); // Get all .tdf files
if (files.length > 0) {
var randomIndex = random((files.length)+1);
var filename = file_getname(files[randomIndex]);
fontfile = filename.replace(/\.tdf$/i, "");
}
}
if (!fontfile)
usage(); usage();
writeln(""); writeln("");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment