Chlumsky / msdf-atlas-gen

MSDF font atlas generator
MIT License
783 stars 175 forks source link

set inverseYAxis of Shape #67

Closed themancalledjakob closed 1 year ago

themancalledjakob commented 1 year ago

When generating the atlas with some fonts, I need to set inverseYAxis to true, but I cannot find a way to do this without removing const from GlyphGeometry's getShape() function. My intuition tells me, that there is a good reason for const here, and it shouldn't just be removed. Another option would be to const_cast the shape. This also feels weird, but has the advantage that nothing would have to be changed in this repository.

To clarify, here how I do it:

[...]
            // Storage for glyph geometry and their coordinates in the atlas
            std::vector <msdf_atlas::GlyphGeometry> glyphs;
[...]
            for(msdf_atlas::GlyphGeometry & glyph : glyphs){
                glyph.getShape().inverseYAxis = true; // only works if we remove const from GlyphGeometry::getShape()

                // or we do a const_cast
                msdfgen::Shape & shape = const_cast <msdfgen::Shape &>(glyph.getShape());
                shape.inverseYAxis = true;

                glyph.edgeColoring(&msdfgen::edgeColoringInkTrap,
                                   3.0, // max corner angle
                                   0); // seed
            }
[...]

Is there a better way? If not, what about either an additional non-const function for getShape, or an additional inverseYAxis parameter when loading the glyphs in FontGeometry::loadCharset and GlyphGeometry::load?

I assume I am not the only one running into this, but if you think const_casting is fine, feel free to simply close this issue. Otherwise I'm happy to send you a PR, or, if there is a better way to do this I would greatly appreciate a pointer in the right direction.

Chlumsky commented 1 year ago

Which font needs its Y-axis inverted? I've never seen one before.

themancalledjakob commented 1 year ago

Thank you for the reply.

You're right, the font does not need an inverted Y-axis. The error must be in the way that I'm handling the atlas later. When I create an atlas with the same font using standalone msdf-atlas-gen, the Y-axis is fine. This is a bit embarrassing, I should have checked that before. Thank you anyways for having a look.

I'll close this now.