Commit graph

313 commits

Author SHA1 Message Date
JunsuChoi
113ca8b845 svg_loader SvgPath: Added corner case handling for flags of Arc
Moved the if statement to check if it is a float.

This patch is that reverts and fixes the reverted patch 55a5b9.
2021-07-02 12:49:00 +09:00
Hermet Park
55a5b9492b Revert "svg_loader SvgPath: Added corner case handling for flags of Arc"
This reverts commit 5da4c81138.

Please double-check this regression bug:

examples/images/samsung-galaxy-s.svg
2021-07-01 18:04:25 +09:00
Mira Grudzinska
f411b5a64c svg_loader: recalculating the default values of grads
The default values of gradient properties were handled differently
than the values given by a user/in an svg file.
2021-07-01 12:15:55 +09:00
Michal Maciola
3086f28b55
svg_loader: allow multiple <defs> tags without data and memory leak (#528)
* svg_loader: allow multiple defs without data and memory leak

If the svg file contained multiple <defs> tags, each subsequent tag
overwritten the previous tag. This resulted in incorrect rendering of the
file and memory leaks.

@Issues: 491

* svg_loader: allow multiple defs without data and memory leak- fix #1

Changed the idea to abandon node creating instead of deleting it after
creation. Removed simpleXmlParseAttributes for _createDefsNode.
2021-06-30 17:21:30 +09:00
Hermet Park
19a3190245 svg_loader: fix a infinite loop error by circular dependency.
Composition can be applied recursively if its children nodes have composition target to this one.
This can be occured by wrong svg description, and tvg prevents this exception case.

@Issue: https://github.com/Samsung/thorvg/issues/494
2021-06-30 16:12:16 +09:00
Hermet Park
fcbc77bcdf svg_loader: code refactoring
unify to tvg fill rule.
2021-06-30 15:18:14 +09:00
Hermet Park
2c24a1fa5e svg_loader: recover partial code from 3e7888b538
oops, log was not tested in the patch...
2021-06-30 15:12:15 +09:00
Hermet Park
571a1e5caa svg_loader: code refactoring
remove more unused declarations...
2021-06-30 14:54:22 +09:00
Hermet Park
3e7888b538 svg_loader: code refactoring
use color structure to keep neat & compact code.
2021-06-30 14:54:12 +09:00
Hermet Park
8dc5d5204b svg_loader: code refactoring
remove unused declaration.
2021-06-30 13:47:22 +09:00
Hermet Park
6a79d2c06e svg_loader: fix the inifite loop bug when size has 'em' unit.
svg may have 'em' unit for fonts, strtof() must handle this case to not
drop in the infinite loop.

Yet thorvg doesn't support font feature in svg,
it must multiply values with font size if those values have 'em' size.

@Issue: https://github.com/Samsung/thorvg/issues/488
2021-06-30 11:27:31 +09:00
Mira Grudzinska
feb71ff36c svg_loader: currentColor - inheritance from a parent
The 'currentColor' attribute value was not inherited. Fixed.
2021-06-29 09:27:52 +09:00
Michal Maciola
520d6e7bbd svg_loader: negative attrs length fix
After finding no attributes but white spaces, attrs length could be negative
that resulted in segmentation fault in simpleXmlParseAttributes function.

@Issue: #487
2021-06-28 16:46:26 +09:00
Hermet Park
78bb8d1f2e svg_loader: fix trivial build warnings.
../src/loaders/svg/tvgSvgLoader.cpp: In function ‘void _copyAttr(SvgNode*, const SvgNode*)’:
../src/loaders/svg/tvgSvgLoader.cpp:1598:60: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct SvgStyleProperty’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
     memcpy(to->style, from->style, sizeof(SvgStyleProperty));

@Issue: 498
2021-06-28 13:47:15 +09:00
Mira Grudzinska
57a22b8462 svg_loader: finish the search after founding the proper color
In the _toColor func, after founding the proper color, the search
should be finiched.
2021-06-28 11:32:44 +09:00
Mira Grudzinska
f477933098 svg_loader: applying opacity to the gradient
Before this change the 'stroke-opacity' and the 'fill-opacity'
grad style attributes were not taken into account.
2021-06-28 10:34:14 +09:00
Hermet Park
a6f9ec3080 svg_loader: fix memory violation issues.
copy attribute must copy the url data,
otherwise, url memory can be atempted freeing twice.

also, fix the memory leak in multiple composition case.
2021-06-25 10:28:27 +09:00
Mira Grudzinska
286f700305 svg_loader: handling the ColorStop offset values
The ColorStop offset < 0 and > 1 should be treated as 0 and 1 respectively.
The offset value < than the previous offset value should be replaced
by the previous value - without this change segfault occurred.
Validating the APIs parameters values is the user responsibility.
2021-06-24 20:54:03 +09:00
Hermet Park
86fd0f67cf svg_loader: prevent heap memory overflow.
if the input points are odd-numberd by invalid svg data, it could access invalid memory.

Prevents it just in case.
2021-06-24 16:54:07 +09:00
JunsuChoi
5da4c81138 svg_loader SvgPath: Added corner case handling for flags of Arc
It handles the case what the flag of the arc of the path is defined
without spaces or commas, such as 00, 01, 11 or 10.
2021-06-24 08:52:30 +02:00
Hermet Park
80090e1189 tvg_loader: recover wrongly introduced change by my mistake. 2021-06-23 19:48:10 +09:00
Hermet Park
c2b84dc500 +++ 2021-06-23 18:59:26 +09:00
Hermet Park
135cba001f tvg_loader: code refactoring.
keep it neat & clean code for better readibility and maintenence.
2021-06-23 18:59:26 +09:00
Hermet Park
87b94b7a7f common: fix compatibility issue for MSVC
Math Constants are not defined in Standard C/C++

for this, we can use _USE_MATH_DEFINES before math headers.
2021-06-23 13:38:46 +09:00
Mira Grudzinska
5679d666a6 svg_loader: correct parsing ColorStop offset values
Values different from numbers and percentages should be ignored
and the default values should be applied (zeros).
2021-06-23 10:35:58 +09:00
JunsuChoi
f20ef0dc15 svg_loader SvgLoader: Copy the missing composite url
When copying an attribute, url information of stype's composite is overwritten with memcpy.
This causes double free by deleting the wrong string in freeNodeStyle.
2021-06-22 10:26:05 +02:00
Hermet Park
58f251163b tvg_loader: code refactoring.
remove if-def code.

Actually, tvg log is supposed to print some useful info for users,
not debugging info for our engine developers.
2021-06-22 17:07:56 +09:00
JunsuChoi
a2d348242b svg_loader SvgLoader: Prevent invalid access
If there is no path information, it is not copied.
2021-06-22 09:55:13 +02:00
JunsuChoi
b791924983 svg_loader XmlParser: Fix check the end of string
While skipping the string, check the end of the string first.
Prevents an invalid read when parser really get to the end of the string.
2021-06-22 13:47:26 +09:00
Hermet Park
0df8c00519 loaders: revise code from cce4b443b3
use copy variable instead of additional buffer pointer.
2021-06-22 10:42:34 +09:00
Michal Maciola
cce4b443b3 loaders: added copy param for Picture::load
@API Changed:
Result Picture::load(const char* data, uint32_t size, bool copy /*=false*/) noexcept
TVG_EXPORT Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data, uint32_t size, bool copy);
2021-06-21 19:52:38 +09:00
Mira Grudzinska
8bb10fb261 svg_loader: radial gradient transformation support
For now the gradient radius is scales like x-axis - it has to be changed
after issue #37 will be resolved.
2021-06-21 10:23:42 +09:00
Mira Grudzinska
2bf21dae3d svg_loader: key and value in the simpleXmlParseW3CAttribute needed to be cleared out of spaces 2021-06-17 11:17:39 +09:00
Mira Grudzinska
7ffeb2e606 svg_loader: fixing color parsing
For colors given in a style attribute in the format "rgb(rrr, ggg, bbb)"
a parsing was incorect. Now fixed.
2021-06-17 11:12:33 +09:00
Mira Grudzinska
20e926c950 svg_loader: after reading an unsupported style attribute no other values were loaded
After finding an unsupported style attribute the log is printed (on request)
and processing of other values continues.
2021-06-17 10:46:20 +09:00
Mira Grudzinska
e0a1aa9355 svg_loader: adding check if stroke-dasharray attribute != none
The stroke-dasharray value equal to "none" was causing a segfault
during a conversion to float. Fixed now.
2021-06-17 10:16:05 +09:00
Mira Grudzinska
a3e784b6b5 svg_loader: gradient update takes into account a stroke and a fill
For shapes with a grad fill and a grad stroke only the fill was drawn.
After this fix both can have a valid gradient.
2021-06-15 14:25:17 +09:00
Hermet Park
26fd6b5dfd tvg_loader: code refactoring.
renamed internal functions, no logical changes.
2021-06-14 14:32:05 +09:00
mmaciola
fa15b9a2af
tvg_loader: added tvg format verification
TVG format verification was added on TvgLoader:open()
2021-06-14 14:18:10 +09:00
Michal Maciola
8123250f52 tvg_loader: Fixed missing 'this->' keyword
Fixed missed 'this->' in tvgTvgLoader.cpp
2021-06-11 23:39:10 +09:00
Hermet Park
15b56a66de tvg_loader: code refactoring.
revise it under the tvg coding convention.
2021-06-11 20:51:50 +09:00
mmaciola
16e39ee81b
TVG Loader/Saver: tvg loader introduced
This patch introduces tvg loader module for loading .tvg binary files.
This allows to load and reuse pregenerated scene.

tvg file format:
.tvg is a binary file format designed for saving/restoring the scene content.
It allows to save scenes and reuse them in other apps or to restore state of
the application.

@Example:
   auto picture = tvg::Picture::gen();
   picture->load(EXAMPLE_DIR"/tvg_file.tvg");
   canvas->push(move(picture));

@API Additions:
   Result paint(std::unique_ptr<Paint> paint) noexcept;

@Issue: Issue ticket is #375.
2021-06-11 12:49:37 +09:00
Mira Grudzinska
9b1356e7cb svg_loader: support stroke gradient
The loader was ready to handle the gradient stroke, but there was no API to support
it when the loader was introduced. We've had this API for a while already, so
its call has been added.
2021-06-10 11:36:20 +09:00
JunsuChoi
3c19f2aaf5 svg_loader SceneBuilder: Remove incorrect calculation for radial gradient
We are doing enough calculations in the parser if the unit is user space.
This causes the cx,cy coordinates of radial gradient to be calculated incorrectly.
So remove it.
2021-06-07 19:12:17 +09:00
JunsuChoi
bd566bdcb2 svg_loader SceneBuilder: Remove incorrect calculation for linear gradient
Calculation of objectBoundingBox case in linear gradient is incorrect code.
This causes the x,y coordinates of the linear gradient to be calculated incorrectly.
So remove it.
2021-06-07 19:12:17 +09:00
Mira Grudzinska
ae5673658e svg_loader: initializing uninitialized variables
The 'loader->svgParse->global' variable was uninitialized when no viewBox attribute
was set. If gradient was applied, the division by zero occured and no gradient was drawn.
2021-06-07 12:30:56 +09:00
Mira Grudzinska
3911a252e2 svg_loader: the viewBox clipping composite layer added independently of the shapes bounds
For now the bounding box of all the shapes was established and if it was larger
than the viewBox of the SVG, the clipping layer was added. The bounds api
returns the rectangle that encloses the shapes before any transformations.
So comparing it with the viewBox doesn't make sense. The comparison is removed
and the clipping layer is always added.
2021-05-28 14:39:02 +09:00
Mira Grudzinska
f1d5571aad Revert "svg_loader: clipping composite layer is added independently on the bounds of the shapes"
This reverts commit c38e4e40a7.
It was pushed by mistake. The same changes are currently under rev in PR #399
2021-05-28 04:30:09 +02:00
Mira Grudzinska
c38e4e40a7 svg_loader: clipping composite layer is added independently on the bounds of the shapes 2021-05-27 12:54:08 +02:00
JunsuChoi
f8f90f3f34 log SvgLoader: Enhance log message
- Change tag name "Doc" to "Svg"
- Fix "Mask" tag name.
- Add element to skip output
 - title
- Add attribute to skip output
 - id, data-name, version, overflow=visible, xmlns*, xml:space
2021-05-13 23:46:17 +09:00