Font Testing
This commit is contained in:
@ -7,4 +7,5 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TextureAsset.cpp
|
||||
TrueTypeAsset.cpp
|
||||
)
|
@ -15,20 +15,22 @@ TextureAsset::TextureAsset(AssetManager &assetManager, std::string name) :
|
||||
}
|
||||
|
||||
void TextureAsset::updateSync() {
|
||||
if(this->state == 0x00 || this->state == 0x01) return;
|
||||
if(
|
||||
this->state != 0x03
|
||||
) return;
|
||||
|
||||
this->state = 0x03;
|
||||
this->state = 0x04;
|
||||
this->texture->setSize(this->width, this->height);
|
||||
this->texture->buffer(this->colors);
|
||||
this->state = 0x04;
|
||||
this->state = 0x05;
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
void TextureAsset::updateAsync() {
|
||||
if(this->state != 0x00) return;
|
||||
this->loader.loadRaw(&this->buffer);
|
||||
|
||||
this->state = 0x01;
|
||||
this->loader.loadRaw(&this->buffer);
|
||||
this->state = 0x02;
|
||||
|
||||
// Parse header data.
|
||||
char integer[32];
|
||||
@ -52,7 +54,7 @@ void TextureAsset::updateAsync() {
|
||||
}
|
||||
|
||||
this->colors = (struct Color *)((void *)(this->buffer + i));
|
||||
this->state = 0x02;
|
||||
this->state = 0x03;
|
||||
}
|
||||
|
||||
TextureAsset::~TextureAsset() {
|
||||
|
76
src/dawn/asset/assets/TrueTypeAsset.cpp
Normal file
76
src/dawn/asset/assets/TrueTypeAsset.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TrueTypeAsset.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TrueTypeAsset::TrueTypeAsset(AssetManager &assMan, std::string name) :
|
||||
Asset(assMan, name),
|
||||
loader(name + ".truetype")
|
||||
{
|
||||
}
|
||||
|
||||
void TrueTypeAsset::updateSync() {
|
||||
if(this->state != 0x04) return;
|
||||
this->font.texture.setSize(this->width, this->height);
|
||||
this->font.texture.buffer(this->pixels);
|
||||
auto i = this->pixels;
|
||||
memoryCopy(
|
||||
this->characterData,
|
||||
this->font.characterData,
|
||||
sizeof(truetypechar_t) * TRUETYPE_NUM_CHARS
|
||||
);
|
||||
this->state = 0x05;
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
void TrueTypeAsset::updateAsync() {
|
||||
int32_t fontSize;
|
||||
size_t i, j;
|
||||
char intBuffer[32];
|
||||
char c;
|
||||
|
||||
if(this->state != 0x00) return;
|
||||
|
||||
this->state = 0x01;
|
||||
this->loader.loadRaw(&this->buffer);
|
||||
this->state = 0x02;
|
||||
|
||||
// Parse header data.
|
||||
i = j = 0;
|
||||
width = -1, height = -1, fontSize = -1;
|
||||
while(true) {
|
||||
c = this->buffer[i++];
|
||||
if(c == '|') {
|
||||
intBuffer[j] = '\0';
|
||||
if(width == -1) {
|
||||
this->width = atoi(intBuffer);
|
||||
j = 0;
|
||||
continue;
|
||||
} else if(height == -1) {
|
||||
this->height = atoi(intBuffer);
|
||||
j = 0;
|
||||
continue;
|
||||
} else {
|
||||
fontSize = atoi(intBuffer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
intBuffer[j++] = c;
|
||||
}
|
||||
|
||||
this->state = 0x03;
|
||||
this->font.fontSize = fontSize;
|
||||
this->pixels = (struct Color*)(this->buffer + i);
|
||||
this->characterData = (truetypechar_t*)(
|
||||
(uint8_t*)this->pixels + (this->width * this->height * sizeof(struct Color))
|
||||
);
|
||||
this->state = 0x04;
|
||||
}
|
||||
|
||||
TrueTypeAsset::~TrueTypeAsset() {
|
||||
|
||||
}
|
30
src/dawn/asset/assets/TrueTypeAsset.hpp
Normal file
30
src/dawn/asset/assets/TrueTypeAsset.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../Asset.hpp"
|
||||
#include "../AssetLoader.hpp"
|
||||
#include "display/font/TrueTypeFont.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TrueTypeAsset : public Asset {
|
||||
protected:
|
||||
AssetLoader loader;
|
||||
uint8_t *buffer = nullptr;
|
||||
truetypechar_t *characterData = nullptr;
|
||||
struct Color *pixels = nullptr;
|
||||
int32_t width, height;
|
||||
|
||||
public:
|
||||
TrueTypeFont font;
|
||||
|
||||
TrueTypeAsset(AssetManager &assMan, std::string name);
|
||||
|
||||
void updateSync() override;
|
||||
void updateAsync() override;
|
||||
|
||||
~TrueTypeAsset();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user