]> git.sesse.net Git - vlc/blob - modules/gui/skins/gtk2/gtk2_font.cpp
* Improved font support for linux (just missing underline parameter )
[vlc] / modules / gui / skins / gtk2 / gtk2_font.cpp
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 $
6  *
7  * Authors: Cyril Deguet     <asmax@videolan.org>
8  *
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.
13  *
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.
18  *
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,
22  * USA.
23  *****************************************************************************/
24
25 #if !defined WIN32
26
27 //--- GTK2 -----------------------------------------------------------------
28 #include <gdk/gdk.h>
29
30 //--- VLC -------------------------------------------------------------------
31 #include <vlc/intf.h>
32
33 //--- SKIN ------------------------------------------------------------------
34 #include "../src/graphics.h"
35 #include "../os_graphics.h"
36 #include "../src/font.h"
37 #include "../os_font.h"
38
39
40
41 //---------------------------------------------------------------------------
42 // Font object
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 )
47 {
48     Context = gdk_pango_context_get();
49     Layout = pango_layout_new( Context );
50
51     // Text properties setting
52     FontDesc = pango_font_description_new();
53
54     pango_font_description_set_family( FontDesc, fontname.c_str() );
55
56     pango_font_description_set_size( FontDesc, size * PANGO_SCALE );
57
58     if( italic )
59         pango_font_description_set_style( FontDesc, PANGO_STYLE_ITALIC );
60     else
61         pango_font_description_set_style( FontDesc, PANGO_STYLE_NORMAL );
62
63     pango_font_description_set_weight( FontDesc, (PangoWeight)weight );
64
65     /* FIXME: underline parameter */
66
67     // Set attributes
68     pango_layout_set_font_description( Layout, FontDesc );
69 }
70 //---------------------------------------------------------------------------
71 GTK2Font::~GTK2Font()
72 {
73 }
74 //---------------------------------------------------------------------------
75 void GTK2Font::AssignFont( Graphics *dest )
76 {
77 }
78 //---------------------------------------------------------------------------
79 void GTK2Font::GetSize( string text, int &w, int &h )
80 {
81     pango_layout_set_text( Layout, text.c_str(), text.length() );
82     pango_layout_get_pixel_size( Layout, &w, &h );
83 }
84 //---------------------------------------------------------------------------
85 void GTK2Font::GenericPrint( Graphics *dest, string text, int x, int y,
86                                  int w, int h, int align, int color )
87 {
88     // Get handles
89     GdkDrawable *drawable = ( (GTK2Graphics *)dest )->GetImage();
90     GdkGC *gc = ( (GTK2Graphics *)dest )->GetGC();
91
92     // Set text
93     pango_layout_set_text( Layout, text.c_str(), text.length() );
94     pango_layout_set_width( Layout, w * PANGO_SCALE );
95
96     // Set attributes
97     pango_layout_set_alignment( Layout, (PangoAlignment)align );
98     gdk_rgb_gc_set_foreground( gc, color );
99
100     // Render text
101     gdk_draw_layout( drawable, gc, x, y, Layout );
102 }
103
104 //---------------------------------------------------------------------------
105 void GTK2Font::Print( Graphics *dest, string text, int x, int y, int w,
106                        int h, int align )
107 {
108     GenericPrint( dest, text, x, y, w, h, align, Color );
109 }
110 //---------------------------------------------------------------------------
111 void GTK2Font::PrintColor( Graphics *dest, string text, int x, int y, int w,
112                             int h, int align, int color )
113 {
114     GenericPrint( dest, text, x, y, w, h, align, color );
115 }
116 //---------------------------------------------------------------------------
117
118 #endif