@@ -16,4 +16,21 @@ config BR2_PACKAGE_GOOGLEFONTDIRECTORY_FONTS
Font directory code base. For example: ufl/ubuntu,
apache/kranky or ofl/gleego.
+config BR2_PACKAGE_GOOGLEFONTDIRECTORY_CREATE_STATIC
+ bool "Convert variable fonts to static"
+ default "false"
+ help
+ Convert the selected fonts to static fonts.
+
+if BR2_PACKAGE_GOOGLEFONTDIRECTORY_CREATE_STATIC
+
+config BR2_PACKAGE_GOOGLEFONTDIRECTORY_CREATE_STATIC_WEIGHTS_WIDTHS
+ string "List of font variants to generate"
+ default "Regular:400:100 Bold:700:100"
+ help
+ Specify a space-separated list of Name:Weight:Width tuples
+ describing the requested static font variants.
+
+endif
+
endif
@@ -27,6 +27,35 @@ endif
GOOGLEFONTDIRECTORY_LICENSE = $(subst $(space),$(comma)$(space),$(GOOGLEFONTDIRECTORY_ALL_LICENSES))
+ifeq ($(BR2_PACKAGE_GOOGLEFONTDIRECTORY_CREATE_STATIC),y)
+GOOGLEFONTDIRECTORY_DEPENDENCIES += host-python-fonttools
+GOOGLEFONTDIRECTORY_FONT_VARIANTS = \
+ $(call qstrip,$(BR2_PACKAGE_GOOGLEFONTDIRECTORY_CREATE_STATIC_WEIGHTS_WIDTHS))
+
+elementFromColonTuple = $(word $2,$(subst :, ,$1))
+define GOOGLEFONTDIRECTORY_BUILD_CMDS
+ $(foreach f,$(GOOGLEFONTDIRECTORY_FONTS), \
+ $(foreach v,$(GOOGLEFONTDIRECTORY_FONT_VARIANTS), \
+ $(foreach d,$(wildcard $(@D)/$(f)/*.ttf), \
+ $(HOST_DIR)/bin/fonttools varLib.mutator -q --output=$(@D)/temp.ttf $(d) wght=$(call elementFromColonTuple,$v,2) wdth=$(call elementFromColonTuple,$v,3)
+ $(HOST_DIR)/bin/ttx -q $(@D)/temp.ttf
+ $(SED) "s/Regular/$(call elementFromColonTuple,$v,1)/g" $(@D)/temp.ttx
+ $(HOST_DIR)/bin/ttx -q -o $(@D)/$(basename $(notdir $f))-$(call LOWERCASE,$(call elementFromColonTuple,$v,1)).ttf $(@D)/temp.ttx
+ $(RM) $(@D)/temp.ttf $(@D)/temp.ttx
+ )
+ )
+ )
+endef
+
+define GOOGLEFONTDIRECTORY_INSTALL_TARGET_CMDS
+ $(foreach d,$(GOOGLEFONTDIRECTORY_FONTS), \
+ mkdir -p $(TARGET_DIR)/usr/share/fonts/$(notdir $(d))
+ -$(INSTALL) -m 0644 -t $(TARGET_DIR)/usr/share/fonts/$(notdir $(d)) $(@D)/$(basename $(notdir $d))-*.ttf
+ )
+endef
+
+else
+
define GOOGLEFONTDIRECTORY_INSTALL_TARGET_CMDS
$(foreach d,$(GOOGLEFONTDIRECTORY_FONTS), \
mkdir -p $(TARGET_DIR)/usr/share/fonts/$(notdir $(d))
@@ -34,4 +63,6 @@ define GOOGLEFONTDIRECTORY_INSTALL_TARGET_CMDS
)
endef
+endif
+
$(eval $(generic-package))