ttf-bitmap: allow arbitrary width/height glyphs

This commit is contained in:
Zack Buhman 2024-02-02 08:49:21 +08:00
parent 5f290a3e93
commit fb0b237e0c
3 changed files with 20 additions and 18 deletions

View File

@ -15,6 +15,7 @@ struct vec<4, T>
inline constexpr vec(); inline constexpr vec();
inline constexpr vec(T scalar); inline constexpr vec(T scalar);
inline constexpr vec(T _x, T _y, T _z, T _w); inline constexpr vec(T _x, T _y, T _z, T _w);
inline constexpr vec(vec<3, T> const& xyz, T w);
constexpr inline vec<4, T> operator-() const; constexpr inline vec<4, T> operator-() const;
inline constexpr T const& operator[](int i) const; inline constexpr T const& operator[](int i) const;
@ -34,8 +35,13 @@ inline constexpr vec<4, T>::vec(T scalar)
{} {}
template <typename T> template <typename T>
inline constexpr vec<4, T>::vec(T _x, T _y, T _z, T _w) inline constexpr vec<4, T>::vec(T x, T y, T z, T w)
: x(_x), y(_y), z(_z), w(_w) : x(x), y(y), z(z), w(w)
{}
template <typename T>
inline constexpr vec<4, T>::vec(vec<3, T> const& xyz, T w)
: x(xyz.x), y(xyz.y), z(xyz.z), w(w)
{} {}
template <typename T> template <typename T>

View File

@ -666,7 +666,7 @@ void init_slots()
scsp.reg.ctrl.MIXER = MIXER__MEM4MB | MIXER__MVOL(0); scsp.reg.ctrl.MIXER = MIXER__MEM4MB | MIXER__MVOL(0);
for (long i = 0; i < 3200; i++) { asm volatile ("nop"); } // wait for (way) more than 30µs for (long i = 0; i < 3200; i++) { asm volatile ("nop"); } // wait for (way) more than 30µs
/* /*
The Saturn BIOS does not (un)initialize the DSP. Without zeroizing the DSP The Saturn BIOS does not (un)initialize the DSP. Without zeroizing the DSP
program, the SCSP DSP appears to have a program that continuously writes to program, the SCSP DSP appears to have a program that continuously writes to

View File

@ -12,7 +12,7 @@ load_bitmap_char(FT_Face face,
FT_ULong char_code, FT_ULong char_code,
uint8_t * buf) uint8_t * buf)
{ {
FT_Error error; FT_Error error;
FT_UInt glyph_index = FT_Get_Char_Index(face, char_code); FT_UInt glyph_index = FT_Get_Char_Index(face, char_code);
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
@ -25,26 +25,22 @@ load_bitmap_char(FT_Face face,
//printf("num_grays %d\n", face->glyph->bitmap.num_grays); //printf("num_grays %d\n", face->glyph->bitmap.num_grays);
//printf("pitch %d\n", face->glyph->bitmap.pitch); //printf("pitch %d\n", face->glyph->bitmap.pitch);
//printf("width %d\n", face->glyph->bitmap.width); //printf("width %d\n", face->glyph->bitmap.width);
assert(face->glyph->bitmap.width == 8);
//printf("char_code %lx rows %d\n", char_code, face->glyph->bitmap.rows); //printf("char_code %lx rows %d\n", char_code, face->glyph->bitmap.rows);
assert((face->glyph->bitmap.rows % 8) == 0); //assert((face->glyph->bitmap.rows % 8) == 0);
assert(face->glyph->bitmap.width / face->glyph->bitmap.pitch == 8); //assert(face->glyph->bitmap.width / face->glyph->bitmap.pitch == 8);
for (int y = 0; y < (int)face->glyph->bitmap.rows; y++) { for (int y = 0; y < (int)face->glyph->bitmap.rows; y++) {
uint8_t * row = &face->glyph->bitmap.buffer[y * face->glyph->bitmap.pitch]; uint8_t * row = &face->glyph->bitmap.buffer[y * face->glyph->bitmap.pitch];
uint8_t row_out = 0; uint8_t row_out = 0;
for (unsigned int x = 0; x < face->glyph->bitmap.width; x++) { for (unsigned int x = 0; x < face->glyph->bitmap.width; x++) {
int bit; if (x % 8 == 0) row_out = 0;
if (x < face->glyph->bitmap.width) { const uint8_t bit = (row[x / 8] >> (7 - (x % 8))) & 1;
bit = (row[x / 8] >> (7 - (x % 8))) & 1;
} else {
bit = 0;
}
//std::cerr << (bit ? "█" : " "); //std::cerr << (bit ? "█" : " ");
row_out |= (bit << (7 - (x % 8))); row_out |= (bit << (7 - (x % 8)));
if (x % 8 == 7 || x == (face->glyph->bitmap.width - 1))
buf[(y * face->glyph->bitmap.pitch) + (x / 8)] = row_out;
} }
//std::cerr << '\n'; //std::cerr << "|\n";
buf[y] = row_out;
} }
// 'pitch' is bytes; 'width' is pixels // 'pitch' is bytes; 'width' is pixels
@ -78,7 +74,7 @@ int main(int argc, char *argv[])
auto end = parse_num<uint32_t>(std::hex, argv[2]); auto end = parse_num<uint32_t>(std::hex, argv[2]);
auto font_file_path = argv[3]; auto font_file_path = argv[3];
auto output_file_path = argv[4]; auto output_file_path = argv[4];
error = FT_Init_FreeType(&library); error = FT_Init_FreeType(&library);
if (error) { if (error) {
std::cerr << "FT_Init_FreeType\n"; std::cerr << "FT_Init_FreeType\n";
@ -90,7 +86,7 @@ int main(int argc, char *argv[])
std::cerr << "FT_New_Face\n"; std::cerr << "FT_New_Face\n";
return -1; return -1;
} }
error = FT_Select_Size(face, 0); error = FT_Select_Size(face, 0);
if (error) { if (error) {
std::cerr << "FT_Select_Size: " << FT_Error_String(error) << ' ' << error << '\n'; std::cerr << "FT_Select_Size: " << FT_Error_String(error) << ' ' << error << '\n';