mirror of
https://github.com/daylinmorgan/monolisa-nerdfont-patch.git
synced 2024-12-21 22:40:44 -06:00
update font-patcher and add update fonts script
This commit is contained in:
parent
85bb7bb025
commit
bbb93d09b8
2 changed files with 32 additions and 36 deletions
49
font-patcher
49
font-patcher
|
@ -659,10 +659,8 @@ class font_patcher:
|
|||
careful = True
|
||||
|
||||
if exactEncoding is False:
|
||||
sourceFontList = []
|
||||
sourceFontList = list(range(sourceFontStart, sourceFontEnd + 1))
|
||||
sourceFontCounter = 0
|
||||
for i in range(sourceFontStart, sourceFontEnd + 1):
|
||||
sourceFontList.append(format(i, 'X'))
|
||||
|
||||
scale_factor = 0
|
||||
if scaleGlyph:
|
||||
|
@ -675,21 +673,18 @@ class font_patcher:
|
|||
# and only copy those that are not already contained in the source font
|
||||
if symbolFontStart == 0:
|
||||
symbolFont.selection.all()
|
||||
self.sourceFont.selection.all()
|
||||
careful = True
|
||||
else:
|
||||
symbolFont.selection.select((str("ranges"), str("unicode")), symbolFontStart, symbolFontEnd)
|
||||
self.sourceFont.selection.select((str("ranges"), str("unicode")), sourceFontStart, sourceFontEnd)
|
||||
|
||||
# Get number of selected non-empty glyphs @TODO FIXME
|
||||
for index, sym_glyph in enumerate(symbolFont.selection.byGlyphs):
|
||||
glyphSetLength += 1
|
||||
# end for
|
||||
# Get number of selected non-empty glyphs
|
||||
symbolFontSelection = list(symbolFont.selection.byGlyphs)
|
||||
glyphSetLength = len(symbolFontSelection)
|
||||
|
||||
if self.args.quiet is False:
|
||||
sys.stdout.write("Adding " + str(max(1, glyphSetLength)) + " Glyphs from " + setName + " Set \n")
|
||||
|
||||
for index, sym_glyph in enumerate(symbolFont.selection.byGlyphs):
|
||||
for index, sym_glyph in enumerate(symbolFontSelection):
|
||||
index = max(1, index)
|
||||
|
||||
try:
|
||||
|
@ -700,25 +695,16 @@ class font_patcher:
|
|||
if exactEncoding:
|
||||
# use the exact same hex values for the source font as for the symbol font
|
||||
currentSourceFontGlyph = sym_glyph.encoding
|
||||
|
||||
# Save as a hex string without the '0x' prefix
|
||||
copiedToSlot = format(sym_glyph.unicode, 'X')
|
||||
else:
|
||||
# use source font defined hex values based on passed in start and end
|
||||
# convince that this string really is a hex:
|
||||
currentSourceFontGlyph = int("0x" + sourceFontList[sourceFontCounter], 16)
|
||||
copiedToSlot = sourceFontList[sourceFontCounter]
|
||||
currentSourceFontGlyph = sourceFontList[sourceFontCounter]
|
||||
sourceFontCounter += 1
|
||||
|
||||
if int(copiedToSlot, 16) < 0:
|
||||
print("Found invalid glyph slot number. Skipping.")
|
||||
continue
|
||||
|
||||
if self.args.quiet is False:
|
||||
if self.args.progressbars:
|
||||
update_progress(round(float(index + 1) / glyphSetLength, 2))
|
||||
else:
|
||||
progressText = "\nUpdating glyph: " + str(sym_glyph) + " " + str(sym_glyph.glyphname) + " putting at: " + copiedToSlot
|
||||
progressText = "\nUpdating glyph: {} {} putting at: {:X}".format(sym_glyph, sym_glyph.glyphname, currentSourceFontGlyph)
|
||||
sys.stdout.write(progressText)
|
||||
sys.stdout.flush()
|
||||
|
||||
|
@ -726,20 +712,17 @@ class font_patcher:
|
|||
sym_dim = get_glyph_dimensions(sym_glyph)
|
||||
|
||||
# check if a glyph already exists in this location
|
||||
if copiedToSlot.startswith("uni"):
|
||||
copiedToSlot = copiedToSlot[3:]
|
||||
codepoint = int("0x" + copiedToSlot, 16)
|
||||
if careful or 'careful' in sym_attr['params']:
|
||||
if codepoint in self.sourceFont:
|
||||
if currentSourceFontGlyph in self.sourceFont:
|
||||
if self.args.quiet is False:
|
||||
print(" Found existing Glyph at {}. Skipping...".format(copiedToSlot))
|
||||
print(" Found existing Glyph at {:X}. Skipping...".format(currentSourceFontGlyph))
|
||||
# We don't want to touch anything so move to next Glyph
|
||||
continue
|
||||
else:
|
||||
# If we overwrite an existing glyph all subtable entries regarding it will be wrong
|
||||
# (Probably; at least if we add a symbol and do not substitude a ligature or such)
|
||||
if codepoint in self.sourceFont:
|
||||
self.sourceFont[codepoint].removePosSub("*")
|
||||
if currentSourceFontGlyph in self.sourceFont:
|
||||
self.sourceFont[currentSourceFontGlyph].removePosSub("*")
|
||||
|
||||
# Select and copy symbol from its encoding point
|
||||
# We need to do this select after the careful check, this way we don't
|
||||
|
@ -791,7 +774,7 @@ class font_patcher:
|
|||
if 'overlap' in sym_attr['params']:
|
||||
scale_ratio_x *= 1 + sym_attr['params']['overlap']
|
||||
scale_ratio_y *= 1 + sym_attr['params']['overlap']
|
||||
self.sourceFont.transform(psMat.scale(scale_ratio_x, scale_ratio_y))
|
||||
self.sourceFont[currentSourceFontGlyph].transform(psMat.scale(scale_ratio_x, scale_ratio_y))
|
||||
|
||||
# Use the dimensions from the newly pasted and stretched glyph
|
||||
sym_dim = get_glyph_dimensions(self.sourceFont[currentSourceFontGlyph])
|
||||
|
@ -822,7 +805,7 @@ class font_patcher:
|
|||
x_align_distance += overlap_width
|
||||
|
||||
align_matrix = psMat.translate(x_align_distance, y_align_distance)
|
||||
self.sourceFont.transform(align_matrix)
|
||||
self.sourceFont[currentSourceFontGlyph].transform(align_matrix)
|
||||
|
||||
# Needed for setting 'advance width' on each glyph so they do not overlap,
|
||||
# also ensures the font is considered monospaced on Windows by setting the
|
||||
|
@ -834,12 +817,6 @@ class font_patcher:
|
|||
# does not overlap the bearings (edges)
|
||||
self.remove_glyph_neg_bearings(self.sourceFont[currentSourceFontGlyph])
|
||||
|
||||
# reset selection so iteration works properly @TODO fix? rookie misunderstanding?
|
||||
# This is likely needed because the selection was changed when the glyph was copy/pasted
|
||||
if symbolFontStart == 0:
|
||||
symbolFont.selection.all()
|
||||
else:
|
||||
symbolFont.selection.select((str("ranges"), str("unicode")), symbolFontStart, symbolFontEnd)
|
||||
# end for
|
||||
|
||||
if self.args.quiet is False or self.args.progressbars:
|
||||
|
|
19
update-fonts
Executable file
19
update-fonts
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
PATCHED_FONTS=./patched
|
||||
INSTALL_DIR=~/.local/share/fonts/MonoLisa
|
||||
|
||||
for font_dir in $PATCHED_FONTS/*; do
|
||||
patched_dir="${font_dir##*/}"
|
||||
echo ">>> $patched_dir"
|
||||
|
||||
if [[ -d "${INSTALL_DIR}/${patched_dir}" ]]; then
|
||||
echo "deleting existing version"
|
||||
rm -rf $INSTALL_DIR/$patched_dir
|
||||
fi
|
||||
|
||||
dest=$INSTALL_DIR/$patched_dir
|
||||
mkdir $dest && cp -v $font_dir/* $dest
|
||||
done
|
||||
|
||||
echo "Don't forget to run 'fc-cache -f -v'"
|
Loading…
Reference in a new issue