T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.quebec/private_html/node_modules/canvas/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.quebec/private_html/node_modules/canvas/src/CanvasGradient.cc
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>

#include "CanvasGradient.h"
#include "InstanceData.h"

#include "Canvas.h"
#include "color.h"

using namespace Napi;

/*
 * Initialize CanvasGradient.
 */

void
Gradient::Initialize(Napi::Env& env, Napi::Object& exports) {
  Napi::HandleScope scope(env);
  InstanceData* data = env.GetInstanceData<InstanceData>();

  Napi::Function ctor = DefineClass(env, "CanvasGradient", {
    InstanceMethod<&Gradient::AddColorStop>("addColorStop", napi_default_method)
  });

  exports.Set("CanvasGradient", ctor);
  data->CanvasGradientCtor = Napi::Persistent(ctor);
}

/*
 * Initialize a new CanvasGradient.
 */

Gradient::Gradient(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Gradient>(info), env(info.Env()) {
  // Linear
  if (
    4 == info.Length() &&
    info[0].IsNumber() &&
    info[1].IsNumber() &&
    info[2].IsNumber() &&
    info[3].IsNumber()
  ) {
    double x0 = info[0].As<Napi::Number>().DoubleValue();
    double y0 = info[1].As<Napi::Number>().DoubleValue();
    double x1 = info[2].As<Napi::Number>().DoubleValue();
    double y1 = info[3].As<Napi::Number>().DoubleValue();
    _pattern = cairo_pattern_create_linear(x0, y0, x1, y1);
    return;
  }

  // Radial
  if (
    6 == info.Length() &&
    info[0].IsNumber() &&
    info[1].IsNumber() &&
    info[2].IsNumber() &&
    info[3].IsNumber() &&
    info[4].IsNumber() &&
    info[5].IsNumber()
  ) {
    double x0 = info[0].As<Napi::Number>().DoubleValue();
    double y0 = info[1].As<Napi::Number>().DoubleValue();
    double r0 = info[2].As<Napi::Number>().DoubleValue();
    double x1 = info[3].As<Napi::Number>().DoubleValue();
    double y1 = info[4].As<Napi::Number>().DoubleValue();
    double r1 = info[5].As<Napi::Number>().DoubleValue();
    _pattern = cairo_pattern_create_radial(x0, y0, r0, x1, y1, r1);
    return;
  }

  Napi::TypeError::New(env, "invalid arguments").ThrowAsJavaScriptException();
}

/*
 * Add color stop.
 */

void
Gradient::AddColorStop(const Napi::CallbackInfo& info) {
  if (!info[0].IsNumber()) {
    Napi::TypeError::New(env, "offset required").ThrowAsJavaScriptException();
    return;
  }

  if (!info[1].IsString()) {
    Napi::TypeError::New(env, "color string required").ThrowAsJavaScriptException();
    return;
  }

  short ok;
  std::string str = info[1].As<Napi::String>();
  uint32_t rgba = rgba_from_string(str.c_str(), &ok);

  if (ok) {
    rgba_t color = rgba_create(rgba);
    cairo_pattern_add_color_stop_rgba(
        _pattern
      , info[0].As<Napi::Number>().DoubleValue()
      , color.r
      , color.g
      , color.b
      , color.a);
  } else {
    Napi::TypeError::New(env, "parse color failed").ThrowAsJavaScriptException();
  }
}


/*
 * Destroy the pattern.
 */

Gradient::~Gradient() {
  if (_pattern) cairo_pattern_destroy(_pattern);
}

CasperSecurity Mini