Skip to content

Commit

Permalink
feat: renew download_font.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
nanai10a committed Jun 19, 2024
1 parent 52c9014 commit 2502e6d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
.env
/db/
/db_config/
/NotoSansJP-Medium.ttf
/OFL.txt
/Noto.zip
/NotoSansCJKjp-Medium.ttf
72 changes: 62 additions & 10 deletions download_font.sh
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 1 addition & 1 deletion src/bot/genkai_point/plot/plotters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 2502e6d

Please sign in to comment.