fix bounding box

This commit is contained in:
jrkb 2023-05-17 22:34:05 +02:00
parent 840dbce493
commit 95527561d0

View file

@ -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;
if(layer->getProps().width > 0){
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
//;
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;
if(layer->getProps().width > 0){
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;
// 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 <ofxGPUFont::Font::Bou
if(variationText[vi].charcode == '-'){
wrapIndex = i;
}
float xxx = bb.p1.x - collectedWrapWidth;
//float xxx = bb.p1.x - collectedWrapWidth;
//if(ofGetFrameNum() % 600 == 0){
//cout << "WRAP INDEX " << char(variationText[vi].charcode) << ":" << ofToString(wrapIndex) << " xxx: " << ofToString(xxx) << " cww: " << ofToString(collectedWrapWidth) << endl;
//}