]> git.sesse.net Git - vlc/blob - modules/gui/skins/x11/x11_font.cpp
* AT LAST events work in X11 skins !
[vlc] / modules / gui / skins / x11 / x11_font.cpp
1 /*****************************************************************************
2  * x11_font.cpp: X11 implementation of the Font class
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: x11_font.cpp,v 1.3 2003/05/19 21:39:34 asmax Exp $
6  *
7  * Authors: Cyril Deguet     <asmax@videolan.org>
8  *          Emmanuel Puig    <karibu@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
23  * USA.
24  *****************************************************************************/
25
26 #ifdef X11_SKINS
27
28 //--- X11 -----------------------------------------------------------------
29 #include <X11/Xlib.h>
30
31 //--- VLC -------------------------------------------------------------------
32 #include <vlc/intf.h>
33
34 //--- SKIN ------------------------------------------------------------------
35 #include "../src/graphics.h"
36 #include "../os_graphics.h"
37 #include "../src/font.h"
38 #include "../os_font.h"
39
40
41
42 //---------------------------------------------------------------------------
43 // Font object
44 //---------------------------------------------------------------------------
45 X11Font::X11Font( intf_thread_t *_p_intf, string fontname, int size,
46     int color, int weight, bool italic, bool underline )
47     : SkinFont( _p_intf, fontname, size, color, weight, italic, underline )
48 {
49 /*    Context = gdk_pango_context_get();
50     Layout = pango_layout_new( Context );
51
52     // Text properties setting
53     FontDesc    = pango_font_description_new();
54
55     pango_font_description_set_family( FontDesc, fontname.c_str() );
56
57     pango_font_description_set_size( FontDesc, size * PANGO_SCALE );
58
59     if( italic )
60     {
61         pango_font_description_set_style( FontDesc, PANGO_STYLE_ITALIC );
62     }
63     else
64     {
65         pango_font_description_set_style( FontDesc, PANGO_STYLE_NORMAL );
66     }
67
68     pango_font_description_set_weight( FontDesc, (PangoWeight)weight );
69
70     //pango_context_set_font_description( Context, FontDesc );
71     pango_layout_set_font_description( Layout, FontDesc );
72
73     // Set attributes
74     PangoAttrList *attrs = pango_attr_list_new();
75     // FIXME: doesn't work 
76     if( underline )
77     {
78         pango_attr_list_insert( attrs, 
79             pango_attr_underline_new( PANGO_UNDERLINE_SINGLE ) );
80     }
81     pango_layout_set_attributes( Layout, attrs );*/
82 }
83 //---------------------------------------------------------------------------
84 X11Font::~X11Font()
85 {
86 }
87 //---------------------------------------------------------------------------
88 void X11Font::AssignFont( Graphics *dest )
89 {
90 }
91 //---------------------------------------------------------------------------
92 void X11Font::GetSize( string text, int &w, int &h )
93 {
94     w = 42;
95     h = 12;
96 /*    pango_layout_set_text( Layout, text.c_str(), text.length() );
97     pango_layout_get_pixel_size( Layout, &w, &h );*/
98 }
99 //---------------------------------------------------------------------------
100 void X11Font::GenericPrint( Graphics *dest, string text, int x, int y,
101                                  int w, int h, int align, int color )
102 {
103 /*    // Set text
104     pango_layout_set_text( Layout, text.c_str(), -1 );
105
106     // Set size
107     pango_layout_set_width( Layout, -1 );
108     int real_w, real_h;
109
110     // Create buffer image
111     Graphics* cov = (Graphics *)new OSGraphics( w, h );
112     cov->CopyFrom( 0, 0, w, h, dest, x, y, SRC_COPY );
113
114     // Get handles
115     GdkDrawable *drawable = ( (X11Graphics *)cov )->GetImage();
116     GdkGC *gc = ( (X11Graphics *)cov )->GetGC();
117
118     // Set width of text
119     pango_layout_set_width( Layout, w * PANGO_SCALE );
120
121     // Set attributes
122     pango_layout_set_alignment( Layout, (PangoAlignment)align );
123     
124     // Avoid transârency for black text
125     if( color == 0 ) color = 10;
126     gdk_rgb_gc_set_foreground( gc, color );
127
128     // Render text on buffer
129     gdk_draw_layout( drawable, gc, 0, 0, Layout );
130
131     // Copy buffer on dest graphics
132     dest->CopyFrom( x, y, w, h, cov, 0, 0, SRC_COPY );
133
134     // Free memory
135     delete (OSGraphics *)cov;*/
136 }
137
138 //---------------------------------------------------------------------------
139 void X11Font::Print( Graphics *dest, string text, int x, int y, int w,
140                        int h, int align )
141 {
142     GenericPrint( dest, text, x, y, w, h, align, Color );
143 }
144 //---------------------------------------------------------------------------
145 void X11Font::PrintColor( Graphics *dest, string text, int x, int y, int w,
146                             int h, int align, int color )
147 {
148     GenericPrint( dest, text, x, y, w, h, align, color );
149 }
150 //---------------------------------------------------------------------------
151
152 #endif