fonts: Use a random pangram for fonts supporting English
This patch is a genuine product of Debconf 2018.
This commit is contained in:
parent
30589bc897
commit
e2fbb7f928
24
data/pangrams/en.txt
Normal file
24
data/pangrams/en.txt
Normal file
@ -0,0 +1,24 @@
|
||||
A quick brown fox jumps over the lazy dog.
|
||||
Whenever the black fox jumped the squirrel gazed suspiciously.
|
||||
The five boxing wizards jump quickly.
|
||||
A large fawn jumped quickly over white zebras in a box.
|
||||
We quietly gave Bert a handsome prize for his six juicy pink plums.
|
||||
Crazy Fredrick bought many very exquisite opal jewels.
|
||||
Five or six big jet planes zoomed quickly past the tower.
|
||||
My grandfather picks up quartz and valuable onyx jewels.
|
||||
Sphinx of black quartz, judge my vow.
|
||||
Two driven jocks help fax my big quiz.
|
||||
Five quacking zephyrs jolt my wax bed.
|
||||
Pack my box with five dozen liquor jugs.
|
||||
Jinxed wizards pluck ivy from the big quilt.
|
||||
We promptly judged antique ivory buckles for the next prize.
|
||||
A mad boxer shot a quick, gloved jab to the jaw of his dizzy opponent.
|
||||
Jaded zombies acted quaintly but kept driving their oxen forward.
|
||||
The job requires extra pluck and zeal from every young wage earner.
|
||||
Jived fox nymph grabs quick waltz.
|
||||
How vexingly quick daft zebras jump!
|
||||
Amazingly few discotheques provide jukeboxes.
|
||||
The quick onyx goblin jumps over the lazy dwarf.
|
||||
Six big devils from Japan quickly forgot how to waltz.
|
||||
Jack amazed a few girls by dropping the antique onyx vase.
|
||||
A quick movement of the enemy will jeopardize six gunboats.
|
@ -19,7 +19,7 @@
|
||||
|
||||
module asgen.font;
|
||||
|
||||
import std.string : format, fromStringz, toStringz, toLower, strip;
|
||||
import std.string : format, fromStringz, toStringz, toLower, strip, splitLines;
|
||||
import std.conv : to;
|
||||
import std.path : buildPath, baseName;
|
||||
import std.array : empty, appender, replace;
|
||||
@ -41,7 +41,9 @@ import asgen.config : Config;
|
||||
|
||||
// global font icon text lookup table, initialized by the constructor or Font and valid (and in memory)
|
||||
// as long as the generator runs.
|
||||
private static string[string] iconTexts;
|
||||
private __gshared static string[string] iconTexts;
|
||||
|
||||
private __gshared static string[] englishPangrams = import("pangrams/en.txt").splitLines ();
|
||||
|
||||
/**
|
||||
* Representation of a single font file.
|
||||
@ -114,8 +116,8 @@ public:
|
||||
if (err != 0)
|
||||
throw new Exception ("Unable to load font face from file. Error code: %s".format (err));
|
||||
|
||||
loadFontConfigData (fname);
|
||||
fileBaseName = fname.baseName;
|
||||
loadFontConfigData (fname);
|
||||
fileBaseName = fname.baseName;
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,6 +309,24 @@ public:
|
||||
import std.uni : byGrapheme, isGraphical, byCodePoint, Grapheme;
|
||||
import std.range;
|
||||
|
||||
string randomEnglishPangram ()
|
||||
{
|
||||
import std.digest.crc : crc32Of;
|
||||
import std.conv : to;
|
||||
import std.bitmanip : read;
|
||||
|
||||
auto tmpFontId = this.family;
|
||||
if (tmpFontId.empty)
|
||||
tmpFontId = this.fileBaseName;
|
||||
|
||||
// we do want deterministic results here, so base the "random"
|
||||
// pangram on the font family / font base name
|
||||
auto hash = crc32Of (tmpFontId).to!(ubyte[]);
|
||||
immutable pangramId = hash.read!uint % englishPangrams.length;
|
||||
|
||||
return englishPangrams[pangramId];
|
||||
}
|
||||
|
||||
void setFallbackSampleTextIfRequired ()
|
||||
{
|
||||
if (sampleText_.empty)
|
||||
@ -341,18 +361,22 @@ public:
|
||||
// determine our sample texts
|
||||
foreach (ref lang; tmpLangList) {
|
||||
auto plang = pango_language_from_string (lang.toStringz);
|
||||
auto text = pango_language_get_sample_string (plang).fromStringz;
|
||||
string text;
|
||||
if (lang == "en")
|
||||
text = randomEnglishPangram ();
|
||||
else
|
||||
text = pango_language_get_sample_string (plang).fromStringz.to!string;
|
||||
|
||||
if (text.empty)
|
||||
continue;
|
||||
if (text.empty)
|
||||
continue;
|
||||
|
||||
sampleText_ = text.dup;
|
||||
sampleText_ = text;
|
||||
const itP = lang in iconTexts;
|
||||
if (itP !is null) {
|
||||
sampleIconText_ = *itP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set some default values if we have been unable to find any texts
|
||||
setFallbackSampleTextIfRequired ();
|
||||
|
@ -7,6 +7,8 @@ configure_file(input : 'defines.d.in',
|
||||
configuration: conf_data
|
||||
)
|
||||
|
||||
data_import_dirs = include_directories('../../data')
|
||||
|
||||
#
|
||||
# Sources
|
||||
#
|
||||
@ -93,6 +95,7 @@ asgen_exe = executable('appstream-generator',
|
||||
fontconfig_dep,
|
||||
pango_dep],
|
||||
link_with: [girbind_lib],
|
||||
d_import_dirs: [data_import_dirs],
|
||||
install: true
|
||||
)
|
||||
|
||||
@ -115,6 +118,7 @@ asgen_test_exe = executable('asgen_test',
|
||||
fontconfig_dep,
|
||||
pango_dep],
|
||||
link_with: [girbind_lib],
|
||||
d_import_dirs: [data_import_dirs],
|
||||
d_unittest: true
|
||||
)
|
||||
test('asgen_tests', asgen_test_exe)
|
||||
|
Loading…
Reference in New Issue
Block a user