Removed old TrueType
This commit is contained in:
@@ -26,5 +26,4 @@ add_subdirectory(prefabtool)
|
||||
add_subdirectory(scenetool)
|
||||
add_subdirectory(texturetool)
|
||||
add_subdirectory(truetypetool)
|
||||
add_subdirectory(vnscenetool)
|
||||
add_subdirectory(newtruetypetool)
|
||||
add_subdirectory(vnscenetool)
|
@@ -1,70 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
project(newtruetypetool VERSION 3.0)
|
||||
add_executable(newtruetypetool)
|
||||
|
||||
target_sources(newtruetypetool
|
||||
PRIVATE
|
||||
${DAWN_SHARED_SOURCES}
|
||||
${DAWN_TOOL_SOURCES}
|
||||
NewTrueTypeTool.cpp
|
||||
)
|
||||
|
||||
target_include_directories(newtruetypetool
|
||||
PUBLIC
|
||||
${DAWN_SHARED_INCLUDES}
|
||||
${DAWN_TOOL_INCLUDES}
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Definitions
|
||||
target_compile_definitions(newtruetypetool
|
||||
PUBLIC
|
||||
${DAWN_SHARED_DEFINITIONS}
|
||||
DAWN_TOOL_INSTANCE=NewTrueTypeTool
|
||||
DAWN_TOOL_HEADER="NewTrueTypeTool.hpp"
|
||||
)
|
||||
|
||||
# Libraries
|
||||
target_link_libraries(newtruetypetool
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
)
|
||||
|
||||
# Tool Function
|
||||
function(tool_newtruetype target)
|
||||
# Defaults
|
||||
set(FILE "" )
|
||||
|
||||
# Parse Args
|
||||
foreach(_PAIR IN LISTS ARGN)
|
||||
if (_PAIR MATCHES "^([^:]+)=(.*)$")
|
||||
set(${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
|
||||
else()
|
||||
message(FATAL_ERROR "Invalid pair: ${_PAIR}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Check for missing args
|
||||
|
||||
set(DEPS "")
|
||||
if(DAWN_BUILD_TOOLS)
|
||||
set(DEPS truetypetool)
|
||||
endif()
|
||||
|
||||
|
||||
add_custom_target(${target}
|
||||
COMMAND newtruetypetool
|
||||
--output="${DAWN_ASSETS_BUILD_DIR}/${target}.newtruetype"
|
||||
--regular="${REGULAR}"
|
||||
--bold="${BOLD}"
|
||||
--italics="${ITALICS}"
|
||||
--bold-italics="${BOLD_ITALICS}"
|
||||
COMMENT "Generating newtruetype"
|
||||
DEPENDS ${DEPS}
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${target})
|
||||
endfunction()
|
@@ -1,164 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "NewTrueTypeTool.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
NewTrueTypeFile::NewTrueTypeFile(std::string path) : file(path) {
|
||||
this->path = path;
|
||||
|
||||
// Remove extension
|
||||
size_t pos = path.find_last_of(".");
|
||||
std::string filename = path.substr(0, pos);
|
||||
|
||||
|
||||
style = 0;
|
||||
if(path.find("bold") != std::string::npos || filename.ends_with("bd") || filename.ends_with("bi")) {
|
||||
style |= NEW_TRUETYPE_VARIANT_BOLD;
|
||||
}
|
||||
if(path.find("italics") != std::string::npos || filename.ends_with("i") || filename.ends_with("bi")) {
|
||||
style |= NEW_TRUETYPE_VARIANT_ITALICS;
|
||||
}
|
||||
|
||||
if(!file.exists()) {
|
||||
std::cout << "File " << path << " does not exist!" << std::endl;
|
||||
throw "File not found";
|
||||
}
|
||||
|
||||
if(!file.open(FILE_MODE_READ)) {
|
||||
std::cout << "Failed to open file " << path << " for reading!" << std::endl;
|
||||
throw "Unable to open file for reading!";
|
||||
}
|
||||
}
|
||||
|
||||
NewTrueTypeFile::~NewTrueTypeFile() {
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> NewTrueTypeTool::getRequiredFlags() {
|
||||
return { "output" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> NewTrueTypeTool::getOptionalFlags() {
|
||||
return {
|
||||
{ "regular", "" },
|
||||
{ "italics", "" },
|
||||
{ "bold", "" },
|
||||
{ "bold-italics", "" }
|
||||
};
|
||||
}
|
||||
|
||||
int32_t NewTrueTypeTool::start() {
|
||||
std::vector<NewTrueTypeFile*> files;
|
||||
std::vector<std::string> flags = { "regular", "italics", "bold", "bold-italics" };
|
||||
|
||||
auto cleanupFiles = [&]() {
|
||||
auto itFile = files.begin();
|
||||
while(itFile != files.end()) {
|
||||
auto file = *itFile;
|
||||
delete file;
|
||||
++itFile;
|
||||
}
|
||||
};
|
||||
|
||||
// For each flag
|
||||
auto itFlag = flags.begin();
|
||||
while(itFlag != flags.end()) {
|
||||
std::string flag = *itFlag;
|
||||
std::string path = this->flags[flag];
|
||||
|
||||
if(path.empty()) {
|
||||
++itFlag;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
auto n = new NewTrueTypeFile(path);
|
||||
files.push_back(n);
|
||||
} catch(const char *e) {
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
++itFlag;
|
||||
}
|
||||
|
||||
if(files.size() == 0) {
|
||||
std::cout << "No valid TTF files provided!" << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create the output file
|
||||
File fileOut = File(this->flags["output"]);
|
||||
if(!fileOut.mkdirp()) {
|
||||
std::cout << "Failed to create output directory!" << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
if(!fileOut.open(FILE_MODE_WRITE)) {
|
||||
std::cout << "Failed to open output file for writing!" << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Prepare to write data
|
||||
std::string header = "DE_TTF|3.00|";
|
||||
|
||||
// Write file count
|
||||
header += std::to_string(files.size()) + "|";
|
||||
|
||||
// For each file
|
||||
auto itFile = files.begin();
|
||||
while(itFile != files.end()) {
|
||||
auto file = *itFile;
|
||||
// Style
|
||||
header += std::to_string(file->style);
|
||||
header += ":";
|
||||
// File length
|
||||
header += std::to_string(file->file.length);
|
||||
header += "|";
|
||||
++itFile;
|
||||
}
|
||||
|
||||
if(!fileOut.writeRaw((char *)header.c_str(), header.length())) {
|
||||
std::cout << "Failed to write TTF Header to " << fileOut.filename << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Now write the data for each file
|
||||
itFile = files.begin();
|
||||
while(itFile != files.end()) {
|
||||
auto file = *itFile;
|
||||
|
||||
// Write the file data
|
||||
file->file.setPosition(0);
|
||||
if(!fileOut.copyRaw(&file->file, file->file.length)) {
|
||||
std::cout << "Failed copy output data of " << file->file.filename << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write vertical bar
|
||||
char sep[1];
|
||||
sep[0] = '|';
|
||||
fileOut.writeRaw(sep, 1);
|
||||
|
||||
++itFile;
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
itFile = files.begin();
|
||||
while(itFile != files.end()) {
|
||||
auto file = *itFile;
|
||||
delete file;
|
||||
++itFile;
|
||||
}
|
||||
|
||||
// Done
|
||||
fileOut.close();
|
||||
return 0;
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/DawnTool.hpp"
|
||||
#include "util/File.hpp"
|
||||
#include "display/font/truetype/NewTrueTypeShared.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class NewTrueTypeFile {
|
||||
public:
|
||||
flag_t style;
|
||||
std::string path;
|
||||
File file;
|
||||
|
||||
NewTrueTypeFile(std::string path);
|
||||
~NewTrueTypeFile();
|
||||
};
|
||||
|
||||
class NewTrueTypeTool : public DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
std::map<std::string, std::string> getOptionalFlags() override;
|
||||
|
||||
public:
|
||||
int32_t start();
|
||||
};
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
project(truetypetool VERSION 2.0)
|
||||
project(truetypetool VERSION 3.0)
|
||||
add_executable(truetypetool)
|
||||
|
||||
target_sources(truetypetool
|
||||
@@ -32,7 +32,6 @@ target_compile_definitions(truetypetool
|
||||
target_link_libraries(truetypetool
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
stb
|
||||
)
|
||||
|
||||
# Tool Function
|
||||
@@ -50,20 +49,21 @@ function(tool_truetype target)
|
||||
endforeach()
|
||||
|
||||
# Check for missing args
|
||||
if(NOT DEFINED FILE)
|
||||
message(FATAL_ERROR "Missing FILE input")
|
||||
endif()
|
||||
|
||||
set(DEPS "")
|
||||
if(DAWN_BUILD_TOOLS)
|
||||
set(DEPS truetypetool)
|
||||
endif()
|
||||
|
||||
|
||||
add_custom_target(${target}
|
||||
COMMAND truetypetool
|
||||
--input="${DAWN_ASSETS_SOURCE_DIR}/${FILE}"
|
||||
--output="${DAWN_ASSETS_BUILD_DIR}/${target}"
|
||||
COMMENT "Generating truetype font ${target} from ${in}"
|
||||
--output="${DAWN_ASSETS_BUILD_DIR}/${target}.truetype"
|
||||
--regular="${REGULAR}"
|
||||
--bold="${BOLD}"
|
||||
--italics="${ITALICS}"
|
||||
--bold-italics="${BOLD_ITALICS}"
|
||||
COMMENT "Generating truetype"
|
||||
DEPENDS ${DEPS}
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${target})
|
||||
|
@@ -4,69 +4,161 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TrueTypeTool.hpp"
|
||||
#ifndef STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <stb_truetype.h>
|
||||
#endif
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TrueTypeFile::TrueTypeFile(std::string path) : file(path) {
|
||||
this->path = path;
|
||||
|
||||
// Remove extension
|
||||
size_t pos = path.find_last_of(".");
|
||||
std::string filename = path.substr(0, pos);
|
||||
|
||||
|
||||
style = 0;
|
||||
if(path.find("bold") != std::string::npos || filename.ends_with("bd") || filename.ends_with("bi")) {
|
||||
style |= TRUE_TYPE_VARIANT_BOLD;
|
||||
}
|
||||
if(path.find("italics") != std::string::npos || filename.ends_with("i") || filename.ends_with("bi")) {
|
||||
style |= TRUE_TYPE_VARIANT_ITALICS;
|
||||
}
|
||||
|
||||
if(!file.exists()) {
|
||||
std::cout << "File " << path << " does not exist!" << std::endl;
|
||||
throw "File not found";
|
||||
}
|
||||
|
||||
if(!file.open(FILE_MODE_READ)) {
|
||||
std::cout << "Failed to open file " << path << " for reading!" << std::endl;
|
||||
throw "Unable to open file for reading!";
|
||||
}
|
||||
}
|
||||
|
||||
TrueTypeFile::~TrueTypeFile() {
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> TrueTypeTool::getRequiredFlags() {
|
||||
return { "input", "output" };
|
||||
return { "output" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> TrueTypeTool::getOptionalFlags() {
|
||||
return {
|
||||
{ "regular", "" },
|
||||
{ "italics", "" },
|
||||
{ "bold", "" },
|
||||
{ "bold-italics", "" }
|
||||
};
|
||||
}
|
||||
|
||||
int32_t TrueTypeTool::start() {
|
||||
File fileIn(flags["input"]);
|
||||
char *ttfData = nullptr;
|
||||
if(!fileIn.readToBuffer(&ttfData)) {
|
||||
std::cout << "Failed to read file to buffer!" << std::endl;
|
||||
std::vector<TrueTypeFile*> files;
|
||||
std::vector<std::string> flags = { "regular", "italics", "bold", "bold-italics" };
|
||||
|
||||
auto cleanupFiles = [&]() {
|
||||
auto itFile = files.begin();
|
||||
while(itFile != files.end()) {
|
||||
auto file = *itFile;
|
||||
delete file;
|
||||
++itFile;
|
||||
}
|
||||
};
|
||||
|
||||
// For each flag
|
||||
auto itFlag = flags.begin();
|
||||
while(itFlag != flags.end()) {
|
||||
std::string flag = *itFlag;
|
||||
std::string path = this->flags[flag];
|
||||
|
||||
if(path.empty()) {
|
||||
++itFlag;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
auto n = new TrueTypeFile(path);
|
||||
files.push_back(n);
|
||||
} catch(const char *e) {
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
++itFlag;
|
||||
}
|
||||
|
||||
if(files.size() == 0) {
|
||||
std::cout << "No valid TTF files provided!" << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create bitmap data. This is a single channel color (alpha).
|
||||
size_t width = 1024;
|
||||
size_t height = 1024;
|
||||
float_t fontSize = 128.0f;
|
||||
size_t textureSize = width * height;
|
||||
stbi_uc *bitmapData = new stbi_uc[textureSize];
|
||||
stbtt_bakedchar characterData[TRUETYPE_NUM_CHARS];
|
||||
|
||||
// Now parse the TTF itself.
|
||||
stbtt_BakeFontBitmap(
|
||||
(uint8_t*)ttfData, 0, (float)fontSize, bitmapData,
|
||||
width, height,
|
||||
TRUETYPE_FIRST_CHAR, TRUETYPE_NUM_CHARS,
|
||||
characterData
|
||||
);
|
||||
|
||||
// Prepare output file for writing.
|
||||
File fileOut(flags["output"] + ".truetype");
|
||||
// Create the output file
|
||||
File fileOut = File(this->flags["output"]);
|
||||
if(!fileOut.mkdirp()) {
|
||||
free(ttfData);
|
||||
delete bitmapData;
|
||||
std::cout << "Failed to create output directory!" << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
if(!fileOut.open(FILE_MODE_WRITE)) {
|
||||
free(ttfData);
|
||||
delete bitmapData;
|
||||
std::cout << "Failed to open output file for writing!" << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Prepare to write data
|
||||
std::string header = "DE_TTF|3.00|";
|
||||
|
||||
// Write file count
|
||||
header += std::to_string(files.size()) + "|";
|
||||
|
||||
// For each file
|
||||
auto itFile = files.begin();
|
||||
while(itFile != files.end()) {
|
||||
auto file = *itFile;
|
||||
// Style
|
||||
header += std::to_string(file->style);
|
||||
header += ":";
|
||||
// File length
|
||||
header += std::to_string(file->file.length);
|
||||
header += "|";
|
||||
++itFile;
|
||||
}
|
||||
|
||||
if(!fileOut.writeRaw((char *)header.c_str(), header.length())) {
|
||||
std::cout << "Failed to write TTF Header to " << fileOut.filename << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write data
|
||||
fileOut.writeString(std::to_string(width) + "|" + std::to_string(height) + "|" + std::to_string(fontSize) + "|");
|
||||
uint8_t pixels[1];
|
||||
for(size_t i = 0; i < textureSize; i++) {
|
||||
pixels[0] = bitmapData[i];
|
||||
fileOut.writeRaw((char*)pixels, 1);
|
||||
// Now write the data for each file
|
||||
itFile = files.begin();
|
||||
while(itFile != files.end()) {
|
||||
auto file = *itFile;
|
||||
|
||||
// Write the file data
|
||||
file->file.setPosition(0);
|
||||
if(!fileOut.copyRaw(&file->file, file->file.length)) {
|
||||
std::cout << "Failed copy output data of " << file->file.filename << std::endl;
|
||||
cleanupFiles();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write vertical bar
|
||||
char sep[1];
|
||||
sep[0] = '|';
|
||||
fileOut.writeRaw(sep, 1);
|
||||
|
||||
++itFile;
|
||||
}
|
||||
|
||||
// Write quads
|
||||
fileOut.writeRaw((char*)characterData, sizeof(stbtt_bakedchar) * TRUETYPE_NUM_CHARS);
|
||||
free(ttfData);
|
||||
delete bitmapData;
|
||||
// Cleanup
|
||||
itFile = files.begin();
|
||||
while(itFile != files.end()) {
|
||||
auto file = *itFile;
|
||||
delete file;
|
||||
++itFile;
|
||||
}
|
||||
|
||||
// Done
|
||||
fileOut.close();
|
||||
|
||||
return 0;
|
||||
}
|
@@ -6,15 +6,23 @@
|
||||
#pragma once
|
||||
#include "util/DawnTool.hpp"
|
||||
#include "util/File.hpp"
|
||||
#include "util/Image.hpp"
|
||||
|
||||
#define TRUETYPE_FIRST_CHAR 32
|
||||
#define TRUETYPE_NUM_CHARS 96
|
||||
#include "display/font/truetype/TrueTypeShared.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TrueTypeFile {
|
||||
public:
|
||||
flag_t style;
|
||||
std::string path;
|
||||
File file;
|
||||
|
||||
TrueTypeFile(std::string path);
|
||||
~TrueTypeFile();
|
||||
};
|
||||
|
||||
class TrueTypeTool : public DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
std::map<std::string, std::string> getOptionalFlags() override;
|
||||
|
||||
public:
|
||||
int32_t start();
|
||||
|
Reference in New Issue
Block a user