static inline NAN_METHOD(register_fonts)
{
    NanScope();

    try
    {
        if (args.Length() == 0 || !args[0]->IsString())
        {
            NanThrowTypeError("first argument must be a path to a directory of fonts");
            NanReturnUndefined();
        }

        bool found = false;

        std::vector<std::string> const names_before = mapnik::freetype_engine::face_names();

        // option hash
        if (args.Length() == 2){
            if (!args[1]->IsObject())
            {
                NanThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse:Boolean }");
                NanReturnUndefined();
            }

            Local<Object> options = args[1].As<Object>();
            if (options->Has(NanNew("recurse")))
            {
                Local<Value> recurse_opt = options->Get(NanNew("recurse"));
                if (!recurse_opt->IsBoolean())
                {
                    NanThrowTypeError("'recurse' must be a Boolean");
                    NanReturnUndefined();
                }

                bool recurse = recurse_opt->BooleanValue();
                std::string path = TOSTR(args[0]);
                found = mapnik::freetype_engine::register_fonts(path,recurse);
            }
        }
        else
        {
            std::string path = TOSTR(args[0]);
            found = mapnik::freetype_engine::register_fonts(path);
        }

        std::vector<std::string> const& names_after = mapnik::freetype_engine::face_names();
        if (names_after.size() == names_before.size())
            found = false;

        NanReturnValue(NanNew(found));
    }
    catch (std::exception const& ex)
    {
        NanThrowError(ex.what());
        NanReturnUndefined();
    }
}
  static NAN_METHOD(New) {
    NanScope();

    if (args.Length() != 1) {
      EIGENJS_THROW_ERROR_INVALID_ARGUMENT()
      NanReturnUndefined();
    }

    if (!args.IsConstructCall()) {
      v8::Local<v8::Value> argv[] ={ args[0] };
      NanReturnValue(
        base_type::new_instance(
          args
        , sizeof(argv) / sizeof(v8::Local<v8::Value>)
        , argv
        )
      );
    }

    if (Matrix::is_matrix(args[0])) {
      const Matrix* const& rhs_obj =
          node::ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
      const typename Matrix::value_type& rhs_matrix = **rhs_obj;

      if (rhs_matrix.rows() != rhs_matrix.cols()) {
        NanThrowError("PartialPivLU is only for square "
                      "(and moreover invertible) matrices");
        NanReturnUndefined();
      }

      PartialPivLU* obj = new PartialPivLU(rhs_matrix);
      obj->Wrap(args.This());
      NanReturnValue(args.This());
    } else if (MatrixBlock::is_matrixblock(args[0])) {
      const MatrixBlock* const& rhs_obj =
          node::ObjectWrap::Unwrap<MatrixBlock>(args[0]->ToObject());
      const typename MatrixBlock::value_type& rhs_matrixblock = **rhs_obj;

      if (rhs_matrixblock.rows() != rhs_matrixblock.cols()) {
        NanThrowError("PartialPivLU is only for square "
                      "(and moreover invertible) matrices");
        NanReturnUndefined();
      }

      PartialPivLU* obj = new PartialPivLU(rhs_matrixblock);
      obj->Wrap(args.This());
      NanReturnValue(args.This());
    }

    EIGENJS_THROW_ERROR_INVALID_ARGUMENT()
    NanReturnUndefined();
  }
Example #3
0
 static NAN_METHOD(ClosePort)
 {
     NanScope();
     NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This());
     output->out->closePort();
     NanReturnUndefined();
 }
Example #4
0
 static NAN_METHOD(ClosePort)
 {
     NanScope();
     NodeMidiInput* input = node::ObjectWrap::Unwrap<NodeMidiInput>(args.This());
     if (input->in->isPortOpen()) {
         input->Unref();
     }
     input->in->closePort();
     uv_close((uv_handle_t*)&input->message_async, NULL);
     NanReturnUndefined();
 }
Example #5
0
    static NAN_METHOD(OpenVirtualPort)
    {
        NanScope();
        NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This());
        if (args.Length() == 0 || !args[0]->IsString()) {
            return NanThrowTypeError("First argument must be a string");
        }

        std::string name(*NanAsciiString(args[0]));

        output->out->openVirtualPort(name);
        NanReturnUndefined();
    }
Example #6
0
    static NAN_METHOD(IgnoreTypes)
    {
        NanScope();
        NodeMidiInput* input = node::ObjectWrap::Unwrap<NodeMidiInput>(args.This());
        if (args.Length() != 3 || !args[0]->IsBoolean() || !args[1]->IsBoolean() || !args[2]->IsBoolean()) {
            return NanThrowTypeError("Arguments must be boolean");
        }

        bool filter_sysex = args[0]->BooleanValue();
        bool filter_timing = args[1]->BooleanValue();
        bool filter_sensing = args[2]->BooleanValue();
        input->in->ignoreTypes(filter_sysex, filter_timing, filter_sensing);
        NanReturnUndefined();
    }
Example #7
0
    static NAN_METHOD(OpenPort)
    {
        NanScope();
        NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This());
        if (args.Length() == 0 || !args[0]->IsUint32()) {
            return NanThrowTypeError("First argument must be an integer");
        }
        unsigned int portNumber = args[0]->Uint32Value();
        if (portNumber >= output->out->getPortCount()) {
            return NanThrowRangeError("Invalid MIDI port number");
        }

        output->out->openPort(portNumber);
        NanReturnUndefined();
    }
static inline NAN_METHOD(register_datasource)
{
    NanScope();
    if (args.Length() != 1 || !args[0]->IsString())
    {
        NanThrowTypeError("first argument must be a path to a mapnik input plugin (.input)");
        NanReturnUndefined();
    }
    std::vector<std::string> names_before = mapnik::datasource_cache::instance().plugin_names();
    std::string path = TOSTR(args[0]);
    mapnik::datasource_cache::instance().register_datasource(path);
    std::vector<std::string> names_after = mapnik::datasource_cache::instance().plugin_names();
    if (names_after.size() > names_before.size())
        NanReturnValue(NanTrue());
    NanReturnValue(NanFalse());
}
Example #9
0
    static NAN_METHOD(SendMessage)
    {
        NanScope();
        NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This());
        if (args.Length() == 0 || !args[0]->IsArray()) {
            return NanThrowTypeError("First argument must be an array");
        }

        v8::Local<v8::Object> message = args[0]->ToObject();
        int32_t messageLength = message->Get(NanNew<v8::String>("length"))->Int32Value();
        std::vector<unsigned char> messageOutput;
        for (int32_t i = 0; i != messageLength; ++i) {
            messageOutput.push_back(message->Get(NanNew<v8::Integer>(i))->Int32Value());
        }
        output->out->sendMessage(&messageOutput);
        NanReturnUndefined();
    }
Example #10
0
  static NAN_METHOD(New) {
    const int& args_length = args.Length();

    NanScope();

    if (args_length == 1) {
      if (!args.IsConstructCall()) {
        v8::Local<v8::Value> argv[] = { args[0] };
        NanReturnValue(
          base_type::new_instance(
            args
          , sizeof(argv) / sizeof(v8::Local<v8::Value>)
          , argv
          )
        );
      }

      if (args[0]->IsNumber()) {
        typename value_type::Index size = args[0]->Int32Value();
        if (size >= 0) {
          Vector* obj = new Vector(size);
          obj->Wrap(args.This());
          NanReturnValue(args.This());
        }
      } else if (args[0]->IsArray()) {
        const v8::Local<v8::Array>& array = args[0].As<v8::Array>();
        uint32_t len = array->Length();
        Vector* obj = new Vector(len);
        Vector::value_type& vector = **obj;

        for (uint32_t i = 0; i < len; ++i) {
          const v8::Local<v8::Value>& elem = array->Get(i);
          vector(i, 0) = elem->NumberValue();
        }

        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (Matrix::is_matrix(args[0])) {
        const Matrix* const& rhs_obj =
            node::ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
        const typename Matrix::value_type& rhs_matrix = **rhs_obj;
        const typename Matrix::value_type::Index& rows = rhs_matrix.rows();
        const typename Matrix::value_type::Index& cols = rhs_matrix.cols();

        if (rows != 1 && cols != 1) {
          EIGENJS_THROW_ERROR_THE_MATRIX_SIZE_MUST_BE_1XN_OR_MX1()
          NanReturnUndefined();
        }

        Vector* obj = new Vector(0);

        if (rows > cols) {
          **obj = rhs_matrix;
        } else {
          **obj = rhs_matrix.transpose();
        }

        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (Vector::is_vector(args[0])) {
        const Vector* const& rhs_obj =
            node::ObjectWrap::Unwrap<Vector>(args[0]->ToObject());
        const typename Vector::value_type& rhs_vector = **rhs_obj;

        Vector* obj = new Vector(0);
        **obj = rhs_vector;
        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (RowVector::is_rowvector(args[0])) {
        const RowVector* const& rhs_obj =
            node::ObjectWrap::Unwrap<RowVector>(args[0]->ToObject());
        const typename RowVector::value_type& rhs_rowvector = **rhs_obj;

        Vector* obj = new Vector(0);
        **obj = rhs_rowvector.transpose();
        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (MatrixBlock::is_matrixblock(args[0])) {
        const MatrixBlock* const& rhs_obj =
            node::ObjectWrap::Unwrap<MatrixBlock>(args[0]->ToObject());
        const typename MatrixBlock::value_type& rhs_matrixblock = **rhs_obj;
        const typename MatrixBlock::value_type::Index& rows =
            rhs_matrixblock.rows();
        const typename MatrixBlock::value_type::Index& cols =
            rhs_matrixblock.cols();

        if (rows != 1 && cols != 1) {
          EIGENJS_THROW_ERROR_THE_MATRIX_SIZE_MUST_BE_1XN_OR_MX1()
          NanReturnUndefined();
        }

        Vector* obj = new Vector(0);

        if (rows > cols) {
          **obj = rhs_matrixblock;
        } else {
          **obj = rhs_matrixblock.transpose();
        }

        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (VectorBlock::is_vectorblock(args[0])) {
        const VectorBlock* const& rhs_obj =
            node::ObjectWrap::Unwrap<VectorBlock>(args[0]->ToObject());
        const typename VectorBlock::value_type& rhs_vectorblock = **rhs_obj;

        Vector* obj = new Vector(0);
        **obj = rhs_vectorblock;
        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (RowVectorBlock::is_rowvectorblock(args[0])) {
        const RowVectorBlock* const& rhs_obj =
            node::ObjectWrap::Unwrap<RowVectorBlock>(args[0]->ToObject());
        const typename RowVectorBlock::value_type& rhs_rowvectorblock =
            **rhs_obj;

        Vector* obj = new Vector(0);
        **obj = rhs_rowvectorblock.transpose();
        obj->Wrap(args.This());
        NanReturnValue(args.This());
      }
    } else if (args_length == 2) {
      if (args[0]->IsNumber() && args[1]->IsNumber()) {
        const typename value_type::Index& rows = args[0]->Int32Value();
        const typename value_type::Index& cols = args[1]->Int32Value();
        (void)cols;

        if (rows >= 0 && cols >= 0) {
          if (args.IsConstructCall()) {
            Vector* obj = new Vector(rows);
            obj->Wrap(args.This());
            NanReturnValue(args.This());
          } else {
           v8::Local<v8::Value> argv[] = { args[0], args[1] };

            NanReturnValue(
              base_type::new_instance(
                args
              , sizeof(argv) / sizeof(v8::Local<v8::Value>)
              , argv
              )
            );
          }
        }
      }
    }

    EIGENJS_THROW_ERROR_INVALID_ARGUMENT()
    NanReturnUndefined();
  }