regen emojis started

This commit is contained in:
John Preston 2015-04-19 14:16:48 +03:00
parent 47b0f901c8
commit b31f2d952c
7 changed files with 58 additions and 13 deletions

View File

@ -515,7 +515,7 @@
6DB9C3763D02B1415CD9D565 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastUpgradeCheck = 0630;
};
buildConfigurationList = DAC4C1AA5EDEA1C85E9CA5E6 /* Build configuration list for PBXProject "MetaEmoji" */;
compatibilityVersion = "Xcode 3.2";
@ -589,6 +589,7 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
@ -677,6 +678,7 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;

View File

@ -18,6 +18,7 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org
#include "genemoji.h"
#include <QtCore/QtPlugin>
#include <QtGui/QFontDatabase>
#ifdef Q_OS_WIN
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
@ -1091,6 +1092,28 @@ void writeEmojiCategory(QTextStream &tcpp, uint64 *emojiCategory, uint32 size, c
tcpp << "\t} break;\n\n";
}
QString textEmojiString(const EmojiData *emoji) {
QString result;
int len = emoji->code2 ? 4 : ((emoji->code >> 16) ? 2 : 1);
bool withPostfix = emojiWithPostfixes.constFind(emoji->code) != emojiWithPostfixes.constEnd();
result.reserve(len + (withPostfix ? 1 : 0));
switch (len) {
case 1: result.append(QChar(emoji->code & 0xFFFF)); break;
case 2:
result.append(QChar((emoji->code >> 16) & 0xFFFF));
result.append(QChar(emoji->code & 0xFFFF));
break;
case 4:
result.append(QChar((emoji->code >> 16) & 0xFFFF));
result.append(QChar(emoji->code & 0xFFFF));
result.append(QChar((emoji->code2 >> 16) & 0xFFFF));
result.append(QChar(emoji->code2 & 0xFFFF));
break;
}
if (withPostfix) result.append(QChar(0xFE0F));
return result;
}
bool genEmoji(QString emoji_in, const QString &emoji_out, const QString &emoji_png) {
int currentRow = 0, currentColumn = 0;
uint32 min1 = 0xFFFFFFFFU, max1 = 0, min2 = 0xFFFFFFFFU, max2 = 0;
@ -1165,17 +1188,40 @@ bool genEmoji(QString emoji_in, const QString &emoji_out, const QString &emoji_p
return true;
}
for (int i = 0, l = sizeof(emojiPostfixed) / sizeof(emojiPostfixed[0]); i < l; ++i) {
emojiWithPostfixes.insert(emojiPostfixed[i], true);
}
QStringList str = QFontDatabase::applicationFontFamilies(QFontDatabase::addApplicationFont(QStringLiteral("/System/Library/Fonts/Apple Color Emoji.ttf")));
for (int i = 0, l = str.size(); i < l; ++i) {
}
qreal emojiFontSizes[4] = { 14.0, 19.0, 27.0, 36.0 };
int emojiDeltas[4] = { 15, 19, 25, 34 };
for (int variantIndex = 0; variantIndex < variantsCount; variantIndex++) {
int imSize = imSizes[variantIndex];
QFont f(QGuiApplication::font());
f.setFamily(QStringLiteral("Apple Color Emoji"));
f.setPointSizeF(emojiFontSizes[variantIndex]);
QImage emojisImg(inRow * imSize, currentRow * imSize, QImage::Format_ARGB32);
QPainter p(&emojisImg);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.fillRect(0, 0, emojisImg.width(), emojisImg.height(), Qt::transparent);
for (EmojisData::const_iterator i = emojisData.cbegin(), e = emojisData.cend(); i != e; ++i) {
int ind = i->index, row = ind / emojisInRow[i->category], col = ind % emojisInRow[i->category], size = sizes[i->category];
QPixmap emoji = QPixmap::fromImage(sprites[i->category].copy(col * size, row * size, size, size).scaled(imSize, imSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
p.drawPixmap(i->x * imSize, i->y * imSize, emoji);
{
QPainter p(&emojisImg);
p.setFont(f);
QPainter::CompositionMode m = p.compositionMode();
p.setCompositionMode(QPainter::CompositionMode_Source);
p.fillRect(0, 0, emojisImg.width(), emojisImg.height(), Qt::transparent);
p.setCompositionMode(m);
for (EmojisData::const_iterator i = emojisData.cbegin(), e = emojisData.cend(); i != e; ++i) {
// int ind = i->index, row = ind / emojisInRow[i->category], col = ind % emojisInRow[i->category], size = sizes[i->category];
// QPixmap emoji = QPixmap::fromImage(sprites[i->category].copy(col * size, row * size, size, size).scaled(imSize, imSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
p.setPen(QColor(0, 0, 0, 255));
p.drawText(i->x * imSize, i->y * imSize + emojiDeltas[variantIndex], textEmojiString(&i.value()));
p.setPen(QColor(((i->x + i->y) % 2) ? 255 : 0, ((i->x + i->y) % 2) ? 255 : 0, ((i->x + i->y) % 2) ? 255 : 0, 100));
p.drawRect(i->x * imSize, i->y * imSize, imSize - 1, imSize - 1);
// p.drawPixmap(i->x * imSize, i->y * imSize, emoji);
}
}
QString postfix = variantPostfix[variantIndex], emojif = emoji_png + postfix + ".png";
QByteArray emojib;
@ -1212,10 +1258,6 @@ bool genEmoji(QString emoji_in, const QString &emoji_out, const QString &emoji_p
}
}
for (int i = 0, l = sizeof(emojiPostfixed) / sizeof(emojiPostfixed[0]); i < l; ++i) {
emojiWithPostfixes.insert(emojiPostfixed[i], true);
}
try {
QByteArray cppText;

View File

@ -132,7 +132,7 @@ int main(int argc, const char * argv[]) {
}
if (update) {
writeLog(@"Starting update files iteration!");
writeLog([@"Starting update files iteration, path: " stringByAppendingString: [workDir stringByAppendingString:@"tupdates/ready"]]);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *srcDir = [workDir stringByAppendingString:@"tupdates/ready/"];
@ -142,6 +142,7 @@ int main(int argc, const char * argv[]) {
includingPropertiesForKeys:keys
options:0
errorHandler:^(NSURL *url, NSError *error) {
writeLog([[[@"Error in enumerating " stringByAppendingString:[url absoluteString]] stringByAppendingString: @" error is: "] stringByAppendingString: [error description]]);
return NO;
}];
for (NSURL *url in enumerator) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 528 KiB

After

Width:  |  Height:  |  Size: 557 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 722 KiB

After

Width:  |  Height:  |  Size: 695 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1003 KiB

After

Width:  |  Height:  |  Size: 1001 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB