Documentation
¶
Overview ¶
Package thorvg provides a Go API for the ThorVG C++ library.
The documentation for most functions is simply a slightly modified version of the C API documentation comments in ThorVG's C API header file. Documentation for the underlying C++ classes can be found in its Class list documentation.
Index ¶
- func AccessorGenerateId(name string) uint
- func EngineInit(threads int) error
- func EngineTerm() error
- func FontLoad(path string) error
- func FontLoadData(name string, data []byte, mimetype string) error
- func FontUnload(path string) error
- func FontUnloadData(name string) error
- func SetErrorHandler(handler func(err ResultError)) func(err ResultError)
- func Version() (int, int, int, string, string, error)
- type Accessor
- type Animation
- func (animation Animation) ApplySlot(id uint) error
- func (animation Animation) Del() error
- func (animation Animation) DelSlot(id uint) error
- func (animation Animation) ExpressionsSupported() bool
- func (animation Animation) GenSlot(slot string) uint32
- func (animation Animation) GetDuration() (float32, error)
- func (animation Animation) GetFrame() (float32, error)
- func (animation Animation) GetMarker(idx uint) (string, error)
- func (animation Animation) GetMarkerInfo(idx uint) (string, float32, float32, error)
- func (animation Animation) GetMarkersCnt() (uint, error)
- func (animation Animation) GetPicture() Picture
- func (animation Animation) GetSegment() (float32, float32, error)
- func (animation Animation) GetTotalFrame() (float32, error)
- func (animation Animation) GetVolume() float32
- func (animation Animation) SetAudioResolver(resolver AudioResolver) error
- func (animation Animation) SetFrame(no float32) error
- func (animation Animation) SetMarker(marker string) error
- func (animation Animation) SetQuality(value uint) error
- func (animation Animation) SetSegment(begin float32, end float32) error
- func (animation Animation) SetVolume(volume float32) error
- func (animation Animation) Tween(from float32, to float32, progress float32) error
- func (animation Animation) TweenGo(progress float32) error
- func (animation Animation) TweenTo(to float32) error
- type AudioInfo
- type AudioResolver
- type BlendMethod
- type Canvas
- func (canvas Canvas) Add(paint Paint) error
- func (canvas Canvas) Buffer() []byte
- func (canvas *Canvas) Destroy() error
- func (canvas Canvas) Draw(clear_ bool) error
- func (canvas Canvas) GetDirtyRegions(cnt uint32) ([]Region, error)
- func (canvas Canvas) GetDirtyRegionsCnt() uint32
- func (canvas *Canvas) GlSetTarget(display unsafe.Pointer, surface unsafe.Pointer, context unsafe.Pointer, id int, ...) error
- func (canvas Canvas) Insert(target Paint, paint Paint) error
- func (canvas Canvas) Remove(paint Paint) error
- func (canvas Canvas) SetViewport(x int, y int, width int, height int) error
- func (canvas *Canvas) SwSetTarget(stride uint, width uint, height uint, cs ColorSpace) error
- func (canvas Canvas) Sync() error
- func (canvas Canvas) Update(Paint) error
- type ColorSpace
- type ColorStop
- type ConicGradient
- func (gradient ConicGradient) Del() error
- func (gradient ConicGradient) Get() (float32, float32, float32, error)
- func (gradient ConicGradient) GetColorStops() ([]ColorStop, error)
- func (gradient ConicGradient) GetSpread() (StrokeFill, error)
- func (gradient ConicGradient) GetTransform() (Matrix, error)
- func (gradient ConicGradient) GetType() (Type, error)
- func (gradient ConicGradient) Set(cx float32, cy float32, angle float32) error
- func (gradient ConicGradient) SetColorStops(colorStops []ColorStop) error
- func (gradient ConicGradient) SetSpread(spread StrokeFill) error
- func (gradient ConicGradient) SetTransform(matrix Matrix) error
- type EngineOption
- type FillRule
- type FilterMethod
- type GlyphMetrics
- type Gradient
- type LinearGradient
- func (gradient LinearGradient) Del() error
- func (gradient LinearGradient) Duplicate() LinearGradient
- func (gradient LinearGradient) Get() (float32, float32, float32, float32, error)
- func (gradient LinearGradient) GetColorStops() ([]ColorStop, error)
- func (gradient LinearGradient) GetSpread() (StrokeFill, error)
- func (gradient LinearGradient) GetTransform() (Matrix, error)
- func (gradient LinearGradient) GetType() (Type, error)
- func (gradient LinearGradient) Set(x1 float32, y1 float32, x2 float32, y2 float32) error
- func (gradient LinearGradient) SetColorStops(colorStops []ColorStop) error
- func (gradient LinearGradient) SetSpread(spread StrokeFill) error
- func (gradient LinearGradient) SetTransform(matrix Matrix) error
- type MaskMethod
- type Matrix
- type Paint
- type PathCommand
- type Picture
- func (picture Picture) Duplicate() Picture
- func (paint Picture) GetAABB() (float32, float32, float32, float32, error)
- func (paint Picture) GetClip() (any, bool)
- func (paint Picture) GetData() uintptr
- func (paint Picture) GetId() uint32
- func (paint Picture) GetMaskMethod(target Paint) (MaskMethod, error)
- func (paint Picture) GetOBB() ([4]Point, error)
- func (paint Picture) GetOpacity() (uint8, error)
- func (picture Picture) GetOrigin() (float32, float32, error)
- func (picture Picture) GetPaint(id uint) (Paint, bool)
- func (paint Picture) GetParent() (any, bool)
- func (paint Picture) GetRef() int
- func (picture Picture) GetSize() (float32, float32, error)
- func (paint Picture) GetTransform() (Matrix, error)
- func (paint Picture) GetType() (Type, error)
- func (paint Picture) GetVisible() bool
- func (paint Picture) Intersects(x int, y int, width int, height int) bool
- func (paint Picture) IntersectsRegion(x int, y int, width int, height int, visibleOnly bool) bool
- func (picture Picture) Load(path string) error
- func (picture Picture) LoadData(data []byte, mimetype string, rpath string) error
- func (picture Picture) LoadDataText(text string, mimetype string, rpath string) error
- func (picture Picture) LoadPixels(data []byte, stride uint, w uint, h uint, colorspace ColorSpace, ...) error
- func (picture Picture) LoadRaw(data []byte, width uint, height uint, colorSpace ColorSpace) error
- func (paint Picture) Ref() int
- func (paint Picture) Rel() error
- func (paint Picture) Rotate(degree float32) error
- func (paint Picture) Scale(factor float32) error
- func (picture Picture) SetAccessible(accessible bool) error
- func (picture Picture) SetAssetResolver(resolver PictureAssetResolver, fallback bool) error
- func (paint Picture) SetBlendMethod(method BlendMethod) error
- func (paint Picture) SetClip(clipper Paint) error
- func (paint Picture) SetData(data uintptr) error
- func (picture Picture) SetFilter(method FilterMethod) error
- func (paint Picture) SetId(id uint32) error
- func (paint Picture) SetMaskMethod(target Paint, method MaskMethod) error
- func (paint Picture) SetOpacity(opacity uint8) error
- func (picture Picture) SetOrigin(x float32, y float32) error
- func (picture Picture) SetSize(width float32, height float32) error
- func (paint Picture) SetTransform(matrix Matrix) error
- func (paint Picture) SetVisible(visible bool) error
- func (paint Picture) Translate(x float32, y float32) error
- func (paint Picture) Unref(free bool) int
- type PictureAssetResolver
- type Point
- type RadialGradient
- func (gradient RadialGradient) Del() error
- func (gradient RadialGradient) Duplicate() RadialGradient
- func (gradient RadialGradient) Get() (float32, float32, float32, float32, float32, float32, error)
- func (gradient RadialGradient) GetColorStops() ([]ColorStop, error)
- func (gradient RadialGradient) GetSpread() (StrokeFill, error)
- func (gradient RadialGradient) GetTransform() (Matrix, error)
- func (gradient RadialGradient) GetType() (Type, error)
- func (gradient RadialGradient) Set(cx float32, cy float32, r float32, fx float32, fy float32, fr float32) error
- func (gradient RadialGradient) SetColorStops(colorStops []ColorStop) error
- func (gradient RadialGradient) SetSpread(spread StrokeFill) error
- func (gradient RadialGradient) SetTransform(matrix Matrix) error
- type Region
- type Result
- type ResultError
- type Saver
- type Scene
- func (scene Scene) Add(paint Paint) error
- func (scene Scene) AddEffectDropShadow(r int, g int, b int, a int, angle float64, distance float64, sigma float64, ...) error
- func (scene Scene) AddEffectFill(r int, g int, b int, a int) error
- func (scene Scene) AddEffectGaussianBlur(sigma float64, direction int, border int, quality int) error
- func (scene Scene) AddEffectMotionBlur(distance float64, angle float64, quality int32) error
- func (scene Scene) AddEffectTint(black_r int, black_g int, black_b int, white_r int, white_g int, white_b int, ...) error
- func (scene Scene) AddEffectTritone(shadow_r int, shadow_g int, shadow_b int, midtone_r int, midtone_g int, ...) error
- func (scene Scene) ClearEffects() error
- func (scene Scene) Duplicate() Scene
- func (paint Scene) GetAABB() (float32, float32, float32, float32, error)
- func (paint Scene) GetClip() (any, bool)
- func (paint Scene) GetData() uintptr
- func (paint Scene) GetId() uint32
- func (paint Scene) GetMaskMethod(target Paint) (MaskMethod, error)
- func (paint Scene) GetOBB() ([4]Point, error)
- func (paint Scene) GetOpacity() (uint8, error)
- func (paint Scene) GetParent() (any, bool)
- func (paint Scene) GetRef() int
- func (paint Scene) GetTransform() (Matrix, error)
- func (paint Scene) GetType() (Type, error)
- func (paint Scene) GetVisible() bool
- func (scene Scene) Insert(target Paint, at Paint) error
- func (paint Scene) Intersects(x int, y int, width int, height int) bool
- func (paint Scene) IntersectsRegion(x int, y int, width int, height int, visibleOnly bool) bool
- func (paint Scene) Ref() int
- func (paint Scene) Rel() error
- func (scene Scene) Remove(paint Paint) error
- func (paint Scene) Rotate(degree float32) error
- func (paint Scene) Scale(factor float32) error
- func (paint Scene) SetBlendMethod(method BlendMethod) error
- func (paint Scene) SetClip(clipper Paint) error
- func (paint Scene) SetData(data uintptr) error
- func (paint Scene) SetId(id uint32) error
- func (paint Scene) SetMaskMethod(target Paint, method MaskMethod) error
- func (paint Scene) SetOpacity(opacity uint8) error
- func (paint Scene) SetTransform(matrix Matrix) error
- func (paint Scene) SetVisible(visible bool) error
- func (paint Scene) Translate(x float32, y float32) error
- func (paint Scene) Unref(free bool) int
- type Shape
- func (shape Shape) AppendCircle(cx float32, cy float32, rx float32, ry float32, cw bool) error
- func (shape Shape) AppendPath(cmds []PathCommand, pts []Point) error
- func (shape Shape) AppendRect(x float32, y float32, w float32, h float32, rx float32, ry float32, cw bool) error
- func (shape Shape) Close() error
- func (shape Shape) CubicTo(cx1 float32, cy1 float32, cx2 float32, cy2 float32, x float32, y float32) error
- func (shape Shape) Duplicate() Shape
- func (paint Shape) GetAABB() (float32, float32, float32, float32, error)
- func (paint Shape) GetClip() (any, bool)
- func (paint Shape) GetData() uintptr
- func (shape Shape) GetFillColor() (uint8, uint8, uint8, uint8, error)
- func (shape Shape) GetFillRule() (FillRule, error)
- func (shape Shape) GetGradient() (Gradient, bool, error)
- func (paint Shape) GetId() uint32
- func (paint Shape) GetMaskMethod(target Paint) (MaskMethod, error)
- func (paint Shape) GetOBB() ([4]Point, error)
- func (paint Shape) GetOpacity() (uint8, error)
- func (paint Shape) GetParent() (any, bool)
- func (shape Shape) GetPath() ([]PathCommand, []Point, error)
- func (paint Shape) GetRef() int
- func (shape Shape) GetStrokeCap() (StrokeCap, error)
- func (shape Shape) GetStrokeColor() (int, int, int, int, error)
- func (shape Shape) GetStrokeDash() ([]float32, float32, error)
- func (shape Shape) GetStrokeGradient() (Gradient, error)
- func (shape Shape) GetStrokeJoin() (StrokeJoin, error)
- func (shape Shape) GetStrokeMiterlimit() (float32, error)
- func (shape Shape) GetStrokeWidth() (float32, error)
- func (paint Shape) GetTransform() (Matrix, error)
- func (paint Shape) GetType() (Type, error)
- func (paint Shape) GetVisible() bool
- func (paint Shape) Intersects(x int, y int, width int, height int) bool
- func (paint Shape) IntersectsRegion(x int, y int, width int, height int, visibleOnly bool) bool
- func (shape Shape) LineTo(x float32, y float32) error
- func (shape Shape) MoveTo(x float32, y float32) error
- func (paint Shape) Ref() int
- func (paint Shape) Rel() error
- func (shape Shape) Reset() error
- func (paint Shape) Rotate(degree float32) error
- func (paint Shape) Scale(factor float32) error
- func (paint Shape) SetBlendMethod(method BlendMethod) error
- func (paint Shape) SetClip(clipper Paint) error
- func (paint Shape) SetData(data uintptr) error
- func (shape Shape) SetFillColor(r uint8, g uint8, b uint8, a uint8) error
- func (shape Shape) SetFillRule(rule FillRule) error
- func (shape Shape) SetGradient(gradient Gradient) error
- func (paint Shape) SetId(id uint32) error
- func (paint Shape) SetMaskMethod(target Paint, method MaskMethod) error
- func (paint Shape) SetOpacity(opacity uint8) error
- func (shape Shape) SetPaintOrder(strokeFirst bool) error
- func (shape Shape) SetStrokeCap(strokeCap StrokeCap) error
- func (shape Shape) SetStrokeColor(r uint, g uint, b uint, a uint) error
- func (shape Shape) SetStrokeDash(pattern []float32, offset float32) error
- func (shape Shape) SetStrokeGradient(grad Gradient) error
- func (shape Shape) SetStrokeJoin(join StrokeJoin) error
- func (shape Shape) SetStrokeMiterlimit(miterlimit float32) error
- func (shape Shape) SetStrokeWidth(width float32) error
- func (paint Shape) SetTransform(matrix Matrix) error
- func (shape Shape) SetTrimpath(begin float32, end float32, simultaneous bool) error
- func (paint Shape) SetVisible(visible bool) error
- func (paint Shape) Translate(x float32, y float32) error
- func (paint Shape) Unref(free bool) int
- type StrokeCap
- type StrokeFill
- type StrokeJoin
- type Text
- func (text Text) Align(x float32, y float32) error
- func (text Text) Duplicate() Text
- func (paint Text) GetAABB() (float32, float32, float32, float32, error)
- func (paint Text) GetClip() (any, bool)
- func (paint Text) GetData() uintptr
- func (text Text) GetGlyphMetrics(ch rune) (GlyphMetrics, error)
- func (paint Text) GetId() uint32
- func (text Text) GetLength() int
- func (paint Text) GetMaskMethod(target Paint) (MaskMethod, error)
- func (paint Text) GetOBB() ([4]Point, error)
- func (paint Text) GetOpacity() (uint8, error)
- func (paint Text) GetParent() (any, bool)
- func (paint Text) GetRef() int
- func (text Text) GetTextMetrics() (TextMetrics, error)
- func (paint Text) GetTransform() (Matrix, error)
- func (paint Text) GetType() (Type, error)
- func (paint Text) GetVisible() bool
- func (paint Text) Intersects(x int, y int, width int, height int) bool
- func (paint Text) IntersectsRegion(x int, y int, width int, height int, visibleOnly bool) bool
- func (text Text) Layout(width float32, h float32) error
- func (paint Text) Ref() int
- func (paint Text) Rel() error
- func (paint Text) Rotate(degree float32) error
- func (paint Text) Scale(factor float32) error
- func (paint Text) SetBlendMethod(method BlendMethod) error
- func (paint Text) SetClip(clipper Paint) error
- func (text Text) SetColor(r uint8, g uint8, b uint8) error
- func (paint Text) SetData(data uintptr) error
- func (text Text) SetFont(name string) error
- func (text Text) SetGradient(gradient Gradient) error
- func (paint Text) SetId(id uint32) error
- func (text Text) SetItalic(shear float32) error
- func (paint Text) SetMaskMethod(target Paint, method MaskMethod) error
- func (paint Text) SetOpacity(opacity uint8) error
- func (text Text) SetOutline(width float32, r uint8, g uint8, b uint8) error
- func (text Text) SetSize(size float32) error
- func (text Text) SetText(utf8 string) error
- func (paint Text) SetTransform(matrix Matrix) error
- func (paint Text) SetVisible(visible bool) error
- func (text Text) Spacing(letter float32, line float32) error
- func (paint Text) Translate(x float32, y float32) error
- func (paint Text) Unref(free bool) int
- func (text Text) WrapMode(mode TextWrap) error
- type TextMetrics
- type TextWrap
- type Type
- type Video
- func (video Video) Del() error
- func (video Video) GetDuration() float32
- func (video Video) GetLoop() bool
- func (video Video) GetMuted() bool
- func (video Video) GetTime() float32
- func (video Video) GetVolume() float32
- func (video Video) Pause() error
- func (video Video) Picture() Picture
- func (video Video) Play() error
- func (video Video) Seek(seconds float32) error
- func (video Video) SetLoop(on bool) error
- func (video Video) SetMute(on bool) error
- func (video Video) SetVolume(volume float32) error
- func (video Video) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessorGenerateId ¶
Generate a unique ID (hash key) from a given name.
This function computes a unique identifier value based on the provided string. You can use this to assign a unique ID to the Paint object.
- name : The input string to generate the unique identifier from.
Return: The generated unique identifier value.
Since: 1.0
func EngineInit ¶
Initializes the ThorVG engine.
Sets up the internal task scheduler and launches the specified number of worker threads for parallel rendering operations.
- threads : The number of worker threads to create. A value of 0 disables worker threads.
Return: Tvg_Result indicating success or failure of initialization.
Note: Initialization is reference-counted. Each successful call increments the reference count. The worker thread count is determined by the first successful initialization and remains unchanged until the engine is fully terminated.
Warning: Each EngineInit call must be paired with a EngineTerm call on the same thread.
see EngineTerm
func EngineTerm ¶
func EngineTerm() error
Terminates the ThorVG engine.
Releases internal resources and shuts down worker threads initialized by tvg_engine_init().
Returns RESULT_INSUFFICIENT_CONDITION : If the engine is not initialized.
Note: Initialization is reference-counted. Each call to EngineTerm decrements the reference count, and the engine is fully terminated only when the count reaches zero.
Warning: Each EngineInit call must be paired with a EngineTerm call on the same thread.
see EngineInit
func FontLoad ¶
Loads a scalable font data from a file.
ThorVG efficiently caches the loaded data using the specified path as a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded font data.
- path : The path to the font file.
Returns RESULT_INVALID_ARGUMENT : An invalid path passed as an argument.
Returns RESULT_NOT_SUPPORTED : When trying to load a file with an unknown extension.
see FontUnload
Since: 0.15
func FontLoadData ¶
Loads a scalable font data from a memory block of a given size.
ThorVG efficiently caches the loaded font data using the specified name as a key. This means that loading the same fonts again will not result in duplicate operations. Instead, ThorVG will reuse the previously loaded font data.
- name : The name under which the font will be stored and accessible (e.x. in a tvg_text_set_font API).
- data : A pointer to a memory location where the content of the font data is stored.
- size : The size in bytes of the memory occupied by the data.
- mimetype : Mimetype or extension of font data. In case a nullptr or an empty "" value is provided the loader will be determined automatically.
- copy : If true the data are copied into the engine local buffer, otherwise they are not (default).
Returns RESULT_INVALID_ARGUMENT : If no name is provided or if size is zero while data points to a valid memory location.
Returns RESULT_NOT_SUPPORTED : When trying to load a file with an unknown extension.
Returns RESULT_INSUFFICIENT_CONDITION : When trying to unload the font data that has not been previously loaded.
Warning:: It's the user responsibility to release the data memory.
Note: To unload the font data loaded using this API, pass the proper name and nullptr as data.
Since: 0.15
func FontUnload ¶
Unloads the specified scalable font data that was previously loaded.
This function is used to release resources associated with a font file that has been loaded into memory.
- path : The path to the loaded font file.
Returns RESULT_INSUFFICIENT_CONDITION : The loader is not initialized.
Note: If the font data is currently in use, it will not be immediately unloaded.
see FontLoad
Since: 0.15
func FontUnloadData ¶
Loads a scalable font data from a memory block of a given size.
ThorVG efficiently caches the loaded font data using the specified name as a key. This means that loading the same fonts again will not result in duplicate operations. Instead, ThorVG will reuse the previously loaded font data.
- name : The name under which the font will be stored and accessible (e.x. in a tvg_text_set_font API).
- data : A pointer to a memory location where the content of the font data is stored.
- size : The size in bytes of the memory occupied by the data.
- mimetype : Mimetype or extension of font data. In case a nullptr or an empty "" value is provided the loader will be determined automatically.
- copy : If true the data are copied into the engine local buffer, otherwise they are not (default).
Returns RESULT_INVALID_ARGUMENT : If no name is provided or if size is zero while data points to a valid memory location.
Returns RESULT_NOT_SUPPORTED : When trying to load a file with an unknown extension.
Returns RESULT_INSUFFICIENT_CONDITION : When trying to unload the font data that has not been previously loaded.
Warning:: It's the user responsibility to release the data memory.
Note: To unload the font data loaded using this API, pass the proper name and nullptr as data.
Since: 0.15
func SetErrorHandler ¶
func SetErrorHandler(handler func(err ResultError)) func(err ResultError)
SetErrorHandler sets an error handler function that will be called when any function returns an error that represents a Result that is not RESULT_SUCCESS.
Providing nil for the handler will result in errors being returned from functions in the normal fashion.
The previous error handler, which may be nil, will be returned.
A lot of the functions in this package return an error if the underlying thorvg C function call returns an unsuccessful result. Checking every returned potential error in an application can be tedious. So an application may want to treat all, or most, thorvg errors in a common way. Perhaps by logging an error, or by exiting. In which case setting an error handler may be appropriate.
An application may wish to treat most thorvg errors in a common way, but here and there needs to handle errors from a function call. In which case it may appropriate to temporarily remove the handler.
oldHandler := SetErrorHandler(nil)
if err := tvg.SomeFunction(...); err != nil {
// handle the error
}
SetErrorHandler(oldHandler)
func Version ¶
Retrieves the version of the TVG engine.
- major : A major version number.
- minor : A minor version number.
- micro : A micro version number.
- version : The version of the engine in the format major.minor.micro, or a nullptr in case of an internal error.
Returns RESULT_SUCCESS :
Since: 0.15
Types ¶
type Accessor ¶
type Accessor uintptr
Accessor ia a structure representing an object that enables iterating through a scene's descendents.
func AccessorNew ¶
func AccessorNew() Accessor
Creates a new accessor object.
Return: A new accessor object.
Since: 1.0
func (Accessor) Del ¶
Deletes the given accessor object.
- accessor : The accessor object to be deleted.
Since: 1.0
func (Accessor) GetName ¶
Retrieve the original name string from a given unique ID.
Returns the name associated with the specified identifier. This method is only valid when Picture.SetAccessible is set to true for the Picture associated with the given paint in Accessor.Set Otherwise, the name information may not be available.
- accessor : An accessor object.
- id : The unique identifier.
Return: The corresponding name string, or nullptr if not found or unavailable.
see [Accessor.GenerateId]
see Accessor.Set
Note: This function is only available within Accessor callbacks registered via Accessor.Set Since: 1.1
func (Accessor) Set ¶
Sets the paint of the accessor then iterates through its descendents.
Iterates through all descendents of the scene passed through the paint argument while calling func on each and passing the data pointer to this function. When func returns false iteration stops and the function returns.
- accessor : An accessor object.
- paint : The scene object.
- func : A function pointer to the function that will be execute for each child.
- data : A void pointer to data that will be passed to the func.
Since: 1.0
type Animation ¶
type Animation uintptr
func AnimationNew ¶
func AnimationNew() Animation
Creates a new Animation object.
Return: Tvg_Animation A new Tvg_Animation object.
Since: 0.13
func LottieAnimationNew ¶
func LottieAnimationNew() Animation
Creates a new LottieAnimation object.
Return: Tvg_Animation A new Tvg_LottieAnimation object.
Since: 0.15
func (Animation) ApplySlot ¶
Applies a previously generated slot to the animation.
- animation : The Lottie animation object.
- id : The ID of the slot to apply, or 0 to reset all slots.
Returns RESULT_INSUFFICIENT_CONDITION : In case the animation is not loaded.
Returns RESULT_INVALID_ARGUMENT : When the given id is invalid
Returns RESULT_NOT_SUPPORTED : The Lottie Animation is not supported.
Since: 1.0
func (Animation) Del ¶
Deletes the given Tvg_Animation object.
- animation : The Tvg_Animation object to be deleted.
Since: 0.13
func (Animation) DelSlot ¶
Deletes a previously generated slot.
- animation : The Lottie animation object.
- id : The ID of the slot to delete.
Return: Tvg_Result enumeration.
Returns RESULT_INSUFFICIENT_CONDITION : In case the animation is not loaded or the slot ID is invalid.
Returns RESULT_NOT_SUPPORTED : The Lottie Animation is not supported.
Note: This function should be paired with gen.
see Animation.GenSlot Since: 1.0
func (Animation) ExpressionsSupported ¶ added in v1.1.2
Checks whether Lottie expressions are supported.
Return: true if expression support is enabled in this build, otherwise false.
Note: Experimental API
func (Animation) GenSlot ¶ added in v1.1.4
Generates a new slot from the given slot data.
- animation : The Lottie animation object.
- slot : The Lottie slot data in JSON format.
Return: The generated slot ID when successful, 0 otherwise.
Since: 1.0
func (Animation) GetDuration ¶
Retrieves the duration of the animation in seconds.
- animation : An animation object.
- duration : The duration of the animation in seconds.
Returns RESULT_INVALID_ARGUMENT : An invalid duration pointer.
Note: If the Picture is not properly configured, this function will return 0.
Since: 0.13
func (Animation) GetFrame ¶
Retrieves the current frame number of the animation.
- animation : An animation object.
- no : The current frame number of the animation, between 0 and totalFrame() - 1.
Returns RESULT_INVALID_ARGUMENT : An invalid no pointer.
Since: 0.13
func (Animation) GetMarkerInfo ¶
Retrieves marker information by index.
- animation : The Lottie animation object.
- idx : The zero-based index of the animation marker.
- name : Pointer to receive the marker name. Pass nullptr if the value is not required.
- begin : Pointer to receive the marker's starting frame. Pass nullptr if the value is not required.
- end : Pointer to receive the marker's ending frame. Pass nullptr if the value is not required.
Returns RESULT_INVALID_ARGUMENT : if idx is out of range.
Returns RESULT_INSUFFICIENT_CONDITION : In case the animation is not loaded.
see Animation.GetMarkersCnt Since: 1.1
func (Animation) GetMarkersCnt ¶
Gets the marker count of the animation.
- animation : The Lottie animation object.
- cnt : The count value of the markers.
Returns RESULT_INVALID_ARGUMENT : In case a nullptr is passed as the argument.
Since: 1.0
func (Animation) GetPicture ¶
Retrieves a picture instance associated with this animation instance.
This function provides access to the picture instance that can be used to load animation formats, such as lot. After setting up the picture, it can be added to the designated canvas, enabling control over animation frames with this Animation instance.
- animation : A animation object to the animation object.
Return: A picture instance that is tied to this animation.
Warning: The picture instance is owned by Animation. It should not be deleted manually.
Since: 0.13
func (Animation) GetSegment ¶
Gets the current segment range information.
- animation : The animation object.
- begin : segment begin frame.
- end : segment end frame.
Returns RESULT_INSUFFICIENT_CONDITION : In case the animation is not loaded.
Since: 1.0
func (Animation) GetTotalFrame ¶
Retrieves the total number of frames in the animation.
- animation : An animation object.
- cnt : The total number of frames in the animation.
Returns RESULT_INVALID_ARGUMENT : An invalid cnt pointer.
Note: Frame numbering starts from 0.
Note: If the Picture is not properly configured, this function will return 0.
Since: 0.13
func (Animation) GetVolume ¶ added in v1.1.2
Retrieves the master playback volume of the Lottie animation.
- animation : A Lottie animation object.
Return: The current master playback volume, otherwise 0 if the animation is invalid.
Note: Experimental API
func (Animation) SetAudioResolver ¶
func (animation Animation) SetAudioResolver(resolver AudioResolver) error
Sets the audio resolver callback for Lottie audio layers.
The resolver is invoked whenever the playback state of an audio layer changes. It allows applications to synchronize audio playback with the animation timeline.
- animation : A Lottie animation object.
- resolver : A user-defined callback that receives audio playback state updates.
- data : User data passed to resolver.
Returns RESULT_INSUFFICIENT_CONDITION : The animation has not been loaded.
Note: To disable audio notifications, pass nullptr as resolver.
Note: Experimental API.
see Tvg_Audio_Resolver
func (Animation) SetFrame ¶
Specifies the current frame in the animation.
- animation : An animation object.
- no : The index of the animation frame to be displayed. The index should be less than the tvg_animation_get_total_frame().
Returns RESULT_INSUFFICIENT_CONDITION : if the given no is the same as the current frame value.
Returns RESULT_NOT_SUPPORTED : The picture data does not support animations.
Note: For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value is less than 0.001. In such cases, it returns Result::InsufficientCondition. Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.
Since: 0.13
func (Animation) SetMarker ¶
Specifies a segment by marker.
- animation : The Lottie animation object.
- marker : The name of the segment marker.
Returns RESULT_INSUFFICIENT_CONDITION : In case the animation is not loaded.
Returns RESULT_INVALID_ARGUMENT : When the given marker is invalid.
Returns RESULT_NOT_SUPPORTED : The Lottie Animation is not supported.
Since: 1.0
func (Animation) SetQuality ¶
Sets the quality level for Lottie effects.
This function controls the rendering quality of effects like blur, shadows, etc. Lower values prioritize performance while higher values prioritize quality.
- animation : The Lottie animation object.
- value : The quality level (0-100). 0 represents lowest quality/best performance, 100 represents highest quality/lowest performance, the initial value is 50.
Returns RESULT_INSUFFICIENT_CONDITION : If the animation is not loaded.
Note: This option is used as a hint; its behavior heavily depends on the render backend.
Since: 1.0
func (Animation) SetSegment ¶
Specifies the playback segment of the animation.
The set segment is designated as the play area of the animation. This is useful for playing a specific segment within the entire animation. After setting, the number of animation frames and the playback time are calculated by mapping the playback segment as the entire range.
- animation : The animation object.
- begin : segment begin frame.
- end : segment end frame.
Returns RESULT_INSUFFICIENT_CONDITION : In case the animation is not loaded.
Returns RESULT_INVALID_ARGUMENT : If the begin is higher than end.
Note: Animation allows a range from 0.0 to the total frame. end should not be lower than begin.
Note: If a marker has been specified, its range will be disregarded.
Since: 1.0
func (Animation) SetVolume ¶ added in v1.1.2
Sets the master playback volume of the Lottie animation.
The specified volume is applied to all media assets in the animation. Each media asset preserves its own volume, and the effective playback volume is calculated by multiplying the master volume by the media asset's volume. A value of 1.0 preserves the original volume. A value of 0.0 mutes all media. Values greater than 1.0 amplify the playback volume. The recommended range is [0.0, 2.0].
- animation : A Lottie animation object.
- volume : Master playback volume.
Returns RESULT_INSUFFICIENT_CONDITION : If the animation is not loaded.
Note: Experimental API
func (Animation) Tween ¶
Interpolates between two frames over a specified duration.
This method performs tweening, a process of generating intermediate frame between from and to based on the given progress.
- animation : The Lottie animation object.
- from : The start frame number of the interpolation.
- to : The end frame number of the interpolation.
- progress : The current progress of the interpolation (range: 0.0 to 1.0).
Returns RESULT_INSUFFICIENT_CONDITION : In case the animation is not loaded.
Since: 1.0
func (Animation) TweenGo ¶
Updates the current tween toward the target frame.
This method advances the interpolation started by Animation.TweenTo using the given progress value.
- animation : The Lottie animation object.
- progress : The current progress of the interpolation (range: 0.0 to 1.0).
Returns RESULT_INSUFFICIENT_CONDITION : If the animation is not loaded.
Returns RESULT_INSUFFICIENT_CONDITION : If Animation.TweenTo has not been called.
Note: Experimental API
func (Animation) TweenTo ¶
Sets the target frame for dynamic tweening.
This method starts a dynamic interpolation from the current animation frame toward to. Use tvg_lottie_animation_tween_go() to update the interpolation progress.
- animation : The Lottie animation object.
- to : The target frame number of the interpolation.
Returns RESULT_INSUFFICIENT_CONDITION : If the animation is not loaded.
Note: The dynamic tweening set by this method is discarded when Animation.SetFrame or Animation.Tween is called.
Note: Experimental API
type AudioInfo ¶
type AudioInfo struct {
Src string // Audio source: a file path/URL or embedded raw bytes.
MimeType string // MIME type string; valid when @c embedded; may be @c NULL.
Size uint32 // Embedded data size in bytes; valid when @c embedded.
Offset float32 // Position within the audio file in seconds; valid when @c active.
Volume float32 // Volume [0, 100]; valid when @c active.
Active bool // @c true while the layer is within its playback range.
Embedded bool // @c true if @p src points to embedded audio data; @c false if it is a file path or URL.
}
AudioInfo describes the current state of a Lottie audio layer.
This structure is provided to the audio resolver callback and contains the information required to synchronize audio playback with the animation timeline. Applications are responsible for managing audio playback using their own audio engine.
Example:
@code
void on_audio(const Tvg_Audio_Info* info, void* data)
{
if (info->active) {
// Start or seek playback of info->src.
} else {
// Stop playback of info->src.
}
}
@endcode
@see tvg_lottie_animation_set_audio_resolver()
@note Experimental API
type AudioResolver ¶
type AudioResolver func(info AudioInfo)
AudioResolver is a callback invoked to provide audio playback information for a Lottie animation.
Applications can use this callback to synchronize external audio playback with the animation timeline.
@param[in] info Audio information for the current timeline state. @param[in] data User data specified when registering the callback. @see tvg_lottie_animation_set_audio_resolver() @note Experimental API.
type BlendMethod ¶
type BlendMethod enum
BlendMethod is an enumeration indicates the method used for blending paint. Please refer to the respective formulas for each method.
@ingroup ThorVGCapi_Paint @since 0.15
const ( BLEND_METHOD_NORMAL BlendMethod = iota // Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D BLEND_METHOD_MULTIPLY // Takes the RGB channel values from 0 to 255 of each pixel in the top layer and multiples them with the values for the corresponding pixel from the bottom layer. (S * D) BLEND_METHOD_SCREEN // The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D) BLEND_METHOD_OVERLAY // Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D) BLEND_METHOD_DARKEN // Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D) BLEND_METHOD_LIGHTEN // Only has the opposite action of Darken Only. max(S, D) BLEND_METHOD_COLORDODGE // Divides the bottom layer by the inverted top layer. D / (255 - S) BLEND_METHOD_COLORBURN // Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S BLEND_METHOD_HARDLIGHT // The same as Overlay but with the color roles reversed. (2 * S * D) if (S < Sa), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D) BLEND_METHOD_SOFTLIGHT // Darkens or lightens the colors, depending on the source color value. If S <= 0.5: D - (1 - 2 * S) * D * (1 - D), otherwise: D + (2 * S - 1) * (G(D) - D), where G(D) = ((16 * D - 12) * D + 4) * D if D <= 0.25, otherwise sqrt(D) BLEND_METHOD_DIFFERENCE // Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S) BLEND_METHOD_EXCLUSION // The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d) BLEND_METHOD_HUE // Uses the hue of the source and the saturation and luminosity of the destination. @since 1.0 BLEND_METHOD_SATURATION // Uses the saturation of the source and the hue and luminosity of the destination. @since 1.0 BLEND_METHOD_COLOR // Uses the hue and saturation of the source and the luminosity of the destination. @since 1.0 BLEND_METHOD_LUMINOSITY // Uses the luminosity of the source and the hue and saturation of the destination. @since 1.0 BLEND_METHOD_ADD // Simply adds pixel values of one layer with the other. (S + D) BLEND_METHOD_COMPOSITION BlendMethod = 255 // Used for intermediate composition. @since 1.0 )
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas is a structure responsible for managing and drawing graphical elements.
It sets up the target buffer, which can be drawn on the screen. It stores the Paint objects (Shape, Scene, Picture).
func GlCanvasCreate ¶
func GlCanvasCreate(option EngineOption) Canvas
Creates a new OpenGL/ES Canvas object with optional rendering engine settings.
This method generates a OpenGL/ES canvas instance that can be used for drawing vector graphics. It accepts an optional parameter op to choose between different rendering engine behaviors.
- op : The rendering engine option.
Return: A new canvas object.
Note: Currently, it does not support TVG_ENGINE_OPTION_SMART_RENDER. The request will be ignored.
see enum Tvg_Engine_Option
Since: 1.0
func SwCanvasCreate ¶
func SwCanvasCreate(option EngineOption) Canvas
Creates a new Software Canvas object with optional rendering engine settings.
This method generates a software canvas instance that can be used for drawing vector graphics. It accepts an optional parameter op to choose between different rendering engine behaviors.
- op : The rendering engine option.
Return: A new canvas object.
see enum Tvg_Engine_Option
func (Canvas) Add ¶
Adds a paint object to the canvas for rendering.
Adds the specified paint into the canvas root scene. Only paints added to the canvas are considered rendering targets. The canvas retains the paint object until it is explicitly removed via tvg_canvas_remove().
- canvas : A handle to the canvas that will manage the paint object.
- paint : A handle to the paint object to be rendered.
Returns RESULT_INSUFFICIENT_CONDITION : If the canvas is not in a valid state to accept new paints.
Note: Ownership of the paint object is transferred to the canvas upon successful addition. To retain ownership, call [Paint.Ref] before adding it to the canvas.
Note: The rendering order of paint objects follows the order in which they are added to the canvas. If layering is required, ensure paints are added in the desired order.
see Canvas.Insert
see Canvas.Remove
Since: 1.0
func (Canvas) Buffer ¶
Buffer returns the buffer target of a software canvas.
The buffer remains the canvas's target, so its contents should not be altered.
If the canvas is not a software canvas, nil will be returned. If the canvas is a software canvas but has never has a target set, nil will be returned.
func (*Canvas) Destroy ¶
Clears the canvas internal data, releases all paints stored by the canvas and destroys the canvas object itself.
- canvas : The canvas object to be destroyed.
func (Canvas) Draw ¶
Requests the canvas to render the Paint objects.
- canvas : The canvas object containing elements to be drawn.
- clear : If true, clears the target buffer to zero before drawing.
Returns RESULT_INSUFFICIENT_CONDITION : The canvas is not properly prepared. This may occur if the canvas target has not been set or if the update is called during drawing. without calling tvg_canvas_sync() in between.
Note: Clearing the buffer is unnecessary if the canvas will be fully covered with opaque content. Skipping the clear can improve performance.
Note: Drawing may be performed asynchronously if the thread count is greater than zero. To ensure the drawing process is complete, call sync() afterwards.
Note: If the canvas has not been updated prior to tvg_canvas_draw(), it may implicitly perform tvg_canvas_update()
see Canvas.Sync
see Canvas.Update
func (Canvas) GetDirtyRegions ¶ added in v1.1.3
Retrieves the dirty regions of the canvas.
- canvas : The canvas object.
- regions : An array to receive the dirty regions.
- cnt : The number of Tvg_Region elements that the array can hold.
Returns RESULT_INVALID_ARGUMENT : If canvas or regions is NULL, or cnt is zero.
Returns RESULT_INSUFFICIENT_CONDITION : If called outside the interval after tvg_canvas_draw() and before tvg_canvas_sync().
Note: This function must be called after Canvas.Draw and before Canvas.Sync
Note: If the active rendering backend does not support TVG_ENGINE_OPTION_SMART_RENDER, a single region covering the entire render target is returned.
Note: Experimental API
func (Canvas) GetDirtyRegionsCnt ¶ added in v1.1.3
Returns the number of dirty regions of the canvas.
- canvas : The canvas object.
Return: The number of regions available for retrieval, or zero if canvas is NULL.
Note: This function must be called after Canvas.Draw and before Canvas.Sync
Note: If the active rendering backend does not support TVG_ENGINE_OPTION_SMART_RENDER, this function returns 1.
Note: Experimental API
func (*Canvas) GlSetTarget ¶
func (canvas *Canvas) GlSetTarget( display unsafe.Pointer, surface unsafe.Pointer, context unsafe.Pointer, id int, width uint, height uint, colorSpace ColorSpace, ) error
Sets the drawing target for rasterization.
This function specifies the drawing target where the rasterization will occur. It can target a specific framebuffer object (FBO) or the main surface.
- display : The platform-specific display handle (EGLDisplay for EGL). Set nullptr for other systems.
- surface : The platform-specific surface handle (EGLSurface for EGL, HDC for WGL). Set nullptr for other systems.
- context : The OpenGL context to be used for rendering on this canvas.
- id : The GL target ID, usually indicating the FBO ID. A value of 0 specifies the main surface.
- w : The width (in pixels) of the raster image.
- h : The height (in pixels) of the raster image.
- cs : Specifies how the pixel values should be interpreted. Currently, it only allows TVG_COLORSPACE_ABGR8888S as GL_RGBA8.
Note: If display and surface are not provided, the ThorVG GL engine assumes that the appropriate OpenGL context is already current and will not attempt to bind a new one.
Returns RESULT_INSUFFICIENT_CONDITION : If the canvas is currently rendering. Ensure that Canvas.Sync has been called before setting a new target.
Returns RESULT_NOT_SUPPORTED : In case the gl engine is not supported.
see Canvas.Sync
Since: 1.0
func (Canvas) Insert ¶
Inserts a paint object into the canvas root scene.
Inserts a paint object into the root scene of the specified canvas. If the at parameter is provided, the paint object is inserted immediately before the specified paint in the root scene. If at is nullptr, the paint object is appended to the end of the root scene.
- canvas : A handle to the canvas that will manage the paint object. This parameter must be a valid canvas handle.
- target : A handle to the paint object to be inserted into the root scene. This parameter must not be nullptr.
- at : A handle to an existing paint object in the root scene before which target will be inserted. If nullptr, target is appended to the end of the root scene.
Note: Ownership of the target object is transferred to the canvas upon successful addition. To retain ownership, call [Paint.Ref] before adding it to the canvas.
Note: The rendering order of paint objects follows their order in the root scene. If layering is required, ensure paints are inserted in the desired order.
see Canvas.Add
see Canvas.Remove
Since: 1.0
func (Canvas) Remove ¶
Removes a paint object from the root scene.
This function removes a specified paint object from the root scene. If no paint object is specified (i.e., the default nullptr is used), the function performs to clear all paints from the scene.
- canvas : A canvas object to remove the paint.
- paint : The paint object to be removed from the root scene. If nullptr, remove all the paints from the root scene.
see Canvas.Add
see Canvas.Insert Since: 1.0
func (Canvas) SetViewport ¶
Sets the drawing region of the canvas.
This function defines a rectangular area of the canvas to be used for drawing operations. The specified viewport clips rendering output to the boundaries of that rectangle. Please note that changing the viewport is only allowed at the beginning of the rendering sequence—that is, after calling tvg_canvas_sync().
- canvas : The canvas object containing elements which were drawn.
- x : The x-coordinate of the upper-left corner of the rectangle.
- y : The y-coordinate of the upper-left corner of the rectangle.
- w : The width of the rectangle.
- h : The height of the rectangle.
Returns RESULT_INSUFFICIENT_CONDITION : If the canvas is not in a synced state.
see Canvas.Sync
see [SwcanvasSetTarget]
see [GlcanvasSetTarget]
see [WgcanvasSetTarget]
Warning: Changing the viewport is not allowed after calling tvg_canvas_add(), tvg_canvas_remove(), tvg_canvas_update(), or tvg_canvas_draw().
Note: When the target is reset, the viewport will also be reset to match the target size. Since: 0.15
func (*Canvas) SwSetTarget ¶
Sets the buffer used in the rasterization process and defines the used colorspace.
For optimisation reasons TVG does not allocate memory for the output buffer on its own. The buffer of a desirable size should be allocated and owned by the caller.
- canvas : The canvas object managing the buffer.
- buffer : The allocated memory block of the size stride x h.
- stride : The stride of the raster image - in most cases same value as w.
- w : The width of the raster image.
- h : The height of the raster image.
- cs : The colorspace value defining the way the 32-bits colors should be read/written.
Returns RESULT_INVALID_ARGUMENT : An invalid canvas or buffer pointer passed or one of the stride, w or h being zero.
Returns RESULT_INSUFFICIENT_CONDITION : if the canvas is performing rendering. Please ensure the canvas is synced.
Returns RESULT_NOT_SUPPORTED : The software engine is not supported.
Warning: Do not access buffer during tvg_canvas_draw() - tvg_canvas_sync(). It should not be accessed while the engine is writing on it.
Note: Currently, only TVG_COLORSPACE_ABGR8888, TVG_COLORSPACE_ARGB8888, TVG_COLORSPACE_ABGR8888S, and TVG_COLORSPACE_ARGB8888S are supported for cs.
see Tvg_Colorspace
func (Canvas) Sync ¶
Guarantees that drawing task is finished.
- canvas : The canvas object containing elements which were drawn.
The Canvas rendering can be performed asynchronously. To make sure that rendering is finished, the tvg_canvas_sync() must be called after the tvg_canvas_draw() regardless of threading.
see Canvas.Draw
func (Canvas) Update ¶
Requests the canvas to update modified paint objects in preparation for rendering.
This function triggers an internal update for all paint instances that have been modified since the last update. It ensures that the canvas state is ready for accurate rendering.
- canvas : The canvas object to be updated.
Returns RESULT_INSUFFICIENT_CONDITION : The canvas is not properly prepared. This may occur if the canvas target has not been set or if the update is called during drawing. Call tvg_canvas_sync() before trying.
Note: Only paint objects that have been changed will be processed.
Note: If the canvas is configured with multiple threads, the update may be performed asynchronously.
see Canvas.Sync
type ColorSpace ¶
type ColorSpace enum
ColorSpace is an enumeration specifying the methods of combining the 8-bit color channels into 32-bit color.
const ( COLORSPACE_ABGR8888 ColorSpace = iota // The channels are joined in the order: alpha, blue, green, red. Colors are alpha-premultiplied. COLORSPACE_ARGB8888 // The channels are joined in the order: alpha, red, green, blue. Colors are alpha-premultiplied. COLORSPACE_ABGR8888S // The channels are joined in the order: alpha, blue, green, red. Colors are un-alpha-premultiplied. (since 0.13) COLORSPACE_ARGB8888S // The channels are joined in the order: alpha, red, green, blue. Colors are un-alpha-premultiplied. (since 0.13) COLORSPACE_XBGR8888 // 32-bit opaque color in the order: unused, blue, green, red. @note Experimental API COLORSPACE_XRGB8888 // 32-bit opaque color in the order: unused, red, green, blue. @note Experimental API COLORSPACE_UNKNOWN ColorSpace = 255 // Unknown channel data. This is reserved for an initial ColorSpace value. (since 1.0) )
type ColorStop ¶
type ColorStop struct {
Offset float32 // The relative position of the color.
R uint8 // The red color channel value in the range [0 ~ 255].
G uint8 // The green color channel value in the range [0 ~ 255].
B uint8 // The blue color channel value in the range [0 ~ 255].
A uint8 // The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
// contains filtered or unexported fields
}
ColorStop is a data structure storing the information about the color and its relative position inside the gradient bounds.
type ConicGradient ¶ added in v1.1.3
type ConicGradient struct {
// contains filtered or unexported fields
}
func ConicGradientNew ¶ added in v1.1.3
func ConicGradientNew() ConicGradient
Creates a new conic gradient object.
Return: A new conic gradient object.
Note: Experimental API
func (ConicGradient) Del ¶ added in v1.1.3
func (gradient ConicGradient) Del() error
Deletes the given gradient object.
- grad : The gradient object to be deleted.
func (ConicGradient) Get ¶ added in v1.1.3
func (gradient ConicGradient) Get() (float32, float32, float32, error)
Gets the conic gradient attributes.
- grad : The Tvg_Gradient object of which to get the gradient attributes.
- cx : The horizontal coordinate of the center of the gradient.
- cy : The vertical coordinate of the center of the gradient.
- angle : The initial angle in degrees.
Note: Experimental API
func (ConicGradient) GetColorStops ¶ added in v1.1.3
Gets the parameters of the colors of the gradient, their position and number
The function does not allocate any memory.
- grad : The Tvg_Gradient object of which to get the color information.
- color_stop : An array of Tvg_Color_Stop data structure.
- cnt : The size of the color_stop array equal to the colors number used in the gradient.
func (ConicGradient) GetSpread ¶ added in v1.1.3
func (gradient ConicGradient) GetSpread() (StrokeFill, error)
Gets the FillSpread value of the gradient object.
- grad : The Tvg_Gradient object.
- spread : The FillSpread value.
func (ConicGradient) GetTransform ¶ added in v1.1.3
Gets the matrix of the affine transformation of the gradient object.
In case no transformation was applied, the identity matrix is set.
- grad : The Tvg_Gradient object of which to get the transformation matrix.
- m : The 3x3 augmented matrix.
func (ConicGradient) GetType ¶ added in v1.1.3
Gets the unique value of the gradient instance indicating the instance type.
- grad : The Tvg_Gradient object of which to get the type value.
- type : The unique type of the gradient instance type.
Since: 1.0
func (ConicGradient) Set ¶ added in v1.1.3
func (gradient ConicGradient) Set(cx float32, cy float32, angle float32) error
Sets the conic gradient attributes.
The gradient sweeps a full turn clockwise around the center (cx, cy), beginning at angle. Color stop offsets from 0% to 100% map clockwise over one full turn from angle.
- grad : The Tvg_Gradient object of which attributes are to be set.
- cx : The horizontal coordinate of the center of the gradient.
- cy : The vertical coordinate of the center of the gradient.
- angle : The initial angle in degrees, measured clockwise from the 3 o'clock direction (positive x-axis).
Note: FillSpread options are ignored because the gradient always sweeps a full turn.
Note: Experimental API
func (ConicGradient) SetColorStops ¶ added in v1.1.3
Sets the parameters of the colors of the gradient and their position.
- grad : The Tvg_Gradient object of which the color information is to be set.
- color_stop : An array of Tvg_Color_Stop data structure.
- cnt : The size of the color_stop array equal to the colors number used in the gradient.
func (ConicGradient) SetSpread ¶ added in v1.1.3
func (gradient ConicGradient) SetSpread(spread StrokeFill) error
Sets the Tvg_Stroke_Fill value, which specifies how to fill the area outside the gradient bounds.
- grad : The Tvg_Gradient object.
- spread : The FillSpread value.
func (ConicGradient) SetTransform ¶ added in v1.1.3
Sets the matrix of the affine transformation for the gradient object.
The augmented matrix of the transformation is expected to be given.
- grad : The Tvg_Gradient object to be transformed.
- m : The 3x3 augmented matrix.
type EngineOption ¶
type EngineOption enum
EngineOption is an enumeration to specify rendering engine behavior.
The availability or behavior of @c ENGINE_OPTION_SMART_RENDER may vary depending on platform or backend support. It attempts to optimize rendering performance by updating only the regions of the canvas that have changed between frames (partial redraw). This can be highly effective in scenarios where most of the canvas remains static and only small portions are updated—such as simple animations or GUI interactions. However, in complex scenes where a large portion of the canvas changes frequently (e.g., full-screen animations or heavy object movements), the overhead of tracking changes and managing update regions may outweigh the benefits, resulting in decreased performance compared to the default rendering mode. Thus, it is recommended to benchmark both modes in your specific use case to determine the optimal setting.
@since 1.0
const ( ENGINE_OPTION_NONE EngineOption = 0 // No engine options are enabled. This may be used to explicitly disable all optional behaviors. ENGINE_OPTION_DEFAULT EngineOption = 1 << 0 // Uses the default rendering mode. ENGINE_OPTION_SMART_RENDER EngineOption = 1 << 1 // Enables automatic partial (smart) rendering optimizations. TVG_ENGINE_OPTION_ALIASED EngineOption = 1 << 2 // Disables anti-aliased rendering from the default rendering mode. @note Experimental API. )
type FillRule ¶
type FillRule enum
FillRule is an enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape.
const ( FILL_RULE_NON_ZERO FillRule = iota // A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape. FILL_RULE_EVEN_ODD // A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape. )
type FilterMethod ¶
type FilterMethod enum
FilterMethod defines the image filtering method used during image scaling or transformation.
@note Experimental API
const ( FILTER_METHOD_BILINEAR FilterMethod = iota ///< Smooth interpolation using surrounding pixels for higher quality. FILTER_METHOD_NEAREST ///< Fast filtering using nearest-neighbor sampling. )
type GlyphMetrics ¶
type GlyphMetrics struct {
Advance float32 ///< The advance distance along the baseline (inline) direction.
Bearing float32 ///< The bearing from the origin to the glyph’s visible bound along the inline-start direction.
Min Point ///< The minimum point of the glyph bounding box in local space.
Max Point ///< The maximum point of the glyph bounding box in local space.
// contains filtered or unexported fields
}
GlyphMetrics describes the layout metrics of a glyph.
Provides the basic layout metrics used for positioning an individual glyph, including its advance along the baseline direction, bearing relative to the inline axis origin, and its bounding box in local glyph space.
The advance value represents the distance the pen position moves along the baseline (inline direction), regardless of whether the text is laid out horizontally or vertically.
The bounding box is defined in the glyph’s local coordinate space and is independent of any layout direction or transformation.
@see tvg_text_get_glyph_metrics() @note Experimental API
type Gradient ¶
type Gradient interface {
// contains filtered or unexported methods
}
Gradient is a structure representing a gradient fill of a Paint object.
type LinearGradient ¶
type LinearGradient struct {
// contains filtered or unexported fields
}
func LinearGradientNew ¶
func LinearGradientNew() LinearGradient
Creates a new linear gradient object.
Return: A new linear gradient object.
func (LinearGradient) Del ¶
func (gradient LinearGradient) Del() error
Deletes the given gradient object.
- grad : The gradient object to be deleted.
func (LinearGradient) Duplicate ¶
func (gradient LinearGradient) Duplicate() LinearGradient
Duplicate duplicates the given Tvg_Gradient object. Creates a new object and sets its all properties as in the original object.
@param[in] grad The Tvg_Gradient object to be copied. @return A copied Tvg_Gradient object if succeed, @c nullptr otherwise.
func (LinearGradient) Get ¶
Gets the linear gradient bounds.
The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing the given points (x1, y1) and (x2, y2), respectively. Both lines are perpendicular to the line linking (x1, y1) and (x2, y2).
- grad : The Tvg_Gradient object of which to get the bounds.
- x1 : The horizontal coordinate of the first point used to determine the gradient bounds.
- y1 : The vertical coordinate of the first point used to determine the gradient bounds.
- x2 : The horizontal coordinate of the second point used to determine the gradient bounds.
- y2 : The vertical coordinate of the second point used to determine the gradient bounds.
func (LinearGradient) GetColorStops ¶
Gets the parameters of the colors of the gradient, their position and number
The function does not allocate any memory.
- grad : The Tvg_Gradient object of which to get the color information.
- color_stop : An array of Tvg_Color_Stop data structure.
- cnt : The size of the color_stop array equal to the colors number used in the gradient.
func (LinearGradient) GetSpread ¶
func (gradient LinearGradient) GetSpread() (StrokeFill, error)
Gets the FillSpread value of the gradient object.
- grad : The Tvg_Gradient object.
- spread : The FillSpread value.
func (LinearGradient) GetTransform ¶
Gets the matrix of the affine transformation of the gradient object.
In case no transformation was applied, the identity matrix is set.
- grad : The Tvg_Gradient object of which to get the transformation matrix.
- m : The 3x3 augmented matrix.
func (LinearGradient) GetType ¶
Gets the unique value of the gradient instance indicating the instance type.
- grad : The Tvg_Gradient object of which to get the type value.
- type : The unique type of the gradient instance type.
Since: 1.0
func (LinearGradient) Set ¶
Sets the linear gradient bounds.
The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing the given points (x1, y1) and (x2, y2), respectively. Both lines are perpendicular to the line linking (x1, y1) and (x2, y2).
- grad : The Tvg_Gradient object of which bounds are to be set.
- x1 : The horizontal coordinate of the first point used to determine the gradient bounds.
- y1 : The vertical coordinate of the first point used to determine the gradient bounds.
- x2 : The horizontal coordinate of the second point used to determine the gradient bounds.
- y2 : The vertical coordinate of the second point used to determine the gradient bounds.
Note: In case the first and the second points are equal, an object is filled with a single color using the last color specified in the tvg_gradient_set_color_stops().
see [GradientSetColorStops]
func (LinearGradient) SetColorStops ¶
Sets the parameters of the colors of the gradient and their position.
- grad : The Tvg_Gradient object of which the color information is to be set.
- color_stop : An array of Tvg_Color_Stop data structure.
- cnt : The size of the color_stop array equal to the colors number used in the gradient.
func (LinearGradient) SetSpread ¶
func (gradient LinearGradient) SetSpread(spread StrokeFill) error
Sets the Tvg_Stroke_Fill value, which specifies how to fill the area outside the gradient bounds.
- grad : The Tvg_Gradient object.
- spread : The FillSpread value.
func (LinearGradient) SetTransform ¶
Sets the matrix of the affine transformation for the gradient object.
The augmented matrix of the transformation is expected to be given.
- grad : The Tvg_Gradient object to be transformed.
- m : The 3x3 augmented matrix.
type MaskMethod ¶
type MaskMethod enum
MaskMethod is an enumeration indicating the method used in the masking of two objects - the target and the source.
@ingroup ThorVGCapi_Paint
const ( MASK_METHOD_NONE MaskMethod = iota // No Masking is applied. MASK_METHOD_ALPHA // Alpha Masking using the masking target's pixels as an alpha value. MASK_METHOD_INVERSE_ALPHA // Alpha Masking using the complement to the masking target's pixels as an alpha value. MASK_METHOD_LUMA // Alpha Masking using the grayscale (0.2126R + 0.7152G + 0.0722*B) of the masking target's pixels. @since 0.9 MASK_METHOD_INVERSE_LUMA // Alpha Masking using the grayscale (0.2126R + 0.7152G + 0.0722*B) of the complement to the masking target's pixels. @since 0.11 MASK_METHOD_ADD // Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) @since 1.0 MASK_METHOD_SUBTRACT // Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) @since 1.0 MASK_METHOD_INTERSECT // Computes the result by taking the minimum value between the target alpha and the source alpha and multiplies it with the target color. (T * min(TA, SA)) @since 1.0 MASK_METHOD_DIFFERENCE // Calculates the absolute difference between the target color and the source color multiplied by the complement of the target alpha. abs(T - S * (255 - TA)) @since 1.0 MASK_METHOD_LIGHTEN // Where multiple masks intersect, the highest transparency value is used. @since 1.0 MASK_METHOD_DARKEN // Where multiple masks intersect, the lowest transparency value is used. @since 1.0 )
type Matrix ¶
type Matrix struct {
E11, E12, E13 float32
E21, E22, E23 float32
E31, E32, E33 float32
// contains filtered or unexported fields
}
Matrix is a data structure representing a three-dimensional matrix.
The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor. The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively. The elements e31 and e32 are set to 0, e33 is set to 1.
type Paint ¶
type Paint interface {
// contains filtered or unexported methods
}
Paint is a structure representing a graphical element.
@warning The TvgPaint objects cannot be shared between Canvases.
type PathCommand ¶
type PathCommand uint8
PathCommand is an enumeration specifying the values of the path commands accepted by ThorVG.
const ( PATH_COMMAND_CLOSE PathCommand = iota // Ends the current sub-path and connects it with its initial point - corresponds to Z command in the svg path commands. PATH_COMMAND_MOVE_TO // Sets a new initial point of the sub-path and a new current point - corresponds to M command in the svg path commands. PATH_COMMAND_LINE_TO // Draws a line from the current point to the given point and sets a new value of the current point - corresponds to L command in the svg path commands. PATH_COMMAND_CUBIC_TO // Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point - corresponds to C command in the svg path commands. )
type Picture ¶
type Picture struct {
// contains filtered or unexported fields
}
func PictureNew ¶
func PictureNew() Picture
Creates a new Picture object.
This function allocates and returns a new Picture instance. To properly destroy the Picture object, use [Paint.Rel]
Return: The newly created Picture object.
see [Paint.Rel]
func (Picture) Duplicate ¶
Duplicate duplicates a Picture.
Creates a new object and sets its all properties as in the original object.
@param[in] paint The Tvg_Paint object to be copied. @return A copied Tvg_Paint object if succeed, @c nullptr otherwise.
func (Picture) GetAABB ¶
Retrieves the axis-aligned bounding box (AABB) of the paint object in canvas space.
Returns the bounding box of the paint as an axis-aligned bounding box (AABB), with all relevant transformations applied. The returned values x, y, w, h, may have invalid if the operation fails. Thus, please check the retval. This bounding box can be used to determine the actual rendered area of the object on the canvas, for purposes such as hit-testing, culling, or layout calculations.
- paint : The paint object of which to get the bounds.
- x : The x-coordinate of the upper-left corner of the bounding box.
- y : The y-coordinate of the upper-left corner of the bounding box.
- w : The width of the bounding box.
- h : The height of the bounding box.
Returns RESULT_INSUFFICIENT_CONDITION : If it failed to compute the bounding box (mostly due to invalid path information).
see [Paint.GetObb]
see Canvas.Update
func (Picture) GetClip ¶
Get the clipper shape of the paint object.
This function returns the clipper that has been previously set to this paint object.
Return: The shape object used as the clipper, or nullptr if no clipper is set.
see [Paint.SetClip]
Since: 1.0
func (Picture) GetData ¶ added in v1.1.2
func (paint Picture) GetData() uintptr
Gets the user-defined data associated with the Paint object.
- paint : The paint object whose user-defined data will be returned.
Return: The user-defined data, or NULL if none is set or paint is invalid.
see [Paint.SetData]
Note: Experimental API
func (Picture) GetId ¶
func (paint Picture) GetId() uint32
Gets the ID of the Paint object.
- paint : The paint object whose ID will be returned.
Return: The ID of the paint object, or 0 if the ID is not set.
see Picture.GetPaint
see [Accessor.GenerateId]
see [Paint.SetId]
Since: 1.1
func (Picture) GetMaskMethod ¶
func (paint Picture) GetMaskMethod(target Paint) (MaskMethod, error)
Gets the masking target object and the masking method.
- paint : The source object of the masking.
- target : The target object of the masking.
- method : The method used to mask the source object with the target.
func (Picture) GetOBB ¶
Retrieves the object-oriented bounding box (OBB) of the paint object in canvas space.
This function returns the bounding box of the paint, as an oriented bounding box (OBB) after transformations are applied. The returned values pt4 may have invalid if the operation fails. Thus, please check the retval. This bounding box can be used to obtain the transformed bounding region in canvas space by taking the geometry's axis-aligned bounding box (AABB) in the object's local coordinate space and applying the object's transformations.
- paint : The paint object of which to get the bounds.
- pt4 : An array of four points representing the bounding box. The array size must be 4.
Returns RESULT_INSUFFICIENT_CONDITION : If it failed to compute the bounding box (mostly due to invalid path information).
see [Paint.GetAabb]
see Canvas.Update
Since: 1.0
func (Picture) GetOpacity ¶
Gets the opacity of the given Tvg_Paint.
- paint : The paint object of which to get the opacity value.
- opacity : The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
func (Picture) GetOrigin ¶
Gets the normalized origin point of the Picture object.
This method retrieves the current origin point of the Picture, expressed in normalized coordinates relative to the picture’s bounds.
- picture : The picture object.
- x : The normalized x-coordinate of the origin (range: 0.0f to 1.0f).
- y : The normalized y-coordinate of the origin (range: 0.0f to 1.0f).
see Picture.SetOrigin Since: 1.0
func (Picture) GetPaint ¶
Retrieve a paint object from the Picture scene by its Unique ID.
This function searches for a paint object within the Picture scene that matches the provided id.
- picture : The picture object.
- id : The Unique ID of the paint object.
Return: The paint object that matches the given identifier, or nullptr if no matching paint object is found.
Note: Setting Picture.SetAccessible to true enables more efficient access.
see [Accessor.GenerateId] Since: 1.0
func (Picture) GetParent ¶
GetParent retrieves the parent paint object.
This function returns a pointer to the parent object if the current paint belongs to one. Otherwise, it returns @c nullptr.
@param[in] paint The Paint object of which to get the scene. @return A pointer to the parent object if available, otherwise @c nullptr. @see tvg_scene_add() @see tvg_canvas_add() @since 1.0
func (Picture) GetRef ¶
func (paint Picture) GetRef() int
Retrieve the current reference count of the Tvg_Paint object.
This method provides the current reference count, allowing the user to check the shared ownership state of the Tvg_Paint object.
- paint : The paint object to return the reference count.
Return: The current reference count of the Tvg_Paint object.
see [Paint.Ref]
see [Paint.Unref]
Since: 1.0
func (Picture) GetSize ¶
Gets the size of the loaded picture.
- picture : The picture object.
- w : A width of the image in pixels.
- h : A height of the image in pixels.
func (Picture) GetTransform ¶
Gets the matrix of the affine transformation of the given Tvg_Paint object.
In case no transformation was applied, the identity matrix is returned.
- paint : The paint object of which to get the transformation matrix.
- m : The 3x3 augmented matrix.
func (Picture) GetType ¶
Gets the unique value of the paint instance indicating the instance type.
- paint : The paint object of which to get the type value.
- type : The unique type of the paint instance type.
Since: 1.0
func (Picture) GetVisible ¶
func (paint Picture) GetVisible() bool
Gets the current visibility status of the Paint object.
- paint : The paint object to return the visibility status.
Return: true if the object is visible and will be rendered. false if the object is hidden and will not be rendered.
see [Paint.SetVisible]
Since: 1.0
func (Picture) Intersects ¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— intersects the geometric fill region of the paint object. This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region. The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
- paint : The paint object to be tested.
- x : The x-coordinate of the top-left corner of the test region.
- y : The y-coordinate of the top-left corner of the test region.
- w : The width of the region to test. Must be greater than 0.
- h : The height of the region to test. Must be greater than 0.
Return: true if any part of the region intersects the filled area; otherwise, false.
Note: To test a single point, set the region size to w = 1, h = 1.
Note: For efficiency, an AABB (axis-aligned bounding box) test is performed internally before precise hit detection.
Note: This test does not take into account the results of blending or masking.
Note: This test does take into account hidden paints as well.
see [Paint.SetVisible] Since: 1.0
func (Picture) IntersectsRegion ¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— intersects the geometric fill region of the paint object. This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region. The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
- paint : The paint object to be tested.
- x : The x-coordinate of the top-left corner of the test region.
- y : The y-coordinate of the top-left corner of the test region.
- w : The width of the region to test. Must be greater than 0.
- h : The height of the region to test. Must be greater than 0.
- visibleOnly : If true, hidden paints are excluded from the intersection test.
Return: true if any part of the region intersects the filled area; otherwise, false.
Note: To test a single point, set the region size to w = 1, h = 1.
Note: This test does not take into account the results of blending or masking.
see [Paint.SetVisible] Since: Experimental API
func (Picture) Load ¶
Loads a picture data directly from a file.
ThorVG efficiently caches the loaded data using the specified path as a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded picture data.
- picture : The picture object.
- path : The absolute path to the image file.
Returns RESULT_INVALID_ARGUMENT : An empty path.
Returns RESULT_NOT_SUPPORTED : A file with an unknown extension.
func (Picture) LoadData ¶
Loads a picture data from a memory block of a given size.
ThorVG efficiently caches the loaded data using the specified data address as a key when the copy has false. This means that loading the same data again will not result in duplicate operations for the sharable data. Instead, ThorVG will reuse the previously loaded picture data.
- picture : The picture object.
- data : A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if copy is false
- size : The size in bytes of the memory occupied by the data.
- mimetype : Mimetype or extension of data such as "jpg", "jpeg", "svg", "svg+xml", "lot", "lottie+json", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one.
- rpath : A resource directory path, if the data needs to access any external resources.
- copy : If true the data are copied into the engine local buffer, otherwise they are not.
Returns RESULT_INVALID_ARGUMENT : In case a nullptr is passed as the argument or the size is zero or less.
Returns RESULT_NOT_SUPPORTED : A file with an unknown extension.
Warning:: It's the user responsibility to release the data memory if the copy is true.
func (Picture) LoadDataText ¶
Loads a picture data from a memory block of a given size.
ThorVG efficiently caches the loaded data using the specified data address as a key when the copy has false. This means that loading the same data again will not result in duplicate operations for the sharable data. Instead, ThorVG will reuse the previously loaded picture data.
- picture : The picture object.
- data : A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if copy is false
- size : The size in bytes of the memory occupied by the data.
- mimetype : Mimetype or extension of data such as "jpg", "jpeg", "svg", "svg+xml", "lot", "lottie+json", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one.
- rpath : A resource directory path, if the data needs to access any external resources.
- copy : If true the data are copied into the engine local buffer, otherwise they are not.
Returns RESULT_INVALID_ARGUMENT : In case a nullptr is passed as the argument or the size is zero or less.
Returns RESULT_NOT_SUPPORTED : A file with an unknown extension.
Warning:: It's the user responsibility to release the data memory if the copy is true.
func (Picture) LoadPixels ¶ added in v1.1.4
func (picture Picture) LoadPixels(data []byte, stride uint, w uint, h uint, colorspace ColorSpace, user_owned bool) error
Loads raw image data from memory.
- picture : The picture object.
- data : A pointer to the raw image data.
- stride : The number of pixels between the starts of consecutive rows, including padding. Must be at least w.
- w : The width of the image in pixels.
- h : The height of the image in pixels.
- cs : Specifies how the 32-bit color values should be interpreted.
- user_owned : If false, ownership of data is transferred to ThorVG, which releases the memory when it is no longer needed. If true, the caller retains ownership and must keep the memory valid while ThorVG uses it.
Returns RESULT_INVALID_ARGUMENT : data pointer is null, width or height is zero, stride is less than width, or colorspace is unknown.
Warning: Transferred memory must be allocated with malloc() or a compatible allocator. Since: 1.2
func (Picture) LoadRaw ¶
Loads raw image data in a specific format from a memory block of the given size.
ThorVG efficiently caches the loaded data, using the provided data address as a key when copy is set to false. This allows ThorVG to avoid redundant operations by reusing the previously loaded picture data for the same sharable data, rather than duplicating the load process.
- picture : The picture object.
- data : The memory block where the raw image data is stored.
- w : The width of the image in pixels.
- h : The height of the image in pixels.
- cs : Specifies how the 32-bit color values should be interpreted (read/write).
- copy : If true, the data is copied into the engine's local buffer. If false, the data is not copied.
Returns RESULT_INVALID_ARGUMENT : No data are provided or the w or h value is zero or less.
Note: TVG_COLORSPACE_XBGR8888 and TVG_COLORSPACE_XRGB8888 overwrite fully covered pixels without alpha blending.
Since: 0.9
func (Picture) Ref ¶
func (paint Picture) Ref() int
Increment the reference count for the Tvg_Paint object.
This method increases the reference count of Tvg_Paint object, allowing shared ownership and control over its lifetime.
- paint : The paint object to increase the reference count.
Return: The updated reference count after the increment by 1.
Warning: Please ensure that each call to tvg_paint_ref() is paired with a corresponding call to tvg_paint_unref() to prevent a dangling instance.
see [Paint.Unref]
see [Paint.GetRef]
Since: 1.0
func (Picture) Rel ¶
func (paint Picture) Rel() error
Safely releases a Tv_Paint object.
This is the counterpart to the `new()` API, and releases the given Paint object safely, handling nullptr and managing ownership properly.
- paint : A paint object to release.
func (Picture) Rotate ¶
Rotates the given Tvg_Paint by the given angle.
The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.
- paint : The paint object to be rotated.
- degree : The value of the rotation angle in degrees.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Picture) Scale ¶
Scales the given Tvg_Paint object by the given factor.
- paint : The paint object to be scaled.
- factor : The value of the scaling factor. The initial value is 1.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Picture) SetAccessible ¶
Enable or disable accessible mode for a Picture.
When accessible mode is enabled, the Picture maintains an internal mapping of ID-accessible vector assets nodes (such as SVG), allowing efficient access to Paint objects and their associated identifier information via Accessor APIs. When disabled, no additional mapping is maintained and all nodes are treated as general traversal targets.
- picture : The target Picture object.
- accessible : Set to true to enable accessible mode, or false to disable it.
see [Accessor.GenerateId]
see Accessor.GetName
see Picture.GetPaint
Since: 1.1
func (Picture) SetAssetResolver ¶
func (picture Picture) SetAssetResolver(resolver PictureAssetResolver, fallback bool) error
Sets the asset resolver callback for external images and fonts.
The callback allows the user to load assets from an external source or a virtual filesystem, or provide a substitute. Set fallback to true to invoke it only when internal resolution fails, or false to invoke it before internal resolution.
picture : The picture object.
resolver : A user-defined function that handles the resolution of asset paths. The function should return true if the asset was successfully resolved by the user, or false if it was not.
data : A pointer to user-defined data that will be passed to the callback each time it is invoked. This can be used to maintain context or access external resources.
fallback : If true, invoke the callback only after internal resolution fails. If false, invoke it first and attempt internal resolution only if it returns false.
Returns RESULT_INSUFFICIENT_CONDITION : If the picture is already loaded. The resolver is not changed.
Note: This function must be called before loading the picture.
Note: Available embedded image and font data is loaded internally without invoking the callback.
Note: src identifies the asset to resolve, such as an image path, a font path, or a font name. Font names are prefixed with "name:" (e.g., "name:FreeSans-Medium") to distinguish them from paths.
Note: For fonts, if neither the callback nor internal resolution succeeds, ThorVG attempts to use an available font.
Note: To unset the resolver before loading, pass nullptr as the resolver parameter.
Note: Experimental API
see Tvg_Picture_Asset_Resolver
func (Picture) SetBlendMethod ¶
func (paint Picture) SetBlendMethod(method BlendMethod) error
Sets the blending method for the paint object.
The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. The blending operation is determined by the chosen BlendMethod, which specifies how the colors or images are combined.
- paint : The paint object of which to set the blend method.
- method : The blending method to be set.
Since: 0.15
func (Picture) SetClip ¶
Clip the drawing region of the paint object.
This function restricts the drawing area of the paint object to the specified shape's paths.
- paint : The target object of the clipping.
- clipper : The shape object as the clipper.
Returns RESULT_INSUFFICIENT_CONDITION : if the target has already belonged to another paint.
Returns RESULT_NOT_SUPPORTED : If the clipper type is not Shape.
see [Paint.GetClip]
Since: 1.0
func (Picture) SetData ¶ added in v1.1.2
Associates user-defined data with the Paint object.
ThorVG does not interpret or manage the lifetime of this data.
- paint : The paint object whose user-defined data will be set.
- data : The user-defined data to associate with the paint object.
see [Paint.GetData]
Note: Experimental API
func (Picture) SetFilter ¶
func (picture Picture) SetFilter(method FilterMethod) error
Sets the image filtering method for rendering this picture.
Specifies how the image data should be filtered when it is scaled or transformed during rendering. This affects the visual quality and performance of the output.
- picture : A Tvg_Paint pointer to the picture object.
- method : The filtering method to apply. The initial value is TVG_FILTER_METHOD_BILINEAR.
see Tvg_Filter_Method Since: 1.1
func (Picture) SetId ¶
Sets the ID of the Paint object.
The ID is used to specify a paint instance in a scene.
- paint : The paint object whose ID will be set.
- id : The ID to assign to the paint object.
see Picture.GetPaint
see [Accessor.GenerateId]
see [Paint.GetId]
Since: 1.1
func (Picture) SetMaskMethod ¶
func (paint Picture) SetMaskMethod(target Paint, method MaskMethod) error
Sets the masking target object and the masking method.
- paint : The source object of the masking.
- target : The target object of the masking.
- method : The method used to mask the source object with the target.
Returns RESULT_INSUFFICIENT_CONDITION : if the target has already belonged to another paint.
func (Picture) SetOpacity ¶
Sets the opacity of the given Tvg_Paint.
- paint : The paint object of which the opacity value is to be set.
- opacity : The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
Note: Setting the opacity with this API may require multiple renderings using a composition. It is recommended to avoid changing the opacity if possible.
func (Picture) SetOrigin ¶
Sets the normalized origin point of the Picture object.
This method defines the origin point of the Picture using normalized coordinates. Unlike a typical pivot point used only for transformations, this origin affects both the transformation behavior and the actual rendering position of the Picture. The specified origin becomes the reference point for positioning the Picture on the canvas. For example, setting the origin to (0.5f, 0.5f) moves the visual center of the picture to the position specified by Paint::translate(). The coordinates are given in a normalized range relative to the picture's bounds: - (0.0f, 0.0f): top-left corner - (0.5f, 0.5f): center - (1.0f, 1.0f): bottom-right corner
- picture : The picture object.
- x : The normalized x-coordinate of the origin point (range: 0.0f to 1.0f).
- y : The normalized y-coordinate of the origin point (range: 0.0f to 1.0f).
Note: This origin directly affects how the Picture is placed on the canvas when using transformations such as translate(), rotate(), or scale().
see [Paint.Translate]
see [Paint.Rotate]
see [Paint.Scale]
see [Paint.SetTransform]
Since: 1.0
func (Picture) SetSize ¶
Resizes the picture content to the given width and height.
The picture content is resized while keeping the default size aspect ratio. The scaling factor is established for each of dimensions and the smaller value is applied to both of them.
- picture : The picture object.
- w : A new width of the image in pixels.
- h : A new height of the image in pixels.
func (Picture) SetTransform ¶
Transforms the given Tvg_Paint using the augmented transformation matrix.
The augmented matrix of the transformation is expected to be given.
- paint : The paint object to be transformed.
- m : The 3x3 augmented matrix.
func (Picture) SetVisible ¶
Sets the visibility of the Paint object.
This is useful for selectively excluding paint objects during rendering.
- paint : The paint object to set the visibility status.
- on : A boolean flag indicating visibility. The initial value is true. true, the object will be rendered by the engine. false, the object will be excluded from the drawing process.
Note: An invisible object is not considered inactive—it may still participate in internal update processing if its properties are updated, but it will not be taken into account for the final drawing output. To completely deactivate a paint object, remove it from the canvas.
see [Paint.GetVisible]
see Canvas.Remove
Since: 1.0
func (Picture) Translate ¶
Moves the given Tvg_Paint in a two-dimensional space.
The origin of the coordinate system is in the upper-left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.
- paint : The paint object to be shifted.
- x : The value of the horizontal shift.
- y : The value of the vertical shift.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Picture) Unref ¶
Decrement the reference count for the Tvg_Paint object.
This method decreases the reference count of the Tvg_Paint object by 1. If the reference count reaches zero and the free flag is set to true, the instance is automatically deleted.
- paint : The paint object to decrease the reference count.
- free : Flag indicating whether to delete the Paint instance when the reference count reaches zero.
Return: The updated reference count after the decrement.
see [Paint.Ref]
see [Paint.GetRef]
Since: 1.0
type PictureAssetResolver ¶
type Point ¶
type Point struct {
X, Y float32
// contains filtered or unexported fields
}
Point is a data structure representing a point in two-dimensional space.
type RadialGradient ¶
type RadialGradient struct {
// contains filtered or unexported fields
}
func RadialGradientNew ¶
func RadialGradientNew() RadialGradient
Creates a new radial gradient object.
Return: A new radial gradient object.
func (RadialGradient) Del ¶
func (gradient RadialGradient) Del() error
Deletes the given gradient object.
- grad : The gradient object to be deleted.
func (RadialGradient) Duplicate ¶
func (gradient RadialGradient) Duplicate() RadialGradient
Duplicate duplicates the given Tvg_Gradient object. Creates a new object and sets its all properties as in the original object.
@param[in] grad The Tvg_Gradient object to be copied. @return A copied Tvg_Gradient object if succeed, @c nullptr otherwise.
func (RadialGradient) Get ¶ added in v1.1.3
The function gets radial gradient attributes.
- grad : The Tvg_Gradient object of which to get the gradient attributes.
- cx : The horizontal coordinate of the center of the end circle.
- cy : The vertical coordinate of the center of the end circle.
- r : The radius of the end circle.
- fx : The horizontal coordinate of the center of the start circle.
- fy : The vertical coordinate of the center of the start circle.
- fr : The radius of the start circle.
func (RadialGradient) GetColorStops ¶
Gets the parameters of the colors of the gradient, their position and number
The function does not allocate any memory.
- grad : The Tvg_Gradient object of which to get the color information.
- color_stop : An array of Tvg_Color_Stop data structure.
- cnt : The size of the color_stop array equal to the colors number used in the gradient.
func (RadialGradient) GetSpread ¶
func (gradient RadialGradient) GetSpread() (StrokeFill, error)
Gets the FillSpread value of the gradient object.
- grad : The Tvg_Gradient object.
- spread : The FillSpread value.
func (RadialGradient) GetTransform ¶
Gets the matrix of the affine transformation of the gradient object.
In case no transformation was applied, the identity matrix is set.
- grad : The Tvg_Gradient object of which to get the transformation matrix.
- m : The 3x3 augmented matrix.
func (RadialGradient) GetType ¶
Gets the unique value of the gradient instance indicating the instance type.
- grad : The Tvg_Gradient object of which to get the type value.
- type : The unique type of the gradient instance type.
Since: 1.0
func (RadialGradient) Set ¶ added in v1.1.3
func (gradient RadialGradient) Set(cx float32, cy float32, r float32, fx float32, fy float32, fr float32) error
Sets the radial gradient attributes.
The radial gradient is defined by the end circle with a center (cx, cy) and a radius r and the start circle with a center/focal point (fx, fy) and a radius fr. The gradient will be rendered such that the gradient stop at an offset of 100% aligns with the edge of the end circle and the stop at an offset of 0% aligns with the edge of the start circle.
- grad : The Tvg_Gradient object of which bounds are to be set.
- cx : The horizontal coordinate of the center of the end circle.
- cy : The vertical coordinate of the center of the end circle.
- r : The radius of the end circle.
- fx : The horizontal coordinate of the center of the start circle.
- fy : The vertical coordinate of the center of the start circle.
- fr : The radius of the start circle.
Returns RESULT_INVALID_ARGUMENT : The radius r or fr value is negative.
Note: In case the radius r is zero, an object is filled with a single color using the last color specified in the specified in the tvg_gradient_set_color_stops().
Note: In case the focal point (fx and fy) lies outside the end circle, it is projected onto the edge of the end circle.
Note: If the start circle doesn't fully fit inside the end circle (after possible repositioning), the fr is reduced accordingly.
Note: By manipulating the position and size of the focal point, a wide range of visual effects can be achieved, such as directing the gradient focus towards a specific edge or enhancing the depth and complexity of shading patterns. If a focal effect is not desired, simply align the focal point (fx and fy) with the center of the end circle (cx and cy) and set the radius (fr) to zero. This will result in a uniform gradient without any focal variations.
see [GradientSetColorStops]
func (RadialGradient) SetColorStops ¶
Sets the parameters of the colors of the gradient and their position.
- grad : The Tvg_Gradient object of which the color information is to be set.
- color_stop : An array of Tvg_Color_Stop data structure.
- cnt : The size of the color_stop array equal to the colors number used in the gradient.
func (RadialGradient) SetSpread ¶
func (gradient RadialGradient) SetSpread(spread StrokeFill) error
Sets the Tvg_Stroke_Fill value, which specifies how to fill the area outside the gradient bounds.
- grad : The Tvg_Gradient object.
- spread : The FillSpread value.
func (RadialGradient) SetTransform ¶
Sets the matrix of the affine transformation for the gradient object.
The augmented matrix of the transformation is expected to be given.
- grad : The Tvg_Gradient object to be transformed.
- m : The 3x3 augmented matrix.
type Region ¶ added in v1.1.3
Region is a data structure representing an axis-aligned rectangular region.
The region is defined by its minimum and maximum x and y coordinates.
@note Experimental API
type Result ¶
type Result enum
Result is an enumeration specifying the result from the APIs.
All ThorVG APIs could potentially return one of the values in the list. Please note that some APIs may additionally specify the reasons that trigger their return values.
const ( RESULT_SUCCESS Result = iota // The value returned in case of a correct request execution. RESULT_INVALID_ARGUMENT // The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers. RESULT_INSUFFICIENT_CONDITION // The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist. RESULT_FAILED_ALLOCATION // The value returned in case of unsuccessful memory allocation. RESULT_MEMORY_CORRUPTION // The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting RESULT_NOT_SUPPORTED // The value returned in case of choosing unsupported engine features(options). RESULT_SYSTEM_ERROR // The value returned when an underlying system operation fails. @note Experimental API RESULT_UNKNOWN Result = 255 // The value returned in all other cases. )
type ResultError ¶
type ResultError struct {
// contains filtered or unexported fields
}
func (ResultError) Error ¶
func (err ResultError) Error() string
func (ResultError) Result ¶
func (err ResultError) Result() Result
type Saver ¶
type Saver uintptr
func SaverNew ¶
func SaverNew() Saver
Creates a new Tvg_Saver object.
Return: A new Tvg_Saver object.
func (Saver) SaveAnimation ¶
Exports the given animation data to the given path
If the saver module supports any compression mechanism, it will optimize the data size. This might affect the encoding/decoding time in some cases. You can turn off the compression if you wish to optimize for speed.
- saver : The Tvg_Saver object connected with the saving task.
- animation : The animation to be saved with all its associated properties.
- path : A path to the file, in which the animation data is to be saved.
- quality : The encoded quality level. 0 is the minimum, 100 is the maximum value(recommended).
- fps : The frames per second for the animation. If 0, the default fps is used.
Returns RESULT_INSUFFICIENT_CONDITION : Currently saving other resources or animation has no frames.
Returns RESULT_NOT_SUPPORTED : Trying to save a file with an unknown extension or in an unsupported format.
Returns RESULT_UNKNOWN : Unknown if attempting to save an empty paint.
Note: A higher frames per second (FPS) would result in a larger file size. It is recommended to use the default value.
Note: Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call tvg_saver_sync() afterwards.
see Saver.Sync
Since: 1.0
func (Saver) SavePaint ¶
Exports the given paint data to the given path
If the saver module supports any compression mechanism, it will optimize the data size. This might affect the encoding/decoding time in some cases. You can turn off the compression if you wish to optimize for speed.
- saver : The Tvg_Saver object connected with the saving task.
- paint : The paint to be saved with all its associated properties.
- path : A path to the file, in which the paint data is to be saved.
- quality : The encoded quality level. 0 is the minimum, 100 is the maximum value(recommended).
Returns RESULT_INSUFFICIENT_CONDITION : Currently saving other resources.
Returns RESULT_NOT_SUPPORTED : Trying to save a file with an unknown extension or in an unsupported format.
Returns RESULT_UNKNOWN : An empty paint is to be saved.
Note: Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call tvg_saver_sync() afterwards.
see Saver.Sync
func (Saver) Sync ¶
Guarantees that the saving task is finished.
The behavior of the Saver module works on a sync/async basis, depending on the threading setting of the Initializer. Thus, if you wish to have a benefit of it, you must call tvg_saver_sync() after the tvg_saver_save_paint() in the proper delayed time. Otherwise, you can call tvg_saver_sync() immediately.
- saver : The Tvg_Saver object connected with the saving task.
Returns RESULT_INSUFFICIENT_CONDITION : No saving task is running.
Note: The asynchronous tasking is dependent on the Saver module implementation.
see Saver.SavePaint
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
func SceneNew ¶
func SceneNew() Scene
Creates a new Scene object.
This function allocates and returns a new Scene instance. To properly destroy the Scene object, use [Paint.Rel]
Return: The newly created Scene object.
see [Paint.Rel]
func (Scene) Add ¶
Adds a paint object to the scene.
Appends the specified paint object to the given scene. Only paint objects added to the scene are considered rendering targets.
- scene : A handle to the scene object. This parameter must not be nullptr.
- paint : A handle to the paint object to be added to the scene. This parameter must not be nullptr.
Note: Ownership of the paint object is transferred to the canvas upon successful addition. To retain ownership, call [Paint.Ref] before adding it to the scene.
Note: The rendering order of paint objects follows their order in the root scene. If layering is required, ensure the paints are added in the desired order.
see Scene.Insert
see Scene.Remove
Since: 1.0
func (Scene) AddEffectDropShadow ¶
func (scene Scene) AddEffectDropShadow( r int, g int, b int, a int, angle float64, distance float64, sigma float64, quality int, ) error
Adds a drop shadow effect to the scene.
This function adds a drop shadow with a Gaussian blur to the scene. The shadow can be customized using color, opacity, angle, distance, blur radius (sigma), and quality parameters.
- scene : The scene object.
- r : Red channel value of the shadow color [0 - 255].
- g : Green channel value of the shadow color [0 - 255].
- b : Blue channel value of the shadow color [0 - 255].
- a : Alpha (opacity) channel value of the shadow [0 - 255].
- angle : Shadow direction in degrees [0 - 360].
- distance : Distance of the shadow from the original object.
- sigma : Gaussian blur sigma value for the shadow. Must be > 0.
- quality : Visual quality level [0 - 100].
Since: 1.0
func (Scene) AddEffectFill ¶
Adds a fill color effect to the scene.
This function overrides the scene's content colors with the specified fill color.
- scene : The scene object.
- r : Red color channel value [0 - 255].
- g : Green color channel value [0 - 255].
- b : Blue color channel value [0 - 255].
- a : Alpha (opacity) channel value [0 - 255].
Since: 1.0
func (Scene) AddEffectGaussianBlur ¶
func (scene Scene) AddEffectGaussianBlur(sigma float64, direction int, border int, quality int) error
Adds a Gaussian blur effect to the scene.
This function adds a Gaussian blur filter to the scene as a post-processing effect. The blur can be applied in different directions with configurable border handling and quality settings.
- scene : The scene object.
- sigma : The blur radius (sigma) value. Must be >= 0.
- direction : Blur direction: 0 = both directions, 1 = horizontal only, 2 = vertical only.
- border : Reserved for border handling. Currently ignored.
- quality : Visual quality level [0 - 100].
Since: 1.0
func (Scene) AddEffectMotionBlur ¶ added in v1.1.3
Adds a centered linear motion blur.
- scene : The scene to apply the effect to.
- distance : Total blur length in scene-local units. Must be >= 0.
- angle : Angle in degrees, clockwise from the positive X axis. The scene transform applies to the blur vector.
- quality : Visual quality level [0 - 100].
Note: Experimental API
func (Scene) AddEffectTint ¶
func (scene Scene) AddEffectTint( black_r int, black_g int, black_b int, white_r int, white_g int, white_b int, intensity float64, ) error
Adds a tint effect to the scene.
This function tints the current scene using specified black and white color values, modulated by a given intensity.
- scene : The scene object.
- black_r : Red component of the black color [0 - 255].
- black_g : Green component of the black color [0 - 255].
- black_b : Blue component of the black color [0 - 255].
- white_r : Red component of the white color [0 - 255].
- white_g : Green component of the white color [0 - 255].
- white_b : Blue component of the white color [0 - 255].
- intensity : Tint intensity value [0 - 100].
Since: 1.0
func (Scene) AddEffectTritone ¶
func (scene Scene) AddEffectTritone( shadow_r int, shadow_g int, shadow_b int, midtone_r int, midtone_g int, midtone_b int, highlight_r int, highlight_g int, highlight_b int, blend int, ) error
Adds a tritone color effect to the scene.
This function adds a tritone color effect to the given scene using three sets of RGB values representing shadow, midtone, and highlight colors.
- scene : The scene object.
- shadow_r : Red component of the shadow color [0 - 255].
- shadow_g : Green component of the shadow color [0 - 255].
- shadow_b : Blue component of the shadow color [0 - 255].
- midtone_r : Red component of the midtone color [0 - 255].
- midtone_g : Green component of the midtone color [0 - 255].
- midtone_b : Blue component of the midtone color [0 - 255].
- highlight_r : Red component of the highlight color [0 - 255].
- highlight_g : Green component of the highlight color [0 - 255].
- highlight_b : Blue component of the highlight color [0 - 255].
- blend : A blending factor that determines the mix between the original color and the tritone colors [0 - 255].
Since: 1.0
func (Scene) ClearEffects ¶
Clears all previously applied scene effects.
This function clears all effects that have been applied to the scene, restoring it to its original state without any post-processing.
- scene : The scene object.
Since: 1.0
func (Scene) Duplicate ¶
Duplicate duplicates a Scene.
Creates a new object and sets its all properties as in the original object.
@param[in] paint The Tvg_Paint object to be copied. @return A copied Tvg_Paint object if succeed, @c nullptr otherwise.
func (Scene) GetAABB ¶
Retrieves the axis-aligned bounding box (AABB) of the paint object in canvas space.
Returns the bounding box of the paint as an axis-aligned bounding box (AABB), with all relevant transformations applied. The returned values x, y, w, h, may have invalid if the operation fails. Thus, please check the retval. This bounding box can be used to determine the actual rendered area of the object on the canvas, for purposes such as hit-testing, culling, or layout calculations.
- paint : The paint object of which to get the bounds.
- x : The x-coordinate of the upper-left corner of the bounding box.
- y : The y-coordinate of the upper-left corner of the bounding box.
- w : The width of the bounding box.
- h : The height of the bounding box.
Returns RESULT_INSUFFICIENT_CONDITION : If it failed to compute the bounding box (mostly due to invalid path information).
see [Paint.GetObb]
see Canvas.Update
func (Scene) GetClip ¶
Get the clipper shape of the paint object.
This function returns the clipper that has been previously set to this paint object.
Return: The shape object used as the clipper, or nullptr if no clipper is set.
see [Paint.SetClip]
Since: 1.0
func (Scene) GetData ¶ added in v1.1.2
func (paint Scene) GetData() uintptr
Gets the user-defined data associated with the Paint object.
- paint : The paint object whose user-defined data will be returned.
Return: The user-defined data, or NULL if none is set or paint is invalid.
see [Paint.SetData]
Note: Experimental API
func (Scene) GetId ¶
func (paint Scene) GetId() uint32
Gets the ID of the Paint object.
- paint : The paint object whose ID will be returned.
Return: The ID of the paint object, or 0 if the ID is not set.
see Picture.GetPaint
see [Accessor.GenerateId]
see [Paint.SetId]
Since: 1.1
func (Scene) GetMaskMethod ¶
func (paint Scene) GetMaskMethod(target Paint) (MaskMethod, error)
Gets the masking target object and the masking method.
- paint : The source object of the masking.
- target : The target object of the masking.
- method : The method used to mask the source object with the target.
func (Scene) GetOBB ¶
Retrieves the object-oriented bounding box (OBB) of the paint object in canvas space.
This function returns the bounding box of the paint, as an oriented bounding box (OBB) after transformations are applied. The returned values pt4 may have invalid if the operation fails. Thus, please check the retval. This bounding box can be used to obtain the transformed bounding region in canvas space by taking the geometry's axis-aligned bounding box (AABB) in the object's local coordinate space and applying the object's transformations.
- paint : The paint object of which to get the bounds.
- pt4 : An array of four points representing the bounding box. The array size must be 4.
Returns RESULT_INSUFFICIENT_CONDITION : If it failed to compute the bounding box (mostly due to invalid path information).
see [Paint.GetAabb]
see Canvas.Update
Since: 1.0
func (Scene) GetOpacity ¶
Gets the opacity of the given Tvg_Paint.
- paint : The paint object of which to get the opacity value.
- opacity : The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
func (Scene) GetParent ¶
GetParent retrieves the parent paint object.
This function returns a pointer to the parent object if the current paint belongs to one. Otherwise, it returns @c nullptr.
@param[in] paint The Paint object of which to get the scene. @return A pointer to the parent object if available, otherwise @c nullptr. @see tvg_scene_add() @see tvg_canvas_add() @since 1.0
func (Scene) GetRef ¶
func (paint Scene) GetRef() int
Retrieve the current reference count of the Tvg_Paint object.
This method provides the current reference count, allowing the user to check the shared ownership state of the Tvg_Paint object.
- paint : The paint object to return the reference count.
Return: The current reference count of the Tvg_Paint object.
see [Paint.Ref]
see [Paint.Unref]
Since: 1.0
func (Scene) GetTransform ¶
Gets the matrix of the affine transformation of the given Tvg_Paint object.
In case no transformation was applied, the identity matrix is returned.
- paint : The paint object of which to get the transformation matrix.
- m : The 3x3 augmented matrix.
func (Scene) GetType ¶
Gets the unique value of the paint instance indicating the instance type.
- paint : The paint object of which to get the type value.
- type : The unique type of the paint instance type.
Since: 1.0
func (Scene) GetVisible ¶
func (paint Scene) GetVisible() bool
Gets the current visibility status of the Paint object.
- paint : The paint object to return the visibility status.
Return: true if the object is visible and will be rendered. false if the object is hidden and will not be rendered.
see [Paint.SetVisible]
Since: 1.0
func (Scene) Insert ¶
Inserts a paint object into the scene.
Inserts the specified paint object into the scene immediately before the given paint object at. The at parameter must reference an existing paint object already added to the scene.
- scene : A handle to the scene object. This parameter must not be nullptr.
- target : A handle to the paint object to be inserted into the scene. This parameter must not be nullptr.
- at : A handle to an existing paint object in the scene before which target will be inserted. This parameter must not be nullptr.
Note: Ownership of the target object is transferred to the scene upon successful addition. To retain ownership, call [Paint.Ref] before adding it to the scene.
Note: The rendering order of paint objects follows their order in the root scene. If layering is required, ensure the paints are added in the desired order.
see Scene.Add
see Scene.Remove
Since: 1.0
func (Scene) Intersects ¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— intersects the geometric fill region of the paint object. This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region. The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
- paint : The paint object to be tested.
- x : The x-coordinate of the top-left corner of the test region.
- y : The y-coordinate of the top-left corner of the test region.
- w : The width of the region to test. Must be greater than 0.
- h : The height of the region to test. Must be greater than 0.
Return: true if any part of the region intersects the filled area; otherwise, false.
Note: To test a single point, set the region size to w = 1, h = 1.
Note: For efficiency, an AABB (axis-aligned bounding box) test is performed internally before precise hit detection.
Note: This test does not take into account the results of blending or masking.
Note: This test does take into account hidden paints as well.
see [Paint.SetVisible] Since: 1.0
func (Scene) IntersectsRegion ¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— intersects the geometric fill region of the paint object. This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region. The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
- paint : The paint object to be tested.
- x : The x-coordinate of the top-left corner of the test region.
- y : The y-coordinate of the top-left corner of the test region.
- w : The width of the region to test. Must be greater than 0.
- h : The height of the region to test. Must be greater than 0.
- visibleOnly : If true, hidden paints are excluded from the intersection test.
Return: true if any part of the region intersects the filled area; otherwise, false.
Note: To test a single point, set the region size to w = 1, h = 1.
Note: This test does not take into account the results of blending or masking.
see [Paint.SetVisible] Since: Experimental API
func (Scene) Ref ¶
func (paint Scene) Ref() int
Increment the reference count for the Tvg_Paint object.
This method increases the reference count of Tvg_Paint object, allowing shared ownership and control over its lifetime.
- paint : The paint object to increase the reference count.
Return: The updated reference count after the increment by 1.
Warning: Please ensure that each call to tvg_paint_ref() is paired with a corresponding call to tvg_paint_unref() to prevent a dangling instance.
see [Paint.Unref]
see [Paint.GetRef]
Since: 1.0
func (Scene) Rel ¶
func (paint Scene) Rel() error
Safely releases a Tv_Paint object.
This is the counterpart to the `new()` API, and releases the given Paint object safely, handling nullptr and managing ownership properly.
- paint : A paint object to release.
func (Scene) Remove ¶
Removes a paint object from the scene.
This function removes a specified paint object from the scene. If no paint object is specified (i.e., the default nullptr is used), the function performs to clear all paints from the scene.
- scene : The scene object.
- paint : The paint object to be removed from the scene. If nullptr, remove all the paints from the scene.
see Scene.Add Since: 1.0
func (Scene) Rotate ¶
Rotates the given Tvg_Paint by the given angle.
The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.
- paint : The paint object to be rotated.
- degree : The value of the rotation angle in degrees.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Scene) Scale ¶
Scales the given Tvg_Paint object by the given factor.
- paint : The paint object to be scaled.
- factor : The value of the scaling factor. The initial value is 1.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Scene) SetBlendMethod ¶
func (paint Scene) SetBlendMethod(method BlendMethod) error
Sets the blending method for the paint object.
The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. The blending operation is determined by the chosen BlendMethod, which specifies how the colors or images are combined.
- paint : The paint object of which to set the blend method.
- method : The blending method to be set.
Since: 0.15
func (Scene) SetClip ¶
Clip the drawing region of the paint object.
This function restricts the drawing area of the paint object to the specified shape's paths.
- paint : The target object of the clipping.
- clipper : The shape object as the clipper.
Returns RESULT_INSUFFICIENT_CONDITION : if the target has already belonged to another paint.
Returns RESULT_NOT_SUPPORTED : If the clipper type is not Shape.
see [Paint.GetClip]
Since: 1.0
func (Scene) SetData ¶ added in v1.1.2
Associates user-defined data with the Paint object.
ThorVG does not interpret or manage the lifetime of this data.
- paint : The paint object whose user-defined data will be set.
- data : The user-defined data to associate with the paint object.
see [Paint.GetData]
Note: Experimental API
func (Scene) SetId ¶
Sets the ID of the Paint object.
The ID is used to specify a paint instance in a scene.
- paint : The paint object whose ID will be set.
- id : The ID to assign to the paint object.
see Picture.GetPaint
see [Accessor.GenerateId]
see [Paint.GetId]
Since: 1.1
func (Scene) SetMaskMethod ¶
func (paint Scene) SetMaskMethod(target Paint, method MaskMethod) error
Sets the masking target object and the masking method.
- paint : The source object of the masking.
- target : The target object of the masking.
- method : The method used to mask the source object with the target.
Returns RESULT_INSUFFICIENT_CONDITION : if the target has already belonged to another paint.
func (Scene) SetOpacity ¶
Sets the opacity of the given Tvg_Paint.
- paint : The paint object of which the opacity value is to be set.
- opacity : The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
Note: Setting the opacity with this API may require multiple renderings using a composition. It is recommended to avoid changing the opacity if possible.
func (Scene) SetTransform ¶
Transforms the given Tvg_Paint using the augmented transformation matrix.
The augmented matrix of the transformation is expected to be given.
- paint : The paint object to be transformed.
- m : The 3x3 augmented matrix.
func (Scene) SetVisible ¶
Sets the visibility of the Paint object.
This is useful for selectively excluding paint objects during rendering.
- paint : The paint object to set the visibility status.
- on : A boolean flag indicating visibility. The initial value is true. true, the object will be rendered by the engine. false, the object will be excluded from the drawing process.
Note: An invisible object is not considered inactive—it may still participate in internal update processing if its properties are updated, but it will not be taken into account for the final drawing output. To completely deactivate a paint object, remove it from the canvas.
see [Paint.GetVisible]
see Canvas.Remove
Since: 1.0
func (Scene) Translate ¶
Moves the given Tvg_Paint in a two-dimensional space.
The origin of the coordinate system is in the upper-left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.
- paint : The paint object to be shifted.
- x : The value of the horizontal shift.
- y : The value of the vertical shift.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Scene) Unref ¶
Decrement the reference count for the Tvg_Paint object.
This method decreases the reference count of the Tvg_Paint object by 1. If the reference count reaches zero and the free flag is set to true, the instance is automatically deleted.
- paint : The paint object to decrease the reference count.
- free : Flag indicating whether to delete the Paint instance when the reference count reaches zero.
Return: The updated reference count after the decrement.
see [Paint.Ref]
see [Paint.GetRef]
Since: 1.0
type Shape ¶
type Shape struct {
// contains filtered or unexported fields
}
func ShapeNew ¶
func ShapeNew() Shape
Creates a new Shape object.
This function allocates and returns a new Shape instance. To properly destroy the Shape object, use [Paint.Rel]
Return: The newly created Shape object.
see [Paint.Rel]
func (Shape) AppendCircle ¶
Appends an ellipse to the path.
The position of the ellipse is specified by the coordinates of its center - cx and cy arguments. The ellipse is treated as a new sub-path - it is not connected with the previous sub-path. The value of the current point is set to (cx, cy - ry).
- paint : The shape object.
- cx : The horizontal coordinate of the center of the ellipse.
- cy : The vertical coordinate of the center of the ellipse.
- rx : The x-axis radius of the ellipse.
- ry : The y-axis radius of the ellipse.
- cw : Specifies the path direction: true for clockwise, false for counterclockwise.
func (Shape) AppendPath ¶
func (shape Shape) AppendPath(cmds []PathCommand, pts []Point) error
Appends a given sub-path to the path.
The current point value is set to the last point from the sub-path. For each command from the cmds array, an appropriate number of points in pts array should be specified. If the number of points in the pts array is different than the number required by the cmds array, the shape with this sub-path will not be displayed on the screen.
- paint : The shape object.
- cmds : The array of the commands in the sub-path.
- cmdCnt : The length of the cmds array.
- pts : The array of the two-dimensional points.
- ptsCnt : The length of the pts array.
Returns RESULT_INVALID_ARGUMENT : A nullptr passed as the argument or cmdCnt or ptsCnt equal to zero.
func (Shape) AppendRect ¶
func (shape Shape) AppendRect(x float32, y float32, w float32, h float32, rx float32, ry float32, cw bool) error
Appends a rectangle to the path.
The rectangle with rounded corners can be achieved by setting non-zero values to rx and ry arguments. The rx and ry values specify the radii of the ellipse defining the rounding of the corners. The position of the rectangle is specified by the coordinates of its upper-left corner - x and y arguments. The rectangle is treated as a new sub-path - it is not connected with the previous sub-path. The value of the current point is set to (x + w, y + ry) - in case ry is greater than h/2 the current point is set to (x + w, y + h/2).
- paint : The shape object.
- x : The horizontal coordinate of the upper-left corner of the rectangle.
- y : The vertical coordinate of the upper-left corner of the rectangle.
- w : The width of the rectangle.
- h : The height of the rectangle.
- rx : The x-axis radius of the ellipse defining the rounded corners of the rectangle.
- ry : The y-axis radius of the ellipse defining the rounded corners of the rectangle.
- cw : Specifies the path direction: true for clockwise, false for counterclockwise.
Note: For rx and ry greater than or equal to the half of w and the half of h, respectively, the shape become an ellipse.
func (Shape) Close ¶
Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path.
The value of the current point is set to the initial point of the closed sub-path.
- paint : The shape object.
Note: In case the sub-path does not contain any points, this function has no effect.
func (Shape) CubicTo ¶
func (shape Shape) CubicTo(cx1 float32, cy1 float32, cx2 float32, cy2 float32, x float32, y float32) error
Adds new points to the sub-path, which results in drawing a cubic Bezier curve.
The Bezier curve starts at the current point and ends at the given end-point (x, y). Two control points (cx1, cy1) and (cx2, cy2) are used to determine the shape of the curve. The value of the current point is set to the given end-point.
- paint : The shape object.
- cx1 : The horizontal coordinate of the 1st control point.
- cy1 : The vertical coordinate of the 1st control point.
- cx2 : The horizontal coordinate of the 2nd control point.
- cy2 : The vertical coordinate of the 2nd control point.
- x : The horizontal coordinate of the endpoint of the curve.
- y : The vertical coordinate of the endpoint of the curve.
Note: In case this is the first command in the path, no data from the path are rendered.
func (Shape) Duplicate ¶
Duplicate duplicates a Shape.
Creates a new object and sets its all properties as in the original object.
@param[in] paint The Tvg_Paint object to be copied. @return A copied Tvg_Paint object if succeed, @c nullptr otherwise.
func (Shape) GetAABB ¶
Retrieves the axis-aligned bounding box (AABB) of the paint object in canvas space.
Returns the bounding box of the paint as an axis-aligned bounding box (AABB), with all relevant transformations applied. The returned values x, y, w, h, may have invalid if the operation fails. Thus, please check the retval. This bounding box can be used to determine the actual rendered area of the object on the canvas, for purposes such as hit-testing, culling, or layout calculations.
- paint : The paint object of which to get the bounds.
- x : The x-coordinate of the upper-left corner of the bounding box.
- y : The y-coordinate of the upper-left corner of the bounding box.
- w : The width of the bounding box.
- h : The height of the bounding box.
Returns RESULT_INSUFFICIENT_CONDITION : If it failed to compute the bounding box (mostly due to invalid path information).
see [Paint.GetObb]
see Canvas.Update
func (Shape) GetClip ¶
Get the clipper shape of the paint object.
This function returns the clipper that has been previously set to this paint object.
Return: The shape object used as the clipper, or nullptr if no clipper is set.
see [Paint.SetClip]
Since: 1.0
func (Shape) GetData ¶ added in v1.1.2
func (paint Shape) GetData() uintptr
Gets the user-defined data associated with the Paint object.
- paint : The paint object whose user-defined data will be returned.
Return: The user-defined data, or NULL if none is set or paint is invalid.
see [Paint.SetData]
Note: Experimental API
func (Shape) GetFillColor ¶
Gets the shape's solid color.
- paint : The shape object.
- r : The red color channel value in the range [0 ~ 255].
- g : The green color channel value in the range [0 ~ 255].
- b : The blue color channel value in the range [0 ~ 255].
- a : The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
func (Shape) GetFillRule ¶
Retrieves the current fill rule used by the shape.
This function returns the fill rule, which determines how the interior regions of the shape are calculated when it overlaps itself.
- paint : The shape object.
- rule : The current Tvg_Fill_Rule value of the shape.
func (Shape) GetGradient ¶
Gets the gradient fill of the shape.
The function does not allocate any data.
- paint : The shape object.
- grad : The gradient fill.
func (Shape) GetId ¶
func (paint Shape) GetId() uint32
Gets the ID of the Paint object.
- paint : The paint object whose ID will be returned.
Return: The ID of the paint object, or 0 if the ID is not set.
see Picture.GetPaint
see [Accessor.GenerateId]
see [Paint.SetId]
Since: 1.1
func (Shape) GetMaskMethod ¶
func (paint Shape) GetMaskMethod(target Paint) (MaskMethod, error)
Gets the masking target object and the masking method.
- paint : The source object of the masking.
- target : The target object of the masking.
- method : The method used to mask the source object with the target.
func (Shape) GetOBB ¶
Retrieves the object-oriented bounding box (OBB) of the paint object in canvas space.
This function returns the bounding box of the paint, as an oriented bounding box (OBB) after transformations are applied. The returned values pt4 may have invalid if the operation fails. Thus, please check the retval. This bounding box can be used to obtain the transformed bounding region in canvas space by taking the geometry's axis-aligned bounding box (AABB) in the object's local coordinate space and applying the object's transformations.
- paint : The paint object of which to get the bounds.
- pt4 : An array of four points representing the bounding box. The array size must be 4.
Returns RESULT_INSUFFICIENT_CONDITION : If it failed to compute the bounding box (mostly due to invalid path information).
see [Paint.GetAabb]
see Canvas.Update
Since: 1.0
func (Shape) GetOpacity ¶
Gets the opacity of the given Tvg_Paint.
- paint : The paint object of which to get the opacity value.
- opacity : The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
func (Shape) GetParent ¶
GetParent retrieves the parent paint object.
This function returns a pointer to the parent object if the current paint belongs to one. Otherwise, it returns @c nullptr.
@param[in] paint The Paint object of which to get the scene. @return A pointer to the parent object if available, otherwise @c nullptr. @see tvg_scene_add() @see tvg_canvas_add() @since 1.0
func (Shape) GetPath ¶
func (shape Shape) GetPath() ([]PathCommand, []Point, error)
Retrieves the current path data of the shape.
This function provides access to the shape's path data, including the commands and points that define the path.
- cmds : Pointer to the array of commands representing the path. Can be nullptr if this information is not needed.
- cmdsCnt : Pointer to the variable that receives the number of commands in the cmds array. Can be nullptr if this information is not needed.
- pts : Pointer to the array of two-dimensional points that define the path. Can be nullptr if this information is not needed.
- ptsCnt : Pointer to the variable that receives the number of points in the pts array. Can be nullptr if this information is not needed.
Note: If any of the arguments are nullptr, that value will be ignored.
func (Shape) GetRef ¶
func (paint Shape) GetRef() int
Retrieve the current reference count of the Tvg_Paint object.
This method provides the current reference count, allowing the user to check the shared ownership state of the Tvg_Paint object.
- paint : The paint object to return the reference count.
Return: The current reference count of the Tvg_Paint object.
see [Paint.Ref]
see [Paint.Unref]
Since: 1.0
func (Shape) GetStrokeCap ¶
Gets the stroke cap style used for stroking the path.
- paint : The shape object.
- cap : The cap style value.
func (Shape) GetStrokeColor ¶
Gets the shape's stroke color.
- paint : The shape object.
- r : The red color channel value in the range [0 ~ 255].
- g : The green color channel value in the range [0 ~ 255].
- b : The blue color channel value in the range [0 ~ 255].
- a : The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
Returns RESULT_INSUFFICIENT_CONDITION : No stroke was set.
func (Shape) GetStrokeDash ¶
Gets the dash pattern of the stroke.
The function does not allocate any memory.
- paint : The shape object.
- dashPattern : The array of consecutive pair values of the dash length and the gap length.
- cnt : The size of the dashPattern array.
- offset : The shift of the starting point within the repeating dash pattern.
Since: 1.0
func (Shape) GetStrokeGradient ¶
Gets the gradient fill of the shape's stroke.
The function does not allocate any memory.
- paint : The shape object.
- grad : The gradient fill.
func (Shape) GetStrokeJoin ¶
func (shape Shape) GetStrokeJoin() (StrokeJoin, error)
The function gets the stroke join method
- paint : The shape object.
- join : The join style value.
func (Shape) GetStrokeMiterlimit ¶
The function gets the stroke miterlimit.
- paint : The shape object.
- miterlimit : The stroke miterlimit.
Since: 0.11
func (Shape) GetStrokeWidth ¶
Gets the shape's stroke width.
- paint : The shape object.
- width : The stroke width.
func (Shape) GetTransform ¶
Gets the matrix of the affine transformation of the given Tvg_Paint object.
In case no transformation was applied, the identity matrix is returned.
- paint : The paint object of which to get the transformation matrix.
- m : The 3x3 augmented matrix.
func (Shape) GetType ¶
Gets the unique value of the paint instance indicating the instance type.
- paint : The paint object of which to get the type value.
- type : The unique type of the paint instance type.
Since: 1.0
func (Shape) GetVisible ¶
func (paint Shape) GetVisible() bool
Gets the current visibility status of the Paint object.
- paint : The paint object to return the visibility status.
Return: true if the object is visible and will be rendered. false if the object is hidden and will not be rendered.
see [Paint.SetVisible]
Since: 1.0
func (Shape) Intersects ¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— intersects the geometric fill region of the paint object. This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region. The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
- paint : The paint object to be tested.
- x : The x-coordinate of the top-left corner of the test region.
- y : The y-coordinate of the top-left corner of the test region.
- w : The width of the region to test. Must be greater than 0.
- h : The height of the region to test. Must be greater than 0.
Return: true if any part of the region intersects the filled area; otherwise, false.
Note: To test a single point, set the region size to w = 1, h = 1.
Note: For efficiency, an AABB (axis-aligned bounding box) test is performed internally before precise hit detection.
Note: This test does not take into account the results of blending or masking.
Note: This test does take into account hidden paints as well.
see [Paint.SetVisible] Since: 1.0
func (Shape) IntersectsRegion ¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— intersects the geometric fill region of the paint object. This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region. The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
- paint : The paint object to be tested.
- x : The x-coordinate of the top-left corner of the test region.
- y : The y-coordinate of the top-left corner of the test region.
- w : The width of the region to test. Must be greater than 0.
- h : The height of the region to test. Must be greater than 0.
- visibleOnly : If true, hidden paints are excluded from the intersection test.
Return: true if any part of the region intersects the filled area; otherwise, false.
Note: To test a single point, set the region size to w = 1, h = 1.
Note: This test does not take into account the results of blending or masking.
see [Paint.SetVisible] Since: Experimental API
func (Shape) LineTo ¶
Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point.
The value of the current point is set to the given end-point.
- paint : The shape object.
- x : The horizontal coordinate of the end-point of the line.
- y : The vertical coordinate of the end-point of the line.
Note: In case this is the first command in the path, it corresponds to the tvg_shape_move_to() call.
func (Shape) MoveTo ¶
Sets the initial point of the sub-path.
The value of the current point is set to the given point.
- paint : The shape object.
- x : The horizontal coordinate of the initial point of the sub-path.
- y : The vertical coordinate of the initial point of the sub-path.
func (Shape) Ref ¶
func (paint Shape) Ref() int
Increment the reference count for the Tvg_Paint object.
This method increases the reference count of Tvg_Paint object, allowing shared ownership and control over its lifetime.
- paint : The paint object to increase the reference count.
Return: The updated reference count after the increment by 1.
Warning: Please ensure that each call to tvg_paint_ref() is paired with a corresponding call to tvg_paint_unref() to prevent a dangling instance.
see [Paint.Unref]
see [Paint.GetRef]
Since: 1.0
func (Shape) Rel ¶
func (paint Shape) Rel() error
Safely releases a Tv_Paint object.
This is the counterpart to the `new()` API, and releases the given Paint object safely, handling nullptr and managing ownership properly.
- paint : A paint object to release.
func (Shape) Reset ¶
Resets the shape path properties.
The color, the fill and the stroke properties are retained.
- paint : The shape object.
Note: The memory, where the path data is stored, is not deallocated at this stage for caching effect.
func (Shape) Rotate ¶
Rotates the given Tvg_Paint by the given angle.
The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.
- paint : The paint object to be rotated.
- degree : The value of the rotation angle in degrees.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Shape) Scale ¶
Scales the given Tvg_Paint object by the given factor.
- paint : The paint object to be scaled.
- factor : The value of the scaling factor. The initial value is 1.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Shape) SetBlendMethod ¶
func (paint Shape) SetBlendMethod(method BlendMethod) error
Sets the blending method for the paint object.
The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. The blending operation is determined by the chosen BlendMethod, which specifies how the colors or images are combined.
- paint : The paint object of which to set the blend method.
- method : The blending method to be set.
Since: 0.15
func (Shape) SetClip ¶
Clip the drawing region of the paint object.
This function restricts the drawing area of the paint object to the specified shape's paths.
- paint : The target object of the clipping.
- clipper : The shape object as the clipper.
Returns RESULT_INSUFFICIENT_CONDITION : if the target has already belonged to another paint.
Returns RESULT_NOT_SUPPORTED : If the clipper type is not Shape.
see [Paint.GetClip]
Since: 1.0
func (Shape) SetData ¶ added in v1.1.2
Associates user-defined data with the Paint object.
ThorVG does not interpret or manage the lifetime of this data.
- paint : The paint object whose user-defined data will be set.
- data : The user-defined data to associate with the paint object.
see [Paint.GetData]
Note: Experimental API
func (Shape) SetFillColor ¶
Sets the shape's solid color.
The parts of the shape defined as inner are colored.
- paint : The shape object.
- r : The red color channel value in the range [0 ~ 255]. The initial value is 0.
- g : The green color channel value in the range [0 ~ 255]. The initial value is 0.
- b : The blue color channel value in the range [0 ~ 255]. The initial value is 0.
- a : The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The initial value is 0.
Note: Either a solid color or a gradient fill is applied, depending on what was set as last.
func (Shape) SetFillRule ¶
Sets the fill rule for the shape.
Specifies how the interior of the shape is determined when its path intersects itself. The initial fill rule is TVG_FILL_RULE_NON_ZERO.
- paint : The shape object.
- rule : The fill rule to apply to the shape.
func (Shape) SetGradient ¶
Sets the gradient fill for all of the figures from the path.
The parts of the shape defined as inner are filled.
- paint : The shape object.
- grad : The gradient fill.
Note: Either a solid color or a gradient fill is applied, depending on what was set as last.
func (Shape) SetId ¶
Sets the ID of the Paint object.
The ID is used to specify a paint instance in a scene.
- paint : The paint object whose ID will be set.
- id : The ID to assign to the paint object.
see Picture.GetPaint
see [Accessor.GenerateId]
see [Paint.GetId]
Since: 1.1
func (Shape) SetMaskMethod ¶
func (paint Shape) SetMaskMethod(target Paint, method MaskMethod) error
Sets the masking target object and the masking method.
- paint : The source object of the masking.
- target : The target object of the masking.
- method : The method used to mask the source object with the target.
Returns RESULT_INSUFFICIENT_CONDITION : if the target has already belonged to another paint.
func (Shape) SetOpacity ¶
Sets the opacity of the given Tvg_Paint.
- paint : The paint object of which the opacity value is to be set.
- opacity : The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
Note: Setting the opacity with this API may require multiple renderings using a composition. It is recommended to avoid changing the opacity if possible.
func (Shape) SetPaintOrder ¶
Sets the rendering order of the stroke and the fill.
- paint : The shape object.
- strokeFirst : If true the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the initial option).
Since: 0.10
func (Shape) SetStrokeCap ¶
Sets the cap style used for stroking the path.
The cap style specifies the shape to be used at the end of the open stroked sub-paths.
- paint : The shape object.
- cap : The cap style value. The initial value is TVG_STROKE_CAP_SQUARE.
func (Shape) SetStrokeColor ¶
Sets the shape's stroke color.
- paint : The shape object.
- r : The red color channel value in the range [0 ~ 255]. The initial value is 0.
- g : The green color channel value in the range [0 ~ 255]. The initial value is 0.
- b : The blue color channel value in the range [0 ~ 255]. The initial value is 0.
- a : The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The initial value is 0.
Note: If the stroke width is 0 (initial value), the stroke will not be visible regardless of the color.
Note: Either a solid color or a gradient fill is applied, depending on what was set as last.
func (Shape) SetStrokeDash ¶
Sets the shape's stroke dash pattern.
- paint : The shape object.
- dashPattern : An array of alternating dash and gap lengths.
- cnt : The size of the dashPattern array.
- offset : The shift of the starting point within the repeating dash pattern, from which the pattern begins to be applied.
Returns RESULT_INVALID_ARGUMENT : In case dashPattern is nullptr and cnt > 0 or dashPattern is not nullptr and cnt is zero.
Note: To reset the stroke dash pattern, pass nullptr to dashPattern and zero to cnt.
Note: Values of dashPattern less than zero are treated as zero.
Note: If all values in the dashPattern are equal to or less than 0, the dash is ignored.
Note: If the dashPattern contains an odd number of elements, the sequence is repeated in the same order to form an even-length pattern, preserving the alternation of dashes and gaps. Since: 1.0
func (Shape) SetStrokeGradient ¶
Sets the gradient fill of the stroke for all of the figures from the path.
- paint : The shape object.
- grad : The gradient fill.
Returns RESULT_MEMORY_CORRUPTION : An invalid gradient object or an error with accessing it.
Note: Either a solid color or a gradient fill is applied, depending on what was set as last.
func (Shape) SetStrokeJoin ¶
func (shape Shape) SetStrokeJoin(join StrokeJoin) error
Sets the join style for stroked path segments.
- paint : The shape object.
- join : The join style value. The initial value is TVG_STROKE_JOIN_BEVEL.
func (Shape) SetStrokeMiterlimit ¶
Sets the stroke miterlimit.
- paint : The shape object.
- miterlimit : The miterlimit imposes a limit on the extent of the stroke join when the TVG_STROKE_JOIN_MITER join style is set. The initial value is 4.
Returns RESULT_INVALID_ARGUMENT : Unsupported miterlimit values (less than zero).
Since: 0.11
func (Shape) SetStrokeWidth ¶
Sets the stroke width for the path.
This function defines the thickness of the stroke applied to all figures in the path object. A stroke is the outline drawn along the edges of the path's geometry.
- paint : The shape object.
- width : The width of the stroke in pixels. Must be positive value. (The initial value is 0)
Note: A value of width 0 disables the stroke.
func (Shape) SetTransform ¶
Transforms the given Tvg_Paint using the augmented transformation matrix.
The augmented matrix of the transformation is expected to be given.
- paint : The paint object to be transformed.
- m : The 3x3 augmented matrix.
func (Shape) SetTrimpath ¶
Sets the trim of the shape along the defined path segment, allowing control over which part of the shape is visible.
If the values of the arguments begin and end exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular.
- paint : The shape object.
- begin : Specifies the start of the segment to display along the path.
- end : Specifies the end of the segment to display along the path.
- simultaneous : Determines how to trim multiple paths within a single shape. If set to true (default), trimming is applied simultaneously to all paths; Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such.
Since: 1.0
func (Shape) SetVisible ¶
Sets the visibility of the Paint object.
This is useful for selectively excluding paint objects during rendering.
- paint : The paint object to set the visibility status.
- on : A boolean flag indicating visibility. The initial value is true. true, the object will be rendered by the engine. false, the object will be excluded from the drawing process.
Note: An invisible object is not considered inactive—it may still participate in internal update processing if its properties are updated, but it will not be taken into account for the final drawing output. To completely deactivate a paint object, remove it from the canvas.
see [Paint.GetVisible]
see Canvas.Remove
Since: 1.0
func (Shape) Translate ¶
Moves the given Tvg_Paint in a two-dimensional space.
The origin of the coordinate system is in the upper-left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.
- paint : The paint object to be shifted.
- x : The value of the horizontal shift.
- y : The value of the vertical shift.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Shape) Unref ¶
Decrement the reference count for the Tvg_Paint object.
This method decreases the reference count of the Tvg_Paint object by 1. If the reference count reaches zero and the free flag is set to true, the instance is automatically deleted.
- paint : The paint object to decrease the reference count.
- free : Flag indicating whether to delete the Paint instance when the reference count reaches zero.
Return: The updated reference count after the decrement.
see [Paint.Ref]
see [Paint.GetRef]
Since: 1.0
type StrokeCap ¶
type StrokeCap enum
StrokeCap is an enumeration determining the ending type of a stroke in the open sub-paths.
const ( STROKE_CAP_BUTT StrokeCap = iota // The stroke ends exactly at each of the two endpoints of a sub-path. For zero length sub-paths no stroke is rendered. STROKE_CAP_ROUND // The stroke is extended in both endpoints of a sub-path by a half circle, with a radius equal to the half of a stroke width. For zero length sub-paths a full circle is rendered. STROKE_CAP_SQUARE // The stroke is extended in both endpoints of a sub-path by a rectangle, with the width equal to the stroke width and the length equal to the half of the stroke width. For zero length sub-paths the square is rendered with the size of the stroke width. )
const ( STROKE_JOIN_MITER StrokeCap = iota // The outer corner of the joined path segments is spiked. The spike is created by extension beyond the join point of the outer edges of the stroke until they intersect. In case the extension goes beyond the limit, the join style is converted to the Bevel style. STROKE_JOIN_ROUND // The outer corner of the joined path segments is rounded. The circular region is centered at the join point. STROKE_JOIN_BEVEL // The outer corner of the joined path segments is bevelled at the join point. The triangular region of the corner is enclosed by a straight line between the outer corners of each stroke. )
type StrokeFill ¶
type StrokeFill enum
StrokeFill is an enumeration specifying how to fill the area outside the gradient bounds.
const ( STROKE_FILL_PAD StrokeFill = iota // The remaining area is filled with the closest stop color. STROKE_FILL_REFLECT // The gradient pattern is reflected outside the gradient area until the expected region is filled. STROKE_FILL_REPEAT // The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled. )
type StrokeJoin ¶
type StrokeJoin enum
StrokeJoin is an enumeration specifying how to fill the area outside the gradient bounds.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
func TextNew ¶
func TextNew() Text
Creates a new Text object.
This function allocates and returns a new Text instance. To properly destroy the Text object, use [Paint.Rel]
Return: The newly created Text object.
see [Paint.Rel]
Since: 0.15
func (Text) Align ¶
Sets text alignment or anchor per axis.
If layout width/height is set on an axis, align within the layout box. Otherwise, treat it as an anchor within the text bounds which point of the text box is pinned to the paint position.
- text : The text object.
- x : Horizontal alignment/anchor in [0..1]: 0=left/start, 0.5=center, 1=right/end. (The initial value is 0)
- y : Vertical alignment/anchor in [0..1]: 0=top, 0.5=middle, 1=bottom. (The initial value is 0)
Since: 1.0
see Text.Layout
func (Text) Duplicate ¶
Duplicate duplicates a Text.
Creates a new object and sets its all properties as in the original object.
@param[in] paint The Tvg_Paint object to be copied. @return A copied Tvg_Paint object if succeed, @c nullptr otherwise.
func (Text) GetAABB ¶
Retrieves the axis-aligned bounding box (AABB) of the paint object in canvas space.
Returns the bounding box of the paint as an axis-aligned bounding box (AABB), with all relevant transformations applied. The returned values x, y, w, h, may have invalid if the operation fails. Thus, please check the retval. This bounding box can be used to determine the actual rendered area of the object on the canvas, for purposes such as hit-testing, culling, or layout calculations.
- paint : The paint object of which to get the bounds.
- x : The x-coordinate of the upper-left corner of the bounding box.
- y : The y-coordinate of the upper-left corner of the bounding box.
- w : The width of the bounding box.
- h : The height of the bounding box.
Returns RESULT_INSUFFICIENT_CONDITION : If it failed to compute the bounding box (mostly due to invalid path information).
see [Paint.GetObb]
see Canvas.Update
func (Text) GetClip ¶
Get the clipper shape of the paint object.
This function returns the clipper that has been previously set to this paint object.
Return: The shape object used as the clipper, or nullptr if no clipper is set.
see [Paint.SetClip]
Since: 1.0
func (Text) GetData ¶ added in v1.1.2
func (paint Text) GetData() uintptr
Gets the user-defined data associated with the Paint object.
- paint : The paint object whose user-defined data will be returned.
Return: The user-defined data, or NULL if none is set or paint is invalid.
see [Paint.SetData]
Note: Experimental API
func (Text) GetGlyphMetrics ¶
func (text Text) GetGlyphMetrics(ch rune) (GlyphMetrics, error)
Retrieves the layout metrics of a glyph in the text object.
Fills the provided Tvg_Glyph_Metrics structure with the horizontal layout values of the specified glyph, such as advance, left-side bearing, and bounding box. The returned values reflect the font size applied to the text object, but do not include any transformations (e.g., scale, rotation, or translation). The input character must be a single UTF-8 encoded character.
- text : The text object.
- ch : A pointer to a UTF-8 encoded character.
- metrics : A pointer to a Tvg_Glyph_Metrics structure to be filled with the resulting values.
- next : An optional pointer that receives the position immediately following the processed UTF-8 character.
Return: TVG_RESULT_INSUFFICIENT_CONDITION if no font or size has been set yet.
Return: TVG_RESULT_INVALID_ARGUMENT if the character or its glyph data is invalid.
see Tvg_Glyph_Metrics
Note: Currently, ThorVG only supports horizontal text layout.
Note: Experimental API
func (Text) GetId ¶
func (paint Text) GetId() uint32
Gets the ID of the Paint object.
- paint : The paint object whose ID will be returned.
Return: The ID of the paint object, or 0 if the ID is not set.
see Picture.GetPaint
see [Accessor.GenerateId]
see [Paint.SetId]
Since: 1.1
func (Text) GetLength ¶ added in v1.1.4
Retrieves the number of glyphs in the laid-out text.
- text : The text object.
Return: The number of output glyphs, or zero if text is NULL or text layout is unavailable.
Note: Each displayed Unicode codepoint counts as one glyph, including spaces and missing glyphs. Line breaks and characters omitted by ellipsis are excluded. Dots added for ellipsis are included.
see [Text.GetText]
Note: Experimental API
func (Text) GetMaskMethod ¶
func (paint Text) GetMaskMethod(target Paint) (MaskMethod, error)
Gets the masking target object and the masking method.
- paint : The source object of the masking.
- target : The target object of the masking.
- method : The method used to mask the source object with the target.
func (Text) GetOBB ¶
Retrieves the object-oriented bounding box (OBB) of the paint object in canvas space.
This function returns the bounding box of the paint, as an oriented bounding box (OBB) after transformations are applied. The returned values pt4 may have invalid if the operation fails. Thus, please check the retval. This bounding box can be used to obtain the transformed bounding region in canvas space by taking the geometry's axis-aligned bounding box (AABB) in the object's local coordinate space and applying the object's transformations.
- paint : The paint object of which to get the bounds.
- pt4 : An array of four points representing the bounding box. The array size must be 4.
Returns RESULT_INSUFFICIENT_CONDITION : If it failed to compute the bounding box (mostly due to invalid path information).
see [Paint.GetAabb]
see Canvas.Update
Since: 1.0
func (Text) GetOpacity ¶
Gets the opacity of the given Tvg_Paint.
- paint : The paint object of which to get the opacity value.
- opacity : The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
func (Text) GetParent ¶
GetParent retrieves the parent paint object.
This function returns a pointer to the parent object if the current paint belongs to one. Otherwise, it returns @c nullptr.
@param[in] paint The Paint object of which to get the scene. @return A pointer to the parent object if available, otherwise @c nullptr. @see tvg_scene_add() @see tvg_canvas_add() @since 1.0
func (Text) GetRef ¶
func (paint Text) GetRef() int
Retrieve the current reference count of the Tvg_Paint object.
This method provides the current reference count, allowing the user to check the shared ownership state of the Tvg_Paint object.
- paint : The paint object to return the reference count.
Return: The current reference count of the Tvg_Paint object.
see [Paint.Ref]
see [Paint.Unref]
Since: 1.0
func (Text) GetTextMetrics ¶
func (text Text) GetTextMetrics() (TextMetrics, error)
Retrieves the layout metrics of the text object.
Fills the provided Tvg_Text_Metrics structure with the font layout values of this text object, such as ascent, descent, linegap, and line advance. The returned values reflect the font size applied to the text object, but do not include any transformations (e.g., scale, rotation, or translation).
- text : The text object.
- metrics : A pointer to a Tvg_Text_Metrics structure to be filled with the resulting values.
Return: TVG_RESULT_INSUFFICIENT_CONDITION if no font or size has been set yet.
see Tvg_Text_Metrics
Note: Experimental API
func (Text) GetTransform ¶
Gets the matrix of the affine transformation of the given Tvg_Paint object.
In case no transformation was applied, the identity matrix is returned.
- paint : The paint object of which to get the transformation matrix.
- m : The 3x3 augmented matrix.
func (Text) GetType ¶
Gets the unique value of the paint instance indicating the instance type.
- paint : The paint object of which to get the type value.
- type : The unique type of the paint instance type.
Since: 1.0
func (Text) GetVisible ¶
func (paint Text) GetVisible() bool
Gets the current visibility status of the Paint object.
- paint : The paint object to return the visibility status.
Return: true if the object is visible and will be rendered. false if the object is hidden and will not be rendered.
see [Paint.SetVisible]
Since: 1.0
func (Text) Intersects ¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— intersects the geometric fill region of the paint object. This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region. The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
- paint : The paint object to be tested.
- x : The x-coordinate of the top-left corner of the test region.
- y : The y-coordinate of the top-left corner of the test region.
- w : The width of the region to test. Must be greater than 0.
- h : The height of the region to test. Must be greater than 0.
Return: true if any part of the region intersects the filled area; otherwise, false.
Note: To test a single point, set the region size to w = 1, h = 1.
Note: For efficiency, an AABB (axis-aligned bounding box) test is performed internally before precise hit detection.
Note: This test does not take into account the results of blending or masking.
Note: This test does take into account hidden paints as well.
see [Paint.SetVisible] Since: 1.0
func (Text) IntersectsRegion ¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (`x`, `y`, `w`, `h`)— intersects the geometric fill region of the paint object. This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region. The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
- paint : The paint object to be tested.
- x : The x-coordinate of the top-left corner of the test region.
- y : The y-coordinate of the top-left corner of the test region.
- w : The width of the region to test. Must be greater than 0.
- h : The height of the region to test. Must be greater than 0.
- visibleOnly : If true, hidden paints are excluded from the intersection test.
Return: true if any part of the region intersects the filled area; otherwise, false.
Note: To test a single point, set the region size to w = 1, h = 1.
Note: This test does not take into account the results of blending or masking.
see [Paint.SetVisible] Since: Experimental API
func (Text) Layout ¶
Sets the virtual layout box (constraints) for the text.
If width/height is set on an axis, that axis is constrained by a virtual layout box and the text may wrap/align inside it. If width/height == 0, the axis is unconstrained and Text.Align acts as an anchor on that axis.
- text : The text object.
- w : Layout width in user space. Use 0 for no horizontal constraint. (The initial value is 0)
- h : Layout height in user space. Use 0 for no vertical constraint. (The initial value is 0)
Note: This defines constraints only; alignment/anchoring is controlled by align(). Since: 1.0
see Text.Align
see Text.Spacing
func (Text) Ref ¶
func (paint Text) Ref() int
Increment the reference count for the Tvg_Paint object.
This method increases the reference count of Tvg_Paint object, allowing shared ownership and control over its lifetime.
- paint : The paint object to increase the reference count.
Return: The updated reference count after the increment by 1.
Warning: Please ensure that each call to tvg_paint_ref() is paired with a corresponding call to tvg_paint_unref() to prevent a dangling instance.
see [Paint.Unref]
see [Paint.GetRef]
Since: 1.0
func (Text) Rel ¶
func (paint Text) Rel() error
Safely releases a Tv_Paint object.
This is the counterpart to the `new()` API, and releases the given Paint object safely, handling nullptr and managing ownership properly.
- paint : A paint object to release.
func (Text) Rotate ¶
Rotates the given Tvg_Paint by the given angle.
The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.
- paint : The paint object to be rotated.
- degree : The value of the rotation angle in degrees.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Text) Scale ¶
Scales the given Tvg_Paint object by the given factor.
- paint : The paint object to be scaled.
- factor : The value of the scaling factor. The initial value is 1.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Text) SetBlendMethod ¶
func (paint Text) SetBlendMethod(method BlendMethod) error
Sets the blending method for the paint object.
The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. The blending operation is determined by the chosen BlendMethod, which specifies how the colors or images are combined.
- paint : The paint object of which to set the blend method.
- method : The blending method to be set.
Since: 0.15
func (Text) SetClip ¶
Clip the drawing region of the paint object.
This function restricts the drawing area of the paint object to the specified shape's paths.
- paint : The target object of the clipping.
- clipper : The shape object as the clipper.
Returns RESULT_INSUFFICIENT_CONDITION : if the target has already belonged to another paint.
Returns RESULT_NOT_SUPPORTED : If the clipper type is not Shape.
see [Paint.GetClip]
Since: 1.0
func (Text) SetColor ¶
Sets the text solid color.
- paint : The text object.
- r : The red color channel value in the range [0 ~ 255]. The initial value is 0.
- g : The green color channel value in the range [0 ~ 255]. The initial value is 0.
- b : The blue color channel value in the range [0 ~ 255]. The initial value is 0.
Note: Either a solid color or a gradient fill is applied, depending on what was set as last.
see Text.SetFont
see Text.SetOutline
Since: 0.15
func (Text) SetData ¶ added in v1.1.2
Associates user-defined data with the Paint object.
ThorVG does not interpret or manage the lifetime of this data.
- paint : The paint object whose user-defined data will be set.
- data : The user-defined data to associate with the paint object.
see [Paint.GetData]
Note: Experimental API
func (Text) SetFont ¶
Sets the font family for the text.
This function specifies the name of the font to be used when rendering text.
- text : The text object.
- name : The name of the font. This should match a font available through the canvas backend. If set to nullptr, ThorVG will attempt to select a fallback font available on the engine.
Returns RESULT_INSUFFICIENT_CONDITION : The specified name cannot be found.
Note: This function only sets the font family name. Use size() to define the font size.
Note: If the name is not specified, ThorVG will select an available fallback font.
see Text.SetSize
see FontLoad
Since: 1.0
func (Text) SetGradient ¶
Sets the gradient fill for the text.
- text : The text object.
- grad : The linear or radial gradient fill
Returns RESULT_MEMORY_CORRUPTION : An invalid gradient object.
Note: Either a solid color or a gradient fill is applied, depending on what was set as last.
see Text.SetFont
Since: 0.15
func (Text) SetId ¶
Sets the ID of the Paint object.
The ID is used to specify a paint instance in a scene.
- paint : The paint object whose ID will be set.
- id : The ID to assign to the paint object.
see Picture.GetPaint
see [Accessor.GenerateId]
see [Paint.GetId]
Since: 1.1
func (Text) SetItalic ¶
Apply an italic (slant) transformation to the text.
This function applies a shear transformation to simulate an italic (oblique) style for the current text object. The shear factor determines the degree of slant applied along the X-axis.
- text : The text object.
- shear : The shear factor to apply. A value of 0.0 applies no slant, while values around 0.5 result in a strong slant. Must be in the range [0.0, 0.5]. Recommended value is 0.18.
Note: The shear factor will be clamped to the valid range if it exceeds the limits.
Note: This does not require the font itself to be italic. It visually simulates the effect by applying a transformation matrix.
Warning: Excessive slanting may cause visual distortion depending on the font and size.
see Text.SetFont
Since: 1.0
func (Text) SetMaskMethod ¶
func (paint Text) SetMaskMethod(target Paint, method MaskMethod) error
Sets the masking target object and the masking method.
- paint : The source object of the masking.
- target : The target object of the masking.
- method : The method used to mask the source object with the target.
Returns RESULT_INSUFFICIENT_CONDITION : if the target has already belonged to another paint.
func (Text) SetOpacity ¶
Sets the opacity of the given Tvg_Paint.
- paint : The paint object of which the opacity value is to be set.
- opacity : The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
Note: Setting the opacity with this API may require multiple renderings using a composition. It is recommended to avoid changing the opacity if possible.
func (Text) SetOutline ¶
Sets an outline (stroke) around the text object.
This function adds an outline to the text with the specified width and RGB color. The outline enhances the visibility of the text by rendering a stroke around its glyphs.
- text : The text object.
- width : The width of the outline. Must be positive value. (The initial value is 0)
- r : Red component of the outline color (0–255).
- g : Green component of the outline color (0–255).
- b : Blue component of the outline color (0–255).
Note: To disable the outline, set width to 0.
see [Text.SetFillColor() To Set The Main Text Fill Color]
Since: 1.0
func (Text) SetSize ¶
Sets the font size for the text.
This function sets the font size used during text rendering. The size is specified in point units, and supports floating-point precision for smooth scaling and animation effects.
- text : The text object.
- size : The font size in points. Must be greater than 0.0.
Returns RESULT_INVALID_ARGUMENT : if the size is less than or equal to 0.
Note: Use this function in combination with font() to fully define text appearance.
Note: Fractional sizes (e.g., 12.5) are supported for sub-pixel rendering and animations.
see Text.SetFont
Since: 1.0
func (Text) SetText ¶
Assigns the given unicode text to be rendered.
This function sets the unicode text that will be displayed by the rendering system. The text is set according to the specified UTF encoding method, which defaults to UTF-8.
- text : The text object.
- utf8 : The multi-byte text encoded with utf8 string to be rendered.
see [Text.GetText]
Since: 1.0
func (Text) SetTransform ¶
Transforms the given Tvg_Paint using the augmented transformation matrix.
The augmented matrix of the transformation is expected to be given.
- paint : The paint object to be transformed.
- m : The 3x3 augmented matrix.
func (Text) SetVisible ¶
Sets the visibility of the Paint object.
This is useful for selectively excluding paint objects during rendering.
- paint : The paint object to set the visibility status.
- on : A boolean flag indicating visibility. The initial value is true. true, the object will be rendered by the engine. false, the object will be excluded from the drawing process.
Note: An invisible object is not considered inactive—it may still participate in internal update processing if its properties are updated, but it will not be taken into account for the final drawing output. To completely deactivate a paint object, remove it from the canvas.
see [Paint.GetVisible]
see Canvas.Remove
Since: 1.0
func (Text) Spacing ¶
Set the spacing scale factors for text layout.
This function adjusts the letter spacing (horizontal space between glyphs) and line spacing (vertical space between lines of text) using scale factors. Both values are relative to the font's default metrics: - The letter spacing is applied as a scale factor to the glyph's advance width. - The line spacing is applied as a scale factor to the glyph's advance height.
text : The text object.
letter : The scale factor for letter spacing. Values > 1.0 increase spacing, values < 1.0 decrease it. Must be greater than or equal to 0.0. The initial value is 1.0.
line : The scale factor for line spacing. Values > 1.0 increase line spacing, values < 1.0 decrease it. Must be greater than or equal to 0.0. The initial value is 1.0.
Since: 1.0
func (Text) Translate ¶
Moves the given Tvg_Paint in a two-dimensional space.
The origin of the coordinate system is in the upper-left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.
- paint : The paint object to be shifted.
- x : The value of the horizontal shift.
- y : The value of the vertical shift.
Returns RESULT_INSUFFICIENT_CONDITION : in case a custom transform is applied.
see [Paint.SetTransform]
func (Text) Unref ¶
Decrement the reference count for the Tvg_Paint object.
This method decreases the reference count of the Tvg_Paint object by 1. If the reference count reaches zero and the free flag is set to true, the instance is automatically deleted.
- paint : The paint object to decrease the reference count.
- free : Flag indicating whether to delete the Paint instance when the reference count reaches zero.
Return: The updated reference count after the decrement.
see [Paint.Ref]
see [Paint.GetRef]
Since: 1.0
func (Text) WrapMode ¶
Sets the text wrapping mode for this text object.
This method controls how the text is laid out when it exceeds the available space. The wrapping mode determines whether text is truncated, wrapped by character or word, or adjusted automatically. An ellipsis mode is also available for truncation with "...".
- text : The text object.
- mode : The wrapping strategy to apply. The initial value is TVG_TEXT_WRAP_NONE.
see Tvg_Text_Wrap
see [Text.LineCount] Since: 1.0
type TextMetrics ¶
type TextMetrics struct {
Ascent float32 ///< Distance from the baseline to the top of the highest glyph (usually positive).
Descent float32 ///< Distance from the baseline to the bottom of the lowest glyph (usually negative, as in TTF).
Linegap float32 ///< Additional spacing recommended between lines (leading).
Advance float32 ///< The total vertical advance between lines of text: ascent - descent + linegap (i.e., ascent + |descent| + linegap when descent is negative).
// contains filtered or unexported fields
}
TextMetrics describes the font metrics of a text object.
Provides the basic vertical layout metrics used for text rendering, such as ascent, descent, and line spacing (linegap).
@see tvg_text_get_text_metrics() @note Experimental API
type TextWrap ¶
type TextWrap enum
TextWrap is an enumeration specifying how text should be wrapped and truncated.
const ( TEXT_WRAP_NONE TextWrap = iota // Do not wrap text. Text is rendered on a single line and may overflow the bounding area. TEXT_WRAP_CHARACTER // Wrap at the character level. If a word cannot fit, it is broken into individual characters to fit the line. TEXT_WRAP_WORD // Wrap at the word level. Words that do not fit are moved to the next line. TEXT_WRAP_SMART // Smart choose wrapping method: word wrap first, falling back to character wrap if a word does not fit. TEXT_WRAP_ELLIPSIS // Truncate overflowing text and append an ellipsis ("...") at the end. Typically used for single-line labels. TEXT_WRAP_HYPHENATION // Reserved. No Support. )
type Type ¶
type Type enum
Type is an enumeration indicating the ThorVG object type value.
ThorVG's drawing objects can return object type values, allowing you to identify the specific type of each object.
@ingroup ThorVGCapi_Paint @see tvg_paint_get_type() @see tvg_gradient_get_type() @since 1.0
type Video ¶ added in v1.1.1
type Video uintptr
Video is a structure representing a video playback controller object.
Experimental API
func VideoNew ¶ added in v1.1.1
func VideoNew() Video
Creates a new video playback.
Return: Tvg_Video A new video object.
Note: Experimental API
func (Video) Del ¶ added in v1.1.1
Releases the given video object and its resources.
- video : The video object to release.
Note: Experimental API
func (Video) GetDuration ¶ added in v1.1.1
Retrieves the total duration of the video.
- video : The video object.
Return: The total duration in seconds.
Note: Experimental API
func (Video) GetLoop ¶ added in v1.1.1
Retrieves whether repeated playback is enabled.
Return: true if repeated playback is enabled, false otherwise.
see Video.SetLoop
Note: Experimental API
func (Video) GetMuted ¶ added in v1.1.1
Retrieves whether the audio is currently muted.
- video : The video object.
Return: true if the audio is muted, false otherwise.
see Video.SetMute
Note: Experimental API
func (Video) GetTime ¶ added in v1.1.1
Retrieves the current playback position.
- video : The video object.
Return: The current playback position in seconds.
see Video.Seek
Note: Experimental API
func (Video) GetVolume ¶ added in v1.1.1
Retrieves the current audio volume level.
- video : The video object.
Return: The current audio volume level in the range [0.0, 1.0].
see Video.SetVolume
Note: Experimental API
func (Video) Pause ¶ added in v1.1.1
Pauses playback while keeping the current position.
- video : The video object.
Returns RESULT_INSUFFICIENT_CONDITION : If the video is not started playing.
Note: Experimental API
func (Video) Picture ¶ added in v1.1.1
Retrieves the picture instance associated with this video object.
This function provides access to the internal picture used by the video object for rendering video frames. After obtaining the picture, it can be added to a canvas enabling control over video frames with this Video object.
- video : The video object.
Return: A picture instance representing the visual content of the video.
Warning: The picture instance is owned by the video object and should not be deleted manually.
Note: Experimental API
func (Video) Play ¶ added in v1.1.1
Starts or resumes playback.
- video : The video object.
Returns RESULT_INSUFFICIENT_CONDITION : If the video is not loaded.
Note: Experimental API
func (Video) Seek ¶ added in v1.1.1
Sets the playback position.
- video : The video object.
- seconds : The target playback position in seconds.
Returns RESULT_INSUFFICIENT_CONDITION : If the video is not loaded.
Returns RESULT_INVALID_ARGUMENT : If seconds is out of range.
Note: Experimental API
func (Video) SetLoop ¶ added in v1.1.1
Enables or disables repeated playback.
- video : The video object.
- on : true to repeat playback, false to play once. The initial value is false.
Returns RESULT_INSUFFICIENT_CONDITION : If the video is not loaded.
see Video.GetLoop
Note: Experimental API
func (Video) SetMute ¶ added in v1.1.1
Mutes or unmutes the audio without changing the volume level.
- video : The video object.
- on : true to mute the audio, false to unmute. The initial value is false.
Returns RESULT_INSUFFICIENT_CONDITION : If the video is not loaded.
see Video.GetMuted
Note: Experimental API
func (Video) SetVolume ¶ added in v1.1.1
Sets the audio volume level.
- video : The video object.
- volume : The audio volume level in the range [0.0, 1.0]. The initial value is 1.0.
Returns RESULT_INVALID_ARGUMENT : If volume is out of range.
Returns RESULT_INSUFFICIENT_CONDITION : If the video is not loaded.
see Video.GetVolume
Note: Experimental API
func (Video) Stop ¶ added in v1.1.1
Stops playback and rewinds to the start.
- video : The video object.
Returns RESULT_INSUFFICIENT_CONDITION : If the video is not loaded.
Note: Experimental API
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
glfw
command
|
|
|
glfw-lottie
command
|
|
|
picture
command
|
|
|
picture-raw-data
command
|
|
|
sdl
command
|
|
|
simple
command
|
|
|
text
command
|
|
|
internal
|
|
|
generate/cmd
command
|
|
|
Package swizzle provides functions for converting between RGBA pixel formats.
|
Package swizzle provides functions for converting between RGBA pixel formats. |