1#!/usr/bin/env python3 2# 3# Copyright 2023 Google LLC 4# 5# Use of this source code is governed by a BSD-style license that can be 6# found in the LICENSE file. 7 8 9""" 10The fonts collected by this script are used by SkParagraphTests.cpp which uses measurements 11that are very particular to the specific font being used. Thus, we try to get the fonts from 12a repeatable, documented source. 13""" 14 15 16import argparse 17import os 18import subprocess 19import tempfile 20import shutil 21 22# NotoNaskhArabic-Regular.ttf from https://fonts.google.com/noto/specimen/Noto+Naskh+Arabic 23# The fonts.google.com website seems to download the various .ttf files and then zip them client 24# side. By using DevTools to watch what happens when the Download Family button is pressed, and 25# then using sha256sum to verify the file in the .zip (with the nice name) matches the 26# indecipherable url, one can find the following link. I mirrored this to 27# https://storage.googleapis.com/skia-cdn/google-web-fonts/NotoNaskhArabic-Regular.ttf 28# in case the gstatic links "expire" at some point. 29# We cannot easily look at the .woff2 links from 30# https://fonts.googleapis.com/css2?family=Noto%20Naskh%20Arabic 31# as those seem to each have a subset of the unicode range and that makes our tests awkward. 32ARABIC_URL = 'https://fonts.gstatic.com/s/notonaskharabic/v33/RrQ5bpV-9Dd1b1OAGA6M9PkyDuVBePeKNaxcsss0Y7bwvc5krK0z9_Mnuw.ttf' 33ARABIC_SHA256 = 'b957e8c71a24e50c1aad4df775c46282bbe5e62e2b2b2ca72b153d75b6a15edd' 34 35def create_asset(target_dir): 36 """Copy the fonts from two different git repos into one folder.""" 37 os.makedirs(target_dir, exist_ok=True) 38 with tempfile.TemporaryDirectory() as tmp: 39 os.chdir(tmp) 40 subprocess.call(['git', 'clone', 'https://github.com/Rusino/textlayout']) 41 subprocess.call(['git', 'clone', 'https://skia.googlesource.com/skia/']) 42 43 os.chdir(os.path.join(tmp, "textlayout")) 44 subprocess.call(['git', 'checkout', '9c1868e84da1db358807ebff5cf52327e53560a0']) 45 shutil.copytree("fonts", target_dir, dirs_exist_ok=True) 46 47 os.chdir(os.path.join(tmp, "skia")) 48 subprocess.call(['git', 'checkout', '2f82ef6e77774dc4e8e382b2fb6159c58c0f8725']) 49 shutil.copytree(os.path.join("resources", "fonts"), target_dir, dirs_exist_ok=True) 50 # Cleanup files that are not fonts needed for tests 51 shutil.rmtree(os.path.join(target_dir, "abc")) 52 shutil.rmtree(os.path.join(target_dir, "svg")) 53 os.remove(os.path.join(target_dir, "fonts.xml")) 54 55 target_file = os.path.join(target_dir, 'NotoNaskhArabic-Regular.ttf') 56 subprocess.call(['wget', '--quiet', '--output-document', target_file, ARABIC_URL]) 57 output = subprocess.check_output(['sha256sum', target_file], encoding='utf-8') 58 actual_hash = output.split(' ')[0] 59 if actual_hash != ARABIC_SHA256: 60 raise Exception('SHA256 does not match (%s != %s)' % (actual_hash, ARABIC_SHA256)) 61 62 63def main(): 64 parser = argparse.ArgumentParser() 65 parser.add_argument('--target_dir', '-t', required=True) 66 args = parser.parse_args() 67 create_asset(args.target_dir) 68 69 70if __name__ == '__main__': 71 main() 72 73