ttf-bitmap: allow arbitrary width/height glyphs
This commit is contained in:
parent
5f290a3e93
commit
fb0b237e0c
@ -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>
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user