@@ -41,7 +41,8 @@ namespace alright_fonts {
41
41
}
42
42
}
43
43
44
- void render_character (text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t <int > origin, pretty_poly::mat3_t transform) {
44
+ template <typename mat_t >
45
+ void render_character (text_metrics_t &tm, uint16_t codepoint, pretty_poly::point_t <int > origin, mat_t transform) {
45
46
if (tm.face .glyphs .count (codepoint) == 1 ) {
46
47
glyph_t glyph = tm.face .glyphs [codepoint];
47
48
@@ -51,26 +52,35 @@ namespace alright_fonts {
51
52
unsigned scale = tm.size << 9 ;
52
53
53
54
std::vector<pretty_poly::contour_t <int8_t >> contours;
55
+ contours.reserve (glyph.contours .size ());
54
56
57
+ unsigned int total_points = 0 ;
55
58
for (auto i = 0u ; i < glyph.contours .size (); i++) {
56
- unsigned int count = glyph.contours [i].count ;
57
- point_t <int8_t > *points = (point_t <int8_t > *)malloc (sizeof (point_t <int8_t >) * count);
59
+ total_points += glyph.contours [i].count ;;
60
+ }
61
+
62
+ point_t <int8_t > *points = (point_t <int8_t > *)malloc (sizeof (point_t <int8_t >) * total_points);
63
+
64
+ for (auto i = 0u ; i < glyph.contours .size (); i++) {
65
+ const unsigned int count = glyph.contours [i].count ;
58
66
for (auto j = 0u ; j < count; j++) {
59
67
point_t <float > point (glyph.contours [i].points [j].x , glyph.contours [i].points [j].y );
60
68
point *= transform;
61
69
points[j] = point_t <int8_t >(point.x , point.y );
62
70
}
63
71
contours.emplace_back (points, count);
72
+ points += count;
64
73
}
65
74
66
75
pretty_poly::draw_polygon<int8_t >(contours, origin, scale);
67
76
68
- for (auto contour : contours) {
69
- free (contour.points );
70
- }
77
+ free (contours[0 ].points );
71
78
}
72
79
}
73
80
81
+ 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);
82
+ 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);
83
+
74
84
/*
75
85
load functions
76
86
*/
0 commit comments