Commit 713d9156 authored by Tianjie Xu's avatar Tianjie Xu Committed by Gerrit Code Review

Merge "Add the missing sr-Latn into png files and rename the png locale header"

parents 34df98ee 2078b22e
......@@ -28,7 +28,10 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \
libdrm \
libsync_recovery
LOCAL_STATIC_LIBRARIES := libpng
LOCAL_STATIC_LIBRARIES := \
libpng \
libbase
LOCAL_CFLAGS := -Werror
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
......@@ -61,7 +64,10 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libminui
LOCAL_WHOLE_STATIC_LIBRARIES += libminui
LOCAL_SHARED_LIBRARIES := libpng
LOCAL_SHARED_LIBRARIES := \
libpng \
libbase
LOCAL_CFLAGS := -Werror
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
......
......@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <functional>
#include <string>
//
// Graphics.
......@@ -93,7 +94,7 @@ int ev_get_epollfd();
// Resources
//
bool matches_locale(const char* prefix, const char* locale);
bool matches_locale(const std::string& prefix, const std::string& locale);
// res_create_*_surface() functions return 0 if no error, else
// negative.
......
......@@ -25,8 +25,11 @@
#include <sys/types.h>
#include <unistd.h>
#include <regex>
#include <string>
#include <vector>
#include <android-base/strings.h>
#include <png.h>
#include "minui/minui.h"
......@@ -371,16 +374,26 @@ int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
// This function tests if a locale string stored in PNG (prefix) matches
// the locale string provided by the system (locale).
bool matches_locale(const char* prefix, const char* locale) {
if (locale == nullptr) {
return false;
}
// Return true if the whole string of prefix matches the top part of
// locale. For instance, prefix == "en" matches locale == "en_US";
// and prefix == "zh_CN" matches locale == "zh_CN_#Hans".
return (strncmp(prefix, locale, strlen(prefix)) == 0);
bool matches_locale(const std::string& prefix, const std::string& locale) {
// According to the BCP 47 format, A locale string may consists of:
// language-{extlang}-{script}-{region}-{variant}
// The locale headers in PNG mostly consist of language-{region} except for sr-Latn, and some
// android's system locale can have the format language-{script}-{region}.
// Return true if the whole string of prefix matches the top part of locale. Otherwise try to
// match the locale string without the {script} section.
// For instance, prefix == "en" matches locale == "en-US", prefix == "sr-Latn" matches locale
// == "sr-Latn-BA", and prefix == "zh-CN" matches locale == "zh-Hans-CN".
if (android::base::StartsWith(locale, prefix.c_str())) {
return true;
}
size_t separator = prefix.find('-');
if (separator == std::string::npos) {
return false;
}
std::regex loc_regex(prefix.substr(0, separator) + "-[A-Za-z]*" + prefix.substr(separator));
return std::regex_match(locale, loc_regex);
}
int res_create_localized_alpha_surface(const char* name,
......
......@@ -122,7 +122,7 @@ static const int BATTERY_READ_TIMEOUT_IN_SEC = 10;
static const int BATTERY_OK_PERCENTAGE = 20;
static const int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
static constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe";
static constexpr const char* DEFAULT_LOCALE = "en_US";
static constexpr const char* DEFAULT_LOCALE = "en-US";
static std::string locale;
static bool has_cache = false;
......
res-hdpi/images/erasing_text.png

49.5 KB | W: | H:

res-hdpi/images/erasing_text.png

49 KB | W: | H:

res-hdpi/images/erasing_text.png
res-hdpi/images/erasing_text.png
res-hdpi/images/erasing_text.png
res-hdpi/images/erasing_text.png
  • 2-up
  • Swipe
  • Onion skin
res-hdpi/images/error_text.png

35.2 KB | W: | H:

res-hdpi/images/error_text.png

35 KB | W: | H:

res-hdpi/images/error_text.png
res-hdpi/images/error_text.png
res-hdpi/images/error_text.png
res-hdpi/images/error_text.png
  • 2-up
  • Swipe
  • Onion skin
res-hdpi/images/installing_text.png

102 KB | W: | H:

res-hdpi/images/installing_text.png

102 KB | W: | H:

res-hdpi/images/installing_text.png
res-hdpi/images/installing_text.png
res-hdpi/images/installing_text.png
res-hdpi/images/installing_text.png
  • 2-up
  • Swipe
  • Onion skin
res-hdpi/images/no_command_text.png

60.6 KB | W: | H:

res-hdpi/images/no_command_text.png

60 KB | W: | H:

res-hdpi/images/no_command_text.png
res-hdpi/images/no_command_text.png
res-hdpi/images/no_command_text.png
res-hdpi/images/no_command_text.png
  • 2-up
  • Swipe
  • Onion skin
res-mdpi/images/erasing_text.png

29.2 KB | W: | H:

res-mdpi/images/erasing_text.png

29 KB | W: | H:

res-mdpi/images/erasing_text.png
res-mdpi/images/erasing_text.png
res-mdpi/images/erasing_text.png
res-mdpi/images/erasing_text.png
  • 2-up
  • Swipe
  • Onion skin
res-mdpi/images/error_text.png

20.7 KB | W: | H:

res-mdpi/images/error_text.png

20.6 KB | W: | H:

res-mdpi/images/error_text.png
res-mdpi/images/error_text.png
res-mdpi/images/error_text.png
res-mdpi/images/error_text.png
  • 2-up
  • Swipe
  • Onion skin
res-mdpi/images/installing_text.png

60.3 KB | W: | H:

res-mdpi/images/installing_text.png

59.8 KB | W: | H:

res-mdpi/images/installing_text.png
res-mdpi/images/installing_text.png
res-mdpi/images/installing_text.png
res-mdpi/images/installing_text.png
  • 2-up
  • Swipe
  • Onion skin
res-mdpi/images/no_command_text.png

33.9 KB | W: | H:

res-mdpi/images/no_command_text.png

33.6 KB | W: | H:

res-mdpi/images/no_command_text.png
res-mdpi/images/no_command_text.png
res-mdpi/images/no_command_text.png
res-mdpi/images/no_command_text.png
  • 2-up
  • Swipe
  • Onion skin
res-xhdpi/images/erasing_text.png

71.6 KB | W: | H:

res-xhdpi/images/erasing_text.png

71.4 KB | W: | H:

res-xhdpi/images/erasing_text.png
res-xhdpi/images/erasing_text.png
res-xhdpi/images/erasing_text.png
res-xhdpi/images/erasing_text.png
  • 2-up
  • Swipe
  • Onion skin
res-xhdpi/images/error_text.png

50.8 KB | W: | H:

res-xhdpi/images/error_text.png

51 KB | W: | H:

res-xhdpi/images/error_text.png
res-xhdpi/images/error_text.png
res-xhdpi/images/error_text.png
res-xhdpi/images/error_text.png
  • 2-up
  • Swipe
  • Onion skin
res-xhdpi/images/installing_text.png

171 KB | W: | H:

res-xhdpi/images/installing_text.png

172 KB | W: | H:

res-xhdpi/images/installing_text.png
res-xhdpi/images/installing_text.png
res-xhdpi/images/installing_text.png
res-xhdpi/images/installing_text.png
  • 2-up
  • Swipe
  • Onion skin
res-xhdpi/images/no_command_text.png

84.6 KB | W: | H:

res-xhdpi/images/no_command_text.png

84.6 KB | W: | H:

res-xhdpi/images/no_command_text.png
res-xhdpi/images/no_command_text.png
res-xhdpi/images/no_command_text.png
res-xhdpi/images/no_command_text.png
  • 2-up
  • Swipe
  • Onion skin
res-xxhdpi/images/erasing_text.png

119 KB | W: | H:

res-xxhdpi/images/erasing_text.png

119 KB | W: | H:

res-xxhdpi/images/erasing_text.png
res-xxhdpi/images/erasing_text.png
res-xxhdpi/images/erasing_text.png
res-xxhdpi/images/erasing_text.png
  • 2-up
  • Swipe
  • Onion skin
res-xxhdpi/images/error_text.png

82.7 KB | W: | H:

res-xxhdpi/images/error_text.png

83 KB | W: | H:

res-xxhdpi/images/error_text.png
res-xxhdpi/images/error_text.png
res-xxhdpi/images/error_text.png
res-xxhdpi/images/error_text.png
  • 2-up
  • Swipe
  • Onion skin
res-xxxhdpi/images/erasing_text.png

258 KB | W: | H:

res-xxxhdpi/images/erasing_text.png

257 KB | W: | H:

res-xxxhdpi/images/erasing_text.png
res-xxxhdpi/images/erasing_text.png
res-xxxhdpi/images/erasing_text.png
res-xxxhdpi/images/erasing_text.png
  • 2-up
  • Swipe
  • Onion skin
res-xxxhdpi/images/error_text.png

173 KB | W: | H:

res-xxxhdpi/images/error_text.png

174 KB | W: | H:

res-xxxhdpi/images/error_text.png
res-xxxhdpi/images/error_text.png
res-xxxhdpi/images/error_text.png
res-xxxhdpi/images/error_text.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -19,14 +19,15 @@
#include "minui/minui.h"
TEST(LocaleTest, Misc) {
EXPECT_TRUE(matches_locale("zh_CN", "zh_CN_#Hans"));
EXPECT_TRUE(matches_locale("zh", "zh_CN_#Hans"));
EXPECT_FALSE(matches_locale("zh_HK", "zh_CN_#Hans"));
EXPECT_TRUE(matches_locale("en_GB", "en_GB"));
EXPECT_TRUE(matches_locale("en", "en_GB"));
EXPECT_FALSE(matches_locale("en_GB", "en"));
EXPECT_FALSE(matches_locale("en_GB", "en_US"));
EXPECT_FALSE(matches_locale("en_US", ""));
// Empty locale prefix in the PNG file will match the input locale.
EXPECT_TRUE(matches_locale("", "en_US"));
EXPECT_TRUE(matches_locale("zh-CN", "zh-Hans-CN"));
EXPECT_TRUE(matches_locale("zh", "zh-Hans-CN"));
EXPECT_FALSE(matches_locale("zh-HK", "zh-Hans-CN"));
EXPECT_TRUE(matches_locale("en-GB", "en-GB"));
EXPECT_TRUE(matches_locale("en", "en-GB"));
EXPECT_FALSE(matches_locale("en-GB", "en"));
EXPECT_FALSE(matches_locale("en-GB", "en-US"));
EXPECT_FALSE(matches_locale("en-US", ""));
// Empty locale prefix in the PNG file will match the input locale.
EXPECT_TRUE(matches_locale("", "en-US"));
EXPECT_TRUE(matches_locale("sr-Latn", "sr-Latn-BA"));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment