Skip to content

Commit

Permalink
Merge pull request #94 from approvers/fix-download-font-sh
Browse files Browse the repository at this point in the history
feat: 壊れた `download_font.sh` を再作成
  • Loading branch information
nanai10a authored Jun 19, 2024
2 parents 52c9014 + 85aaef9 commit 9cb95f0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
toolchain: ${{ steps.parse-toolchain.outputs.spec }}
- uses: Swatinem/rust-cache@v2
- name: install native deps
run: sudo apt update && sudo apt install clang llvm pkg-config nettle-dev
run: sudo apt update && sudo apt install clang llvm pkg-config nettle-dev fontforge
- run: cargo install cargo-udeps --locked

- run: cargo fmt -- --check
Expand Down
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
83 changes: 73 additions & 10 deletions download_font.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,76 @@
#!/bin/sh
#!/bin/bash

set -exu
set -e

cd $(dirname "$0")
function failed () {
info 0
info 2 "unexpected exitcode! exiting..."
}

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
trap failed ERR

export TERM="${TERM:-xterm-256color}"

function info () {
local SUFFIX=$(tput sgr0)

if [ $1 -eq 0 ]; then
local PREFIX
elif [ $1 -eq 1 ]; then
local PREFIX="$(tput bold)==> "
elif [ $1 -eq 2 ]; then
local PREFIX=" -> "
fi

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! font file is now available"
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 9cb95f0

Please sign in to comment.