1 /*****************************************************************************
2 * gtk2_font.cpp: GTK2 implementation of the Font class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2_font.cpp,v 1.8 2003/04/17 15:43:29 karibu Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
23 *****************************************************************************/
27 //--- GTK2 -----------------------------------------------------------------
30 //--- VLC -------------------------------------------------------------------
33 //--- SKIN ------------------------------------------------------------------
34 #include "../src/graphics.h"
35 #include "../os_graphics.h"
36 #include "../src/font.h"
37 #include "../os_font.h"
41 //---------------------------------------------------------------------------
43 //---------------------------------------------------------------------------
44 GTK2Font::GTK2Font( intf_thread_t *_p_intf, string fontname, int size,
45 int color, int weight, bool italic, bool underline )
46 : Font( _p_intf, fontname, size, color, weight, italic, underline )
48 Context = gdk_pango_context_get();
49 Layout = pango_layout_new( Context );
51 // Text properties setting
52 FontDesc = pango_font_description_new();
54 pango_font_description_set_family( FontDesc, fontname.c_str() );
56 pango_font_description_set_size( FontDesc, size * PANGO_SCALE );
59 pango_font_description_set_style( FontDesc, PANGO_STYLE_ITALIC );
61 pango_font_description_set_style( FontDesc, PANGO_STYLE_NORMAL );
63 pango_font_description_set_weight( FontDesc, (PangoWeight)weight );
65 /* FIXME: underline parameter */
68 pango_layout_set_font_description( Layout, FontDesc );
70 //---------------------------------------------------------------------------
74 //---------------------------------------------------------------------------
75 void GTK2Font::AssignFont( Graphics *dest )
78 //---------------------------------------------------------------------------
79 void GTK2Font::GetSize( string text, int &w, int &h )
81 pango_layout_set_text( Layout, text.c_str(), text.length() );
82 pango_layout_get_pixel_size( Layout, &w, &h );
84 //---------------------------------------------------------------------------
85 void GTK2Font::GenericPrint( Graphics *dest, string text, int x, int y,
86 int w, int h, int align, int color )
89 GdkDrawable *drawable = ( (GTK2Graphics *)dest )->GetImage();
90 GdkGC *gc = ( (GTK2Graphics *)dest )->GetGC();
93 pango_layout_set_text( Layout, text.c_str(), text.length() );
94 pango_layout_set_width( Layout, w * PANGO_SCALE );
97 pango_layout_set_alignment( Layout, (PangoAlignment)align );
98 gdk_rgb_gc_set_foreground( gc, color );
101 gdk_draw_layout( drawable, gc, x, y, Layout );
104 //---------------------------------------------------------------------------
105 void GTK2Font::Print( Graphics *dest, string text, int x, int y, int w,
108 GenericPrint( dest, text, x, y, w, h, align, Color );
110 //---------------------------------------------------------------------------
111 void GTK2Font::PrintColor( Graphics *dest, string text, int x, int y, int w,
112 int h, int align, int color )
114 GenericPrint( dest, text, x, y, w, h, align, color );
116 //---------------------------------------------------------------------------