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 $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
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.
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.
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,
24 *****************************************************************************/
27 //--- WIN32 -----------------------------------------------------------------
30 //--- VLC -------------------------------------------------------------------
33 //--- SKIN ------------------------------------------------------------------
35 #include "win32_graphics.h"
37 #include "win32_font.h"
41 //---------------------------------------------------------------------------
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 )
49 //---------------------------------------------------------------------------
50 Win32Font::~Win32Font()
53 //---------------------------------------------------------------------------
54 void Win32Font::AssignWin32Font( HDC DC )
57 HGDIOBJ fontObj = CreateFont(
58 -MulDiv( Size, GetDeviceCaps( DC, LOGPIXELSX ), 72 ),
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
75 SelectObject( DC, fontObj );
78 DeleteObject( fontObj );
80 //---------------------------------------------------------------------------
81 void Win32Font::AssignFont( Graphics *dest )
83 HDC DC = ( (Win32Graphics *)dest )->GetImageHandle();
84 AssignWin32Font( DC );
86 //---------------------------------------------------------------------------
87 void Win32Font::GetSize( string text, int &w, int &h )
89 // Get device context of screen
90 HDC DeskDC = GetWindowDC( GetDesktopWindow() );
93 LPRECT rect = new RECT;;
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;
101 // Release screen device context
102 ReleaseDC( GetDesktopWindow(), DeskDC );
104 //---------------------------------------------------------------------------
105 void Win32Font::GenericPrint( Graphics *dest, string text, int x, int y,
106 int w, int h, int align, int color )
108 HDC DC = ( (Win32Graphics *)dest )->GetImageHandle();
116 // Get desktop Device Context
117 SetBkMode( DC, TRANSPARENT );
119 // Modify desktop attributes
123 SetTextColor( DC, color );
125 // Draw text on screen
126 DrawText( DC, text.c_str(), text.length(), r, align );
128 // Set text color to black to avoid graphic bugs
129 SetTextColor( DC, 0 );
135 //---------------------------------------------------------------------------
136 void Win32Font::Print( Graphics *dest, string text, int x, int y, int w,
139 GenericPrint( dest, text, x, y, w, h, align, Color );
141 //---------------------------------------------------------------------------
142 void Win32Font::PrintColor( Graphics *dest, string text, int x, int y, int w,
143 int h, int align, int color )
145 GenericPrint( dest, text, x, y, w, h, align, color );
147 //---------------------------------------------------------------------------