]> git.saurik.com Git - wxWidgets.git/blame - src/os2/font.cpp
added support for item attributes in virtual list control
[wxWidgets.git] / src / os2 / font.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: font.cpp
3// Purpose: wxFont class
21802234 4// Author: David Webster
0e320a79 5// Modified by:
21802234 6// Created: 10/06/99
0e320a79 7// RCS-ID: $Id$
21802234
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
21802234
DW
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
7e99520b 20 #include <malloc.h>
21802234
DW
21// For compilers that support precompilation, includes "wx.h".
22#include "wx/wxprec.h"
0e320a79 23
21802234
DW
24#ifndef WX_PRECOMP
25 #include <stdio.h>
26 #include "wx/setup.h"
27 #include "wx/list.h"
28 #include "wx/utils.h"
29 #include "wx/app.h"
30 #include "wx/font.h"
31#endif // WX_PRECOMP
32
33#include "wx/os2/private.h"
0e320a79 34
e99762c0 35IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
21802234 36
e99762c0
DW
37#if wxUSE_PORTABLE_FONTS_IN_MSW
38 IMPLEMENT_DYNAMIC_CLASS(wxFontNameDirectory, wxObject)
39#endif
0e320a79 40
21802234
DW
41// ----------------------------------------------------------------------------
42// wxFontRefData - the internal description of the font
43// ----------------------------------------------------------------------------
44
45class WXDLLEXPORT wxFontRefData: public wxGDIRefData
0e320a79 46{
21802234
DW
47friend class WXDLLEXPORT wxFont;
48
49public:
50 wxFontRefData()
51 {
52 Init(12, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
53 "", wxFONTENCODING_DEFAULT);
54 }
55
56 wxFontRefData(const wxFontRefData& data)
57 {
e99762c0
DW
58 Init(data.m_nPointSize, data.m_nFamily, data.m_nStyle, data.m_nWeight,
59 data.m_bUnderlined, data.m_sFaceName, data.m_vEncoding);
21802234 60
e99762c0 61 m_nFontId = data.m_nFontId;
21802234
DW
62 }
63
e99762c0
DW
64 wxFontRefData( int nSize
65 ,int nFamily
66 ,int nStyle
67 ,int nWeight
68 ,bool bUnderlined
69 ,const wxString& sFaceName
70 ,wxFontEncoding vEncoding
71 )
21802234 72 {
e99762c0 73 Init(nSize, nFamily, nStyle, nWeight, bUnderlined, sFaceName, vEncoding);
21802234 74 }
0e320a79 75
21802234
DW
76 virtual ~wxFontRefData();
77
78protected:
79 // common part of all ctors
e99762c0
DW
80 void Init( int nSize
81 ,int nFamily
82 ,int nStyle
83 ,int nWeight
84 ,bool bUnderlined
85 ,const wxString& rsFaceName
86 ,wxFontEncoding vEncoding
87 );
88
89 //
21802234
DW
90 // If TRUE, the pointer to the actual font is temporary and SHOULD NOT BE
91 // DELETED by destructor
e99762c0
DW
92 //
93 bool m_bTemporary;
94 int m_nFontId;
95
96 //
97 // Font characterstics
98 //
99 int m_nPointSize;
100 int m_nFamily;
101 int m_nStyle;
102 int m_nWeight;
103 bool m_bUnderlined;
104 wxString m_sFaceName;
105 wxFontEncoding m_vEncoding;
106
107 //
108 // Some PM specific stuff
109 //
110 WXHFONT m_hFont;
111 PFONTMETRICS m_pFM; // array of FONTMETRICS structs
112 int m_nNumFonts; // number of fonts in array
113 HPS m_hPS; // PS handle this font belongs to
114 FATTRS m_vFattrs; // Current fattrs struct
115 FACENAMEDESC m_vFname; // Current facename struct
116}; // end of CLASS wxFontRefData
21802234
DW
117
118// ============================================================================
119// implementation
120// ============================================================================
121
122// ----------------------------------------------------------------------------
123// wxFontRefData
124// ----------------------------------------------------------------------------
125
e99762c0
DW
126void wxFontRefData::Init(
127 int nPointSize
128, int nFamily
129, int nStyle
130, int nWeight
131, bool bUnderlined
132, const wxString& rsFaceName
133, wxFontEncoding vEncoding
134)
0e320a79 135{
e99762c0
DW
136 m_nStyle = nStyle;
137 m_nPointSize = nPointSize;
138 m_nFamily = nFamily;
139 m_nStyle = nStyle;
140 m_nWeight = nWeight;
141 m_bUnderlined = bUnderlined;
142 m_sFaceName = rsFaceName;
143 m_vEncoding = vEncoding;
144 m_nFontId = 0;
145 m_bTemporary = FALSE;
146
147 m_hFont = 0;
148 m_pFM = (PFONTMETRICS)NULL;
149 m_hPS = NULLHANDLE;
150 m_nNumFonts = 0;
151} // end of wxFontRefData::Init
0e320a79
DW
152
153wxFontRefData::~wxFontRefData()
154{
e99762c0
DW
155 if (m_pFM)
156 delete [] m_pFM;
157 m_pFM = (PFONTMETRICS)NULL;
0e320a79
DW
158}
159
21802234
DW
160// ----------------------------------------------------------------------------
161// wxFont
162// ----------------------------------------------------------------------------
0e320a79 163
21802234 164void wxFont::Init()
0e320a79 165{
0e320a79
DW
166 if ( wxTheFontList )
167 wxTheFontList->Append(this);
168}
169
e99762c0
DW
170// ----------------------------------------------------------------------------
171// Constructor for a font. Note that the real construction is done
172// in wxDC::SetFont, when information is available about scaling etc.
173// ----------------------------------------------------------------------------
174bool wxFont::Create(
175 int nPointSize
176, int nFamily
177, int nStyle
178, int nWeight
179, bool bUnderlined
180, const wxString& rsFaceName
181, wxFontEncoding vEncoding
182)
0e320a79
DW
183{
184 UnRef();
e99762c0
DW
185 m_refData = new wxFontRefData( nPointSize
186 ,nFamily
187 ,nStyle
188 ,nWeight
189 ,bUnderlined
190 ,rsFaceName
191 ,vEncoding
192 );
0e320a79 193 RealizeResource();
0e320a79 194 return TRUE;
e99762c0 195} // end of wxFont::Create
0e320a79
DW
196
197wxFont::~wxFont()
198{
e99762c0 199 if (wxTheFontList)
0e320a79 200 wxTheFontList->DeleteObject(this);
e99762c0 201} // end of wxFont::~wxFont
0e320a79 202
21802234
DW
203// ----------------------------------------------------------------------------
204// real implementation
f6bcfd97
BP
205// Boris' Kovalenko comments:
206// Because OS/2 fonts are associated with PS we can not create the font
207// here, but we may check that font definition is true
21802234
DW
208// ----------------------------------------------------------------------------
209
0e320a79
DW
210bool wxFont::RealizeResource()
211{
e99762c0
DW
212 LONG lNumFonts = 0L;
213 LONG lTemp = 0L;
214 PFONTMETRICS pFM = NULL;
215 ERRORID vError;
216
21802234
DW
217 if ( GetResourceHandle() )
218 {
219 // VZ: the old code returned FALSE in this case, but it doesn't seem
220 // to make sense because the font _was_ created
223d09f6 221 wxLogDebug(wxT("Calling wxFont::RealizeResource() twice"));
21802234
DW
222
223 return TRUE;
224 }
225
e99762c0
DW
226 LONG flId;
227 bool bInternalPS = FALSE; // if we have to create one
f6bcfd97 228
e99762c0
DW
229 //
230 // Now cheking
231 //
232 flId = 1L;
233 if (!M_FONTDATA->m_hPS)
21802234 234 {
e99762c0
DW
235 M_FONTDATA->m_hPS = ::WinGetPS(HWND_DESKTOP);
236 bInternalPS = TRUE;
21802234
DW
237 }
238
e99762c0 239 if (M_FONTDATA->m_pFM)
21802234 240 {
e99762c0
DW
241 delete [] M_FONTDATA->m_pFM;
242 M_FONTDATA->m_pFM = NULL;
21802234 243 }
e99762c0
DW
244 //
245 // Determine the number of fonts.
246 //
247 lNumFonts = ::GpiQueryFonts( M_FONTDATA->m_hPS
248 ,QF_PUBLIC
249 ,NULL
250 ,&lTemp
251 ,(LONG) sizeof(FONTMETRICS)
252 ,NULL
253 );
254
255 //
256 // Allocate space for the font metrics.
257 //
258 pFM = new FONTMETRICS[lNumFonts + 1];
259
260 //
261 // Retrieve the font metrics.
262 //
263 lTemp = lNumFonts;
264 lTemp = ::GpiQueryFonts( M_FONTDATA->m_hPS
265 ,QF_PUBLIC
266 ,NULL
267 ,&lTemp
268 ,(LONG) sizeof(FONTMETRICS)
269 ,pFM
270 );
271 SetFM( pFM
272 ,(int)lNumFonts
273 );
274
275 wxString sVals;
276
277 for (int i = 0; i < lNumFonts; i++)
21802234 278 {
e99762c0
DW
279 sVals << "Face: " <<M_FONTDATA->m_pFM[i].szFacename
280 << "Family: " <<M_FONTDATA->m_pFM[i].szFamilyname
281 << " PointSize: " << M_FONTDATA->m_pFM[i].lEmHeight
282 << " Height: " << M_FONTDATA->m_pFM[i].lXHeight
283 ;
284 sVals = "";
21802234 285 }
e99762c0
DW
286 M_FONTDATA->m_vFattrs.usRecordLength = sizeof(FATTRS);
287 M_FONTDATA->m_vFattrs.fsFontUse = FATTR_FONTUSE_OUTLINE | // only outline fonts allowed
288 FATTR_FONTUSE_TRANSFORMABLE; // may be transformed
289 M_FONTDATA->m_vFattrs.fsType = 0;
290 M_FONTDATA->m_vFattrs.lMaxBaselineExt = M_FONTDATA->m_vFattrs.lAveCharWidth = 0;
291 M_FONTDATA->m_vFattrs.idRegistry = 0;
292 M_FONTDATA->m_vFattrs.lMatch = 0;
21802234 293
e99762c0
DW
294 M_FONTDATA->m_vFname.usSize = sizeof(FACENAMEDESC);
295 M_FONTDATA->m_vFname.usWidthClass = FWIDTH_NORMAL;
296 M_FONTDATA->m_vFname.usReserved = 0;
297 M_FONTDATA->m_vFname.flOptions = 0;
21802234 298
e99762c0 299 OS2SelectMatchingFontByName();
f6bcfd97 300
e99762c0
DW
301 long lNumLids = ::GpiQueryNumberSetIds(M_FONTDATA->m_hPS);
302 long lGpiError;
7e99520b 303
e99762c0 304 //
f6bcfd97 305 // First we should generate unique id
e99762c0
DW
306 //
307 if(lNumLids )
f6bcfd97 308 {
e99762c0
DW
309 long alTypes[255];
310 STR8 azNames[255];
311 long alIds[255];
312
313 if(!::GpiQuerySetIds( M_FONTDATA->m_hPS
314 ,lNumLids
315 ,alTypes
316 ,azNames
317 ,alIds
318 ))
f6bcfd97 319 {
e99762c0
DW
320 if (bInternalPS)
321 ::WinReleasePS(M_FONTDATA->m_hPS);
f6bcfd97
BP
322 return 0;
323 }
7e99520b 324
e99762c0
DW
325 for(unsigned long LCNum = 0; LCNum < lNumLids; LCNum++)
326 if(alIds[LCNum] == flId)
327 ++flId;
328 if(flId > 254) // wow, no id available!
f6bcfd97 329 {
e99762c0
DW
330 if (bInternalPS)
331 ::WinReleasePS(M_FONTDATA->m_hPS);
f6bcfd97
BP
332 return 0;
333 }
334 }
335
e99762c0
DW
336 //
337 // Release and delete the current font
338 //
339 ::GpiSetCharSet(M_FONTDATA->m_hPS, LCID_DEFAULT);/* release the font before deleting */
340 ::GpiDeleteSetId(M_FONTDATA->m_hPS, 1L); /* delete the logical font */
341
342 //
343 // Now build a facestring
344 //
345 char zFacename[128];
346 strcpy(zFacename, M_FONTDATA->m_vFattrs.szFacename);
347
348 if(::GpiQueryFaceString( M_FONTDATA->m_hPS
349 ,zFacename
350 ,&M_FONTDATA->m_vFname
351 ,FACESIZE
352 ,M_FONTDATA->m_vFattrs.szFacename
353 ) == GPI_ERROR)
f6bcfd97 354 {
e99762c0 355 vError = ::WinGetLastError(vHabmain);
f6bcfd97
BP
356 }
357
e99762c0 358 strcpy(zFacename, M_FONTDATA->m_vFattrs.szFacename);
f6bcfd97 359
e99762c0
DW
360 if(::GpiCreateLogFont( M_FONTDATA->m_hPS
361 ,NULL
362 ,flId
363 ,&M_FONTDATA->m_vFattrs
364 ) != GPI_ERROR)
365 M_FONTDATA->m_hFont = (WXHFONT)1;
f6bcfd97 366
f6bcfd97 367
e99762c0
DW
368 if (bInternalPS)
369 {
370 if(M_FONTDATA->m_hFont)
371 ::GpiDeleteSetId( M_FONTDATA->m_hPS
372 ,flId
373 );
f6bcfd97 374
e99762c0
DW
375 ::WinReleasePS(M_FONTDATA->m_hPS);
376 }
377 else
378 ::GpiSetCharSet(M_FONTDATA->m_hPS, flId); // sets font for presentation space
379 if (!M_FONTDATA->m_hFont)
21802234
DW
380 {
381 wxLogLastError("CreateFont");
382 }
e99762c0
DW
383 M_FONTDATA->m_nFontId = flId;
384 return(M_FONTDATA->m_hFont != 0);
385} // end of wxFont::RealizeResource
21802234 386
e99762c0
DW
387bool wxFont::FreeResource(
388 bool bForce
389)
21802234 390{
e99762c0 391 if (GetResourceHandle())
21802234 392 {
21802234 393 M_FONTDATA->m_hFont = 0;
e99762c0
DW
394 ::GpiDeleteSetId( M_FONTDATA->m_hPS
395 ,M_FONTDATA->m_nFontId
396 );
21802234
DW
397 return TRUE;
398 }
0e320a79 399 return FALSE;
e99762c0 400} // end of wxFont::FreeResource
0e320a79 401
5fd2b2c6 402WXHANDLE wxFont::GetHFONT() const
21802234 403{
e99762c0 404 if (!M_FONTDATA)
21802234
DW
405 return 0;
406 else
e99762c0 407 return (WXHANDLE)M_FONTDATA->m_hFont;
5fd2b2c6
DW
408} // end of wxFont::GetHFONT
409
410WXHANDLE wxFont::GetResourceHandle()
411{
412 return GetHFONT();
e99762c0 413} // end of wxFont::GetResourceHandle
21802234
DW
414
415bool wxFont::IsFree() const
416{
417 return (M_FONTDATA && (M_FONTDATA->m_hFont == 0));
e99762c0 418} // end of wxFont::IsFree
21802234 419
0e320a79
DW
420void wxFont::Unshare()
421{
21802234
DW
422 // Don't change shared data
423 if ( !m_refData )
0e320a79 424 {
21802234
DW
425 m_refData = new wxFontRefData();
426 }
0e320a79
DW
427 else
428 {
21802234
DW
429 wxFontRefData* ref = new wxFontRefData(*M_FONTDATA);
430 UnRef();
431 m_refData = ref;
432 }
e99762c0 433} // end of wxFont::Unshare
0e320a79 434
21802234
DW
435// ----------------------------------------------------------------------------
436// change font attribute: we recreate font when doing it
437// ----------------------------------------------------------------------------
438
e99762c0
DW
439void wxFont::SetPointSize(
440 int nPointSize
441)
0e320a79
DW
442{
443 Unshare();
444
e99762c0 445 M_FONTDATA->m_nPointSize = nPointSize;
0e320a79
DW
446
447 RealizeResource();
e99762c0 448} // end of wxFont::SetPointSize
0e320a79 449
e99762c0
DW
450void wxFont::SetFamily(
451 int nFamily
452)
0e320a79
DW
453{
454 Unshare();
455
e99762c0 456 M_FONTDATA->m_nFamily = nFamily;
0e320a79
DW
457
458 RealizeResource();
e99762c0 459} // end of wxFont::SetFamily
0e320a79 460
e99762c0
DW
461void wxFont::SetStyle(
462 int nStyle
463)
0e320a79
DW
464{
465 Unshare();
466
e99762c0 467 M_FONTDATA->m_nStyle = nStyle;
0e320a79
DW
468
469 RealizeResource();
e99762c0 470} // end of wxFont::SetStyle
0e320a79 471
e99762c0
DW
472void wxFont::SetWeight(
473 int nWeight
474)
0e320a79
DW
475{
476 Unshare();
477
e99762c0 478 M_FONTDATA->m_nWeight = nWeight;
0e320a79
DW
479
480 RealizeResource();
e99762c0 481} // end of wxFont::SetWeight
0e320a79 482
e99762c0
DW
483void wxFont::SetFaceName(
484 const wxString& rsFaceName
485)
0e320a79
DW
486{
487 Unshare();
488
e99762c0 489 M_FONTDATA->m_sFaceName = rsFaceName;
0e320a79
DW
490
491 RealizeResource();
e99762c0 492} // end of wxFont::SetFaceName
0e320a79 493
e99762c0
DW
494void wxFont::SetUnderlined(
495 bool bUnderlined
496)
0e320a79
DW
497{
498 Unshare();
499
e99762c0 500 M_FONTDATA->m_bUnderlined = bUnderlined;
0e320a79
DW
501
502 RealizeResource();
e99762c0 503} // end of wxFont::SetUnderlined
0e320a79 504
e99762c0
DW
505void wxFont::SetEncoding(
506 wxFontEncoding vEncoding
507)
0e320a79 508{
21802234
DW
509 Unshare();
510
e99762c0 511 M_FONTDATA->m_vEncoding = vEncoding;
21802234
DW
512
513 RealizeResource();
e99762c0
DW
514} // end of wxFont::SetEncoding
515
516void wxFont::SetPS(
517 HPS hPS
518)
519{
520 Unshare();
521
522 M_FONTDATA->m_hPS = hPS;
523
524 RealizeResource();
525} // end of wxFont::SetPS
526
527void wxFont::SetFM(
528 PFONTMETRICS pFM
529, int nNumFonts
530)
531{
532 //
533 // Don't realize the font with this one
534 //
535 M_FONTDATA->m_pFM = pFM;
536 M_FONTDATA->m_nNumFonts = nNumFonts;
537} // end of wxFont::SetFM
0e320a79 538
21802234
DW
539// ----------------------------------------------------------------------------
540// accessors
541// ----------------------------------------------------------------------------
542
543int wxFont::GetPointSize() const
0e320a79 544{
7e99520b
DW
545 wxFontRefData* pTmp;
546
547 pTmp = M_FONTDATA;
548 if(pTmp)
e99762c0 549 return pTmp->m_nPointSize;
7e99520b
DW
550 else
551 return 10;
e99762c0 552} // end of wxFont::GetPointSize
0e320a79 553
21802234 554int wxFont::GetFamily() const
0e320a79 555{
e99762c0
DW
556 return M_FONTDATA->m_nFamily;
557} // end of wxFont::GetFamily
21802234
DW
558
559int wxFont::GetFontId() const
560{
e99762c0
DW
561 return M_FONTDATA->m_nFontId;
562} // end of wxFont::GetFontId
21802234
DW
563
564int wxFont::GetStyle() const
565{
e99762c0
DW
566 return M_FONTDATA->m_nStyle;
567} // end of wxFont::GetStyle
21802234
DW
568
569int wxFont::GetWeight() const
570{
e99762c0 571 return M_FONTDATA->m_nWeight;
21802234
DW
572}
573
574bool wxFont::GetUnderlined() const
575{
e99762c0
DW
576 return M_FONTDATA->m_bUnderlined;
577} // end of wxFont::GetUnderlined
21802234
DW
578
579wxString wxFont::GetFaceName() const
580{
e99762c0
DW
581 wxString sStr;
582
21802234 583 if ( M_FONTDATA )
e99762c0
DW
584 sStr = M_FONTDATA->m_sFaceName ;
585 return sStr;
586} // end of wxFont::GetFaceName
21802234
DW
587
588wxFontEncoding wxFont::GetEncoding() const
589{
e99762c0
DW
590 return M_FONTDATA->m_vEncoding;
591} // end of wxFont::GetEncoding
592
593HPS wxFont::GetPS() const
594{
595 return M_FONTDATA->m_hPS;
596} // end of wxFont::GetPS
597
598void wxFont::OS2SelectMatchingFontByName()
599{
600 int i;
601 int nDiff0;
602 int nDiff;
603 int nIs;
604 int nIndex;
605 int nMinDiff;
606 int nMinDiff0;
607 int nApirc;
608 int anDiff[16];
609 int anMinDiff[16];
610 STR8 zFn;
611 char zFontFaceName[FACESIZE];
612 wxString sFaceName;
613 USHORT usWeightClass;
614 int fsSelection = 0;
615
616 nMinDiff0 = 0xf000;
617 for(i = 0;i < 16; i++)
618 anMinDiff[i] = nMinDiff0;
619
620 switch (GetFamily())
621 {
622 case wxSCRIPT:
623 sFaceName = wxT("Script");
624 break;
625
626 case wxDECORATIVE:
627 case wxROMAN:
628 sFaceName = wxT("Times New Roman");
629 break;
630
631 case wxTELETYPE:
632 case wxMODERN:
633 sFaceName = wxT("Courier") ;
634 break;
635
636 case wxSWISS:
637 sFaceName = wxT("WarpSans") ;
638 break;
639
640 case wxDEFAULT:
641 default:
642 sFaceName = wxT("Helv") ;
643 }
644
645 switch (GetWeight())
646 {
647 default:
648 wxFAIL_MSG(_T("unknown font weight"));
649 // fall through
650 usWeightClass = FWEIGHT_DONT_CARE;
651 break;
652
653 case wxNORMAL:
654 usWeightClass = FWEIGHT_NORMAL;
655 break;
656
657 case wxLIGHT:
658 usWeightClass = FWEIGHT_LIGHT;
659 break;
660
661 case wxBOLD:
662 usWeightClass = FWEIGHT_BOLD;
663 break;
664
665 case wxFONTWEIGHT_MAX:
666 usWeightClass = FWEIGHT_ULTRA_BOLD;
667 break;
668 }
669 M_FONTDATA->m_vFname.usWeightClass = usWeightClass;
670
671 switch (GetStyle())
672 {
673 case wxITALIC:
674 case wxSLANT:
675 fsSelection = FM_SEL_ITALIC;
676 M_FONTDATA->m_vFname.flOptions = FTYPE_ITALIC;
677 break;
678
679 default:
680 wxFAIL_MSG(wxT("unknown font slant"));
681 // fall through
682
683 case wxNORMAL:
684 fsSelection = 0;
685 break;
686 }
687
688 wxStrncpy(zFontFaceName, sFaceName.c_str(), WXSIZEOF(zFontFaceName));
689 M_FONTDATA->m_nPointSize = GetPointSize();
690 nIndex = 0;
691 for(i = 0, nIs = 0; i < M_FONTDATA->m_nNumFonts; i++)
692 {
693 // Debug code
694 int nPointSize = M_FONTDATA->m_nPointSize;
695 int nEmHeight = 0;
696 int nXHeight = 0;
697 anDiff[0] = wxGpiStrcmp(M_FONTDATA->m_pFM[i].szFamilyname, zFontFaceName);
698 anDiff[1] = abs(M_FONTDATA->m_pFM[i].lEmHeight - M_FONTDATA->m_nPointSize);
699 anDiff[2] = abs(M_FONTDATA->m_pFM[i].usWeightClass - usWeightClass);
700 anDiff[3] = abs((M_FONTDATA->m_pFM[i].fsSelection & 0x2f) - fsSelection);
701 if(anDiff[0] == 0)
702 {
703 nEmHeight = (int)M_FONTDATA->m_pFM[i].lEmHeight;
704 nXHeight =(int)M_FONTDATA->m_pFM[i].lXHeight;
705 if( (nIs & 0x01) == 0)
706 {
707 nIs = 1;
708 nIndex = i;
709 anMinDiff[1] = anDiff[1];
710 anMinDiff[2] = anDiff[2];
711 anMinDiff[3] = anDiff[3];
712 }
713 else if(anDiff[3] < anMinDiff[3])
714 {
715 nIndex = i;
716 anMinDiff[3] = anDiff[3];
717 }
718 else if(anDiff[2] < anMinDiff[2])
719 {
720 nIndex = i;
721 anMinDiff[2] = anDiff[2];
722 }
723 else if(anDiff[1] < anMinDiff[1])
724 {
725 nIndex = i;
726 anMinDiff[1] = anDiff[1];
727 }
728 anMinDiff[0] = 0;
729 }
730 else if(anDiff[0] < anMinDiff[0])
731 {
732 nIs = 2;
733 nIndex = i;
734 anMinDiff[3] = anDiff[3];
735 anMinDiff[2] = anDiff[2];
736 anMinDiff[1] = anDiff[1];
737 anMinDiff[0] = anDiff[0];
738 }
739 else if(anDiff[0] == anMinDiff[0])
740 {
741 if(anDiff[3] < anMinDiff[3])
742 {
743 nIndex = i;
744 anMinDiff[3] = anDiff[3];
745 nIs = 2;
746 }
747 else if(anDiff[2] < anMinDiff[2])
748 {
749 nIndex = i;
750 anMinDiff[2] = anDiff[2];
751 nIs = 2;
752 }
753 else if(anDiff[1] < anMinDiff[1])
754 {
755 nIndex = i;
756 anMinDiff[1] = anDiff[1];
757 nIs = 2;
758 }
759 }
760 }
761
762 M_FONTDATA->m_vFattrs.usRecordLength = sizeof(FATTRS); // sets size of structure
763 M_FONTDATA->m_vFattrs.fsSelection = M_FONTDATA->m_pFM[nIndex].fsSelection; // uses default selection
764 M_FONTDATA->m_vFattrs.lMatch = M_FONTDATA->m_pFM[nIndex].lMatch; // force match
765 M_FONTDATA->m_vFattrs.idRegistry = M_FONTDATA->m_pFM[nIndex].idRegistry; // uses default registry
766 M_FONTDATA->m_vFattrs.usCodePage = M_FONTDATA->m_pFM[nIndex].usCodePage; // code-page
767 if(M_FONTDATA->m_pFM[nIndex].lMatch)
768 {
769 M_FONTDATA->m_vFattrs.lMaxBaselineExt = M_FONTDATA->m_pFM[nIndex].lMaxBaselineExt; // requested font height
770 M_FONTDATA->m_vFattrs.lAveCharWidth = M_FONTDATA->m_pFM[nIndex].lAveCharWidth ; // requested font width
771 }
772 else
773 {
774 M_FONTDATA->m_vFattrs.lMaxBaselineExt = 0;
775 M_FONTDATA->m_vFattrs.lAveCharWidth = 0;
776 }
777 M_FONTDATA->m_vFattrs.fsType = 0;// pfm->fsType; /* uses default type */
778 M_FONTDATA->m_vFattrs.fsFontUse = 0;
779
780 wxStrcpy(M_FONTDATA->m_vFattrs.szFacename, M_FONTDATA->m_pFM[nIndex].szFacename);
781 // Debug
782 strcpy(zFontFaceName, M_FONTDATA->m_pFM[nIndex].szFacename);
783 strcpy(zFontFaceName, M_FONTDATA->m_vFattrs.szFacename);
784
785 if(usWeightClass >= FWEIGHT_BOLD)
786 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_BOLD;
787 if(GetUnderlined())
788 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_UNDERSCORE;
789 if(fsSelection & FM_SEL_ITALIC)
790 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_ITALIC;
0e320a79
DW
791}
792
e99762c0
DW
793
794