summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorThanos Doukoudakis <thanos.doukoudakis@isode.com>2018-04-16 09:59:34 (GMT)
committerKevin Smith <kevin.smith@isode.com>2018-05-10 08:13:57 (GMT)
commit4663da31954d989f8535b94c4a78a0f4515542a4 (patch)
treeaa6cf7a359ed0e61e038f3f518581bc9351d52f9 /Swift
parent8fab33012e5ac7c03ab00ec30118dcb2c5218051 (diff)
downloadswift-4663da31954d989f8535b94c4a78a0f4515542a4.zip
swift-4663da31954d989f8535b94c4a78a0f4515542a4.tar.bz2
Enable Emojis on Windows and Linux
This patch enables emojis for Linux and Windows. In windows, currently the emojis are only black and white, due to some inconsistencies in the UI. For Linux the Noto Colour Emoji font (https://www.google.com/get/noto/) is used. The client must be build with Qt 5.6 or newer to support the emoji characters. Test-Information: Tested the changes with Qt 5.8 on Windows 10 and Linux Ubuntu 17.10. Built and tested the appimage on Ubuntu 17.10 and Ubuntu 16.04. Change-Id: I6d0f2842349eae789d773c33d1a93ad33304df3e
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp12
-rw-r--r--Swift/QtUI/QtEmojiCell.cpp15
-rw-r--r--Swift/QtUI/QtEmojisSelector.cpp9
-rw-r--r--Swift/QtUI/QtSwift.cpp9
-rw-r--r--Swift/QtUI/SConscript3
-rw-r--r--Swift/resources/themes/Default/Noto/LICENSE92
-rw-r--r--Swift/resources/themes/Default/Noto/NotoColorEmoji.ttfbin0 -> 7253060 bytes
-rw-r--r--Swift/resources/themes/Default/main.css2
8 files changed, 127 insertions, 15 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 231a9b9..cbdab48 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -155,11 +155,15 @@ QtChatWindow::QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventSt
connect(input_, SIGNAL(lostFocus()), this, SLOT(handleTextInputLostFocus()));
connect(input_, SIGNAL(itemDropped(QDropEvent*)), this, SLOT(dropEvent(QDropEvent*)));
QPushButton* emojisButton_ = new QPushButton(this);
-
-#ifdef SWIFTEN_PLATFORM_MACOSX
emojisButton_->setText("\xF0\x9F\x98\x83");
-#else
- emojisButton_->setIcon(QIcon(":/emoticons/smile.png"));
+
+#if defined(SWIFTEN_PLATFORM_WINDOWS) || defined(SWIFTEN_PLATFORM_LINUX)
+ //Using a emoji glyph instead of an image makes the button sizes inequal in windows & linux,
+ //so we set fixed size for both buttons, the one that is hinted for actionButton_
+ emojisButton_->setMaximumWidth(actionButton_->sizeHint().width());
+ emojisButton_->setMaximumHeight(actionButton_->sizeHint().height());
+ actionButton_->setMaximumWidth(actionButton_->sizeHint().width());
+ actionButton_->setMaximumHeight(actionButton_->sizeHint().height());
#endif
connect(emojisButton_, SIGNAL(clicked()), this, SLOT(handleEmojisButtonClicked()));
diff --git a/Swift/QtUI/QtEmojiCell.cpp b/Swift/QtUI/QtEmojiCell.cpp
index 865f1f6..106e968 100644
--- a/Swift/QtUI/QtEmojiCell.cpp
+++ b/Swift/QtUI/QtEmojiCell.cpp
@@ -1,11 +1,13 @@
/*
- * Copyright (c) 2016-2017 Isode Limited.
+ * Copyright (c) 2016-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtEmojiCell.h>
+#include <Swiften/Base/Platform.h>
+
#include <QFont>
#include <QFontMetrics>
#include <QPushButton>
@@ -17,13 +19,20 @@ namespace Swift {
QtEmojiCell::QtEmojiCell(QString shortname, QString text, QWidget* parent) : QPushButton(parent) {
setText(text);
QFont font = this->font();
+#ifdef SWIFTEN_PLATFORM_WINDOWS
+ //Windows emoji font miscalculates the bounding rectangular that surrounds the emoji. We set a multiplier value to make it look consistent with linux & Mac
+ const float sizeMultiplier = 1.3;
+ font.setPointSize(18);
+#else
font.setPointSize(22);
+ const float sizeMultiplier = 1;
+#endif
font.setBold(true);
setFont(font);
const auto boundingRect = fontMetrics().boundingRect("\xF0\x9F\x98\x83");
- setFixedWidth(qMax(boundingRect.width(), boundingRect.height()));
- setFixedHeight(qMax(boundingRect.width(), boundingRect.height()));
+ setFixedWidth(qMax(sizeMultiplier*boundingRect.width(), sizeMultiplier*boundingRect.height()));
+ setFixedHeight(qMax(sizeMultiplier*boundingRect.width(), sizeMultiplier*boundingRect.height()));
setFlat(true);
setToolTip(shortname);
diff --git a/Swift/QtUI/QtEmojisSelector.cpp b/Swift/QtUI/QtEmojisSelector.cpp
index 62ed862..fe2f235 100644
--- a/Swift/QtUI/QtEmojisSelector.cpp
+++ b/Swift/QtUI/QtEmojisSelector.cpp
@@ -24,7 +24,6 @@
namespace Swift {
QtEmojisSelector::QtEmojisSelector(QSettings* settings, const std::map<std::string, std::string>& emoticonsMap, QWidget* parent) : QTabWidget(parent), settings_(settings), emoticonsMap_(emoticonsMap) {
-#ifdef SWIFTEN_PLATFORM_MACOSX
recentEmojisGrid_ = addRecentTab();
connect(recentEmojisGrid_, SIGNAL(onEmojiSelected(QString)), this, SLOT(emojiClickedSlot(QString)));
@@ -34,17 +33,13 @@ namespace Swift {
connect(grid, SIGNAL(onEmojiSelected(QString)), this, SLOT(emojiClickedSlot(QString)));
}
}
-
loadSettings();
-#else
- setupEmoticonsTab();
-#endif
+ //The size of an emoji cell varies depending the OS, 42 is the ceil value.
+ setFixedSize(QSize(EmojiMapper::emojisInCategory.size() * 42, 300));
}
QtEmojisSelector::~QtEmojisSelector() {
-#ifdef SWIFTEN_PLATFORM_MACOSX
writeSettings();
-#endif
}
QtRecentEmojisGrid* QtEmojisSelector::addRecentTab() {
diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp
index 76e3583..2d75565 100644
--- a/Swift/QtUI/QtSwift.cpp
+++ b/Swift/QtUI/QtSwift.cpp
@@ -233,6 +233,15 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa
SWIFT_LOG_ASSERT(error != -1, error) << "Failed to load font " << fontPath << std::endl;
}
+#ifdef SWIFTEN_PLATFORM_LINUX
+ std::string fontPath = std::string(":/themes/Default/Noto/NotoColorEmoji.ttf");
+ int error = QFontDatabase::addApplicationFont(P2QSTRING(fontPath));
+ SWIFT_LOG_ASSERT(error != -1, error) << "Failed to load font " << fontPath << std::endl;
+ QFont::insertSubstitution(QApplication::font().family(),"NotoColorEmoji");
+#endif
+#ifdef SWIFTEN_PLATFORM_WINDOWS
+ QFont::insertSubstitution(QApplication::font().family(), "Segoe UI Emoji");
+#endif
bool enableAdHocCommandOnJID = options.count("enable-jid-adhocs") > 0;
tabs_ = nullptr;
if (options.count("no-tabs") && !splitter_) {
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index b8ec3ba..09860ed 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -7,6 +7,9 @@ def generateQRCTheme(dir, prefix) :
result += "<RCC version =\"1.0\">"
result += "<qresource prefix=\"/themes/" + prefix + "\">"
for (path, dirs, files) in os.walk(sourceDir) :
+ #skip the Noto emoji fonts in Windows. No need to package them since they aren't used
+ if "Noto" in path and not env["PLATFORM"] == "linux" :
+ continue
for file in files :
filePath = os.path.join(path,file)
result += "<file alias=\"%(alias)s\">%(path)s</file>" % {
diff --git a/Swift/resources/themes/Default/Noto/LICENSE b/Swift/resources/themes/Default/Noto/LICENSE
new file mode 100644
index 0000000..d952d62
--- /dev/null
+++ b/Swift/resources/themes/Default/Noto/LICENSE
@@ -0,0 +1,92 @@
+This Font Software is licensed under the SIL Open Font License,
+Version 1.1.
+
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font
+creation efforts of academic and linguistic communities, and to
+provide a free and open framework in which fonts may be shared and
+improved in partnership with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply to
+any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software
+components as distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to,
+deleting, or substituting -- in part or in whole -- any of the
+components of the Original Version, by changing formats or by porting
+the Font Software to a new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed,
+modify, redistribute, and sell modified and unmodified copies of the
+Font Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components, in
+Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the
+corresponding Copyright Holder. This restriction only applies to the
+primary font name as presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created using
+the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/Swift/resources/themes/Default/Noto/NotoColorEmoji.ttf b/Swift/resources/themes/Default/Noto/NotoColorEmoji.ttf
new file mode 100644
index 0000000..9d82f52
--- /dev/null
+++ b/Swift/resources/themes/Default/Noto/NotoColorEmoji.ttf
Binary files differ
diff --git a/Swift/resources/themes/Default/main.css b/Swift/resources/themes/Default/main.css
index 2fe7374..64ab7bf 100644
--- a/Swift/resources/themes/Default/main.css
+++ b/Swift/resources/themes/Default/main.css
@@ -1,7 +1,7 @@
/* Chat Window Container */
body {
- font-family: 'Lato', sans-serif;
+ font-family: 'Lato', 'apple color emoji', 'notocoloremoji', sans-serif;
margin: 0;
padding: 0;
}