diff --git a/.gitignore b/.gitignore index a5cc017b1..8307d40fe 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__/ *.pyc waveflag build/ +venv/ diff --git a/Makefile b/Makefile index 3e1f820ee..ca6b7e34b 100644 --- a/Makefile +++ b/Makefile @@ -24,11 +24,8 @@ PNGQUANTFLAGS = --speed 1 --skip-if-larger --quality 85-95 --force BODY_DIMENSIONS = 136x128 IMOPS := -size $(BODY_DIMENSIONS) canvas:none -compose copy -gravity center -# zopflipng is better (about 5-10%) but much slower. it will be used if -# present. pass ZOPFLIPNG= as an arg to make to use optipng instead. - ZOPFLIPNG = zopflipng -OPTIPNG = optipng +TTX = ttx EMOJI_BUILDER = third_party/color_emoji/emoji_builder.py # flag for emoji builder. Default to legacy small metrics for the time being. @@ -83,6 +80,23 @@ SELECTED_FLAGS = AC AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ \ ZA ZM ZW \ GB-ENG GB-SCT GB-WLS +ifeq (,$(shell which $(ZOPFLIPNG))) + ifeq (,$(wildcard $(ZOPFLIPNG))) + MISSING_ZOPFLI = fail + endif +endif + +ifndef VIRTUAL_ENV + MISSING_VENV = fail +endif + +ifeq (, $(shell which $(VS_ADDER))) + MISSING_PY_TOOLS = fail +endif +ifeq (, $(shell which $(TTX))) + MISSING_PY_TOOLS = fail +endif + ALL_FLAGS = $(basename $(notdir $(wildcard $(FLAGS_SRC_DIR)/*.png))) FLAGS = $(SELECTED_FLAGS) @@ -91,7 +105,11 @@ FLAG_NAMES = $(FLAGS:%=%.png) FLAG_FILES = $(addprefix $(FLAGS_DIR)/, $(FLAG_NAMES)) RESIZED_FLAG_FILES = $(addprefix $(RESIZED_FLAGS_DIR)/, $(FLAG_NAMES)) +ifndef MISSING_PY_TOOLS FLAG_GLYPH_NAMES = $(shell $(PYTHON) flag_glyph_name.py $(FLAGS)) +else +FLAG_GLYPH_NAMES = +endif RENAMED_FLAG_NAMES = $(FLAG_GLYPH_NAMES:%=emoji_%.png) RENAMED_FLAG_FILES = $(addprefix $(RENAMED_FLAGS_DIR)/, $(RENAMED_FLAG_NAMES)) @@ -103,23 +121,6 @@ ALL_NAMES = $(EMOJI_NAMES) $(RENAMED_FLAG_NAMES) ALL_QUANTIZED_FILES = $(addprefix $(QUANTIZED_DIR)/, $(ALL_NAMES)) ALL_COMPRESSED_FILES = $(addprefix $(COMPRESSED_DIR)/, $(ALL_NAMES)) -# tool checks -ifeq (,$(shell which $(ZOPFLIPNG))) - ifeq (,$(wildcard $(ZOPFLIPNG))) - MISSING_ZOPFLI = fail - endif -endif - -ifeq (,$(shell which $(OPTIPNG))) - ifeq (,$(wildcard $(OPTIPNG))) - MISSING_OPTIPNG = fail - endif -endif - -ifeq (, $(shell which $(VS_ADDER))) - MISSING_ADDER = fail -endif - emoji: $(EMOJI_FILES) @@ -133,22 +134,16 @@ quantized: $(ALL_QUANTIZED_FILES) compressed: $(ALL_COMPRESSED_FILES) -check_compress_tool: +check_tools: ifdef MISSING_ZOPFLI - ifdef MISSING_OPTIPNG - $(error "neither $(ZOPFLIPNG) nor $(OPTIPNG) is available") - else - @echo "using $(OPTIPNG)" - endif -else - @echo "using $(ZOPFLIPNG)" + $(error "Missing $(ZOPFLIPNG). Try 'brew install zopfli' (Mac) or 'sudo apt-get install zopfli' (linux)") endif - -check_vs_adder: -ifdef MISSING_ADDER - $(error "$(VS_ADDER) not in path, run setup.py in nototools") +ifdef MISSING_VENV + $(error "Please start your virtual environment, and run: "'pip install -r requirements.txt'") +endif +ifdef MISSING_PY_TOOLS + $(error "Missing tools; run: "'pip install -r requirements.txt' in your virtual environment") endif - $(EMOJI_DIR) $(FLAGS_DIR) $(RESIZED_FLAGS_DIR) $(RENAMED_FLAGS_DIR) $(QUANTIZED_DIR) $(COMPRESSED_DIR): mkdir -p "$@" @@ -192,12 +187,8 @@ $(QUANTIZED_DIR)/%.png: $(RENAMED_FLAGS_DIR)/%.png | $(QUANTIZED_DIR) $(QUANTIZED_DIR)/%.png: $(EMOJI_DIR)/%.png | $(QUANTIZED_DIR) @($(PNGQUANT) $(PNGQUANTFLAGS) -o "$@" "$<"; case "$$?" in "98"|"99") echo "reuse $<";cp $< $@;; *) exit "$$?";; esac) -$(COMPRESSED_DIR)/%.png: $(QUANTIZED_DIR)/%.png | check_compress_tool $(COMPRESSED_DIR) -ifdef MISSING_ZOPFLI - @$(OPTIPNG) -quiet -o7 -clobber -force -out "$@" "$<" -else +$(COMPRESSED_DIR)/%.png: $(QUANTIZED_DIR)/%.png | check_tools $(COMPRESSED_DIR) @$(ZOPFLIPNG) -y "$<" "$@" 1> /dev/null 2>&1 -endif # Make 3.81 can endless loop here if the target is missing but no # prerequisite is updated and make has been invoked with -j, e.g.: @@ -216,7 +207,8 @@ endif ttx "$<" $(EMOJI).ttf: check_sequence $(EMOJI).tmpl.ttf $(EMOJI_BUILDER) $(PUA_ADDER) \ - $(ALL_COMPRESSED_FILES) | check_vs_adder + $(ALL_COMPRESSED_FILES) | check_tools + @$(PYTHON) $(EMOJI_BUILDER) $(SMALL_METRICS) -V $< "$@" "$(COMPRESSED_DIR)/emoji_u" @$(PYTHON) $(PUA_ADDER) "$@" "$@-with-pua" @$(VS_ADDER) -vs 2640 2642 2695 --dstdir '.' -o "$@-with-pua-varsel" "$@-with-pua" @@ -238,5 +230,5 @@ clean: .SECONDARY: $(EMOJI_FILES) $(FLAG_FILES) $(RESIZED_FLAG_FILES) $(RENAMED_FLAG_FILES) \ $(ALL_QUANTIZED_FILES) $(ALL_COMPRESSED_FILES) -.PHONY: clean flags emoji renamed_flags quantized compressed check_compress_tool +.PHONY: clean flags emoji renamed_flags quantized compressed check_tools diff --git a/README.md b/README.md index 1883dd933..01401661d 100644 --- a/README.md +++ b/README.md @@ -2,25 +2,36 @@ # Noto Emoji Color and Black-and-White Noto emoji fonts, and tools for working with them. +## Prerequisites +Building Noto Color Emoji requires: +- Python 3 +- [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) +- [pngquant](https://pngquant.org/) +- [zopflipng](https://github.com/google/zopfli) + ## Building NotoColorEmoji +This project uses a virtual environment to manage dependencies. Use the following steps to get up and running: -Building NotoColorEmoji currently requires a Python 2.x wide build. To build -the emoji font you will require a few files from nototools. Clone a copy from -https://github.com/googlei18n/nototools and either put it in your PYTHONPATH or -use 'python setup.py develop' ('install' currently won't fully install all the -data used by nototools). You will also need fontTools, get it from -https://github.com/behdad/fonttools.git. +```shell +# make sure you have the Prerequisites -Then run make. NotoColorEmoji is the default target. It's suggested to use -j, -especially if you are using zopflipng for compression. Intermediate products -(compressed image files, for example) will be put into a build subdirectory; the -font will be at the top level. +# create & activate a virtual environment +python3 -m venv venv +source venv/bin/activate + +# install python requirements +pip install -r requirements.txt + +time make -j +``` + +Intermediate products (compressed image files, for example) will be put into a build subdirectory; the font will be at the top level. ## Using NotoColorEmoji NotoColorEmoji uses the CBDT/CBLC color font format, which is supported by Android and Chrome/Chromium OS. Windows supports it starting with Windows 10 Anniversary -Update in Chome and Edge. On macOS, only Chrome supports it, while on Linux it will +Update in Chrome and Edge. On macOS, only Chrome supports it, while on Linux it will support it with some fontconfig tweaking, see [issue #36](https://github.com/googlei18n/noto-emoji/issues/36). Currently we do not build other color font formats. ## Color emoji assets diff --git a/add_emoji_gsub.py b/add_emoji_gsub.py index 9f578a302..9f1c40366 100755 --- a/add_emoji_gsub.py +++ b/add_emoji_gsub.py @@ -18,13 +18,11 @@ __author__ = "roozbeh@google.com (Roozbeh Pournader)" - import sys from fontTools import agl -from fontTools import ttLib from fontTools.ttLib.tables import otTables - +from fontTools import ttLib from nototools import font_data diff --git a/flag_glyph_name.py b/flag_glyph_name.py index e5ce40c20..84cfeb64b 100755 --- a/flag_glyph_name.py +++ b/flag_glyph_name.py @@ -22,7 +22,11 @@ __author__ = 'roozbeh@google.com (Roozbeh Pournader)' import re import sys -import add_emoji_gsub +try: + import add_emoji_gsub +except ImportError as e: + print(e, file=sys.stderr) + sys.exit('Python environment is not setup right') def two_letter_code_to_glyph_name(region_code): return 'u%04x_%04x' % ( diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..4cda58f53 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +fonttools>=4.7.0 +notofonttools>=0.2.4 \ No newline at end of file