Skip to content

Commit

Permalink
Generate theme sizes based off of fontsize
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthayhurst committed Oct 30, 2020
1 parent a77c05b commit ed67e8b
Show file tree
Hide file tree
Showing 210 changed files with 108 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
37 changes: 12 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ BACKGROUNDS4k=$(wildcard ./backgrounds/4k/*.png)
ICONSVGS=$(wildcard ./assets/svg/icons/*.svg)
SELECTSVGS=$(wildcard ./assets/svg/select/*.svg)

.PHONY: clean compress-backgrounds generate-icons generate-select generate-all $(ICONSVGS) $(SELECTSVGS) $(BACKGROUNDS1080p) $(BACKGROUNDS2k) $(BACKGROUNDS4k)
.PHONY: clean full-clean compress-backgrounds generate-icons generate-select generate-all $(ICONSVGS) $(SELECTSVGS) $(BACKGROUNDS1080p) $(BACKGROUNDS2k) $(BACKGROUNDS4k)

clean:
rm -rvf "./build"
full-clean:
rm -rvf "./assets/icons/"*
rm -rvf "./assets/select/"*
rm -rvf "./build"
compress-backgrounds:
read -ra backgrounds <<< "$$(echo ./backgrounds/*/*.png)"; \
make "$${backgrounds[@]}" "-j$$(nproc)"
Expand All @@ -25,32 +28,16 @@ generate-all:
make generate-icons generate-select

$(ICONSVGS): ./assets/svg/icons/%.svg: ./Makefile
dpis=("96" "144" "192"); \
for dpi in "$${dpis[@]}"; do \
if [[ "$$dpi" == "96" ]]; then \
resolution="1080p"; \
elif [[ "$$dpi" == "144" ]]; then \
resolution="2k"; \
elif [[ "$$dpi" == "192" ]]; then \
resolution="4k"; \
fi; \
mkdir -p "./assets/icons/$$resolution"; \
icon="$@"; icon="$${icon##*/}"; icon="$${icon/.svg/.png}"; \
inkscape "--export-dpi=$$dpi" "--export-filename=./assets/icons/$$resolution/$$icon" "$@" >/dev/null 2>&1; \
resolutions=("32" "48" "64"); \
for resolution in "$${resolutions[@]}"; do \
icon="$@"; \
./install.sh "--generate" "$$resolution" "icons" "default" "$$icon"; \
done
$(SELECTSVGS): ./assets/svg/select/%.svg: ./Makefile
dpis=("96" "144" "192"); \
for dpi in "$${dpis[@]}"; do \
if [[ "$$dpi" == "96" ]]; then \
resolution="1080p"; \
elif [[ "$$dpi" == "144" ]]; then \
resolution="2k"; \
elif [[ "$$dpi" == "192" ]]; then \
resolution="4k"; \
fi; \
mkdir -p "./assets/select/$$resolution"; \
select="$@"; select="$${select##*/}"; select="$${select/.svg/.png}"; \
inkscape "--export-dpi=$$dpi" "--export-filename=./assets/select/$$resolution/$$select" "$@" >/dev/null 2>&1; \
resolutions=("37" "56" "74"); \
for resolution in "$${resolutions[@]}"; do \
select="$@"; \
./install.sh "--generate" "$$resolution" "select" "default" "$$select"; \
done

$(BACKGROUNDS1080p): ./backgrounds/1080p/%.png: ./Makefile
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Required arguments: [--install + --background / --uninstall / --preview]
- Install the theme for a 4k display, using the `Night` wallpaper:
- `sudo ./install.sh --install --resolution 4k --background Night`

- Preview the theme with a fontsize of 32:
- `./install.sh -p -b Crystals -fs 32`

- Install the theme into /boot/grub/themes:
- `sudo ./install.sh -i -e -b Night`

Expand All @@ -33,8 +36,12 @@ Required arguments: [--install + --background / --uninstall / --preview]
- Individual images at end of document

## Dependencies:
#### Mandatory:
- `make` - Used for the build system
- `inkscape` - Used to generate pngs from svgs (Used by `make generate-all`)
- `inkscape` is needed if the fontsize used isn't 16, 24 or 32
- `imagemagick / convert` can be used as an alternative
#### Optional:
- `optipng` - Used to losslessly compress pngs (Used by `make compress-backgrounds`)
- `grub2-theme-preview` - Used to preview themes (Used by --preview)

Expand All @@ -56,13 +63,14 @@ Required arguments: [--install + --background / --uninstall / --preview]
![Grey](docs/Grey.png)

## Makefile options:
- `make clean` - Remove all generated assets
- `make clean` - Remove assets generated at build time
- `make full-clean` - Remove all generated assets
- `make generate-all` - Generate all assets
- `make compress-backgrounds` - Compress backgrounds losslessly

## Contributing:
- If you made changes to any images, or added a new one:
- Run `make clean`
- Run `make full-clean`
- Run `make generate-all`
- If the change was to a background, scale the background for each resolution, then:
- Run `make compress-backgrounds`
Expand Down
Binary file removed assets/icons/1080p/solus.png
Binary file not shown.
Binary file removed assets/icons/2k/solus.png
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/icons/32px/solus.png
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/icons/48px/solus.png
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed assets/icons/4k/solus.png
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/icons/64px/solus.png
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed assets/select/1080p/select_c.png
Diff not rendered.
Binary file removed assets/select/1080p/select_e.png
Diff not rendered.
Binary file removed assets/select/1080p/select_w.png
Diff not rendered.
Binary file removed assets/select/2k/select_c.png
Diff not rendered.
Binary file removed assets/select/2k/select_e.png
Diff not rendered.
Binary file removed assets/select/2k/select_w.png
Diff not rendered.
Binary file added assets/select/32px/select_c.png
Binary file added assets/select/32px/select_e.png
Binary file added assets/select/32px/select_w.png
Binary file added assets/select/48px/select_c.png
Binary file added assets/select/48px/select_e.png
Binary file added assets/select/48px/select_w.png
Binary file removed assets/select/4k/select_c.png
Diff not rendered.
Binary file removed assets/select/4k/select_e.png
Diff not rendered.
Binary file removed assets/select/4k/select_w.png
Diff not rendered.
Binary file added assets/select/64px/select_c.png
Binary file added assets/select/64px/select_e.png
Binary file added assets/select/64px/select_w.png
2 changes: 1 addition & 1 deletion theme/theme-template.txt → assets/theme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
title-text: ""
desktop-image: "background.png"
desktop-color: "#000000"
terminal-font: "Terminus Regular {font_size_template}"
terminal-font: "Terminus Regular 16"
terminal-box: "terminal_box_*.png"
terminal-left: "0%"
terminal-top: "0%"
Expand Down
98 changes: 84 additions & 14 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ getResolution() {
getFontSize() {
fontsize="${1/"px"}"
if checkArg "$fontsize"; then
if [[ ! "$fontsize" =~ ^[0-9]+$ ]] || [[ "$fontsize" -gt "32" ]] || [[ "$fontsize" -lt "10" ]]; then
output "warning" "Font size must be a number between 10 and 32, ignoring"
if [[ ! "$fontsize" =~ ^[0-9]+$ ]]; then
output "warning" "Font size must be an integer, ignoring"
fontsize=""
fi
else
Expand All @@ -89,32 +89,93 @@ getFontSize() {
fi
}

generateIcons() {
#generateIcons "resolution" "icons/select" "default/install" "svgFile"
generateIcon() {
pngFile="${svgFile##*/}"
pngFile="${pngFile/.svg/.png}"
if checkCommand inkscape; then
inkscape "-h" "$assetSize" "--export-filename=$buildDir/$pngFile" "$svgFile" >/dev/null 2>&1
elif checkCommand convert; then
output "warning" "Low quality: Inkscape not found, using imagemagick..."
convert -scale "x$assetSize" -extent "x$assetSize" -background none "$svgFile" "$buildDir/$pngFile"
else
output "error" "Neither inkscape or convert are available"
output "warning" "Please install inkscape or imagemagick (preferably inkscape)"
fi
}
assetSize="${1/px}"
if [[ "$3" == "default" ]] && [[ "$2" == "select" ]]; then
case $assetSize in
"37") assetSizeDir="32";;
"56") assetSizeDir="48";;
"74") assetSizeDir="64";;
esac
else
assetSizeDir="$assetSize"
fi
if [[ "$3" == "default" ]]; then
buildDir="./assets/$2/${assetSizeDir}px"
elif [[ "$3" == "install" ]]; then
buildDir="./build/$2"
fi
mkdir -p "$buildDir"
if [[ "$3" == "default" ]]; then
svgFile="./$4"
generateIcon
else
for svgFile in "./assets/svg/$2/"*; do
generateIcon
done
fi
}

generateThemeValues() {
icon_size="$(($1 * 2))"
item_icon_space="$((icon_size / 2 + 2))"
item_height="$((icon_size / 6 + icon_size))"
item_padding="$((icon_size / 4))"
item_spacing="$((icon_size / 3))"
font_name="${font_name:-DejaVu Sans Regular}"
}

installCore() {
#Generate and install theme.txt
output "success" "Generating theme.txt..."
font_size="$fontsize"
source "theme/theme-values.sh"
fileContent="$(cat theme/theme-template.txt)"
generateThemeValues "$fontsize"
fileContent="$(cat assets/theme.txt)"
fileContent="${fileContent//"{icon_size_template}"/"$icon_size"}"
fileContent="${fileContent//"{item_icon_space_template}"/"$item_icon_space"}"
fileContent="${fileContent//"{item_height_template}"/"$item_height"}"
fileContent="${fileContent//"{item_padding_template}"/"$item_padding"}"
fileContent="${fileContent//"{item_spacing_template}"/"$item_spacing"}"
fileContent="${fileContent//"{font_size_template}"/"$font_size"}"
fileContent="${fileContent//"{font_size_template}"/"$fontsize"}"
fileContent="${fileContent//"{font_name_template}"/"$font_name"}"
echo "$fileContent" > "$installDir/theme.txt"

#Generate and set path for icons
if [[ ! -d "./assets/icons/${icon_size}px" ]]; then
output "success" "Generating theme assets..."
generateIcons "$icon_size" "icons" "install"
generateIcons "$item_height" "select" "install"
iconDir="./build/icons"
selectDir="./build/select"
else
iconDir="./assets/icons/${icon_size}px"
selectDir="./assets/select/${icon_size}px"
fi

#Install theme components
output "success" "Installing theme assets..."
cp -r "assets/icons/$resolution" "$installDir/icons"
cp "assets/select/$resolution/"*.png "$installDir/"
cp -r "$iconDir" "$installDir/icons"
cp "$selectDir/"*.png "$installDir/"

#Generate and install fonts
generateFont() {
grub-mkfont "$1" -o "$2" -s "$3"
}
generateFont "fonts/DejaVuSans.ttf" "$installDir/dejava_sans_$font_size.pf2" "$font_size"
generateFont "fonts/Terminus.ttf" "$installDir/terminus_$font_size.pf2" "$font_size"
generateFont "fonts/DejaVuSans.ttf" "$installDir/dejava_sans_$fontsize.pf2" "$fontsize"
generateFont "fonts/Terminus.ttf" "$installDir/terminus_16.pf2" "16"

#Install background
if [[ ! -f "$background" ]]; then
Expand Down Expand Up @@ -162,6 +223,8 @@ installTheme() {
gfxmode="GRUB_GFXMODE=3840x2160,auto"
elif [[ "$resolution" == '2k' ]]; then
gfxmode="GRUB_GFXMODE=2560x1440,auto"
else
gfxmode="auto"
fi

if grep "GRUB_GFXMODE=" /etc/default/grub >/dev/null 2>&1; then
Expand Down Expand Up @@ -247,15 +310,16 @@ uninstallTheme() {

previewTheme() {
if ! checkCommand grub2-theme-preview; then
echo "No working copy of grub2-theme-preview found"
echo "grub2-theme-preview: https://github.com/hartwork/grub2-theme-preview"
output "error" "No working copy of grub2-theme-preview found"
output "warning" "grub2-theme-preview: https://github.com/hartwork/grub2-theme-preview"
exit 1
fi
installDir="$(mktemp -d)"

#Install files to $installDir
installCore

echo "Installed to $installDir"
output "success" "Installed to $installDir"
grub2-theme-preview "$installDir"
rm -rf "$installDir"
}
Expand All @@ -281,7 +345,7 @@ while [[ $i -le "$(($# - 1))" ]]; do
output "normal" " - Leave blank to view available backgrounds"
output "normal" "-r | --resolution : Use a specific resolution (Default: 1080p)"
output "normal" " - Leave blank to view available resolutions"
output "normal" "-fs| --fontsize : Use a specific font size (10-32)"
output "normal" "-fs| --fontsize : Use a specific font size"
output "normal" "\nRequired arguments: [--install + --background / --uninstall / --preview]"; \
output "success" "Program written by: Stuart Hayhurst"; exit 0;;
-i|--install) programOperation="install";;
Expand All @@ -291,6 +355,7 @@ while [[ $i -le "$(($# - 1))" ]]; do
-b|--background) getBackground "${args["$((i + 1))"]}" && i="$((i + 1))";;
-r|--resolution) getResolution "${args["$((i + 1))"]}" && i="$((i + 1))";;
-fs|--fontsize|--font-size) getFontSize "${args["$((i + 1))"]}" && i="$((i + 1))";;
-g|--generate) generateIcons "${args["$((i + 1))"]}" "${args["$((i + 2))"]}" "${args["$((i + 3))"]}" "${args["$((i + 4))"]}"; exit;;
*) output "error" "Unknown parameter passed: $arg"; exit 1;;
esac
i=$((i + 1))
Expand All @@ -301,6 +366,11 @@ warnArgs() {
output "warning" "No resolution specified, using default of 1080p"
resolution="1080p"
fi
if [[ "$fontsize" == "" ]]; then
output "warning" "No fontsize specified, use -fs [VALUE] to set a font size"
output "warning" " - Default of 24 will be used"
fontsize="24"
fi
if [[ "$background" == "" ]]; then
output "error" "No background specified, use -b to list available backgrounds"
output "warning" " - Call the program with '-b [background]'"
Expand Down
25 changes: 0 additions & 25 deletions theme/theme-values.sh

This file was deleted.

0 comments on commit ed67e8b

Please sign in to comment.