Mercurial > MadButterfly
changeset 575:97159102f886
Function of query font face in Javascript
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 10 Jun 2010 09:36:41 +0800 |
parents | a2faee809514 |
children | 5a68e2bcea17 |
files | nodejs/Makefile.am nodejs/font.cc nodejs/mbfly_njs.cc nodejs/mbfly_njs.h nodejs/wscript |
diffstat | 5 files changed, 94 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/Makefile.am Wed Jun 09 22:06:50 2010 +0800 +++ b/nodejs/Makefile.am Thu Jun 10 09:36:41 2010 +0800 @@ -1,5 +1,6 @@ -mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c coord.cc shapes.cc paints.cc +mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c coord.cc shapes.cc paints.cc \ + font.cc mbfly_node_CFLAGS= -I$(abs_top_builddir)/include \ -I$(abs_top_srcdir)/include \ -I$(prefix)/include \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/font.cc Thu Jun 10 09:36:41 2010 +0800 @@ -0,0 +1,87 @@ +#include <v8.h> +#include "mbfly_njs.h" + +extern "C" { +#include <mb.h> +} + +#ifndef ASSERT +#define ASSERT(x) +#endif + +using namespace v8; + +static Persistent<FunctionTemplate> xnjsmb_font_face_temp; + +/*! \brief Query a font face. + * + * This function should be a method of rt object. + * + * \param family is family of font face. + * \param slant is slant type of font face. + * \param weight is weight of font face. + */ +static Handle<Value> +xnjsmb_font_face_query(const Arguments &args) { + HandleScope scope; + int argc = args.Length(); + Handle<Object> self = args.This(); + char *face; + int slant, weight; + redraw_man_t *rdman; + mb_font_face_t *font_face; + Handle<Function> func_obj; + Handle<Object> face_obj; + + if(argc != 3) + THROW("Invalid number of arguments (!= 3)"); + if(!args[0]->IsString() || !args[1]->IsInt32() || !args[2]->IsInt32()) + THROW("Invalid argument type"); + + String::Utf8Value face_utf8(args[0]); + face = *face_utf8; + slant = args[1]->ToInt32()->Value(); + weight = args[2]->ToInt32()->Value(); + + rdman = xnjsmb_rt_rdman(self); + font_face = mb_font_face_query(rdman, face, slant, weight); + if(font_face == NULL) + return Null(); + + func_obj = xnjsmb_font_face_temp->GetFunction(); + face_obj = func_obj->NewInstance(); + WRAP(face_obj, font_face); + + return face_obj; +} + +static void +xnjsmb_font_face_init_temp(void) { + Handle<FunctionTemplate> temp; + Handle<ObjectTemplate> inst_temp; + + temp = FunctionTemplate::New(); + temp->SetClassName(String::New("font_face")); + + inst_temp = temp->InstanceTemplate(); + inst_temp->SetInternalFieldCount(1); + + xnjsmb_font_face_temp = Persistent<FunctionTemplate>::New(temp); +} + +void +xnjsmb_font_init_mb_rt_temp(Handle<FunctionTemplate> mb_rt_temp) { + HandleScope scope; + static int init_flag = 0; + Handle<ObjectTemplate> rt_proto_temp; + Handle<FunctionTemplate> query_func_temp; + + if(!init_flag) { + xnjsmb_font_face_init_temp(); + init_flag = 1; + } + + rt_proto_temp = mb_rt_temp->PrototypeTemplate(); + query_func_temp = FunctionTemplate::New(xnjsmb_font_face_query); + SET(rt_proto_temp, "font_fact_query", query_func_temp); +}
--- a/nodejs/mbfly_njs.cc Wed Jun 09 22:06:50 2010 +0800 +++ b/nodejs/mbfly_njs.cc Thu Jun 10 09:36:41 2010 +0800 @@ -147,6 +147,7 @@ */ xnjsmb_shapes_init_mb_rt_temp(mb_rt_func); xnjsmb_paints_init_mb_rt_temp(mb_rt_func); + xnjsmb_font_init_mb_rt_temp(mb_rt_func); target->Set(String::New("mb_rt"), mb_rt_func->GetFunction()); }
--- a/nodejs/mbfly_njs.h Wed Jun 09 22:06:50 2010 +0800 +++ b/nodejs/mbfly_njs.h Thu Jun 10 09:36:41 2010 +0800 @@ -29,4 +29,7 @@ /* From paints.cc */ void xnjsmb_paints_init_mb_rt_temp(v8::Handle<v8::FunctionTemplate> rt_temp); +/* From font.cc */ +void xnjsmb_font_init_mb_rt_temp(v8::Handle<v8::FunctionTemplate> mb_rt_temp); + #endif /* __MBFLY_NJS_H_ */
--- a/nodejs/wscript Wed Jun 09 22:06:50 2010 +0800 +++ b/nodejs/wscript Thu Jun 10 09:36:41 2010 +0800 @@ -23,7 +23,7 @@ obj = conf.new_task_gen('cxx', 'shlib', 'node_addon') obj.target = 'mbfly' - obj.source = 'mbfly_njs.cc coord.cc shapes.cc paints.cc' + obj.source = 'mbfly_njs.cc coord.cc shapes.cc paints.cc font.cc' obj.add_objects = 'X_supp_njs.o' obj.staticlib = 'mbfly'