]> git.saurik.com Git - wxWidgets.git/blame - src/os2/font.cpp
support for multiple images in one file
[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
19193a2c
KB
164wxFont::wxFont(const wxNativeFontInfo& rInfo)
165 {
166 Init();
167
168 (void)Create( rInfo.pointSize
169 ,rInfo.family
170 ,rInfo.style
171 ,rInfo.weight
172 ,rInfo.underlined
173 ,rInfo.faceName
174 ,rInfo.encoding
175 );
176 }
177
178
21802234 179void wxFont::Init()
0e320a79 180{
0e320a79
DW
181 if ( wxTheFontList )
182 wxTheFontList->Append(this);
183}
184
e99762c0
DW
185// ----------------------------------------------------------------------------
186// Constructor for a font. Note that the real construction is done
187// in wxDC::SetFont, when information is available about scaling etc.
188// ----------------------------------------------------------------------------
189bool wxFont::Create(
190 int nPointSize
191, int nFamily
192, int nStyle
193, int nWeight
194, bool bUnderlined
195, const wxString& rsFaceName
196, wxFontEncoding vEncoding
197)
0e320a79
DW
198{
199 UnRef();
e99762c0
DW
200 m_refData = new wxFontRefData( nPointSize
201 ,nFamily
202 ,nStyle
203 ,nWeight
204 ,bUnderlined
205 ,rsFaceName
206 ,vEncoding
207 );
0e320a79 208 RealizeResource();
0e320a79 209 return TRUE;
e99762c0 210} // end of wxFont::Create
0e320a79
DW
211
212wxFont::~wxFont()
213{
e99762c0 214 if (wxTheFontList)
0e320a79 215 wxTheFontList->DeleteObject(this);
e99762c0 216} // end of wxFont::~wxFont
0e320a79 217
21802234
DW
218// ----------------------------------------------------------------------------
219// real implementation
f6bcfd97
BP
220// Boris' Kovalenko comments:
221// Because OS/2 fonts are associated with PS we can not create the font
222// here, but we may check that font definition is true
21802234
DW
223// ----------------------------------------------------------------------------
224
0e320a79
DW
225bool wxFont::RealizeResource()
226{
e99762c0
DW
227 LONG lNumFonts = 0L;
228 LONG lTemp = 0L;
229 PFONTMETRICS pFM = NULL;
230 ERRORID vError;
231
21802234
DW
232 if ( GetResourceHandle() )
233 {
234 // VZ: the old code returned FALSE in this case, but it doesn't seem
235 // to make sense because the font _was_ created
223d09f6 236 wxLogDebug(wxT("Calling wxFont::RealizeResource() twice"));
21802234
DW
237
238 return TRUE;
239 }
240
e99762c0
DW
241 LONG flId;
242 bool bInternalPS = FALSE; // if we have to create one
f6bcfd97 243
e99762c0
DW
244 //
245 // Now cheking
246 //
247 flId = 1L;
248 if (!M_FONTDATA->m_hPS)
21802234 249 {
e99762c0
DW
250 M_FONTDATA->m_hPS = ::WinGetPS(HWND_DESKTOP);
251 bInternalPS = TRUE;
21802234
DW
252 }
253
e99762c0 254 if (M_FONTDATA->m_pFM)
21802234 255 {
e99762c0
DW
256 delete [] M_FONTDATA->m_pFM;
257 M_FONTDATA->m_pFM = NULL;
21802234 258 }
e99762c0
DW
259 //
260 // Determine the number of fonts.
261 //
262 lNumFonts = ::GpiQueryFonts( M_FONTDATA->m_hPS
263 ,QF_PUBLIC
264 ,NULL
265 ,&lTemp
266 ,(LONG) sizeof(FONTMETRICS)
267 ,NULL
268 );
269
270 //
271 // Allocate space for the font metrics.
272 //
273 pFM = new FONTMETRICS[lNumFonts + 1];
274
275 //
276 // Retrieve the font metrics.
277 //
278 lTemp = lNumFonts;
279 lTemp = ::GpiQueryFonts( M_FONTDATA->m_hPS
280 ,QF_PUBLIC
281 ,NULL
282 ,&lTemp
283 ,(LONG) sizeof(FONTMETRICS)
284 ,pFM
285 );
286 SetFM( pFM
287 ,(int)lNumFonts
288 );
289
290 wxString sVals;
291
292 for (int i = 0; i < lNumFonts; i++)
21802234 293 {
e99762c0
DW
294 sVals << "Face: " <<M_FONTDATA->m_pFM[i].szFacename
295 << "Family: " <<M_FONTDATA->m_pFM[i].szFamilyname
296 << " PointSize: " << M_FONTDATA->m_pFM[i].lEmHeight
297 << " Height: " << M_FONTDATA->m_pFM[i].lXHeight
298 ;
299 sVals = "";
21802234 300 }
e99762c0
DW
301 M_FONTDATA->m_vFattrs.usRecordLength = sizeof(FATTRS);
302 M_FONTDATA->m_vFattrs.fsFontUse = FATTR_FONTUSE_OUTLINE | // only outline fonts allowed
303 FATTR_FONTUSE_TRANSFORMABLE; // may be transformed
304 M_FONTDATA->m_vFattrs.fsType = 0;
305 M_FONTDATA->m_vFattrs.lMaxBaselineExt = M_FONTDATA->m_vFattrs.lAveCharWidth = 0;
306 M_FONTDATA->m_vFattrs.idRegistry = 0;
307 M_FONTDATA->m_vFattrs.lMatch = 0;
21802234 308
e99762c0
DW
309 M_FONTDATA->m_vFname.usSize = sizeof(FACENAMEDESC);
310 M_FONTDATA->m_vFname.usWidthClass = FWIDTH_NORMAL;
311 M_FONTDATA->m_vFname.usReserved = 0;
312 M_FONTDATA->m_vFname.flOptions = 0;
21802234 313
e99762c0 314 OS2SelectMatchingFontByName();
f6bcfd97 315
e99762c0
DW
316 long lNumLids = ::GpiQueryNumberSetIds(M_FONTDATA->m_hPS);
317 long lGpiError;
7e99520b 318
e99762c0 319 //
f6bcfd97 320 // First we should generate unique id
e99762c0
DW
321 //
322 if(lNumLids )
f6bcfd97 323 {
e99762c0
DW
324 long alTypes[255];
325 STR8 azNames[255];
326 long alIds[255];
327
328 if(!::GpiQuerySetIds( M_FONTDATA->m_hPS
329 ,lNumLids
330 ,alTypes
331 ,azNames
332 ,alIds
333 ))
f6bcfd97 334 {
e99762c0
DW
335 if (bInternalPS)
336 ::WinReleasePS(M_FONTDATA->m_hPS);
f6bcfd97
BP
337 return 0;
338 }
7e99520b 339
e99762c0
DW
340 for(unsigned long LCNum = 0; LCNum < lNumLids; LCNum++)
341 if(alIds[LCNum] == flId)
342 ++flId;
343 if(flId > 254) // wow, no id available!
f6bcfd97 344 {
e99762c0
DW
345 if (bInternalPS)
346 ::WinReleasePS(M_FONTDATA->m_hPS);
f6bcfd97
BP
347 return 0;
348 }
349 }
350
e99762c0
DW
351 //
352 // Release and delete the current font
353 //
354 ::GpiSetCharSet(M_FONTDATA->m_hPS, LCID_DEFAULT);/* release the font before deleting */
355 ::GpiDeleteSetId(M_FONTDATA->m_hPS, 1L); /* delete the logical font */
356
357 //
358 // Now build a facestring
359 //
360 char zFacename[128];
361 strcpy(zFacename, M_FONTDATA->m_vFattrs.szFacename);
362
363 if(::GpiQueryFaceString( M_FONTDATA->m_hPS
364 ,zFacename
365 ,&M_FONTDATA->m_vFname
366 ,FACESIZE
367 ,M_FONTDATA->m_vFattrs.szFacename
368 ) == GPI_ERROR)
f6bcfd97 369 {
e99762c0 370 vError = ::WinGetLastError(vHabmain);
f6bcfd97
BP
371 }
372
987da0d4 373 M_FONTDATA->m_sFaceName = zFacename;
f6bcfd97 374
e99762c0
DW
375 if(::GpiCreateLogFont( M_FONTDATA->m_hPS
376 ,NULL
377 ,flId
378 ,&M_FONTDATA->m_vFattrs
379 ) != GPI_ERROR)
380 M_FONTDATA->m_hFont = (WXHFONT)1;
f6bcfd97 381
f6bcfd97 382
e99762c0
DW
383 if (bInternalPS)
384 {
385 if(M_FONTDATA->m_hFont)
386 ::GpiDeleteSetId( M_FONTDATA->m_hPS
387 ,flId
388 );
f6bcfd97 389
e99762c0
DW
390 ::WinReleasePS(M_FONTDATA->m_hPS);
391 }
392 else
393 ::GpiSetCharSet(M_FONTDATA->m_hPS, flId); // sets font for presentation space
394 if (!M_FONTDATA->m_hFont)
21802234
DW
395 {
396 wxLogLastError("CreateFont");
397 }
e99762c0
DW
398 M_FONTDATA->m_nFontId = flId;
399 return(M_FONTDATA->m_hFont != 0);
400} // end of wxFont::RealizeResource
21802234 401
e99762c0
DW
402bool wxFont::FreeResource(
403 bool bForce
404)
21802234 405{
e99762c0 406 if (GetResourceHandle())
21802234 407 {
21802234 408 M_FONTDATA->m_hFont = 0;
e99762c0
DW
409 ::GpiDeleteSetId( M_FONTDATA->m_hPS
410 ,M_FONTDATA->m_nFontId
411 );
21802234
DW
412 return TRUE;
413 }
0e320a79 414 return FALSE;
e99762c0 415} // end of wxFont::FreeResource
0e320a79 416
5fd2b2c6 417WXHANDLE wxFont::GetHFONT() const
21802234 418{
e99762c0 419 if (!M_FONTDATA)
21802234
DW
420 return 0;
421 else
e99762c0 422 return (WXHANDLE)M_FONTDATA->m_hFont;
5fd2b2c6
DW
423} // end of wxFont::GetHFONT
424
425WXHANDLE wxFont::GetResourceHandle()
426{
427 return GetHFONT();
e99762c0 428} // end of wxFont::GetResourceHandle
21802234
DW
429
430bool wxFont::IsFree() const
431{
432 return (M_FONTDATA && (M_FONTDATA->m_hFont == 0));
e99762c0 433} // end of wxFont::IsFree
21802234 434
0e320a79
DW
435void wxFont::Unshare()
436{
21802234
DW
437 // Don't change shared data
438 if ( !m_refData )
0e320a79 439 {
21802234
DW
440 m_refData = new wxFontRefData();
441 }
0e320a79
DW
442 else
443 {
21802234
DW
444 wxFontRefData* ref = new wxFontRefData(*M_FONTDATA);
445 UnRef();
446 m_refData = ref;
447 }
e99762c0 448} // end of wxFont::Unshare
0e320a79 449
21802234
DW
450// ----------------------------------------------------------------------------
451// change font attribute: we recreate font when doing it
452// ----------------------------------------------------------------------------
453
e99762c0
DW
454void wxFont::SetPointSize(
455 int nPointSize
456)
0e320a79
DW
457{
458 Unshare();
459
e99762c0 460 M_FONTDATA->m_nPointSize = nPointSize;
0e320a79
DW
461
462 RealizeResource();
e99762c0 463} // end of wxFont::SetPointSize
0e320a79 464
e99762c0
DW
465void wxFont::SetFamily(
466 int nFamily
467)
0e320a79
DW
468{
469 Unshare();
470
e99762c0 471 M_FONTDATA->m_nFamily = nFamily;
0e320a79
DW
472
473 RealizeResource();
e99762c0 474} // end of wxFont::SetFamily
0e320a79 475
e99762c0
DW
476void wxFont::SetStyle(
477 int nStyle
478)
0e320a79
DW
479{
480 Unshare();
481
e99762c0 482 M_FONTDATA->m_nStyle = nStyle;
0e320a79
DW
483
484 RealizeResource();
e99762c0 485} // end of wxFont::SetStyle
0e320a79 486
e99762c0
DW
487void wxFont::SetWeight(
488 int nWeight
489)
0e320a79
DW
490{
491 Unshare();
492
e99762c0 493 M_FONTDATA->m_nWeight = nWeight;
0e320a79
DW
494
495 RealizeResource();
e99762c0 496} // end of wxFont::SetWeight
0e320a79 497
e99762c0
DW
498void wxFont::SetFaceName(
499 const wxString& rsFaceName
500)
0e320a79
DW
501{
502 Unshare();
503
e99762c0 504 M_FONTDATA->m_sFaceName = rsFaceName;
0e320a79
DW
505
506 RealizeResource();
e99762c0 507} // end of wxFont::SetFaceName
0e320a79 508
e99762c0
DW
509void wxFont::SetUnderlined(
510 bool bUnderlined
511)
0e320a79
DW
512{
513 Unshare();
514
e99762c0 515 M_FONTDATA->m_bUnderlined = bUnderlined;
0e320a79
DW
516
517 RealizeResource();
e99762c0 518} // end of wxFont::SetUnderlined
0e320a79 519
e99762c0
DW
520void wxFont::SetEncoding(
521 wxFontEncoding vEncoding
522)
0e320a79 523{
21802234
DW
524 Unshare();
525
e99762c0 526 M_FONTDATA->m_vEncoding = vEncoding;
21802234
DW
527
528 RealizeResource();
e99762c0
DW
529} // end of wxFont::SetEncoding
530
531void wxFont::SetPS(
532 HPS hPS
533)
534{
535 Unshare();
536
537 M_FONTDATA->m_hPS = hPS;
538
539 RealizeResource();
540} // end of wxFont::SetPS
541
542void wxFont::SetFM(
543 PFONTMETRICS pFM
544, int nNumFonts
545)
546{
547 //
548 // Don't realize the font with this one
549 //
550 M_FONTDATA->m_pFM = pFM;
551 M_FONTDATA->m_nNumFonts = nNumFonts;
552} // end of wxFont::SetFM
0e320a79 553
21802234
DW
554// ----------------------------------------------------------------------------
555// accessors
556// ----------------------------------------------------------------------------
557
558int wxFont::GetPointSize() const
0e320a79 559{
7e99520b
DW
560 wxFontRefData* pTmp;
561
562 pTmp = M_FONTDATA;
563 if(pTmp)
e99762c0 564 return pTmp->m_nPointSize;
7e99520b
DW
565 else
566 return 10;
e99762c0 567} // end of wxFont::GetPointSize
0e320a79 568
21802234 569int wxFont::GetFamily() const
0e320a79 570{
e99762c0
DW
571 return M_FONTDATA->m_nFamily;
572} // end of wxFont::GetFamily
21802234
DW
573
574int wxFont::GetFontId() const
575{
e99762c0
DW
576 return M_FONTDATA->m_nFontId;
577} // end of wxFont::GetFontId
21802234
DW
578
579int wxFont::GetStyle() const
580{
e99762c0
DW
581 return M_FONTDATA->m_nStyle;
582} // end of wxFont::GetStyle
21802234
DW
583
584int wxFont::GetWeight() const
585{
e99762c0 586 return M_FONTDATA->m_nWeight;
21802234
DW
587}
588
589bool wxFont::GetUnderlined() const
590{
e99762c0
DW
591 return M_FONTDATA->m_bUnderlined;
592} // end of wxFont::GetUnderlined
21802234
DW
593
594wxString wxFont::GetFaceName() const
595{
e99762c0
DW
596 wxString sStr;
597
21802234 598 if ( M_FONTDATA )
e99762c0
DW
599 sStr = M_FONTDATA->m_sFaceName ;
600 return sStr;
601} // end of wxFont::GetFaceName
21802234
DW
602
603wxFontEncoding wxFont::GetEncoding() const
604{
e99762c0
DW
605 return M_FONTDATA->m_vEncoding;
606} // end of wxFont::GetEncoding
607
608HPS wxFont::GetPS() const
609{
610 return M_FONTDATA->m_hPS;
611} // end of wxFont::GetPS
612
613void wxFont::OS2SelectMatchingFontByName()
614{
615 int i;
616 int nDiff0;
617 int nDiff;
618 int nIs;
619 int nIndex;
620 int nMinDiff;
621 int nMinDiff0;
622 int nApirc;
623 int anDiff[16];
624 int anMinDiff[16];
625 STR8 zFn;
626 char zFontFaceName[FACESIZE];
627 wxString sFaceName;
628 USHORT usWeightClass;
629 int fsSelection = 0;
630
631 nMinDiff0 = 0xf000;
632 for(i = 0;i < 16; i++)
633 anMinDiff[i] = nMinDiff0;
634
635 switch (GetFamily())
636 {
637 case wxSCRIPT:
638 sFaceName = wxT("Script");
639 break;
640
641 case wxDECORATIVE:
642 case wxROMAN:
643 sFaceName = wxT("Times New Roman");
644 break;
645
646 case wxTELETYPE:
647 case wxMODERN:
648 sFaceName = wxT("Courier") ;
649 break;
650
651 case wxSWISS:
652 sFaceName = wxT("WarpSans") ;
653 break;
654
655 case wxDEFAULT:
656 default:
657 sFaceName = wxT("Helv") ;
658 }
659
660 switch (GetWeight())
661 {
662 default:
663 wxFAIL_MSG(_T("unknown font weight"));
664 // fall through
665 usWeightClass = FWEIGHT_DONT_CARE;
666 break;
667
668 case wxNORMAL:
669 usWeightClass = FWEIGHT_NORMAL;
670 break;
671
672 case wxLIGHT:
673 usWeightClass = FWEIGHT_LIGHT;
674 break;
675
676 case wxBOLD:
677 usWeightClass = FWEIGHT_BOLD;
678 break;
679
680 case wxFONTWEIGHT_MAX:
681 usWeightClass = FWEIGHT_ULTRA_BOLD;
682 break;
683 }
684 M_FONTDATA->m_vFname.usWeightClass = usWeightClass;
685
686 switch (GetStyle())
687 {
688 case wxITALIC:
689 case wxSLANT:
690 fsSelection = FM_SEL_ITALIC;
691 M_FONTDATA->m_vFname.flOptions = FTYPE_ITALIC;
692 break;
693
694 default:
695 wxFAIL_MSG(wxT("unknown font slant"));
696 // fall through
697
698 case wxNORMAL:
699 fsSelection = 0;
700 break;
701 }
702
703 wxStrncpy(zFontFaceName, sFaceName.c_str(), WXSIZEOF(zFontFaceName));
704 M_FONTDATA->m_nPointSize = GetPointSize();
705 nIndex = 0;
706 for(i = 0, nIs = 0; i < M_FONTDATA->m_nNumFonts; i++)
707 {
708 // Debug code
709 int nPointSize = M_FONTDATA->m_nPointSize;
710 int nEmHeight = 0;
711 int nXHeight = 0;
712 anDiff[0] = wxGpiStrcmp(M_FONTDATA->m_pFM[i].szFamilyname, zFontFaceName);
713 anDiff[1] = abs(M_FONTDATA->m_pFM[i].lEmHeight - M_FONTDATA->m_nPointSize);
714 anDiff[2] = abs(M_FONTDATA->m_pFM[i].usWeightClass - usWeightClass);
715 anDiff[3] = abs((M_FONTDATA->m_pFM[i].fsSelection & 0x2f) - fsSelection);
716 if(anDiff[0] == 0)
717 {
718 nEmHeight = (int)M_FONTDATA->m_pFM[i].lEmHeight;
719 nXHeight =(int)M_FONTDATA->m_pFM[i].lXHeight;
720 if( (nIs & 0x01) == 0)
721 {
722 nIs = 1;
723 nIndex = i;
724 anMinDiff[1] = anDiff[1];
725 anMinDiff[2] = anDiff[2];
726 anMinDiff[3] = anDiff[3];
727 }
728 else if(anDiff[3] < anMinDiff[3])
729 {
730 nIndex = i;
731 anMinDiff[3] = anDiff[3];
732 }
733 else if(anDiff[2] < anMinDiff[2])
734 {
735 nIndex = i;
736 anMinDiff[2] = anDiff[2];
737 }
738 else if(anDiff[1] < anMinDiff[1])
739 {
740 nIndex = i;
741 anMinDiff[1] = anDiff[1];
742 }
743 anMinDiff[0] = 0;
744 }
745 else if(anDiff[0] < anMinDiff[0])
746 {
747 nIs = 2;
748 nIndex = i;
749 anMinDiff[3] = anDiff[3];
750 anMinDiff[2] = anDiff[2];
751 anMinDiff[1] = anDiff[1];
752 anMinDiff[0] = anDiff[0];
753 }
754 else if(anDiff[0] == anMinDiff[0])
755 {
756 if(anDiff[3] < anMinDiff[3])
757 {
758 nIndex = i;
759 anMinDiff[3] = anDiff[3];
760 nIs = 2;
761 }
762 else if(anDiff[2] < anMinDiff[2])
763 {
764 nIndex = i;
765 anMinDiff[2] = anDiff[2];
766 nIs = 2;
767 }
768 else if(anDiff[1] < anMinDiff[1])
769 {
770 nIndex = i;
771 anMinDiff[1] = anDiff[1];
772 nIs = 2;
773 }
774 }
775 }
776
777 M_FONTDATA->m_vFattrs.usRecordLength = sizeof(FATTRS); // sets size of structure
778 M_FONTDATA->m_vFattrs.fsSelection = M_FONTDATA->m_pFM[nIndex].fsSelection; // uses default selection
779 M_FONTDATA->m_vFattrs.lMatch = M_FONTDATA->m_pFM[nIndex].lMatch; // force match
780 M_FONTDATA->m_vFattrs.idRegistry = M_FONTDATA->m_pFM[nIndex].idRegistry; // uses default registry
781 M_FONTDATA->m_vFattrs.usCodePage = M_FONTDATA->m_pFM[nIndex].usCodePage; // code-page
782 if(M_FONTDATA->m_pFM[nIndex].lMatch)
783 {
784 M_FONTDATA->m_vFattrs.lMaxBaselineExt = M_FONTDATA->m_pFM[nIndex].lMaxBaselineExt; // requested font height
785 M_FONTDATA->m_vFattrs.lAveCharWidth = M_FONTDATA->m_pFM[nIndex].lAveCharWidth ; // requested font width
786 }
787 else
788 {
789 M_FONTDATA->m_vFattrs.lMaxBaselineExt = 0;
790 M_FONTDATA->m_vFattrs.lAveCharWidth = 0;
791 }
792 M_FONTDATA->m_vFattrs.fsType = 0;// pfm->fsType; /* uses default type */
793 M_FONTDATA->m_vFattrs.fsFontUse = 0;
794
795 wxStrcpy(M_FONTDATA->m_vFattrs.szFacename, M_FONTDATA->m_pFM[nIndex].szFacename);
796 // Debug
797 strcpy(zFontFaceName, M_FONTDATA->m_pFM[nIndex].szFacename);
798 strcpy(zFontFaceName, M_FONTDATA->m_vFattrs.szFacename);
799
800 if(usWeightClass >= FWEIGHT_BOLD)
801 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_BOLD;
802 if(GetUnderlined())
803 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_UNDERSCORE;
804 if(fsSelection & FM_SEL_ITALIC)
805 M_FONTDATA->m_vFattrs.fsSelection |= FATTR_SEL_ITALIC;
0e320a79
DW
806}
807
e99762c0
DW
808
809