Commit graph

1019 commits

Author SHA1 Message Date
Mira Grudzinska
b414854c07 svg: fix nested use nodes
Previously, only single-level <use> references were supported.
If a <use> node pointed to another element that itself contained
a <use> node, the reference wasn’t resolved.
This has been fixed by replacing the array of postponed elements
with a list. The list is traversed, and nodes aren’t cloned while
they or any of their children remain unresolved. In such cases,
the target element also gets added to the list, enabling recursive
resolution of nested href references.

issue: https://github.com/thorvg/thorvg/issues/3615
2025-07-22 18:59:44 +02:00
Hermet Park
74e494ec49 lottie: adjusted the effect distance 2025-07-22 18:59:44 +02:00
Hermet Park
bf90903cd7 lottie: arrange the blur quality
there are several reports about poor quality,
arranged the value to the medium level.
2025-07-22 18:59:44 +02:00
Mira Grudzinska
2c9311d301 lottie: prevent mem leak
Masks of pooled shapes were not unrefed, filling up
the memory pool.
2025-07-22 18:59:44 +02:00
Mira Grudzinska
ec16c688db lottie: ensure proper shape closure
- Ensured proper closure of star and polygon shapes.
The start and end points now match - in cases with
degenerate bezier curves, the second-to-last point
is also aligned.
Proper shape closure is necessary for modifiers like
offset (future pucker bloat). If the start and end
points aren’t equal (within the comparison function’s
precision), the shape will be closed with a straight
line - and during offsetting, that line will become
visible, even though it’s not intended.

- Use of the internal _zero() function for point equality check
in modifiers algs led to incorrect results when p2.x or p2.y
was zero (division by zero).
The intent was to treat nearly identical points as equal, but
this approach was flawed - at the modifier stage, it’s no longer
possible to tell if small gaps are intentional or just due to
limited numerical precision (as seen for example in the difference
between the start and end points of star/polygon shapes).
2025-07-22 18:59:44 +02:00
Mira Grudzinska
2901d30cbd lottie: fix offset with miter join
One point was skipped during the creation of the offset
corner. The error was not visible because the point lies
on the line, but it will become apparent if further
modifiers are applied to the object (not supported now).
2025-07-22 18:59:44 +02:00
Hermet Park
fef0be9f72 sw_engine: revised the texture clipping
previous logic doesn't work if the clipping shape
has any inner corners. replace the logic
with a intermediate composition approach for
stability.

- performance can be drop at texture clipping by ~11%
- size is reduced by -0.5kb

issue: https://github.com/thorvg/thorvg/issues/3520
2025-07-22 18:59:44 +02:00
Hermet Park
081cb8cad3 lottie: do not try matting if the layer has no contents 2025-07-22 18:59:43 +02:00
Hermet Park
5262726b04 lottie: fixed a repeater opacity logic
preserve the target opacity by multiplying,
do not overwrite it.
2025-07-22 18:59:43 +02:00
Mira Grudzinska
a27839e80a lottie: fix precomposition with masking
A precomposition layer is clipped to its viewport.
If the same layer also had a mask that was optimized
using clipping, this clip was unintentionally overridden
by the viewport clipping. This conflict is now fixed.
2025-07-21 14:26:13 +02:00
JunsuChoi
fda24c3f59 svg_loader: Fix <stop> being registered in closed latestGradient
If stop is declared immediately after Gradient is closed, the stop is registered in latestGradient.
Change latestGradient to a Stack and add a stop only to the last added gradient.
When that gradient is closed, no more stops should be registered for that gradient.
And gradients do not allow nested declarations, so only the earliest declared Gradient is valid.
2025-05-24 01:37:24 +09:00
Hermet Park
d7db54ea5e lottie: removed undesired embedded option.
Use local font by default and fall back if no glyphs exist.

Co-Authored-By: Mira Grudzinska <mira@lottiefiles.com>
2025-05-24 01:37:24 +09:00
Jinny You
450b0fe92b lottie: handle time remapping with zero value correctly
The time remapping logic had an issue where animations with zero value "tm"(Time Remap) were not being processed correctly.

This was happening because the previous implementation only applied time remapping when the value was non-zero. (A zero-value Time Remap should be applied, but is ignored)

The fix changes the default time remap value to `-1.0` (since frame values cannot be negative) and applies time remapping when the value is 0.0 or greater. This ensures that zero value time remapping is properly processed.
2025-05-24 01:37:24 +09:00
Mira Grudzinska
751ad1c1ec lottie: fix points calculation for rounded polygon
Added missing factor.

issue: https://github.com/thorvg/thorvg/issues/2629
2025-05-24 01:37:24 +09:00
Mira Grudzinska
a6898ccf42 lottie: enhance parsing of position's SeparateCoords
The "s" key does not have to appear at the beginning
of the position block. Previously, such cases would
result in a parsing error — now they are handled correctly.
2025-05-24 01:37:24 +09:00
Hermet Park
a21ecdc1ae lottie/parser: revise logic to handle exceptional cases more gracefully
- prioritize valid (positive) cases first
- continue parsing even when encountering parsing errors

Co-Authored-By: Mira Grudzinska <mira@lottiefiles.com>
2025-05-24 01:37:24 +09:00
Mira Grudzinska
00f6600499 svg_loader: fix clipping in use/symbol nodes
Clipping for the <use> node when a <symbol> was used,
was being overridden when 'overflowVisible' was 'true'
(the default value), which caused the 'clip-path' applied
to the <use> node to have no visible effect.
The clipping for the <use> node (without <symbol> node) was
transformed in an incorrect order, resulting in a visually
incorrect results.

@Issue: https://github.com/thorvg/thorvg/issues/3392
2025-05-24 01:37:24 +09:00
Hermet Park
ea6cfdf3da lottie/expressions: --memory leak 2025-05-24 01:37:24 +09:00
Hermet Park
e1beceba80 lottie: fixed a invalid memory access
looping doesn't make sense if the animation
doesn't have frames. use the current frame number.
2025-05-24 01:37:24 +09:00
Hermet Park
8b2024a8f4 lottie/expressions: hotfix
issue: https://github.com/thorvg/thorvg/issues/3400
2025-05-24 01:37:24 +09:00
Mira Grudzinska
852424e69d ttf: prevent crash while converting utf8 to unicode
If wrong utf8 sequence if given as an input, decoding
return nullptr and it has to be handled correctly.
2025-05-24 01:37:24 +09:00
Mira Grudzinska
ee8eebfef8 lottie: safety++
Prevents a crash when the font family in the text document
does not match any font in the provided font list.
2025-05-24 01:37:24 +09:00
Hermet Park
55c0849746 loaders: explicit variable scope to improve portability
issue: https://github.com/godotengine/godot/pull/105093
2025-05-24 01:37:24 +09:00
Hermet Park
126265feb9 lottie/expressions: tiny optimization
reuse the user callback data by the reference count.
2025-05-24 01:37:21 +09:00
Jinny You
08fa801461 lottie/text: added range selector flags
Duplicated text document properties (fill color, stroke color, and stroke width) to the text range.

If these properties are not defined in the range selector, ThorVG incorrectly overrides them with default values.

The correct behavior is to preserve the original values. The added flags address this issue.

Co-Authored-By: Hermet Park<hermet@lottiefiles.com>
2025-05-22 16:58:24 +02:00
Hermet Park
dd416e326d loaders: ++static loader thread safty
make it sync before deleting the loaders.
2025-04-03 22:31:07 +02:00
Hermet Park
96d4ab1590 lottie/expressions: support wiggle effect
usage: wiggle(freq, amp, octaves=1, amp_mult=.5, t=time)

issue: https://github.com/thorvg/thorvg/issues/1640
2025-04-03 22:28:04 +02:00
Hermet Park
558a9991de lottie: improve the compatiblity
merge the scene with more accurate condition to allow
the evenodd pathes among the lottie render tree.
2025-04-03 22:17:03 +02:00
Hermet Park
4e5ff3ea9a lottie: safety++
Don't apply matte — it's already been pushed into the scene.
This is a corner-case bug that occurs when the Lottie data
violates the specification.
2025-04-03 22:10:21 +02:00
Hermet Park
7d8bb168d2 ttf: ++thread safety
Properly allow the ttf loader sharable among threads.

issue: https://github.com/thorvg/thorvg/issues/3165
2025-04-03 21:31:52 +02:00
Hermet Park
6708fae17b common: ++loader thread safety
fortitfy the thread safety
in multi-threaded resource loading.

issue: https://github.com/thorvg/thorvg/issues/3306
2025-04-03 21:09:21 +02:00
Mira Grudzinska
7730b1d632 svg_loader: handle embedded fonts
It is possible to embed fonts directly into an SVG file.
Support for parsing and loading embedded fonts has been added.

@Issue: https://github.com/thorvg/thorvg/issues/1897
2025-04-03 18:56:45 +02:00
Jinny You
097d3814ea lottie/slot: fix image deep copy logic
When the datas are copied with deep copy, memory issue caused (SEGV on unknown address) due to these reasons:

1. `mimeType` is nullptr when it's not embedded(base64) data

2. datas(b64Data, mimeType) should not be clear, it's used for next slot copy in same pair.
2025-04-03 14:28:02 +02:00
Mira Grudzinska
731f137d2d svg: fix incorrect assignment of <stop> elements
If the svg contained an unsupported element with <stop> elements,
they were incorrectly assigned to the last loaded gradient. Now fixed.

@Issue: https://github.com/thorvg/thorvg/issues/3321
2025-03-12 21:02:51 +01:00
Hermet Park
fe383d44e7 lottie: --compiler warnings
In member function ‘constexpr LottieGenericProperty<LottieScalarFrame<float>, float>& LottieGenericProperty<LottieScalarFrame<float>, float>::ope>    inlined from ‘LottieFloat& LottieStroke::dashValue()’ at ../src/loaders/lottie/tvgLottieModel.h:60:104,
    inlined from ‘void LottieParser::parseStrokeDash(LottieStroke*)’ at ../src/loaders/lottie/tvgLottieParser.cpp:623:82:
../src/loaders/lottie/tvgLottieProperty.h:297:8: warning: ‘<anonymous>.LottieGenericProperty<LottieScalarFrame<float>, float>::value’ may be used>  297 | struct LottieGenericProperty : LottieProperty
      |        ^~~~~~~~~~~~~~~~~~~~~
../src/loaders/lottie/tvgLottieModel.h: In member function ‘void LottieParser::parseStrokeDash(LottieStroke*)’:
../src/loaders/lottie/tvgLottieModel.h:60:104: note: ‘<anonymous>’ declared here
   60 |             for (uint8_t i = 0; i < dashattr->size; ++i) newValues[i] = LottieFloat(dashattr->values[i]);
      |
2025-03-12 21:02:44 +01:00
Jinny You
7c27ae021d lottie/slot: Support expressions overriding
issue: #3168

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2025-03-12 20:26:39 +01:00
Jinny You
dec4b141ec lottie/slot: fix potential memory leak when overriding twice
Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2025-03-12 20:26:39 +01:00
Mira Grudzinska
572e5ef9b1 ttf_loader: handling contours starting with OFF_CURVE
It might happen that the first point doesn't belong
to the contour - such cases were observed as artifacts
till now.

@Issue: https://github.com/thorvg/thorvg/issues/3268
2025-03-12 20:26:38 +01:00
Jinny You
52dc586089 lottie/expressions: Fix incorrect evaluation result check condition
A JavaScript code line may return undefined, but this should not be treated as an error.

For example, consider the following two lines of code:
- `var $bm_rt = 30` (Statement) → result: `undefined`
- `$bm_rt = 30` (Expression) → result: `30`

Both lines execute the same operation, but the JavaScript interpreter (REPL JS) evaluates them differently.

Therefore, an evaluation result of undefined should not be blocked, as it does not indicate a failed code execution.
2025-03-12 20:26:38 +01:00
Mira Grudzinska
589e93fa74 lottie: parsing embedded fonts data (#3220)
Only parsing and font loading is added with
a very basic text update while building the scene.

@Issue: https://github.com/thorvg/thorvg/issues/3184
2025-03-12 02:10:32 +01:00
Hermet Park
7a1df343cc lottie: properly copy missing property values 2025-03-12 02:10:32 +01:00
Mira Grudzinska
1354613d59 lottie: ++ dashed stroke support
Until now lottie loader supported only a single
dash-gap pair, and only the case where only the dash
was provided was handled correctly. When both values
were provided, the gap was incorrectly increased by
the dash value. If more values were supplied, only
the last pair was considered.

@Issue: https://github.com/thorvg/thorvg/issues/3191
2025-03-12 02:10:32 +01:00
Hermet Park
09ebf10432 lottie: revise the effect parsing logic
Unify the common parts of the parsing logic
by applying a strategy pattern,
allowing the behavior to vary based on the effect type.

This helps to reduce the size and improved the parsing safety.
2025-01-30 20:36:02 +09:00
Hermet Park
6c0c8865cd lottie/expressions: ++safety
Prevent segfault in case of the omitted name json data
2025-01-30 20:21:09 +09:00
Mira Grudzinska
12b9c5fc53 lottie: fix text stroke's 'of' property
The text stroke's 'of' property determines whether
the stroke appears above (true) or below (false)
the fill.
Previously, it was incorrectly used to decide whether
the stroke would render.

@Issue: https://github.com/thorvg/thorvg/issues/3126
2025-01-16 18:49:49 +01:00
faxe1008
6489e65064 common: Use explicit floating-point value types.
Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2025-01-16 18:34:12 +01:00
faxe1008
14ea212535 drenderer: include alloca.h for Zephyr
Changes the conditional for to also include the alloca.h header in case
it is build for the zephyr rtos.
2025-01-16 18:30:36 +01:00
Hermet Park
d7ad915647 webp: --compiler warning
warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]
2025-01-16 18:30:19 +01:00
Jinny You
1ae817b634 lottie/slot: Support transform slot overriding
issue: https://github.com/thorvg/thorvg/issues/2591
2025-01-16 16:11:55 +01:00
Mira Grudzinska
e293d73f11 svg_loader: fix transformation order
If a clip was defined by a use node pointing
to a basic shape subject to transformation, and
the use node itself was translated, the order
of applying these transformations was incorrect.
2025-01-02 15:10:04 +01:00