new emoji support added

This commit is contained in:
John Preston 2015-11-27 20:10:16 +03:00
parent 4487ad9e15
commit ba0825c892
17 changed files with 5500 additions and 3843 deletions

View File

@ -564,10 +564,10 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
"lng_emoji_category1" = "People";
"lng_emoji_category2" = "Nature";
"lng_emoji_category3" = "Food & Drink";
"lng_emoji_category4" = "Celebration";
"lng_emoji_category5" = "Activity";
"lng_emoji_category6" = "Travel & Places";
"lng_emoji_category7" = "Objects & Symbols";
"lng_emoji_category4" = "Activity";
"lng_emoji_category5" = "Travel & Places";
"lng_emoji_category6" = "Objects";
"lng_emoji_category7" = "Symbols & Flags";
"lng_switch_stickers" = "Stickers";
"lng_switch_emoji" = "Emoji";

View File

@ -1806,14 +1806,14 @@ emojiNatureOver: sprite(42px, 196px, 21px, 22px);
emojiNatureActive: sprite(245px, 286px, 21px, 22px);
emojiFoodOver: sprite(63px, 196px, 21px, 22px);
emojiFoodActive: sprite(266px, 286px, 21px, 22px);
emojiCelebrationOver: sprite(84px, 196px, 21px, 22px);
emojiCelebrationActive: sprite(287px, 286px, 21px, 22px);
emojiActivityOver: sprite(126px, 196px, 21px, 22px);
emojiActivityActive: sprite(287px, 264px, 21px, 22px);
emojiTravelOver: sprite(105px, 196px, 21px, 22px);
emojiTravelActive: sprite(308px, 286px, 21px, 22px);
emojiObjectsOver: sprite(147px, 196px, 21px, 22px);
emojiObjectsActive: sprite(308px, 264px, 21px, 22px);
emojiSymbolsOver: sprite(84px, 196px, 21px, 22px);
emojiSymbolsActive: sprite(287px, 286px, 21px, 22px);
emojiPanCategories: #f7f7f7;
@ -1867,14 +1867,6 @@ rbEmojiFood: flatCheckbox(rbEmoji) {
disImageRect: emojiFoodOver;
chkDisImageRect: emojiFoodActive;
}
rbEmojiCelebration: flatCheckbox(rbEmoji) {
imageRect: emojiCelebrationOver;
chkImageRect: emojiCelebrationActive;
overImageRect: emojiCelebrationOver;
chkOverImageRect: emojiCelebrationActive;
disImageRect: emojiCelebrationOver;
chkDisImageRect: emojiCelebrationActive;
}
rbEmojiActivity: flatCheckbox(rbEmoji) {
imageRect: emojiActivityOver;
chkImageRect: emojiActivityActive;
@ -1899,6 +1891,14 @@ rbEmojiObjects: flatCheckbox(rbEmoji) {
disImageRect: emojiObjectsOver;
chkDisImageRect: emojiObjectsActive;
}
rbEmojiSymbols: flatCheckbox(rbEmoji) {
imageRect: emojiSymbolsOver;
chkImageRect: emojiSymbolsActive;
overImageRect: emojiSymbolsOver;
chkOverImageRect: emojiSymbolsActive;
disImageRect: emojiSymbolsOver;
chkDisImageRect: emojiSymbolsActive;
}
emojiPanPadding: 12px;
emojiPanSize: size(45px, 41px);
emojiPanWidth: 345px;

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 586 KiB

After

Width:  |  Height:  |  Size: 762 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 789 KiB

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

@ -1831,14 +1831,14 @@ void EmojiSwitchButton::paintEvent(QPaintEvent *e) {
EmojiPan::EmojiPan(QWidget *parent) : TWidget(parent), _maxHeight(st::emojiPanMaxHeight),
_horizontal(false), _noTabUpdate(false), _hiding(false), a_opacity(0), _shadow(st::dropdownDef.shadow),
_recent(this , qsl("emoji_group"), dbietRecent , QString(), true , st::rbEmojiRecent),
_people(this , qsl("emoji_group"), dbietPeople , QString(), false, st::rbEmojiPeople),
_nature(this , qsl("emoji_group"), dbietNature , QString(), false, st::rbEmojiNature),
_food(this , qsl("emoji_group"), dbietFood , QString(), false, st::rbEmojiFood),
_celebration(this, qsl("emoji_group"), dbietCelebration, QString(), false, st::rbEmojiCelebration),
_activity(this , qsl("emoji_group"), dbietActivity , QString(), false, st::rbEmojiActivity),
_travel(this , qsl("emoji_group"), dbietTravel , QString(), false, st::rbEmojiTravel),
_objects(this , qsl("emoji_group"), dbietObjects , QString(), false, st::rbEmojiObjects),
_recent(this , qsl("emoji_group"), dbietRecent , QString(), true , st::rbEmojiRecent),
_people(this , qsl("emoji_group"), dbietPeople , QString(), false, st::rbEmojiPeople),
_nature(this , qsl("emoji_group"), dbietNature , QString(), false, st::rbEmojiNature),
_food(this , qsl("emoji_group"), dbietFood , QString(), false, st::rbEmojiFood),
_activity(this, qsl("emoji_group"), dbietActivity, QString(), false, st::rbEmojiActivity),
_travel(this , qsl("emoji_group"), dbietTravel , QString(), false, st::rbEmojiTravel),
_objects(this , qsl("emoji_group"), dbietObjects , QString(), false, st::rbEmojiObjects),
_symbols(this , qsl("emoji_group"), dbietSymbols , QString(), false, st::rbEmojiSymbols),
_iconOver(-1), _iconSel(0), _iconDown(-1), _iconsDragging(false),
_iconAnim(animFunc(this, &EmojiPan::iconAnim)),
_iconsLeft(0), _iconsTop(0), _iconsStartX(0), _iconsMax(0), _iconsX(0, 0), _iconSelX(0, 0), _iconsStartAnim(0),
@ -1872,10 +1872,10 @@ s_scroll(this, st::emojiScroll), s_inner(), s_switch(&s_scroll, false), _removin
prepareTab(left, top, _width, _people);
prepareTab(left, top, _width, _nature);
prepareTab(left, top, _width, _food);
prepareTab(left, top, _width, _celebration);
prepareTab(left, top, _width, _activity);
prepareTab(left, top, _width, _travel);
prepareTab(left, top, _width, _objects);
prepareTab(left, top, _width, _symbols);
e_inner.fillPanels(e_panels);
updatePanelsPositions(e_panels, 0);
@ -1938,10 +1938,10 @@ void EmojiPan::setMaxHeight(int32 h) {
_people.move(_people.x(), _iconsTop);
_nature.move(_nature.x(), _iconsTop);
_food.move(_food.x(), _iconsTop);
_celebration.move(_celebration.x(), _iconsTop);
_activity.move(_activity.x(), _iconsTop);
_travel.move(_travel.x(), _iconsTop);
_objects.move(_objects.x(), _iconsTop);
_symbols.move(_symbols.x(), _iconsTop);
update();
}
@ -2474,10 +2474,10 @@ void EmojiPan::showAll() {
_people.hide();
_nature.hide();
_food.hide();
_celebration.hide();
_activity.hide();
_travel.hide();
_objects.hide();
_symbols.hide();
e_scroll.hide();
} else {
s_scroll.hide();
@ -2485,10 +2485,10 @@ void EmojiPan::showAll() {
_people.show();
_nature.show();
_food.show();
_celebration.show();
_activity.show();
_travel.show();
_objects.show();
_symbols.show();
e_scroll.show();
}
}
@ -2498,10 +2498,10 @@ void EmojiPan::hideAll() {
_people.hide();
_nature.hide();
_food.hide();
_celebration.hide();
_activity.hide();
_travel.hide();
_objects.hide();
_symbols.hide();
e_scroll.hide();
s_scroll.hide();
e_inner.clearSelection(true);
@ -2514,10 +2514,10 @@ void EmojiPan::onTabChange() {
if (_people.checked()) newTab = dbietPeople;
else if (_nature.checked()) newTab = dbietNature;
else if (_food.checked()) newTab = dbietFood;
else if (_celebration.checked()) newTab = dbietCelebration;
else if (_activity.checked()) newTab = dbietActivity;
else if (_travel.checked()) newTab = dbietTravel;
else if (_objects.checked()) newTab = dbietObjects;
else if (_symbols.checked()) newTab = dbietSymbols;
e_inner.showEmojiPack(newTab);
}
@ -2540,14 +2540,14 @@ void EmojiPan::onScroll() {
DBIEmojiTab tab = e_inner.currentTab(st);
FlatRadiobutton *check = 0;
switch (tab) {
case dbietRecent : check = &_recent ; break;
case dbietPeople : check = &_people ; break;
case dbietNature : check = &_nature ; break;
case dbietFood : check = &_food ; break;
case dbietCelebration: check = &_celebration; break;
case dbietActivity : check = &_activity ; break;
case dbietTravel : check = &_travel ; break;
case dbietObjects : check = &_objects ; break;
case dbietRecent : check = &_recent ; break;
case dbietPeople : check = &_people ; break;
case dbietNature : check = &_nature ; break;
case dbietFood : check = &_food ; break;
case dbietActivity: check = &_activity; break;
case dbietTravel : check = &_travel ; break;
case dbietObjects : check = &_objects ; break;
case dbietSymbols : check = &_symbols ; break;
}
if (check && !check->checked()) {
_noTabUpdate = true;

View File

@ -545,7 +545,7 @@ private:
BoxShadow _shadow;
FlatRadiobutton _recent, _people, _nature, _food, _celebration, _activity, _travel, _objects;
FlatRadiobutton _recent, _people, _nature, _food, _activity, _travel, _objects, _symbols;
QVector<StickerIcon> _icons;
QVector<float64> _iconHovers;
int32 _iconOver, _iconSel, _iconDown;

File diff suppressed because it is too large Load Diff

View File

@ -85,7 +85,7 @@ inline EmojiPtr emojiFromUrl(const QString &url) {
inline EmojiPtr emojiFromText(const QChar *ch, const QChar *e, int &len) {
EmojiPtr emoji = 0;
if (ch + 1 < e && ((ch->isHighSurrogate() && (ch + 1)->isLowSurrogate()) || (((ch->unicode() >= 48 && ch->unicode() < 58) || ch->unicode() == 35) && (ch + 1)->unicode() == 0x20E3))) {
if (ch + 1 < e && ((ch->isHighSurrogate() && (ch + 1)->isLowSurrogate()) || (((ch->unicode() >= 0x30 && ch->unicode() < 0x3A) || ch->unicode() == 0x23 || ch->unicode() == 0x2A) && (ch + 1)->unicode() == 0x20E3))) {
uint32 code = (ch->unicode() << 16) | (ch + 1)->unicode();
emoji = emojiGet(code);
if (emoji) {
@ -105,6 +105,11 @@ inline EmojiPtr emojiFromText(const QChar *ch, const QChar *e, int &len) {
}
}
}
} else if (ch + 2 < e && ((ch->unicode() >= 0x30 && ch->unicode() < 0x3A) || ch->unicode() == 0x23 || ch->unicode() == 0x2A) && (ch + 1)->unicode() == 0xFE0F && (ch + 2)->unicode() == 0x20E3) {
uint32 code = (ch->unicode() << 16) | (ch + 2)->unicode();
emoji = emojiGet(code);
len = emoji->len + 1;
return emoji;
} else if (ch < e) {
emoji = emojiGet(ch->unicode());
Q_ASSERT(emoji != TwoSymbolEmoji);

View File

@ -545,7 +545,7 @@ public:
void parseCurrentChar() {
int skipBack = 0;
ch = ((ptr < end) ? *ptr : 0);
chInt = ch.unicode();
emojiLookback = 0;
bool skip = false, isNewLine = multiline && chIsNewline(ch), isSpace = chIsSpace(ch), isDiac = chIsDiac(ch), isTilde = checkTilde && (ch == '~');
if (chIsBad(ch) || ch.isLowSurrogate()) {
skip = true;
@ -561,15 +561,7 @@ public:
skipBack = -1;
++ptr;
ch = *ptr;
chInt = (chInt << 16) | ch.unicode();
}
} else if ((ch >= 48 && ch < 58) || ch == 35) { // check for digit emoji
if (ptr + 1 < end && (ptr + 1)->unicode() == 0x20E3) {
_t->_text.push_back(ch);
skipBack = -1;
++ptr;
ch = *ptr;
chInt = (chInt << 16) | 0x20E3;
emojiLookback = 1;
}
}
@ -601,11 +593,11 @@ public:
}
void parseEmojiFromCurrent() {
int len = 0, skipped = (chInt > 0xFFFFU) ? 1 : 0;
EmojiPtr e = emojiFromText(ptr - skipped, end, len);
int len = 0;
EmojiPtr e = emojiFromText(ptr - emojiLookback, end, len);
if (!e) return;
for (int l = len - skipped - 1; l > 0; --l) {
for (int l = len - emojiLookback - 1; l > 0; --l) {
_t->_text.push_back(*++ptr);
}
if (e->postfix && _t->_text.at(_t->_text.size() - 1).unicode() != e->postfix) {
@ -688,7 +680,7 @@ public:
blockStart = 0;
emoji = 0;
ch = chInt = 0;
ch = emojiLookback = 0;
lastSkipped = false;
checkTilde = !cRetina() && _t->_font->size() == 13 && _t->_font->flags() == 0; // tilde Open Sans fix
entitiesEnd = entities.cend();
@ -789,7 +781,7 @@ private:
// current char data
QChar ch; // current char (low surrogate, if current char is surrogate pair)
uint32 chInt; // full ch, could be surrogate pair
int32 emojiLookback; // how far behind the current ptr to look for current emoji
bool lastSkipped; // did we skip current char
bool checkTilde; // do we need a special text block for tilde symbol
};
@ -2553,7 +2545,7 @@ void Text::setMarkedText(style::font font, const QString &text, const EntitiesIn
_font = font;
clean();
{
// QByteArray ba = text.toUtf8();
// QByteArray ba = text.toUtf8(); // chars for OS X crash investigation
// const char *ch = ba.constData();
// LOG(("STR: %1").arg(text));
// LOG(("BYTES: %1").arg(mb(ba.constData(), ba.size()).str()));
@ -2562,6 +2554,36 @@ void Text::setMarkedText(style::font font, const QString &text, const EntitiesIn
// }
// int32 w = _font->width(text);
// QString newText; // utf16 of the text for emoji
// newText.reserve(8 * text.size());
// for (const QChar *ch = text.constData(), *e = ch + text.size(); ch != e; ++ch) {
// if (chIsNewline(*ch)) {
// newText.append(*ch);
// } else {
// if (ch->isHighSurrogate() || ch->isLowSurrogate()) {
// if (ch->isHighSurrogate() && (ch + 1 != e) && ((ch + 1)->isLowSurrogate())) {
// newText.append("0x").append(QString::number((uint32(ch->unicode()) << 16) | uint32((ch + 1)->unicode()), 16).toUpper()).append("LLU,");
// ++ch;
// } else {
// newText.append("BADx").append(QString::number(ch->unicode(), 16).toUpper()).append("LLU,");
// }
// } else {
// newText.append("0x").append(QString::number(ch->unicode(), 16).toUpper()).append("LLU,");
// }
// }
// }
// newText.append("\n\n").append(text);
// TextParser parser(this, newText, EntitiesInText(), options);
// QString newText; // utf8 of the text for emoji sequences
// newText.reserve(8 * text.size());
// QByteArray ba = text.toUtf8();
// for (int32 i = 0, l = ba.size(); i < l; ++i) {
// newText.append("\\x").append(QString::number(uchar(ba.at(i)), 16).toLower());
// }
// newText.append("\n\n").append(text);
// TextParser parser(this, newText, EntitiesInText(), options);
TextParser parser(this, text, entities, options);
}
recountNaturalSize(true, options.dir);

View File

@ -1092,22 +1092,12 @@ namespace {
cSetCompressPastedImage(v == 1);
} break;
case dbiEmojiTab: {
case dbiEmojiTabOld: {
qint32 v;
stream >> v;
if (!_checkStreamStatus(stream)) return false;
switch (v) {
case dbietRecent : cSetEmojiTab(dbietRecent ); break;
case dbietPeople : cSetEmojiTab(dbietPeople ); break;
case dbietNature : cSetEmojiTab(dbietNature ); break;
case dbietFood : cSetEmojiTab(dbietFood ); break;
case dbietCelebration: cSetEmojiTab(dbietCelebration); break;
case dbietActivity : cSetEmojiTab(dbietActivity ); break;
case dbietTravel : cSetEmojiTab(dbietTravel ); break;
case dbietObjects : cSetEmojiTab(dbietObjects ); break;
case dbietStickers : cSetEmojiTab(dbietStickers ); break;
}
// deprecated
} break;
case dbiRecentEmojisOld: {
@ -1420,7 +1410,6 @@ namespace {
data.stream << quint32(dbiAskDownloadPath) << qint32(cAskDownloadPath());
data.stream << quint32(dbiDownloadPath) << (cAskDownloadPath() ? QString() : cDownloadPath()) << (cAskDownloadPath() ? QByteArray() : cDownloadPathBookmark());
data.stream << quint32(dbiCompressPastedImage) << qint32(cCompressPastedImage());
data.stream << quint32(dbiEmojiTab) << qint32(cEmojiTab());
data.stream << quint32(dbiDialogLastPath) << cDialogLastPath();
data.stream << quint32(dbiSongVolume) << qint32(qRound(cSongVolume() * 1e6));

View File

@ -100,7 +100,6 @@ bool gHasPasscode = false;
bool gHasAudioPlayer = true;
bool gHasAudioCapture = true;
DBIEmojiTab gEmojiTab = dbietRecent;
RecentEmojiPack gRecentEmojis;
RecentEmojisPreload gRecentEmojisPreload;
EmojiColorVariants gEmojiVariants;

View File

@ -169,8 +169,6 @@ T convertScale(T v) {
return v;
}
DeclareSetting(DBIEmojiTab, EmojiTab);
struct EmojiData {
EmojiData(uint16 x, uint16 y, uint32 code, uint32 code2, uint16 len, uint16 postfix, uint32 color) : x(x), y(y), code(code), code2(code2), len(len), postfix(postfix), color(color) {
}

View File

@ -260,7 +260,7 @@ enum DataBlockId {
dbiAskDownloadPath = 0x14,
dbiDownloadPathOld = 0x15,
dbiScale = 0x16,
dbiEmojiTab = 0x17,
dbiEmojiTabOld = 0x17,
dbiRecentEmojisOld = 0x18,
dbiLoggedPhoneNumber = 0x19,
dbiMutedPeers = 0x1a,
@ -342,15 +342,15 @@ enum DBIScale {
static const int MatrixRowShift = 40000;
enum DBIEmojiTab {
dbietRecent = -1,
dbietPeople = 0,
dbietNature = 1,
dbietFood = 2,
dbietCelebration = 3,
dbietActivity = 4,
dbietTravel = 5,
dbietObjects = 6,
dbietStickers = 666,
dbietRecent = -1,
dbietPeople = 0,
dbietNature = 1,
dbietFood = 2,
dbietActivity = 3,
dbietTravel = 4,
dbietObjects = 5,
dbietSymbols = 6,
dbietStickers = 666,
};
static const int emojiTabCount = 8;
inline DBIEmojiTab emojiTabAtIndex(int index) {