From 95527561d07991cc3e67a51ff4cf0dc0eed57f11 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Wed, 17 May 2023 22:34:05 +0200 Subject: [PATCH] fix bounding box --- src/GPUFontAtlasLayerCombo.cpp | 93 +++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 24 deletions(-) diff --git a/src/GPUFontAtlasLayerCombo.cpp b/src/GPUFontAtlasLayerCombo.cpp index d2c02a2..5001e3f 100644 --- a/src/GPUFontAtlasLayerCombo.cpp +++ b/src/GPUFontAtlasLayerCombo.cpp @@ -223,18 +223,38 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){ true, layer->getProps().fontSize_px, layer->getProps().lineHeight); float lineHeight = font->getLineHeight(layer->getProps().fontSize_px) * layer->getProps().lineHeight; - int n_wraps = wrapBoundingBoxes(bbs, - layer->getVariationText(), - layer->getProps().width, - lineHeight); - //if(ofGetFrameNum() % 600 == 0){ - //cout - //<< "n_wraps: " << ofToString(n_wraps) << endl - //<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl - //; + if(layer->getProps().width > 0){ + int n_wraps = wrapBoundingBoxes(bbs, + layer->getVariationText(), + layer->getProps().width, + lineHeight); + float min_x = FLT_MAX; + float min_y = FLT_MAX; + float max_x = -FLT_MAX; + float max_y = -FLT_MAX; + for(const auto & sbb : bbs){ + min_x = min(sbb.p0.x, min_x); + min_y = min(sbb.p0.y, min_y); + max_x = max(sbb.p2.x, max_x); + max_y = max(sbb.p2.y, max_y); + } + bb.p0.x = min_x; + bb.p0.y = min_y; + bb.p1.x = max_x; + bb.p1.y = min_y; + bb.p2.x = max_x; + bb.p2.y = max_y; + bb.p3.x = min_x; + bb.p3.y = max_y; - //bb.p2.y += n_wraps * lineHeight; - //bb.p3.y += n_wraps * lineHeight; + if(ofGetFrameNum() % 600 == 0){ + cout + << "n_wraps: " << ofToString(n_wraps) << endl + << "layer->getProps().width: " << ofToString(layer->getProps().width) << endl + ; + + } + } glm::vec4 transformOrigin; getAndApplyTransformOrigin(transformOrigin, layer->getOuterNode(), @@ -462,18 +482,43 @@ void GPUFontAtlasLayerCombo::draw(int width, true, layer->getProps().fontSize_px, layer->getProps().lineHeight); float lineHeight = font->getLineHeight(layer->getProps().fontSize_px) * layer->getProps().lineHeight; - int n_wraps = wrapBoundingBoxes(bbs, - layer->getVariationText(), - layer->getProps().width, - lineHeight); - //if(ofGetFrameNum() % 600 == 0){ - //cout - //<< "n_wraps: " << ofToString(n_wraps) << endl - //<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl - //; - //} - //bb.p2.y += n_wraps * lineHeight; - //bb.p3.y += n_wraps * lineHeight; + if(layer->getProps().width > 0){ + int n_wraps = wrapBoundingBoxes(bbs, + layer->getVariationText(), + layer->getProps().width, + lineHeight); + // could be optimized by: + // - min_x = bbs[0].p0.x + // - max_x = min_x + layer->getProps().width + // - min_y = bbs[0].p0.y + // - max_y = lineHeight * (n_wraps + 1) + float min_x = FLT_MAX; + float min_y = FLT_MAX; + float max_x = -FLT_MAX; + float max_y = -FLT_MAX; + for(const auto & sbb : bbs){ + min_x = min(sbb.p0.x, min_x); + min_y = min(sbb.p0.y, min_y); + max_x = max(sbb.p2.x, max_x); + max_y = max(sbb.p2.y, max_y); + } + bb.p0.x = min_x; + bb.p0.y = min_y; + bb.p1.x = max_x; + bb.p1.y = min_y; + bb.p2.x = max_x; + bb.p2.y = max_y; + bb.p3.x = min_x; + bb.p3.y = max_y; + + if(ofGetFrameNum() % 600 == 0){ + cout + << "n_wraps: " << ofToString(n_wraps) << endl + << "layer->getProps().width: " << ofToString(layer->getProps().width) << endl + ; + + } + } glm::vec4 transformOrigin; getAndApplyTransformOrigin(transformOrigin, layer->getOuterNode(), @@ -720,7 +765,7 @@ int GPUFontAtlasLayerCombo::wrapBoundingBoxes(std::vector