23 #if defined VG_FEATURE_FONT && \
24 (defined VG_FEATURE_FONT_FREETYPE_VECTOR || defined VG_FEATURE_FONT_FREETYPE_BITMAP) && \
25 (VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_VECTOR || VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_BITMAP)
45 static void __add_axis_value(
VG_OUTLINE_BOX *box,
float v,
bool is_x) {
55 static float __quad_at(
float p0,
float p1,
float p2,
float t) {
57 return (u * u * p0) + (2.f * u * t * p1) + (t * t * p2);
60 static float __cubic_at(
float p0,
float p1,
float p2,
float p3,
float t) {
62 return (u * u * u * p0) + (3.f * u * u * t * p1) + (3.f * u * t * t * p2) + (t * t * t * p3);
65 static void __quad_axis(
VG_OUTLINE_BOX *box,
float p0,
float p1,
float p2,
float lo,
float hi,
67 if ((p1 >= lo) && (p1 <= hi)) {
74 float d = (p0 - (2.f * p1)) + p2;
78 float t = (p0 - p1) / d;
79 if ((t > 0.f) && (t < 1.f)) {
80 __add_axis_value(box, __quad_at(p0, p1, p2, t), is_x);
84 static void __cubic_axis(
VG_OUTLINE_BOX *box,
float p0,
float p1,
float p2,
float p3,
float lo,
85 float hi,
bool is_x) {
86 if ((p1 >= lo) && (p1 <= hi) && (p2 >= lo) && (p2 <= hi)) {
89 float a = ((-p0 + (3.f * p1)) - (3.f * p2)) + p3;
90 float b = ((2.f * p0) - (4.f * p1)) + (2.f * p2);
100 float disc = (b * b) - (4.f * a * c);
102 float sq = sqrtf(disc);
103 roots[nb] = (-b + sq) / (2.f * a);
105 roots[nb] = (-b - sq) / (2.f * a);
109 for (
int i = 0; i < nb; i++) {
111 if ((t > 0.f) && (t < 1.f)) {
112 __add_axis_value(box, __cubic_at(p0, p1, p2, p3, t), is_x);
121 struct outline_walk {
126 static int __move_to(
const FT_Vector *to,
void *user) {
127 struct outline_walk *w = (
struct outline_walk *)user;
128 __add_point(w->box, (
float)to->x, (
float)to->y);
133 static int __line_to(
const FT_Vector *to,
void *user) {
134 struct outline_walk *w = (
struct outline_walk *)user;
135 __add_point(w->box, (
float)to->x, (
float)to->y);
140 static int __conic_to(
const FT_Vector *control,
const FT_Vector *to,
void *user) {
141 struct outline_walk *w = (
struct outline_walk *)user;
142 __add_point(w->box, (
float)to->x, (
float)to->y);
143 __quad_axis(w->box, (
float)w->current.x, (
float)control->x, (
float)to->x, w->box->x_min,
144 w->box->x_max,
true);
145 __quad_axis(w->box, (
float)w->current.y, (
float)control->y, (
float)to->y, w->box->y_min,
146 w->box->y_max,
false);
151 static int __cubic_to(
const FT_Vector *control1,
const FT_Vector *control2,
const FT_Vector *to,
153 struct outline_walk *w = (
struct outline_walk *)user;
154 __add_point(w->box, (
float)to->x, (
float)to->y);
155 __cubic_axis(w->box, (
float)w->current.x, (
float)control1->x, (
float)control2->x, (
float)to->x,
156 w->box->x_min, w->box->x_max,
true);
157 __cubic_axis(w->box, (
float)w->current.y, (
float)control1->y, (
float)control2->y, (
float)to->y,
158 w->box->y_min, w->box->y_max,
false);
169 box->
x_min = FLT_MAX;
170 box->
x_max = -FLT_MAX;
171 box->
y_min = FLT_MAX;
172 box->
y_max = -FLT_MAX;
175 static const FT_Outline_Funcs funcs = {
176 .move_to = __move_to,
177 .line_to = __line_to,
178 .conic_to = __conic_to,
179 .cubic_to = __cubic_to,
184 struct outline_walk walk;
188 int error = FT_Outline_Decompose((FT_Outline *)outline, &funcs, &walk);
189 if ((0 != error) || box->
empty) {
The box of the curve an outline draws, control points excluded.
MicroEJ MicroVG library low level API: enable some features according to the hardware capacities.
MicroEJ MicroVG library low level API: box of the curve an outline draws.
void VG_OUTLINE_BOX_compute(const FT_Outline *outline, VG_OUTLINE_BOX *box)
Computes the box of the curve the given outline draws, where the box a font declares also bounds the ...