Use Android fonts as they are for layoutlib native

Layoutlib native can handle fonts as the Android framework does. So
simply copy the Android fonts for layoutlib.

Exempt-From-Owner-Approval: experimental branch
Bug: 143073883
Test: layoutlib tests
Change-Id: Ida2e081d1b0737c70ea8621b23b5f0e729d5df35
Merged-In: Ida2e081d1b0737c70ea8621b23b5f0e729d5df35
This commit is contained in:
Jerome Gaillard 2019-10-23 11:43:26 +01:00
parent 3c7d3b3498
commit cf713d429b
3 changed files with 40 additions and 72 deletions

View file

@ -5973,8 +5973,6 @@ else
sdk_atree_files += $(atree_dir)/sdk.atree
endif
include $(BUILD_SYSTEM)/sdk_font.mk
deps := \
$(target_notice_file_txt) \
$(tools_notice_file_txt) \
@ -5995,8 +5993,7 @@ deps := \
$(ATREE_FILES) \
$(sdk_atree_files) \
$(HOST_OUT_EXECUTABLES)/atree \
$(HOST_OUT_EXECUTABLES)/line_endings \
$(SDK_FONT_DEPS)
$(HOST_OUT_EXECUTABLES)/line_endings
INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
$(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
@ -6019,7 +6016,6 @@ $(INTERNAL_SDK_TARGET): $(deps)
fi; \
done; \
if [ $$FAIL ]; then exit 1; fi
$(hide) echo $(notdir $(SDK_FONT_DEPS)) | tr " " "\n" > $(SDK_FONT_TEMP)/fontsInSdk.txt
$(hide) ( \
ATREE_STRIP="$(HOST_STRIP) -x" \
$(HOST_OUT_EXECUTABLES)/atree \
@ -6035,7 +6031,6 @@ $(INTERNAL_SDK_TARGET): $(deps)
-v "TARGET_ARCH=$(TARGET_ARCH)" \
-v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
-v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
-v "FONT_OUT=$(SDK_FONT_TEMP)" \
-o $(PRIVATE_DIR) && \
cp -f $(target_notice_file_txt) \
$(PRIVATE_DIR)/system-images/android-$(PLATFORM_VERSION)/$(TARGET_CPU_ABI)/NOTICE.txt && \
@ -6121,3 +6116,7 @@ $(call dist-for-goals,haiku,$(SOONG_FUZZ_PACKAGING_ARCH_MODULES))
.PHONY: haiku-rust
haiku-rust: $(SOONG_RUST_FUZZ_PACKAGING_ARCH_MODULES) $(ALL_RUST_FUZZ_TARGETS)
$(call dist-for-goals,haiku-rust,$(SOONG_RUST_FUZZ_PACKAGING_ARCH_MODULES))
# -----------------------------------------------------------------
# Extract platform fonts used in Layoutlib
include $(BUILD_SYSTEM)/layoutlib_fonts.mk

35
core/layoutlib_fonts.mk Normal file
View file

@ -0,0 +1,35 @@
# Fonts for layoutlib
FONT_TEMP := $(call intermediates-dir-for,PACKAGING,fonts,HOST,COMMON)
# The font configuration files - system_fonts.xml, fallback_fonts.xml etc.
font_config := $(sort $(wildcard frameworks/base/data/fonts/*.xml))
font_config := $(addprefix $(FONT_TEMP)/, $(notdir $(font_config)))
$(font_config): $(FONT_TEMP)/%.xml: \
frameworks/base/data/fonts/%.xml
$(hide) mkdir -p $(dir $@)
$(hide) cp -vf $< $@
# List of fonts on the device that we want to ship. This is all .ttf, .ttc and .otf fonts.
fonts_device := $(filter $(TARGET_OUT)/fonts/%.ttf $(TARGET_OUT)/fonts/%.ttc $(TARGET_OUT)/fonts/%.otf, $(INTERNAL_SYSTEMIMAGE_FILES))
fonts_device := $(addprefix $(FONT_TEMP)/, $(notdir $(fonts_device)))
# TODO: If the font file is a symlink, reuse the font renamed from the symlink
# target.
$(fonts_device): $(FONT_TEMP)/%: $(TARGET_OUT)/fonts/%
$(hide) mkdir -p $(dir $@)
$(hide) cp -vf $< $@
# List of all dependencies - all fonts and configuration files.
FONT_FILES := $(fonts_device) $(font_config)
.PHONY: layoutlib layoutlib-tests
layoutlib layoutlib-tests: $(FONT_FILES)
$(call dist-for-goals, layoutlib, $(foreach m,$(FONT_FILES), $(m):layoutlib_native/fonts/$(notdir $(m))))
FONT_TEMP :=
font_config :=
fonts_device :=
FONT_FILES :=

View file

@ -1,66 +0,0 @@
###############################################################################
# Fonts shipped with the SDK need to be renamed for Java to handle them
# properly. Hence, a special script is used to rename the fonts. We bundle all
# the fonts that are shipped on a newer non-space-constrained device. However,
# OpenType fonts used on these devices are not supported by Java. Their
# replacements are added separately.
###############################################################################
# The script that renames the font.
sdk_font_rename_script := frameworks/layoutlib/rename_font/build_font_single.py
# Location of the fonttools library that the above script depends on.
fonttools_lib := external/fonttools/Lib
# A temporary location to store the renamed fonts. atree picks all files in
# this directory and bundles it with the SDK.
SDK_FONT_TEMP := $(call intermediates-dir-for,PACKAGING,sdk-fonts,HOST,COMMON)
# The font configuration files - system_fonts.xml, fallback_fonts.xml etc.
sdk_font_config := $(sort $(wildcard frameworks/base/data/fonts/*.xml))
sdk_font_config := $(addprefix $(SDK_FONT_TEMP)/standard/, $(notdir $(sdk_font_config)))
$(sdk_font_config): $(SDK_FONT_TEMP)/standard/%.xml: \
frameworks/base/data/fonts/%.xml
$(hide) mkdir -p $(dir $@)
$(hide) cp -vf $< $@
# List of fonts on the device that we want to ship. This is all .ttf fonts.
sdk_fonts_device := $(filter $(TARGET_OUT)/fonts/%.ttf, $(INTERNAL_SYSTEMIMAGE_FILES))
sdk_fonts_device := $(addprefix $(SDK_FONT_TEMP)/, $(notdir $(sdk_fonts_device)))
# Macro to rename the font.
sdk_rename_font = PYTHONPATH=$$PYTHONPATH:$(fonttools_lib) $(sdk_font_rename_script) \
$1 $2
# TODO: If the font file is a symlink, reuse the font renamed from the symlink
# target.
$(sdk_fonts_device): $(SDK_FONT_TEMP)/%.ttf: $(TARGET_OUT)/fonts/%.ttf \
$(sdk_font_rename_script)
$(hide) mkdir -p $(dir $@)
$(hide) $(call sdk_rename_font,$<,$@)
# List of all dependencies - all fonts and configuration files.
SDK_FONT_DEPS := $(sdk_fonts_device) $(sdk_font_config)
# Define a macro to create rule for addititional fonts that we want to include
# in the SDK.
# $1 Output font name
# $2 Source font path
define sdk-extra-font-rule
fontfullname := $$(SDK_FONT_TEMP)/$1
ifeq ($$(filter $$(fontfullname),$$(sdk_fonts_device)),)
SDK_FONT_DEPS += $$(fontfullname)
$$(fontfullname): $2 $$(sdk_font_rename_script)
$$(hide) mkdir -p $$(dir $$@)
$$(hide) $$(call sdk_rename_font,$$<,$$@)
endif
fontfullname :=
endef
# These extra fonts are used as a replacement for OpenType fonts.
$(eval $(call sdk-extra-font-rule,NanumGothic.ttf,external/naver-fonts/NanumGothic.ttf))
$(eval $(call sdk-extra-font-rule,DroidSansFallback.ttf,frameworks/base/data/fonts/DroidSansFallbackFull.ttf))
sdk-extra-font-rule :=