genallfont.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env bash
  2. #####################################################################
  3. # genallfont.sh for Marlin
  4. #
  5. # This script generates font data for language headers
  6. #
  7. # Copyright 2015-2018 Yunhui Fu <yhfudev@gmail.com>
  8. # License: GPL/BSD
  9. #####################################################################
  10. my_getpath() {
  11. local PARAM_DN="$1"
  12. shift
  13. #readlink -f
  14. local DN="${PARAM_DN}"
  15. local FN=
  16. if [ ! -d "${DN}" ]; then
  17. FN=$(basename "${DN}")
  18. DN=$(dirname "${DN}")
  19. fi
  20. cd "${DN}" > /dev/null 2>&1
  21. DN=$(pwd)
  22. cd - > /dev/null 2>&1
  23. echo -n "${DN}"
  24. [[ -z "$FN" ]] || echo -n "/${FN}"
  25. }
  26. DN_EXEC=$(dirname $(my_getpath "$0") )
  27. #
  28. # Get language arguments
  29. #
  30. LANG_ARG="$@"
  31. #
  32. # Use 6x12 combined font data for Western languages
  33. #
  34. FN_FONT="${DN_EXEC}/marlin-6x12-3.bdf"
  35. #
  36. # Change to working directory 'Marlin'
  37. #
  38. OLDWD=`pwd`
  39. [[ $(basename "$OLDWD") != 'Marlin' && -d "Marlin" ]] && cd Marlin
  40. [[ -f "Configuration.h" ]] || { echo -n "cd to the 'Marlin' folder to run " ; basename $0 ; exit 1; }
  41. #
  42. # Compile the 'genpages.exe' and 'bdf2u8g.exe' commands in-place
  43. #
  44. if [[ ! -x "${DN_EXEC}/genpages/genpages.exe" ]]; then
  45. echo "Building genpages.exe..."
  46. ( cd ${DN_EXEC}/genpages ; cc -o genpages.exe genpages.c getline.c )
  47. [[ -x "${DN_EXEC}/genpages/genpages.exe" ]] || { echo "Build of genpages.exe failed" ; exit 1 ; }
  48. fi
  49. if [[ ! -x "${DN_EXEC}/bdf2u8g/bdf2u8g.exe" ]]; then
  50. echo "Building bdf2u8g.exe..."
  51. ( cd ${DN_EXEC}/bdf2u8g ; make )
  52. [[ -x "${DN_EXEC}/bdf2u8g/bdf2u8g.exe" ]] || { echo "Build of bdf2u8g.exe failed" ; exit 1 ; }
  53. fi
  54. #
  55. # By default loop through all languages
  56. #
  57. LANGS_DEFAULT="an bg ca cz da de el el_CY en es eu fi fr fr_na gl hr hu it jp_kana ko_KR nl pl pt pt_br ro ru sk sv tr uk vi zh_CN zh_TW test"
  58. #
  59. # Generate data for language list MARLIN_LANGS or all if not provided
  60. #
  61. for ALANG in ${LANG_ARG:=$LANGS_DEFAULT} ; do
  62. echo "Generating Marlin language data for '${ALANG}'" >&2
  63. case "$ALANG" in
  64. zh_* ) FONTFILE="wenquanyi_12pt" ;;
  65. ko_* ) FONTFILE="${DN_EXEC}/NanumGothic.bdf" ;;
  66. * ) FONTFILE="${DN_EXEC}/marlin-6x12-3.bdf" ;;
  67. esac
  68. DN_WORK=$(mktemp -d)
  69. cp Configuration.h ${DN_WORK}/
  70. cp src/lcd/language/language_${ALANG}.h ${DN_WORK}/
  71. cd "${DN_WORK}"
  72. ${DN_EXEC}/uxggenpages.sh "${FONTFILE}" $ALANG
  73. sed -i fontutf8-data.h -e 's|fonts//|fonts/|g' -e 's|fonts//|fonts/|g' -e 's|[/0-9a-zA-Z_\-]*buildroot/share/fonts|buildroot/share/fonts|' 2>/dev/null
  74. cd - >/dev/null
  75. mv ${DN_WORK}/fontutf8-data.h src/lcd/dogm/fontdata/langdata_${ALANG}.h
  76. rm -rf ${DN_WORK}
  77. done
  78. #
  79. # Generate default ASCII font (char range 0-255):
  80. # Marlin/src/lcd/dogm/fontdata/fontdata_ISO10646_1.h
  81. #
  82. EXEC_BDF2U8G="${DN_EXEC}/bdf2u8g/bdf2u8g.exe"
  83. #if [ "${MARLIN_LANGS}" == "${LANGS_DEFAULT}" ]; then
  84. if [ 1 = 1 ]; then
  85. DN_WORK=$(mktemp -d)
  86. cd ${DN_WORK}
  87. ${EXEC_BDF2U8G} -b 1 -e 127 ${FN_FONT} ISO10646_1_5x7 tmp1.h >/dev/null
  88. ${EXEC_BDF2U8G} -b 1 -e 255 ${FN_FONT} ISO10646_1_5x7 tmp2.h >/dev/null
  89. TMP1=$(cat tmp1.h)
  90. TMP2=$(cat tmp2.h)
  91. cd - >/dev/null
  92. rm -rf ${DN_WORK}
  93. cat <<EOF >src/lcd/dogm/fontdata/fontdata_ISO10646_1.h
  94. /**
  95. * Marlin 3D Printer Firmware
  96. * Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  97. *
  98. * Based on Sprinter and grbl.
  99. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  100. *
  101. * This program is free software: you can redistribute it and/or modify
  102. * it under the terms of the GNU General Public License as published by
  103. * the Free Software Foundation, either version 3 of the License, or
  104. * (at your option) any later version.
  105. *
  106. * This program is distributed in the hope that it will be useful,
  107. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  108. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  109. * GNU General Public License for more details.
  110. *
  111. * You should have received a copy of the GNU General Public License
  112. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  113. *
  114. */
  115. #include <U8glib-HAL.h>
  116. #if defined(__AVR__) && ENABLED(NOT_EXTENDED_ISO10646_1_5X7)
  117. // reduced font (only symbols 1 - 127) - saves about 1278 bytes of FLASH
  118. $TMP1
  119. #else
  120. // extended (original) font (symbols 1 - 255)
  121. $TMP2
  122. #endif
  123. EOF
  124. fi
  125. cd "$OLDWD"