1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
//===============================================================
// vfont.cxx - The font class - Windows
//
// Copyright (C) 1995,1996, 1997, 1998 Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================
#include <v/vwin32.h> // for Win 32 stuff
#include <v/vapp.h>
#include <v/vfont.h>
//=======================>>> vFont::vFont <<<=============================
vFont::vFont(vFontID fam, int size, vFontID sty, vFontID wt, int und, int ang)
{
SysDebug(Constructor,"vFont::vFont() constructor\n")
_family = fam; _pointSize = size; _style = sty; _weight = wt;
_underlined = und; _isStockFont = 0; _hFont = 0;
_fontColor = 0; _angle = ang;
memset(&_lf, 0, sizeof(LOGFONT));
}
//=====================>>> vFont::vFont <<<===========================
vFont::vFont(const vFont& ft)
{
// Copy constructor - needs to delete object if already
// created, and copy the values as needed
if (_hFont != 0 && !_isStockFont)
::DeleteObject(_hFont);
_isStockFont = 0; _hFont = 0;
_family = ft._family; _style = ft._style; _weight = ft._weight;
_pointSize = ft._pointSize; _underlined = ft._underlined;
_fontColor = ft._fontColor; _angle = ft._angle;
_lf = ft._lf;
}
//=====================>>> vFont::= <<<===========================
vFont& vFont::operator =(const vFont& ft)
{
if (this == &ft) // assigning to self
{
return *this;
}
// just like the copy constructor
if (_hFont != 0 && !_isStockFont)
::DeleteObject(_hFont);
_isStockFont = 0; _hFont = 0;
_family = ft._family; _style = ft._style; _weight = ft._weight;
_pointSize = ft._pointSize; _underlined = ft._underlined;
_angle = ft._angle;
_fontColor = ft._fontColor;
_lf = ft._lf;
return *this;
}
//=====================>>> vFont::SetFontValues <<<===========================
void vFont::SetFontValues(vFontID fam, int size, vFontID sty, vFontID wt,
int und)
{
if (_hFont != 0 && !_isStockFont)
::DeleteObject(_hFont);
_isStockFont = 0; _hFont = 0;
_family = fam; _style = sty; _weight = wt;
_pointSize = size; _underlined = und;
_fontColor = 0;
}
///=====================>>> vFont::SetWinFontValues <<<========================
void vFont::SetWinFontValues(LOGFONT& lf, CHOOSEFONT& cf)
{
if (_hFont != 0 && !_isStockFont)
::DeleteObject(_hFont);
_lf = lf;
_isStockFont = 0; _hFont = 0;
// Map to whatever
// First, set what will be true no matter what
_pointSize = cf.iPointSize / 10;
_style = lf.lfItalic ? vfItalic : vfNormal;
_underlined = lf.lfUnderline;
_fontColor = cf.rgbColors;
_angle = lf.lfEscapement / 10;
// Now set things that might make it NOT a V font.
if (lf.lfWeight == FW_NORMAL)
_weight = vfNormal;
else if (lf.lfWeight == FW_BOLD)
_weight = vfBold;
else
{
_weight = vfNormal;
goto WinNative;
}
if (lf.lfStrikeOut)
goto WinNative;
// Now, determine if it is a V family
if (lf.lfPitchAndFamily == (DEFAULT_PITCH | FF_ROMAN) &&
strcmp(lf.lfFaceName,"Times New Roman") == 0)
{
_family = vfSerif;
return;
}
else if (lf.lfPitchAndFamily == (DEFAULT_PITCH | FF_SWISS) &&
strcmp(lf.lfFaceName,"Arial") == 0)
{
_family = vfSansSerif;
return;
}
else if (lf.lfPitchAndFamily == (DEFAULT_PITCH | FF_MODERN) &&
strcmp(lf.lfFaceName,"Courier New") == 0)
{
_family = vfFixed;
return;
}
else if (lf.lfPitchAndFamily == (DEFAULT_PITCH | FF_DECORATIVE) &&
strcmp(lf.lfFaceName,"Wingdings") == 0 && lf.lfCharSet == SYMBOL_CHARSET)
{
_family = vfDecorative;
return;
}
WinNative: // a Native Windows font
_family = vfOtherFont;
return;
}
//=======================>>> vFont::~vFont <<<=============================
vFont::~vFont()
{
SysDebug(Destructor,"vFont::~vFont() destructor\n")
if (_hFont != 0 && !_isStockFont)
::DeleteObject(_hFont); // free the font resource
}
//=======================>>> vFont::LoadFont <<<=============================
void vFont::LoadFont(HDC dc, int isPrinterDC)
{
// Create the stuff needed for interal font stuff
if (_hFont != 0)
return;
SysDebug(Misc,"Loading font\n");
BYTE ff_italic = 0;
int ff_weight = 0;
int ff_family = 0;
char *ff_face = NULL;
BYTE chrSet = ANSI_CHARSET;
_isStockFont = 0; // assume not a stock font
switch (_family)
{
case vfDefaultVariable: // default font
if (isPrinterDC)
{
ff_family = FF_SWISS;
ff_face = "Arial";
}
else
{
_isStockFont = 1;
_hFont = (HFONT) ::GetStockObject(SYSTEM_FONT);
}
break;
// The rest of the fonts will be Windows TrueType fonts
case vfSerif: // Serif font
ff_family = FF_ROMAN;
ff_face = "Times New Roman" ;
break;
case vfSansSerif: // SansSerif Font
ff_family = FF_SWISS;
ff_face = "Arial";
break;
case vfFixed: // Fixed
ff_family = FF_MODERN;
ff_face = "Courier New";
break;
case vfDecorative: // Decorative
ff_family = FF_DECORATIVE;
ff_face = "Wingdings";
chrSet = SYMBOL_CHARSET;
break;
case vfOtherFont: // set by font picker dialog
{
if (isPrinterDC) // Need to override this to be same as
_lf.lfHeight = _pointSize*12/10; // other "V" fonts
_hFont = ::CreateFontIndirect(&_lf);
if (_hFont == NULL) // just in case
{
_hFont = (HFONT) ::GetStockObject(SYSTEM_FONT);
_isStockFont = 1;
_angle = 0;
}
return;
}
case vfDefaultFixed: // default font
case vfDefaultSystem:
default:
if (isPrinterDC)
{
ff_family = FF_MODERN;
ff_face = "Courier New" ;
}
else
{
_isStockFont = 1;
_hFont = (HFONT) ::GetStockObject(SYSTEM_FIXED_FONT);
_angle = 0;
}
break;
}
// Now, set the rest of the font attributes
ff_italic = (_style == vfItalic) ? 1 : 0;
;
if (_weight == vfNormal)
ff_weight = FW_NORMAL;
else if (_weight == vfBold)
ff_weight = FW_BOLD;
if (!_isStockFont) // load non stock fonts
{
int nHeight;
// This is a bit of a kludge, but these values give fonts that
// are very close to the same physical print size as the PostScript
// version. It doesn't look too bad!
if (isPrinterDC)
nHeight = _pointSize*12/10;
else
nHeight = _pointSize*GetDeviceCaps(dc, LOGPIXELSY)/72;
_hFont = ::CreateFont(nHeight, 0, _angle * 10, 0,ff_weight,ff_italic,
(BYTE)_underlined,
0, chrSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, DEFAULT_PITCH | ff_family, ff_face);
}
if (_hFont == NULL) // just in case
{
_hFont = (HFONT) ::GetStockObject(SYSTEM_FONT);
_isStockFont = 1;
}
}
//########################################################################
|