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

View File

@ -25,26 +25,22 @@ load_bitmap_char(FT_Face face,
//printf("num_grays %d\n", face->glyph->bitmap.num_grays);
//printf("pitch %d\n", face->glyph->bitmap.pitch);
//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);
assert((face->glyph->bitmap.rows % 8) == 0);
assert(face->glyph->bitmap.width / face->glyph->bitmap.pitch == 8);
//assert((face->glyph->bitmap.rows % 8) == 0);
//assert(face->glyph->bitmap.width / face->glyph->bitmap.pitch == 8);
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_out = 0;
for (unsigned int x = 0; x < face->glyph->bitmap.width; x++) {
int bit;
if (x < face->glyph->bitmap.width) {
bit = (row[x / 8] >> (7 - (x % 8))) & 1;
} else {
bit = 0;
}
if (x % 8 == 0) row_out = 0;
const uint8_t bit = (row[x / 8] >> (7 - (x % 8))) & 1;
//std::cerr << (bit ? "█" : " ");
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';
buf[y] = row_out;
//std::cerr << "|\n";
}
// 'pitch' is bytes; 'width' is pixels