# HG changeset patch # User Thinker K.F. Li # Date 1276133801 -28800 # Node ID 97159102f886850780ea3a9709cd5b15989d8abf # Parent a2faee809514a3f750acfd81e6a67a35457bdc32 Function of query font face in Javascript diff -r a2faee809514 -r 97159102f886 nodejs/Makefile.am --- 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 \ diff -r a2faee809514 -r 97159102f886 nodejs/font.cc --- /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 +#include "mbfly_njs.h" + +extern "C" { +#include +} + +#ifndef ASSERT +#define ASSERT(x) +#endif + +using namespace v8; + +static Persistent 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 +xnjsmb_font_face_query(const Arguments &args) { + HandleScope scope; + int argc = args.Length(); + Handle self = args.This(); + char *face; + int slant, weight; + redraw_man_t *rdman; + mb_font_face_t *font_face; + Handle func_obj; + Handle 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 temp; + Handle inst_temp; + + temp = FunctionTemplate::New(); + temp->SetClassName(String::New("font_face")); + + inst_temp = temp->InstanceTemplate(); + inst_temp->SetInternalFieldCount(1); + + xnjsmb_font_face_temp = Persistent::New(temp); +} + +void +xnjsmb_font_init_mb_rt_temp(Handle mb_rt_temp) { + HandleScope scope; + static int init_flag = 0; + Handle rt_proto_temp; + Handle 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); +} diff -r a2faee809514 -r 97159102f886 nodejs/mbfly_njs.cc --- 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()); } diff -r a2faee809514 -r 97159102f886 nodejs/mbfly_njs.h --- 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 rt_temp); +/* From font.cc */ +void xnjsmb_font_init_mb_rt_temp(v8::Handle mb_rt_temp); + #endif /* __MBFLY_NJS_H_ */ diff -r a2faee809514 -r 97159102f886 nodejs/wscript --- 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'