From 93273a4c9ea13888894cd7e765972cb445280465 Mon Sep 17 00:00:00 2001
From: Yunhui Fu <yhfudev@gmail.com>
Date: Sun, 15 Apr 2018 14:12:02 -0400
Subject: [PATCH] Fix u8g.h search path error (#10419)

Support env MARLIN_LANGS for user select generated language, and update doc; update script to generate dogm_font_data_ISO10646_1.h automatically.
---
 .travis.yml                          |  4 +++
 Marlin/src/lcd/u8g_fontutf8.c        |  7 ++--
 buildroot/share/fonts/genallfont.sh  | 49 ++++++++++++++++++++++++----
 buildroot/share/fonts/uxggenpages.md | 16 +++++----
 buildroot/share/fonts/uxggenpages.sh |  2 +-
 5 files changed, 60 insertions(+), 18 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9866d6c408..6268a5e9cd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -43,6 +43,10 @@ before_script:
   - cat ${TRAVIS_BUILD_DIR}/Marlin/src/inc/_Version.h
   #
 script:
+  #
+  # Fix include path problem in platformio.ini, U8glib-HAL_ID1932/src/lib/u8g.h
+  #
+  - find Marlin/ -name "*.h" | while read a; do sed -e 's|clib/u8g.h|u8g.h|' -i "$a"; done
   #
   # Backup pins_RAMPS.h
   #
diff --git a/Marlin/src/lcd/u8g_fontutf8.c b/Marlin/src/lcd/u8g_fontutf8.c
index 4e59e23055..8c0827582c 100644
--- a/Marlin/src/lcd/u8g_fontutf8.c
+++ b/Marlin/src/lcd/u8g_fontutf8.c
@@ -8,7 +8,6 @@
  */
 
 #include <string.h>
-#include <clib/u8g.h>
 #include "fontutils.h"
 #include "u8g_fontutf8.h"
 
@@ -216,7 +215,7 @@ unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, wchar_t
   const font_t *fnt_default = uxg_GetFont(pu8g);
 
   if (!uxg_Utf8FontIsInited()) {
-    u8g_DrawStrP(pu8g, x, y, PSTR("Err: utf8 font not initialized."));
+    u8g_DrawStrP(pu8g, x, y, (const u8g_pgm_uint8_t *)PSTR("Err: utf8 font not initialized."));
     return 0;
   }
   data.pu8g = pu8g;
@@ -250,7 +249,7 @@ unsigned int uxg_DrawUtf8Str(u8g_t *pu8g, unsigned int x, unsigned int y, const
   const font_t *fnt_default = uxg_GetFont(pu8g);
 
   if (!uxg_Utf8FontIsInited()) {
-    u8g_DrawStrP(pu8g, x, y, PSTR("Err: utf8 font not initialized."));
+    u8g_DrawStrP(pu8g, x, y, (const u8g_pgm_uint8_t *)PSTR("Err: utf8 font not initialized."));
     return 0;
   }
   data.pu8g = pu8g;
@@ -285,7 +284,7 @@ unsigned int uxg_DrawUtf8StrP(u8g_t *pu8g, unsigned int x, unsigned int y, const
 
   if (!uxg_Utf8FontIsInited()) {
     TRACE("Error, utf8string not inited!");
-    u8g_DrawStrP(pu8g, x, y, PSTR("Err: utf8 font not initialized."));
+    u8g_DrawStrP(pu8g, x, y, (const u8g_pgm_uint8_t *)PSTR("Err: utf8 font not initialized."));
     return 0;
   }
   data.pu8g = pu8g;
diff --git a/buildroot/share/fonts/genallfont.sh b/buildroot/share/fonts/genallfont.sh
index d23f481a76..0d382da425 100755
--- a/buildroot/share/fonts/genallfont.sh
+++ b/buildroot/share/fonts/genallfont.sh
@@ -37,16 +37,13 @@ EXEC_BDF2U8G=`which bdf2u8g`
 echo "0 set EXEC_BDF2U8G=$EXEC_BDF2U8G"
 if [ ! -x "${EXEC_BDF2U8G}" ]; then
     EXEC_BDF2U8G="${DN_EXEC}/bdf2u8g"
-echo "1 set EXEC_BDF2U8G=$EXEC_BDF2U8G"
 fi
 if [ ! -x "${EXEC_BDF2U8G}" ]; then
     EXEC_BDF2U8G="${PWD}/bdf2u8g"
-echo "2 set EXEC_BDF2U8G=$EXEC_BDF2U8G"
 fi
 if [ ! -x "${EXEC_BDF2U8G}" ]; then
-  echo "Not found bdf2u8g!"
-  echo "plaese compile u8blib/tools/font/bdf2u8g/bdf2u8g and link to it from here!"
-
+  echo "ERR: Not found bdf2u8g!" >&2
+  echo "plaese compile u8blib/tools/font/bdf2u8g/bdf2u8g and link to it from here!" >&2
   exit 1
 fi
 
@@ -59,17 +56,55 @@ DN_WORK=./tmp1
 
 (cd ${DN_EXEC}; gcc -o genpages genpages.c getline.c)
 
-LANGS="an bg ca zh_CN zh_TW cz da de el el-gr en es eu fi fr gl hr it jp-kana nl pl pt pt-br ru sk tr uk test"
+LANGS_DEFAULT="an bg ca zh_CN zh_TW cz da de el el-gr en es eu fi fr gl hr it jp-kana nl pl pt pt-br ru sk tr uk test"
+
+for LANG in ${MARLIN_LANGS:=$LANGS_DEFAULT} ; do
+    echo "INFO: generate Marlin language data for '${LANG}'" >&2
 
-for LANG in ${LANGS} ; do
     rm -rf ${DN_WORK}/
     mkdir -p ${DN_WORK}
     cp Configuration.h    ${DN_WORK}/
     cp src/lcd/language/language_${LANG}.h ${DN_WORK}/
     cd ${DN_WORK}/
     ${EXEC_WXGGEN} "${FN_NEWFONT}"
+    sed -e 's|fonts//|fonts/|g' -e 's|fonts//|fonts/|g' -e 's|[/0-9a-zA-Z_\-]*buildroot/share/fonts|buildroot/share/fonts|' -i fontutf8-data.h
     cd ../
     mv ${DN_WORK}/fontutf8-data.h src/lcd/dogm/language_data_${LANG}.h
     rm -rf ${DN_WORK}/
 done
 
+
+# generate default ASCII font (char range 0-255):
+#   Marlin/src/lcd/dogm/dogm_font_data_ISO10646_1.h
+#if [ "${MARLIN_LANGS}" == "${LANGS_DEFAULT}" ]; then
+if [ 1 = 1 ]; then
+    rm -rf ${DN_WORK}/
+    mkdir -p ${DN_WORK}
+    cd ${DN_WORK}/
+    ${EXEC_BDF2U8G} -b 1 -e 127 ${FN_NEWFONT} ISO10646_1_5x7 tmp1.h
+    ${EXEC_BDF2U8G} -b 1 -e 255 ${FN_NEWFONT} ISO10646_1_5x7 tmp2.h
+
+    cat << EOF >tmp3.h
+#include <U8glib.h>
+
+#if defined(__AVR__) && ENABLED(NOT_EXTENDED_ISO10646_1_5X7)
+  // reduced font (only sysmbols 1 - 127) - saves about 1278 bytes of FLASH
+
+EOF
+    cat tmp1.h >>tmp3.h
+    cat << EOF >>tmp3.h
+#else
+  // extended (original) font (sysmbols 1 - 255)
+EOF
+    cat tmp2.h >>tmp3.h
+    cat << EOF >>tmp3.h
+
+#endif
+EOF
+    sed -e 's|#include "u8g.h"|#include <clib/u8g.h>|' -i tmp3.h
+
+    cd ..
+    mv ${DN_WORK}/tmp3.h src/lcd/dogm/dogm_font_data_ISO10646_1.h
+fi
+
+
diff --git a/buildroot/share/fonts/uxggenpages.md b/buildroot/share/fonts/uxggenpages.md
index 01ca41925b..f105cf2cb0 100644
--- a/buildroot/share/fonts/uxggenpages.md
+++ b/buildroot/share/fonts/uxggenpages.md
@@ -3,7 +3,7 @@
 ### Supported hardware
 
 Marlin supports HD44780 character LCD and 128x64 graphical LCD via U8GLIB.
-Because of the limitation of HD44780 hardware, Marlin can only support three
+Because of the limitation of HD44780 hardwares, Marlin can only support three
 character sets for that hardware:
 Japanese (kana_utf8), Russian/Cyrillic (ru), or Western (Roman characters)
 
@@ -61,18 +61,19 @@ ln -s u8glib-master/tools/font/bdf2u8g/bdf2u8g
 ```
 
 The 'genallfont.sh' script will generate the font data for all of the
-language translation files. You may edit the script to change the variable
-LANGS to the list of languages you want to process. For example:
+language translation files.
+
+You may specify the language list you want to process. For example:
 
 ```bash
-LANGS="zh_TW"
+MARLIN_LANGS="zh_CN zh_TW"
 ```
 
-and then run the script to generate the font data (`language_data_xx.h`):
+and run the script to generate the font data (`language_data_xx.h`):
 
 ```bash
 cd marlin-git/Marlin/
-../buildroot/share/fonts/genallfont.sh
+MARLIN_LANGS="zh_CN zh_TW" ../buildroot/share/fonts/genallfont.sh
 ```
 
 3. Change the language settings
@@ -108,6 +109,9 @@ example, your new font file name is `newfont.bdf`, then run the following comman
 ```bash
 cd Marlin/
 ../buildroot/share/fonts/genallfont.sh ./newfont.bdf
+
+# OR if you just want to regenerate the language font data for a specific language:
+MARLIN_LANGS="zh_TW" ../buildroot/share/fonts/genallfont.sh ./newfont.bdf
 ```
 
 ### Suggestions for Maintainers
diff --git a/buildroot/share/fonts/uxggenpages.sh b/buildroot/share/fonts/uxggenpages.sh
index 55d2c7f012..b98595472f 100755
--- a/buildroot/share/fonts/uxggenpages.sh
+++ b/buildroot/share/fonts/uxggenpages.sh
@@ -143,7 +143,7 @@ grep -Hrn _UxGT . | grep '"' | \
   while read PAGE BEGIN END UTF8BEGIN UTF8END; do \
     if [ ! -f ${DN_DATA}/fontpage_${PAGE}_${BEGIN}_${END}.h ]; then \
       ${EXEC_BDF2U8G} -u ${PAGE} -b ${BEGIN} -e ${END} ${FN_FONT} fontpage_${PAGE}_${BEGIN}_${END} ${DN_DATA}/fontpage_${PAGE}_${BEGIN}_${END}.h > /dev/null 2>&1 ;
-      #sed -i 's|#include "u8g.h"|#include "utility/u8g.h"|' ${DN_DATA}/fontpage_${PAGE}_${BEGIN}_${END}.h ;
+      #sed -i 's|#include "u8g.h"|#include <clib/u8g.h>|' ${DN_DATA}/fontpage_${PAGE}_${BEGIN}_${END}.h ;
     fi ;\
     grep -A 10000000000 u8g_fntpgm_uint8_t ${DN_DATA}/fontpage_${PAGE}_${BEGIN}_${END}.h >> tmpa ;\
     echo "    FONTDATA_ITEM(${PAGE}, ${BEGIN}, ${END}, fontpage_${PAGE}_${BEGIN}_${END}), // '${UTF8BEGIN}' -- '${UTF8END}'" >> tmpb ;\
-- 
GitLab