glyph appearance and color

This commit is contained in:
jrkb 2023-04-19 16:51:02 +02:00
parent 01f2960f5d
commit 1e4588357d
4 changed files with 50 additions and 25 deletions

View file

@ -203,6 +203,7 @@ void GPUFontAtlasLayerCombo::draw(){
std::vector <ofxGPUFont::Font::BoundingBox> bbs; std::vector <ofxGPUFont::Font::BoundingBox> bbs;
float advanceY = 0; float advanceY = 0;
font->collectBoundingBoxes(layer->getVariationText(), font->collectBoundingBoxes(layer->getVariationText(),
layer->getVariationTextAppearance(),
bb, bbs, advanceY, bb, bbs, advanceY,
true, layer->getProps().fontSize_px); true, layer->getProps().fontSize_px);
glm::vec4 transformOrigin; glm::vec4 transformOrigin;
@ -240,11 +241,10 @@ void GPUFontAtlasLayerCombo::draw(){
mirrorOuterNode.move(layer->getProps().mirror_x_distance * -1, 0, 0); mirrorOuterNode.move(layer->getProps().mirror_x_distance * -1, 0, 0);
mirrorOuterNode.setScale(-1, 1, 1); mirrorOuterNode.setScale(-1, 1, 1);
font->collectVerticesAndIndices(mirrorInnerNode, font->collectVerticesAndIndices(mirrorInnerNode,
layer->getVariationTextAppearance(),
bbs_mirror_x, bbs_mirror_x,
vertices, vertices,
indices, indices);
layer->getColor(),
layer->getProps().fontSize_px);
} }
if(layer->getProps().mirror_y){ if(layer->getProps().mirror_y){
auto bbs_mirror_y = bbs; auto bbs_mirror_y = bbs;
@ -257,11 +257,10 @@ void GPUFontAtlasLayerCombo::draw(){
mirrorOuterNode.move(0, layer->getProps().mirror_y_distance * -1, 0); mirrorOuterNode.move(0, layer->getProps().mirror_y_distance * -1, 0);
mirrorOuterNode.setScale(1, -1, 1); mirrorOuterNode.setScale(1, -1, 1);
font->collectVerticesAndIndices(mirrorInnerNode, font->collectVerticesAndIndices(mirrorInnerNode,
layer->getVariationTextAppearance(),
bbs_mirror_y, bbs_mirror_y,
vertices, vertices,
indices, indices);
layer->getColor(),
layer->getProps().fontSize_px);
} }
if(layer->getProps().mirror_xy){ if(layer->getProps().mirror_xy){
auto bbs_mirror_xy = bbs; auto bbs_mirror_xy = bbs;
@ -275,22 +274,22 @@ void GPUFontAtlasLayerCombo::draw(){
layer->getProps().mirror_y_distance * -1, 0); layer->getProps().mirror_y_distance * -1, 0);
mirrorOuterNode.setScale(-1, -1, 1); mirrorOuterNode.setScale(-1, -1, 1);
font->collectVerticesAndIndices(mirrorInnerNode, font->collectVerticesAndIndices(mirrorInnerNode,
layer->getVariationTextAppearance(),
bbs_mirror_xy, bbs_mirror_xy,
vertices, vertices,
indices, indices);
layer->getColor(),
layer->getProps().fontSize_px);
} }
font->collectVerticesAndIndices(layer->getInnerNode(), font->collectVerticesAndIndices(layer->getInnerNode(),
layer->getVariationTextAppearance(),
bbs, bbs,
vertices, vertices,
indices, indices);
layer->getColor(),
layer->getProps().fontSize_px);
} }
{
OFX_PROFILER_SCOPE("font->draw()");
font->draw(vertices, indices); font->draw(vertices, indices);
}
glUseProgram(currentProgram); glUseProgram(currentProgram);
ofPushStyle(); ofPushStyle();

View file

@ -66,18 +66,30 @@ void GPUFontLayer::setMomsComboIdentifier(const ComboIdentifier & identifier){
void GPUFontLayer::setProps(const Props & props){ void GPUFontLayer::setProps(const Props & props){
OFX_PROFILER_FUNCTION(); OFX_PROFILER_FUNCTION();
if(propsBuffer.size() == 0 || props.text != propsBuffer[0].text bool propsBufferEmpty = propsBuffer.size() == 0;
bool setAppearanceAlready = false;
if(propsBufferEmpty || props.text != propsBuffer[0].text
|| propsBuffer[0].fontVariations != props.fontVariations){ || propsBuffer[0].fontVariations != props.fontVariations){
setAppearanceAlready = true;
OFX_PROFILER_SCOPE("variations"); OFX_PROFILER_SCOPE("variations");
setDirtyDirty(true); setDirtyDirty(true);
variationText.clear(); variationText.clear();
variationText.resize(props.text.size()); variationText.resize(props.text.size());
variationTextAppearance.clear();
variationTextAppearance.resize(props.text.size());
int i = 0; int i = 0;
for(const char c : props.text){ for(const char c : props.text){
OFX_PROFILER_SCOPE("char"); OFX_PROFILER_SCOPE("char");
const Props & vProps = propsBufferEmpty ? props : getProps(i * props.letterDelay);
ofxGPUFont::GlyphIdentity glyphIdentity; ofxGPUFont::GlyphIdentity glyphIdentity;
ofxGPUFont::GlyphAppearance glyphAppearance;
glyphIdentity.charcode = ofxGPUFont::decodeCharcode(&c); glyphIdentity.charcode = ofxGPUFont::decodeCharcode(&c);
const Props & vProps = getProps(i * props.letterDelay); glyphAppearance.charcode = glyphIdentity.charcode;
glyphAppearance.color.r = vProps.color[0];
glyphAppearance.color.g = vProps.color[1];
glyphAppearance.color.b = vProps.color[2];
glyphAppearance.color.a = vProps.color[3];
glyphAppearance.fontSize_px = vProps.fontSize_px;
for(const auto & fv : vProps.fontVariations){ for(const auto & fv : vProps.fontVariations){
glyphIdentity.coords.push_back( glyphIdentity.coords.push_back(
std::move(ofxGPUFont::float2f16dot16(round(fv.value * 0.1) * 10)) // convert to FT std::move(ofxGPUFont::float2f16dot16(round(fv.value * 0.1) * 10)) // convert to FT
@ -86,11 +98,25 @@ void GPUFontLayer::setProps(const Props & props){
); );
} }
variationText[i] = std::move(glyphIdentity); variationText[i] = std::move(glyphIdentity);
variationTextAppearance[i] = std::move(glyphAppearance);
i++; i++;
} }
} }
if(props.fontPath != propsBuffer[0].fontPath){ if(!setAppearanceAlready
&& !propsBufferEmpty
&& (propsBuffer[0].fontSize_px != props.fontSize_px
|| propsBuffer[0].color != props.color)){
for(int i = 0; i < props.text.size(); i++){
const Props & vProps = getProps(i * props.letterDelay);
ofxGPUFont::GlyphAppearance & glyphAppearance = variationTextAppearance[i];
glyphAppearance.fontSize_px = vProps.fontSize_px;
variationTextAppearance[i].color.r = vProps.color[0];
variationTextAppearance[i].color.g = vProps.color[1];
variationTextAppearance[i].color.b = vProps.color[2];
variationTextAppearance[i].color.a = vProps.color[3];
}
}
if(!propsBufferEmpty && props.fontPath != propsBuffer[0].fontPath){
notHappyWithMom = true; notHappyWithMom = true;
} }
@ -124,4 +150,7 @@ const LayerID & GPUFontLayer::getId(){
const vector <ofxGPUFont::GlyphIdentity> & GPUFontLayer::getVariationText(){ const vector <ofxGPUFont::GlyphIdentity> & GPUFontLayer::getVariationText(){
return variationText; return variationText;
} }
const vector <ofxGPUFont::GlyphAppearance> & GPUFontLayer::getVariationTextAppearance(){
return variationTextAppearance;
}
} }

View file

@ -48,22 +48,19 @@ class GPUFontLayer : public Layer {
ofNode & getInnerNode() override; ofNode & getInnerNode() override;
const vector <ofxGPUFont::GlyphIdentity> & getVariationText(); const vector <ofxGPUFont::GlyphIdentity> & getVariationText();
const vector <ofxGPUFont::GlyphAppearance> & getVariationTextAppearance();
//void setAtlas(shared_ptr <ofxGPUFont::Atlas> _atlas);
//shared_ptr <ofxGPUFont::Atlas> getAtlas() const;
//shared_ptr <ofxGPUFont::Atlas> atlas;
LayerSettings settings; LayerSettings settings;
std::deque <Props> propsBuffer;
/// \brief are props updated but not drawn yet /// \brief are props updated but not drawn yet
bool isDirty = true; bool isDirty = true;
/// \brief hashed id, or just counting up /// \brief hashed id, or just counting up
string id = ""; string id = "";
VFlipState vFlip = V_FLIP_UNKNOWN; VFlipState vFlip = V_FLIP_UNKNOWN;
vector <ofxGPUFont::GlyphIdentity> variationText; vector <ofxGPUFont::GlyphIdentity> variationText;
vector <ofxGPUFont::GlyphAppearance> variationTextAppearance;
private: private:
std::deque <Props> propsBuffer;
ComboIdentifier momsComboIdentifier; ComboIdentifier momsComboIdentifier;
bool notHappyWithMom = false; bool notHappyWithMom = false;
LayerType type = GPUFONT; LayerType type = GPUFONT;

View file

@ -30,7 +30,7 @@ class Layer {
float y = 200; float y = 200;
float rotation = 0; float rotation = 0;
float fontSize_px = 42; float fontSize_px = 42;
float color[4]; std::array <float, 4> color;
bool mirror_x = false; bool mirror_x = false;
float mirror_x_distance = 0; float mirror_x_distance = 0;
bool mirror_y = false; bool mirror_y = false;