* Copyright (C) 2003-2004 Ushodaya Enterprises Limited
* Author: Dan Dennedy <dan@dennedy.org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "producer_pango.h"
+#include <framework/mlt_producer.h>
#include <framework/mlt_frame.h>
#include <framework/mlt_geometry.h>
#include <stdlib.h>
#include <freetype/freetype.h>
#include <iconv.h>
#include <pthread.h>
+#include <ctype.h>
+
+typedef struct producer_pango_s *producer_pango;
+
+typedef enum
+{
+ pango_align_left = 0,
+ pango_align_center,
+ pango_align_right
+} pango_align;
static pthread_mutex_t pango_mutex = PTHREAD_MUTEX_INITIALIZER;
( *strrchr( markup, '.' ) ) = '\0';
while ( strchr( markup, '~' ) )
( *strchr( markup, '~' ) ) = '\n';
- mlt_properties_set( properties, "resource", ( char * )filename );
+ mlt_properties_set( properties, "resource", filename );
mlt_properties_set( properties, "markup", markup );
free( copy );
}
mlt_properties contents = mlt_properties_load( filename );
mlt_geometry key_frames = mlt_geometry_init( );
struct mlt_geometry_item_s item;
- mlt_properties_set( properties, "resource", ( char * )filename );
+ mlt_properties_set( properties, "resource", filename );
mlt_properties_set_data( properties, "contents", contents, 0, ( mlt_destructor )mlt_properties_close, NULL );
mlt_properties_set_data( properties, "key_frames", key_frames, 0, ( mlt_destructor )mlt_geometry_close, NULL );
if ( markup[ strlen( markup ) - 1 ] == '\n' )
markup[ strlen( markup ) - 1 ] = '\0';
- mlt_properties_set( properties, "resource", ( char * ) filename );
- mlt_properties_set( properties, "markup", ( char * ) ( markup == NULL ? "" : markup ) );
+ mlt_properties_set( properties, "resource", filename );
+ mlt_properties_set( properties, "markup", ( markup == NULL ? "" : markup ) );
free( markup );
}
else
return NULL;
}
-static void set_string( char **string, char *value, char *fallback )
+static void set_string( char **string, const char *value, const char *fallback )
{
if ( value != NULL )
{
/** Convert a string property to UTF-8
*/
-static int iconv_utf8( mlt_properties properties, char *prop_name, const char* encoding )
+static int iconv_utf8( mlt_properties properties, const char *prop_name, const char* encoding )
{
char *text = mlt_properties_get( properties, prop_name );
int result = -1;
else if ( strcmp( interps, "hyper" ) == 0 )
interp = GDK_INTERP_HYPER;
-// fprintf( stderr, "SCALING PANGO from %dx%d to %dx%d was %dx%d\n", gdk_pixbuf_get_width( pixbuf ), gdk_pixbuf_get_height( pixbuf ), width, height, this->width, this->height );
-
+// fprintf(stderr,"%s: scaling from %dx%d to %dx%d\n", __FILE__, this->width, this->height, width, height);
+
// Note - the original pixbuf is already safe and ready for destruction
pixbuf = gdk_pixbuf_scale_simple( pixbuf, width, height, interp );
producer_pango this = producer->child;
// Generate a frame
- *frame = mlt_frame_init( );
+ *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
// Obtain properties of frame and producer
mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
pango_layout_set_width( layout, -1 ); // set wrapping constraints
pango_font_description_set_weight( desc, ( PangoWeight ) weight );
if ( size != 0 )
- pango_font_description_set_size( desc, PANGO_SCALE * size );
+ pango_font_description_set_absolute_size( desc, PANGO_SCALE * size );
pango_layout_set_font_description( layout, desc );
// pango_layout_set_spacing( layout, space );
pango_layout_set_alignment( layout, ( PangoAlignment ) align );
if ( markup != NULL && strcmp( markup, "" ) != 0 )
+ {
pango_layout_set_markup( layout, markup, strlen( markup ) );
+ }
else if ( text != NULL && strcmp( text, "" ) != 0 )
- pango_layout_set_text( layout, text, strlen( text ) );
+ {
+ // Replace all ~'s with a line feed (silly convention, but handy)
+ char *copy = strdup( text );
+ while ( strchr( copy, '~' ) )
+ ( *strchr( copy, '~' ) ) = '\n';
+ pango_layout_set_text( layout, copy, strlen( copy ) );
+ free( copy );
+ }
else
+ {
+ // Pango doesn't like empty strings
pango_layout_set_text( layout, " ", 2 );
+ }
pango_layout_get_pixel_size( layout, &w, &h );
+ // Interpret size property as an absolute pixel height and compensate for
+ // freetype's "interpretation" of our absolute size request. This gives
+ // precise control over compositing and better quality by reducing scaling
+ // artifacts with composite geometries that constrain the dimensions.
+ // If you do not want this, then put the size in the font property or in
+ // the pango markup.
+ if ( size != 0 )
+ {
+ pango_font_description_set_absolute_size( desc, PANGO_SCALE * size * size/h );
+ pango_layout_set_font_description( layout, desc );
+ pango_layout_get_pixel_size( layout, &w, &h );
+ }
+
pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE /* has alpha */, 8, w + 2 * pad, h + 2 * pad );
pango_draw_background( pixbuf, bg );