Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started Image

  • Loading branch information...
commit e6ba903a5360cd2a3bbffae9e8bd45766c75479f 1 parent 0a5aa4c
@tj tj authored
Showing with 84 additions and 0 deletions.
  1. +53 −0 src/Image.cc
  2. +31 −0 src/Image.h
View
53 src/Image.cc
@@ -0,0 +1,53 @@
+
+//
+// Image.cc
+//
+// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
+//
+
+#include "canvas.h"
+#include "image.h"
+
+/*
+ * Initialize Image.
+ */
+
+void
+Image::Initialize(Handle<Object> target) {
+ HandleScope scope;
+ Local<FunctionTemplate> t = FunctionTemplate::New(Image::New);
+ t->InstanceTemplate()->SetInternalFieldCount(1);
+ t->SetClassName(String::NewSymbol("Image"));
+
+ Local<ObjectTemplate> proto = t->PrototypeTemplate();
+ proto->SetAccessor(String::NewSymbol("src"), GetSrc, SetSrc);
+ target->Set(String::NewSymbol("Image"), t->GetFunction());
+}
+
+/*
+ * Initialize a new Image.
+ */
+
+Handle<Value>
+Image::New(const Arguments &args) {
+ HandleScope scope;
+ Image *img = new Image;
+ img->Wrap(args.This());
+ return args.This();
+}
+
+/*
+ * Initialize a new Image.
+ */
+
+Image::Image() {
+ _surface = NULL;
+}
+
+/*
+ * Destroy image and associated surface.
+ */
+
+Image::~Image() {
+ cairo_surface_destroy(_surface);
+}
View
31 src/Image.h
@@ -0,0 +1,31 @@
+
+//
+// Image.h
+//
+// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
+//
+
+#ifndef __NODE_IMAGE_H__
+#define __NODE_IMAGE_H__
+
+#include "canvas.h"
+
+using namespace v8;
+
+class Image: public node::ObjectWrap {
+ public:
+ static void Initialize(Handle<Object> target);
+ static Handle<Value> New(const Arguments &args);
+ static Handle<Value> GetSrc(Local<String> prop, const AccessorInfo &info);
+ static void SetSrc(Local<String> prop, Local<Value> val, const AccessorInfo &info);
+ inline cairo_surface_t *surface(){ return _surface; }
+ inline char *filename(){ return _filename; }
+ Image();
+
+ private:
+ char *_filename;
+ cairo_surface_t *_surface;
+ ~Image();
+};
+
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.