blob: affe132ad2b9a2a3fa1181f300b4ed0057e09abc [file] [log] [blame]
[email protected]bd29cdd2013-02-22 03:49:201#!/usr/bin/env python
2# Copyright 2013 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# Script to install the Chrome OS fonts on Linux.
7# This script can be run manually (as root), but is also run as part
8# install-build-deps.sh.
9
Raul Tambre9e24293b2019-05-12 06:11:0710from __future__ import print_function
11
[email protected]bd29cdd2013-02-22 03:49:2012import os
13import shutil
14import subprocess
15import sys
16
dzhioeve9b72dd2015-11-15 12:11:4117URL_TEMPLATE = ('https://commondatastorage.googleapis.com/chromeos-localmirror/'
18 'distfiles/%(name)s-%(version)s.tar.bz2')
19
20# Taken from the media-fonts/<name> ebuilds in chromiumos-overlay.
jshin9492ea72017-03-30 19:54:2221# noto-cjk used to be here, but is removed because fc-cache takes too long
22# regenerating the fontconfig cache (See crbug.com/697954.)
23# TODO(jshin): Add it back when the above issue can be avoided.
dzhioeve9b72dd2015-11-15 12:11:4124SOURCES = [
25 {
26 'name': 'notofonts',
jshin70180dc2016-12-13 09:56:5027 'version': '20161129'
28 }, {
dzhioeve9b72dd2015-11-15 12:11:4129 'name': 'robotofonts',
jshinaf7381c2016-07-18 18:06:3630 'version': '2.132'
dzhioeve9b72dd2015-11-15 12:11:4131 }
32]
33
34URLS = sorted([URL_TEMPLATE % d for d in SOURCES])
[email protected]bd29cdd2013-02-22 03:49:2035FONTS_DIR = '/usr/local/share/fonts'
36
[email protected]bd29cdd2013-02-22 03:49:2037def main(args):
38 if not sys.platform.startswith('linux'):
Raul Tambre9e24293b2019-05-12 06:11:0739 print("Error: %s must be run on Linux." % __file__)
[email protected]bd29cdd2013-02-22 03:49:2040 return 1
41
42 if os.getuid() != 0:
Raul Tambre9e24293b2019-05-12 06:11:0743 print("Error: %s must be run as root." % __file__)
[email protected]bd29cdd2013-02-22 03:49:2044 return 1
45
46 if not os.path.isdir(FONTS_DIR):
Raul Tambre9e24293b2019-05-12 06:11:0747 print("Error: Destination directory does not exist: %s" % FONTS_DIR)
[email protected]bd29cdd2013-02-22 03:49:2048 return 1
49
50 dest_dir = os.path.join(FONTS_DIR, 'chromeos')
51
[email protected]bcbaa112013-02-27 18:03:2352 stamp = os.path.join(dest_dir, ".stamp02")
[email protected]bd29cdd2013-02-22 03:49:2053 if os.path.exists(stamp):
54 with open(stamp) as s:
dzhioeve9b72dd2015-11-15 12:11:4155 if s.read() == '\n'.join(URLS):
Raul Tambre9e24293b2019-05-12 06:11:0756 print("Chrome OS fonts already up to date in %s." % dest_dir)
[email protected]bd29cdd2013-02-22 03:49:2057 return 0
58
59 if os.path.isdir(dest_dir):
60 shutil.rmtree(dest_dir)
[email protected]bcbaa112013-02-27 18:03:2361 os.mkdir(dest_dir)
62 os.chmod(dest_dir, 0755)
[email protected]bd29cdd2013-02-22 03:49:2063
Raul Tambre9e24293b2019-05-12 06:11:0764 print("Installing Chrome OS fonts to %s." % dest_dir)
dzhioeve9b72dd2015-11-15 12:11:4165 for url in URLS:
66 tarball = os.path.join(dest_dir, os.path.basename(url))
67 subprocess.check_call(['curl', '-L', url, '-o', tarball])
68 subprocess.check_call(['tar', '--no-same-owner', '--no-same-permissions',
69 '-xf', tarball, '-C', dest_dir])
70 os.remove(tarball)
[email protected]bd29cdd2013-02-22 03:49:2071
72 readme = os.path.join(dest_dir, "README")
73 with open(readme, 'w') as s:
74 s.write("This directory and its contents are auto-generated.\n")
75 s.write("It may be deleted and recreated. Do not modify.\n")
76 s.write("Script: %s\n" % __file__)
77
78 with open(stamp, 'w') as s:
dzhioeve9b72dd2015-11-15 12:11:4179 s.write('\n'.join(URLS))
[email protected]bd29cdd2013-02-22 03:49:2080
[email protected]bcbaa112013-02-27 18:03:2381 for base, dirs, files in os.walk(dest_dir):
82 for dir in dirs:
83 os.chmod(os.path.join(base, dir), 0755)
84 for file in files:
85 os.chmod(os.path.join(base, file), 0644)
86
Raul Tambre9e24293b2019-05-12 06:11:0787 print("""\
derat5ae8fac2017-02-09 21:08:4988
89Chrome OS font rendering settings are specified using Fontconfig. If your
90system's configuration doesn't match Chrome OS's (which vary for different
91devices), fonts may be rendered with different subpixel rendering, subpixel
92positioning, or hinting settings. This may affect font metrics.
93
94Chrome OS's settings are stored in the media-libs/fontconfig package, which is
95at src/third_party/chromiumos-overlay/media-libs/fontconfig in a Chrome OS
96checkout. You can configure your system to match Chrome OS's defaults by
97creating or editing a ~/.fonts.conf file:
98
99<?xml version="1.0"?>
100<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
101<fontconfig>
102 <match target="font">
103 <edit name="antialias" mode="assign"><bool>true</bool></edit>
104 <edit name="autohint" mode="assign"><bool>true</bool></edit>
105 <edit name="hinting" mode="assign"><bool>true</bool></edit>
106 <edit name="hintstyle" mode="assign"><const>hintslight</const></edit>
107 <edit name="rgba" mode="assign"><const>rgb</const></edit>
108 </match>
109</fontconfig>
110
111To load additional per-font configs (and assuming you have Chrome OS checked
112out), add the following immediately before the "</fontconfig>" line:
113
114 <include ignore_missing="yes">/path/to/src/third_party/chromiumos-overlay/media-libs/fontconfig/files/local.conf</include>
Raul Tambre9e24293b2019-05-12 06:11:07115""")
derat5ae8fac2017-02-09 21:08:49116
[email protected]bd29cdd2013-02-22 03:49:20117 return 0
118
119if __name__ == '__main__':
120 sys.exit(main(sys.argv[1:]))