bb3a6a1292d27e878413666b07c17c9b275d7b1f
[platform/upstream/gstreamer.git] / ext / pango / gsttextrender.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2003> David Schleef <ds@schleef.org>
4  * Copyright (C) <2009> Young-Ho Cha <ganadist@gmail.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22
23 /**
24  * SECTION:element-textrender
25  * @see_also: #GstTextOverlay
26  *
27  * This plugin renders text received on the text sink pad to a video
28  * buffer (retaining the alpha channel), so it can later be overlayed
29  * on top of video streams using other elements.
30  *
31  * The text can contain newline characters. (FIXME: What about text 
32  * wrapping? It does not make sense in this context)
33  *
34  * <refsect2>
35  * <title>Example launch lines</title>
36  * |[
37  * gst-launch -v filesrc location=subtitles.srt ! subparse ! textrender ! xvimagesink
38  * ]|
39  * </refsect2>
40  */
41
42 #ifdef HAVE_CONFIG_H
43 #include <config.h>
44 #endif
45
46 #include <gst/gst.h>
47 #include <gst/video/video.h>
48
49 #include "gsttextrender.h"
50 #include <string.h>
51
52 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
53 # define CAIRO_ARGB_A 3
54 # define CAIRO_ARGB_R 2
55 # define CAIRO_ARGB_G 1
56 # define CAIRO_ARGB_B 0
57 #else
58 # define CAIRO_ARGB_A 0
59 # define CAIRO_ARGB_R 1
60 # define CAIRO_ARGB_G 2
61 # define CAIRO_ARGB_B 3
62 #endif
63
64 GST_DEBUG_CATEGORY_EXTERN (pango_debug);
65 #define GST_CAT_DEFAULT pango_debug
66
67 #define MINIMUM_OUTLINE_OFFSET 1.0
68
69 #define DEFAULT_PROP_VALIGNMENT GST_TEXT_RENDER_VALIGN_BASELINE
70 #define DEFAULT_PROP_HALIGNMENT GST_TEXT_RENDER_HALIGN_CENTER
71 #define DEFAULT_PROP_LINE_ALIGNMENT GST_TEXT_RENDER_LINE_ALIGN_CENTER
72 #define DEFAULT_PROP_XPAD       25
73 #define DEFAULT_PROP_YPAD       25
74
75 #define DEFAULT_RENDER_WIDTH 720
76 #define DEFAULT_RENDER_HEIGHT 576
77
78 enum
79 {
80   PROP_0,
81   PROP_HALIGNMENT,
82   PROP_VALIGNMENT,
83   PROP_LINE_ALIGNMENT,
84   PROP_XPAD,
85   PROP_YPAD,
86   PROP_FONT_DESC
87 };
88
89
90 static GstStaticPadTemplate src_template_factory =
91     GST_STATIC_PAD_TEMPLATE ("src",
92     GST_PAD_SRC,
93     GST_PAD_ALWAYS,
94     GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_ARGB)
95     );
96
97 static GstStaticPadTemplate sink_template_factory =
98     GST_STATIC_PAD_TEMPLATE ("sink",
99     GST_PAD_SINK,
100     GST_PAD_ALWAYS,
101     GST_STATIC_CAPS ("text/x-pango-markup; text/plain")
102     );
103
104 #define GST_TYPE_TEXT_RENDER_VALIGN (gst_text_render_valign_get_type())
105 static GType
106 gst_text_render_valign_get_type (void)
107 {
108   static GType text_render_valign_type = 0;
109   static const GEnumValue text_render_valign[] = {
110     {GST_TEXT_RENDER_VALIGN_BASELINE, "baseline", "baseline"},
111     {GST_TEXT_RENDER_VALIGN_BOTTOM, "bottom", "bottom"},
112     {GST_TEXT_RENDER_VALIGN_TOP, "top", "top"},
113     {0, NULL, NULL},
114   };
115
116   if (!text_render_valign_type) {
117     text_render_valign_type =
118         g_enum_register_static ("GstTextRenderVAlign", text_render_valign);
119   }
120   return text_render_valign_type;
121 }
122
123 #define GST_TYPE_TEXT_RENDER_HALIGN (gst_text_render_halign_get_type())
124 static GType
125 gst_text_render_halign_get_type (void)
126 {
127   static GType text_render_halign_type = 0;
128   static const GEnumValue text_render_halign[] = {
129     {GST_TEXT_RENDER_HALIGN_LEFT, "left", "left"},
130     {GST_TEXT_RENDER_HALIGN_CENTER, "center", "center"},
131     {GST_TEXT_RENDER_HALIGN_RIGHT, "right", "right"},
132     {0, NULL, NULL},
133   };
134
135   if (!text_render_halign_type) {
136     text_render_halign_type =
137         g_enum_register_static ("GstTextRenderHAlign", text_render_halign);
138   }
139   return text_render_halign_type;
140 }
141
142 #define GST_TYPE_TEXT_RENDER_LINE_ALIGN (gst_text_render_line_align_get_type())
143 static GType
144 gst_text_render_line_align_get_type (void)
145 {
146   static GType text_render_line_align_type = 0;
147   static const GEnumValue text_render_line_align[] = {
148     {GST_TEXT_RENDER_LINE_ALIGN_LEFT, "left", "left"},
149     {GST_TEXT_RENDER_LINE_ALIGN_CENTER, "center", "center"},
150     {GST_TEXT_RENDER_LINE_ALIGN_RIGHT, "right", "right"},
151     {0, NULL, NULL}
152   };
153
154   if (!text_render_line_align_type) {
155     text_render_line_align_type =
156         g_enum_register_static ("GstTextRenderLineAlign",
157         text_render_line_align);
158   }
159   return text_render_line_align_type;
160 }
161
162 static void gst_text_render_adjust_values_with_fontdesc (GstTextRender *
163     render, PangoFontDescription * desc);
164
165 GST_BOILERPLATE (GstTextRender, gst_text_render, GstElement, GST_TYPE_ELEMENT);
166
167 static void gst_text_render_finalize (GObject * object);
168 static void gst_text_render_set_property (GObject * object,
169     guint prop_id, const GValue * value, GParamSpec * pspec);
170 static void gst_text_render_get_property (GObject * object,
171     guint prop_id, GValue * value, GParamSpec * pspec);
172
173 static void
174 gst_text_render_base_init (gpointer g_class)
175 {
176   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
177
178   gst_element_class_add_pad_template (element_class,
179       gst_static_pad_template_get (&src_template_factory));
180   gst_element_class_add_pad_template (element_class,
181       gst_static_pad_template_get (&sink_template_factory));
182
183   gst_element_class_set_details_simple (element_class, "Text renderer",
184       "Filter/Editor/Video",
185       "Renders a text string to an image bitmap",
186       "David Schleef <ds@schleef.org>, "
187       "Ronald S. Bultje <rbultje@ronald.bitfreak.net>");
188 }
189
190 static void
191 gst_text_render_class_init (GstTextRenderClass * klass)
192 {
193   GObjectClass *gobject_class;
194   GstElementClass *gstelement_class;
195   PangoFontMap *fontmap;
196
197   gobject_class = (GObjectClass *) klass;
198   gstelement_class = (GstElementClass *) klass;
199
200   parent_class = g_type_class_peek_parent (klass);
201
202   gobject_class->finalize = gst_text_render_finalize;
203   gobject_class->set_property = gst_text_render_set_property;
204   gobject_class->get_property = gst_text_render_get_property;
205
206   fontmap = pango_cairo_font_map_get_default ();
207   klass->pango_context =
208       pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
209   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_FONT_DESC,
210       g_param_spec_string ("font-desc", "font description",
211           "Pango font description of font "
212           "to be used for rendering. "
213           "See documentation of "
214           "pango_font_description_from_string"
215           " for syntax.", "", G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
216   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_VALIGNMENT,
217       g_param_spec_enum ("valignment", "vertical alignment",
218           "Vertical alignment of the text", GST_TYPE_TEXT_RENDER_VALIGN,
219           DEFAULT_PROP_VALIGNMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
220   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HALIGNMENT,
221       g_param_spec_enum ("halignment", "horizontal alignment",
222           "Horizontal alignment of the text", GST_TYPE_TEXT_RENDER_HALIGN,
223           DEFAULT_PROP_HALIGNMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
224   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_XPAD,
225       g_param_spec_int ("xpad", "horizontal paddding",
226           "Horizontal paddding when using left/right alignment", 0, G_MAXINT,
227           DEFAULT_PROP_XPAD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
228   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_YPAD,
229       g_param_spec_int ("ypad", "vertical padding",
230           "Vertical padding when using top/bottom alignment", 0, G_MAXINT,
231           DEFAULT_PROP_YPAD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
232   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LINE_ALIGNMENT,
233       g_param_spec_enum ("line-alignment", "line alignment",
234           "Alignment of text lines relative to each other.",
235           GST_TYPE_TEXT_RENDER_LINE_ALIGN, DEFAULT_PROP_LINE_ALIGNMENT,
236           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
237 }
238
239 static void
240 gst_text_render_adjust_values_with_fontdesc (GstTextRender * render,
241     PangoFontDescription * desc)
242 {
243   gint font_size = pango_font_description_get_size (desc) / PANGO_SCALE;
244
245   render->shadow_offset = (double) (font_size) / 13.0;
246   render->outline_offset = (double) (font_size) / 15.0;
247   if (render->outline_offset < MINIMUM_OUTLINE_OFFSET)
248     render->outline_offset = MINIMUM_OUTLINE_OFFSET;
249 }
250
251 static void
252 gst_text_render_render_pangocairo (GstTextRender * render)
253 {
254   cairo_t *cr;
255   cairo_surface_t *surface;
256   cairo_t *cr_shadow;
257   cairo_surface_t *surface_shadow;
258   PangoRectangle ink_rect, logical_rect;
259   gint width, height;
260
261   pango_layout_get_pixel_extents (render->layout, &ink_rect, &logical_rect);
262
263   width = logical_rect.width + render->shadow_offset;
264   height = logical_rect.height + logical_rect.y + render->shadow_offset;
265
266   surface_shadow = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
267   cr_shadow = cairo_create (surface_shadow);
268
269   /* clear shadow surface */
270   cairo_set_operator (cr_shadow, CAIRO_OPERATOR_CLEAR);
271   cairo_paint (cr_shadow);
272   cairo_set_operator (cr_shadow, CAIRO_OPERATOR_OVER);
273
274   /* draw shadow text */
275   cairo_save (cr_shadow);
276   cairo_set_source_rgba (cr_shadow, 0.0, 0.0, 0.0, 0.5);
277   cairo_translate (cr_shadow, render->shadow_offset, render->shadow_offset);
278   pango_cairo_show_layout (cr_shadow, render->layout);
279   cairo_restore (cr_shadow);
280
281   /* draw outline text */
282   cairo_save (cr_shadow);
283   cairo_set_source_rgb (cr_shadow, 0.0, 0.0, 0.0);
284   cairo_set_line_width (cr_shadow, render->outline_offset);
285   pango_cairo_layout_path (cr_shadow, render->layout);
286   cairo_stroke (cr_shadow);
287   cairo_restore (cr_shadow);
288
289   cairo_destroy (cr_shadow);
290
291   render->text_image = g_realloc (render->text_image, 4 * width * height);
292
293   surface = cairo_image_surface_create_for_data (render->text_image,
294       CAIRO_FORMAT_ARGB32, width, height, width * 4);
295   cr = cairo_create (surface);
296   cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
297   cairo_paint (cr);
298   cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
299
300   /* set default color */
301   cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
302
303   cairo_save (cr);
304   /* draw text */
305   pango_cairo_show_layout (cr, render->layout);
306   cairo_restore (cr);
307
308   /* composite shadow with offset */
309   cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
310   cairo_set_source_surface (cr, surface_shadow, 0.0, 0.0);
311   cairo_paint (cr);
312
313   cairo_destroy (cr);
314   cairo_surface_destroy (surface_shadow);
315   cairo_surface_destroy (surface);
316   render->image_width = width;
317   render->image_height = height;
318 }
319
320 static void
321 gst_text_render_check_argb (GstTextRender * render)
322 {
323   GstCaps *peer_caps;
324   peer_caps = gst_pad_get_allowed_caps (render->srcpad);
325   if (G_LIKELY (peer_caps)) {
326     guint i = 0, n = 0;
327
328     n = gst_caps_get_size (peer_caps);
329     GST_DEBUG_OBJECT (render, "peer allowed caps (%u structure(s)) are %"
330         GST_PTR_FORMAT, n, peer_caps);
331
332     /* Check if AYUV or ARGB is first */
333     for (i = 0; i < n; i++) {
334       GstStructure *s = gst_caps_get_structure (peer_caps, i);
335       if (gst_structure_has_name (s, "video/x-raw-rgb") &&
336           gst_structure_has_field (s, "alpha_mask")) {
337         render->use_ARGB = TRUE;
338         break;
339       } else if (gst_structure_has_name (s, "video/x-raw-yuv")) {
340         guint fourcc;
341         if (gst_structure_get_fourcc (s, "format", &fourcc) &&
342             fourcc == GST_MAKE_FOURCC ('A', 'Y', 'U', 'V')) {
343           render->use_ARGB = FALSE;
344           break;
345         }
346       }
347     }
348     gst_caps_unref (peer_caps);
349   }
350 }
351
352 static gboolean
353 gst_text_render_setcaps (GstPad * pad, GstCaps * caps)
354 {
355   GstTextRender *render = GST_TEXT_RENDER (gst_pad_get_parent (pad));
356   GstStructure *structure;
357   gboolean ret = FALSE;
358   gint width = 0, height = 0;
359
360   structure = gst_caps_get_structure (caps, 0);
361   gst_structure_get_int (structure, "width", &width);
362   gst_structure_get_int (structure, "height", &height);
363
364   GST_DEBUG ("Got caps %" GST_PTR_FORMAT, caps);
365
366   if (width >= render->image_width && height >= render->image_height) {
367     render->width = width;
368     render->height = height;
369     ret = TRUE;
370   }
371
372   gst_text_render_check_argb (render);
373
374   gst_object_unref (render);
375   return ret;
376 }
377
378 static void
379 gst_text_render_fixate_caps (GstPad * pad, GstCaps * caps)
380 {
381   GstTextRender *render = GST_TEXT_RENDER (gst_pad_get_parent (pad));
382   GstStructure *s = gst_caps_get_structure (caps, 0);
383
384   GST_DEBUG ("Fixating caps %" GST_PTR_FORMAT, caps);
385   gst_structure_fixate_field_nearest_int (s, "width", render->image_width);
386   gst_structure_fixate_field_nearest_int (s, "height", render->image_height);
387   GST_DEBUG ("Fixated to    %" GST_PTR_FORMAT, caps);
388
389   gst_object_unref (render);
390 }
391
392 static void
393 gst_text_renderer_image_to_ayuv (GstTextRender * render, guchar * pixbuf,
394     int xpos, int ypos, int stride)
395 {
396   int y;                        /* text bitmap coordinates */
397   guchar *p, *bitp;
398   guchar a, r, g, b;
399   int width, height;
400
401   width = render->image_width;
402   height = render->image_height;
403   bitp = render->text_image;
404
405   for (y = 0; y < height; y++) {
406     int n;
407     p = pixbuf + (ypos + y) * stride + xpos * 4;
408     for (n = 0; n < width; n++) {
409       b = bitp[CAIRO_ARGB_B];
410       g = bitp[CAIRO_ARGB_G];
411       r = bitp[CAIRO_ARGB_R];
412       a = bitp[CAIRO_ARGB_A];
413       bitp += 4;
414
415       *p++ = a;
416       *p++ = CLAMP ((int) (((19595 * r) >> 16) + ((38470 * g) >> 16) +
417               ((7471 * b) >> 16)), 0, 255);
418       *p++ = CLAMP ((int) (-((11059 * r) >> 16) - ((21709 * g) >> 16) +
419               ((32768 * b) >> 16) + 128), 0, 255);
420       *p++ = CLAMP ((int) (((32768 * r) >> 16) - ((27439 * g) >> 16) -
421               ((5329 * b) >> 16) + 128), 0, 255);
422     }
423   }
424 }
425
426 static void
427 gst_text_renderer_image_to_argb (GstTextRender * render, guchar * pixbuf,
428     int xpos, int ypos, int stride)
429 {
430   int i, j;
431   guchar *p, *bitp;
432   int width, height;
433
434   width = render->image_width;
435   height = render->image_height;
436   bitp = render->text_image;
437
438   for (i = 0; i < height; i++) {
439     p = pixbuf + (ypos + i) * stride + xpos * 4;
440     for (j = 0; j < width; j++) {
441       p[0] = bitp[CAIRO_ARGB_A];
442       p[1] = bitp[CAIRO_ARGB_R];
443       p[2] = bitp[CAIRO_ARGB_G];
444       p[3] = bitp[CAIRO_ARGB_B];
445
446       bitp += 4;
447       p += 4;
448     }
449   }
450 }
451
452 static GstFlowReturn
453 gst_text_render_chain (GstPad * pad, GstBuffer * inbuf)
454 {
455   GstTextRender *render;
456   GstFlowReturn ret;
457   GstBuffer *outbuf;
458   GstCaps *caps = NULL;
459   guint8 *data = GST_BUFFER_DATA (inbuf);
460   guint size = GST_BUFFER_SIZE (inbuf);
461   gint n;
462   gint xpos, ypos;
463
464   render = GST_TEXT_RENDER (gst_pad_get_parent (pad));
465
466   /* somehow pango barfs over "\0" buffers... */
467   while (size > 0 &&
468       (data[size - 1] == '\r' ||
469           data[size - 1] == '\n' || data[size - 1] == '\0')) {
470     size--;
471   }
472
473   /* render text */
474   GST_DEBUG ("rendering '%*s'", size, data);
475   pango_layout_set_markup (render->layout, (gchar *) data, size);
476   gst_text_render_render_pangocairo (render);
477
478   gst_text_render_check_argb (render);
479
480   if (!render->use_ARGB) {
481     caps =
482         gst_video_format_new_caps (GST_VIDEO_FORMAT_AYUV, render->width,
483         render->height, 1, 1, 1, 1);
484   } else {
485     caps =
486         gst_video_format_new_caps (GST_VIDEO_FORMAT_ARGB, render->width,
487         render->height, 1, 1, 1, 1);
488   }
489
490   if (!gst_pad_set_caps (render->srcpad, caps)) {
491     gst_caps_unref (caps);
492     GST_ELEMENT_ERROR (render, CORE, NEGOTIATION, (NULL), (NULL));
493     ret = GST_FLOW_ERROR;
494     goto done;
495   }
496
497   GST_DEBUG ("Allocating buffer WxH = %dx%d", render->width, render->height);
498   ret =
499       gst_pad_alloc_buffer_and_set_caps (render->srcpad, GST_BUFFER_OFFSET_NONE,
500       render->width * render->height * 4, caps, &outbuf);
501
502   if (ret != GST_FLOW_OK)
503     goto done;
504
505   gst_buffer_copy_metadata (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS);
506   data = GST_BUFFER_DATA (outbuf);
507
508   if (render->use_ARGB) {
509     memset (data, 0, render->width * render->height * 4);
510   } else {
511     for (n = 0; n < render->width * render->height; n++) {
512       data[n * 4] = data[n * 4 + 1] = 0;
513       data[n * 4 + 2] = data[n * 4 + 3] = 128;
514     }
515   }
516
517   switch (render->halign) {
518     case GST_TEXT_RENDER_HALIGN_LEFT:
519       xpos = render->xpad;
520       break;
521     case GST_TEXT_RENDER_HALIGN_CENTER:
522       xpos = (render->width - render->image_width) / 2;
523       break;
524     case GST_TEXT_RENDER_HALIGN_RIGHT:
525       xpos = render->width - render->image_width - render->xpad;
526       break;
527     default:
528       xpos = 0;
529   }
530
531   switch (render->valign) {
532     case GST_TEXT_RENDER_VALIGN_BOTTOM:
533       ypos = render->height - render->image_height - render->ypad;
534       break;
535     case GST_TEXT_RENDER_VALIGN_BASELINE:
536       ypos = render->height - (render->image_height + render->ypad);
537       break;
538     case GST_TEXT_RENDER_VALIGN_TOP:
539       ypos = render->ypad;
540       break;
541     default:
542       ypos = render->ypad;
543       break;
544   }
545
546   if (render->text_image) {
547     if (render->use_ARGB) {
548       gst_text_renderer_image_to_argb (render, data, xpos, ypos,
549           render->width * 4);
550     } else {
551       gst_text_renderer_image_to_ayuv (render, data, xpos, ypos,
552           render->width * 4);
553     }
554   }
555
556   ret = gst_pad_push (render->srcpad, outbuf);
557
558 done:
559   if (caps)
560     gst_caps_unref (caps);
561   gst_buffer_unref (inbuf);
562   gst_object_unref (render);
563   return ret;
564 }
565
566 static void
567 gst_text_render_finalize (GObject * object)
568 {
569   GstTextRender *render = GST_TEXT_RENDER (object);
570
571   g_free (render->text_image);
572
573   if (render->layout)
574     g_object_unref (render->layout);
575
576   G_OBJECT_CLASS (parent_class)->finalize (object);
577 }
578
579 static void
580 gst_text_render_init (GstTextRender * render, GstTextRenderClass * klass)
581 {
582   GstPadTemplate *template;
583
584   /* sink */
585   template = gst_static_pad_template_get (&sink_template_factory);
586   render->sinkpad = gst_pad_new_from_template (template, "sink");
587   gst_object_unref (template);
588   gst_pad_set_chain_function (render->sinkpad,
589       GST_DEBUG_FUNCPTR (gst_text_render_chain));
590   gst_element_add_pad (GST_ELEMENT (render), render->sinkpad);
591
592   /* source */
593   template = gst_static_pad_template_get (&src_template_factory);
594   render->srcpad = gst_pad_new_from_template (template, "src");
595   gst_object_unref (template);
596   gst_pad_set_fixatecaps_function (render->srcpad,
597       GST_DEBUG_FUNCPTR (gst_text_render_fixate_caps));
598   gst_pad_set_setcaps_function (render->srcpad,
599       GST_DEBUG_FUNCPTR (gst_text_render_setcaps));
600
601   gst_element_add_pad (GST_ELEMENT (render), render->srcpad);
602
603   render->line_align = DEFAULT_PROP_LINE_ALIGNMENT;
604   render->layout =
605       pango_layout_new (GST_TEXT_RENDER_GET_CLASS (render)->pango_context);
606   pango_layout_set_alignment (render->layout,
607       (PangoAlignment) render->line_align);
608
609   render->halign = DEFAULT_PROP_HALIGNMENT;
610   render->valign = DEFAULT_PROP_VALIGNMENT;
611   render->xpad = DEFAULT_PROP_XPAD;
612   render->ypad = DEFAULT_PROP_YPAD;
613
614   render->width = DEFAULT_RENDER_WIDTH;
615   render->height = DEFAULT_RENDER_HEIGHT;
616
617   render->use_ARGB = FALSE;
618 }
619
620 static void
621 gst_text_render_set_property (GObject * object, guint prop_id,
622     const GValue * value, GParamSpec * pspec)
623 {
624   GstTextRender *render = GST_TEXT_RENDER (object);
625
626   switch (prop_id) {
627     case PROP_VALIGNMENT:
628       render->valign = g_value_get_enum (value);
629       break;
630     case PROP_HALIGNMENT:
631       render->halign = g_value_get_enum (value);
632       break;
633     case PROP_LINE_ALIGNMENT:
634       render->line_align = g_value_get_enum (value);
635       pango_layout_set_alignment (render->layout,
636           (PangoAlignment) render->line_align);
637       break;
638     case PROP_XPAD:
639       render->xpad = g_value_get_int (value);
640       break;
641     case PROP_YPAD:
642       render->ypad = g_value_get_int (value);
643       break;
644     case PROP_FONT_DESC:
645     {
646       PangoFontDescription *desc;
647
648       desc = pango_font_description_from_string (g_value_get_string (value));
649       if (desc) {
650         GST_LOG ("font description set: %s", g_value_get_string (value));
651         GST_OBJECT_LOCK (render);
652         pango_layout_set_font_description (render->layout, desc);
653         gst_text_render_adjust_values_with_fontdesc (render, desc);
654         pango_font_description_free (desc);
655         gst_text_render_render_pangocairo (render);
656         GST_OBJECT_UNLOCK (render);
657       } else {
658         GST_WARNING ("font description parse failed: %s",
659             g_value_get_string (value));
660       }
661       break;
662     }
663
664     default:
665       break;
666   }
667 }
668
669 static void
670 gst_text_render_get_property (GObject * object, guint prop_id,
671     GValue * value, GParamSpec * pspec)
672 {
673   GstTextRender *render = GST_TEXT_RENDER (object);
674
675   switch (prop_id) {
676     case PROP_VALIGNMENT:
677       g_value_set_enum (value, render->valign);
678       break;
679     case PROP_HALIGNMENT:
680       g_value_set_enum (value, render->halign);
681       break;
682     case PROP_LINE_ALIGNMENT:
683       g_value_set_enum (value, render->line_align);
684       break;
685     case PROP_XPAD:
686       g_value_set_int (value, render->xpad);
687       break;
688     case PROP_YPAD:
689       g_value_set_int (value, render->ypad);
690       break;
691     default:
692       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
693       break;
694   }
695 }