Skip to content

Commit

Permalink
automate most of the font generation steps and allow multi chars per …
Browse files Browse the repository at this point in the history
…glyph
  • Loading branch information
wchristian committed Dec 9, 2018
1 parent 207a9c2 commit d95be94
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 93 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
19 changes: 8 additions & 11 deletions font_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def glyph_nach_datei(glyph):
return glyph + ".glyph"
elif glyph == " ":
return "space.glyph"
elif glyph == "-":
return "uni2010.glyph"
else:
chars = list(glyph)
i = 0
Expand Down Expand Up @@ -65,24 +67,19 @@ class Schrift:
def __init__(self, name, quellordner, zielordner):
self.name = name
self.ordner = zielordner
if self.ordner in os.listdir("."):
raise Exception("Fehler: Zielordner existiert bereits.")
return None
else:
if not os.path.isdir(self.ordner):
os.mkdir(self.ordner)

for datei in os.listdir(quellordner):
if os.path.isfile(quellordner + "/" + datei):
shutil.copy(quellordner + "/" + datei, self.ordner)

self.props = []

for datei in os.listdir(quellordner):
if os.path.isfile(quellordner + "/" + datei):
shutil.copy(quellordner + "/" + datei, self.ordner)

self.props_oeffnen()
for i,zeile in enumerate(self.props):
for nameString in ["FontName:", "FullName:", "FamilyName:"]:
if zeile.startswith(nameString):
self.props[i] = nameString + " " + self.name + "\n"

def __del__(self):
self.props_schliessen()

Expand Down
2 changes: 1 addition & 1 deletion font_mod_character_pairs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Str|ate|Ret|urn|Adm|ira|l C|Cho|ose
Str|ate|gy|Ret|urn|Adm|ira|l C|omm|and|Cho|ose|ls |Com|man|der
Sel|ect
5 changes: 3 additions & 2 deletions font_mod_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

from font_manipulator import *
import itertools
import sys

start_unicode = "0xE000"
unicode_point_int = int(start_unicode, 0)
pairs = [line.rstrip('\n').split("|") for line in open('font_mod_character_pairs')]
pairs = filter(None, list(itertools.chain.from_iterable(pairs)))

name = "A-OTF-UDShinGoPro-Regular"
M20 = Schrift(name, "../"+name+".sfdir", "../"+name+"_mod.sfdir")
fontname = sys.argv[1]
M20 = Schrift(fontname, "../fonts/"+fontname+".sfdir", "../fonts/"+fontname+"_mod.sfdir")

for pair in pairs:
name = "uni%X" % unicode_point_int
Expand Down
79 changes: 79 additions & 0 deletions fonts/license.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<html>

<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8">
</head>
<body>

<pre>
-------------------------------------------------------------------------------
梅フォントのライセンス (日本語 UTF-8) (UmeFont license (In Japanese UTF-8))
-------------------------------------------------------------------------------

本ライセンスは以下の梅フォントに共通のライセンスです。

* 梅ゴシック
* 梅ゴシックC4
* 梅ゴシックS4
* 梅ゴシックO5
* 梅ゴシックC5
* 梅ゴシックS5
* 梅Pゴシック
* 梅PゴシックC4
* 梅PゴシックS4
* 梅PゴシックO5
* 梅PゴシックC5
* 梅PゴシックS5
* 梅UIゴシック
* 梅UIゴシックO5
* 梅Hyゴシック
* 梅HyゴシックO5
* 梅明朝
* 梅明朝S3
* 梅P明朝
* 梅P明朝S3


これらのフォントはフリー(自由な)ソフトウエアです。
あらゆる改変の有無に関わらず、また商業的な利用であっても、自由にご利用、複製、
再配布することができますが、全て無保証とさせていただきます。



-------------------------------------------------------------------------------
UmeFont license (In English)
-------------------------------------------------------------------------------

This is common license of the UmeFont family. UmeFont family provides the
following fonts:

* Ume Gothic
* Ume Gothic C4
* Ume Gothic S4
* Ume Gothic O5
* Ume Gothic C5
* Ume Gothic S5
* Ume P Gothic
* Ume P Gothic C4
* Ume P Gothic S4
* Ume P Gothic O5
* Ume P Gothic C5
* Ume P Gothic S5
* Ume UI Gothic
* Ume UI Gothic O5
* Ume Hy Gothic
* Ume Hy Gothic O5
* Ume Mincho
* Ume Mincho S3
* Ume P Mincho
* Ume P Mincho S3


These fonts are free software.
Unlimited permission is granted to use, copy, and distribute it,
with or without modification, either commercially and noncommercially.
THESE FONTS ARE PROVIDED "AS IS" WITHOUT WARRANTY.

</pre>
</body>
</html>
Binary file added fonts/ume-pgc4.ttf
Binary file not shown.
Binary file added fonts/ume-pgc5.ttf
Binary file not shown.
Binary file added fonts/ume-pgs4.ttf
Binary file not shown.
Binary file added fonts/ume-pgs5.ttf
Binary file not shown.
Binary file added fonts/ume-ugo4.ttf
Binary file not shown.
Binary file added fonts/ume-ugo5.ttf
Binary file not shown.
5 changes: 5 additions & 0 deletions generate_font_from_dir.ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dirname = $1
outfile = $2

Open(dirname)
Generate(outfile)
54 changes: 17 additions & 37 deletions kc_tr_notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,46 +80,26 @@ Detailed steps from start to finish:

<dll dictionary updater here>

But first it makes sense to run translate_utf16_binary.pl to regenerate
Assembly-CSharp.dll. It might complain, depending on whether the
translation dictionary has changed, that pairs are missing. Add them
judiciously to the font_mod_character_pairs file until it stops
complaining about that.
First we need to to regenerate Assembly-CSharp.dll. It might complain, depending
on whether the translation dictionary has changed, that pairs are missing. Add
them judiciously to the font_mod_character_pairs file until it stops
complaining.

- # perl translate_utf16_binary.pl

The following steps set up a font to prepare it for injecting character pairs.

- do this with:
- ..\kc_original_unpack\Media\Unity_Assets_Files\sharedassets2\A-OTF-ShinGoPro-Regular.ttf
- ..\kc_original_unpack\Media\Unity_Assets_Files\sharedassets3\A-OTF-UDShinGoPro-Regular.ttf
- open the ttf file in font forge
- CID > flatten
- save as directory in d:\vita\
- close
- open font dir in font forge
- save (wait a little)
- close
- open font file in font forge
- TODO: explain how to add a char for "space"
- copy text from unifraktur-maguntia/set_new_glyphs_as_unicode.txt
- ctrl+end, file > execute script, paste, select FF, OK (this'll take a while)
- save (wait a little)
- close



Now we have a directory with the specification of the font that contains
5000+ prepared glyphs in the first "Private Use Area". In the following
steps we make a copy of that and inject multi-character pairs into the
prepared glyphs.

After that, these steps will take a copy of the earlier prepared directory
and add the glyphs with the character pairs in the pairs file.

- # cd unifraktur-maguntia
- # python mod_kc_font.py
- open this directory in fontforge: unifraktur-maguntia/A-OTF-UDShinGoPro-Regular.sfdir
- file > generate fonts > opentype (cff)
- close ff
First directories are created with copies of the fonts that contain 5000+
prepared glyphs in the first "Private Use Area". Then copies of these
directories are made and multi-character strings injected into the prepared
glyphs. After that those mod directories are converted into fonts which are
stored in the appropriate translation candidate sub-directories.

The script caches font directories in ../fonts to speed things up. If you
suspect something went wrong, deleting either of them will cause them to be
rebuilt.

- # perl modify_fonts_and_inject.pl

And these steps inject them into the assets file,
ready for sending to the vita.
Expand Down
82 changes: 82 additions & 0 deletions modify_fonts_and_inject.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use 5.010;
use strictures 2;
use IO::All -binary;
use Capture::Tiny 'tee';

run();

sub run {
$|++;
say "you might want to run this to enable kanji: chcp 65001";
say "your terminal's font will need to support kanji too (e.g. MS Gothic, MS Mincho)\n";

while (1) {
system qq[perl translate_utf16_binary.pl];
print "do you wish to repeat the CSharp translation build? [n]";
my $in = <>;
chomp $in;
last if !$in or $in =~ /^n/;
}
print "do you wish to proceed [y]";
my $in = <>;
chomp $in;
return if $in and $in !~ /^y/;

my $ff = "C:/Program Files (x86)/FontForgeBuilds/bin/fontforge.exe";
my $candidate_dir = "../kc_translation_mod_candidate";
my @fonts = (
{
name => "A-OTF-UDShinGoPro-Regular",
target_path => "Media/Unity_Assets_Files/sharedassets3",
src => "fonts/ume-pgs4.ttf"
},
{
name => "A-OTF-ShinGoPro-Regular",
target_path => "Media/Unity_Assets_Files/sharedassets2",
src => "../kc_original_unpack/Media/Unity_Assets_Files/sharedassets3/A-OTF-UDShinGoPro-Regular.ttf"
},
);
io("../fonts")->mkdir if !-d "../fonts";
mod_font( $ff, $candidate_dir, $_->%* ) for @fonts;
say "all done";
return;
}

sub mod_font {
my ( $ff, $candidate_dir, %font ) = @_;
say "processing font '$font{name}'";

if ( !-e "../fonts/$font{name}.sfdir" ) {
say "preparing font from source with empty PUA glyphs and guaranteed space glyph";
my ( $out, $err, $res ) = tee { system(qq["$ff" -script prepare_new_font.ff "$font{src}" "../fonts/$font{name}.sfdir"]) };
$err =~ s/^Copyright.*\n(^ .*\n)+//m;
$err =~ s/^The following table.*ignored.*\n(^ .*\n)+//m;
$err =~ s/^Warning:.*\n(^ .*\n)+//mg;
$err =~ s/^This font contains both.*\n(^ .*\n)+//m;
$out =~ s/^log:.*\n//mg;
die "error:\nout:\n$out\nerr:\n$err\nres: $res\n" if $out or $err or $res;
}

say "modding font with multi-glyphs";
my ( $out, $err, $res ) = tee { system(qq[python font_mod_run.py "$font{name}"]) };
die "error:\nout:\n$out\nerr:\n$err\nres: $res\n" if $out or $err or $res;

say "generating font file from mod dir";
my $target_path = "$candidate_dir/$font{target_path}";
io($target_path)->mkpath;
my $target_body = "$target_path/$font{name}";
my $temp_target = "$target_body.otf";
my $mod_dir = "../fonts/$font{name}_mod.sfdir";
my ( $out2, $err2, $res2 ) = tee { system(qq["$ff" -script generate_font_from_dir.ff "$mod_dir" "$temp_target"]) };
$err2 =~ s/^Copyright.*\n(^ .*\n)+//m;
$err2 =~ s/^Lookup sub table.*is too big.*\n//m;
$err2 =~ s/^Lookup .* has an\n(^ .*\n)+//m;
die "error:\nout:\n$out2\nerr:\n$err2\nres: $res2\n" if $out2 or $err2 or $res2;

# the extension here is for compatibility. the fonts in kc are OTF, but
# have the extension ttf, so we generate the replacements to match
say "fixing final extension";
io($temp_target)->rename("$target_body.ttf");
say "done\n";
return;
}
58 changes: 58 additions & 0 deletions prepare_new_font.ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
infile = $1
dirname = $2

Print( "log: loading for saving to dir" )
Open(infile) # flatten if necessary, then save to a dir
if ($iscid)
Print( "log: flattening CID font" )
CIDFlatten()
endif
Print( "log: saving to dir" )
Save(dirname)
Close()

Print( "log: loading for resave" )
Open(dirname) # force the font through the load/save loop
Print( "log: resaving" ) # as a dir in case ff decides to change some
Save(dirname) # values again
Close()

Print( "log: loading for processing" )
Open(dirname)
Print( "log: processing" )

Print( "log: preparing PUA filling" )
start = 0xE000
chars_to_add = 5000
# would prefer to add 6400 and use up the entire PUA, but UDShinGoPro-Regular
# already has a char at F6BE and i guess now that we can add multiple chars per
# glyph using less is fine

Select("#") # copy this so we can add a shape to new chars so ff will save them
Copy()

oldsize = CharCnt() # add the new slots
SetCharCnt(oldsize + chars_to_add)

Select(oldsize, oldsize + chars_to_add - 2) # select all the newly added slots

Print( "log: filling PUA" )
foreach
Paste() # add the "#" shape
SetUnicodeValue(start) # set the correct unicode value
start++
endloop

Print( "log: ensuring there's a space char" )
if (!InFont("space"))
oldsize = CharCnt()
SetCharCnt(oldsize + 1)
Select(oldsize - 1)
Print("log: adding space glyph"+GlyphInfo("Name")+" "+GlyphInfo("Unicode")+" "+GlyphInfo("Encoding"))
SetUnicodeValue(0x0020)
SetWidth(333)
SetGlyphName("space")
endif

Print( "log: saving changes" )
Save(dirname)
22 changes: 0 additions & 22 deletions set_new_glyphs_as_unicode.txt

This file was deleted.

Loading

0 comments on commit d95be94

Please sign in to comment.