kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Small improvements to rotated font rendering
rodzic
841c141ebf
commit
cdd648f3f6
|
@ -41,7 +41,8 @@ namespace alright_fonts {
|
|||
}
|
||||
}
|
||||
|
||||
void render_character(text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t<int> origin, pretty_poly::mat3_t transform) {
|
||||
template<typename mat_t>
|
||||
void render_character(text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t<int> origin, mat_t transform) {
|
||||
if(tm.face.glyphs.count(codepoint) == 1) {
|
||||
glyph_t glyph = tm.face.glyphs[codepoint];
|
||||
|
||||
|
@ -51,26 +52,35 @@ namespace alright_fonts {
|
|||
unsigned scale = tm.size << 9;
|
||||
|
||||
std::vector<pretty_poly::contour_t<int8_t>> contours;
|
||||
contours.reserve(glyph.contours.size());
|
||||
|
||||
unsigned int total_points = 0;
|
||||
for(auto i = 0u; i < glyph.contours.size(); i++) {
|
||||
total_points += glyph.contours[i].count;;
|
||||
}
|
||||
|
||||
point_t<int8_t> *points = (point_t<int8_t> *)malloc(sizeof(point_t<int8_t>) * total_points);
|
||||
|
||||
for(auto i = 0u; i < glyph.contours.size(); i++) {
|
||||
unsigned int count = glyph.contours[i].count;
|
||||
point_t<int8_t> *points = (point_t<int8_t> *)malloc(sizeof(point_t<int8_t>) * count);
|
||||
const unsigned int count = glyph.contours[i].count;
|
||||
for(auto j = 0u; j < count; j++) {
|
||||
point_t<float> point(glyph.contours[i].points[j].x, glyph.contours[i].points[j].y);
|
||||
point *= transform;
|
||||
points[j] = point_t<int8_t>(point.x, point.y);
|
||||
}
|
||||
contours.emplace_back(points, count);
|
||||
points += count;
|
||||
}
|
||||
|
||||
pretty_poly::draw_polygon<int8_t>(contours, origin, scale);
|
||||
|
||||
for(auto contour : contours) {
|
||||
free(contour.points);
|
||||
}
|
||||
free(contours[0].points);
|
||||
}
|
||||
}
|
||||
|
||||
template void render_character<pretty_poly::mat3_t>(text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t<int> origin, pretty_poly::mat3_t transform);
|
||||
template void render_character<pretty_poly::mat2_t>(text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t<int> origin, pretty_poly::mat2_t transform);
|
||||
|
||||
/*
|
||||
load functions
|
||||
*/
|
||||
|
|
|
@ -70,5 +70,6 @@ namespace alright_fonts {
|
|||
*/
|
||||
|
||||
void render_character(text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t<int> origin);
|
||||
void render_character(text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t<int> origin, pretty_poly::mat3_t transform);
|
||||
template<typename mat_t>
|
||||
void render_character(text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t<int> origin, mat_t transform);
|
||||
}
|
|
@ -114,7 +114,7 @@ namespace pimoroni {
|
|||
|
||||
// Prepare a transformation matrix for character and offset rotation
|
||||
angle = (2 * (float)M_PI / 360.f) * angle;
|
||||
pretty_poly::mat3_t transform = pretty_poly::mat3_t::rotation(angle);
|
||||
pretty_poly::mat2_t transform = pretty_poly::mat2_t::rotation(angle);
|
||||
|
||||
// Align text from the bottom left
|
||||
caret.y += text_metrics.line_height;
|
||||
|
|
|
@ -252,7 +252,7 @@ namespace pretty_poly {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void draw_polygon(std::vector<contour_t<T>> contours, point_t<int> origin, int scale) {
|
||||
void draw_polygon(const std::vector<contour_t<T>>& contours, point_t<int> origin, int scale) {
|
||||
|
||||
debug("> draw polygon with %lu contours\n", contours.size());
|
||||
|
||||
|
@ -306,7 +306,7 @@ namespace pretty_poly {
|
|||
memset(tile.data, 0, tile_buffer_size);
|
||||
|
||||
// build the nodes for each contour
|
||||
for(contour_t<T> &contour : contours) {
|
||||
for(const contour_t<T> &contour : contours) {
|
||||
debug(" : build nodes for contour\n");
|
||||
build_nodes(contour, tile, origin, scale);
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ namespace pretty_poly {
|
|||
}
|
||||
}
|
||||
|
||||
template void pretty_poly::draw_polygon<int>(std::vector<contour_t<int>> contours, point_t<int> origin, int scale);
|
||||
template void pretty_poly::draw_polygon<float>(std::vector<contour_t<float>> contours, point_t<int> origin, int scale);
|
||||
template void pretty_poly::draw_polygon<uint8_t>(std::vector<contour_t<uint8_t>> contours, point_t<int> origin, int scale);
|
||||
template void pretty_poly::draw_polygon<int8_t>(std::vector<contour_t<int8_t>> contours, point_t<int> origin, int scale);
|
||||
template void pretty_poly::draw_polygon<int>(const std::vector<contour_t<int>>& contours, point_t<int> origin, int scale);
|
||||
template void pretty_poly::draw_polygon<float>(const std::vector<contour_t<float>>& contours, point_t<int> origin, int scale);
|
||||
template void pretty_poly::draw_polygon<uint8_t>(const std::vector<contour_t<uint8_t>>& contours, point_t<int> origin, int scale);
|
||||
template void pretty_poly::draw_polygon<int8_t>(const std::vector<contour_t<int8_t>>& contours, point_t<int> origin, int scale);
|
|
@ -68,5 +68,5 @@ namespace pretty_poly {
|
|||
void draw_polygon(T *points, unsigned count);
|
||||
|
||||
template<typename T>
|
||||
void draw_polygon(std::vector<contour_t<T>> contours, point_t<int> origin = point_t<int>(0, 0), int scale = 65536);
|
||||
void draw_polygon(const std::vector<contour_t<T>>& contours, point_t<int> origin = point_t<int>(0, 0), int scale = 65536);
|
||||
}
|
|
@ -145,7 +145,7 @@ namespace pretty_poly {
|
|||
//point_t<T> *begin() const { return points; };
|
||||
//point_t<T> *end() const { return points + count * sizeof(point_t<T>); };
|
||||
|
||||
rect_t bounds() {
|
||||
rect_t bounds() const {
|
||||
T minx = this->points[0].x, maxx = minx;
|
||||
T miny = this->points[0].y, maxy = miny;
|
||||
for(auto i = 1u; i < this->count; i++) {
|
||||
|
|
Ładowanie…
Reference in New Issue