[core] Use UTF-16 instead of UTF-32 for label features to avoid extra conversions and reduce in-memory size.

Continue to use uint32 as glyph ID to maintain Glyph PBF, even though we're only using 16 bits of that uint32.
Use std::codecvt instead of boost::unicode_iterator for UTF8->UTF16 conversions.
This commit is contained in:
Chris Loer
2016-11-09 18:23:49 -08:00
committed by John Firebaugh
parent 5c7aeec5c7
commit 40b0c8d076
16 changed files with 40 additions and 39 deletions

View File

@@ -8,7 +8,7 @@ namespace {
@param last The last codepoint in the block, inclusive.
*/
#define DEFINE_IS_IN_UNICODE_BLOCK(name, first, last) \
inline bool isIn##name(uint32_t codepoint) { \
inline bool isIn##name(uint16_t codepoint) { \
return codepoint >= first && codepoint <= last; \
}
@@ -294,13 +294,13 @@ namespace mbgl {
namespace util {
namespace i18n {
bool isVisible(uint32_t chr) {
bool isVisible(uint16_t chr) {
return (chr == 0x0a /* newline */
|| chr == 0x20 /* space */
|| chr == 0x200b /* zero-width space */);
}
bool allowsWordBreaking(uint32_t chr) {
bool allowsWordBreaking(uint16_t chr) {
return (chr == 0x0a /* newline */
|| chr == 0x20 /* space */
|| chr == 0x26 /* ampersand */
@@ -314,8 +314,8 @@ bool allowsWordBreaking(uint32_t chr) {
|| chr == 0x2013 /* en dash */);
}
bool allowsIdeographicBreaking(const std::u32string& string) {
for (uint32_t chr : string) {
bool allowsIdeographicBreaking(const std::u16string& string) {
for (uint16_t chr : string) {
if (!allowsIdeographicBreaking(chr)) {
return false;
}
@@ -323,7 +323,7 @@ bool allowsIdeographicBreaking(const std::u32string& string) {
return true;
}
bool allowsIdeographicBreaking(uint32_t chr) {
bool allowsIdeographicBreaking(uint16_t chr) {
// Return early for characters outside all ideographic ranges.
if (chr < 0x2E80)
return false;