Commit graph

313 commits

Author SHA1 Message Date
JunsuChoi
475fc22f6d loader SvgLoader: Fix memory leak
Add memory release for style->comp.url, which is the leaking memory.

[Valgrind Test Result]
==21595== 32 bytes in 1 blocks are definitely lost in loss record 29 of 152
==21595==    at 0x4C3217F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21595==    by 0x5C248C6: _idFromUrl(char const*) (tvgSvgLoader.cpp:272)
==21595==    by 0x5C24DE1: _handleClipPathAttr(SvgLoaderData*, SvgNode*, char const*) (tvgSvgLoader.cpp:860)
==21595==    by 0x5C260CC: _attrParseGNode(void*, char const*, char const*) (tvgSvgLoader.cpp:953)
==21595==    by 0x5C2ABA9: simpleXmlParseAttributes(char const*, unsigned int, bool (*)(void*, char const*, char const*), void const*) (tvgXmlParser.cpp:272)
==21595==    by 0x5C26F6E: _createGNode(SvgLoaderData*, SvgNode*, char const*, unsigned int) (tvgSvgLoader.cpp:1063)
==21595==    by 0x5C27A04: _svgLoaderParserXmlOpen(SvgLoaderData*, char const*, unsigned int, bool) (tvgSvgLoader.cpp:2168)
==21595==    by 0x5C27CE9: _svgLoaderParser(void*, SimpleXMLType, char const*, unsigned int) (tvgSvgLoader.cpp:2226)
==21595==    by 0x5C2AC8C: simpleXmlParse(char const*, unsigned int, bool, bool (*)(void*, SimpleXMLType, char const*, unsigned int), void const*) (tvgXmlParser.cpp:378)
==21595==    by 0x5C27E09: SvgLoader::run(unsigned int) (tvgSvgLoader.cpp:2571)
==21595==    by 0x5C1A7C1: operator() (tvgTaskScheduler.h:68)
==21595==    by 0x5C1A7C1: tvg::TaskSchedulerImpl::run(unsigned int) (tvgTaskScheduler.cpp:138)
==21595==    by 0x5EED6DE: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
2021-05-03 16:29:30 +09:00
Hermet Park
1d923a8632 loader svg: fix build break due to typo 2021-05-01 12:37:45 +09:00
Hermet Park
e1ebcf6153 loaders svg: code refactoring
split functions as its purpose.
2021-04-21 11:12:22 +09:00
JunsuChoi
51e4757a3b loader SvgLoader: Fix wrong debug log
1.
Modify that attribute information used for use type
looks like it was used for g type.

2.
Fix clippath node looking like setting "none"
(clippath's display = false is intentional)
2021-04-21 11:11:37 +09:00
JunsuChoi
8b54b6768a loader SvgLoader: add locale-independent strtof function
strtof's behavior is changed by system locale.
https://linux.die.net/man/3/strtof

Because of this, strtof(10.0000) returns 0.0 in some locales.
When a given value string is locale-independent, strtof has to be
replaced to custom function.
2021-04-20 19:44:04 +09:00
Hermet Park
b541a0654c loaders svg: ++safety
prevent buffer overflow just in case.
2021-04-20 17:49:48 +09:00
Mira Grudzinska
332012dd6b loader svg: displaying SVG images without the specified viewBox attribute
If no viewBox attribute is given, the height and width attributes are used
to establish the viewBox size. However, this information was not available
inside the scene builder, even though it was needed.
2021-04-15 04:34:44 -07:00
JunsuChoi
5d81fe2446 loader SvgLoader: Fix for coding convention 2021-04-13 19:01:19 +09:00
JunsuChoi
b75e7ea91a loader SvgLoader: return null if transform attribute invalid
In transform matrix parsing, null is returned if any of the matrices are invalid.
2021-04-13 19:01:19 +09:00
Hermet Park
d3a73f7ee9 loaders svg: fix a wrongly handles the corner case.
Stop the internel loop quick as possible, and state must be reset.
2021-04-13 17:49:29 +09:00
Hermet Park
b3559ecf56 loaders svg: code refactoring.
keep it clean & neat within tvg coding convention.
2021-04-13 17:16:38 +09:00
Hermet Park
d2c04f6037 wasm: fix compile errors. 2021-04-09 22:18:57 +09:00
Hermet Park
5c9016158e loader svg: fix composition(mask/clip) issue.
composition target missed transform of its source.

That brings incorrect composition area.

This fixes it.
2021-04-09 21:02:55 +09:00
Hermet Park
35fdc9a278 loaders svg: set default color for composition paint.
not only clippath but alpha compositions might also have any valid color.
Set it default and let it override values while appending shapes if it's necessary.
2021-04-09 17:10:20 +09:00
Hermet Park
903df3da6a loaders svg: prevent composition setting if the result shape is invalid.
Current loader could return invalid shapes -default, from _appendShape()-
by a certain interpretation result,

Though it's a wrong or exception case, we can prevent worse case by avoiding it.
2021-04-09 16:51:05 +09:00
Hermet Park
e1eb98af79 loaders svg: code refactoring
clean up code and remove unnecessary internal class.

this also helps to reduce binary size by 5.5kb

no logical changes.
2021-04-09 15:57:23 +09:00
Hermet Park
adf1312a5e loaders svg: ++ log info for wrong situation.
if either log is printed, we need to improve the composition method.
2021-04-09 11:02:35 +09:00
Hermet Park
605a3bf175 loaders svg: code refactoring
++ clean code.
2021-04-09 10:55:09 +09:00
Hermet Park
6239eca92f loaders svg: fix invalid clip path result.
tvg engine expects the valid clippath with valid colors,
loaders set any colors values to enable it.

this fixes invalid clippath behavior.
2021-04-08 17:54:25 +09:00
Hermet Park
cd0c7486f3 loader png: code refactoring
Seperate behaviors open/read/close,
free/close pngimage properly,
add copyright for files.

There still left one optimization point by applying Task.
2021-04-02 12:50:38 +09:00
Hermet Park
9e725226da
meson: revise png loader meson script.
We hate spagettie code, not even build script.
this revise it to keep the build script consistency.
2021-04-02 12:49:18 +09:00
Mateusz Palkowski
832568e07a Added libpng based png loading 2021-04-01 19:38:00 +09:00
Hermet Park
1a7d41ce71 updated copyright 2021-03-23 14:31:58 +09:00
Mira Grudzinska
234a9b2f93
svg_loader: ommiting xml entities in the svg file (#278)
SVG files created using 'sketch' may contain xml entities,
which are not understandable by the svg loader.
For now only '"' is ommited.
2021-03-23 09:22:46 +09:00
Hermet Park
79f1ba8516 loader svg: fix coding convention 2021-03-22 16:28:08 +09:00
Mira Grudzinska
f0540d753a svg_loader: applying AlphaMask during scene building
The AlphaMask composition case was omitted in the _sceneBuilderHelper().
2021-03-22 10:45:14 +09:00
Hermet Park
c40823d70e loaders svg: remove unnecessary move call, move is guaranteed at the return value.
warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
2021-03-16 13:29:16 +09:00
JunsuChoi
631c1e5651 loader SvgSceneBuilder: Add root node to clipping viewBox.
If the boundary of scene created through the scenebuilder is larger than the viewbox,
scene(SVG's root) should be clipped to the size of the viewbox.
So, if scene need a clip, add a parent root and add clippath composition to that root.
2021-03-15 15:24:10 +09:00
Hermet Park
9f0fafa5df This is too untable.... Stress in example is crashed by this.
Revert "svg_loader: limiting the ploted area of svg to viewBox"

This reverts commit 2bb108b2f1.
2021-03-12 18:10:26 +09:00
Mira Grudzinska
2bb108b2f1 svg_loader: limiting the ploted area of svg to viewBox
The 'viewBox' element given in the svg file determines
the coordinates of the plotted area. ClipPath used in Svg loader.
2021-03-12 10:54:38 +09:00
JunsuChoi
355cc8c253 svg_loader SvgPath: Remove unnecessary optimization code
This condition(optimization) is not a step suggested by arc implementation.
https://www.w3.org/TR/SVG11/implnote.html#ArcCorrectionOutOfRangeRadii (Step2)
This code is useful if the arc is too small to represent.
However, scaling often occurs in vectors, which can create unnecessary problems.

example path
<path d="M32.41,20.49a.41.41,0,1,1-.41-.42A.41.41,0,0,1,32.41,20.49Z" transform="translate(0)" fill="#020202"/>
2021-03-05 16:39:16 +09:00
JunsuChoi
f590571e3a svg_loader SvgLoader: Fix copy conditions for stop of gradient
When getting a linked stop list, if there is no existing stop list
in current gradient, it is copied.
2021-03-04 18:43:58 +09:00
Mira Grudzinska
a173b16ed5 svgloader: fixing linear gradient transformation
Gradient stop points were incorrectly transformed when building
the scene in the SVG loader.
2021-03-03 19:48:26 -08:00
Mira Grudzinska
a72be6159d svgloader: fixing SVG image display when viewBox size is not given
When viewBox is not given its dimensions should be determined
by the height and width parameters
2021-03-03 18:02:36 -08:00
Mira Grudzinska
d03db583e5 svgloader: fillRule value passed to the shape
The value was loadeed but not set to the shape.
2021-03-02 18:05:54 -08:00
Hermet Park
197879f2ef fixed all wasm build breaks. 2021-02-23 10:47:46 +09:00
Patryk Kaczmarek
795121fa67 SvgLoader: Mask style implementation
Supprot case when style is defined as <mask> attribute.

[Example SVG file]
```html
<svg version="1.1" id="Layer_1" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve"
  xmlns="http://www.w3.org/2000/svg">
  <defs>
    <mask id="myMask">
      <circle id="maskID" cx="40" cy="40" r="10" fill="white" fill-opacity="1" />
    </mask>
  </defs>
  <rect x="0" y="0" width="64" height="64" style="fill: skyblue; mask=url(#myMask);"/>
</svg>
```

Change-Id: I3b856db85204bf7c503a20e4023417ca79aa930c
2021-02-19 18:23:47 +09:00
JunsuChoi
415fca577e common: TVG_UNUSED marking on unused parameter 2021-02-19 16:51:50 +09:00
JunsuChoi
c819754056 common: Refactoring incorrectly declared loop variable
Loop variables should be declared in the minimal possible scope
thorvg prefers to declare when using local variables.
2021-02-19 16:51:50 +09:00
JunsuChoi
08c37978a9 common: Pointer that can declare const are refactored to use const
Pointer and reference parameters should be "const" if the corresponding object is not modified
2021-02-19 16:51:50 +09:00
JunsuChoi
c63f961b9c common: Clean up code
- Combine if condition with the same return value.
- Remove empty space
- Remove tab
2021-02-18 14:03:47 +09:00
JunsuChoi
5c914f4ad2 svg_loader SvgLoader: Prevent memory leak
When OOM of SvgLinear/RadialGradient occurs,
the allocated id, ref, transform may become a memory leak.
Therefore, add free memory.
2021-02-02 10:51:50 +09:00
Hermet Park
e737ee4a4f svg_loader: fixed wrong boundary check
sz must be less than 20 to append 'carriage return'
2020-12-22 11:04:39 +09:00
Hermet Park
59ffa16b32 raw_loader: remove unnecessary declaration. 2020-12-22 10:55:23 +09:00
JunsuChoi
438b7d6b02 svg_loader SvgLoader: Add memory allocation failed check
Prevent to null access when out of memory.
2020-12-18 19:51:06 +09:00
JunsuChoi
21b751291a raw_loader RawLoader: Add initialize
Add initialization to 'copy' member
2020-12-18 19:51:06 +09:00
JunsuChoi
f13e1947ff svg_loader SvgLoader: Prevent array overflow
Since tagName array set '\0' at the end,
it may overflow when sz reaches 20.
So make it a maximum of 19.
2020-12-18 19:51:06 +09:00
Hermet Park
cee1348a44 svg_loader XmlParser: code refactoring.
just renamed _nodeTypeToString() -> xmlParserNodeTypeToString()

+ print meson message if log is enabled.
2020-12-17 16:11:09 +09:00
JunsuChoi
23331cf8d4 svg_loader SvgLoader: Print inefficient elements
Opacity is 0
both Fill.Opacity and Stroke Opacity are 0
point is 0 in Path
declared display="none"
width or height of bounds becomes 0
2020-12-17 13:56:09 +09:00
Shinwoo Kim
135e6c872b fix typo 2020-12-16 09:58:40 +09:00