hack fix outlines

This commit is contained in:
jrkb 2023-09-21 10:08:00 +02:00
parent 6f8b6633be
commit 4af4adb3e2

View file

@ -921,6 +921,9 @@ class Font {
std::vector <float> directions(n_contours, 0);
std::vector <std::vector <BufferCurve> > curves(n_contours);
std::vector <BBox> bbs(n_contours);
int largestIndex = 0;
float largestArea = 0;
bool flipAll = false;
for(int i = 0; i < n_contours; i++){
// Note: The end indices in face->glyph->outline.contours are inclusive.
bbs[i].xMin = FLT_MAX;
@ -929,35 +932,60 @@ class Font {
bbs[i].yMax = -FLT_MAX;
convertContour(curves[i], directions[i], bbs[i], &face->glyph->outline, start, face->glyph->outline.contours[i], emSize);
start = face->glyph->outline.contours[i] + 1;
}
for(int i = 0; i < n_contours; i++){
if(directions[i] < 0){
bool flip = true;
for(int j = 0; j < n_contours; j++){
if(i != j){
bool inside = bbs[j].xMin <= bbs[i].xMin
&& bbs[j].xMax >= bbs[i].xMax
&& bbs[j].yMin <= bbs[i].yMin
&& bbs[j].yMax >= bbs[i].yMax;
if(inside){
flip = false;
break;
}
}
}
if(flip){
for(BufferCurve & curve : curves[i]){
float tmp_x = curve.x0;
float tmp_y = curve.y0;
curve.x0 = curve.x2;
curve.y0 = curve.y2;
curve.x2 = tmp_x;
curve.y2 = tmp_y;
}
std::reverse(curves[i].begin(), curves[i].end());
float area = abs(bbs[i].xMax - bbs[i].xMin) * abs(bbs[i].yMax - bbs[i].yMin);
if(area > largestArea){
largestArea = area;
largestIndex = i;
if(directions[i] < 0){
flipAll = true;
}else{
flipAll = false;
}
}
bufferCurves.insert(bufferCurves.end(), curves[i].begin(), curves[i].end());
}
if(flipAll){
for(int i = 0; i < n_contours; i++){
for(BufferCurve & curve : curves[i]){
float tmp_x = curve.x0;
float tmp_y = curve.y0;
curve.x0 = curve.x2;
curve.y0 = curve.y2;
curve.x2 = tmp_x;
curve.y2 = tmp_y;
}
std::reverse(curves[i].begin(), curves[i].end());
bufferCurves.insert(bufferCurves.end(), curves[i].begin(), curves[i].end());
}
}else{
for(int i = 0; i < n_contours; i++){
if(directions[i] < 0){
bool flip = true;
for(int j = 0; j < n_contours; j++){
if(i != j){
bool inside = bbs[j].xMin <= bbs[i].xMin
&& bbs[j].xMax >= bbs[i].xMax
&& bbs[j].yMin <= bbs[i].yMin
&& bbs[j].yMax >= bbs[i].yMax;
if(inside){
flip = false;
break;
}
}
}
if(flip){
for(BufferCurve & curve : curves[i]){
float tmp_x = curve.x0;
float tmp_y = curve.y0;
curve.x0 = curve.x2;
curve.y0 = curve.y2;
curve.x2 = tmp_x;
curve.y2 = tmp_y;
}
std::reverse(curves[i].begin(), curves[i].end());
}
}
bufferCurves.insert(bufferCurves.end(), curves[i].begin(), curves[i].end());
}
}
}else{
short start = 0;