]> git.saurik.com Git - wxWidgets.git/blame - src/os2/font.cpp
fixed KDE link file reading code
[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
21802234
DW
402WXHANDLE wxFont::GetResourceHandle()
403{
e99762c0 404 if (!M_FONTDATA)
21802234
DW
405 return 0;
406 else
e99762c0
DW
407 return (WXHANDLE)M_FONTDATA->m_hFont;
408} // end of wxFont::GetResourceHandle
21802234
DW
409
410bool wxFont::IsFree() const
411{
412 return (M_FONTDATA && (M_FONTDATA->m_hFont == 0));
e99762c0 413} // end of wxFont::IsFree
21802234 414
0e320a79
DW
415void wxFont::Unshare()
416{
21802234
DW
417 // Don't change shared data
418 if ( !m_refData )
0e320a79 419 {
21802234
DW
420 m_refData = new wxFontRefData();
421 }
0e320a79
DW
422 else
423 {
21802234
DW
424 wxFontRefData* ref = new wxFontRefData(*M_FONTDATA);
425 UnRef();
426 m_refData = ref;
427 }
e99762c0 428} // end of wxFont::Unshare
0e320a79 429
21802234
DW
430// ----------------------------------------------------------------------------
431// change font attribute: we recreate font when doing it
432// ----------------------------------------------------------------------------
433
e99762c0
DW
434void wxFont::SetPointSize(
435 int nPointSize
436)
0e320a79
DW
437{
438 Unshare();
439
e99762c0 440 M_FONTDATA->m_nPointSize = nPointSize;
0e320a79
DW
441
442 RealizeResource();
e99762c0 443} // end of wxFont::SetPointSize
0e320a79 444
e99762c0
DW
445void wxFont::SetFamily(
446 int nFamily
447)
0e320a79
DW
448{
449 Unshare();
450
e99762c0 451 M_FONTDATA->m_nFamily = nFamily;
0e320a79
DW
452
453 RealizeResource();
e99762c0 454} // end of wxFont::SetFamily
0e320a79 455
e99762c0
DW
456void wxFont::SetStyle(
457 int nStyle
458)
0e320a79
DW
459{
460 Unshare();
461
e99762c0 462 M_FONTDATA->m_nStyle = nStyle;
0e320a79
DW
463
464 RealizeResource();
e99762c0 465} // end of wxFont::SetStyle
0e320a79 466
e99762c0
DW
467void wxFont::SetWeight(
468 int nWeight
469)
0e320a79
DW
470{
471 Unshare();
472
e99762c0 473 M_FONTDATA->m_nWeight = nWeight;
0e320a79
DW
474
475 RealizeResource();
e99762c0 476} // end of wxFont::SetWeight
0e320a79 477
e99762c0
DW
478void wxFont::SetFaceName(
479 const wxString& rsFaceName
480)
0e320a79
DW
481{
482 Unshare();
483
e99762c0 484 M_FONTDATA->m_sFaceName = rsFaceName;
0e320a79
DW
485
486 RealizeResource();
e99762c0 487} // end of wxFont::SetFaceName
0e320a79 488
e99762c0
DW
489void wxFont::SetUnderlined(
490 bool bUnderlined
491)
0e320a79
DW
492{
493 Unshare();
494
e99762c0 495 M_FONTDATA->m_bUnderlined = bUnderlined;
0e320a79
DW
496
497 RealizeResource();
e99762c0 498} // end of wxFont::SetUnderlined
0e320a79 499
e99762c0
DW
500void wxFont::SetEncoding(
501 wxFontEncoding vEncoding
502)
0e320a79 503{
21802234
DW
504 Unshare();
505
e99762c0 506 M_FONTDATA->m_vEncoding = vEncoding;
21802234
DW
507
508 RealizeResource();
e99762c0
DW
509} // end of wxFont::SetEncoding
510
511void wxFont::SetPS(
512 HPS hPS
513)
514{
515 Unshare();
516
517 M_FONTDATA->m_hPS = hPS;
518
519 RealizeResource();
520} // end of wxFont::SetPS
521
522void wxFont::SetFM(
523 PFONTMETRICS pFM
524, int nNumFonts
525)
526{
527 //
528 // Don't realize the font with this one
529 //
530 M_FONTDATA->m_pFM = pFM;
531 M_FONTDATA->m_nNumFonts = nNumFonts;
532} // end of wxFont::SetFM
0e320a79 533
21802234
DW
534// ----------------------------------------------------------------------------
535// accessors
536// ----------------------------------------------------------------------------
537
538int wxFont::GetPointSize() const
0e320a79 539{
7e99520b
DW
540 wxFontRefData* pTmp;
541
542 pTmp = M_FONTDATA;
543 if(pTmp)
e99762c0 544 return pTmp->m_nPointSize;
7e99520b
DW
545 else
546 return 10;
e99762c0 547} // end of wxFont::GetPointSize
0e320a79 548
21802234 549int wxFont::GetFamily() const
0e320a79 550{
e99762c0
DW
551 return M_FONTDATA->m_nFamily;
552} // end of wxFont::GetFamily
21802234
DW
553
554int wxFont::GetFontId() const
555{
e99762c0
DW
556 return M_FONTDATA->m_nFontId;
557} // end of wxFont::GetFontId
21802234
DW
558
559int wxFont::GetStyle() const
560{
e99762c0
DW
561 return M_FONTDATA->m_nStyle;
562} // end of wxFont::GetStyle
21802234
DW
563
564int wxFont::GetWeight() const
565{
e99762c0 566 return M_FONTDATA->m_nWeight;
21802234
DW
567}
568
569bool wxFont::GetUnderlined() const
570{
e99762c0
DW
571 return M_FONTDATA->m_bUnderlined;
572} // end of wxFont::GetUnderlined
21802234
DW
573
574wxString wxFont::GetFaceName() const
575{
e99762c0
DW
576 wxString sStr;
577
21802234 578 if ( M_FONTDATA )
e99762c0
DW
579 sStr = M_FONTDATA->m_sFaceName ;
580 return sStr;
581} // end of wxFont::GetFaceName
21802234
DW
582
583wxFontEncoding wxFont::GetEncoding() const
584{
e99762c0
DW
585 return M_FONTDATA->m_vEncoding;
586} // end of wxFont::GetEncoding
587
588HPS wxFont::GetPS() const
589{
590 return M_FONTDATA->m_hPS;
591} // end of wxFont::GetPS
592
593void wxFont::OS2SelectMatchingFontByName()
594{
595 int i;
596 int nDiff0;
597 int nDiff;
598 int nIs;
599 int nIndex;
600 int nMinDiff;
601 int nMinDiff0;
602 int nApirc;
603 int anDiff[16];
604 int anMinDiff[16];
605 STR8 zFn;
606 char zFontFaceName[FACESIZE];
607 wxString sFaceName;
608 USHORT usWeightClass;
609 int fsSelection = 0;
610
611 nMinDiff0 = 0xf000;
612 for(i = 0;i < 16; i++)
613 anMinDiff[i] = nMinDiff0;
614
615 switch (GetFamily())
616 {
617 case wxSCRIPT:
618 sFaceName = wxT("Script");
619 break;
620
621 case wxDECORATIVE:
622 case wxROMAN:
623 sFaceName = wxT("Times New Roman");
624 break;
625
626 case wxTELETYPE:
627 case wxMODERN:
628 sFaceName = wxT("Courier") ;
629 break;
630
631 case wxSWISS:
632 sFaceName = wxT("WarpSans") ;
633 break;
634
635 case wxDEFAULT:
636 default:
637 sFaceName = wxT("Helv") ;
638 }
639
640 switch (GetWeight())
641 {
642 default:
643 wxFAIL_MSG(_T("unknown font weight"));
644 // fall through
645 usWeightClass = FWEIGHT_DONT_CARE;
646 break;
647
648 case wxNORMAL:
649 usWeightClass = FWEIGHT_NORMAL;
650 break;
651
652 case wxLIGHT:
653 usWeightClass = FWEIGHT_LIGHT;
654 break;
655
656 case wxBOLD:
657 usWeightClass = FWEIGHT_BOLD;
658 break;
659
660 case wxFONTWEIGHT_MAX:
661 usWeightClass = FWEIGHT_ULTRA_BOLD;
662 break;
663 }
664 M_FONTDATA->m_vFname.usWeightClass = usWeightClass;
665
666 switch (GetStyle())
667 {
668 case wxITALIC:
669 case wxSLANT:
670 fsSelection = FM_SEL_ITALIC;
671 M_FONTDATA->m_vFname.flOptions = FTYPE_ITALIC;
672 break;
673
674 default:
675 wxFAIL_MSG(wxT("unknown font slant"));
676 // fall through
677
678 case wxNORMAL:
679 fsSelection = 0;
680 break;
681 }
682
683 wxStrncpy(zFontFaceName, sFaceName.c_str(), WXSIZEOF(zFontFaceName));
684 M_FONTDATA->m_nPointSize = GetPointSize();
685 nIndex = 0;
686 for(i = 0, nIs = 0; i < M_FONTDATA->m_nNumFonts; i++)
687 {
688 // Debug code
689 int nPointSize = M_FONTDATA->m_nPointSize;
690 int nEmHeight = 0;
691 int nXHeight = 0;
692 anDiff[0] = wxGpiStrcmp(M_FONTDATA->m_pFM[i].szFamilyname, zFontFaceName);
693 anDiff[1] = abs(M_FONTDATA->m_pFM[i].lEmHeight - M_FONTDATA->m_nPointSize);
694 anDiff[2] = abs(M_FONTDATA->m_pFM[i].usWeightClass - usWeightClass);
695 anDiff[3] = abs((M_FONTDATA->m_pFM[i].fsSelection & 0x2f) - fsSelection);
696 if(anDiff[0] == 0)
697 {
698 nEmHeight = (int)M_FONTDATA->m_pFM[i].lEmHeight;
699 nXHeight =(int)M_FONTDATA->m_pFM[i].lXHeight;
700 if( (nIs & 0x01) == 0)
701 {
702 nIs = 1;
703 nIndex = i;
704 anMinDiff[1] = anDiff[1];
705 anMinDiff[2] = anDiff[2];
706 anMinDiff[3] = anDiff[3];
707 }
708 else if(anDiff[3] < anMinDiff[3])
709 {
710 nIndex = i;
711 anMinDiff[3] = anDiff[3];
712 }
713 else if(anDiff[2] < anMinDiff[2])
714 {
715 nIndex = i;
716 anMinDiff[2] = anDiff[2];
717 }
718 else if(anDiff[1] < anMinDiff[1])
719 {
720 nIndex = i;
721 anMinDiff[1] = anDiff[1];
722 }
723 anMinDiff[0] = 0;
724 }
725 else if(anDiff[0] < anMinDiff[0])
726 {
727 nIs = 2;
728 nIndex = i;
729 anMinDiff[3] = anDiff[3];
730 anMinDiff[2] = anDiff[2];
731 anMinDiff[1] = anDiff[1];
732 anMinDiff[0] = anDiff[0];
733 }
734 else if(anDiff[0] == anMinDiff[0])
735 {
736 if(anDiff[3] < anMinDiff[3])
737 {
738 nIndex = i;
739 anMinDiff[3] = anDiff[3];
740 nIs = 2;
741 }
742 else if(anDiff[2] < anMinDiff[2])
743 {
744 nIndex = i;
745 anMinDiff[2] = anDiff[2];
746 nIs = 2;
747 }
748 else if(anDiff[1] < anMinDiff[1])
749 {
750 nIndex = i;
751 anMinDiff[1] = anDiff[1];
752 nIs = 2;
753 }
754 }
755 }
756
757 M_FONTDATA->m_vFattrs.usRecordLength = sizeof(FATTRS); // sets size of structure
758 M_FONTDATA->m_vFattrs.fsSelection = M_FONTDATA->m_pFM[nIndex].fsSelection; // uses default selection
759 M_FONTDATA->m_vFattrs.lMatch = M_FONTDATA->m_pFM[nIndex].lMatch; // force match
760 M_FONTDATA->m_vFattrs.idRegistry = M_FONTDATA->m_pFM[nIndex].idRegistry; // uses default registry
761 M_FONTDATA->m_vFattrs.usCodePage = M_FONTDATA->m_pFM[nIndex].usCodePage; // code-page
762 if(M_FONTDATA->m_pFM[nIndex].lMatch)
763 {
764 M_FONTDATA->m_vFattrs.lMaxBaselineExt = M_FONTDATA->m_pFM[nIndex].lMaxBaselineExt; // requested font height
765 M_FONTDATA->m_vFattrs.lAveCharWidth = M_FONTDATA->m_pFM[nIndex].lAveCharWidth ; // requested font width
766 }
767 else
768 {
769 M_FONTDATA->m_vFattrs.lMaxBaselineExt = 0;
770 M_FONTDATA->m_vFattrs.lAveCharWidth = 0;
771 }
772 M_FONTDATA->m_vFattrs.fsType = 0;// pfm->fsType; /* uses default type */
773 M_FONTDATA->m_vFattrs.fsFontUse = 0;
774
775 wxStrcpy(M_FONTDATA->m_vFattrs.szFacename, M_FONTDATA->m_pFM[nIndex].szFacename);
776 // Debug
777 strcpy(zFontFaceName, M_FONTDATA->m_pFM[nIndex].szFacename);
778 strcpy(zFontFaceName, M_FONTDATA->m_vFattrs.szFacename);
779
780 if(usWeightClass >= FWEIGHT_BOLD)
781 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_BOLD;
782 if(GetUnderlined())
783 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_UNDERSCORE;
784 if(fsSelection & FM_SEL_ITALIC)
785 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_ITALIC;
0e320a79
DW
786}
787
e99762c0
DW
788
789