Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read text from svg file #17

Closed
OriBibi opened this issue Nov 25, 2020 · 6 comments
Closed

Read text from svg file #17

OriBibi opened this issue Nov 25, 2020 · 6 comments
Labels
question Further information is requested

Comments

@OriBibi
Copy link

OriBibi commented Nov 25, 2020

I have seen the previous issues about reading text from svg file. Can I get more detailed about it? Or another example of the improvement you made? If I use the loadfromdata() function, what kind of string can be inserted into the function for reading text from svg?I tried to use the text tag but it was not so successful.

@sammycage
Copy link
Owner

Rendering text requires font so you have to call loadFontFromFile(<path to font file>) first before rendering. If i get your question correctly!? :-)

@sammycage
Copy link
Owner

Please clarify your question with an example!

@OriBibi
Copy link
Author

OriBibi commented Nov 25, 2020

I will use your example with a little change:

#include <lunasvg/svgdocument.h>

using namespace lunasvg;

int main()
{
    SVGDocument document;
    document.loadFontFromFile("ARLRDBD.TTF");
    document.loadFromData("<svg><text x="0" y="15" fill="red">I love SVG!</text></svg>");
    
    Bitmap bitmap = document.renderToBitmap();
    
    // do something useful with the bitmap.
    
    return 0;
}

Everything works great for me except the text. Maybe I need a particular font or all types of font should work?
I took the font from the fnots that windows provide (C:\Windows\Fonts).Maybe the string in loadFromData function invalid?. it doesn't work for me. Am I doing something wrong?
BTW thank you for amazing library!

@sammycage
Copy link
Owner

Please test whether this will fail.

#include <lunasvg/svgdocument.h>

#include <iostream>

using namespace lunasvg;

int main()
{
    SVGDocument document;

    if(!document.loadFontFromFile("ARLRDBD.TTF"))
        std::cout << "loadFontFromFile : Failed" << std::endl;

    if(!document.loadFromData("<svg><text x='0' y='15' fill='red'>I love SVG Too!</text></svg>"))
        std::cout << "loadFromData : Failed" << std::endl;

    Bitmap bitmap = document.renderToBitmap();

    // do something useful with the bitmap.

    return 0;
}

@OriBibi
Copy link
Author

OriBibi commented Nov 26, 2020

It works! thanks.

@sammycage
Copy link
Owner

You're welcome :-)

@sammycage sammycage added the question Further information is requested label Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants