-
Notifications
You must be signed in to change notification settings - Fork 0
/
FontForm.cpp
193 lines (158 loc) · 4.14 KB
/
FontForm.cpp
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
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "FontForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TfontSelect* fontSelect;
//---------------------------------------------------------------------------
__fastcall TfontSelect::TfontSelect(TComponent* Owner, TFont* font)
: TForm(Owner)
{
if (font)
{
//memset(font, 0, sizeof(TFont));
Font = font;
}
}
void __fastcall TfontSelect::FormCreate(TObject* Sender)
{
TStringList* list = new TStringList();
if (list)
{
list->Sorted = true;
list->Duplicates = System::Types::TDuplicates::dupIgnore;
CollectFonts(list);
fontFamilyList->Clear();
//
for (int i = 0; i < list->Count; i++)
{
fontFamilyList->Items->Add(list->Strings[ i ]);
}
delete list;
}
}
void __fastcall TfontSelect::okButtonClick(TObject* Sender)
{
Font->Family = sample->Font->Family;
Font->Size = sample->Font->Size;
Font->Style = sample->Font->Style;
}
void __fastcall TfontSelect::underlineChange(TObject* Sender)
{
TCheckBox* cb = dynamic_cast< TCheckBox * >(Sender);
if (cb)
{
if (cb->IsChecked)
{
if (UpperCase(cb->Name) == "UNDERLINE")
{
TFontStyles AStyle(4);
sample->Font->Style = sample->Font->Style + AStyle;
}
else
{
TFontStyles AStyle(8);
sample->Font->Style = sample->Font->Style + AStyle;
}
}
else
{
if (UpperCase(cb->Name) == "UNDERLINE")
{
TFontStyles AStyle(4);
sample->Font->Style = sample->Font->Style - AStyle;
}
else
{
TFontStyles AStyle(8);
sample->Font->Style = sample->Font->Style - AStyle;
}
}
}
}
void __fastcall TfontSelect::familyNameKeyUp(TObject* Sender, WORD& Key, System::WideChar& KeyChar, TShiftState Shift)
{
if (KeyChar)
{
for (int i = 0;i < fontFamilyList->Items->Count; i++)
{
//fontFamilyList->Items->Strings[0]
if (familyName->Text.Length() <= fontFamilyList->Items->Strings[ i ].Length())
{
AnsiString s = AnsiString(fontFamilyList->Items->Strings[ i ]).SubString(0,familyName->Text.Length());
//if (UpperCase(familyName->Text) == UpperCase(fontFamilyList->Items->Strings[ i ]))
if (UpperCase(familyName->Text) == UpperCase(s))
{
fontFamilyList->ItemIndex = i;
break;
}
}
}
}
}
void __fastcall TfontSelect::fontSizeKeyUp(TObject* Sender, WORD& Key, System::WideChar& KeyChar, TShiftState Shift)
{
if (KeyChar)
{
for (int i = 0; i < fontSizeList->Items->Count; i++)
{
AnsiString s = fontSizeList->Items->Strings[ i ];
//if (UpperCase(familyName->Text) == UpperCase(fontFamilyList->Items->Strings[ i ]))
if (fontSize->Text == s)
{
fontSizeList->ItemIndex = i;
break;
}
}
}
}
#ifdef _Windows
int __stdcall EnumFontsProc(const TLogFont* LogFont, const TTextMetric* TextMetric, unsigned long FontType, LPARAM lparam)
{
TStringList* S = (TStringList *)lparam;
AnsiString temp;
temp = LogFont->lfFaceName;
char c = temp.c_str()[ 0 ];
if ((S->Count == 0) || (AnsiCompareText(AnsiString(S->Strings[ S->Count - 1 ]), temp) != 0) && c != '@')
{
S->Add(temp);
//return 1;
}
return 1;
}
#endif
void __fastcall TfontSelect::CollectFonts(TStringList* FontList)
{
#ifdef __APPLE__
NsFontManager fManager;
NSArray list;
NSString lItem;
#else
//#ifdef MSWINDOWS
HDC DC;
TLogFont* LFont = new TLogFont();
#endif
#ifdef __APPLE__
fManager = TNsFontManager.Wrap(TNsFontManager.OCClass.sharedFontManager);
list = fManager.availableFontFamilies;
if ((list != NULL) && (list.count > 0))
{
begin
for (int i = 0; i < to list.Count - 1; i++)
{
lItem = TNSString.Wrap(list.objectAtIndex(i));
FontList->Add(String(lItem.UTF8String))
}
}
#else
//#ifdef MSWINDOWS
DC = GetDC(0);
memset(LFont, 0, sizeof(TLogFont));
//LFont->lfCharSet = DEFAULT_CHARSET;
LFont->lfCharSet = ANSI_CHARSET;
EnumFontFamiliesEx(DC, LFont, & EnumFontsProc, LPARAM(FontList), 0);
ReleaseDC(0, DC);
#endif
}