wrapping with slight error on side
This commit is contained in:
parent
24273912cb
commit
976e309a54
1 changed files with 69 additions and 44 deletions
|
@ -210,6 +210,7 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
indices.resize(totalCharacters * 6);
|
indices.resize(totalCharacters * 6);
|
||||||
|
|
||||||
std::vector <ofVboMesh> outerBoundingBoxes;
|
std::vector <ofVboMesh> outerBoundingBoxes;
|
||||||
|
ofRectangle r;
|
||||||
for(const auto & layer : layers){
|
for(const auto & layer : layers){
|
||||||
OFX_PROFILER_SCOPE("draw layer");
|
OFX_PROFILER_SCOPE("draw layer");
|
||||||
float ascender = font->getAscender(layer->getProps().fontSize_px);
|
float ascender = font->getAscender(layer->getProps().fontSize_px);
|
||||||
|
@ -227,14 +228,14 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
layer->getVariationText(),
|
layer->getVariationText(),
|
||||||
layer->getProps().width,
|
layer->getProps().width,
|
||||||
lineHeight);
|
lineHeight);
|
||||||
if(ofGetFrameNum() % 30 == 0){
|
if(ofGetFrameNum() % 600 == 0){
|
||||||
cout
|
cout
|
||||||
<< "n_wraps: " << ofToString(n_wraps) << endl
|
<< "n_wraps: " << ofToString(n_wraps) << endl
|
||||||
<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl
|
<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
bb.p2.y += n_wraps * lineHeight;
|
//bb.p2.y += n_wraps * lineHeight;
|
||||||
bb.p3.y += n_wraps * lineHeight;
|
//bb.p3.y += n_wraps * lineHeight;
|
||||||
glm::vec4 transformOrigin;
|
glm::vec4 transformOrigin;
|
||||||
getAndApplyTransformOrigin(transformOrigin,
|
getAndApplyTransformOrigin(transformOrigin,
|
||||||
layer->getOuterNode(),
|
layer->getOuterNode(),
|
||||||
|
@ -347,6 +348,8 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
float width = max_x - min_x;
|
float width = max_x - min_x;
|
||||||
float height = max_y - min_y;
|
float height = max_y - min_y;
|
||||||
layer->setBoundingBox(Layer::BoundingBox{min_x, min_y, width, height});
|
layer->setBoundingBox(Layer::BoundingBox{min_x, min_y, width, height});
|
||||||
|
|
||||||
|
r = ofRectangle(layer->getProps().x, layer->getProps().y, layer->getProps().width, 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -355,6 +358,11 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
}
|
}
|
||||||
|
|
||||||
glUseProgram(currentProgram);
|
glUseProgram(currentProgram);
|
||||||
|
ofPushStyle();
|
||||||
|
ofSetColor(ofColor::green);
|
||||||
|
ofNoFill();
|
||||||
|
ofDrawRectangle(r);
|
||||||
|
ofPopStyle();
|
||||||
//ofPushStyle();
|
//ofPushStyle();
|
||||||
//ofSetColor(ofColor::white);
|
//ofSetColor(ofColor::white);
|
||||||
//for(const auto & b : outerBoundingBoxes){
|
//for(const auto & b : outerBoundingBoxes){
|
||||||
|
@ -449,71 +457,88 @@ int GPUFontAtlasLayerCombo::wrapBoundingBoxes(std::vector <ofxGPUFont::Font::Bou
|
||||||
float advanceY){
|
float advanceY){
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
int vi = 0;
|
||||||
int wrapIndex = -1;
|
int wrapIndex = -1;
|
||||||
int n_wraps = 0;
|
int n_wraps = 0;
|
||||||
bool firstToBreak = true;
|
bool firstToBreak = true;
|
||||||
vector <int> breakPoints;
|
float collectedWrapWidth = 0;
|
||||||
|
|
||||||
for(ofxGPUFont::Font::BoundingBox & bb : bbs){
|
for(ofxGPUFont::Font::BoundingBox & bb : bbs){
|
||||||
bool hasGoodCharacter = false;
|
bool hasGoodCharacter = false;
|
||||||
bool hadAlwaysGoodCharacter = true;
|
while(!hasGoodCharacter && vi < variationText.size() - 1){
|
||||||
while(!hasGoodCharacter && i < variationText.size() - 1){
|
if(variationText[vi].charcode == '\0'
|
||||||
if(variationText[i].charcode == '\0'
|
|| variationText[vi].charcode == '\r'
|
||||||
|| variationText[i].charcode == '\r'
|
|| variationText[vi].charcode == '\n'){
|
||||||
|| variationText[i].charcode == '\n'){
|
|
||||||
hadAlwaysGoodCharacter = false;
|
|
||||||
wrapIndex = -1;
|
wrapIndex = -1;
|
||||||
i++;
|
collectedWrapWidth = 0;
|
||||||
|
vi++;
|
||||||
|
}else if(variationText[vi].charcode == ' '){ // TODO: any whitespace
|
||||||
|
wrapIndex = i;
|
||||||
|
vi++;
|
||||||
}else{
|
}else{
|
||||||
hasGoodCharacter = true;
|
hasGoodCharacter = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( //!hadAlwaysGoodCharacter ||
|
if(variationText[vi].charcode == '-'){
|
||||||
(variationText[i].charcode == '-'
|
wrapIndex = i;
|
||||||
|| variationText[i].charcode == ' ')){
|
|
||||||
wrapIndex = i + 1;
|
|
||||||
cout << "WRAP INDEX " << ofToString(wrapIndex) << endl;
|
|
||||||
}
|
}
|
||||||
if(bb.p1.x > width){
|
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;
|
||||||
|
}
|
||||||
|
if(bb.p1.x - collectedWrapWidth > width){
|
||||||
if(wrapIndex >= 0){
|
if(wrapIndex >= 0){
|
||||||
if(wrapIndex == i){
|
if(wrapIndex == i){
|
||||||
breakPoints.push_back(i);
|
float wrapWidth = bb.p0.x;
|
||||||
bb.p0.x = 0;
|
collectedWrapWidth = wrapWidth;
|
||||||
bb.p1.x -= bb.p0.x;
|
n_wraps++;
|
||||||
bb.p2.x -= bb.p0.x;
|
bb.p0.x -= wrapWidth;
|
||||||
bb.p3.x -= bb.p0.x;
|
bb.p1.x -= wrapWidth;
|
||||||
bb.p0.y += (n_wraps + 1) * advanceY;
|
bb.p2.x -= wrapWidth;
|
||||||
bb.p1.y += (n_wraps + 1) * advanceY;
|
bb.p3.x -= wrapWidth;
|
||||||
bb.p2.y += (n_wraps + 1) * advanceY;
|
bb.p0.y += (n_wraps) * advanceY;
|
||||||
bb.p3.y += (n_wraps + 1) * advanceY;
|
bb.p1.y += (n_wraps) * advanceY;
|
||||||
|
bb.p2.y += (n_wraps) * advanceY;
|
||||||
|
bb.p3.y += (n_wraps) * advanceY;
|
||||||
}else{
|
}else{
|
||||||
if(firstToBreak){
|
if(firstToBreak){
|
||||||
breakPoints.push_back(wrapIndex);
|
collectedWrapWidth = bbs[wrapIndex].p0.x;
|
||||||
|
n_wraps++;
|
||||||
for(int w = wrapIndex; w <= i; w++){
|
for(int w = wrapIndex; w <= i; w++){
|
||||||
bbs[w].p0.x -= bbs[wrapIndex].p0.x;
|
bbs[w].p0.x -= collectedWrapWidth;
|
||||||
bbs[w].p1.x -= bbs[wrapIndex].p0.x;
|
bbs[w].p1.x -= collectedWrapWidth;
|
||||||
bbs[w].p2.x -= bbs[wrapIndex].p0.x;
|
bbs[w].p2.x -= collectedWrapWidth;
|
||||||
bbs[w].p3.x -= bbs[wrapIndex].p0.x;
|
bbs[w].p3.x -= collectedWrapWidth;
|
||||||
bbs[w].p0.y += (n_wraps + 1) * advanceY;
|
bbs[w].p0.y += (n_wraps) * advanceY;
|
||||||
bbs[w].p1.y += (n_wraps + 1) * advanceY;
|
bbs[w].p1.y += (n_wraps) * advanceY;
|
||||||
bbs[w].p2.y += (n_wraps + 1) * advanceY;
|
bbs[w].p2.y += (n_wraps) * advanceY;
|
||||||
bbs[w].p3.y += (n_wraps + 1) * advanceY;
|
bbs[w].p3.y += (n_wraps) * advanceY;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
bb.p0.x -= bbs[wrapIndex].p0.x;
|
bb.p0.x -= collectedWrapWidth;
|
||||||
bb.p1.x -= bbs[wrapIndex].p0.x;
|
bb.p1.x -= collectedWrapWidth;
|
||||||
bb.p2.x -= bbs[wrapIndex].p0.x;
|
bb.p2.x -= collectedWrapWidth;
|
||||||
bb.p3.x -= bbs[wrapIndex].p0.x;
|
bb.p3.x -= collectedWrapWidth;
|
||||||
bb.p0.y += (n_wraps + 1) * advanceY;
|
bb.p0.y += (n_wraps) * advanceY;
|
||||||
bb.p1.y += (n_wraps + 1) * advanceY;
|
bb.p1.y += (n_wraps) * advanceY;
|
||||||
bb.p2.y += (n_wraps + 1) * advanceY;
|
bb.p2.y += (n_wraps) * advanceY;
|
||||||
bb.p3.y += (n_wraps + 1) * advanceY;
|
bb.p3.y += (n_wraps) * advanceY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n_wraps++;
|
|
||||||
firstToBreak = false;
|
firstToBreak = false;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
bb.p0.x -= collectedWrapWidth;
|
||||||
|
bb.p1.x -= collectedWrapWidth;
|
||||||
|
bb.p2.x -= collectedWrapWidth;
|
||||||
|
bb.p3.x -= collectedWrapWidth;
|
||||||
|
bb.p0.y += (n_wraps) * advanceY;
|
||||||
|
bb.p1.y += (n_wraps) * advanceY;
|
||||||
|
bb.p2.y += (n_wraps) * advanceY;
|
||||||
|
bb.p3.y += (n_wraps) * advanceY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vi++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return n_wraps;
|
return n_wraps;
|
||||||
|
|
Loading…
Reference in a new issue