Commit graph

921 commits

Author SHA1 Message Date
Hermet Park
1fced1905d lottie/expressions: minor size down expressions engine.
- disable unused builtin realm functions.
- disable global this
- disable regexp (potential)
- disable unicode case conversion (potential)

Some features are marked with (potential)
since we are not certain these are used practically.

until now, total binary size diff by expressions: +287kb
2024-06-24 12:33:19 +09:00
Hermet Park
7f1fbdcaa4 lottie/expressions: ++exceptional handling
Stop handling if the interpreting result is invalid.
2024-06-24 12:33:04 +09:00
Hermet Park
9cff11f25e lottie/expressions: apply expressions to missing properites. 2024-06-24 12:32:57 +09:00
Hermet Park
027e0fd6f0 lottie/expressions: enhance stability
When the system fails to interpret the expression code,
it forcibly disables the feature per property.

This improvement enhances stability and performance
by avoiding reckless attempts to interpret JavaScript code.

When we confirm the full stability with expressions,
we can revert this code.
2024-06-24 12:32:14 +09:00
Hermet Park
fca4ef3109 lottie/expressions: ++exceptional handling.
Add an exceptional handling if interpreting code is failed.
2024-06-24 12:32:06 +09:00
Hermet Park
ac477d6896 lottie/expressions: make it up the insufficient content() behavior
this is a follow-up fix for the initial expressions feature.
2024-06-24 12:31:58 +09:00
Hermet Park
10c07476c6 lottie: fix a logic by a mistake. 2024-06-24 12:31:48 +09:00
Hermet Park
d80b9969de lottie/jerryscript - size down the engine.
get rid of unused features in thorvg lottie.
2024-06-24 12:29:29 +09:00
Hermet Park
709ef9158f lottie: support the expression feature
The current development of the expression engine is experimental.
It does not support multi-threading.

Therefore, when tvg::Initializer::init() is configured
with more than one thread, expressions will be automatically disabled.

issue: https://github.com/thorvg/thorvg/issues/1640
2024-06-24 12:29:17 +09:00
Hermet Park
a685ed5ce5 lottie/model: Added some essential functions through expressions.
These internal methods have been introduced to search for content within
an object (parent) using a given parameter (name or index).

- LottieLayer* LottieGroup::asset(const char* name)
- LottieLayer* LottieComposition::asset(const char* name)
- LottieLayer* LottieComposition::layer(uint16_t id)
- LottieLayer* LottieComposition::layer(const char* name)

This converts the frame number to the corresponding time.
- float LottieComposition::timeAtFrame(float frameNo)
2024-06-24 12:28:09 +09:00
Hermet Park
09a45b007e lottie: ++binary search stability.
this ensures that the return value is not below 0,
when the frame count is just 2.
2024-06-24 12:28:01 +09:00
Hermet Park
060f858568 lottie: specify the explicit parsing type.
these explicit type values are expected
to be referenced by the expressions.
2024-06-24 12:27:52 +09:00
Hermet Park
acd42f3bfa lottie: generalize parent context access in parsing.
ensure parent context is generally accessible,
not limited to gradients.
2024-06-24 12:27:45 +09:00
Hermet Park
625a5ca747 lottie: integrate JerryScript engine for expressions
introduced the JerryScript engine to interpret Lottie
expressions, enhancing the capability to support runtime
programmable animation logic within Lottie expressions
spec. This feature, based on js scripting, represents
the most complicated addition to the Lottie spec so far.

ThorVG probably could includes an option to toggle
this feature at build time, allowing for customizable user
configurations according to specific requirements.

removed unused features for the optimal size:
- DEBUGGER
- MEM_STATS
- SNAPSHOT
- BUILTIN_JSON
- BUILTIN_PROXY
- BUILTIN_REFLECT
- BUILTIN_ATOMICS
- PROMISE_CALLBACK
- MODULE_SYSTEM
- SYSTEM_PORT

This is an experimental version.
Please manually enable the 'lottie-expressions' in meson.build
when you wish to use it.

See: https://jerryscript.net/
2024-06-24 12:27:26 +09:00
Jinny You
7ecd90810d lottie: correct the text alignment
When the Lottie Text Justify sets to center, text alignment should also be center.
2024-06-24 12:24:04 +09:00
JunsuChoi
dca857d129 loader/svg: Check current graphics node that not closed
If any of the graphics nodes are not closed,
the graphics nodes between them are ignored.

related issue: https://github.com/thorvg/thorvg/issues/2210
2024-06-24 12:23:57 +09:00
JunsuChoi
6f6f311bb7 loader/svg: If link string is empty, not create picture object
An empty link causes the wrong loader to be found and causes various problems.

related issue : https://github.com/thorvg/thorvg/issues/2078#issuecomment-2067726046
2024-06-24 12:23:51 +09:00
Mira Grudzinska
4a8148f147 svg_loader: fix opacity cloning
The opacity value should be copied along
with other node properties.
2024-06-24 12:23:29 +09:00
Mira Grudzinska
81228855f9 svg_loader: copy display property
The display property was not copied along with other
node properties. This caused incorrect rendering
of an object with display=none if accessed through
a use tag.
2024-06-24 12:21:50 +09:00
Mira Grudzinska
4316dd2620 svg_loader: correct polygon's points loading
Only an even number of correctly read points defining
a polygon should be loaded and passed on for rendering.
Any remaining points should be ignored.
2024-06-24 12:21:44 +09:00
Mira Grudzinska
c5266725d4 Revert "loader/svg: Skip to invalid polygon"
This reverts commit 75e587a9a9.
If incorrect data for the points in a polygon is provided,
the element should still be rendered, but only up to the point
where the error occurs—using an even number of the points that
have been successfully loaded.
2024-06-24 12:21:38 +09:00
Mira Grudzinska
cc92865634 build: enforcing saver/loader usage for given tool
Selecting a tool without choosing the required tools
resulted in a usage error. Now, the activation
of the appropriate saver/loader for a given tool
is enforced.
2024-06-24 12:21:10 +09:00
Hermet Park
39e9d6b583 lottie: code clean up 2024-06-24 12:18:16 +09:00
Jinny You
557de3eb40 lottie/loader: Fix crash when parsing error
When parsing error, lottie loader raises runtime crash.
Check whether the composition is nullptr.
2024-06-24 12:17:59 +09:00
JunsuChoi
c69049ad78 loader/svg: Return actual decoded size
Returns the actual length of the decoded array.

related issue: https://github.com/thorvg/thorvg/issues/2156
2024-06-24 12:17:51 +09:00
Hermet Park
0c12e662e4 lottie: ++stability
ensure that the loading has been completed before overriding.
2024-06-24 12:12:56 +09:00
JunsuChoi
db1107c41b loader/svg: Add null to the end of data
Because memcpy() is not guaranteed to copy null at the end of the data array,
it increase the size by 1 and add null
This prevents invalid access of string functions in parser.
2024-06-24 12:12:40 +09:00
Hermet Park
c7d51ad0bb lottie: code refactoring.
make it neat and clean.
2024-06-24 12:12:26 +09:00
Hermet Park
bfed28e86e common: code refactoring
introduced mathDeg2Rad() and mathRad2Deg() for a common implementation.
2024-06-24 12:12:19 +09:00
Hermet Park
026d85f6a8 lottie: code refactoring.
keep the coding style.
2024-06-24 12:05:59 +09:00
Lucas Niu
194bd8f01d lottie: Support the Animation Segment(Marker)
A single animation might have a desinated markers with naming: 0 ~ 0.5 (sector A), 0.5 ~ 1.0  (sector B). Selecting one of them using a marker name(sector A) and could play only that part with animation controllers.

usage:
- `animation->segment("sectionA") // Named segment(Marker)`
- `auto cnt = animation->markerCnt()`
- `auto name = animation->markers(index)`
- `animation->segment(0, 0.5) // Segment`
- `animation->segment(&begin, &end)`

Co-authored-by: Jinny You <jinny@lottiefiles.com>
2024-06-24 12:00:25 +09:00
JunsuChoi
6a03c4c2c1 loader/svg: Ignore unrecognized commands following 'z'
If the command after `m` is not recognized, it must be recognized as `l` or `L`.
However, if it is not recognized after ending with `z`, all commands after it are ignored.

```
<svg width="100" version="1.0" xmlns="http://www.w3.org/2000/svg" height="100" xmlns:xlink="http://www.w3.org/1999/xlink">

<path style="stroke:#F00" d="m 20,20 0,50 50 0 -50 -50 z  70,70 0,50 50 0 -50 -50 z  "/>

</svg>
```
2024-06-24 11:59:55 +09:00
JunsuChoi
43b5d0e462 loader/svg: Skip to invalid polygon
If a Polygon's points array is odd, it is not a valid shape.
2024-06-24 11:59:32 +09:00
Hermet Park
f108fc9363 lottie: corrected the comp/layer size data type.
Actually, the these size is expected to be a floating-point value.
This correction addresses a parsing error.

issue: https://github.com/thorvg/thorvg/issues/2153
2024-06-24 11:59:16 +09:00
Hermet Park
ca7aec5fff lottie: rectify the frame updates.
Currently, tvg ignores the frame value if the difference
is less than 0.001. In most cases, updating the frames
when the change is less than 1ms is just an unnecessary
burden on the system.

Instead, this ensures that the perfect last frame is reached.

issue: https://github.com/thorvg/thorvg/issues/2147
2024-06-24 11:58:48 +09:00
Hermet Park
37b431c02f svg: code refactoring
-- compiler warnings on msvc
2024-04-07 15:15:59 +09:00
JunsuChoi
b3b2bc6bd5 loader/svg: Fix invalid syntax check
If the key is not parsed and the '=' keyword is located next,
modify it to parse the following syntax.

related issue:
https://github.com/thorvg/thorvg/issues/2116
2024-04-06 12:48:30 +09:00
Hermet Park
1632ad9ee5 lottie: removed unused code.
Currently, thorvg has no plan to support dotlottie format.
2024-04-06 12:48:30 +09:00
Hermet Park
ef03e5b006 lottie: hotfix memory corruption.
revise the fix that occured a side effect by:
287e6d33d2
2024-04-06 12:48:30 +09:00
Jinny You
f54f22ae78 lottie: Fix heap-buffer-overflow in gradient populate 2024-04-06 12:48:30 +09:00
JunsuChoi
349fd266b9 loader/svg: Check invalid color
Checks whether the string that can be specified in Color is valid.

example)
```
     style="stroke:asdasd"
```

related issue: https://github.com/thorvg/thorvg/issues/1255
2024-04-06 12:48:30 +09:00
Hermet Park
ecee01ebd6 lottie: Properly handle the TrimPath mode.
This correction addresses the drawing order of
objects when a group contains a TrimPath and
is merging shapes.

Additionally, the TrimPath method is can applied
to the engine to control the drawing behavior by
7f3dc541d6b7abcdc03facd884489f37c327fd98

issue: https://github.com/thorvg/thorvg/issues/2047
2024-04-06 12:48:30 +09:00
Hermet Park
6688f03396 sw_engine: revised the trimpath dash line logic
Support the TrimPath modes (individual/simultaneous)
internally in the engine to handle them efficiently.
2024-04-06 12:48:30 +09:00
JunsuChoi
0c6395cbea loader/svg: Support hsl color format
Support parsing of hsl(hue, saturation, brightness) color type
and conversion to rgb color.
2024-04-06 12:48:30 +09:00
Hermet Park
f7bfc57f23 portability: removed a compiler waring
D:\Projects\thorvg\src\loaders\lottie\tvgLottieParserHandler.h(52): warning C4083: expected ')'; found identifier 'effc'
[44/46] Compiling C++ object src/thorvg-0.dll.p/loaders_lottie_tvgLottieParserHandler.cpp.obj
D:\Projects\thorvg\src\loaders\lottie\tvgLottieParserHandler.h(52): warning C4083: expected ')'; found identifier 'effc'
[45/46] Compiling C++ object src/thorvg-0.dll.p/loaders_lottie_tvgLottieParser.cpp.obj
D:\Projects\thorvg\src\loaders\lottie\tvgLottieParserHandler.h(52): warning C4083: expected ')'; found identifier 'effc'

I'm not sure this option is really necessary.
2024-04-06 12:08:23 +09:00
Hermet Park
d883cc23cf lottie: polish up a comment. 2024-04-06 12:08:23 +09:00
Hermet Park
1f04df60dd lottie: Removed redundant code.
The settings were incorrect;
'direction' and 'fillRule' do not have a relationship.
2024-04-06 12:08:23 +09:00
Hermet Park
f6170a224a lottie: optimize the rendering performance.
this optimization nicely merges shapes
when a child group has a only (transformed) pathes.

this also fixes the following compatibility issue nicely.

issue: https://github.com/thorvg/thorvg/issues/2061
2024-04-06 12:08:23 +09:00
Hermet Park
40647d5882 lottie: optimize the rendering by preventing partial rendering branches.
this optimization is to figure out if this group is a simple path drawing.
In that case, the rendering context can be sharable with the parent's.
2024-04-06 12:08:23 +09:00
JunsuChoi
f0527a2304 loader/svg: Check whether href id of use is parent or not
When finding the 'nodeFrom' referenced by `<use>`,
if it is the parent, it is not referenced.

https://www.w3.org/TR/SVG2/struct.html#UseElement
Specification:
If the referenced element is a (shadow-including) ancestor
of the ‘use’ element, then this is an invalid circular reference
and the ‘use’ element is in error.

related issue: https://github.com/thorvg/thorvg/issues/2078
SVG_FILE_65171.svg
SVG_FILE_65172.svg
2024-04-06 12:08:23 +09:00