Commit graph

83 commits

Author SHA1 Message Date
Mira Grudzinska
4485db4f15 svg_loader: a function to establish shapes boundries without a stroke introduced
To handle the objectBoundingBox units, the shape's boundaries have to be known.
According to the SVG standard, a stroke shouldn't be taken into account. Since
the bounds() api uses the shape's stroke information, a new function is introduced,
that compensates this and returns boundaries without any strokes.
2021-11-26 11:47:15 +01:00
Mira Grudzinska
bd7c19a592 svg_loader: struct used to pass 1 args instead of 4 of them
The Box struct is introduced to replace the four functions
args: vx, vy, vw, vh, so all of them can be passed at once.
2021-11-26 11:47:15 +01:00
Hermet Park
0fcdba8a4b common math: code refactoring
introduced mathZero(), mathEqual() for floating variables.
2021-11-15 17:10:54 +09:00
Hermet Park
88d34f0d9a svg_loader: reduce binary size
removed the std::string usages.

saved 17kb.
2021-11-05 17:12:53 +09:00
Mira Grudzinska
b85eaddcf2 svg_loader: passing the svgPath information into the _applyComposition
An image can be a mask, so the information about it's path is necessary
during a composition application.
2021-11-05 13:10:52 +09:00
Mira Grudzinska
0501863195 svg_loader: mask node loaded as a scene
Since the mask is a container element (in opposite to the clipPath),
it has to be loaded as a scene.
2021-11-05 13:10:52 +09:00
Mira Grudzinska
16a153c804 svg_loader: fix bounds for gradient
In the case when bounds should not include a stroke width, width
and height values were reduced by half of a stroke width, instead
of the full width.
2021-11-01 20:36:48 +01:00
Michal Maciola
00dfd55f18 SVG: Support geometry properties of use tag
This patch adds a support for geometry properties (x, y) of <use> tag
2021-10-29 14:10:44 +09:00
Mira Grudzinska
4db3087c45 svg_loader: gradient transformation properly applied
The final gradient transformation depends on the coordinate system.
It can not be applied during an svg loading. The transformation matrix
has to be passed via api for further gradient processing.
2021-10-29 10:58:43 +09:00
Mira Grudzinska
ba25cb80eb svg_loader: shape's bounds without a stroke
A shape's bounds used for a gradient transformation shouldn't take
a stroke into account.
2021-10-28 12:18:17 +02:00
Mira Grudzinska
a93b5b98a9 svg loader: converting the image path to the absolute one
The href image tag should point to an absolute image path.
2021-10-23 02:26:55 +02:00
Hermet Park
9c8e785fdc updated license
Add missing original copyright texts in the source code.
2021-10-20 22:50:07 +09:00
Mira Grudzinska
1abee9f8d5 svg_loader: fixing viewBox clipping
For vw=width and vh=height, vx or vy > 0 had no effect. Fixed
2021-10-15 12:33:26 +09:00
Mira Grudzinska
0497ac894e svg_loader: removed unused variable
The gradient values passed to the scene builder are always given as percentages,
so there is no need to mark/check that.
2021-10-13 18:40:05 +09:00
Mira Grudzinska
c2bbdccac1 svg_loader: removed unnecessary casting
The used scaling factor should be a float - casting it to an int caused
misevaluation of the radial gradient radius
2021-10-11 18:59:23 +09:00
Mira Grudzinska
a16e91b441 all: fix compiler warnings
pow->powf and sqrt->sqrtf
2021-10-07 14:49:00 +09:00
Hermet Park
74954db56d common paint: refine the bounds() api to return the values after applying transformation.
Current paint::bounds() returns the coordinates under the raw status,
the values are not quite useful if the paint object has the transformed children.

Thus, we extends the feature and give an additional parameter "transformed"
to return the coordinates values after transformation by user demands.

This is also necessary for tvg format, since we need the exact view size of the scene information.

The previous api is deprecated and we introduce a new api to replace it.

@APIs:
+ Result Paint::bounds(float* x, float* y, float* w, float* h, bool transformed) const noexcept;
- Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept;

@Issues: https://github.com/Samsung/thorvg/issues/746
2021-09-24 11:25:49 +09:00
Michal Maciola
702f452c6c svg: fix url property
If 'fill="url(#image)"' and defs with id 'image' was not found, the paint was
improperly filled with color.
2021-09-21 20:20:59 +02:00
Mira Grudzinska
4589196689
common: preventing msvc compiler warnings (#817) 2021-09-20 13:54:06 +02:00
Mira Grudzinska
c9c3776207 svg_loader: proper svg resizing
Solves the problem of 'vx' and 'vy' < 0 and cases with 'width'
and 'height' values different than widht and height from the 'viewBox'
attribute.
2021-09-15 19:12:43 +09:00
Michal Maciola
e6ebb5379b common: RenderRegion x, y protect against negative value in unsigned int
This change protects against negative value in unsigned int of
RenderRegion.x/y. This fixes a problem of invisible paint if ClipPath
bounds was negative.

@issue: #704
2021-08-11 21:46:59 +09:00
Michal Maciola
cff8815404
loaders: Pass mimetype to picture::load
* loaders: Pass mimetype to picture::load

Added mimetype attribute to enfaster loading using a proper loader.

@Changed api: Picture::load(const char* data, uint32_t size, const std::string& mimeType, bool copy = false)
@issue: #571
2021-08-05 11:02:26 +09:00
Hermet Park
f7f241cff5 common picture: remove viewbox() api.
picture provides size() interface to return the image size,
viewbox() is conceptually not correct with the Picture.

Remove it under the beta api.
2021-07-28 13:07:43 +09:00
Hermet Park
e949883049 common log: use the log macro to replace the print method easier.
We can replace the system logger method by changing single line print source in common,
This also helps to remove the THORVG_LOG_ENABLED macro from each use-cases.

TVGLOG(): To print the hint & tip messages for users.
TVGERR(): To print the error message for debugging.

@Issues: https://github.com/Samsung/thorvg/issues/36
2021-07-23 21:17:01 +09:00
Michal Maciola
c2ec997db5
svg_loader: allow both clipPath and mask together (#622)
* svg_loader: allow both clipPath and mask together

* svg_loader: allow both clipPath and mask together fix #1

Changed seperate functions _applyClipPathComposition and _applyMaskComposition into single function _applyComposition
2021-07-21 12:12:09 +09:00
Michal Maciola
b89abde7cb
svg_loader: image tag: force size equal to the viewbox (#603)
* svg_loader: image tag: force size equal to the viewbox

For some svg files it is needed to force size equal the viewbox
for proper scaling

* svg_loader: image tag: force size equal to the viewbox fix #1
2021-07-15 17:48:35 -07:00
Michal Maciola
28342c5c1f svg_loader: <image> tag introduced fix #8
Disable embedded svg files to protect against recursive svg image loading
2021-07-09 12:04:29 +09:00
Michal Maciola
1f67c1d689 svg_loader: <image> tag introduced fix #6
Moved file:// removing into _imageBuildHelper
2021-07-09 12:04:29 +09:00
Michal Maciola
e01f29270a svg_loader: <image> tag introduced fix #4
fixed mistyped vw to w and vh to h
2021-07-09 12:04:29 +09:00
Michal Maciola
d69805c668 svg_loader: <image> tag introduced fix #3
Added working composition
2021-07-09 12:04:29 +09:00
Michal Maciola
c35f7e1f64 svg_loader: <image> tag introduced fix #2
Removed #ifdef from tvgSvgSceneBuilder.cpp
2021-07-09 12:04:29 +09:00
Michal Maciola
80fa97d366 svg_loader: <image> tag introduced
This patch introduces embeded <image> tag for svg files.
Images can be now loaded from local path or using data URI Scheme (RFC2397).
Base64 and utf8/uri are welcome.

@issue: #518
2021-07-09 12:04:29 +09:00
Hermet Park
3997aedcd5 svg_loader: optimize memory usage.
-- unnecessary memory fragmentation.
2021-07-09 11:58:44 +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
3e7888b538 svg_loader: code refactoring
use color structure to keep neat & compact code.
2021-06-30 14:54:12 +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
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
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
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
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
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
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
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