]> git.sesse.net Git - vlc/blob - modules/gui/skins/win32/win32_font.cpp
70eaa131ce8fd98341a51dfc12279fe38173306d
[vlc] / modules / gui / skins / win32 / win32_font.cpp
1 /*****************************************************************************
2  * win32_font.cpp: Win32 implementation of the Font class
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: win32_font.cpp,v 1.1 2003/03/18 02:21:47 ipkiss Exp $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
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
27 //--- WIN32 -----------------------------------------------------------------
28 #include <windows.h>
29
30 //--- VLC -------------------------------------------------------------------
31 #include <vlc/intf.h>
32
33 //--- SKIN ------------------------------------------------------------------
34 #include "graphics.h"
35 #include "win32_graphics.h"
36 #include "font.h"
37 #include "win32_font.h"
38
39
40
41 //---------------------------------------------------------------------------
42 // Font object
43 //---------------------------------------------------------------------------
44 Win32Font::Win32Font( 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 }
49 //---------------------------------------------------------------------------
50 Win32Font::~Win32Font()
51 {
52 }
53 //---------------------------------------------------------------------------
54 void Win32Font::AssignWin32Font( HDC DC )
55 {
56     // Create font
57     HGDIOBJ fontObj = CreateFont(
58         -MulDiv( Size, GetDeviceCaps( DC, LOGPIXELSX ), 72 ),
59         0,
60         0,                  // angle of escapement
61         0,                  // base-line orientation angle
62         Weight,             // font weight
63         Italic,             // italic attribute flag
64         Underline,          // underline attribute flag
65         0,                  // strikeout attribute flag
66         ANSI_CHARSET,       // character set identifier
67         OUT_TT_PRECIS,      // output precision
68         0,                  // clipping precision
69         ANTIALIASED_QUALITY,      // output quality
70         0,                  // pitch and family
71         FontName.c_str()    // pointer to typeface name string
72     );
73
74     // Assign font to DC
75     SelectObject( DC, fontObj );
76
77     // Free memory
78     DeleteObject( fontObj );
79 }
80 //---------------------------------------------------------------------------
81 void Win32Font::AssignFont( Graphics *dest )
82 {
83     HDC DC = ( (Win32Graphics *)dest )->GetImageHandle();
84     AssignWin32Font( DC );
85 }
86 //---------------------------------------------------------------------------
87 void Win32Font::GetSize( string text, int &w, int &h )
88 {
89     // Get device context of screen
90     HDC DeskDC = GetWindowDC( GetDesktopWindow() );
91
92     // Get size
93     LPRECT rect = new RECT;;
94     rect->left   = 0;
95     rect->top    = 0;
96     AssignWin32Font( DeskDC );
97     DrawText( DeskDC, text.c_str(), text.length(), rect, DT_CALCRECT);
98     w = rect->right - rect->left;
99     h = rect->bottom - rect->top;
100
101     // Release screen device context
102     ReleaseDC( GetDesktopWindow(), DeskDC );
103 }
104 //---------------------------------------------------------------------------
105 void Win32Font::GenericPrint( Graphics *dest, string text, int x, int y,
106                                  int w, int h, int align, int color )
107 {
108     HDC DC = ( (Win32Graphics *)dest )->GetImageHandle();
109     // Set boundaries
110     LPRECT r = new RECT;
111     r->left   = x;
112     r->top    = y;
113     r->right  = x + w;
114     r->bottom = y + h;
115
116     // Get desktop Device Context
117     SetBkMode( DC, TRANSPARENT );
118
119     // Modify desktop attributes
120     AssignFont( dest );
121
122     // Change text color
123     SetTextColor( DC, color );
124
125     // Draw text on screen
126     DrawText( DC, text.c_str(), text.length(), r, align );
127
128     // Set text color to black to avoid graphic bugs
129     SetTextColor( DC, 0 );
130
131     // Free memory
132     delete r;
133 }
134
135 //---------------------------------------------------------------------------
136 void Win32Font::Print( Graphics *dest, string text, int x, int y, int w,
137                        int h, int align )
138 {
139     GenericPrint( dest, text, x, y, w, h, align, Color );
140 }
141 //---------------------------------------------------------------------------
142 void Win32Font::PrintColor( Graphics *dest, string text, int x, int y, int w,
143                             int h, int align, int color )
144 {
145     GenericPrint( dest, text, x, y, w, h, align, color );
146 }
147 //---------------------------------------------------------------------------
148
149