Initial commit
This commit is contained in:
302670
buildroot/share/fonts/NanumGothic.bdf
Normal file
302670
buildroot/share/fonts/NanumGothic.bdf
Normal file
File diff suppressed because it is too large
Load Diff
21
buildroot/share/fonts/README.md
Normal file
21
buildroot/share/fonts/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Marlin fonts
|
||||
|
||||
## Author and license
|
||||
The original author of the following font files is [A. Hardtung](https://github.com/AnHardt).
|
||||
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
https://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
- HD44780_C.fon ([fe2bd23](https://github.com/MarlinFirmware/Marlin/commit/fe2bd237d556439499dfdee852c1550c7a16430a))
|
||||
- HD44780_J.fon ([fe2bd23](https://github.com/MarlinFirmware/Marlin/commit/fe2bd237d556439499dfdee852c1550c7a16430a))
|
||||
- HD44780_W.fon ([fe2bd23](https://github.com/MarlinFirmware/Marlin/commit/fe2bd237d556439499dfdee852c1550c7a16430a))
|
||||
- ISO10646-1.fon ([be79235](https://github.com/MarlinFirmware/Marlin/commit/be79235ef255a5c42fd385820447ec351f23b9b1))
|
||||
- ISO10646_5_Cyrillic.fon ([fe2bd23](https://github.com/MarlinFirmware/Marlin/commit/fe2bd237d556439499dfdee852c1550c7a16430a))
|
||||
- ISO10646_CN.fon ([6b1b718](https://github.com/MarlinFirmware/Marlin/commit/6b1b71837c98ceab55db7433357a13cd829d1ede))
|
||||
- ISO10646_Kana.fon ([fe2bd23](https://github.com/MarlinFirmware/Marlin/commit/fe2bd237d556439499dfdee852c1550c7a16430a))
|
||||
- Marlin_symbols.fon ([fe2bd23](https://github.com/MarlinFirmware/Marlin/commit/fe2bd237d556439499dfdee852c1550c7a16430a))
|
||||
|
||||
Additional changes to the original font files distributed with Marlin are copyrighted under the terms of the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.txt) license.
|
||||
|
||||
## Documentation
|
||||
For detailed information about adding new fonts to Marlin [see this article](https://marlinfw.org/docs/development/fonts.html).
|
15
buildroot/share/fonts/bdf2u8g/Makefile
Normal file
15
buildroot/share/fonts/bdf2u8g/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CFLAGS = -g -Wall
|
||||
#CFLAGS = -O4 -Wall
|
||||
|
||||
SRC = bdf2u8g.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
bdf2u8g: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o bdf2u8g.exe
|
||||
|
||||
clean:
|
||||
-rm $(OBJ) bdf2u8g.exe
|
||||
|
||||
test:
|
||||
./bdf2u8g.exe -f 2 ../bdf/9x18.bdf u8g_aafont_9x18 u8g_aafont_9x18.c
|
1214
buildroot/share/fonts/bdf2u8g/bdf2u8g.c
Normal file
1214
buildroot/share/fonts/bdf2u8g/bdf2u8g.c
Normal file
File diff suppressed because it is too large
Load Diff
64
buildroot/share/fonts/buildhzk.py
Normal file
64
buildroot/share/fonts/buildhzk.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# Generate a 'HZK' font file for the T5UIC1 DWIN LCD
|
||||
# from multiple bdf font files.
|
||||
# Note: the 16x16 glyphs are not produced
|
||||
# Author: Taylor Talkington
|
||||
# License: GPL
|
||||
|
||||
import bdflib.reader
|
||||
import math
|
||||
|
||||
def glyph_bits(size_x, size_y, font, glyph_ord):
|
||||
asc = font[b'FONT_ASCENT']
|
||||
desc = font[b'FONT_DESCENT']
|
||||
bits = [0 for y in range(size_y)]
|
||||
|
||||
glyph_bytes = math.ceil(size_x / 8)
|
||||
try:
|
||||
glyph = font[glyph_ord]
|
||||
for y, row in enumerate(glyph.data):
|
||||
v = row
|
||||
rpad = size_x - glyph.bbW
|
||||
if rpad < 0: rpad = 0
|
||||
if glyph.bbW > size_x: v = v >> (glyph.bbW - size_x) # some glyphs are actually too wide to fit!
|
||||
v = v << (glyph_bytes * 8) - size_x + rpad
|
||||
v = v >> glyph.bbX
|
||||
bits[y + desc + glyph.bbY] |= v
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
bits.reverse()
|
||||
return bits
|
||||
|
||||
def marlin_font_hzk():
|
||||
fonts = [
|
||||
[6,12,'marlin-6x12-3.bdf'],
|
||||
[8,16,'marlin-8x16.bdf'],
|
||||
[10,20,'marlin-10x20.bdf'],
|
||||
[12,24,'marlin-12x24.bdf'],
|
||||
[14,28,'marlin-14x28.bdf'],
|
||||
[16,32,'marlin-16x32.bdf'],
|
||||
[20,40,'marlin-20x40.bdf'],
|
||||
[24,48,'marlin-24x48.bdf'],
|
||||
[28,56,'marlin-28x56.bdf'],
|
||||
[32,64,'marlin-32x64.bdf']
|
||||
]
|
||||
|
||||
with open('marlin_fixed.hzk','wb') as output:
|
||||
for f in fonts:
|
||||
with open(f[2], 'rb') as file:
|
||||
print(f'{f[0]}x{f[1]}')
|
||||
font = bdflib.reader.read_bdf(file)
|
||||
for glyph in range(128):
|
||||
bits = glyph_bits(f[0], f[1], font, glyph)
|
||||
glyph_bytes = math.ceil(f[0]/8)
|
||||
|
||||
for b in bits:
|
||||
try:
|
||||
z = b.to_bytes(glyph_bytes, 'big')
|
||||
output.write(z)
|
||||
except OverflowError:
|
||||
print('Overflow')
|
||||
print(f'{glyph}')
|
||||
print(font[glyph])
|
||||
for b in bits: print(f'{b:0{f[0]}b}')
|
||||
return
|
143
buildroot/share/fonts/genallfont.sh
Executable file
143
buildroot/share/fonts/genallfont.sh
Executable file
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#####################################################################
|
||||
# genallfont.sh for Marlin
|
||||
#
|
||||
# This script generates font data for language headers
|
||||
#
|
||||
# Copyright 2015-2018 Yunhui Fu <yhfudev@gmail.com>
|
||||
# License: GPL/BSD
|
||||
#####################################################################
|
||||
my_getpath() {
|
||||
local PARAM_DN="$1"
|
||||
shift
|
||||
#readlink -f
|
||||
local DN="${PARAM_DN}"
|
||||
local FN=
|
||||
if [ ! -d "${DN}" ]; then
|
||||
FN=$(basename "${DN}")
|
||||
DN=$(dirname "${DN}")
|
||||
fi
|
||||
cd "${DN}" > /dev/null 2>&1
|
||||
DN=$(pwd)
|
||||
cd - > /dev/null 2>&1
|
||||
echo -n "${DN}"
|
||||
[[ -z "$FN" ]] || echo -n "/${FN}"
|
||||
}
|
||||
|
||||
DN_EXEC=$(dirname $(my_getpath "$0") )
|
||||
|
||||
#
|
||||
# Get language arguments
|
||||
#
|
||||
LANG_ARG="$@"
|
||||
|
||||
#
|
||||
# Use 6x12 combined font data for Western languages
|
||||
#
|
||||
FN_FONT="${DN_EXEC}/marlin-6x12-3.bdf"
|
||||
|
||||
#
|
||||
# Change to working directory 'Marlin'
|
||||
#
|
||||
OLDWD=`pwd`
|
||||
[[ $(basename "$OLDWD") != 'Marlin' && -d "Marlin" ]] && cd Marlin
|
||||
[[ -f "Configuration.h" ]] || { echo -n "cd to the 'Marlin' folder to run " ; basename $0 ; exit 1; }
|
||||
|
||||
#
|
||||
# Compile the 'genpages.exe' and 'bdf2u8g.exe' commands in-place
|
||||
#
|
||||
if [[ ! -x "${DN_EXEC}/genpages/genpages.exe" ]]; then
|
||||
echo "Building genpages.exe..."
|
||||
( cd ${DN_EXEC}/genpages ; cc -o genpages.exe genpages.c getline.c )
|
||||
[[ -x "${DN_EXEC}/genpages/genpages.exe" ]] || { echo "Build of genpages.exe failed" ; exit 1 ; }
|
||||
fi
|
||||
|
||||
if [[ ! -x "${DN_EXEC}/bdf2u8g/bdf2u8g.exe" ]]; then
|
||||
echo "Building bdf2u8g.exe..."
|
||||
( cd ${DN_EXEC}/bdf2u8g ; make )
|
||||
[[ -x "${DN_EXEC}/bdf2u8g/bdf2u8g.exe" ]] || { echo "Build of bdf2u8g.exe failed" ; exit 1 ; }
|
||||
fi
|
||||
|
||||
#
|
||||
# By default loop through all languages
|
||||
#
|
||||
LANGS_DEFAULT="an bg ca cz da de el el_CY en es eu fi fr 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"
|
||||
|
||||
#
|
||||
# Generate data for language list MARLIN_LANGS or all if not provided
|
||||
#
|
||||
for ALANG in ${LANG_ARG:=$LANGS_DEFAULT} ; do
|
||||
echo "Generating Marlin language data for '${ALANG}'" >&2
|
||||
case "$ALANG" in
|
||||
zh_* ) FONTFILE="wenquanyi_12pt" ;;
|
||||
ko_* ) FONTFILE="${DN_EXEC}/NanumGothic.bdf" ;;
|
||||
* ) FONTFILE="${DN_EXEC}/marlin-6x12-3.bdf" ;;
|
||||
esac
|
||||
DN_WORK=$(mktemp -d)
|
||||
cp Configuration.h ${DN_WORK}/
|
||||
cp src/lcd/language/language_${ALANG}.h ${DN_WORK}/
|
||||
cd "${DN_WORK}"
|
||||
${DN_EXEC}/uxggenpages.sh "${FONTFILE}" $ALANG
|
||||
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
|
||||
cd - >/dev/null
|
||||
mv ${DN_WORK}/fontutf8-data.h src/lcd/dogm/fontdata/langdata_${ALANG}.h
|
||||
rm -rf ${DN_WORK}
|
||||
done
|
||||
|
||||
#
|
||||
# Generate default ASCII font (char range 0-255):
|
||||
# Marlin/src/lcd/dogm/fontdata/fontdata_ISO10646_1.h
|
||||
#
|
||||
EXEC_BDF2U8G="${DN_EXEC}/bdf2u8g/bdf2u8g.exe"
|
||||
#if [ "${MARLIN_LANGS}" == "${LANGS_DEFAULT}" ]; then
|
||||
if [ 1 = 1 ]; then
|
||||
DN_WORK=$(mktemp -d)
|
||||
cd ${DN_WORK}
|
||||
${EXEC_BDF2U8G} -b 1 -e 127 ${FN_FONT} ISO10646_1_5x7 tmp1.h >/dev/null
|
||||
${EXEC_BDF2U8G} -b 1 -e 255 ${FN_FONT} ISO10646_1_5x7 tmp2.h >/dev/null
|
||||
TMP1=$(cat tmp1.h)
|
||||
TMP2=$(cat tmp2.h)
|
||||
cd - >/dev/null
|
||||
rm -rf ${DN_WORK}
|
||||
|
||||
cat <<EOF >src/lcd/dogm/fontdata/fontdata_ISO10646_1.h
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <U8glib-HAL.h>
|
||||
|
||||
#if defined(__AVR__) && ENABLED(NOT_EXTENDED_ISO10646_1_5X7)
|
||||
// reduced font (only symbols 1 - 127) - saves about 1278 bytes of FLASH
|
||||
|
||||
$TMP1
|
||||
#else
|
||||
// extended (original) font (symbols 1 - 255)
|
||||
|
||||
$TMP2
|
||||
|
||||
#endif
|
||||
EOF
|
||||
|
||||
fi
|
||||
|
||||
cd "$OLDWD"
|
193
buildroot/share/fonts/genpages/genpages.c
Normal file
193
buildroot/share/fonts/genpages/genpages.c
Normal file
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* @file genpages.c
|
||||
* @brief generate required font page files
|
||||
* @author Yunhui Fu (yhfudev@gmail.com)
|
||||
* @version 1.0
|
||||
* @date 2015-02-19
|
||||
* @copyright Yunhui Fu (2015)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h> /* uint8_t */
|
||||
#include <stdlib.h> /* size_t */
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "getline.h"
|
||||
|
||||
wchar_t get_val_utf82uni(uint8_t *pstart) {
|
||||
size_t cntleft;
|
||||
wchar_t retval = 0;
|
||||
|
||||
if (0 == (0x80 & *pstart)) return *pstart;
|
||||
|
||||
if (((*pstart & 0xE0) ^ 0xC0) == 0) {
|
||||
cntleft = 1;
|
||||
retval = *pstart & ~0xE0;
|
||||
}
|
||||
else if (((*pstart & 0xF0) ^ 0xE0) == 0) {
|
||||
cntleft = 2;
|
||||
retval = *pstart & ~0xF0;
|
||||
}
|
||||
else if (((*pstart & 0xF8) ^ 0xF0) == 0) {
|
||||
cntleft = 3;
|
||||
retval = *pstart & ~0xF8;
|
||||
}
|
||||
else if (((*pstart & 0xFC) ^ 0xF8) == 0) {
|
||||
cntleft = 4;
|
||||
retval = *pstart & ~0xFC;
|
||||
}
|
||||
else if (((*pstart & 0xFE) ^ 0xFC) == 0) {
|
||||
cntleft = 5;
|
||||
retval = *pstart & ~0xFE;
|
||||
}
|
||||
else {
|
||||
/* encoding error */
|
||||
cntleft = 0;
|
||||
retval = 0;
|
||||
}
|
||||
pstart++;
|
||||
for (; cntleft > 0; cntleft --) {
|
||||
retval <<= 6;
|
||||
retval |= *pstart & 0x3F;
|
||||
pstart++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 转换 UTF-8 编码的一个字符为本地的 Unicode 字符(wchar_t)
|
||||
*
|
||||
* @param pstart : 存储 UTF-8 字符的指针
|
||||
* @param pval : 需要返回的 Unicode 字符存放地址指针
|
||||
*
|
||||
* @return 成功返回下个 UTF-8 字符的位置
|
||||
*
|
||||
* 转换 UTF-8 编码的一个字符为本地的 Unicode 字符(wchar_t)
|
||||
*/
|
||||
uint8_t* get_utf8_value(uint8_t *pstart, wchar_t *pval) {
|
||||
uint32_t val = 0;
|
||||
uint8_t *p = pstart;
|
||||
/*size_t maxlen = strlen(pstart);*/
|
||||
|
||||
assert(NULL != pstart);
|
||||
|
||||
#define NEXT_6_BITS() do{ val <<= 6; p++; val |= (*p & 0x3F); }while(0)
|
||||
|
||||
if (0 == (0x80 & *p)) {
|
||||
val = (size_t)*p;
|
||||
p++;
|
||||
}
|
||||
else if (0xC0 == (0xE0 & *p)) {
|
||||
val = *p & 0x1F;
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0xE0 == (0xF0 & *p)) {
|
||||
val = *p & 0x0F;
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0xF0 == (0xF8 & *p)) {
|
||||
val = *p & 0x07;
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0xF8 == (0xFC & *p)) {
|
||||
val = *p & 0x03;
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0xFC == (0xFE & *p)) {
|
||||
val = *p & 0x01;
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
NEXT_6_BITS();
|
||||
p++;
|
||||
assert((wchar_t)val == get_val_utf82uni(pstart));
|
||||
}
|
||||
else if (0x80 == (0xC0 & *p)) {
|
||||
/* error? */
|
||||
for (; 0x80 == (0xC0 & *p); p++);
|
||||
}
|
||||
else {
|
||||
/* error */
|
||||
for (; ((0xFE & *p) > 0xFC); p++);
|
||||
}
|
||||
/*
|
||||
if (val == 0) {
|
||||
p = NULL;
|
||||
*/
|
||||
/*
|
||||
}
|
||||
else if (pstart + maxlen < p) {
|
||||
p = pstart;
|
||||
if (pval) *pval = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
if (pval) *pval = val;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void usage(char *progname) {
|
||||
fprintf(stderr, "usage: %s\n", progname);
|
||||
fprintf(stderr, " read data from stdin\n");
|
||||
}
|
||||
|
||||
void utf8_parse(const char *msg, unsigned int len) {
|
||||
uint8_t *pend = NULL;
|
||||
uint8_t *p;
|
||||
uint8_t *pre;
|
||||
wchar_t val;
|
||||
int page;
|
||||
|
||||
pend = (uint8_t *)msg + len;
|
||||
for (pre = (uint8_t *)msg; pre < pend;) {
|
||||
val = 0;
|
||||
p = get_utf8_value(pre, &val);
|
||||
if (NULL == p) break;
|
||||
page = val / 128;
|
||||
if (val >= 256) {
|
||||
fprintf(stdout, "%d %d ", page, (val % 128));
|
||||
for (; pre < p; pre++) fprintf(stdout, "%c", *pre);
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
pre = p;
|
||||
}
|
||||
}
|
||||
|
||||
int load_file(FILE *fp) {
|
||||
char * buffer = NULL;
|
||||
size_t szbuf = 0;
|
||||
|
||||
szbuf = 10000;
|
||||
buffer = (char*)malloc(szbuf);
|
||||
if (NULL == buffer) return -1;
|
||||
//pos = ftell (fp);
|
||||
while (getline( &buffer, &szbuf, fp ) > 0)
|
||||
utf8_parse((const char*)buffer, (unsigned int)strlen ((char *)buffer));
|
||||
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
if (argc > 1) {
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
load_file(stdin);
|
||||
}
|
126
buildroot/share/fonts/genpages/getline.c
Normal file
126
buildroot/share/fonts/genpages/getline.c
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* getline.c --- Based on...
|
||||
*
|
||||
* getdelim.c --- Implementation of replacement getdelim function.
|
||||
* Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005 Free
|
||||
* Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/* Ported from glibc by Simon Josefsson. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !HAVE_GETLINE
|
||||
|
||||
//#include "getdelim.h"
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
#ifndef SSIZE_MAX
|
||||
#define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
|
||||
#endif
|
||||
#if !HAVE_FLOCKFILE
|
||||
#undef flockfile
|
||||
#define flockfile(x) ((void)0)
|
||||
#endif
|
||||
#if !HAVE_FUNLOCKFILE
|
||||
#undef funlockfile
|
||||
#define funlockfile(x) ((void)0)
|
||||
#endif
|
||||
|
||||
/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
|
||||
NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
|
||||
NULL), pointing to *N characters of space. It is realloc'ed as
|
||||
necessary. Returns the number of characters read (not including
|
||||
the null terminator), or -1 on error or EOF. */
|
||||
|
||||
ssize_t
|
||||
getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) {
|
||||
ssize_t result;
|
||||
size_t cur_len = 0;
|
||||
|
||||
if (lineptr == NULL || n == NULL || fp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
flockfile (fp);
|
||||
|
||||
if (*lineptr == NULL || *n == 0) {
|
||||
*n = 120;
|
||||
*lineptr = (char *) malloc(*n);
|
||||
if (*lineptr == NULL) {
|
||||
result = -1;
|
||||
goto unlock_return;
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int i;
|
||||
|
||||
i = getc(fp);
|
||||
if (i == EOF) {
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Make enough space for len+1 (for final NUL) bytes. */
|
||||
if (cur_len + 1 >= *n) {
|
||||
size_t needed_max =
|
||||
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
|
||||
size_t needed = 2 * *n + 1; /* Be generous. */
|
||||
char *new_lineptr;
|
||||
|
||||
if (needed_max < needed)
|
||||
needed = needed_max;
|
||||
if (cur_len + 1 >= needed) {
|
||||
result = -1;
|
||||
goto unlock_return;
|
||||
}
|
||||
|
||||
new_lineptr = (char *) realloc (*lineptr, needed);
|
||||
if (new_lineptr == NULL) {
|
||||
result = -1;
|
||||
goto unlock_return;
|
||||
}
|
||||
|
||||
*lineptr = new_lineptr;
|
||||
*n = needed;
|
||||
}
|
||||
|
||||
(*lineptr)[cur_len] = i;
|
||||
cur_len++;
|
||||
|
||||
if (i == delimiter) break;
|
||||
}
|
||||
(*lineptr)[cur_len] = '\0';
|
||||
result = cur_len ? (int) cur_len : (int) result;
|
||||
|
||||
unlock_return:
|
||||
funlockfile(fp);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
12
buildroot/share/fonts/genpages/getline.h
Normal file
12
buildroot/share/fonts/genpages/getline.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef MYGETLINE_H
|
||||
#define MYGETLINE_H
|
||||
|
||||
//#include "config.h"
|
||||
|
||||
#if !HAVE_GETLINE
|
||||
#include <stdio.h>
|
||||
ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);
|
||||
#define getline(lineptr, n, stream) getdelim (lineptr, n, '\n', stream)
|
||||
#endif
|
||||
|
||||
#endif // MYGETLINE_H
|
39
buildroot/share/fonts/make_lang_na.sh
Executable file
39
buildroot/share/fonts/make_lang_na.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# make_lang_na.sh
|
||||
#
|
||||
# Create non-accented language files given a list of accented language files.
|
||||
#
|
||||
|
||||
which gsed >/dev/null || { echo "gsed is required for this script." ; exit 1 ; }
|
||||
which perl >/dev/null || { echo "perl is required for this script." ; exit 1 ; }
|
||||
|
||||
#
|
||||
# Get language arguments
|
||||
#
|
||||
[ $# ] || { echo "One or more language codes (such as 'fr') must be supplied." ; exit 1 ; }
|
||||
|
||||
LANG_ARG="$@"
|
||||
|
||||
#
|
||||
# Change to working directory 'Marlin'
|
||||
#
|
||||
OLDWD=`pwd`
|
||||
[[ $(basename "$OLDWD") != 'Marlin' && -d "Marlin" ]] && cd Marlin
|
||||
[[ -f "Configuration.h" ]] || { echo -n "cd to the 'Marlin' folder to run " ; basename $0 ; exit 1; }
|
||||
|
||||
#
|
||||
# Generate a non-accented language file
|
||||
#
|
||||
for ALANG in $LANG_ARG ; do
|
||||
echo "Generating a non-accented language for '${ALANG}'" >&2
|
||||
OUTFILE=src/lcd/language/language_${ALANG}_na.h
|
||||
cp src/lcd/language/language_${ALANG}.h $OUTFILE
|
||||
perl -pi -e 's/\s*#define DISPLAY_CHARSET_.+\n*//g' $OUTFILE
|
||||
perl -pi -e 's/\s*constexpr .+ CHARSIZE.+\n*//g' $OUTFILE
|
||||
perl -pi -e "s/namespace Language_${ALANG}/#define DISPLAY_CHARSET_ISO10646_1\n#define NOT_EXTENDED_ISO10646_1_5X7\n\nnamespace Language_${ALANG}_na/" $OUTFILE
|
||||
gsed -i 'y/āáǎàâäēéěèêīíǐìïîōóǒòöôūúǔùǖǘǚǜüûĀÁǍÀĒÉĚÈÊĪÍǏÌÎŌÓǑÒÔŪÚǓÙǕǗǙǛÜÛÇçÑñ/aaaaaaeeeeeiiiiiioooooouuuuuuuuuuAAAAEEEEEIIIIIOOOOOUUUUUUUUUUCcNn/' $OUTFILE
|
||||
perl -pi -e 's/ß/ss/g' $OUTFILE
|
||||
done
|
||||
|
||||
cd "$OLDWD"
|
4104
buildroot/share/fonts/marlin-10x20.bdf
Normal file
4104
buildroot/share/fonts/marlin-10x20.bdf
Normal file
File diff suppressed because it is too large
Load Diff
4558
buildroot/share/fonts/marlin-12x24.bdf
Normal file
4558
buildroot/share/fonts/marlin-12x24.bdf
Normal file
File diff suppressed because it is too large
Load Diff
5078
buildroot/share/fonts/marlin-14x28.bdf
Normal file
5078
buildroot/share/fonts/marlin-14x28.bdf
Normal file
File diff suppressed because it is too large
Load Diff
5492
buildroot/share/fonts/marlin-16x32.bdf
Normal file
5492
buildroot/share/fonts/marlin-16x32.bdf
Normal file
File diff suppressed because it is too large
Load Diff
6458
buildroot/share/fonts/marlin-20x40.bdf
Normal file
6458
buildroot/share/fonts/marlin-20x40.bdf
Normal file
File diff suppressed because it is too large
Load Diff
6462
buildroot/share/fonts/marlin-24x48.bdf
Normal file
6462
buildroot/share/fonts/marlin-24x48.bdf
Normal file
File diff suppressed because it is too large
Load Diff
7311
buildroot/share/fonts/marlin-28x56.bdf
Normal file
7311
buildroot/share/fonts/marlin-28x56.bdf
Normal file
File diff suppressed because it is too large
Load Diff
9870
buildroot/share/fonts/marlin-32x64.bdf
Normal file
9870
buildroot/share/fonts/marlin-32x64.bdf
Normal file
File diff suppressed because it is too large
Load Diff
64283
buildroot/share/fonts/marlin-6x12-1.bdf
Normal file
64283
buildroot/share/fonts/marlin-6x12-1.bdf
Normal file
File diff suppressed because it is too large
Load Diff
65510
buildroot/share/fonts/marlin-6x12-2.bdf
Normal file
65510
buildroot/share/fonts/marlin-6x12-2.bdf
Normal file
File diff suppressed because it is too large
Load Diff
588241
buildroot/share/fonts/marlin-6x12-3.bdf
Normal file
588241
buildroot/share/fonts/marlin-6x12-3.bdf
Normal file
File diff suppressed because it is too large
Load Diff
16606
buildroot/share/fonts/marlin-6x9.bdf
Normal file
16606
buildroot/share/fonts/marlin-6x9.bdf
Normal file
File diff suppressed because it is too large
Load Diff
3701
buildroot/share/fonts/marlin-8x16.bdf
Normal file
3701
buildroot/share/fonts/marlin-8x16.bdf
Normal file
File diff suppressed because it is too large
Load Diff
110
buildroot/share/fonts/uxggenpages.md
Normal file
110
buildroot/share/fonts/uxggenpages.md
Normal file
@@ -0,0 +1,110 @@
|
||||
## Language engine and tools
|
||||
|
||||
### Supported hardware
|
||||
|
||||
Marlin supports HD44780 character LCD and 128x64 graphical LCD via U8GLIB. 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)
|
||||
|
||||
For the graphical LCD modules, there's far less limitation. Users and language maintainers can easily change the language translation strings when saved with UTF-8 encoding. The only extra step is to regenerate the font data from an existing BDF font file.
|
||||
|
||||
### How to support a new language?
|
||||
|
||||
1. Prepare the translation source file
|
||||
|
||||
You need to add a language header file `language_xx.h`, replacing xx with the language/country code. (e.g., "en" for English). You can start with a existing language file by copying it to a new location:
|
||||
|
||||
```bash
|
||||
cp language_zh_CN.h language_zh_TW.h
|
||||
```
|
||||
|
||||
Then simply replace the strings inside the `_UxGT()` macros.
|
||||
|
||||
Make sure the file is saved as UTF-8 encoded.
|
||||
|
||||
2. Generate the font data file
|
||||
|
||||
This step gathers the glyphs used in the language file from a 9pt bitmap font and saves the data in a language_data_xx.h file. So the font used for conversion should contain all the characters in your language file.
|
||||
|
||||
The default bitmap font is WQY's 9pt bitmap font.
|
||||
|
||||
Download from [here](http://wenq.org/daily/wqy-bitmapfont-bdf-gb18030-nightly_build.tar.gz), or to install in a Debian/Ubuntu system:
|
||||
|
||||
```
|
||||
sudo apt-get install xfonts-wqy
|
||||
```
|
||||
|
||||
You also need to compile the `bdf2u8g` binary to convert BDF font files into U8glib data structures:
|
||||
|
||||
```bash
|
||||
cd marlin-git/buildroot/share/fonts/
|
||||
./get-bdf2u8g.sh
|
||||
```
|
||||
|
||||
The `genallfont.sh` script generates font data for all language translation files.
|
||||
|
||||
You may specify a list of languages to process. For example:
|
||||
|
||||
```bash
|
||||
MARLIN_LANGS="zh_CN zh_TW"
|
||||
```
|
||||
|
||||
and run the script to generate the font data (`language_data_xx.h`):
|
||||
|
||||
```bash
|
||||
cd marlin-git/Marlin/
|
||||
MARLIN_LANGS="zh_CN zh_TW" ../buildroot/share/fonts/genallfont.sh
|
||||
```
|
||||
|
||||
3. Change the language settings
|
||||
|
||||
To compile Marlin with your language, choose a language in `Configuration.h`. For Chinese (Taiwan) you would use:
|
||||
|
||||
```cpp
|
||||
#define LCD_LANGUAGE zh_TW
|
||||
```
|
||||
|
||||
4. Compile and Upload the firmware
|
||||
|
||||
Open `Marlin.ino` in your IDE and compile the firmware. Once the build succeeds, upload it to your board.
|
||||
|
||||
### Update the language translation
|
||||
|
||||
Whenever language files are changed, you need to run the script `genallfont.sh` again to update the font data file.
|
||||
|
||||
### Use a cool font
|
||||
|
||||
You may need to use a different font to support your own language, because the default 9pt font is not complete. (You may also support them by adding the missing glyphs to the font.)
|
||||
|
||||
After you've prepared your font, specify the font file path as an argument to `genallfont.sh`, so that the font used for your language is your new font. For example, if your font is named `newfont.bdf` run the following command:
|
||||
|
||||
```bash
|
||||
cd Marlin/
|
||||
../buildroot/share/fonts/genallfont.sh ./newfont.bdf
|
||||
```
|
||||
|
||||
...or to regenerate the language font data for a specific language:
|
||||
|
||||
```bash
|
||||
MARLIN_LANGS="zh_TW" ../buildroot/share/fonts/genallfont.sh ./newfont.bdf
|
||||
```
|
||||
|
||||
### Suggestions for Maintainers
|
||||
|
||||
The tool and the language engine can be easily updated. Since it uses common bitmap font files and UTF-8 text, the maintainer needs to confirm that the font contains the glyphs in the language files.
|
||||
|
||||
At this time, the font file `marlin-6x12-3.bdf` is used to generate the font data. It combines all of Marlin's ISO10646-1 fonts and the WQY 9pt bitmap font.
|
||||
|
||||
### Related resources
|
||||
|
||||
#### Fonts
|
||||
|
||||
- [WQY](http://wenq.org/)
|
||||
- [WQY 9pt bitmap font](http://wenq.org/daily/wqy-bitmapfont-bdf-gb18030-nightly_build.tar.gz)
|
||||
- [unifont (16x8 or 16x16)](https://unifoundry.com/unifont.html)
|
||||
|
||||
Documents related to the old version of the language engine:
|
||||
|
||||
- [Marlin Fonts Documentation](https://www.marlinfw.org/docs/development/fonts.html)
|
||||
- [Marlin LCD Language](https://marlinfw.org/docs/development/lcd_language.html)
|
||||
- [U8GLIB](https://github.com/olikraus/u8glib.git)
|
||||
- [UTF-8 for U8GLIB](https://github.com/yhfudev/u8glib-fontutf8.git)
|
||||
- [Standalone test project for the Marlin UTF-8 language engine](https://github.com/yhfudev/marlin-fontutf8.git)
|
173
buildroot/share/fonts/uxggenpages.sh
Executable file
173
buildroot/share/fonts/uxggenpages.sh
Executable file
@@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#####################################################################
|
||||
# uxggenpages.sh for u8g
|
||||
#
|
||||
# This script will generate u8g c files for specified fonts
|
||||
#
|
||||
# Copyright 2015-2018 Yunhui Fu <yhfudev@gmail.com>
|
||||
# License: BSD
|
||||
#####################################################################
|
||||
|
||||
my_getpath() {
|
||||
local PARAM_DN="$1"
|
||||
shift
|
||||
|
||||
#readlink -f
|
||||
local DN="${PARAM_DN}"
|
||||
local FN=
|
||||
if [ ! -d "${DN}" ]; then
|
||||
FN=$(basename "${DN}")
|
||||
DN=$(dirname "${DN}")
|
||||
fi
|
||||
cd "${DN}" > /dev/null 2>&1
|
||||
DN=$(pwd)
|
||||
cd - > /dev/null 2>&1
|
||||
echo -n "${DN}"
|
||||
[[ -z "$FN" ]] || echo -n "/${FN}"
|
||||
}
|
||||
#DN_EXEC=`echo "$0" | ${EXEC_AWK} -F/ '{b=$1; for (i=2; i < NF; i ++) {b=b "/" $(i)}; print b}'`
|
||||
DN_EXEC=$(dirname $(my_getpath "$0") )
|
||||
|
||||
#####################################################################
|
||||
|
||||
EXEC_GENPAGES=${DN_EXEC}/genpages/genpages.exe
|
||||
[ -x "${EXEC_GENPAGES}" ] || { echo "Error: genpages not found!" ; exit 1; }
|
||||
|
||||
EXEC_BDF2U8G=${DN_EXEC}/bdf2u8g/bdf2u8g.exe
|
||||
[ -x "${EXEC_BDF2U8G}" ] || { echo "Error: bdf2u8g not found!" ; exit 1; }
|
||||
|
||||
DN_CUR=$(pwd)
|
||||
DN_DATA=$(pwd)/datatmp
|
||||
mkdir -p "${DN_DATA}"
|
||||
|
||||
#####################################################################
|
||||
|
||||
FONTHOME=/usr/share/fonts
|
||||
|
||||
FN_FONT_BASE="marlin-6x12-3"
|
||||
#FN_FONT_BASE=unifont
|
||||
#FN_FONT_BASE=wenquanyi_12pt
|
||||
#FN_FONT_BASE=wenquanyi_9pt
|
||||
|
||||
FN_FONT="${1:-}"
|
||||
LANG="$2"
|
||||
DN_FONT0=`dirname ${FN_FONT}`
|
||||
DN_FONT="$(my_getpath ${DN_FONT0})"
|
||||
FN_FONT="$(my_getpath "${DN_FONT}")/"`basename ${FN_FONT}`
|
||||
[ -z "${FN_FONT}" ] && FN_FONT=${DN_DATA}/../${FN_FONT_BASE}.bdf
|
||||
[ -f "${FN_FONT}" ] || FN_FONT=${DN_EXEC}/${FN_FONT_BASE}.bdf
|
||||
[ -f "${FN_FONT}" ] || FN_FONT="$FONTHOME/wenquanyi/${FN_FONT_BASE}.bdf"
|
||||
[ -f "${FN_FONT}" ] || FN_FONT="$FONTHOME/X11/misc/${FN_FONT_BASE}.bdf"
|
||||
[ -f "${FN_FONT}" ] || FN_FONT="$FONTHOME/misc/${FN_FONT_BASE}.bdf"
|
||||
#echo "uxggenpages.sh: FN_FONT=${FN_FONT}"
|
||||
|
||||
if [ ! -f "${FN_FONT}" ]; then
|
||||
FN_FONT_PCF="$FONTHOME/X11/misc/${FN_FONT_BASE}.pcf"
|
||||
[ -f "${FN_FONT_PCF}" ] || FN_FONT_PCF="$FONTHOME/misc/${FN_FONT_BASE}.pcf"
|
||||
[ -f "${FN_FONT_PCF}" ] || FN_FONT_PCF="$FONTHOME/wenquanyi/${FN_FONT_BASE}.pcf"
|
||||
if [ -f "${FN_FONT_PCF}" ]; then
|
||||
EXEC_PCF2BDF=$(which pcf2bdf)
|
||||
if [ ! -x "${EXEC_PCF2BDF}" ]; then
|
||||
echo "Error: not found pcf2bdf!"
|
||||
echo " Please install pcf2bdf."
|
||||
exit 1
|
||||
fi
|
||||
FN_FONT="./${FN_FONT_BASE}.bdf"
|
||||
echo ${EXEC_PCF2BDF} -o "${FN_FONT}" "${FN_FONT_PCF}"
|
||||
${EXEC_PCF2BDF} -o "${FN_FONT}" "${FN_FONT_PCF}"
|
||||
fi
|
||||
fi
|
||||
|
||||
[ -f "${FN_FONT}" ] || { echo "Error: can't find font ${FN_FONT}!" ; exit 1; }
|
||||
|
||||
#####################################################################
|
||||
|
||||
#(cd ${DN_EXEC}; gcc -o genpages genpages.c getline.c)
|
||||
|
||||
rm -f tmpa tmpb
|
||||
touch tmpa tmpb
|
||||
#rm -f ${DN_EXEC}/fontpage_*.h
|
||||
rm -f fontpage_*.h
|
||||
|
||||
cat << EOF >"proc.awk"
|
||||
BEGIN {
|
||||
cur_page=0;
|
||||
val_begin=0;
|
||||
val_pre=0;
|
||||
utf8_pre="";
|
||||
utf8_begin="";
|
||||
}{
|
||||
page=\$1;
|
||||
val_real=\$2;
|
||||
utf8=\$3;
|
||||
# assert (val_real < 128);
|
||||
val=val_real + 128;
|
||||
if (cur_page != page) {
|
||||
if (cur_page != 0) {
|
||||
if (val_begin != 0) {
|
||||
print cur_page " " val_begin " " val_pre " " utf8_begin " " utf8_pre;
|
||||
}
|
||||
}
|
||||
cur_page=page;
|
||||
val_begin=val;
|
||||
val_pre=val;
|
||||
utf8_begin=utf8;
|
||||
utf8_pre=utf8;
|
||||
} else {
|
||||
if (val_pre + 1 != val) {
|
||||
if (cur_page != 0) {
|
||||
print cur_page " " val_begin " " val_pre " " utf8_begin " " utf8_pre;
|
||||
}
|
||||
val_begin=val;
|
||||
val_pre=val;
|
||||
utf8_begin=utf8;
|
||||
utf8_pre=utf8;
|
||||
} else {
|
||||
val_pre = val;
|
||||
utf8_pre=utf8;
|
||||
}
|
||||
}
|
||||
} END {
|
||||
if (cur_page != 0) {
|
||||
print cur_page " " val_begin " " val_pre " " utf8_begin " " utf8_pre;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
AWK=$(which gawk || which awk)
|
||||
|
||||
grep -Hrn _UxGT . | grep '"' \
|
||||
| sed 's/_UxGT("/\n&/g;s/[^\n]*\n_UxGT("\([^"]*\)[^\n]*/\1 /g;s/.$//' \
|
||||
| ${EXEC_GENPAGES} \
|
||||
| sort -k 1n -k 2n | uniq \
|
||||
| "$AWK" -v EXEC_PREFIX=${DN_EXEC} -f "proc.awk" \
|
||||
| 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 ;
|
||||
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 ;\
|
||||
done
|
||||
|
||||
TMPA=$(cat tmpa)
|
||||
TMPB=$(cat tmpb)
|
||||
|
||||
EOL=$'\n'
|
||||
[[ ! "$TMPA" == "" ]] && TMPA="$TMPA$EOL$EOL"
|
||||
[[ ! "$TMPB" == "" ]] && TMPB="$EOL$TMPB$EOL"
|
||||
|
||||
rm -f tmpa tmpb "proc.awk"
|
||||
|
||||
cat <<EOF >fontutf8-data.h
|
||||
/**
|
||||
* Generated automatically by buildroot/share/fonts/uxggenpages.sh
|
||||
* Contents will be REPLACED by future processing!
|
||||
* Use genallfont.sh to generate font data for updated languages.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "langdata.h"
|
||||
|
||||
${TMPA}static const uxg_fontinfo_t g_fontinfo_${LANG}[] PROGMEM = {${TMPB}};
|
||||
EOF
|
Reference in New Issue
Block a user