When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
9 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
u16 emSize = 32;
u16 glyphWidth = ((glyphDescription->xMax - glyphDescription->xMin) * emSize) / head->unitsPerEm;
u16 glyphHeight = ((glyphDescription->yMax - glyphDescription->yMin) * emSize) / head->unitsPerEm;
for (u16 y = 0; y < glyphHeight; y++) {
bool intersections[64] = { 0 }; // assume glyphWidth is never greater than 64 for now
u16 startIndex = 0;
for (i16 i = 0; i < glyphDescription->numberOfContours; i++) {
u16 length = (endPtsOfContours[i] + 1) - startIndex;
for (u16 index = startIndex; index <= endPtsOfContours[i]; index++) {
u16 nextIndex = startIndex + (((index + 1) - startIndex) % length);
if ((flags[index] & ON_CURVE_POINT) && (flags[nextIndex] & ON_CURVE_POINT)) { // it's a straight line
i16vec2 start = (points[index] * emSize) / (i16)head->unitsPerEm;
i16vec2 end = (points[nextIndex] * emSize) / (i16)head->unitsPerEm;
float yMax = __builtin_fmaxf(start.y, end.y);
float yMin = __builtin_fminf(start.y, end.y);
if (y <= yMin) continue;
if (y > yMax) continue;
float dx = end.x - start.x;
float dy = end.y - start.y;
float slope = dy / dx;
// y = scanline coordinate
float intersection = (y - start.y) * slope + start.x;
if (intersection < 0.f)
intersection = start.x;
intersections[(u16)intersection] = true;
} else { // quadratic or cubic bezier, handled later
}
}
startIndex = endPtsOfContours[i] + 1;
}
bool filling = false;
for (u16 x = 0; x < glyphWidth; x++) {
if (intersections[x])
filling = !filling;
imageData[y * 1024 + x] = filling ? 255 : 0;
}
}
just noticed the fill code is wrong too
will fix that first
fixed
also signed overflow happening
I'll use this thread to rubberduck
@spiral mirage
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity