2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/*  image_loader_svg.cpp                                                  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/*                         This file is part of:                          */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/*                             GODOT ENGINE                               */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/*                        https://godotengine.org                         */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* Permission is hereby granted, free of charge, to any person obtaining  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* a copy of this software and associated documentation files (the        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* "Software"), to deal in the Software without restriction, including    */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* without limitation the rights to use, copy, modify, merge, publish,    */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* distribute, sublicense, and/or sell copies of the Software, and to     */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* permit persons to whom the Software is furnished to do so, subject to  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* the following conditions:                                              */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* The above copyright notice and this permission notice shall be         */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* included in all copies or substantial portions of the Software.        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
									
										
										
										
											2018-01-05 00:50:27 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								# include  "image_loader_svg.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								# include  "core/os/memory.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								# include  "core/variant/variant.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								# include  <thorvg.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-22 22:07:02 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								HashMap < Color ,  Color >  ImageLoaderSVG : : forced_color_map  =  HashMap < Color ,  Color > ( ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								void  ImageLoaderSVG : : set_forced_color_map ( const  HashMap < Color ,  Color >  & p_color_map )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									forced_color_map  =  p_color_map ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-23 14:15:31 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								void  ImageLoaderSVG : : _replace_color_property ( const  HashMap < Color ,  Color >  & p_color_map ,  const  String  & p_prefix ,  String  & r_string )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// Replace colors in the SVG based on what is passed in `p_color_map`.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									// Used to change the colors of editor icons based on the used theme.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// The strings being replaced are typically of the form:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									//   fill="#5abbef"
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									// But can also be 3-letter codes, include alpha, be "none" or a named color
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-23 14:15:31 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									// string ("blue"). So we convert to Godot Color to compare with `p_color_map`.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									const  int  prefix_len  =  p_prefix . length ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									int  pos  =  r_string . find ( p_prefix ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									while  ( pos  ! =  - 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										pos  + =  prefix_len ;  // Skip prefix.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-16 18:52:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										int  end_pos  =  r_string . find_char ( ' " ' ,  pos ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										ERR_FAIL_COND_MSG ( end_pos  = =  - 1 ,  vformat ( " Malformed SVG string after property  \" %s \" . " ,  p_prefix ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										const  String  color_code  =  r_string . substr ( pos ,  end_pos  -  pos ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										if  ( color_code  ! =  " none "  & &  ! color_code . begins_with ( " url( " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
											const  Color  color  =  Color ( color_code ) ;  // Handles both HTML codes and named colors.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-23 14:15:31 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											if  ( p_color_map . has ( color ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												r_string  =  r_string . left ( pos )  +  " # "  +  p_color_map [ color ] . to_html ( false )  +  r_string . substr ( end_pos ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-30 20:29:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										// Search for other occurrences.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										pos  =  r_string . find ( p_prefix ,  pos ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-30 20:29:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2017-09-08 04:31:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:27:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Ref < Image >  ImageLoaderSVG : : load_mem_svg ( const  uint8_t  * p_svg ,  int  p_size ,  float  p_scale )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Ref < Image >  img ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									img . instantiate ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Error  err  =  create_image_from_utf8_buffer ( img ,  p_svg ,  p_size ,  p_scale ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 20:33:22 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									ERR_FAIL_COND_V_MSG ( err  ! =  OK ,  Ref < Image > ( ) ,  vformat ( " ImageLoaderSVG: Failed to create SVG from buffer, error code %d. " ,  err ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:27:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  img ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Error  ImageLoaderSVG : : create_image_from_utf8_buffer ( Ref < Image >  p_image ,  const  uint8_t  * p_buffer ,  int  p_buffer_size ,  float  p_scale ,  bool  p_upsample )  {  
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									ERR_FAIL_COND_V_MSG ( Math : : is_zero_approx ( p_scale ) ,  ERR_INVALID_PARAMETER ,  " ImageLoaderSVG: Can't load SVG with a scale of 0. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 04:31:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									std : : unique_ptr < tvg : : Picture >  picture  =  tvg : : Picture : : gen ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-19 23:21:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:27:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									tvg : : Result  result  =  picture - > load ( ( const  char  * ) p_buffer ,  p_buffer_size ,  " svg " ,  true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  ( result  ! =  tvg : : Result : : Success )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										return  ERR_INVALID_DATA ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-19 23:21:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									float  fw ,  fh ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-14 00:00:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									picture - > size ( & fw ,  & fh ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 02:09:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-19 14:18:09 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									uint32_t  width  =  MAX ( 1 ,  std : : round ( fw  *  p_scale ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									uint32_t  height  =  MAX ( 1 ,  std : : round ( fh  *  p_scale ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									const  uint32_t  max_dimension  =  16384 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  ( width  >  max_dimension  | |  height  >  max_dimension )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										WARN_PRINT ( vformat ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
												String : : utf8 ( " ImageLoaderSVG: Target canvas dimensions %d× ×  " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
												width ,  height ,  p_scale ,  max_dimension ,  max_dimension ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										width  =  MIN ( width ,  max_dimension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										height  =  MIN ( height ,  max_dimension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									picture - > size ( width ,  height ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									std : : unique_ptr < tvg : : SwCanvas >  sw_canvas  =  tvg : : SwCanvas : : gen ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-19 12:37:56 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									Vector < uint8_t >  buffer ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									buffer . resize ( sizeof ( uint32_t )  *  width  *  height ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-19 12:37:56 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									tvg : : Result  res  =  sw_canvas - > target ( ( uint32_t  * ) buffer . ptrw ( ) ,  width ,  width ,  height ,  tvg : : SwCanvas : : ABGR8888S ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  ( res  ! =  tvg : : Result : : Success )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										ERR_FAIL_V_MSG ( FAILED ,  " ImageLoaderSVG: Couldn't set target on ThorVG canvas. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-19 23:21:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-10 12:05:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									res  =  sw_canvas - > push ( std : : move ( picture ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  ( res  ! =  tvg : : Result : : Success )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										ERR_FAIL_V_MSG ( FAILED ,  " ImageLoaderSVG: Couldn't insert ThorVG picture on canvas. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									res  =  sw_canvas - > draw ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  ( res  ! =  tvg : : Result : : Success )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										ERR_FAIL_V_MSG ( FAILED ,  " ImageLoaderSVG: Couldn't draw ThorVG pictures on canvas. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									res  =  sw_canvas - > sync ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  ( res  ! =  tvg : : Result : : Success )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										ERR_FAIL_V_MSG ( FAILED ,  " ImageLoaderSVG: Couldn't sync ThorVG canvas. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-19 12:37:56 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									p_image - > set_data ( width ,  height ,  false ,  Image : : FORMAT_RGBA8 ,  buffer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									res  =  sw_canvas - > clear ( true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									return  OK ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:27:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Error  ImageLoaderSVG : : create_image_from_utf8_buffer ( Ref < Image >  p_image ,  const  PackedByteArray  & p_buffer ,  float  p_scale ,  bool  p_upsample )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  create_image_from_utf8_buffer ( p_image ,  p_buffer . ptr ( ) ,  p_buffer . size ( ) ,  p_scale ,  p_upsample ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-19 21:42:43 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Error  ImageLoaderSVG : : create_image_from_string ( Ref < Image >  p_image ,  String  p_string ,  float  p_scale ,  bool  p_upsample ,  const  HashMap < Color ,  Color >  & p_color_map )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  ( p_color_map . size ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										_replace_color_property ( p_color_map ,  " stop-color= \" " ,  p_string ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										_replace_color_property ( p_color_map ,  " fill= \" " ,  p_string ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										_replace_color_property ( p_color_map ,  " stroke= \" " ,  p_string ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									PackedByteArray  bytes  =  p_string . to_utf8_buffer ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  create_image_from_utf8_buffer ( p_image ,  bytes ,  p_scale ,  p_upsample ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								void  ImageLoaderSVG : : get_recognized_extensions ( List < String >  * p_extensions )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									p_extensions - > push_back ( " svg " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-08 15:01:02 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Error  ImageLoaderSVG : : load_image ( Ref < Image >  p_image ,  Ref < FileAccess >  p_fileaccess ,  BitField < ImageFormatLoader : : LoaderFlags >  p_flags ,  float  p_scale )  {  
						 
					
						
							
								
									
										
										
										
											2024-04-12 18:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									const  uint64_t  len  =  p_fileaccess - > get_length ( )  -  p_fileaccess - > get_position ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Vector < uint8_t >  buffer ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									buffer . resize ( len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									p_fileaccess - > get_buffer ( buffer . ptrw ( ) ,  buffer . size ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									String  svg ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 12:25:48 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									Error  err  =  svg . append_utf8 ( ( const  char  * ) buffer . ptr ( ) ,  buffer . size ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-12 18:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  ( err  ! =  OK )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  err ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-22 22:07:02 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  ( p_flags  &  FLAG_CONVERT_COLORS )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										err  =  create_image_from_string ( p_image ,  svg ,  p_scale ,  false ,  forced_color_map ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-22 22:07:02 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-18 22:47:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										err  =  create_image_from_string ( p_image ,  svg ,  p_scale ,  false ,  HashMap < Color ,  Color > ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									if  ( err  ! =  OK )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  err ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									}  else  if  ( p_image - > is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										return  ERR_INVALID_DATA ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-22 22:07:02 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-23 13:25:14 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
									if  ( p_flags  &  FLAG_FORCE_LINEAR )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-13 13:54:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
										p_image - > srgb_to_linear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									return  OK ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 21:21:24 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:27:56 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								ImageLoaderSVG : : ImageLoaderSVG ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
									Image : : _svg_scalable_mem_loader_func  =  load_mem_svg ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}