diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index 2aa3aa8..d832511 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -148,8 +148,8 @@ void ofApp::update(){ float animationSpeed = ofMap(sin(ofGetElapsedTimef() * 0.01), -1, 1, 0.0, 2); float threshold = 5.0; for(int i = 0; i < fontVariationAxes.size(); i++){ - Font::FontVariationAxis & axis = fontVariationAxes[i]; - Font::FontVariationAxisParameters & axisParams = fontVariationAxesParameters[i]; + ofxGPUFont::Font::FontVariationAxis & axis = fontVariationAxes[i]; + ofxGPUFont::Font::FontVariationAxisParameters & axisParams = fontVariationAxesParameters[i]; double newValue = ofMap(sin(ofGetElapsedTimef() * animationSpeed), -1, 1, axisParams.minValue, axisParams.maxValue); diff --git a/example/src/ofApp.h b/example/src/ofApp.h index 785fab8..e47ce5a 100644 --- a/example/src/ofApp.h +++ b/example/src/ofApp.h @@ -2,39 +2,7 @@ #include "ofMain.h" #include "ofxGPUFont.h" -#include "gpufont/font.hpp" -#include "gpufont/shader_catalog.hpp" -static std::unique_ptr loadFont(FT_Library & library, const std::string & filename, float worldSize = 1.0f, bool hinting = false){ - std::string error; - FT_Face face = Font::loadFace(library, filename, error); - if(error != ""){ - std::cerr << "[font] failed to load " << filename << ": " << error << std::endl; - return std::unique_ptr {}; - } - - return std::make_unique (face, worldSize, hinting); -} - -static void tryUpdateMainFont(FT_Library & library, - const std::string & filename, - const string & mainText, - unique_ptr & mainFont, - Font::BoundingBox & bb){ - { - auto font = loadFont(library, filename, 0.05f); - if(!font){ - return; - } - - font->dilation = 0.1f; - - font->prepareGlyphsForText(mainText); - - mainFont = std::move(font); - bb = mainFont->measure(0, 0, mainText); - } -} class ofApp : public ofBaseApp { public: @@ -71,7 +39,7 @@ class ofApp : public ofBaseApp { void exit(); - unique_ptr font; + unique_ptr font; FT_Library library; // Empty VAO used when the vertex shader has no input and only uses gl_VertexID, @@ -82,7 +50,7 @@ class ofApp : public ofBaseApp { //std::shared_ptr backgroundShader; std::shared_ptr fontShader; - Font::BoundingBox bb; + ofxGPUFont::Font::BoundingBox bb; Transform transform; @@ -152,7 +120,7 @@ class ofApp : public ofBaseApp { "data/celines-fonts/Version-3-var.ttf" }; - std::vector fontVariationAxesParameters; - std::vector fontVariationAxes; + std::vector fontVariationAxesParameters; + std::vector fontVariationAxes; }; diff --git a/example/src/defer.hpp b/src/defer.hpp similarity index 100% rename from example/src/defer.hpp rename to src/defer.hpp diff --git a/example/src/gpufont/font.hpp b/src/gpufont/font.hpp similarity index 97% rename from example/src/gpufont/font.hpp rename to src/gpufont/font.hpp index eee6793..00ad13f 100644 --- a/example/src/gpufont/font.hpp +++ b/src/gpufont/font.hpp @@ -1,3 +1,4 @@ +#pragma once // Note: See "main.cpp" for headers. // This file was extracted to improve the organization of the code, // but it is still compiled in the "main.cpp" translation unit, @@ -17,6 +18,8 @@ #define F16DOT16_TO_DOUBLE(x) (1 / 65536. * double(x)) #define DOUBLE_TO_F16DOT16(x) FT_Fixed(65536. * x) +namespace ofxGPUFont { + inline int32_t calculateUpperPowerOfTwo(int32_t v){ v--; v |= v >> 1; @@ -32,7 +35,6 @@ inline bool isPowerOfTwo(int i){ return (i & (i - 1)) == 0; } - class Font { struct Glyph { FT_UInt index; @@ -318,7 +320,6 @@ class Font { } void prepareGlyphsForText(const std::string & text, bool forceChange = false){ - // TODO: do not duplicate glyphs bool changed = false; if(forceChange){ @@ -916,3 +917,35 @@ class Font { // anti-aliasing. Value is relative to emSize. float dilation = 0; }; + +static std::unique_ptr loadFont(FT_Library & library, const std::string & filename, float worldSize = 1.0f, bool hinting = false){ + std::string error; + FT_Face face = Font::loadFace(library, filename, error); + if(error != ""){ + std::cerr << "[font] failed to load " << filename << ": " << error << std::endl; + return std::unique_ptr {}; + } + + return std::make_unique (face, worldSize, hinting); +} + +static void tryUpdateMainFont(FT_Library & library, + const std::string & filename, + const string & mainText, + unique_ptr & mainFont, + Font::BoundingBox & bb){ + { + auto font = loadFont(library, filename, 0.05f); + if(!font){ + return; + } + + font->dilation = 0.1f; + + font->prepareGlyphsForText(mainText); + + mainFont = std::move(font); + bb = mainFont->measure(0, 0, mainText); + } +} +} diff --git a/example/src/gpufont/glm.hpp b/src/gpufont/glm.hpp similarity index 100% rename from example/src/gpufont/glm.hpp rename to src/gpufont/glm.hpp diff --git a/example/src/gpufont/maingpufont.hpp b/src/gpufont/maingpufont.hpp similarity index 100% rename from example/src/gpufont/maingpufont.hpp rename to src/gpufont/maingpufont.hpp diff --git a/example/src/gpufont/shader_catalog.cpp b/src/gpufont/shader_catalog.cpp similarity index 100% rename from example/src/gpufont/shader_catalog.cpp rename to src/gpufont/shader_catalog.cpp diff --git a/example/src/gpufont/shader_catalog.hpp b/src/gpufont/shader_catalog.hpp similarity index 100% rename from example/src/gpufont/shader_catalog.hpp rename to src/gpufont/shader_catalog.hpp diff --git a/src/ofxGPUFont.h b/src/ofxGPUFont.h index 1a42a12..e1b7675 100644 --- a/src/ofxGPUFont.h +++ b/src/ofxGPUFont.h @@ -1 +1,4 @@ -#pragma one +#pragma once + +#include "gpufont/font.hpp" +#include "gpufont/shader_catalog.hpp"