Commit graph

293 commits

Author SHA1 Message Date
Hermet Park
b77f3ca024 common: introduced designated memory allocators
Support the bindings to be more integrable with a system's coherent memory management.

Pleaes note that thorvg now only allow the desinated memory allocators here:
malloc -> tvg::malloc
calloc -> tvg::calloc
realloc -> tvg::realloc
free -> tvg::free

issue: https://github.com/thorvg/thorvg/issues/2652
2025-02-18 17:20:31 +09:00
Hermet Park
0dd0a3b45c common: neat code++
introduced common BBox structure
2025-02-06 15:40:32 +09:00
Mira Grudzinska
56799beefd
svg_loader: loc-- (#3149)
* svg_loader: loc--

Removed unnecessary initialization of variables
to 0.0/false/nullptr in memory allocated by calloc.
2025-01-22 13:25:24 +01:00
Hermet Park
7f6af7ebe6 svg: ++readability
!strcmp() -> STR_AS()
2025-01-21 12:41:31 +09:00
Mira Grudzinska
fbdc958623 svg: added filter and gaussian blur nodes support
@Issue: https://github.com/thorvg/thorvg/issues/1367
2025-01-20 17:24:06 +01:00
Hermet Park
07e73a9e6f common: code refactoring
use ARRAY_FOREACH() for neat code and
accessing the memory efficiently than normal indexing.
2025-01-15 18:03:46 +09:00
Hermet Park
1c3b958d5b svg: ++loc reduction 2025-01-14 21:04:45 +09:00
faxe1008
0c09580cd4 common: Use explicit floating-point value types.
Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2025-01-10 12:16:13 +09:00
Hermet Park
a12accbc93 updated copyright 2025-01-03 14:32:31 +09:00
Hermet Park
0e9bc74603 api: renamed FillRule::Winding to NonZero
aligned the name with the web standard.
2024-12-27 21:16:27 +09:00
Hermet Park
1422c4ca5f renderer: make the file io configurable
certain systems, may not support file I/O operations.
ThorVG should provide users with an option to configure
builds according to their requirements.

This ensures that file I/O calls are avoided,
preventing potential crashes.

Please use the meson '-Dfile=true/false' option for this.

Please note that "THORVG_FILE_IO_SUPPORT" might be expected
for your thorvg manual build.

issue: https://github.com/thorvg/thorvg/issues/3008
2024-12-02 11:50:59 +09:00
Mira Grudzinska
511495f6d8 svg_loader: handle currentColor inside gradient
@Issue: https://github.com/thorvg/thorvg/issues/2960
2024-11-20 01:46:19 +09:00
Hermet Park
ed01ef717e api: revise the spec
Remove the requirement for unique_ptr in the function prototypes.
This change will simplify the API usage, making it more streamlined
and user-friendly. However, memory management will now be the
responsibility of the user.

C++ API Modification:
- Result Paint::mask(std::unique_ptr<Paint> target, MaskMethod method) -> Result Paint::mask(Paint* target, MaskMethod method)
- Result Paint::clip(std::unique_ptr<Paint> clipper) -> Result Paint::clip(Paint* clipper)
- virtual Result Canvas::push(std::unique_ptr<Paint> paint) -> virtual Result Canvas::push(Paint* paint)
- std::unique_ptr<LinearGradient> LinearGradient::gen() -> LinearGradient* LinearGradient::gen()
- std::unique_ptr<RadialGradient> RadialGradient::gen() -> RadialGradient* RadialGradient::gen()
- Result Shape::strokeFill(std::unique_ptr<Fill> f) -> Result Shape::strokeFill(Fill* f)
- Result Shape::fill(std::unique_ptr<Fill> f) -> Result Shape::fill(Fill* f)
- std::unique_ptr<Shape> Shape::gen() -> Shape* Shape::gen()
- std::unique_ptr<Picture> Picture::gen() -> Result Picture::push(Paint* paint)
- std::unique_ptr<Scene> Scene::gen() -> Scene* Scene::gen()
- Result Text::fill(std::unique_ptr<Fill> f) -> Result Text::fill(Fill* f)
- std::unique_ptr<Text> Text::gen() -> Text* Text::gen()
- std::unique_ptr<SwCanvas> SwCanvas::gen() -> SwCanvas* SwCanvas::gen()
- std::unique_ptr<GlCanvas> GlCanvas::gen() -> GlCanvas* GlCanvas::gen()
- std::unique_ptr<Animation> Animation::gen() -> Animation* Animation::gen()
- Result Saver::background(std::unique_ptr<Paint> paint) -> Result Saver::background(Paint* paint)
- Result Saver::save(std::unique_ptr<Paint> paint, const char* filename, uint32_t quality = 100) -> Result Saver::save(Paint* paint, const char* filename, uint32_t quality = 100)
- std::unique_ptr<Saver> Saver::gen() -> Saver* Saver::gen()
- std::unique_ptr<Accessor> Accessor::gen() -> Accessor* Accessor::gen()

C++ API removal:
- template<typename T = tvg::Paint> std::unique_ptr<T> cast(Paint* paint)
- template<typename T = tvg::Paint> std::unique_ptr<T> cast(Paint* paint)

issue: https://github.com/thorvg/thorvg/issues
2024-11-09 12:29:15 +09:00
Hermet Park
4aaa0dafc4 common: code refactoring
replaced internal string usage with char*
2024-11-08 15:26:04 +09:00
Hermet Park
798968e83a svg: clean up code 2024-10-24 00:37:49 +09:00
Mira Grudzinska
ec25ce9362 svg_loader: fix circle radius if in percentages 2024-09-24 14:33:15 +09:00
JunsuChoi
853d701d27 svg_loader: Fix calculation when stroke-width unit is percentage
When stroke-width unit is percentage, loader refer to the normalized diagonal of viewport.
+) Add Diagonal type so as not to affect existing types.

https://svgwg.org/svg2-draft/painting.html#StrokeWidth
https://svgwg.org/svg2-draft/coords.html#Units

example)
```
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
   <rect x="15" y="15" width="70" height="20" fill="none" stroke="#F00" stroke-width="10%"/>
   <rect x="15" y="15" width="70" height="20" fill="none" stroke="#00F" stroke-opacity=".3" stroke-width="10"/>
</svg>

```

related issue: https://github.com/thorvg/thorvg/issues/2131
2024-09-20 21:29:36 +09:00
Mira Grudzinska
bf9f5ab1c5 svg_loader: append text to the SvgTextNode
Text can be added in parts due to the presence
of the <tspan> tag. This requires that each
subsequent piece of text is appended rather than
overwriting the previous one.
2024-09-10 19:02:24 +09:00
Mira Grudzinska
ce61a33756 svg_loader: fix text nodes issue
Since the text node wasn't pushed onto the loader's stack,
closing the text node incorrectly caused an element to be
popped from the stack (if one was present).
This could result in elements that were supposed to have
that element as a parent being rendered incorrectly or not
being rendered at all.
Now, the text node is correctly pushed onto the stack.

@Issue: https://github.com/thorvg/thorvg/issues/2706
2024-09-05 23:47:30 +09:00
JunsuChoi
dd223b4065 svg_loader: Adjust hsl values out of range
The range of saturation and brightness values is 0 ~ 100% and range of hue is 0 ~ 360.
If a value greater than 100% is loaded, it will be modified to be 100%.

issue: https://github.com/thorvg/thorvg/issues/2678
2024-08-29 12:05:47 +02:00
Hermet Park
c7ae3ae2af svg: resolve compiler warnings.
../src/loaders/svg/tvgSvgLoader.cpp: In function ‘bool _toColor(const char*, uint8_t*, uint8_t*, uint8_t*, char**)’:
../src/loaders/svg/tvgSvgLoader.cpp:108:17: warning: ‘hue’ may be used uninitialized [-Wmaybe-uninitialized]
  108 |     const char* _end = end ? *end : nullptr;
      |                 ^~~~
../src/loaders/svg/tvgSvgLoader.cpp:713:31: note: ‘hue’ was declared here
  713 |         const char *content, *hue, *saturation, *brightness;
      |                               ^~~
../src/loaders/svg/tvgSvgLoader.cpp:108:17: warning: ‘saturation’ may be used uninitialized [-Wmaybe-uninitialized]
  108 |     const char* _end = end ? *end : nullptr;
      |                 ^~~~
../src/loaders/svg/tvgSvgLoader.cpp:713:37: note: ‘saturation’ was declared here
  713 |         const char *content, *hue, *saturation, *brightness;
      |                                     ^~~~~~~~~~
../src/loaders/svg/tvgSvgLoader.cpp:108:17: warning: ‘brightness’ may be used uninitialized [-Wmaybe-uninitialized]
  108 |     const char* _end = end ? *end : nullptr;
      |                 ^~~~
../src/loaders/svg/tvgSvgLoader.cpp:713:50: note: ‘brightness’ was declared here
  713 |         const char *content, *hue, *saturation, *brightness;
      |                                                  ^~~~~~~~~~
2024-07-23 17:09:26 +09:00
Hermet Park
5a2a6fc4a9 common: replace the round() with nearbyint()
nearbyint() is 2x faster than round() in our local test.
2024-07-10 23:43:10 +09:00
Hermet Park
44955b704e common/math: code refactoring
Replaced the prefix "math" with "tvg" namespace.
2024-07-10 00:21:02 +09:00
JunsuChoi
6b6eac8f93 svg_loader: Fix incorrect stack.pop() call in loader
loader->stack.pop() at line 3271 is called to remove
the defs node added to the stack due to nested graphics elements.
However, it is called in an inappropriate situation and the loader's node tree is damaged.
Fixes an error where the close tag is recognized as a `line` of the graphics tag when it is `linearGradient`.
ex)
```
    <defs id="def">
        <linearGradient x1="1" y1="2" x2="3" y2="4" id="l"/>
        </linearGradient>
        <rect x="10" y="10" width="10" height="10"  fill="blue" id="r2"/>
    </defs>
```

related issue: https://github.com/thorvg/thorvg/issues/2518
2024-07-06 11:43:21 +09:00
Josh Soref
e061fa6628
common: fix 178+ spelling errors 2024-07-01 21:58:46 +09:00
Mira Grudzinska
8afb7f7ca8 svg_loader: handle text node
The text node is handled, but default values
of the font-family and font-size as used in
the user's system are not.
For now font has to be loaded by the user.

@Issue: https://github.com/thorvg/thorvg/issues/2350
2024-06-10 13:27:14 +02:00
Hermet Park
a1818cf62b common: code refactoring
Replace the math functions with operator overloading.
This should potentially reduce the code size.
2024-05-27 10:48:46 +09:00
Hermet Park
975907731d math: introduced a custom floating epsilon
Rather than aiming for extremely high accuracy,
a compromise can achieve with better performance.

This modification helps prevent unnecessary image rotation.

issue: https://github.com/thorvg/thorvg/issues/2265
2024-05-24 10:45:24 +09:00
Mira Grudzinska
ed14966144 svg_loader: move the display property to the style
The display property, like any other node's style property,
should be part of a node style. This ensures its correct
copying and inheritance.
For the 'symbol' node, which is not rendered unless it is
used within a 'use' node, the display property can also be
applied. Because of that it cannot be utilized during scene
construction to determine whether the symbol is being defined
or used within a 'use' context.
2024-05-09 10:36:54 +09:00
Mira Grudzinska
8c04b9d65e svg_loader: improved clarity, no logical changes
Unnecessary structure removed, typos corrected,
comment added, an unused function argument removed.
2024-05-07 11:57:29 +02:00
JunsuChoi
0d20eb71eb 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-04-25 16:23:07 +09:00
Mira Grudzinska
d55b8afd6a svg_loader: fix opacity cloning
The opacity value should be copied along
with other node properties.
2024-04-25 10:41:15 +09:00
Mira Grudzinska
08fe14280d 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-04-23 11:20:37 +09:00
Mira Grudzinska
8d81ad360f 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-04-22 11:12:15 +09:00
Mira Grudzinska
2cb89c71a1 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-04-22 11:12:15 +09:00
JunsuChoi
66c43352ef 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-04-16 10:27:20 +09:00
Hermet Park
be7437e0a3 common: code refactoring
introduced mathDeg2Rad() and mathRad2Deg() for a common implementation.
2024-04-15 20:35:33 +09:00
JunsuChoi
75e587a9a9 loader/svg: Skip to invalid polygon
If a Polygon's points array is odd, it is not a valid shape.
2024-04-11 10:55:20 +09:00
Hermet Park
1c4b254015 svg: code refactoring
-- compiler warnings on msvc
2024-04-08 17:25:05 +09:00
JunsuChoi
79c65aa5e7 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-03 11:38:49 +09:00
JunsuChoi
dea08681c0 loader/svg: Support hsl color format
Support parsing of hsl(hue, saturation, brightness) color type
and conversion to rgb color.
2024-04-02 22:59:13 +09:00
JunsuChoi
fdebb15dcb 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-03-28 22:53:57 +09:00
JunsuChoi
46448a1520 loader/svg: Do recalc after gradient inheritance
Inherit gradientUnits and recalculate each element
radial(cx, cy, r,...), linear(x1, y1, x2, y2).

related issue: https://github.com/thorvg/thorvg/issues/2078
2024-03-28 22:52:45 +09:00
Vincent Torri
2ec9fdb932 [common] code clean up
use fmodf() instead of fmod()
2024-03-23 11:45:11 +09:00
vtorri
04977c43f1
[common] code clean up
use MATH_PI and MATH_PI2 instead of M_PI and M_PI_2
2024-03-22 23:48:25 +09:00
JunsuChoi
d32c90cbbf svg: Improve valid check for url(#id)
Improve parenthesis checking and space checking.
 - There must be only one pair of parentheses.
 - There cannot be spaces(and ') between id strings.

Issue: https://github.com/thorvg/thorvg/issues/1983

Co-authored-by: Hermet Park <hermet@lottiefiles.com>
2024-02-22 21:51:19 +09:00
Hermet Park
043b6b9f4f common/array: code refactoring
Make the array interface pair begin()/end() for consistency.
2024-02-19 19:09:30 +09:00
JunsuChoi
53e2ecd81c loader/svg: Fix empty id to null
empty id is invalid. Therefore, set it to null and make it is not used.

issue: https://github.com/thorvg/thorvg/issues/1977
2024-02-15 10:29:13 +09:00
Hermet Park
67d8d9f36c svg_loader: code refactoring
removed duplicate matrix multiply function.
2024-01-22 19:03:59 +09:00
Mew Pur Pur
de00104566
svg_loader: Add missing implementation of skewX and skewY in transform-list 2024-01-22 18:52:37 +09:00