comparison nodejs/font.cc @ 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
children 5a68e2bcea17
comparison
equal deleted inserted replaced
574:a2faee809514 575:97159102f886
1 #include <v8.h>
2 #include "mbfly_njs.h"
3
4 extern "C" {
5 #include <mb.h>
6 }
7
8 #ifndef ASSERT
9 #define ASSERT(x)
10 #endif
11
12 using namespace v8;
13
14 static Persistent<FunctionTemplate> xnjsmb_font_face_temp;
15
16 /*! \brief Query a font face.
17 *
18 * This function should be a method of rt object.
19 *
20 * \param family is family of font face.
21 * \param slant is slant type of font face.
22 * \param weight is weight of font face.
23 */
24 static Handle<Value>
25 xnjsmb_font_face_query(const Arguments &args) {
26 HandleScope scope;
27 int argc = args.Length();
28 Handle<Object> self = args.This();
29 char *face;
30 int slant, weight;
31 redraw_man_t *rdman;
32 mb_font_face_t *font_face;
33 Handle<Function> func_obj;
34 Handle<Object> face_obj;
35
36 if(argc != 3)
37 THROW("Invalid number of arguments (!= 3)");
38 if(!args[0]->IsString() || !args[1]->IsInt32() || !args[2]->IsInt32())
39 THROW("Invalid argument type");
40
41 String::Utf8Value face_utf8(args[0]);
42 face = *face_utf8;
43 slant = args[1]->ToInt32()->Value();
44 weight = args[2]->ToInt32()->Value();
45
46 rdman = xnjsmb_rt_rdman(self);
47 font_face = mb_font_face_query(rdman, face, slant, weight);
48 if(font_face == NULL)
49 return Null();
50
51 func_obj = xnjsmb_font_face_temp->GetFunction();
52 face_obj = func_obj->NewInstance();
53 WRAP(face_obj, font_face);
54
55 return face_obj;
56 }
57
58 static void
59 xnjsmb_font_face_init_temp(void) {
60 Handle<FunctionTemplate> temp;
61 Handle<ObjectTemplate> inst_temp;
62
63 temp = FunctionTemplate::New();
64 temp->SetClassName(String::New("font_face"));
65
66 inst_temp = temp->InstanceTemplate();
67 inst_temp->SetInternalFieldCount(1);
68
69 xnjsmb_font_face_temp = Persistent<FunctionTemplate>::New(temp);
70 }
71
72 void
73 xnjsmb_font_init_mb_rt_temp(Handle<FunctionTemplate> mb_rt_temp) {
74 HandleScope scope;
75 static int init_flag = 0;
76 Handle<ObjectTemplate> rt_proto_temp;
77 Handle<FunctionTemplate> query_func_temp;
78
79 if(!init_flag) {
80 xnjsmb_font_face_init_temp();
81 init_flag = 1;
82 }
83
84 rt_proto_temp = mb_rt_temp->PrototypeTemplate();
85 query_func_temp = FunctionTemplate::New(xnjsmb_font_face_query);
86 SET(rt_proto_temp, "font_fact_query", query_func_temp);
87 }