From 27647cef3ef01538a463e08bf672a44091c66d9a Mon Sep 17 00:00:00 2001 From: Michael Yin Date: Mon, 4 Jul 2016 20:34:28 -0600 Subject: [PATCH] windows: Add windows install package Adds an install process to replace Emoji on Windows. It merges the EmojiOne font with Segoe UI Symbol on the user's machine, and replaces Segoe UI Emoji as well on Win 8 and 10. An uninstall script is also included to assist the user in restoring the original Windows fonts. README also updated. Fixes #15 --- Makefile | 16 ++++- README.md | 23 ++++-- windows/.gitattributes | 1 + windows/generate_cmap4_from_12.py | 56 +++++++++++++++ windows/install.cmd | 114 ++++++++++++++++++++++++++++++ windows/uninstall.cmd | 18 +++++ 6 files changed, 220 insertions(+), 8 deletions(-) create mode 100644 windows/.gitattributes create mode 100755 windows/generate_cmap4_from_12.py create mode 100644 windows/install.cmd create mode 100644 windows/uninstall.cmd diff --git a/Makefile b/Makefile index 45d4050..312d86d 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,8 @@ OSX_FONT := build/$(FONT_PREFIX)-OSX.ttf OSX_PACKAGE := build/$(FONT_PREFIX)-OSX-$(VERSION) LINUX_PACKAGE := $(FONT_PREFIX)-Linux-$(VERSION) DEB_PACKAGE := fonts-emojione-svginot +WINDOWS_TOOLS := windows +WINDOWS_PACKAGE := build/$(FONT_PREFIX)-Win-$(VERSION) # There are two SVG source directories to keep the emojione assets separate # from the additions @@ -31,12 +33,12 @@ SVG_STAGE_FILES := $(patsubst $(SVG_EXTRA)/%.svg, build/stage/%.svg, $(SVG_STAGE SVG_BW_FILES := $(patsubst build/stage/%.svg, build/svg-bw/%.svg, $(SVG_STAGE_FILES)) SVG_COLOR_FILES := $(patsubst build/stage/%.svg, build/svg-color/%.svg, $(SVG_STAGE_FILES)) -.PHONY: all package regular-package linux-package osx-package copy-extra clean +.PHONY: all package regular-package linux-package osx-package windows-package copy-extra clean all: $(REGULAR_FONT) $(OSX_FONT) # Create the operating system specific packages -package: regular-package linux-package deb-package osx-package +package: regular-package linux-package deb-package osx-package windows-package regular-package: $(REGULAR_FONT) rm -f $(REGULAR_PACKAGE).zip @@ -73,6 +75,16 @@ osx-package: $(OSX_FONT) cp README.md $(OSX_PACKAGE) 7z a -tzip -mx=9 $(OSX_PACKAGE).zip ./$(OSX_PACKAGE) +windows-package: $(REGULAR_FONT) + rm -f $(WINDOWS_PACKAGE).zip + rm -rf $(WINDOWS_PACKAGE) + mkdir $(WINDOWS_PACKAGE) + cp $(REGULAR_FONT) $(WINDOWS_PACKAGE) + cp LICENSE* $(WINDOWS_PACKAGE) + cp README.md $(WINDOWS_PACKAGE) + cp $(WINDOWS_TOOLS)/* $(WINDOWS_PACKAGE) + 7z a -tzip -mx=9 $(WINDOWS_PACKAGE).zip ./$(WINDOWS_PACKAGE) + # Build both versions of the fonts $(REGULAR_FONT): $(SVG_BW_FILES) $(SVG_COLOR_FILES) copy-extra $(SCFBUILD) -c scfbuild.yml -o $(REGULAR_FONT) --font-version="$(VERSION)" diff --git a/README.md b/README.md index c2ae87d..6320601 100644 --- a/README.md +++ b/README.md @@ -153,13 +153,24 @@ Chrome will use the fallback black and white emoji.* ## Install on Windows -The font installs like any other font and can be specifically selected, but -the system will default to the `Segoe UI Emoji` font. Get the current version -from: https://github.com/eosrei/emojione-color-font/releases - -Help wanted: [How to override the Windows default Segoe UI Emoji font][16] +There are two install options for OS X. Both SVGinOT versions are available +from releases: https://github.com/eosrei/emojione-color-font/releases -[16]:https://github.com/eosrei/emojione-color-font/issues/15 +1. `EmojiOneColor-SVGinOT-1.2.zip` - The regular version of the font + installs like any other font and can be specifically selected, but Windows + will default to the `Segoe UI Emoji` font for emojis. +2. `EmojiOneColor-SVGinOT-Win-1.2.zip` - Because Windows 7, 8, 10 use Emoji in + both Segoe UI Symbol and Segoe UI Emoji, to be the default emoji, we need to + replace both, but keep the existing symbol characters from Segoe UI Symbol. + This package contains an install script that will generate both fonts (or + in Windows 7, just Segoe UI Symbol), and install them for you. Running the + install script requires both [Python (2 or 3)][16] and FontTools (which can be + installed using `pip install fonttools` once Python is installed). + +[16]:https://www.python.org/downloads/windows/ + +*Reiterating: Only FireFox supports the SVGinOT color emoji for now. IE and +Chrome will use the fallback black and white emoji.* ## Building Overview: diff --git a/windows/.gitattributes b/windows/.gitattributes new file mode 100644 index 0000000..6f3fd87 --- /dev/null +++ b/windows/.gitattributes @@ -0,0 +1 @@ +*.cmd text eol=crlf \ No newline at end of file diff --git a/windows/generate_cmap4_from_12.py b/windows/generate_cmap4_from_12.py new file mode 100755 index 0000000..03b2e18 --- /dev/null +++ b/windows/generate_cmap4_from_12.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# +# Some parts may be copyrighted Behdad Esfahbod and falls under the +# LICENSE for FontTools found at https://github.com/behdad/fonttools/blob/master/LICENSE + +"""\ +usage: generate_cmap4_from_12.py [options] input.ttf output.ttf +""" +import os.path +import tempfile +import argparse +import sys + +from fontTools.ttLib import TTFont +from fontTools.ttLib.tables._c_m_a_p import CmapSubtable + + +def main(argv): + parser = argparse.ArgumentParser( + description='Generate a cmap format 4 subtable when only a format 12 exists. This ensures Windows compatibility') + parser.add_argument('input', metavar='input.ttf', help='the font with subtable 12') + parser.add_argument('output', metavar='output.ttf', + help='a filename where a copy of the font will be saved including subtable 4') + + args = parser.parse_args() + font = TTFont(args.input) + cmap = font['cmap'] + + outtables = [] + + for table in cmap.tables: + outtables.append(table) + if (table.format == 12 and + table.platformID == 3 and + table.platEncID == 10): + # found a cmap12 3/10 subtable, create a matching cmap4 3/1 subtable + # must restrict to BMP characters + mapping = dict((k,v) for k,v in table.cmap.items() if k <= 0xFFFF) + newtable = CmapSubtable.newSubtable(4) + newtable.platformID = 3 + newtable.platEncID = 1 + newtable.language = table.language + newtable.cmap = mapping + outtables.append(newtable) + + if len(outtables) == len(cmap.tables): + print("Whoops! Couldn't find a cmap subtable format 12, platform id 3, platform encoding 10.") + return + + cmap.tables = outtables + + font.save(args.output) + +if __name__ == "__main__": + main(sys.argv) \ No newline at end of file diff --git a/windows/install.cmd b/windows/install.cmd new file mode 100644 index 0000000..b35accd --- /dev/null +++ b/windows/install.cmd @@ -0,0 +1,114 @@ +@ECHO OFF +SETLOCAL + +SET MS_EMOJI_FONT_PATH="%SystemRoot%\Fonts\seguiemj.ttf" +SET MS_FONT_PATH="%SystemRoot%\Fonts\seguisym.ttf" +SET EMOJI_FONT_PATH="%CD%\EmojiOneColor-SVGinOT.ttf" +SET FINAL_EMJ_FONT_PATH_NO_QUOTES=%CD%\Segoe UI Emoji with EmojiOne.ttf +SET FINAL_EMJ_FONT_PATH="%FINAL_EMJ_FONT_PATH_NO_QUOTES%" +SET FINAL_FONT_PATH_NO_QUOTES=%CD%\Segoe UI Symbol with EmojiOne.ttf +SET FINAL_FONT_PATH="%FINAL_FONT_PATH_NO_QUOTES%" +SET CMAP_SCRIPT="%CD%\generate_cmap4_from_12.py" + +ECHO Checking if Segoe UI Emoji is installed + +REM Windows 8 uses Segoe UI Emoji in addition to Symbol +REM Windows 7 only uses Segoe UI Symbol +REM We have to replace _both_ +ECHO Checking if Segoe UI Symbol is installed. + +IF NOT EXIST %MS_FONT_PATH% ( + ECHO. + ECHO You don't seem to have the Segoe UI Symbol Font installed. + ECHO https://support.microsoft.com/en-us/kb/2729094 + GOTO :ERROR +) + +ECHO Checking if prerequisites are installed. + +WHERE python >nul 2>nul || ( + ECHO. + ECHO Python not available in PATH. Is it installed? + ECHO https://www.python.org/downloads/windows/ + GOTO :ERROR +) +WHERE pyftmerge >nul 2>nul || ( + ECHO. + ECHO FontTools 3.x is not available in PATH. Is it installed? + ECHO https://github.com/behdad/fonttools + GOTO :ERROR +) + +PUSHD %TEMP% +IF EXIST %MS_EMOJI_FONT_PATH% ( + ECHO Creating new Segoe UI Emoji font from EmojiOne + ttx -t "name" -o "emjname.ttx" %MS_EMOJI_FONT_PATH% || GOTO :ERROR + ttx -o %FINAL_EMJ_FONT_PATH% -m %EMOJI_FONT_PATH% "emjname.ttx" || GOTO :ERROR + DEL "emjname.ttx" +) + +ECHO Creating new Segoe UI Symbol font from EmojiOne +REM Merge Segoe UI Symbol into EmojiOne, this keeps emoji one's glyph ids intact +REM for the 'SVG ' table data +pyftmerge %EMOJI_FONT_PATH% %MS_FONT_PATH% +REM pyftmerge doesn't generate a cmap4 table if either font has a cmap12 table +python %CMAP_SCRIPT% "merged.ttf" "mergedc4.ttf" || GOTO :ERROR +DEL "merged.ttf" +ECHO Dumping SVG emojis +ttx -t "SVG " -o "svg.ttx" %EMOJI_FONT_PATH% || GOTO :ERROR +ttx -t "name" -o "name.ttx" %MS_FONT_PATH% || GOTO :ERROR +ECHO Merging in dumped emojis +ttx -o "almost.ttf" -m "mergedc4.ttf" "name.ttx" || GOTO :ERROR +DEL "mergedc4.ttf" +DEL "name.ttx" +ttx -o %FINAL_FONT_PATH% -m "almost.ttf" "svg.ttx" || GOTO :ERROR +DEL "almost.ttf" +DEL "svg.ttx" +REM Get back to working directory. +POPD + +ECHO. +ECHO. +IF EXIST %MS_EMOJI_FONT_PATH% ( + ECHO The fonts are now saved in + ECHO %FINAL_FONT_PATH% + ECHO and + ECHO %FINAL_EMJ_FONT_PATH% + ECHO After installation, the original fonts will still be located at + ECHO %MS_FONT_PATH% + ECHO and + ECHO %MS_EMOJI_FONT_PATH% +) ELSE ( + ECHO The font is now saved in + ECHO %FINAL_FONT_PATH% + ECHO After installation, the original font will still be located at + ECHO %MS_FONT_PATH% +) +ECHO It is not overwritten, and can be reinstalled with uninstall.cmd +ECHO To finish installation, the font will be opened for you to install. +ECHO. +ECHO If the font is in a network path, copy to a local disk and +ECHO double click to install. +ECHO Press the [INSTALL] button in the Font Viewer, then close the viewer. +CHOICE /m "Would you like to install the fonts now?" +IF ERRORLEVEL 2 ( + EXIT /b +) +ECHO. +ECHO Running the font installer for Segoe UI Symbol +REM The font viewer doesn't like quotes for some reason, but is fine with paths with spaces. +fontview %FINAL_FONT_PATH_NO_QUOTES% +if EXIST %MS_EMOJI_FONT_PATH% ( + ECHO. + ECHO Running the font installer for Segoe UI Emoji + fontview %FINAL_EMJ_FONT_PATH_NO_QUOTES% +) +ECHO. +ECHO All Done! +PAUSE +EXIT /b + +:ERROR +ECHO Installation failed! +PAUSE +EXIT /b %ERRORLEVEL% \ No newline at end of file diff --git a/windows/uninstall.cmd b/windows/uninstall.cmd new file mode 100644 index 0000000..a95d4b2 --- /dev/null +++ b/windows/uninstall.cmd @@ -0,0 +1,18 @@ +@ECHO OFF +SETLOCAL + +SET MS_EMOJI_FONT_PATH="%SystemRoot%\Fonts\seguiemj.ttf" +SET MS_FONT_PATH="%SystemRoot%\Fonts\seguisym.ttf" + +IF EXIST %MS_EMOJI_FONT_PATH% ( + ECHO Pressing [INSTALL] button in the Font Viewer will reinstall + ECHO the original Segoe UI Emoji font. + fontview %SystemRoot%\Fonts\seguiemj.ttf +) +ECHO. +ECHO Pressing [INSTALL] button in the Font Viewer will reinstall +ECHO the original Segoe UI Symbol font. +fontview %SystemRoot%\Fonts\seguisym.ttf +ECHO. +ECHO All Done! +PAUSE