Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use UTF-strlen() if the text is not UTF #4281

Merged
merged 2 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Marlin/language_an.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_AN_H
#define LANGUAGE_AN_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_ca.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_CA_H
#define LANGUAGE_CA_H

//#define MAPPER_NON
#define MAPPER_C2C3 // because of "ó"
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
Expand Down
2 changes: 0 additions & 2 deletions Marlin/language_cn.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
*/
#ifndef LANGUAGE_CN_H
#define LANGUAGE_CN_H

#define MAPPER_NON // For direct ascii codes
#define DISPLAY_CHARSET_ISO10646_CN

#define WELCOME_MSG "\xa4\xa5\xa6\xa7"
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_cz.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#ifndef LANGUAGE_CZ_H
#define LANGUAGE_CZ_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
4 changes: 0 additions & 4 deletions Marlin/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
#define DISPLAY_CHARSET_ISO10646_1 // use the better font on full graphic displays.
#endif

#if DISABLED(MAPPER_NON) && DISABLED(MAPPER_C2C3) && DISABLED(MAPPER_D0D1) && DISABLED(MAPPER_D0D1_MOD) && DISABLED(MAPPER_E382E383) && DISABLED(MAPPER_CECF)
#define MAPPER_NON // For direct ascii codes
#endif

#ifndef WELCOME_MSG
#define WELCOME_MSG MACHINE_NAME " ready."
#endif
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_es.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_ES_H
#define LANGUAGE_ES_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_eu.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_EU_H
#define LANGUAGE_EU_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_FR_H
#define LANGUAGE_FR_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_hr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_HR_H
#define LANGUAGE_HR_H

#define MAPPER_NON

// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_IT_H
#define LANGUAGE_IT_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_kana.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#ifndef LANGUAGE_KANA_H
#define LANGUAGE_KANA_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_KANA
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_nl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_NL_H
#define LANGUAGE_NL_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_pl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_PL_H
#define LANGUAGE_PL_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_pt-br.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_PT_BR_H
#define LANGUAGE_PT_BR_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_pt-br_utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_PT_BR_UTF_H
#define LANGUAGE_PT_BR_UTF_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_PT_H
#define LANGUAGE_PT_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
1 change: 0 additions & 1 deletion Marlin/language_pt_utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef LANGUAGE_PT_UTF_H
#define LANGUAGE_PT_UTF_H

#define MAPPER_NON
// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
#define DISPLAY_CHARSET_ISO10646_1
Expand Down
3 changes: 1 addition & 2 deletions Marlin/language_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@
// Kanji (an other Japanese symbol set) uses far more than two codepages. So currently I don't see a chance to map the Unicodes. Its not
// impossible to have a close to direct mapping but will need giant conversion tables and fonts (we don't want to have in a embedded system).


#define MAPPER_NON // For direct ascii codes ( until now all languages except ru, de, fi, kana_utf8, ... )
//#define MAPPER_C2C3 // For most European languages when language file is in utf8
//#define MAPPER_D0D1 // For Cyrillic
//#define MAPPER_E382E383 // For Katakana
//#define MAPPER_NON // For direct ascii codes. Fall back mapper - if no other is defined.

// Define SIMULATE_ROMFONT to see what is seen on the character based display defined in Configuration.h
//#define SIMULATE_ROMFONT
Expand Down
12 changes: 10 additions & 2 deletions Marlin/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2481,7 +2481,11 @@ void lcd_init() {
int lcd_strlen(const char* s) {
int i = 0, j = 0;
while (s[i]) {
if ((s[i] & 0xc0) != 0x80) j++;
#ifdef MAPPER_NON
j++;
#else
if ((s[i] & 0xc0) != 0x80) j++;
#endif
i++;
}
return j;
Expand All @@ -2490,7 +2494,11 @@ int lcd_strlen(const char* s) {
int lcd_strlen_P(const char* s) {
int j = 0;
while (pgm_read_byte(s)) {
if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
#ifdef MAPPER_NON
j++;
#else
if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
#endif
s++;
}
return j;
Expand Down
18 changes: 8 additions & 10 deletions Marlin/utf_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,7 @@
#endif // DISPLAY_CHARSET_HD44780
#endif // SIMULATE_ROMFONT

#if ENABLED(MAPPER_NON)

char charset_mapper(char c) {
HARDWARE_CHAR_OUT( c );
return 1;
}

#elif ENABLED(MAPPER_C2C3)
#if ENABLED(MAPPER_C2C3)

char charset_mapper(char c) {
static uint8_t utf_hi_char; // UTF-8 high part
Expand Down Expand Up @@ -353,8 +346,13 @@

#else

#error "You have to define one of the DISPLAY_INPUT_CODE_MAPPERs in your language_xx.h file" // should not occur because (en) will set.
#define MAPPER_NON

char charset_mapper(char c) {
HARDWARE_CHAR_OUT( c );
return 1;
}

#endif // code mappers
#endif // code mappers

#endif // UTF_MAPPER_H