nerdfonts patcher support

master
Qwreey 2023-03-17 03:23:03 +09:00
parent 7eeb30a086
commit 2d55e92464
No known key found for this signature in database
GPG Key ID: 01D9B192033CF43F
3 changed files with 44 additions and 8 deletions

View File

@ -1,10 +1,10 @@
import argparse
import utility as Utility
def callPatcher(font):
import sys
NerdFontPatcher = sys.modules["NerdFontPatcher"]
NerdFontPatcher = sys.modules.get("NerdFontPatcher",None)
if not NerdFontPatcher:
import importlib.util
spec = importlib.util.spec_from_file_location("NerdFontPatcher", "assets/NerdFontPatcher_extract/fontPatcher.py")
@ -32,7 +32,9 @@ def callPatcher(font):
args.windows = True
args.alsowindows = False
args.nonmono = False
# args.progressbars = False
args.progressbars = True
# args.quiet = True
args.quiet = False
args.adjustLineHeight = True
# args.careful = True
@ -50,9 +52,36 @@ def callPatcher(font):
selFlag = ("more","ranges","unicode")
def postScript(font,deselectOriginalGlyphs,baseSize):
# Termux, Vscode 등에서 정의된 크기에 따라
# 폰트 크기를 맞춥니다
# 일반 크기
font.selection.none()
font.selection.select()
deselectOriginalGlyphs()
font.selection.select(selFlag,0xE200,0xF8FE)
font.selection.select(selFlag,0xFADA,0xFD46)
font.selection.select(selFlag,0xF8FF,0xF8FF)
font.selection.select(selFlag,0xF0001,0xF1AF0)
deselectOriginalGlyphs(font)
Utility.setWidthWithSavingPosition(
font=font,targetWidth=baseSize*2
)
Utility.width(font=font,targetWidth=baseSize)
# 2배 크기
font.selection.none()
font.selection.select(selFlag,0xF8FF,0xFAD9)
deselectOriginalGlyphs(font)
Utility.setWidthWithSavingPosition(
font=font,targetWidth=baseSize*2
)
# 몰라 그냥 다 2배로
# font.selection.none()
# font.selection.select(selFlag,0xF8FF,0xFAD9)
# deselectOriginalGlyphs(font)
# Utility.setWidthWithSavingPosition(
# font=font,targetWidth=baseSize*2
# )
def build(target,deselectOriginalGlyphs,NerdFontsAdjust=True,baseSize=550,weightStr="Regular"):
# 용량적 이유로 Regular 폰트에만 패치를 적용함
@ -64,5 +93,5 @@ def build(target,deselectOriginalGlyphs,NerdFontsAdjust=True,baseSize=550,weight
callPatcher(target)
# 적절한 크기를 위해서 크기조절을 수행함
# if NerdFontsAdjust:
# postScript(target,deselectOriginalGlyphs,baseSize)
if NerdFontsAdjust:
postScript(target,deselectOriginalGlyphs,baseSize)

View File

@ -40,15 +40,18 @@ def build(config=None):
print("--------------------- Patching ----------------------")
# 유지 목록 (덮어쓰기 금지) 만들기
kawaii.selection.all()
keepList = [i.unicode for i in kawaii.selection.byGlyphs]
keepList = None
def deselectOriginalGlyphs(target):
nonlocal keepList
for unicode in keepList:
if unicode == -1: continue
target.selection.select(deselectFlags,unicode)
def updateOriginalGlyphs():
nonlocal keepList
kawaii.selection.all()
keepList = [i.unicode for i in kawaii.selection.byGlyphs]
kawaii.selection.none()
updateOriginalGlyphs()
# 모든 글리프를 붇여넣을 수 있도록 인코딩을 utf full 로 변경
kawaii.encoding = 'UnicodeFull'
@ -93,6 +96,7 @@ def build(config=None):
baseSize=baseSize,
weightStr="Regular",
deselectOriginalGlyphs = deselectOriginalGlyphs)
updateOriginalGlyphs()
# 생성
if not os.path.exists("out"): os.mkdir("out")

View File

@ -9,6 +9,9 @@ def setWidthWithSavingPosition(font,targetWidth):
glyph.right_side_bearing = int(glyph.right_side_bearing + math.ceil(sideAdjust))
glyph.width = targetWidth # 타겟 너비로 정확하게 설정
def width(font,targetWidth):
for glyph in font.selection.byGlyphs: glyph.width = targetWidth
def scale(font,targetScale):
font.transform(psMat.scale(targetScale))
font.round()