GithubHelp home page GithubHelp logo

lunasvg's People

Contributors

etodanik avatar ewouth avatar fdwr avatar lemirep avatar lhlaurini avatar lolpie244 avatar m-carrasco avatar reputeless avatar sammycage avatar seanharmer avatar toge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lunasvg's Issues

Generating SVG

Nice project!
I am looking for a simple library to generate simple svg files: only multiple pieces of text
and multiple bounding boxes. Would it be easy to carve out the svg generating code into a separate
part of the library? I can work on it, just wondering if it is easy to do ?
Thanks!
Aaron

Add a supported SVG element matrix

SVG Element Supported
svg ๐Ÿ‘
g ๐Ÿ‘
clipPath ๐Ÿ‘
defs ๐Ÿ‘
ellipse ๐Ÿ‘
line ๐Ÿ‘
path ๐Ÿ‘
polyline ๐Ÿ‘
polygon ๐Ÿ‘
rect ๐Ÿ‘
marker ๐Ÿ‘
mask ๐Ÿ‘
linearGradient ๐Ÿ‘
radialGradient ๐Ÿ‘
pattern ๐Ÿ‘
solidColor ๐Ÿ‘
stop ๐Ÿ‘
symbol ๐Ÿ‘
text ๐Ÿ‘
use ๐Ÿ‘
text โ›”๏ธ
filter โ›”๏ธ
image โ›”๏ธ
style โ›”๏ธ

svg format supported?

Hi I would like to know if Luna library can process this type of struct:

<style type="text/css"> text { font-size: 9; } rect { fill: none; stroke: blue; } </style>

Use lunasvg in iOS Xcode project

Is it possible to use lunasvg in iOS?
so far so good

char *input_image = strdup([[[NSBundle mainBundle] pathForResource:@"1" ofType:@"svg"] UTF8String]);

    NSLog(@"%s",input_image);
    auto document = Document::loadFromFile(input_image);
 
    auto bitmap = document->renderToBitmap();

    NSLog(@"%d",bitmap.width()); 

Seems it works , but how can I convert lunasvg::Bitmap to UIImage (iOS)
I try use stb_image_write.h to write the file to the iOS Documents folder ,then load it as UIImage
but got an error
Undefined symbol: _stbi_write_png

So I make the liblunasvg.a , and included in the xcode project

But another error
/Users/tang/Desktop/lunasvg_/lunasvg.xcodeproj Building for iOS, but the linked library 'liblunasvg.a' was built for macOS.

Any solution?
Thanks

Feature : stroke-dasharray

Hi the rasterizer is pretty good but lack of StrokeDash array support.
Do you plan to implement this feature in near future?

SpecRef: https://www.w3.org/TR/SVG11/painting.html#StrokeDasharrayProperty

Here the kind of SVG we generate, and the result we obtain (i use roboto-regular.ttf)

<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" width="43.95" height="43.95" viewBox="26.75 26.75 146.5 146.5">
<path d="M63,63 C63,20 137,20 137,63 C180,63 180,137 137,137 C137,180 63,180 63,137 C20,137 20,63 63,63 Z" stroke-width="4" stroke-dasharray="8,12" stroke="black" fill="rgb(255, 255, 128)" ></path>
<path d="M50,65L150,135M50,135L150,65" stroke-width="4" stroke="black" fill="black" ></path>
<text x="100" y="77" text-anchor="middle" font-size="30" font-family="Arial"  font-weight="bold" stroke-width="4" stroke="black" fill="black" >R</text>
<path d="M75,140 C75,125 100,125 100,140 C100,125 125,125 125,140" stroke-width="4" stroke="black" fill="none" ></path>
</svg>

test_0312

API for background image

Using Bitmap(std::uint8_t* data, std::uint32_t width, std::uint32_t height, std::uint32_t stride); one can supply a custom buffer with a background image.

However, both render and renderToBitmap have a background color. Does this mean that lunasvg will always overwrite the custom background?

Is there a time plan for an animated version?

This is a cool library, I found it by accident because I need to render SVG animation in my App, but unfortunately it does not currently support animation, otherwise I can happily introduce it to my ^_^

In addition, NanoVG is good, and there is hope that SVG can be rendered in real time. Have you considered using NanoVG?

Read text from svg file

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.

render TEXT element

Hi, I would like to know if is possible read and render Text element from svg file

Consistency in Scaling

Hi, @sammycage.

When I changed documentWidth and documentHeight in the svg2png example as follows, the image content was cropped in some cases.

        double documentWidth = document.documentWidth() * 0.5;
        double documentHeight = document.documentHeight() * 0.5;

scaled:

image

cropped:

image

Is there a consistent way to scale the content to fit the lunasvg::Bitmap size without cropping?

svgren has a option to request a size, and it works as I expect.
https://github.com/igagis/svgren/blob/ca45437ab6b89430c8336404889b00bc5f0147ef/src/svgren/render.hpp#L12-L27

Here are the test files.

The order of multiplication of the document matrix is โ€‹โ€‹not clearly indicated

By doing

document
    ->scale(0.5, 0.5)
    ->translate(0, 25)

I would expect the document to be scaled, then translated by the appropriate amounts

But since the translate function is implemented as

Document* Document::translate(double tx, double ty)
{
    root->transform.translate(tx, ty);
    return this;
}

which in turn

Transform& Transform::translate(double tx, double ty)
{
    *this = translated(tx, ty) * *this;
    return *this;
}

which is actually a pre-multiply as indicated by:

Transform& Transform::premultiply(const Transform& transform)
{
    *this = transform * *this;
    return *this;
}

Transform& Transform::postmultiply(const Transform& transform)
{
    *this = *this * transform;
    return *this;
}

by doing

document
    ->scale(0.5, 0.5)
    ->translate(0, 25)

you first translate, then scale the document instead of the (expected) other way around.

I believe Document::translate and consorts (Document::scale, Document::rotate and Document::shear) should be implemented with an explicit post-mutiply

Document* Document::translate(double tx, double ty)
{
    root->transform.postMultiply(Transform::translated(tx, ty));
    return this;
}

Run on linux

Does the library have the ability to run on LINUX? If yes, is it possible to get a CMakeLists.txt file to help me with this? Or another guide about how to work with the library on LINUX .

Sliding over SVG?

Currently I am using nanosvg on some project and I want to change it with lunasvg because of performance issues. However when I try to render some SVG string I get whole SVG rendered like this (btw I am using translate method to shift the svg.):
luna_out

However I want to process this normally big (7k x 7k) image tile by tile. With nanosvg I could do this with no overhead.
Is there any way to achieve this in lunasvg?
Currently my code is like this:

	svgImage = lunasvg::Document::loadFromData(svgStr);
	svgImage->translate(-x, -y) ;
	lunasvg::Bitmap bitmap = svgImage->renderToBitmap(width, height);
        
        // opencv section
        auto res = cv::Mat(height, width, CV_8UC4);
	res.data = bitmap.data();
	cv::cvtColor(res, res, CV_RGBA2GRAY);
	res = res > 0;

Updating text element content

Hi !

We are using SVGs as a template for engineering drawings. We want to dynamically replace the content of specific text elements to display calculated values. We tried to use SVGElement::insertContent(...) for this but we were not succesful.

SVGElement* test = document.getElementById("text1"); test->insertContent("12345", InsertPosition::AfterBegin);

We traced it down into the parser and found out that the TagType is detected as KTagPCData but since the blocks stack is empty the if-branch for this Tagtype is not executed.

else if(tagType==KTagPCData && !blocks.empty())
{
SVGElementText* element = new SVGElementText(document, content);
element->parent = blocks.top();
element->prev = current;
current->next = element;
current = element;
}

We were able to reach our desired functionality with changes to the parser but we are not sure if we are possibly just using the existing possibilities in a wrong way.

Update:

I pushed the changes we are testing at the moment to our fork

https://github.com/mxdamien/lunasvg/commit/36b824eee63f65b753e72830e9dfa6d27fb070d4

Regards,

David

Feature request: text path

Hi,

First thank you for lunasvg, I love how fast it is compared to others.

TextPath aren't supported yet and I don't see it mentioned in the todo,
so today it is not possible to do something like:

TextPath

This example also makes use of the attributes "textLength", "textAdjust" and "startOffset".

(svg: TextPath.zip)

Would it be possible to add it to the list ?

Build fails with vcpkg dependencies

I have cairo installed via vcpkg.

cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:\Users\Administrator\vcpkg\scripts\buildsystems\vcpkg.cmake"

Build still does not detect cairo.
CMakeOutput.log

-- Found PkgConfig: C:/MinGW/bin/pkg-config.exe (found version "0.23")
-- Checking for module 'cairo'
-- No package 'cairo' found
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPkgConfig.cma
ke:545 (message):
A required package was not found
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.18/Modules/FindPkgConfig.cmake:733 (pkg
check_modules_internal)
CMakeLists.txt:22 (pkg_check_modules)

Cannot parse some SVG's tile by tile

I have two SVG's. One is smaller (12k x 7k) other one is bigger (28k x 32k) I can parse the smaller one tile by tile with no problem. But with other one I get Access Violation error. I triple checked the code and cannot find any problem. Here is a sample code to reproduce it:

std::vector<std::vector<float>> tileParamList; // coordinates from the json file
const int width = 1024;
const int height = 1024;
auto svgImage = lunasvg::Document::loadFromData(svgStr);

for (int i = 0; i < tileParamList.size(); i++)
{
	lunasvg::Bitmap bitmap{ width, height };
	lunasvg::Matrix matrix{ 1, 0, 0, 1, -tileParamList[i][0], -tileParamList[i][1] };
	
	svgImage->render(bitmap, matrix); <----------- HERE

	auto res = cv::Mat(height, width, CV_8UC4);
	res.data = bitmap.data();
	cv::cvtColor(res, res, CV_RGBA2GRAY);
	res = res > 0;
}

SVG and tileList can be found here: broken.zip
And other SVG can be found here (One that works correctly. Note: First few iterations might be blank image.): notbroken.zip

build the library in x64

I get an error when I try to build the library in x64. This is the error I get:

Error LNK1112 module machine type 'x64' conflicts with target machine type 'x86'
lunasvg C:\lunasvg-master\build\x64\Debug\affinetransform.obj

How should I build lunasvg in x64?

Render to gray-scale

Your library set Bitmap to be RGBA only. The RenderToBitmap function is good but I need RenderToGrayScale function. Is it possible to add support or any conversion option to gray-scale as well?

LINKER ERROR

I cann't declare VGDocument document. Maybe, I forget .lib files ?
My code:

 #include "lunasvg/include/svgdocument.h
 using namespace lunasvg;
 SVGDocument document;

However, this won't compile and gives many errors similar to:
Error LNK2019 unresolved external symbol "public: __thiscall lunasvg::SVGDocument::SVGDocument(void)" (??0SVGDocument@lunasvg@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'document''(void)" (??__Edocument@@yaxxz)

Text support under TODO

Hello. I saw that you entered the text support under TODO and also downloaded the "loadFontFromFile" function for loading text. Do you know when the text support is expected to return. And will the support include the "font-family" attribute?

Text anchor is not working properly

I'm trying to draw text based off this svg string:

<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" width="341.33333333333326" height="176" viewBox="-33.33333333333333 1 341.3333333333333 176"></path></g><text x="5" y="160" te
xt-anchor="end" font-size="40" font-family="Arial" stroke-width="4" stroke="none" fill="black" >A</text><text x="195" y="160" text-anchor="start" font-size="40" font-family="Arial" stroke-width="4" stroke="none" fill="black" >1-327</text></svg>

I tested it online and it works, I'm guessing however some setting inside this svg isn't supported yet? My question is what can I remove or change about this svg while keeping the basic text and text location and have it show up using lunasvg?

Tested using built 1.4.2 version of the library, or should I be just using master?

Any help is appreciated, thank you.

How to get lunasvg version number?

The About dialog in the app displays a summary of the products used. How to get lunasvg version number?

MMEX is using the following support products:
โ€ข wxWidgets 3.1.5 (wxMSW 10.0)
โ€ข wxSQLite3 4.6.0 (SQLite 3.31.1)
โ€ข RapidJSON 1.1.0
โ€ข Lua 5.3.5
โ€ข lunasvg 
โ€ข libcurl/7.61.1-DEV WinSSL
โ€ข gettext 0.21
โ€ข apexcharts.js

Thanks

[Feature] support 'rgba()'

I find when I using document.loadFromData, I get a wrong fill when using rgba().

int main() {
  // ...
  lunasvg::SVGDocument document;
  document.loadFromData(base64_decoded); // base64_decodede: "<svg xmlns='http://www.w3.org/2000/svg' fill='rgba(255,123,123,1)'><path d='M0 0L375 0L375 88L0 88L0 0Z' /></svg>"

  std::cout << document.toString() << std::endl; // I got: "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" style=\"fill:#000000;\">\n\t<path d=\"M0 0 L375 0 375 88 0 88 0 0 Z\"/>\n</svg>\n"
}

Can lunasvg support the rgba and rgb the same as modern browser behavior (like Chrome, Fireox...).

Issues linking, compiler statement fine

I built the library from source via cmake .. inside my build folder, then used the generated Visual Studio project to build all files. In Debug, I copied the newly-generated library file into my MinGW's library path. After, I created the following example project:

#include <lunasvg.h>

int main () {
	using namespace lunasvg;

	auto doc = Document::loadFromFile ("svgtest.svg");
	if (doc == nullptr)
		return 1;

	doc->rotate (45);
	Bitmap bitmap = doc->renderToBitmap ();

	return 0;
}

then compiled with g++ test.cpp -o b.exe -llunasvg:

C:\Users\james\AppData\Local\Temp\ccr7qqTq.o:test.cpp:(.text+0xc0): undefined reference to `lunasvg::Document::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>
> const&)'
C:\Users\james\AppData\Local\Temp\ccr7qqTq.o:test.cpp:(.text+0x10c): undefined reference to `lunasvg::Document::rotate(double)'
C:\Users\james\AppData\Local\Temp\ccr7qqTq.o:test.cpp:(.text+0x140): undefined reference to `lunasvg::Document::renderToBitmap(unsigned int, unsigned int, unsigned int) const'
C:\Users\james\AppData\Local\Temp\ccr7qqTq.o:test.cpp:(.text$_ZNKSt14default_deleteIN7lunasvg8DocumentEEclEPS1_[__ZNKSt14default_deleteIN7lunasvg8DocumentEEclEPS1_]+0x14): undefined reference to `lunasv
g::Document::~Document()'
collect2.exe: error: ld returned 1 exit status

No errors had shown up in my IDE, and had the library not existed, MinGW would have told me. Have I missed a step?

Gradient support

linearGradient doesn't seem to be working with the file below. Is this something I'm doing wrong, or isn't implemented yet?

<?xml version="1.0" encoding="iso-8859-1"?>
<svg version="1.1" viewBox="0 0 300 300" x="50%" y="50%" width="300" height="300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <defs>
        <linearGradient id="myGradient" gradientTransform="rotate(90)">
            <stop offset="5%"  stop-color="gold" />
            <stop offset="95%" stop-color="red" />
        </linearGradient>
    </defs>

    <!-- using my linear gradient -->
    <circle cx="150" cy="150" r="150" fill="url('#myGradient')" />
</svg>

Bitmap compatibility

Hi, I will like to know if is possible or there is some kind of compatibility to cast lunasvg::Bitmap to CBitmap.
Regards

Add the ability to replace colors

void set_convert_colors(Dictionary *p_replace_color) {
	if (p_replace_color) {
		Dictionary replace_color = *p_replace_color;
		for (int i = 0; i < replace_color.keys().size(); i++) {
			Variant o_c = replace_color.keys()[i];
			Variant n_c = replace_color[replace_color.keys()[i]];
			if (o_c.get_type() == Variant::COLOR && n_c.get_type() == Variant::COLOR) {
				Color old_color = o_c;
				Color new_color = n_c;
				replace_colors.old_colors.push_back(old_color.to_abgr32());
				replace_colors.new_colors.push_back(new_color.to_abgr32());
			}
		}
	} else {
		replace_colors.old_colors.clear();
		replace_colors.new_colors.clear();
	}
}

Use to make light and dark theme variations of svg icons.

Feature request: embedded bitmap

Hi, Iโ€™m looking for a way to display shadows using lunasvg. I know that svg filters (like gaussian blur) are not implemented. Is there any chance for embedded images support, so I can use shadows like this example?
example.zip

How to add this library as external using git submodule?

I cannot find variables like LUNASVG_INCLUDE_DIRS and LUNASVG_LIBRARIES to use.

add_subdirectory(${EXTERNAL_DIR}/lunasvg)
target_include_directories(main PRIVATE ${LUNASVG_INCLUDE_DIRS})
target_link_libraries(main ${LUNASVG_LIBRARIES})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.