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

View file

@ -66,18 +66,30 @@ void GPUFontLayer::setMomsComboIdentifier(const ComboIdentifier & identifier){
void GPUFontLayer::setProps(const Props & props){
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){
setAppearanceAlready = true;
OFX_PROFILER_SCOPE("variations");
setDirtyDirty(true);
variationText.clear();
variationText.resize(props.text.size());
variationTextAppearance.clear();
variationTextAppearance.resize(props.text.size());
int i = 0;
for(const char c : props.text){
OFX_PROFILER_SCOPE("char");
const Props & vProps = propsBufferEmpty ? props : getProps(i * props.letterDelay);
ofxGPUFont::GlyphIdentity glyphIdentity;
ofxGPUFont::GlyphAppearance glyphAppearance;
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){
glyphIdentity.coords.push_back(
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);
variationTextAppearance[i] = std::move(glyphAppearance);
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;
}
@ -124,4 +150,7 @@ const LayerID & GPUFontLayer::getId(){
const vector <ofxGPUFont::GlyphIdentity> & GPUFontLayer::getVariationText(){
return variationText;
}
const vector <ofxGPUFont::GlyphAppearance> & GPUFontLayer::getVariationTextAppearance(){
return variationTextAppearance;
}
}

View file

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

View file

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