From 4af4adb3e259edfe87226aa64e9c565a7746bb53 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Thu, 21 Sep 2023 10:08:00 +0200 Subject: [PATCH] hack fix outlines --- src/gpufont/font.hpp | 82 +++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/src/gpufont/font.hpp b/src/gpufont/font.hpp index efa7b93..f468077 100644 --- a/src/gpufont/font.hpp +++ b/src/gpufont/font.hpp @@ -921,6 +921,9 @@ class Font { std::vector directions(n_contours, 0); std::vector > curves(n_contours); std::vector 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;