diff --git a/Telegram/SourceFiles/codegen/emoji/generator.cpp b/Telegram/SourceFiles/codegen/emoji/generator.cpp index f251499a8..2e9c1c90b 100644 --- a/Telegram/SourceFiles/codegen/emoji/generator.cpp +++ b/Telegram/SourceFiles/codegen/emoji/generator.cpp @@ -28,6 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include #include +#ifdef SUPPORT_IMAGE_GENERATION Q_IMPORT_PLUGIN(QWebpPlugin) #ifdef Q_OS_MAC Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) @@ -36,6 +37,7 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) #else // !Q_OS_MAC && !Q_OS_WIN Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) #endif // !Q_OS_MAC && !Q_OS_WIN +#endif // SUPPORT_IMAGE_GENERATION namespace codegen { namespace emoji { @@ -126,7 +128,11 @@ QString computeId(Id id) { } // namespace -Generator::Generator(const Options &options) : project_(Project), writeImages_(options.writeImages), data_(PrepareData()) { +Generator::Generator(const Options &options) : project_(Project) +#ifdef SUPPORT_IMAGE_GENERATION +, writeImages_(options.writeImages) +#endif // SUPPORT_IMAGE_GENERATION +, data_(PrepareData()) { QDir dir(options.outputPath); if (!dir.mkpath(".")) { common::logError(kErrorCantWritePath, "Command Line") << "can not open path for writing: " << dir.absolutePath().toStdString(); @@ -142,13 +148,11 @@ int Generator::generate() { return -1; } +#ifdef SUPPORT_IMAGE_GENERATION if (writeImages_) { -#ifdef Q_OS_MAC return writeImages() ? 0 : -1; -#else // Q_OS_MAC - common::logError(common::kErrorInternal, "Command Line") << "can not generate images in this OS."; -#endif // Q_OS_MAC } +#endif // SUPPORT_IMAGE_GENERATION if (!writeSource()) { return -1; @@ -163,6 +167,7 @@ int Generator::generate() { constexpr auto kVariantsCount = 5; constexpr auto kEmojiInRow = 40; +#ifdef SUPPORT_IMAGE_GENERATION QImage Generator::generateImage(int variantIndex) { constexpr int kEmojiSizes[kVariantsCount + 1] = { 18, 22, 27, 36, 45, 180 }; constexpr bool kBadSizes[kVariantsCount] = { true, true, false, false, false }; @@ -261,6 +266,7 @@ bool Generator::writeImages() { } return true; } +#endif // SUPPORT_IMAGE_GENERATION bool Generator::writeSource() { source_ = std::make_unique(outputPath_ + ".cpp", project_); diff --git a/Telegram/SourceFiles/codegen/emoji/generator.h b/Telegram/SourceFiles/codegen/emoji/generator.h index 112a9b9b3..a0bf28a8d 100644 --- a/Telegram/SourceFiles/codegen/emoji/generator.h +++ b/Telegram/SourceFiles/codegen/emoji/generator.h @@ -39,8 +39,11 @@ public: int generate(); private: +#ifdef SUPPORT_IMAGE_GENERATION QImage generateImage(int variantIndex); bool writeImages(); +#endif // SUPPORT_IMAGE_GENERATION + bool writeSource(); bool writeHeader(); @@ -56,7 +59,9 @@ private: const common::ProjectInfo &project_; int colorsCount_ = 0; +#ifdef SUPPORT_IMAGE_GENERATION bool writeImages_ = false; +#endif // SUPPORT_IMAGE_GENERATION QString outputPath_; QString spritePath_; std::unique_ptr source_; diff --git a/Telegram/SourceFiles/codegen/emoji/main.cpp b/Telegram/SourceFiles/codegen/emoji/main.cpp index 20095ab01..94e009658 100644 --- a/Telegram/SourceFiles/codegen/emoji/main.cpp +++ b/Telegram/SourceFiles/codegen/emoji/main.cpp @@ -24,7 +24,14 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "codegen/emoji/generator.h" int main(int argc, char *argv[]) { +#ifdef SUPPORT_IMAGE_GENERATION +#ifndef Q_OS_MAC +#error "Image generation is supported only on macOS" +#endif // Q_OS_MAC QGuiApplication app(argc, argv); +#else // SUPPORT_IMAGE_GENERATION + QCoreApplication app(argc, argv); +#endif // SUPPORT_IMAGE_GENERATION auto options = codegen::emoji::parseOptions(); diff --git a/Telegram/SourceFiles/codegen/emoji/options.cpp b/Telegram/SourceFiles/codegen/emoji/options.cpp index 98240f34b..d999ca8ca 100644 --- a/Telegram/SourceFiles/codegen/emoji/options.cpp +++ b/Telegram/SourceFiles/codegen/emoji/options.cpp @@ -50,8 +50,10 @@ Options parseOptions() { } } else if (arg.startsWith("-o")) { result.outputPath = arg.mid(2); +#ifdef SUPPORT_IMAGE_GENERATION } else if (arg == "--images") { result.writeImages = true; +#endif // SUPPORT_IMAGE_GENERATION } } if (result.outputPath.isEmpty()) { diff --git a/Telegram/SourceFiles/codegen/emoji/options.h b/Telegram/SourceFiles/codegen/emoji/options.h index d27877ac2..12a021431 100644 --- a/Telegram/SourceFiles/codegen/emoji/options.h +++ b/Telegram/SourceFiles/codegen/emoji/options.h @@ -28,7 +28,10 @@ namespace emoji { struct Options { QString outputPath = "."; + +#ifdef SUPPORT_IMAGE_GENERATION bool writeImages = false; +#endif // SUPPORT_IMAGE_GENERATION }; // Parsing failed if inputPath is empty in the result.