sammycage / lunasvg

lunasvg is a standalone SVG rendering library in C++
MIT License
818 stars 115 forks source link

Unable to rotate image with rotate or scale #149

Closed caiovlp closed 6 months ago

caiovlp commented 6 months ago

I'm trying to rotate an image with transform rotate or scale and neither seem to be working. Here's an example:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
    xml:space="preserve" id="svg89" version="1.1" viewBox="0 0 100 100" transform="scale(-1 -1)">
    <g id="test" class="test">
        <path xmlns="http://www.w3.org/2000/svg" d="M30,76q6-14,13-26q6-12,14-23q8-12,13-17q3-4,6-6q1-1,5-2q8-1,12-1q1,0,1,1q0,1-1,2q-13,11-27,33q-14,21-24,44q-4,9-5,11q-1,2-9,2q-5,0-6-1q-1-1-5-6q-5-8-12-15q-3-4-3-6q0-2,4-5q3-2,6-2q3,0,8,3q5,4,10,14z" fill="green"/>
    </g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
    xml:space="preserve" id="svg89" version="1.1" viewBox="0 0 100 100" transform="rotate(180)">
    <g id="test" class="test">
        <path xmlns="http://www.w3.org/2000/svg" d="M30,76q6-14,13-26q6-12,14-23q8-12,13-17q3-4,6-6q1-1,5-2q8-1,12-1q1,0,1,1q0,1-1,2q-13,11-27,33q-14,21-24,44q-4,9-5,11q-1,2-9,2q-5,0-6-1q-1-1-5-6q-5-8-12-15q-3-4-3-6q0-2,4-5q3-2,6-2q3,0,8,3q5,4,10,14z" fill="green"/>
    </g>
</svg>

Both are valid SVGs and are rotated correctly on the browser but yield a blank image when using lunasvg.

For reference, this is how I'm using it to render an SVG with OpenGL:

auto bitmap = document->renderToBitmap();
bitmap.convertToRGBA();

GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bitmap.width(), bitmap.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap.data());

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Here's the original image rendered successfully: Oirignal

Here's the rotated image blank: Rotated

sammycage commented 6 months ago

Interesting https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin

sammycage commented 6 months ago

Fixed. If you are experiencing any issues, let me know; otherwise, close this issue.

caiovlp commented 6 months ago

That was really fast. Looks great! Thanks