Repository navigation
Expand file tree
/
Copy pathfont.cpp
More file actions
1150 lines (967 loc) · 31.3 KB
/
Copy pathfont.cpp
File metadata and controls
1150 lines (967 loc) · 31.3 KB
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/////////////////////////////////////////////////////////////////////////////
// Name: src/os2/font.cpp
// Purpose: wxFont class
// Author: David Webster
// Modified by:
// Created: 10/06/99
// RCS-ID: $Id$
// Copyright: (c) David Webster
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/font.h"
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/list.h"
#include "wx/utils.h"
#include "wx/app.h"
#include "wx/log.h"
#endif // WX_PRECOMP
#include "wx/os2/private.h"
#include "wx/fontutil.h"
#include "wx/fontmap.h"
#include "wx/encinfo.h"
#include "wx/tokenzr.h"
#include <malloc.h>
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
// ----------------------------------------------------------------------------
// wxFontRefData - the internal description of the font
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxFontRefData: public wxGDIRefData
{
public:
wxFontRefData()
{
Init(-1, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false,
wxEmptyString, wxFONTENCODING_DEFAULT);
}
wxFontRefData( int nSize
,wxFontFamily nFamily
,wxFontStyle nStyle
,wxFontWeight nWeight
,bool bUnderlined
,const wxString& sFaceName
,wxFontEncoding vEncoding
)
{
Init( nSize
,nFamily
,nStyle
,nWeight
,bUnderlined
,sFaceName
,vEncoding
);
}
wxFontRefData( const wxNativeFontInfo& rInfo
,WXHFONT hFont = 0
,WXHANDLE hPS = 0
)
{
Init( rInfo
,hFont
,hPS
);
}
wxFontRefData(const wxFontRefData& rData)
{
Init( rData.m_nPointSize
,rData.m_nFamily
,rData.m_nStyle
,rData.m_nWeight
,rData.m_bUnderlined
,rData.m_sFaceName
,rData.m_vEncoding
);
m_nFontId = rData.m_nFontId;
}
virtual ~wxFontRefData();
//
// Operations
//
bool Alloc(wxFont* pFont);
void Free(void);
//
// All wxFont accessors
//
inline int GetPointSize(void) const
{
//
// We don't use the actual native font point size since it is
// the chosen physical font, which is usually only and approximation
// of the desired outline font. The actual displayable point size
// is the one stored in the refData
//
return m_nPointSize;
}
inline wxFontFamily GetFamily(void) const
{
return m_nFamily;
}
inline wxFontStyle GetStyle(void) const
{
return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetStyle()
: m_nStyle;
}
inline wxFontWeight GetWeight(void) const
{
return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetWeight()
: m_nWeight;
}
inline bool GetUnderlined(void) const
{
return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetUnderlined()
: m_bUnderlined;
}
inline wxString GetFaceName(void) const
{
wxString sFaceName;
if (m_bNativeFontInfoOk)
sFaceName = m_vNativeFontInfo.GetFaceName();
else
sFaceName = m_sFaceName;
return sFaceName;
}
inline wxFontEncoding GetEncoding(void) const
{
return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetEncoding()
: m_vEncoding;
}
inline WXHFONT GetHFONT(void) const { return m_hFont; }
inline HPS GetPS(void) const { return m_hPS; }
inline PFONTMETRICS GetFM(void) const { return m_pFM; }
inline int GetNumFonts(void) const { return m_nNumFonts; }
// ... and setters
inline void SetPointSize(int nPointSize)
{
if (m_bNativeFontInfoOk)
m_vNativeFontInfo.SetPointSize(nPointSize);
else
m_nPointSize = nPointSize;
}
inline void SetFamily(wxFontFamily nFamily)
{
m_nFamily = nFamily;
}
inline void SetStyle(wxFontStyle nStyle)
{
if (m_bNativeFontInfoOk)
m_vNativeFontInfo.SetStyle(nStyle);
else
m_nStyle = nStyle;
}
inline void SetWeight(wxFontWeight nWeight)
{
if (m_bNativeFontInfoOk)
m_vNativeFontInfo.SetWeight(nWeight);
else
m_nWeight = nWeight;
}
inline bool SetFaceName(const wxString& sFaceName)
{
if (m_bNativeFontInfoOk)
return m_vNativeFontInfo.SetFaceName(sFaceName);
else
m_sFaceName = sFaceName;
return true;
}
inline void SetUnderlined(bool bUnderlined)
{
if (m_bNativeFontInfoOk)
m_vNativeFontInfo.SetUnderlined(bUnderlined);
else
m_bUnderlined = bUnderlined;
}
inline void SetEncoding(wxFontEncoding vEncoding)
{
if (m_bNativeFontInfoOk)
m_vNativeFontInfo.SetEncoding(vEncoding);
else
m_vEncoding = vEncoding;
}
inline void SetPS(HPS hPS)
{
m_hPS = hPS;
}
inline void SetFM(PFONTMETRICS pFM)
{
m_pFM = pFM;
}
inline void SetNumFonts(int nNumFonts)
{
m_nNumFonts = nNumFonts;
}
//
// Native font info tests
//
bool HasNativeFontInfo() const { return m_bNativeFontInfoOk; }
const wxNativeFontInfo& GetNativeFontInfo() const
{ return m_vNativeFontInfo; }
protected:
//
// Common part of all ctors
//
void Init( int nSize
,wxFontFamily nFamily
,wxFontStyle nStyle
,wxFontWeight nWeight
,bool bUnderlined
,const wxString& rsFaceName
,wxFontEncoding vEncoding
);
void Init( const wxNativeFontInfo& rInfo
,WXHFONT hFont = 0
,WXHANDLE hPS = 0
);
//
// If true, the pointer to the actual font is temporary and SHOULD NOT BE
// DELETED by destructor
//
bool m_bTemporary;
int m_nFontId;
//
// Font characterstics
//
int m_nPointSize;
wxFontFamily m_nFamily;
wxFontStyle m_nStyle;
wxFontWeight m_nWeight;
bool m_bUnderlined;
wxString m_sFaceName;
wxFontEncoding m_vEncoding;
WXHFONT m_hFont;
//
// Native font info
//
wxNativeFontInfo m_vNativeFontInfo;
bool m_bNativeFontInfoOk;
//
// Some PM specific stuff
//
PFONTMETRICS m_pFM; // array of FONTMETRICS structs
int m_nNumFonts; // number of fonts in array
HPS m_hPS; // PS handle this font belongs to
FATTRS m_vFattrs; // Current fattrs struct
FACENAMEDESC m_vFname; // Current facename struct
bool m_bInternalPS; // Internally generated PS?
}; // end of CLASS wxFontRefData
#define M_FONTDATA ((wxFontRefData*)m_refData)
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxFontRefData
// ----------------------------------------------------------------------------
void wxFontRefData::Init(
int nPointSize
, wxFontFamily nFamily
, wxFontStyle nStyle
, wxFontWeight nWeight
, bool bUnderlined
, const wxString& rsFaceName
, wxFontEncoding vEncoding
)
{
m_nStyle = nStyle;
m_nPointSize = nPointSize;
m_nFamily = nFamily;
m_nStyle = nStyle;
m_nWeight = nWeight;
m_bUnderlined = bUnderlined;
m_sFaceName = rsFaceName;
m_vEncoding = vEncoding;
m_hFont = 0;
m_bNativeFontInfoOk = false;
m_nFontId = 0;
m_bTemporary = false;
m_pFM = (PFONTMETRICS)NULL;
m_hPS = NULLHANDLE;
m_nNumFonts = 0;
} // end of wxFontRefData::Init
void wxFontRefData::Init(
const wxNativeFontInfo& rInfo
, WXHFONT hFont //this is the FontId -- functions as the hFont for OS/2
, WXHANDLE hPS // Presentation Space we are using
)
{
//
// hFont may be zero, or it be passed in case we really want to
// use the exact font created in the underlying system
// (for example where we can't guarantee conversion from HFONT
// to LOGFONT back to HFONT)
//
m_hFont = hFont;
m_nFontId = (int)hFont;
m_bNativeFontInfoOk = true;
m_vNativeFontInfo = rInfo;
if (hPS == NULLHANDLE)
{
m_hPS = ::WinGetPS(HWND_DESKTOP);
m_bInternalPS = true;
}
else
m_hPS = (HPS)hPS;
m_nFontId = 0;
m_bTemporary = false;
m_pFM = (PFONTMETRICS)NULL;
m_nNumFonts = 0;
} // end of wxFontRefData::Init
wxFontRefData::~wxFontRefData()
{
Free();
}
bool wxFontRefData::Alloc( wxFont* pFont )
{
wxString sFaceName;
long flId = m_hFont;
long lRc;
ERRORID vError;
wxString sError;
if (!m_bNativeFontInfoOk)
{
wxFillLogFont( &m_vNativeFontInfo.fa
,&m_vNativeFontInfo.fn
,&m_hPS
,&m_bInternalPS
,&flId
,sFaceName
,pFont
);
m_bNativeFontInfoOk = true;
}
else
{
if (flId == 0L)
flId = 1L;
else
flId++;
if (flId > 254)
flId = 1L;
}
if((lRc = ::GpiCreateLogFont( m_hPS
,NULL
,flId
,&m_vNativeFontInfo.fa
)) != GPI_ERROR)
{
m_hFont = (WXHFONT)flId;
m_nFontId = flId;
}
if (!m_hFont)
{
vError = ::WinGetLastError(vHabmain);
sError = wxPMErrorToStr(vError);
wxLogLastError(wxT("CreateFont"));
}
::GpiSetCharSet(m_hPS, flId); // sets font for presentation space
::GpiQueryFontMetrics(m_hPS, sizeof(FONTMETRICS), &m_vNativeFontInfo.fm);
//
// Set refData members with the results
//
memcpy(&m_vFattrs, &m_vNativeFontInfo.fa, sizeof(m_vFattrs));
memcpy(&m_vFname, &m_vNativeFontInfo.fn, sizeof(m_vFname));
//
// Going to leave the point size alone. Mostly we use outline fonts
// that can be set to any point size inside of Presentation Parameters,
// regardless of whether or not the actual font is registered in the system.
// The GpiCreateLogFont will do enough by selecting the right family,
// and face name.
//
if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Times New Roman") == 0)
m_nFamily = wxFONTFAMILY_ROMAN;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Times New Roman MT 30") == 0)
m_nFamily = wxFONTFAMILY_ROMAN;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "@Times New Roman MT 30") == 0)
m_nFamily = wxFONTFAMILY_ROMAN;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Tms Rmn") == 0)
m_nFamily = wxFONTFAMILY_ROMAN;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "WarpSans") == 0)
m_nFamily = wxFONTFAMILY_DECORATIVE;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Helvetica") == 0)
m_nFamily = wxFONTFAMILY_SWISS;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Helv") == 0)
m_nFamily = wxFONTFAMILY_SWISS;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Script") == 0)
m_nFamily = wxFONTFAMILY_SCRIPT;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Courier New") == 0)
m_nFamily = wxFONTFAMILY_TELETYPE;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Courier") == 0)
m_nFamily = wxFONTFAMILY_TELETYPE;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "System Monospaced") == 0)
m_nFamily = wxFONTFAMILY_TELETYPE;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "System VIO") == 0)
m_nFamily = wxFONTFAMILY_MODERN;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "System Proportional") == 0)
m_nFamily = wxFONTFAMILY_MODERN;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Arial") == 0)
m_nFamily = wxFONTFAMILY_SWISS;
else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Swiss") == 0)
m_nFamily = wxFONTFAMILY_SWISS;
else
m_nFamily = wxFONTFAMILY_SWISS;
if (m_vNativeFontInfo.fa.fsSelection & FATTR_SEL_ITALIC)
m_nStyle = wxFONTSTYLE_ITALIC;
else
m_nStyle = wxFONTSTYLE_NORMAL;
switch(m_vNativeFontInfo.fn.usWeightClass)
{
case FWEIGHT_DONT_CARE:
m_nWeight = wxFONTWEIGHT_NORMAL;
break;
case FWEIGHT_NORMAL:
m_nWeight = wxFONTWEIGHT_NORMAL;
break;
case FWEIGHT_LIGHT:
m_nWeight = wxFONTWEIGHT_LIGHT;
break;
case FWEIGHT_BOLD:
m_nWeight = wxFONTWEIGHT_BOLD;
break;
case FWEIGHT_ULTRA_BOLD:
m_nWeight = wxFONTWEIGHT_MAX;
break;
default:
m_nWeight = wxFONTWEIGHT_NORMAL;
}
m_bUnderlined = ((m_vNativeFontInfo.fa.fsSelection & FATTR_SEL_UNDERSCORE) != 0);
m_sFaceName = (wxChar*)m_vNativeFontInfo.fa.szFacename;
m_vEncoding = wxGetFontEncFromCharSet(m_vNativeFontInfo.fa.usCodePage);
//
// We don't actuall keep the font around if using a temporary PS
//
if (m_bInternalPS)
{
if(m_hFont)
::GpiDeleteSetId( m_hPS
,flId
);
::WinReleasePS(m_hPS);
}
else
//
// Select the font into the Presentation space
//
::GpiSetCharSet(m_hPS, flId); // sets font for presentation space
return true;
} // end of wxFontRefData::Alloc
void wxFontRefData::Free()
{
if (m_pFM)
delete [] m_pFM;
m_pFM = (PFONTMETRICS)NULL;
if ( m_hFont )
{
::GpiDeleteSetId(m_hPS, 1L); /* delete the logical font */
m_nFontId = 0;
m_hFont = 0;
}
if (m_bInternalPS)
::WinReleasePS(m_hPS);
m_hPS = NULLHANDLE;
} // end of wxFontRefData::Free
// ----------------------------------------------------------------------------
// wxNativeFontInfo
// ----------------------------------------------------------------------------
void wxNativeFontInfo::Init()
{
memset(&fa, '\0', sizeof(FATTRS));
} // end of wxNativeFontInfo::Init
int wxNativeFontInfo::GetPointSize() const
{
return fm.lEmHeight;
} // end of wxNativeFontInfo::GetPointSize
wxFontStyle wxNativeFontInfo::GetStyle() const
{
return fa.fsSelection & FATTR_SEL_ITALIC ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL;
} // end of wxNativeFontInfo::GetStyle
wxFontWeight wxNativeFontInfo::GetWeight() const
{
switch(fn.usWeightClass)
{
case FWEIGHT_DONT_CARE:
return wxFONTWEIGHT_NORMAL;
case FWEIGHT_NORMAL:
return wxFONTWEIGHT_NORMAL;
case FWEIGHT_LIGHT:
return wxFONTWEIGHT_LIGHT;
case FWEIGHT_BOLD:
return wxFONTWEIGHT_BOLD;
case FWEIGHT_ULTRA_BOLD:
return wxFONTWEIGHT_MAX;
}
return wxFONTWEIGHT_NORMAL;
} // end of wxNativeFontInfo::GetWeight
bool wxNativeFontInfo::GetUnderlined() const
{
return ((fa.fsSelection & FATTR_SEL_UNDERSCORE) != 0);
} // end of wxNativeFontInfo::GetUnderlined
wxString wxNativeFontInfo::GetFaceName() const
{
return (wxChar*)fm.szFacename;
} // end of wxNativeFontInfo::GetFaceName
wxFontFamily wxNativeFontInfo::GetFamily() const
{
int nFamily;
//
// Extract family from facename
//
if (strcmp(fm.szFamilyname, "Times New Roman") == 0)
nFamily = wxFONTFAMILY_ROMAN;
else if (strcmp(fm.szFamilyname, "Times New Roman MT 30") == 0)
nFamily = wxFONTFAMILY_ROMAN;
else if (strcmp(fm.szFamilyname, "@Times New Roman MT 30") == 0)
nFamily = wxFONTFAMILY_ROMAN;
else if (strcmp(fm.szFamilyname, "Tms Rmn") == 0)
nFamily = wxFONTFAMILY_ROMAN;
else if (strcmp(fm.szFamilyname, "WarpSans") == 0)
nFamily = wxFONTFAMILY_DECORATIVE;
else if (strcmp(fm.szFamilyname, "Helvetica") == 0)
nFamily = wxFONTFAMILY_SWISS;
els
10BC8
e if (strcmp(fm.szFamilyname, "Helv") == 0)
nFamily = wxFONTFAMILY_SWISS;
else if (strcmp(fm.szFamilyname, "Script") == 0)
nFamily = wxFONTFAMILY_SCRIPT;
else if (strcmp(fm.szFamilyname, "Courier New") == 0)
nFamily = wxFONTFAMILY_TELETYPE;
else if (strcmp(fm.szFamilyname, "Courier") == 0)
nFamily = wxFONTFAMILY_TELETYPE;
else if (strcmp(fm.szFamilyname, "System Monospaced") == 0)
nFamily = wxFONTFAMILY_TELETYPE;
else if (strcmp(fm.szFamilyname, "System VIO") == 0)
nFamily = wxFONTFAMILY_MODERN;
else if (strcmp(fm.szFamilyname, "System Proportional") == 0)
nFamily = wxFONTFAMILY_MODERN;
else if (strcmp(fm.szFamilyname, "Arial") == 0)
nFamily = wxFONTFAMILY_SWISS;
else if (strcmp(fm.szFamilyname, "Swiss") == 0)
nFamily = wxFONTFAMILY_SWISS;
else
nFamily = wxFONTFAMILY_SWISS;
return (wxFontFamily)nFamily;
} // end of wxNativeFontInfo::GetFamily
wxFontEncoding wxNativeFontInfo::GetEncoding() const
{
return wxGetFontEncFromCharSet(fa.usCodePage);
} // end of wxNativeFontInfo::GetEncoding
void wxNativeFontInfo::SetPointSize(
int nPointsize
)
{
fm.lEmHeight = (LONG)nPointsize;
} // end of wxNativeFontInfo::SetPointSize
void wxNativeFontInfo::SetStyle(
wxFontStyle eStyle
)
{
switch (eStyle)
{
default:
wxFAIL_MSG( _T("unknown font style") );
// fall through
case wxFONTSTYLE_NORMAL:
break;
case wxFONTSTYLE_ITALIC:
case wxFONTSTYLE_SLANT:
fa.fsSelection |= FATTR_SEL_ITALIC;
break;
}
} // end of wxNativeFontInfo::SetStyle
void wxNativeFontInfo::SetWeight(
wxFontWeight eWeight
)
{
switch (eWeight)
{
default:
wxFAIL_MSG( _T("unknown font weight") );
// fall through
case wxFONTWEIGHT_NORMAL:
fn.usWeightClass = FWEIGHT_NORMAL;
break;
case wxFONTWEIGHT_LIGHT:
fn.usWeightClass = FWEIGHT_LIGHT;
break;
case wxFONTWEIGHT_BOLD:
fn.usWeightClass = FWEIGHT_BOLD;
break;
}
} // end of wxNativeFontInfo::SetWeight
void wxNativeFontInfo::SetUnderlined(
bool bUnderlined
)
{
if(bUnderlined)
fa.fsSelection |= FATTR_SEL_UNDERSCORE;
} // end of wxNativeFontInfo::SetUnderlined
bool wxNativeFontInfo::SetFaceName(
const wxString& sFacename
)
{
wxStrlcpy((wxChar*)fa.szFacename, sFacename, WXSIZEOF(fa.szFacename));
return true;
} // end of wxNativeFontInfo::SetFaceName
void wxNativeFontInfo::SetFamily(
wxFontFamily eFamily
)
{
wxString sFacename;
switch (eFamily)
{
case wxFONTFAMILY_SCRIPT:
sFacename = wxT("Tms Rmn");
break;
case wxFONTFAMILY_DECORATIVE:
sFacename = wxT("WarpSans");
break;
case wxFONTFAMILY_ROMAN:
sFacename = wxT("Tms Rmn");
break;
case wxFONTFAMILY_TELETYPE:
sFacename = wxT("Courier") ;
break;
case wxFONTFAMILY_MODERN:
sFacename = wxT("System VIO") ;
break;
case wxFONTFAMILY_SWISS:
sFacename = wxT("Helv") ;
break;
case wxFONTFAMILY_DEFAULT:
default:
sFacename = wxT("System VIO") ;
}
if (!wxStrlen((wxChar*)fa.szFacename) )
{
SetFaceName(sFacename);
}
} // end of wxNativeFontInfo::SetFamily
void wxNativeFontInfo::SetEncoding( wxFontEncoding eEncoding )
{
wxNativeEncodingInfo vInfo;
if ( !wxGetNativeFontEncoding( eEncoding
,&vInfo
))
{
if (wxFontMapper::Get()->GetAltForEncoding( eEncoding
,&vInfo
))
{
if (!vInfo.facename.empty())
{
//
// If we have this encoding only in some particular facename, use
// the facename - it is better to show the correct characters in a
// wrong facename than unreadable text in a correct one
//
SetFaceName(vInfo.facename);
}
}
else
{
// unsupported encoding, replace with the default
vInfo.charset = 850;
}
}
fa.usCodePage = (USHORT)vInfo.charset;
} // end of wxNativeFontInfo::SetFaceName
bool wxNativeFontInfo::FromString( const wxString& rsStr )
{
long lVal;
wxStringTokenizer vTokenizer(rsStr, _T(";"));
//
// First the version
//
wxString sToken = vTokenizer.GetNextToken();
if (sToken != _T('0'))
return false;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fm.lEmHeight = lVal;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fa.lAveCharWidth = lVal;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fa.fsSelection = (USHORT)lVal;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fa.fsType = (USHORT)lVal;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fa.fsFontUse = (USHORT)lVal;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fa.idRegistry = (USHORT)lVal;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fa.usCodePage = (USHORT)lVal;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fa.lMatch = lVal;
sToken = vTokenizer.GetNextToken();
if (!sToken.ToLong(&lVal))
return false;
fn.usWeightClass = (USHORT)lVal;
sToken = vTokenizer.GetNextToken();
if(!sToken)
return false;
wxStrcpy((wxChar*)fa.szFacename, sToken.c_str());
return true;
} // end of wxNativeFontInfo::FromString
wxString wxNativeFontInfo::ToString() const
{
wxString sStr;
sStr.Printf(_T("%d;%ld;%ld;%ld;%d;%d;%d;%d;%d;%ld;%d;%s"),
0, // version, in case we want to change the format later
fm.lEmHeight,
fa.lAveCharWidth,
fa.lMaxBaselineExt,
fa.fsSelection,
fa.fsType,
fa.fsFontUse,
fa.idRegistry,
fa.usCodePage,
fa.lMatch,
fn.usWeightClass,
(char *)fa.szFacename);
return sStr;
} // end of wxNativeFontInfo::ToString
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
bool wxFont::Create( const wxNativeFontInfo& rInfo,
WXHFONT hFont )
{
UnRef();
m_refData = new wxFontRefData( rInfo
,hFont
);
RealizeResource();
return true;
} // end of wxFont::Create
wxFont::wxFont(
const wxString& rsFontdesc
)
{
wxNativeFontInfo vInfo;
if (vInfo.FromString(rsFontdesc))
(void)Create(vInfo);
} // end of wxFont::wxFont
// ----------------------------------------------------------------------------
// Constructor for a font. Note that the real construction is done
// in wxDC::SetFont, when information is available about scaling etc.
// ----------------------------------------------------------------------------
bool wxFont::Create( int nPointSize,
wxFontFamily nFamily,
wxFontStyle nStyle,
wxFontWeight nWeight,
bool bUnderlined,
const wxString& rsFaceName,
wxFontEncoding vEncoding )
{
UnRef();
//
// wxDEFAULT is a valid value for the font size too so we must treat it
// specially here (otherwise the size would be 70 == wxDEFAULT value)
//
if (nPointSize == wxDEFAULT)
{
nPointSize = wxNORMAL_FONT->GetPointSize();
}
m_refData = new wxFontRefData( nPointSize
,nFamily
,nStyle
,nWeight
,bUnderlined
,rsFaceName
,vEncoding
);
RealizeResource();
return true;
} // end of wxFont::Create
wxFont::~wxFont()
{
} // end of wxFont::~wxFont
// ----------------------------------------------------------------------------
// real implementation
// Boris' Kovalenko comments:
// Because OS/2 fonts are associated with PS we can not create the font
// here, but we may check that font definition is true
// ----------------------------------------------------------------------------
wxGDIRefData *wxFont::CreateGDIRefData() const
{
return new wxFontRefData();
}
wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
{
return new wxFontRefData(*static_cast<const wxFontRefData *>(data));
}
bool wxFont::RealizeResource()
{
if ( GetResourceHandle() )
{
return true;
}
return M_FONTDATA->Alloc(this);
} // end of wxFont::RealizeResource
bool wxFont::FreeResource( bool WXUNUSED(bForce) )
{
if (GetResourceHandle())
{
M_FONTDATA->Free();
return true;
}
return false;
} // end of wxFont::FreeResource
WXHANDLE wxFont::GetResourceHandle() const
{
return GetHFONT();
} // end of wxFont::GetResourceHandle
WXHFONT wxFont::GetHFONT() const
{
return M_FONTDATA ? M_FONTDATA->GetHFONT() : 0;
} // end of wxFont::GetHFONT
bool wxFont::IsFree() const
{
return M_FONTDATA && (M_FONTDATA->GetHFONT() == 0);
} // end of wxFont::IsFree
// ----------------------------------------------------------------------------
// change font attribute: we recreate font when doing it
// ----------------------------------------------------------------------------
void wxFont::SetPointSize(
int nPointSize
)
{
AllocExclusive();
M_FONTDATA->SetPointSize(nPointSize);
RealizeResource();
} // end of wxFont::SetPointSize
void wxFont::SetFamily(
wxFontFamily nFamily
)
{
AllocExclusive();
M_FONTDATA->SetFamily(nFamily);