Commit graph

62 commits

Author SHA1 Message Date
Hermet Park
e1eb98af79 loaders svg: code refactoring
clean up code and remove unnecessary internal class.

this also helps to reduce binary size by 5.5kb

no logical changes.
2021-04-09 15:57:23 +09:00
Hermet Park
adf1312a5e loaders svg: ++ log info for wrong situation.
if either log is printed, we need to improve the composition method.
2021-04-09 11:02:35 +09:00
Hermet Park
605a3bf175 loaders svg: code refactoring
++ clean code.
2021-04-09 10:55:09 +09:00
Hermet Park
1a7d41ce71 updated copyright 2021-03-23 14:31:58 +09:00
JunsuChoi
f590571e3a svg_loader SvgLoader: Fix copy conditions for stop of gradient
When getting a linked stop list, if there is no existing stop list
in current gradient, it is copied.
2021-03-04 18:43:58 +09:00
Mira Grudzinska
a72be6159d svgloader: fixing SVG image display when viewBox size is not given
When viewBox is not given its dimensions should be determined
by the height and width parameters
2021-03-03 18:02:36 -08:00
Hermet Park
197879f2ef fixed all wasm build breaks. 2021-02-23 10:47:46 +09:00
Patryk Kaczmarek
795121fa67 SvgLoader: Mask style implementation
Supprot case when style is defined as <mask> attribute.

[Example SVG file]
```html
<svg version="1.1" id="Layer_1" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve"
  xmlns="http://www.w3.org/2000/svg">
  <defs>
    <mask id="myMask">
      <circle id="maskID" cx="40" cy="40" r="10" fill="white" fill-opacity="1" />
    </mask>
  </defs>
  <rect x="0" y="0" width="64" height="64" style="fill: skyblue; mask=url(#myMask);"/>
</svg>
```

Change-Id: I3b856db85204bf7c503a20e4023417ca79aa930c
2021-02-19 18:23:47 +09:00
JunsuChoi
415fca577e common: TVG_UNUSED marking on unused parameter 2021-02-19 16:51:50 +09:00
JunsuChoi
c819754056 common: Refactoring incorrectly declared loop variable
Loop variables should be declared in the minimal possible scope
thorvg prefers to declare when using local variables.
2021-02-19 16:51:50 +09:00
JunsuChoi
08c37978a9 common: Pointer that can declare const are refactored to use const
Pointer and reference parameters should be "const" if the corresponding object is not modified
2021-02-19 16:51:50 +09:00
JunsuChoi
5c914f4ad2 svg_loader SvgLoader: Prevent memory leak
When OOM of SvgLinear/RadialGradient occurs,
the allocated id, ref, transform may become a memory leak.
Therefore, add free memory.
2021-02-02 10:51:50 +09:00
Hermet Park
e737ee4a4f svg_loader: fixed wrong boundary check
sz must be less than 20 to append 'carriage return'
2020-12-22 11:04:39 +09:00
JunsuChoi
438b7d6b02 svg_loader SvgLoader: Add memory allocation failed check
Prevent to null access when out of memory.
2020-12-18 19:51:06 +09:00
JunsuChoi
f13e1947ff svg_loader SvgLoader: Prevent array overflow
Since tagName array set '\0' at the end,
it may overflow when sz reaches 20.
So make it a maximum of 19.
2020-12-18 19:51:06 +09:00
Hermet Park
cee1348a44 svg_loader XmlParser: code refactoring.
just renamed _nodeTypeToString() -> xmlParserNodeTypeToString()

+ print meson message if log is enabled.
2020-12-17 16:11:09 +09:00
JunsuChoi
23331cf8d4 svg_loader SvgLoader: Print inefficient elements
Opacity is 0
both Fill.Opacity and Stroke Opacity are 0
point is 0 in Path
declared display="none"
width or height of bounds becomes 0
2020-12-17 13:56:09 +09:00
Shinwoo Kim
135e6c872b fix typo 2020-12-16 09:58:40 +09:00
Shinwoo Kim
aedd3afd00 fix mistake 2020-12-16 09:57:57 +09:00
Hermet Park
abc9e89517 common log: notify opacity composition usage log.
replaced [XXX] log prefix with XXX:
2020-12-15 14:29:52 +09:00
JunsuChoi
54816339ed svg_loader XmlParser: Print unsupported elements, attribute with log option
* Using printf is temporary. We are planning a proper way to print the log.
When parsing a Svg file, Loader print unsupported elements and attributes.
2020-12-15 14:07:38 +09:00
Hermet Park
932cc65543 loaders: fix memory leak.
While looking for image loader, it occured memory leaks.
Fixed it properly.

@Issues: 178
2020-12-10 11:57:38 +09:00
Hermet Park
1ed611386d
common sw_engine: code refactoring & stabilizing.
Apply tvg Array instead of std::vector

Also Fixed to compList in update() to passed by reference, not copying.
Also Fixed Composition Target memory leak

Here is the binary size result:

[libthorvg.so] 1785376 >> 1607416
[text] 121255 >> 118277
[data] 7792 >> 7736
[dec] 129119 >> 126085
2020-12-09 19:56:59 +09:00
Hermet Park
d13cd37094 fix typo 2020-12-09 15:29:22 +09:00
Hermet Park
d4515d2732 common array: Introduce Array function to common.
This Array is promoted from SvgVector to use it widely in tvg.
It's similar with std::vector, we can use it instead of it.

Also, svg_loader replaced with it subsequently.
2020-12-09 15:29:22 +09:00
Hermet Park
1e78d1f845
picture: replace size parameter to float.
Considering smooth-resizing on sub-pixeling.
2020-12-08 12:27:13 +09:00
JunsuChoi
6889f0ad1f
common Picture : Introduce Picture's size setter, getter APIs
* common Picture : Introduce Picture's size setter, getter APIs

If picture or file loaded by picture has an explicit Size(width, height),
it is transformed to fit the size.
2020-12-04 15:03:25 +09:00
JunsuChoi
d3020b7bbe svg_loader Loader,XmlParser: String that has not been parsed returns false
Existing parser functions always return true.
Parser function's return value was not being properly used.
So, add a return to check whether it is parsed or not.
2020-12-03 18:39:47 +09:00
JunsuChoi
e00f948705
raw_loader Loader: Introduce Raw image loader
Add RawLoader class that loads and display raw images,
and adds a Rasterizer for image data.
Image data can be loaded via picture.
Loaded image supports Composition, Transformation and Alpha blending.

New API
Result load(uint32_t* data, uint32_t width, uint32_t height, bool isCopy) noexcept;
2020-11-23 18:12:36 +09:00
Hermet Park
9872cf066d
common taskScheduler: thread sync optmization
replaced future/promise with mutex since they use a lot of memory allocation number.

plus, binary size is reduced from 2094896 -> 1746864
2020-11-09 14:36:22 +09:00
Hermet Park
1b8188ee67
sw_engine shape: performance optimization.
we introduced shared memory pool for avoiding reallocate memory
while it process the stroke outlines, It experimentally increase
the outline data if we use the allocated memory for multiples shape strokes,
we don't need to alloc/free memory during the process.

This shared outline memory is allocated for threads count
so that we don't interrupt memory access during the tasks.

@Issues: 75
2020-11-04 16:28:47 +09:00
JunsuChoi
dc822174e8 svg_loader: Fixed a typo
lenght ->length
2020-11-02 14:16:13 +09:00
JunsuChoi
d4e9450ec1 common lib/loaders: Fix missing space for coding convention
Correct missing or incorrect spaces according to coding convention.
2020-11-02 14:15:05 +09:00
JunsuChoi
1bf123ff46 svg_loader SvgLoader: Fix wrong indentation
indent 3 -> 4
2020-11-02 14:14:36 +09:00
JunsuChoi
6cf2d89571 svg_loader SvgLoader: Prevent memory overflow for tagName
When copying tagName, if length of referenced string is longer
than general case, it is not used as tagName.
2020-10-30 17:06:06 +09:00
Hermet Park
389b028be4 svg_loader XmlParser: just renamed file name to simplify.
XmlParser without "Simple" is enough to address itself.
2020-10-15 20:44:53 +09:00
JunsuChoi
77ccbcc6fe
tvgSvgLoader: Add points copy of missing polygon/polyline
When using <use> node, do atrribute copy.
At that time, when target(url) is polygon or polyline,
points array is not copied, causing a problem in output.
So, add missing array copy.
2020-10-13 13:45:40 +09:00
JunsuChoi
098c94819c tvgSvgLoader: Fix wrong bracket 2020-10-13 13:43:54 +09:00
JunsuChoi
e73cf7db60 tvgSvgLoader: Add "clip-path" attribute
Below node types support clip-path.
<circle>
<ellipse>
<g>
<path>
<polygon>
<polyline>
<rect>
2020-10-13 13:43:54 +09:00
JunsuChoi
ea0ce1f496 SvgLoader: Implement ClipPath style
Supports case of using style attribute for defined <clipPath>.
In SVG, <clipPath> can be used as a "clipPath" attribute or a style "clip-path".
This patch only supports "clip-path" of style is declared.
The remaining features will be added later.

[Example SVG case]

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve">
 <defs>
      <clipPath id="clipPath">
          <rect x="15" y="15" width="40" height="40" fill="#F00" />
          <circle cx="20" cy="20" r="10" fill="#F00" />
      </clipPath>
  </defs>

  <circle cx="25" cy="25" r="20"
          style="fill: #0000ff; clip-path: url(#clipPath); " />
</svg>
2020-10-13 13:43:54 +09:00
Hermet Park
6365d02a96 optimization: cut off file dependencies.
we should avoid code insertion during file dependencies,
such as #include "xxx.h" which has implementations.

This could increase binary size, we can avoid it as possible.

Current patch improves binary size like this:

From: file(2059008) = text(120360) data(8096) bss(80) dec(128536)
To  : file(1921832) = text(118429) data(7872) bss(56) dec(126357)

More additional patches will come in to optmize binary size.
2020-09-23 20:57:30 +09:00
JunsuChoi
855397be36 SvgLoader: Fix wrong display when dasharray size is 1
If dash array size is 1, it means that dash and gap size are the same.
2020-09-15 12:21:02 +09:00
JunsuChoi
1280548cf1 SvgLoader: Fix missing doc.gradients update
When both <defs> and <svg> gradients are declared,
the update of gradient declared in <svg> is omitted.
Therefore, this patch fixes any missing gradient updates.
2020-09-11 11:11:13 +09:00
JunsuChoi
68ce2dc7d8 SvgLoader: Supports case when only rx or ry is declared
In relation to the declaration of rx and ry attribute of rect, the following three cases occur.
rx="10" (or ry="10"
rx="10" ry = "0" (or rx="0" ry = "10")
rx="10" ry = "10"
To cover these case, we check the rx and ry declarations.
2020-09-10 10:31:31 +09:00
Hermet Park
3e63263646 svg_loader: refactoring code.
merge loader class with task to simplfy code.
2020-09-08 10:43:38 +09:00
JunsuChoi
801896cf8f SvgLoader: Add Mask, ClipPath nodees as dummy.
Mask and clippath TAG are not supported yet.
If this TAG is used, the Child TAG declared with this TAG may cause problems.
To prevent that, declare them as Unknown types until they are supported. (display=none)
2020-09-04 19:47:22 +09:00
JunsuChoi
bd36738011 SvgLoader: Support DashArray attribute for stroke
It supports stroke-dasharray, one of the stroke properties of svg.
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
2020-09-04 16:45:31 +09:00
JunsuChoi
497c1ef131 SvgLoader: Fix memory leak for loader's gradient
Release the memory that was not released.
2020-09-04 16:03:46 +09:00
JunsuChoi
c27a952f44 SvgLoader: Add null check
Since the pointer actually used inside the if condition is loader->def,
add a null check for this.
2020-09-04 16:03:07 +09:00
Hermet Park
b40016c81d svg_loader: prevent dangling node in exception case.
We prefer the independent unit function behavior.
2020-09-04 11:49:08 +09:00