From 2502e6d7eb8db324cd8109f1bb0ec8e1ab6cc047 Mon Sep 17 00:00:00 2001 From: Nanai Jua Date: Tue, 18 Jun 2024 21:01:31 +0900 Subject: [PATCH] feat: renew `download_font.sh` --- .gitignore | 4 +- download_font.sh | 72 +++++++++++++++++++++++---- src/bot/genkai_point/plot/plotters.rs | 2 +- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index f70e92b..b2ba477 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,4 @@ .env /db/ /db_config/ -/NotoSansJP-Medium.ttf -/OFL.txt -/Noto.zip +/NotoSansCJKjp-Medium.ttf diff --git a/download_font.sh b/download_font.sh index d6614d0..f15244f 100755 --- a/download_font.sh +++ b/download_font.sh @@ -1,13 +1,65 @@ -#!/bin/sh +#!/bin/bash -set -exu +function info () { + local SUFFIX=$(tput sgr0) -cd $(dirname "$0") + if [ $1 -eq 0 ]; then + local PREFIX + elif [ $1 -eq 1 ]; then + local PREFIX="$(tput bold)==> " + elif [ $1 -eq 2 ]; then + local PREFIX=" -> " + fi -mkdir tmp -cd tmp -wget --https-only -O Noto.zip 'https://fonts.google.com/download?family=Noto%20Sans%20JP' -unzip Noto.zip static/NotoSansJP-Medium.ttf OFL.txt -mv static/NotoSansJP-Medium.ttf OFL.txt ../ -cd ../ -rm -rf tmp + echo -E "${PREFIX}${2}${SUFFIX}" >> /dev/stderr +} + +function findtools () { + info 1 "find ${1} ..." + + if which ${1} &> /dev/null; then + local LOCATION=$(which ${1}) + info 2 "found! (${LOCATION})" + info 0 + + echo -n "${LOCATION}" + else + info 2 "not found! exiting..." + fi + +} + +cd $(dirname "${0}") + +OTF_VARIANT="Sans" +OTF_FILENAME="Noto${OTF_VARIANT}CJKjp-Medium.otf" +OTF_URL="https://raw.githubusercontent.com/notofonts/noto-cjk/main/${OTF_VARIANT}/OTF/Japanese/${OTF_FILENAME}" + +TTF_FILENAME="${OTF_FILENAME%.*}.ttf" + +if [ -e "${TTF_FILENAME}" ]; then + info 1 "${TTF_FILENAME} is exists! exiting..." + exit +fi + +WGET=$(findtools wget) +[ ! ${WGET} ] && exit 1 + +FONTFORGE=$(findtools fontforge) +[ ! ${FONTFORGE} ] && exit 1 + +info 1 "download ${OTF_FILENAME}" +$WGET --https-only --output-document "${OTF_FILENAME}" "${OTF_URL}" +# info 0 + +info 1 "convert ${OTF_FILENAME} to ${TTF_FILENAME}" +$FONTFORGE -lang=ff -c 'Open($1); Generate($2)' "${OTF_FILENAME}" "${TTF_FILENAME}" +info 0 + +info 1 "remove unnecessary file" +info 2 "delete ${OTF_FILENAME}" +rm -f "${OTF_FILENAME}" +info 0 + +info 1 "complete! now available font" +info 2 "at ${TTF_FILENAME}" diff --git a/src/bot/genkai_point/plot/plotters.rs b/src/bot/genkai_point/plot/plotters.rs index 0ebf04e..eaba281 100644 --- a/src/bot/genkai_point/plot/plotters.rs +++ b/src/bot/genkai_point/plot/plotters.rs @@ -19,7 +19,7 @@ impl Plotters { plotters::style::register_font( "sans-serif", FontStyle::Normal, - include_bytes!("../../../../NotoSansJP-Medium.ttf"), // RUN download_font.sh IF YOU GOT THE NOT FOUND ERROR HERE + include_bytes!("../../../../NotoSansCJKjp-Medium.ttf"), // RUN download_font.sh IF YOU GOT THE NOT FOUND ERROR HERE ) // this error doesn't implement Debug .map_err(|_| panic!("failed to load embedded font"))