From bafa76cb36da104f6139f63a22b0e8a5d447f357 Mon Sep 17 00:00:00 2001 From: Anvar Date: Mon, 8 Jan 2024 14:10:48 -0500 Subject: [PATCH] All Files Forgot to create a repository before beginning the project. --- Font_To_Uint_8t.sln | 31 ++++ Font_To_Uint_8t.vcxproj | 147 +++++++++++++++++++ Font_To_Uint_8t.vcxproj.filters | 27 ++++ Font_To_Uint_8t.vcxproj.user | 4 + MyForm.cpp | 13 ++ MyForm.h | 253 ++++++++++++++++++++++++++++++++ MyForm.resx | 120 +++++++++++++++ 7 files changed, 595 insertions(+) create mode 100644 Font_To_Uint_8t.sln create mode 100644 Font_To_Uint_8t.vcxproj create mode 100644 Font_To_Uint_8t.vcxproj.filters create mode 100644 Font_To_Uint_8t.vcxproj.user create mode 100644 MyForm.cpp create mode 100644 MyForm.h create mode 100644 MyForm.resx diff --git a/Font_To_Uint_8t.sln b/Font_To_Uint_8t.sln new file mode 100644 index 0000000..ed246a4 --- /dev/null +++ b/Font_To_Uint_8t.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34330.188 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Font_To_Uint_8t", "Font_To_Uint_8t.vcxproj", "{E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}.Debug|x64.ActiveCfg = Debug|x64 + {E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}.Debug|x64.Build.0 = Debug|x64 + {E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}.Debug|x86.ActiveCfg = Debug|Win32 + {E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}.Debug|x86.Build.0 = Debug|Win32 + {E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}.Release|x64.ActiveCfg = Release|x64 + {E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}.Release|x64.Build.0 = Release|x64 + {E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}.Release|x86.ActiveCfg = Release|Win32 + {E0A2BC4E-2867-42F6-8131-5A78B95A7BC7}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {13239F32-ECE9-47C9-B722-64FF065D3F8F} + EndGlobalSection +EndGlobal diff --git a/Font_To_Uint_8t.vcxproj b/Font_To_Uint_8t.vcxproj new file mode 100644 index 0000000..2e6ba5e --- /dev/null +++ b/Font_To_Uint_8t.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + {e0a2bc4e-2867-42f6-8131-5a78b95a7bc7} + v4.8 + ManagedCProj + Font_To_Uint_8t + 10.0.22621.0 + + + + Application + true + v142 + true + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v143 + true + Unicode + + + Application + false + v143 + true + Unicode + x64 + + + + + + + + + + + + + + + + + + + + + + + Level3 + _DEBUG;%(PreprocessorDefinitions) + + + + Windows + main + + + + + Level3 + WIN32;_DEBUG;%(PreprocessorDefinitions) + + + + Windows + main + + + + + Level3 + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + + Windows + main + + + + + Level3 + NDEBUG;%(PreprocessorDefinitions) + stdcpplatest + stdc17 + + + + Windows + main + + + + + + + + + + + + + + + CppForm + + + + + MyForm.h + + + + + + \ No newline at end of file diff --git a/Font_To_Uint_8t.vcxproj.filters b/Font_To_Uint_8t.vcxproj.filters new file mode 100644 index 0000000..b2bc201 --- /dev/null +++ b/Font_To_Uint_8t.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/Font_To_Uint_8t.vcxproj.user b/Font_To_Uint_8t.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/Font_To_Uint_8t.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/MyForm.cpp b/MyForm.cpp new file mode 100644 index 0000000..9d85dc2 --- /dev/null +++ b/MyForm.cpp @@ -0,0 +1,13 @@ +#include "MyForm.h" + +using namespace System; +using namespace System::Windows::Forms; + +[STAThreadAttribute] + +void main(array^ args) { + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + $safeprojectname$::MyForm form; + Application::Run(% form); +} \ No newline at end of file diff --git a/MyForm.h b/MyForm.h new file mode 100644 index 0000000..0b5e4e9 --- /dev/null +++ b/MyForm.h @@ -0,0 +1,253 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace $safeprojectname$ { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + /// + /// Summary for MyForm + /// + public ref class MyForm : public System::Windows::Forms::Form + { + public: + MyForm(void) + { + InitializeComponent(); + // + //TODO: Add the constructor code here + // + } + + protected: + /// + /// Clean up any resources being used. + /// + ~MyForm() + { + if (components) + { + delete components; + } + } + private: System::Windows::Forms::Label^ label1; + protected: + private: System::Windows::Forms::ComboBox^ comboBox1; + private: System::Windows::Forms::Label^ label2; + private: System::Windows::Forms::Button^ button1; + private: System::Windows::Forms::Label^ label3; + + private: + /// + /// Required designer variable. + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->label1 = (gcnew System::Windows::Forms::Label()); + this->comboBox1 = (gcnew System::Windows::Forms::ComboBox()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->button1 = (gcnew System::Windows::Forms::Button()); + this->label3 = (gcnew System::Windows::Forms::Label()); + this->SuspendLayout(); + // + // label1 + // + this->label1->AutoSize = true; + this->label1->BackColor = System::Drawing::Color::Transparent; + this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->label1->ForeColor = System::Drawing::Color::White; + this->label1->Location = System::Drawing::Point(49, 9); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(481, 29); + this->label1->TabIndex = 0; + this->label1->Text = L"Font TTF / OTF To Unsigned Char (Uint_8t)"; + // + // comboBox1 + // + this->comboBox1->Location = System::Drawing::Point(12, 101); + this->comboBox1->Name = L"comboBox1"; + this->comboBox1->Size = System::Drawing::Size(259, 21); + this->comboBox1->TabIndex = 4; + this->comboBox1->Text = L"Select Font"; + // + // label2 + // + this->label2->AutoSize = true; + this->label2->BackColor = System::Drawing::Color::Transparent; + this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->label2->ForeColor = System::Drawing::Color::White; + this->label2->Location = System::Drawing::Point(7, 69); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(186, 29); + this->label2->TabIndex = 2; + this->label2->Text = L"Font To Convert"; + // + // button1 + // + this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->button1->Location = System::Drawing::Point(316, 76); + this->button1->Name = L"button1"; + this->button1->Size = System::Drawing::Size(214, 46); + this->button1->TabIndex = 3; + this->button1->Text = L"Convert"; + this->button1->UseVisualStyleBackColor = true; + this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); + this->button1->MouseLeave += gcnew System::EventHandler(this, &MyForm::button1_MouseLeave); + this->button1->MouseHover += gcnew System::EventHandler(this, &MyForm::button1_MouseHover); + // + // label3 + // + this->label3->AutoSize = true; + this->label3->BackColor = System::Drawing::Color::Transparent; + this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->label3->ForeColor = System::Drawing::Color::White; + this->label3->Location = System::Drawing::Point(326, 143); + this->label3->Name = L"label3"; + this->label3->Size = System::Drawing::Size(193, 120); + this->label3->TabIndex = 5; + this->label3->Text = L"This will create a .txt file in \r\n(C:/FileConverter)\r\n\r\nThe .txt file will have a" + L" \r\nprinted/converted\r\nfont to hex"; + this->label3->Visible = false; + // + // MyForm + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->BackColor = System::Drawing::Color::FromArgb(static_cast(static_cast(30)), static_cast(static_cast(30)), + static_cast(static_cast(30))); + this->ClientSize = System::Drawing::Size(580, 137); + this->Controls->Add(this->label3); + this->Controls->Add(this->button1); + this->Controls->Add(this->label2); + this->Controls->Add(this->comboBox1); + this->Controls->Add(this->label1); + this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D; + this->Name = L"MyForm"; + this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen; + this->Text = L"Font Converter"; + this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load); + this->ResumeLayout(false); + this->PerformLayout(); + + } +#pragma endregion + // Checks if extention is supported + inline bool contain_ext(const std::filesystem::path& path) + { + static const std::set supported_formats = { + ".ttf", ".otf" + }; + const auto ext = path.extension().string(); + return supported_formats.contains(ext); + } + + private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) + { + // Clear Combo box dropdown + comboBox1->Items->Clear(); + + // Check if FontConverter folder exists + if (const std::filesystem::path font_path = "C:/FontConverter"; exists(font_path)) + { + for (const auto& dir_entry : std::filesystem::directory_iterator(font_path)) + { + if (dir_entry.is_regular_file() && contain_ext(dir_entry.path())) + { + // Add file to combo box (only file names) + comboBox1->Items->Add(gcnew String(dir_entry.path().filename().string().c_str())); + } + } + } + else + { + // Create FontConverter folder + std::filesystem::create_directory(font_path); + } + } + private: System::Void button1_MouseHover(System::Object^ sender, System::EventArgs^ e) + { + MyForm::Size = System::Drawing::Size(600, 325); + label3->Visible = true; + } + private: System::Void button1_MouseLeave(System::Object^ sender, System::EventArgs^ e) { + MyForm::Size = System::Drawing::Size(600, 180); + label3->Visible = false; + } + private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) + { + try + { + const std::size_t bufferSize = 100000; + + // Get selected font + std::string font_name = msclr::interop::marshal_as(comboBox1->SelectedItem->ToString()); + + // Open the TTF file + std::ifstream ttfFile("C:/FontConverter/" + font_name, std::ios::binary); + + if (!ttfFile.is_open()) { + MessageBox::Show("Error opening file", "Error", MessageBoxButtons::OK, MessageBoxIcon::Error); + return; + } + + // Get the size of the file + ttfFile.seekg(0, std::ios::end); + std::streampos fileSize = ttfFile.tellg(); + ttfFile.seekg(0, std::ios::beg); + + // Read the file in chunks + std::vector fontData; + fontData.resize(fileSize); + + std::size_t bytesRead = 0; + while (bytesRead < fileSize) { + ttfFile.read(reinterpret_cast(fontData.data() + bytesRead), bufferSize); + bytesRead += ttfFile.gcount(); + } + + // Print the font data as hex + std::ofstream outFile("C:/FontConverter/" + font_name + ".txt"); + + outFile << "inline constexpr std::uint8_t " << font_name << "[" << fileSize << "] = { "; + + for (std::size_t i = 0; i < fileSize; ++i) { + outFile << "0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(1) << static_cast(fontData[i]) << ", "; + } + + outFile << " };"; + + outFile.close(); + ttfFile.close(); + } + catch (const std::exception& ex) { + MessageBox::Show("Error: " + gcnew String(ex.what()), "Error", MessageBoxButtons::OK, MessageBoxIcon::Error); + return; + } + } + }; +} \ No newline at end of file diff --git a/MyForm.resx b/MyForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MyForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file