1 // This file is part of Desktop App Toolkit,
2 // a set of libraries for developing nice desktop applications.
3 //
4 // For license and copyright information please follow this link:
5 // https://github.com/desktop-app/legal/blob/master/LEGAL
6 //
7 #pragma once
8 
9 #include <memory>
10 #include <QtCore/QString>
11 #include <QtCore/QSet>
12 #include <QtGui/QImage>
13 #include "codegen/common/cpp_file.h"
14 #include "codegen/emoji/options.h"
15 #include "codegen/emoji/data.h"
16 #include "codegen/emoji/replaces.h"
17 
18 namespace codegen {
19 namespace emoji {
20 
21 using uint32 = unsigned int;
22 
23 class Generator {
24 public:
25 	Generator(const Options &options);
26 	Generator(const Generator &other) = delete;
27 	Generator &operator=(const Generator &other) = delete;
28 
29 	int generate();
30 
31 private:
32 	[[nodiscard]] QImage generateImage(int imageIndex);
33 	bool writeImages();
34 
35 	bool writeSource();
36 	bool writeHeader();
37 	bool writeSuggestionsSource();
38 	bool writeSuggestionsHeader();
39 
40 	template <typename Callback>
41 	bool enumerateWholeList(Callback callback);
42 
43 	bool writeInitCode();
44 	bool writeSections();
45 	bool writeReplacements();
46 	bool writeGetSections();
47 	bool writeFindReplace();
48 	bool writeFind();
49 	bool writeFindFromDictionary(
50 		const std::map<QString, int, std::greater<QString>> &dictionary,
51 		bool skipPostfixes = false,
52 		const std::set<int> &postfixRequired = {});
53 	bool writeGetReplacements();
54 	void startBinary();
55 	bool writeStringBinary(common::CppFile *source, const QString &string);
56 	void writeIntBinary(common::CppFile *source, int data);
57 	void writeUintBinary(common::CppFile *source, uint32 data);
58 
59 	const common::ProjectInfo &project_;
60 	int colorsCount_ = 0;
61 	QString writeImages_;
62 	QString outputPath_;
63 	QString spritePath_;
64 	std::unique_ptr<common::CppFile> source_;
65 	Data data_;
66 
67 	QString suggestionsPath_;
68 	std::unique_ptr<common::CppFile> suggestionsSource_;
69 	Replaces replaces_;
70 
71 	int _binaryFullLength = 0;
72 	int _binaryCount = 0;
73 
74 };
75 
76 } // namespace emoji
77 } // namespace codegen
78