Mid prog font
This commit is contained in:
@ -82,6 +82,7 @@ namespace Dawn {
|
||||
* @param color Color to fill.
|
||||
*/
|
||||
virtual void fill(struct Color) = 0;
|
||||
virtual void fill(uint8_t) = 0;
|
||||
|
||||
/**
|
||||
* Returns true only when the texture has been loaded, sized and put on
|
||||
|
@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
ExampleFont.cpp
|
||||
TrueTypeFont.cpp
|
||||
FontMeasure.cpp
|
||||
NewTrueType.cpp
|
||||
)
|
68
src/dawn/display/font/NewTrueType.cpp
Normal file
68
src/dawn/display/font/NewTrueType.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "NewTrueType.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void Dawn::_newTrueTypePlaceholder(
|
||||
FT_Face face,
|
||||
Texture &texture,
|
||||
std::map<FT_ULong, struct TrueTypeCharacterInfo> &charStore
|
||||
) {
|
||||
size_t w = 0, h = 0;
|
||||
FT_ULong c;
|
||||
|
||||
for(c = NEW_TRUETYPE_CHAR_BEGIN; c < NEW_TRUETYPE_CHAR_END; c++) {
|
||||
// Load the character
|
||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
|
||||
// Update the width and height
|
||||
w = mathMax<size_t>(w, face->glyph->bitmap.width);
|
||||
h += face->glyph->bitmap.rows;
|
||||
}
|
||||
|
||||
|
||||
// Now buffer pixels to the texture
|
||||
float_t y = 0;
|
||||
|
||||
// I'd love to just buffer straight to the GPU, but it seems that is a bit
|
||||
// unstable right now.
|
||||
uint8_t *buffer = (uint8_t *)memoryAllocate(w * h * sizeof(uint8_t));
|
||||
memorySet(buffer, 0x00, sizeof(uint8_t) * w * h);
|
||||
|
||||
size_t offset = 0;
|
||||
for(c = NEW_TRUETYPE_CHAR_BEGIN; c < NEW_TRUETYPE_CHAR_END; c++) {
|
||||
// Load the character
|
||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
|
||||
// Store the character information
|
||||
struct TrueTypeCharacterInfo info;
|
||||
info.advance = glm::vec2(face->glyph->advance.x, face->glyph->advance.y);
|
||||
info.bitmapSize = glm::vec2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
|
||||
info.bitmapPosition = glm::vec2(face->glyph->bitmap_left, face->glyph->bitmap_top);
|
||||
info.textureY = y;
|
||||
charStore[c] = info;
|
||||
|
||||
// Buffer the pixels, oh dear GOD there has to be a more efficient way.
|
||||
for(int32_t i = 0; i < face->glyph->bitmap.rows; i++) {
|
||||
memoryCopy(
|
||||
(void *)(face->glyph->bitmap.buffer + (i * face->glyph->bitmap.width)),
|
||||
(void *)(buffer + offset),
|
||||
face->glyph->bitmap.width * sizeof(uint8_t)
|
||||
);
|
||||
offset += w * sizeof(uint8_t);
|
||||
}
|
||||
y += face->glyph->bitmap.rows;
|
||||
}
|
||||
|
||||
texture.setSize(w, h, TEXTURE_FORMAT_R);
|
||||
texture.buffer(buffer);
|
||||
memoryFree(buffer);
|
||||
}
|
27
src/dawn/display/font/NewTrueType.hpp
Normal file
27
src/dawn/display/font/NewTrueType.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
#define NEW_TRUETYPE_CHAR_BEGIN 0x00
|
||||
#define NEW_TRUETYPE_CHAR_END 0xFF
|
||||
|
||||
namespace Dawn {
|
||||
struct TrueTypeCharacterInfo {
|
||||
glm::vec2 advance;
|
||||
glm::vec2 bitmapSize;
|
||||
glm::vec2 bitmapPosition;
|
||||
float_t textureY;
|
||||
};
|
||||
|
||||
void _newTrueTypePlaceholder(
|
||||
FT_Face face,
|
||||
Texture &texture,
|
||||
std::map<FT_ULong, struct TrueTypeCharacterInfo> &charStore
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user