… | |
… | |
17 | #include <netinet/tcp.h> |
17 | #include <netinet/tcp.h> |
18 | |
18 | |
19 | static PangoContext *context; |
19 | static PangoContext *context; |
20 | static PangoFontMap *fontmap; |
20 | static PangoFontMap *fontmap; |
21 | |
21 | |
|
|
22 | typedef struct cf_layout { |
|
|
23 | PangoLayout *pl; |
|
|
24 | int base_height; |
|
|
25 | } *CFClient__Layout; |
|
|
26 | |
|
|
27 | static void |
|
|
28 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
|
|
29 | { |
|
|
30 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
31 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
|
|
32 | |
|
|
33 | pango_layout_get_pixel_size (self->pl, w, h); |
|
|
34 | |
|
|
35 | *w = (*w + 3) & ~3; |
|
|
36 | if (!*w) *w = 1; |
|
|
37 | if (!*h) *h = 1; |
|
|
38 | } |
|
|
39 | |
22 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
40 | MODULE = CFClient PACKAGE = CFClient |
23 | |
41 | |
24 | PROTOTYPES: ENABLE |
42 | PROTOTYPES: ENABLE |
25 | |
43 | |
26 | BOOT: |
44 | BOOT: |
27 | { |
45 | { |
… | |
… | |
47 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
65 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
48 | OUTPUT: |
66 | OUTPUT: |
49 | RETVAL |
67 | RETVAL |
50 | |
68 | |
51 | void |
69 | void |
|
|
70 | add_font (char *file) |
|
|
71 | CODE: |
|
|
72 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
|
|
73 | |
|
|
74 | void |
52 | set_font (char *file) |
75 | set_font (char *file) |
53 | CODE: |
76 | CODE: |
54 | { |
77 | { |
55 | int count; |
78 | int count; |
56 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
79 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
57 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
|
|
58 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
80 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
59 | FcPatternDestroy (pattern); |
81 | FcPatternDestroy (pattern); |
60 | pango_context_set_font_description (context, font); |
82 | pango_context_set_font_description (context, font); |
61 | } |
83 | } |
62 | |
84 | |
|
|
85 | MODULE = CFClient PACKAGE = CFClient::Layout |
|
|
86 | |
|
|
87 | CFClient::Layout |
|
|
88 | new (SV *class, int base_height = 10) |
|
|
89 | CODE: |
|
|
90 | New (0, RETVAL, 1, struct cf_layout); |
|
|
91 | RETVAL->base_height = base_height; |
|
|
92 | RETVAL->pl = pango_layout_new (context); |
|
|
93 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
|
|
94 | OUTPUT: |
|
|
95 | RETVAL |
|
|
96 | |
63 | void |
97 | void |
64 | font_render (SV *text_, int height = 10) |
98 | DESTROY (CFClient::Layout self) |
65 | PPCODE: |
99 | CODE: |
|
|
100 | g_object_unref (self->pl); |
|
|
101 | Safefree (self); |
|
|
102 | |
|
|
103 | void |
|
|
104 | set_markup (CFClient::Layout self, SV *text_) |
|
|
105 | CODE: |
66 | { |
106 | { |
67 | STRLEN textlen; |
107 | STRLEN textlen; |
68 | char *text = SvPVutf8 (text_, textlen); |
108 | char *text = SvPVutf8 (text_, textlen); |
|
|
109 | |
|
|
110 | pango_layout_set_markup (self->pl, text, textlen); |
|
|
111 | } |
|
|
112 | |
|
|
113 | void |
|
|
114 | set_height (CFClient::Layout self, int base_height) |
|
|
115 | CODE: |
|
|
116 | self->base_height = base_height; |
|
|
117 | |
|
|
118 | void |
|
|
119 | set_width (CFClient::Layout self, int max_width = -1) |
|
|
120 | CODE: |
|
|
121 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
|
|
122 | |
|
|
123 | void |
|
|
124 | size (CFClient::Layout self) |
|
|
125 | PPCODE: |
|
|
126 | { |
|
|
127 | int w, h; |
|
|
128 | |
|
|
129 | layout_get_pixel_size (self, &w, &h); |
|
|
130 | |
|
|
131 | EXTEND (SP, 2); |
|
|
132 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
133 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
134 | } |
|
|
135 | |
|
|
136 | void |
|
|
137 | render (CFClient::Layout self) |
|
|
138 | PPCODE: |
|
|
139 | { |
69 | SV *retval; |
140 | SV *retval; |
70 | int w, h; |
141 | int w, h; |
71 | FT_Bitmap bitmap; |
142 | FT_Bitmap bitmap; |
72 | PangoLayout *layout; |
|
|
73 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
74 | pango_font_description_set_absolute_size (font, height * PANGO_SCALE); |
|
|
75 | |
143 | |
76 | layout = pango_layout_new (context); |
|
|
77 | pango_layout_set_markup (layout, text, textlen); |
|
|
78 | pango_layout_get_pixel_size (layout, &w, &h); |
144 | layout_get_pixel_size (self, &w, &h); |
79 | |
|
|
80 | w = (w + 3) & ~3; |
|
|
81 | if (!w) w = 1; |
|
|
82 | if (!h) h = 1; |
|
|
83 | |
145 | |
84 | retval = newSV (w * h); |
146 | retval = newSV (w * h); |
85 | SvPOK_only (retval); |
147 | SvPOK_only (retval); |
86 | SvCUR_set (retval, w * h); |
148 | SvCUR_set (retval, w * h); |
87 | |
149 | |
… | |
… | |
92 | bitmap.num_grays = 256; |
154 | bitmap.num_grays = 256; |
93 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
155 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
94 | |
156 | |
95 | memset (bitmap.buffer, 0, w * h); |
157 | memset (bitmap.buffer, 0, w * h); |
96 | |
158 | |
97 | pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
159 | pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
98 | g_object_unref (layout); |
|
|
99 | |
160 | |
100 | EXTEND (SP, 3); |
161 | EXTEND (SP, 3); |
101 | PUSHs (sv_2mortal (newSViv (w))); |
162 | PUSHs (sv_2mortal (newSViv (w))); |
102 | PUSHs (sv_2mortal (newSViv (h))); |
163 | PUSHs (sv_2mortal (newSViv (h))); |
103 | PUSHs (sv_2mortal (retval)); |
164 | PUSHs (sv_2mortal (retval)); |
104 | } |
165 | } |
105 | |
166 | |
106 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture |
167 | MODULE = CFClient PACKAGE = CFClient::Texture |
107 | |
168 | |
108 | void |
169 | void |
109 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
170 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
110 | PROTOTYPE: $$$;$$ |
171 | PROTOTYPE: $$$;$$ |
111 | CODE: |
172 | CODE: |