Skip to content

Commit

Permalink
feat: Allow multiple family-names per project
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jul 7, 2020
1 parent 0c26f81 commit b11fdca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
10 changes: 6 additions & 4 deletions src/functions.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
glyphInstances = $(shell $(PYTHON) -c 'from glyphsLib import GSFont; list(map(lambda x: print(x.name), GSFont("$1").instances))')
glyphsFamilyName = $(shell $(PYTHON) -c 'from glyphsLib import GSFont; print(GSFont("$1").familyName)')
ufoInstances = $(shell $(PYTHON) -c 'import babelfont; print(babelfont.OpenFont("$1").info.styleName)')
ufoFamilyName = $(shell $(PYTHON) -c 'import babelfont; print(babelfont.OpenFont("$1").info.familyName)')
glyphsFamilyNames ?= $(shell $(PYTHON) -c 'from glyphsLib import GSFont; print(GSFont("$1").familyName.title().replace(" ", ""))')
sfdFamilyNames ?=
ufoFamilyNames ?= $(shell $(PYTHON) -c 'import babelfont; print(babelfont.OpenFont("$1").info.familyName.title().replace(" ", ""))')
glyphsInstances ?= $(shell $(PYTHON) -c 'from glyphsLib import GSFont; list(map(lambda x: print(x.name), GSFont("$1").instances))')
ufoInstances ?= $(shell $(PYTHON) -c 'import babelfont; print(babelfont.OpenFont("$1").info.styleName)')
sfdInstances ?=

define normalizeVersion =
$(FONTV) $(FONTVFLAGS) write --ver=$(FontVersion) $(if $(isTagged),--rel,--dev --sha1) $@
Expand Down
49 changes: 25 additions & 24 deletions src/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,25 @@ include $(FONTSHIPDIR)/functions.mk

# Read font name from metadata file or guess from repository name
ifeq ($(CANONICAL),glyphs)
FamilyName ?= $(call glyphsFamilyName,$(firstword $(filter %.glyphs,$(SOURCES))))
FamilyNames ?= $(foreach SOURCE,$(filter %.glyphs,$(SOURCES)),$(call glyphsFamilyNames,$(SOURCE)))
FontStyles ?= $(foreach SOURCE,$(filter %.glyphs),$(SOURCES)),$(call glyphsInstances,$(SOURCE)))
isVariable ?= true
endif

ifeq ($(CANONICAL),sfd)
FamilyNames ?= $(foreach SOURCE,$(filter %.sfd,$(SOURCES)),$(call sfdFamilyNames,$(SOURCE)))
# FontStyles = $(subst $(FontBase)-,,$(basename $(wildcard $(FontBase)-*.ufo)))
endif

ifeq ($(CANONICAL),ufo)
FamilyName ?= $(call ufoFamilyName,$(firstword $(filter %.ufo,$(SOURCES))))
FamilyNames ?= $(foreach SOURCE,$(filter %.ufo,$(SOURCES)),$(call ufoFamilyNames,$(SOURCE)))
FontStyles ?= $(foreach SOURCE,$(filter %.ufo,$(SOURCES))),$(call ufoInstances,$(SOURCE)))
endif

FamilyName ?= $(shell $(CONTAINERIZED) || $(PYTHON) $(PYTHONFLAGS) -c 'print("$(PROJECT)".replace("-", " ").title())')

INSTANCES ?= $(foreach FamilyName,$(FamilyNames),$(foreach STYLE,$(FontStyles),$(BASE)-$(STYLE)))

GITVER = --tags --abbrev=6 --match='[0-9].[0-9][0-9][0-9]'
# Determine font version automatically from repository git tags
FontVersion ?= $(shell git describe $(GITVER) 2> /dev/null | sed 's/-.*//g')
Expand All @@ -87,26 +96,6 @@ endif
.PHONY: default
default: all

# Look for what fonts & styles are in this repository that will need building
FontBase = $(subst $(space),,$(FamilyName))

FontStyles = $(subst $(FontBase)-,,$(basename $(filter %.ufo,$(SOURCES))))
FontStyles += $(foreach UFO,$(filter %.ufo,$(SOURCES)),$(call ufoInstances,$(UFO)))
FontStyles += $(foreach GLYPHS,$(filter %.glyphs,$(SOURCES)),$(call glyphInstances,$(GLYPHS)))

INSTANCES = $(foreach BASE,$(FontBase),$(foreach STYLE,$(FontStyles),$(BASE)-$(STYLE)))

STATICOTFS = $(and $(STATICOTF),$(addsuffix .otf,$(INSTANCES)))
STATICTTFS = $(and $(STATICTTF),$(addsuffix .ttf,$(INSTANCES)))
STATICWOFFS = $(and $(STATICWOFF),$(addsuffix .woff,$(INSTANCES)))
STATICWOFF2S = $(and $(STATICWOFF2),$(addsuffix .woff2,$(INSTANCES)))
ifeq ($(isVariable),true)
VARIABLEOTFS = $(and $(VARIABLEOTF),$(addsuffix -VF.otf,$(FamilyNames)))
VARIABLETTFS = $(and $(VARIABLETTF),$(addsuffix -VF.ttf,$(FamilyNames)))
VARIABLEWOFFS = $(and $(VARIABLEWOFF),$(addsuffix -VF.woff,$(FamilyNames)))
VARIABLEWOFF2S = $(and $(VARIABLEWOFF2),$(addsuffix -VF.woff2,$(FamilyNames)))
endif

ifeq ($(DEBUG),true)
.SHELLFLAGS += +x
MAKEFLAGS += --no-silent
Expand Down Expand Up @@ -152,6 +141,17 @@ endif
endif
endif

STATICOTFS = $(and $(STATICOTF),$(addsuffix .otf,$(INSTANCES)))
STATICTTFS = $(and $(STATICTTF),$(addsuffix .ttf,$(INSTANCES)))
STATICWOFFS = $(and $(STATICWOFF),$(addsuffix .woff,$(INSTANCES)))
STATICWOFF2S = $(and $(STATICWOFF2),$(addsuffix .woff2,$(INSTANCES)))
ifeq ($(isVariable),true)
VARIABLEOTFS = $(and $(VARIABLEOTF),$(addsuffix -VF.otf,$(FamilyNames)))
VARIABLETTFS = $(and $(VARIABLETTF),$(addsuffix -VF.ttf,$(FamilyNames)))
VARIABLEWOFFS = $(and $(VARIABLEWOFF),$(addsuffix -VF.woff,$(FamilyNames)))
VARIABLEWOFF2S = $(and $(VARIABLEWOFF2),$(addsuffix -VF.woff2,$(FamilyNames)))
endif

.PHONY: debug
debug:
echo FONTSHIPDIR = $(FONTSHIPDIR)
Expand All @@ -161,8 +161,7 @@ debug:
echo PUBDIR = $(PUBDIR)
echo SOURCEDIR = $(SOURCEDIR)
echo ----------------------------
echo FamilyName = $(FamilyName)
echo FontBase = $(FontBase)
echo FamilyNames = $(FamilyNames)
echo FontStyles = $(FontStyles)
echo FontVersion = $(FontVersion)
echo FontVersionMeta = $(FontVersionMeta)
Expand Down Expand Up @@ -254,6 +253,8 @@ ifeq ($(PROJECT),data)
$(warning We cannot read the Project’s name inside Docker. Please manually specify it by adding PROOJECT='Name' as an agument to your command invocation)
endif

-include $(FONTSHIPDIR)/rules-$(CANONICAL).mk

# Webfont compressions

%.woff: %.ttf
Expand Down

0 comments on commit b11fdca

Please sign in to comment.