gtk2_font.cpp 5.89 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * gtk2_font.cpp: GTK2 implementation of the Font class
 *****************************************************************************
 * Copyright (C) 2003 VideoLAN
Cyril Deguet's avatar
Cyril Deguet committed
5
 * $Id: gtk2_font.cpp,v 1.6 2003/04/17 10:42:41 asmax Exp $
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * Authors: Cyril Deguet     <asmax@videolan.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 program 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.
 *
 * 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,
 * USA.
 *****************************************************************************/

25
#if !defined WIN32
26 27

//--- GTK2 -----------------------------------------------------------------
28
#include <gdk/gdk.h>
29 30 31 32 33

//--- VLC -------------------------------------------------------------------
#include <vlc/intf.h>

//--- SKIN ------------------------------------------------------------------
34
#include "../src/graphics.h"
35
#include "gtk2_graphics.h"
36
#include "../src/font.h"
37 38 39
#include "gtk2_font.h"


40

41 42 43 44 45 46 47
//---------------------------------------------------------------------------
// Font object
//---------------------------------------------------------------------------
GTK2Font::GTK2Font( intf_thread_t *_p_intf, string fontname, int size,
    int color, int weight, bool italic, bool underline )
    : Font( _p_intf, fontname, size, color, weight, italic, underline )
{
48 49 50 51 52 53
/* FIXME */
/*    GFont = gdk_font_load( "-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1" );
    if( GFont == NULL )
    {
        msg_Err( _p_intf, "Could not load font %s", fontname.c_str());
    }*/
Cyril Deguet's avatar
Cyril Deguet committed
54 55
    Context = gdk_pango_context_get();
    Layout = pango_layout_new( Context );
56 57 58 59 60 61
}
//---------------------------------------------------------------------------
GTK2Font::~GTK2Font()
{
}
//---------------------------------------------------------------------------
62
/*void GTK2Font::AssignGTK2Font( GdkDrawable *DC )
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
{
    // 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 );
87 88
//    GdkGC *gc = gdk_gc_new( DC );
//    gdk_gc_set_font( GFont, gc );
89
}*/
90 91
//---------------------------------------------------------------------------
void GTK2Font::AssignFont( Graphics *dest )
92 93
{
/*    GdkDrawable *DC = ( (GTK2Graphics *)dest )->GetImageHandle();
94
    AssignGTK2Font( DC );*/
95 96 97 98
}
//---------------------------------------------------------------------------
void GTK2Font::GetSize( string text, int &w, int &h )
{
99
/*    // Get device context of screen
100 101 102 103 104 105 106 107 108 109 110 111
    HDC DeskDC = GetWindowDC( GetDesktopWindow() );

    // Get size
    LPRECT rect = new RECT;;
    rect->left   = 0;
    rect->top    = 0;
    AssignGTK2Font( DeskDC );
    DrawText( DeskDC, text.c_str(), text.length(), rect, DT_CALCRECT);
    w = rect->right - rect->left;
    h = rect->bottom - rect->top;

    // Release screen device context
112
    ReleaseDC( GetDesktopWindow(), DeskDC );*/
113 114 115
    /*FIXME*/
/*    w = gdk_text_width( GFont, text.c_str(), text.length() );
    h = gdk_text_height( GFont, text.c_str(), text.length() );*/
Cyril Deguet's avatar
Cyril Deguet committed
116 117
    w = 100;
    h = 50;
118 119 120 121 122
}
//---------------------------------------------------------------------------
void GTK2Font::GenericPrint( Graphics *dest, string text, int x, int y,
                                 int w, int h, int align, int color )
{
Cyril Deguet's avatar
Cyril Deguet committed
123 124
    GdkDrawable *drawable = ( (GTK2Graphics *)dest )->GetImage();
    GdkGC *gc = ( (GTK2Graphics *)dest )->GetGC();
125
/*    HDC DC = ( (GTK2Graphics *)dest )->GetImageHandle();
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
    // 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 color to black to avoid graphic bugs
    SetTextColor( DC, 0 );

    // Free memory
149
    delete r;*/
Cyril Deguet's avatar
Cyril Deguet committed
150 151
    pango_layout_set_text( Layout, text.c_str(), text.length() );
    gdk_draw_layout( drawable, gc, x, y, Layout );
152 153 154 155 156 157
}

//---------------------------------------------------------------------------
void GTK2Font::Print( Graphics *dest, string text, int x, int y, int w,
                       int h, int align )
{
158
    GenericPrint( dest, text, x, y, w, h, align, Color );
159 160 161 162 163
}
//---------------------------------------------------------------------------
void GTK2Font::PrintColor( Graphics *dest, string text, int x, int y, int w,
                            int h, int align, int color )
{
164
    GenericPrint( dest, text, x, y, w, h, align, color );
165 166 167
}
//---------------------------------------------------------------------------

168
#endif