]> git.sesse.net Git - vlc/commitdiff
* Improved font support for linux (just missing underline parameter )
authorEmmanuel Puig <karibu@videolan.org>
Thu, 17 Apr 2003 15:43:30 +0000 (15:43 +0000)
committerEmmanuel Puig <karibu@videolan.org>
Thu, 17 Apr 2003 15:43:30 +0000 (15:43 +0000)
modules/gui/skins/gtk2/gtk2_font.cpp
modules/gui/skins/gtk2/gtk2_font.h
modules/gui/skins/os_font.h
modules/gui/skins/parser/wrappers.cpp

index 71ecad18eb8d9c7ee84620dfc8a90e792a191ffc..e2dad26e6d00f19f7d5cc6a8cd5724126ac95da4 100644 (file)
@@ -2,7 +2,7 @@
  * gtk2_font.cpp: GTK2 implementation of the Font class
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: gtk2_font.cpp,v 1.7 2003/04/17 13:46:55 karibu Exp $
+ * $Id: gtk2_font.cpp,v 1.8 2003/04/17 15:43:29 karibu Exp $
  *
  * Authors: Cyril Deguet     <asmax@videolan.org>
  *
@@ -32,9 +32,9 @@
 
 //--- SKIN ------------------------------------------------------------------
 #include "../src/graphics.h"
-#include "gtk2_graphics.h"
+#include "../os_graphics.h"
 #include "../src/font.h"
-#include "gtk2_font.h"
+#include "../os_font.h"
 
 
 
@@ -47,45 +47,33 @@ GTK2Font::GTK2Font( intf_thread_t *_p_intf, string fontname, int size,
 {
     Context = gdk_pango_context_get();
     Layout = pango_layout_new( Context );
+
+    // Text properties setting
+    FontDesc = pango_font_description_new();
+
+    pango_font_description_set_family( FontDesc, fontname.c_str() );
+
+    pango_font_description_set_size( FontDesc, size * PANGO_SCALE );
+
+    if( italic )
+        pango_font_description_set_style( FontDesc, PANGO_STYLE_ITALIC );
+    else
+        pango_font_description_set_style( FontDesc, PANGO_STYLE_NORMAL );
+
+    pango_font_description_set_weight( FontDesc, (PangoWeight)weight );
+
+    /* FIXME: underline parameter */
+
+    // Set attributes
+    pango_layout_set_font_description( Layout, FontDesc );
 }
 //---------------------------------------------------------------------------
 GTK2Font::~GTK2Font()
 {
 }
 //---------------------------------------------------------------------------
-/*void GTK2Font::AssignGTK2Font( GdkDrawable *DC )
-{
-    // Create font
-    HGDIOBJ fontObj = CreateFont(
-        -MulDiv( Size, GetDeviceCaps( DC, LOGPIXELSX ), 72 ),
-        0,
-        0,                  // angle of escapement
-        0,                  // base-line orientation angle
-        Weight,             // font weight
-        Italic,             // italic attribute flag
-        Underline,          // underline attribute flag
-        0,                  // strikeout attribute flag
-        ANSI_CHARSET,       // character set identifier
-        OUT_TT_PRECIS,      // output precision
-        0,                  // clipping precision
-        ANTIALIASED_QUALITY,      // output quality
-        0,                  // pitch and family
-        FontName.c_str()    // pointer to typeface name string
-    );
-
-    // Assign font to DC
-    SelectObject( DC, fontObj );
-
-    // Free memory
-    DeleteObject( fontObj );
-//    GdkGC *gc = gdk_gc_new( DC );
-//    gdk_gc_set_font( GFont, gc );
-}*/
-//---------------------------------------------------------------------------
 void GTK2Font::AssignFont( Graphics *dest )
 {
-/*    GdkDrawable *DC = ( (GTK2Graphics *)dest )->GetImageHandle();
-    AssignGTK2Font( DC );*/
 }
 //---------------------------------------------------------------------------
 void GTK2Font::GetSize( string text, int &w, int &h )
@@ -97,34 +85,19 @@ void GTK2Font::GetSize( string text, int &w, int &h )
 void GTK2Font::GenericPrint( Graphics *dest, string text, int x, int y,
                                  int w, int h, int align, int color )
 {
+    // Get handles
     GdkDrawable *drawable = ( (GTK2Graphics *)dest )->GetImage();
     GdkGC *gc = ( (GTK2Graphics *)dest )->GetGC();
-/*    HDC DC = ( (GTK2Graphics *)dest )->GetImageHandle();
-    // Set boundaries
-    LPRECT r = new RECT;
-    r->left   = x;
-    r->top    = y;
-    r->right  = x + w;
-    r->bottom = y + h;
-
-    // Get desktop Device Context
-    SetBkMode( DC, TRANSPARENT );
-
-    // Modify desktop attributes
-    AssignFont( dest );
 
-    // Change text color
-    SetTextColor( DC, color );
-
-    // Draw text on screen
-    DrawText( DC, text.c_str(), text.length(), r, align );
+    // Set text
+    pango_layout_set_text( Layout, text.c_str(), text.length() );
+    pango_layout_set_width( Layout, w * PANGO_SCALE );
 
-    // Set text color to black to avoid graphic bugs
-    SetTextColor( DC, 0 );
+    // Set attributes
+    pango_layout_set_alignment( Layout, (PangoAlignment)align );
+    gdk_rgb_gc_set_foreground( gc, color );
 
-    // Free memory
-    delete r;*/
-    pango_layout_set_text( Layout, text.c_str(), text.length() );
+    // Render text
     gdk_draw_layout( drawable, gc, x, y, Layout );
 }
 
index 4cf33ba9fffc886f6d2955227a545b87e6a411fa..3bfa62daa77f1db15773fc5b20d9b0c2e38058e3 100644 (file)
@@ -2,7 +2,7 @@
  * gtk2_font.h: GTK2 implementation of the Font class
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: gtk2_font.h,v 1.4 2003/04/17 13:46:55 karibu Exp $
+ * $Id: gtk2_font.h,v 1.5 2003/04/17 15:43:29 karibu Exp $
  *
  * Authors: Cyril Deguet     <asmax@videolan.org>
  *
@@ -41,8 +41,10 @@ class Graphics;
 class GTK2Font : Font
 {
     private:
-        PangoContext *Context;
-        PangoLayout *Layout;
+        PangoContext  *Context;
+        PangoLayout   *Layout;
+        PangoFontDescription *FontDesc;
+
         // Assign font to Device Context
         virtual void AssignFont( Graphics *dest );
 
index 71de1bcde06e83b103d42f35b9db29d0685fbcb0..6221cf4a630f5ffadabf52548a45ee6e13ad3696 100644 (file)
@@ -2,7 +2,7 @@
  * os_font.h: Wrapper for the OSFont class
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: os_font.h,v 1.3 2003/04/16 21:40:07 ipkiss Exp $
+ * $Id: os_font.h,v 1.4 2003/04/17 15:43:29 karibu Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
 #if defined( WIN32 )
     #include "win32/win32_font.h"
     #define OSFont Win32Font
-#else    
+
+    #define VLC_FONT_ALIGN_LEFT    DT_LEFT
+    #define VLC_FONT_ALIGN_CENTER  DT_CENTER
+    #define VLC_FONT_ALIGN_RIGHT   DT_RIGHT
+
+#else
     #include "gtk2/gtk2_font.h"
     #define OSFont GTK2Font
+
+    #define VLC_FONT_ALIGN_LEFT    PANGO_ALIGN_LEFT
+    #define VLC_FONT_ALIGN_CENTER  PANGO_ALIGN_CENTER
+    #define VLC_FONT_ALIGN_RIGHT   PANGO_ALIGN_RIGHT
+
 #endif
index 741f81791e8fc104166cb444431a111e485f7dfb..cde7b337fba15575693909ab39c44c8a391ddea9 100644 (file)
@@ -2,7 +2,7 @@
  * wrappers.cpp: Wrappers around C++ objects
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: wrappers.cpp,v 1.7 2003/04/16 21:40:07 ipkiss Exp $
+ * $Id: wrappers.cpp,v 1.8 2003/04/17 15:43:30 karibu Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -38,6 +38,7 @@ extern intf_thread_t *g_pIntf;
 #include "../src/banks.h"
 #include "../controls/controls.h"
 #include "../src/font.h"
+#include "../os_font.h"
 #include "../src/window.h"
 #include "../src/theme.h"
 #include "../src/skin_common.h"
@@ -385,12 +386,12 @@ static void ConvertCoords( char *coord, double *p_coord )
 static int ConvertAlign( char *align )
 {
     if( strcmp( align, "left" ) == 0 )
-        return DT_LEFT;
+        return VLC_FONT_ALIGN_LEFT;
     else if( strcmp( align, "right" ) == 0 )
-        return DT_RIGHT;
+        return VLC_FONT_ALIGN_RIGHT;
     else if( strcmp( align, "center" ) == 0 )
-        return DT_CENTER;
+        return VLC_FONT_ALIGN_CENTER;
     else
-        return DT_LEFT;
+        return VLC_FONT_ALIGN_LEFT;
 }
 //---------------------------------------------------------------------------