annotate nodejs/font.cc @ 722:f95d58a8edd1

Add javascript-based animation test program. We should make it as module in the future.
author wycc
date Sun, 15 Aug 2010 19:44:09 +0800
parents 5a68e2bcea17
children 586e50f82c1f
rev   line source
575
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <v8.h>
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include "mbfly_njs.h"
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 extern "C" {
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <mb.h>
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 }
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #ifndef ASSERT
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #define ASSERT(x)
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 #endif
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 using namespace v8;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 static Persistent<FunctionTemplate> xnjsmb_font_face_temp;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 /*! \brief Query a font face.
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 *
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 * This function should be a method of rt object.
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 *
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 * \param family is family of font face.
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 * \param slant is slant type of font face.
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 * \param weight is weight of font face.
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 */
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 static Handle<Value>
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 xnjsmb_font_face_query(const Arguments &args) {
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 HandleScope scope;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 int argc = args.Length();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 Handle<Object> self = args.This();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 char *face;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 int slant, weight;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 redraw_man_t *rdman;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 mb_font_face_t *font_face;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 Handle<Function> func_obj;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 Handle<Object> face_obj;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 if(argc != 3)
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 THROW("Invalid number of arguments (!= 3)");
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 if(!args[0]->IsString() || !args[1]->IsInt32() || !args[2]->IsInt32())
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 THROW("Invalid argument type");
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 String::Utf8Value face_utf8(args[0]);
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 face = *face_utf8;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 slant = args[1]->ToInt32()->Value();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 weight = args[2]->ToInt32()->Value();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 rdman = xnjsmb_rt_rdman(self);
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 font_face = mb_font_face_query(rdman, face, slant, weight);
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 if(font_face == NULL)
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 return Null();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 func_obj = xnjsmb_font_face_temp->GetFunction();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 face_obj = func_obj->NewInstance();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 WRAP(face_obj, font_face);
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 return face_obj;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 }
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 static void
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 xnjsmb_font_face_init_temp(void) {
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 Handle<FunctionTemplate> temp;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 Handle<ObjectTemplate> inst_temp;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 temp = FunctionTemplate::New();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 temp->SetClassName(String::New("font_face"));
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 inst_temp = temp->InstanceTemplate();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 inst_temp->SetInternalFieldCount(1);
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 xnjsmb_font_face_temp = Persistent<FunctionTemplate>::New(temp);
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 }
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71
576
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 575
diff changeset
72 /*! \brief Add properties to the template of runtime objects.
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 575
diff changeset
73 */
575
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 void
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 xnjsmb_font_init_mb_rt_temp(Handle<FunctionTemplate> mb_rt_temp) {
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 HandleScope scope;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 static int init_flag = 0;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 Handle<ObjectTemplate> rt_proto_temp;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 Handle<FunctionTemplate> query_func_temp;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 if(!init_flag) {
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 xnjsmb_font_face_init_temp();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 init_flag = 1;
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 }
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 rt_proto_temp = mb_rt_temp->PrototypeTemplate();
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 query_func_temp = FunctionTemplate::New(xnjsmb_font_face_query);
576
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 575
diff changeset
88 SET(rt_proto_temp, "font_face_query", query_func_temp);
575
97159102f886 Function of query font face in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 }