Font loading progress
This commit is contained in:
73
src/dawn/asset/assets/NewTrueTypeAsset.cpp
Normal file
73
src/dawn/asset/assets/NewTrueTypeAsset.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "NewTrueTypeAsset.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
NewTrueTypeAsset::NewTrueTypeAsset(AssetManager *assMan, std::string name) :
|
||||
Asset(assMan, name),
|
||||
loader(name + ".newtruetype")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NewTrueTypeAsset::updateSync() {
|
||||
|
||||
}
|
||||
|
||||
void NewTrueTypeAsset::updateAsync() {
|
||||
if(this->state != NEW_TRUE_TYPE_ASSET_STATE_INITIAL) return;
|
||||
|
||||
|
||||
this->state = NEW_TRUE_TYPE_ASSET_STATE_OPEN;
|
||||
this->loader.open();
|
||||
|
||||
this->state = NEW_TRUE_TYPE_ASSET_STATE_VALIDATE_HEADER;
|
||||
|
||||
char buffer[1024];
|
||||
this->loader.rewind();
|
||||
size_t read = this->loader.read(buffer, sizeof(char) * 6);
|
||||
assertTrue(read == (6 * sizeof(char)));
|
||||
buffer[6] = '\0';
|
||||
|
||||
// Confirm "DE_TTF"
|
||||
assertTrue(std::string(buffer) == "DE_TTF");
|
||||
|
||||
// Vertical bar
|
||||
this->loader.read(buffer, 1);
|
||||
assertTrue(buffer[0] == '|');
|
||||
|
||||
// Read version
|
||||
this->state = NEW_TRUE_TYPE_ASSET_STATE_VALIDATE_VERSION;
|
||||
read = this->loader.read(buffer, sizeof(char) * 5);
|
||||
assertTrue(buffer[0] == '3');
|
||||
assertTrue(buffer[1] == '.');
|
||||
assertTrue(buffer[2] == '0');
|
||||
assertTrue(buffer[3] == '0');
|
||||
assertTrue(buffer[4] == '|');
|
||||
|
||||
// Read the count of font styles / variants.
|
||||
this->state = NEW_TRUE_TYPE_ASSET_STATE_READ_VARIANT_COUNT;
|
||||
read = this->loader.read(buffer, 64);
|
||||
assertTrue(read > 0);
|
||||
|
||||
// Get position of vertical bar.
|
||||
size_t i = 0;
|
||||
while(buffer[i] != '|' && i < 64) i++;
|
||||
assertTrue(buffer[i] == '|');
|
||||
buffer[i] = '\0';
|
||||
|
||||
int32_t count = atoi(buffer);
|
||||
assertTrue(count > 0);
|
||||
|
||||
// Now begin parsing each font style
|
||||
while(true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
NewTrueTypeAsset::~NewTrueTypeAsset() {
|
||||
}
|
Reference in New Issue
Block a user