From c9f89f5853f14cb115bfd7b5adb0eee814486f39 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Mon, 17 Apr 2023 17:07:36 +0200 Subject: [PATCH] pseudo rotation with ofNode --- src/gpufont/font.hpp | 57 ++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/gpufont/font.hpp b/src/gpufont/font.hpp index b6bdacc..d2f4ddd 100644 --- a/src/gpufont/font.hpp +++ b/src/gpufont/font.hpp @@ -876,9 +876,13 @@ class Font { std::vector & indices, const bool vFlip = false, const float fontSize_px = 42){ - float x = position.x; - float y = position.y; - float originalX = x; + float advanceX = 0; + float advanceY = 0; + + float degree = ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 90); + ofNode node; + node.rotateDeg(degree, glm::vec3(0, 0, 1)); + node.move(position); FT_UInt previous = 0; for(const GlyphIdentity & glyphIdentity : variationText){ @@ -892,11 +896,14 @@ class Font { continue; } - if(charcode == '\n'){ - x = originalX; - y -= (float)face->height / (float)face->units_per_EM * worldSize; + if(charcode == '\n' || charcode == 'n'){ + advanceX = 0; + advanceY += ((float)face->height * fontSize_px) / (float)face->units_per_EM * worldSize; + if(!vFlip){ + advanceY *= -1; + } if(hinting){ - y = std::round(y); + advanceY = std::round(advanceY); } continue; } @@ -909,7 +916,7 @@ class Font { FT_Vector kerning; FT_Error error = FT_Get_Kerning(face, previous, glyph.index, kerningMode, &kerning); if(!error){ - x += (float)kerning.x / emSize * worldSize; + advanceX += ((float)kerning.x * fontSize_px) / emSize * worldSize; } } @@ -922,31 +929,35 @@ class Font { float u1 = (float)(glyph.bearingX + glyph.width + d) / emSize; float v1 = (float)(glyph.bearingY + d) / emSize; - - float x0 = x + u0 * worldSize * letterFontSize_px; - float y0 = y + v0 * worldSize * letterFontSize_px; - float x1 = x + u1 * worldSize * letterFontSize_px; - float y1 = y + v1 * worldSize * letterFontSize_px; + float x0 = advanceX + u0 * worldSize * letterFontSize_px; + float y0 = v0 * worldSize * letterFontSize_px; + float x1 = advanceX + u1 * worldSize * letterFontSize_px; + float y1 = v1 * worldSize * letterFontSize_px; if(vFlip){ float _v = v0; v0 = v1; v1 = _v; - y0 = y - v0 * worldSize * letterFontSize_px; - y1 = y - v1 * worldSize * letterFontSize_px; + y0 = -v0 * worldSize * letterFontSize_px; + y1 = -v1 * worldSize * letterFontSize_px; } + glm::vec4 p0 = node.getGlobalTransformMatrix() * glm::vec4(x0, y0 + advanceY, 0, 1); + glm::vec4 p1 = node.getGlobalTransformMatrix() * glm::vec4(x1, y0 + advanceY, 0, 1); + glm::vec4 p2 = node.getGlobalTransformMatrix() * glm::vec4(x1, y1 + advanceY, 0, 1); + glm::vec4 p3 = node.getGlobalTransformMatrix() * glm::vec4(x0, y1 + advanceY, 0, 1); + int32_t base = static_cast (vertices.size()); - vertices.push_back(BufferVertex{x0, y0, u0, v0, glyph.bufferIndex}); - vertices.push_back(BufferVertex{x1, y0, u1, v0, glyph.bufferIndex}); - vertices.push_back(BufferVertex{x1, y1, u1, v1, glyph.bufferIndex}); - vertices.push_back(BufferVertex{x0, y1, u0, v1, glyph.bufferIndex}); + vertices.push_back(BufferVertex{p0.x, p0.y, u0, v0, glyph.bufferIndex}); + vertices.push_back(BufferVertex{p1.x, p1.y, u1, v0, glyph.bufferIndex}); + vertices.push_back(BufferVertex{p2.x, p2.y, u1, v1, glyph.bufferIndex}); + vertices.push_back(BufferVertex{p3.x, p3.y, u0, v1, glyph.bufferIndex}); indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base}); } - x += ((float)glyph.advance * letterFontSize_px) / emSize * worldSize; + advanceX += ((float)glyph.advance * letterFontSize_px) / emSize * worldSize; previous = glyph.index; } } @@ -970,9 +981,8 @@ class Font { }; BoundingBox measure(float x, float y, const std::string & text){ - BoundingBox bb; + //BoundingBox bb; cerr << "ofxGPUFont::Font::BoundingBox not implemented" << endl; - cout << "ofxGPUFont::Font::BoundingBox not implemented" << endl; //bb.minX = +std::numeric_limits ::infinity(); //bb.minY = +std::numeric_limits ::infinity(); //bb.maxX = -std::numeric_limits ::infinity(); @@ -1036,7 +1046,8 @@ class Font { //previous = glyph.index; //} - return bb; + //return bb; + return BoundingBox(); } private: