Hi,

attached patch implement text rotation in pango producer.

example of usage:

melt \
    -v \
    -profile square_pal \
    /tmp/demo.mp4 \
    -consumer sdl \
    -filter watermark:pango \
        producer.force_apect_ratio="@1/1" \
        producer.text="Hi, here!" \
        producer.family="Arial" \
        producer.size="32" \
        producer.weight="700" \
        producer.fgcolour="#FF000000" \
        producer.bgcolour="#48CCCCFF" \
        producer.rot_angle="48" \
        composite.geometry="300/-300:100%x100%:100%" \
        composite.halign="left" \
        composite.valign="bottom"

--
________________________________________
Maksym Veremeyenko
>From cd4dab4903761af2902a9cad6aa210a86e09af2b Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <ve...@m1.tv>
Date: Sun, 10 May 2015 19:21:51 +0200
Subject: [PATCH] Implement text rotation in pango producer

---
 src/modules/gtk2/producer_pango.c   |   47 +++++++++++++++++++++++++++++++---
 src/modules/gtk2/producer_pango.yml |   10 +++++++
 2 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/src/modules/gtk2/producer_pango.c b/src/modules/gtk2/producer_pango.c
index c450de5..d6f5c68 100644
--- a/src/modules/gtk2/producer_pango.c
+++ b/src/modules/gtk2/producer_pango.c
@@ -80,6 +80,7 @@ struct producer_pango_s
 	int   size;
 	int   style;
 	int   weight;
+	int   rot_angle;
 };
 
 static void clean_cached( producer_pango self )
@@ -98,7 +99,7 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int ind
 static void producer_close( mlt_producer parent );
 static void pango_draw_background( GdkPixbuf *pixbuf, rgba_color bg );
 static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const char *font,
-		rgba_color fg, rgba_color bg, rgba_color ol, int pad, int align, char* family, int style, int weight, int size, int outline );
+		rgba_color fg, rgba_color bg, rgba_color ol, int pad, int align, char* family, int style, int weight, int size, int outline, int rot_angle );
 static void fill_pixbuf( GdkPixbuf* pixbuf, FT_Bitmap* bitmap, int w, int h, int pad, int align, rgba_color fg, rgba_color bg );
 static void fill_pixbuf_with_outline( GdkPixbuf* pixbuf, FT_Bitmap* bitmap, int w, int h, int pad, int align, rgba_color fg, rgba_color bg, rgba_color ol, int outline );
 
@@ -179,6 +180,7 @@ mlt_producer producer_pango_init( const char *filename )
 		mlt_properties_set( properties, "style", "normal" );
 		mlt_properties_set( properties, "encoding", "UTF-8" );
 		mlt_properties_set_int( properties, "weight", PANGO_WEIGHT_NORMAL );
+		mlt_properties_set_int( properties, "rot_angle", 0 );
 		mlt_properties_set_int( properties, "seekable", 1 );
 
 		if ( filename == NULL || ( filename && ( !strcmp( filename, "" )
@@ -394,6 +396,7 @@ static void refresh_image( mlt_frame frame, int width, int height )
 	int style = parse_style( mlt_properties_get( producer_props, "style" ) );
 	char *encoding = mlt_properties_get( producer_props, "encoding" );
 	int weight = mlt_properties_get_int( producer_props, "weight" );
+	int rot_angle = mlt_properties_get_int( producer_props, "rot_angle" );
 	int size = mlt_properties_get_int( producer_props, "size" );
 	int property_changed = 0;
 
@@ -423,6 +426,7 @@ static void refresh_image( mlt_frame frame, int width, int height )
 		property_changed = property_changed || ( font && this->font && strcmp( font, this->font ) );
 		property_changed = property_changed || ( family && this->family && strcmp( family, this->family ) );
 		property_changed = property_changed || ( weight != this->weight );
+		property_changed = property_changed || ( rot_angle != this->rot_angle );
 		property_changed = property_changed || ( style != this->style );
 		property_changed = property_changed || ( size != this->size );
 
@@ -438,6 +442,7 @@ static void refresh_image( mlt_frame frame, int width, int height )
 		set_string( &this->font, font, NULL );
 		set_string( &this->family, family, "Sans" );
 		this->weight = weight;
+		this->rot_angle = rot_angle;
 		this->style = style;
 		this->size = size;
 	}
@@ -469,7 +474,7 @@ static void refresh_image( mlt_frame frame, int width, int height )
 		}
 		
 		// Render the title
-		pixbuf = pango_get_pixbuf( markup, text, font, fgcolor, bgcolor, olcolor, pad, align, family, style, weight, size, outline );
+		pixbuf = pango_get_pixbuf( markup, text, font, fgcolor, bgcolor, olcolor, pad, align, family, style, weight, size, outline, rot_angle );
 
 		if ( pixbuf != NULL )
 		{
@@ -735,11 +740,12 @@ static void pango_draw_background( GdkPixbuf *pixbuf, rgba_color bg )
 	}
 }
 
-static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const char *font, rgba_color fg, rgba_color bg, rgba_color ol, int pad, int align, char* family, int style, int weight, int size, int outline )
+static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const char *font, rgba_color fg, rgba_color bg, rgba_color ol, int pad, int align, char* family, int style, int weight, int size, int outline, int rot_angle )
 {
 	PangoContext *context = pango_ft2_font_map_create_context( fontmap );
 	PangoLayout *layout = pango_layout_new( context );
 	int w, h;
+	int x = 0, y = 0;
 	GdkPixbuf *pixbuf = NULL;
 	FT_Bitmap bitmap;
 	PangoFontDescription *desc = NULL;
@@ -780,7 +786,38 @@ static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const
 		// Pango doesn't like empty strings
 		pango_layout_set_text( layout, "  ", 2 );
 	}
-	pango_layout_get_pixel_size( layout, &w, &h );
+
+	if ( rot_angle )
+	{
+		double n_x, n_y;
+		PangoRectangle rect;
+		PangoMatrix m_layout = PANGO_MATRIX_INIT, m_offset = PANGO_MATRIX_INIT;
+
+		pango_matrix_rotate( &m_layout, rot_angle );
+		pango_matrix_rotate( &m_offset, -rot_angle );
+
+		pango_context_set_base_gravity( context, PANGO_GRAVITY_AUTO );
+		pango_context_set_matrix( context, &m_layout );
+		pango_layout_context_changed( layout );
+		pango_layout_get_extents( layout, NULL, &rect );
+		pango_matrix_transform_rectangle( pango_context_get_matrix( context ), &rect);
+
+		n_x = -rect.x;
+		n_y = -rect.y;
+		pango_matrix_transform_point( &m_offset, &n_x, &n_y );
+		rect.x = n_x;
+		rect.y = n_y;
+
+		pango_extents_to_pixels( &rect, NULL );
+
+		w = rect.width;
+		h = rect.height;
+
+		x = rect.x;
+		y = rect.y;
+	}
+	else
+		pango_layout_get_pixel_size( layout, &w, &h );
 
 	if ( pad == 0 )
 		pad = 1;
@@ -797,7 +834,7 @@ static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const
 
 	memset( bitmap.buffer, 0, h * bitmap.pitch );
 
-	pango_ft2_render_layout( &bitmap, layout, 0, 0 );
+	pango_ft2_render_layout( &bitmap, layout, x, y );
 
 	if ( outline )
 	{
diff --git a/src/modules/gtk2/producer_pango.yml b/src/modules/gtk2/producer_pango.yml
index 0096322..68fd1c3 100644
--- a/src/modules/gtk2/producer_pango.yml
+++ b/src/modules/gtk2/producer_pango.yml
@@ -223,3 +223,13 @@ parameters:
     type: float
     description: Optionally override a (mis)detected aspect ratio
     mutable: yes
+
+  - identifier: rot_angle
+    title: Rotation angle
+    type: integer
+    description: >
+      The angle of text rotation in degrees. Positive value is clockwise.
+    default: 0
+    readonly: no
+    mutable: yes
+    widget: spinner
-- 
1.7.7.6

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Mlt-devel mailing list
Mlt-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlt-devel

Reply via email to