gtk: font enumeration support for requested pitch, fontenum example updated

git-svn-id: trunk@10406 -
This commit is contained in:
jesus 2007-01-09 09:02:10 +00:00
parent de5347bf38
commit 667426dd97
6 changed files with 129 additions and 99 deletions

View File

@ -6,6 +6,7 @@
<General>
<Flags>
<SaveClosedFiles Value="False"/>
<SaveOnlyProjectUnits Value="True"/>
</Flags>
<MainUnit Value="0"/>
<IconPath Value="./"/>
@ -46,14 +47,13 @@
<IsPartOfProject Value="True"/>
<ResourceFilename Value="mainunit.lrs"/>
<UnitName Value="mainunit"/>
<CursorPos X="55" Y="554"/>
<TopLine Value="118"/>
<CursorPos X="41" Y="447"/>
<TopLine Value="400"/>
<EditorIndex Value="0"/>
<UsageCount Value="158"/>
<Loaded Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="0" HistoryIndex="-1"/>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>

View File

@ -8,6 +8,7 @@ uses
{ add your units here }, mainunit;
begin
Application.Title:='project1';
Application.Initialize;
Application.CreateForm(TfrmMain, frmMain);
Application.Run;

View File

@ -1,68 +1,66 @@
object frmMain: TfrmMain
Left = 563
Left = 33
Height = 440
Top = 356
Top = 116
Width = 714
HorzScrollBar.Page = 713
VertScrollBar.Page = 439
ActiveControl = lbFamily
Caption = 'frmMain'
ClientHeight = 440
ClientWidth = 714
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnShow = FormShow
ShowHint = True
object Label3: TLabel
Left = 548
Height = 17
Height = 13
Top = 257
Width = 36
Width = 29
Caption = 'Filtro'
Color = clNone
ParentColor = False
end
object Label4: TLabel
Left = 216
Height = 17
Height = 13
Top = 16
Width = 94
Width = 73
Caption = 'Face font list'
Color = clNone
ParentColor = False
end
object Label5: TLabel
Left = 424
Height = 17
Height = 13
Top = 11
Width = 45
Width = 35
Caption = 'Styles'
Color = clNone
ParentColor = False
end
object Sizes: TLabel
Left = 648
Height = 17
Height = 13
Top = 11
Width = 40
Width = 31
Caption = 'Sizes'
Color = clNone
ParentColor = False
end
object lblCharset: TLabel
Left = 424
Height = 17
Height = 13
Top = 176
Width = 73
Width = 57
Caption = 'lblCharset'
Color = clNone
ParentColor = False
end
object Label6: TLabel
Left = 11
Height = 17
Height = 13
Top = 16
Width = 36
Width = 29
Caption = 'Filter'
Color = clNone
ParentColor = False
@ -152,17 +150,17 @@ object frmMain: TfrmMain
end
object chkStrike: TCheckBox
Left = 591
Height = 24
Height = 20
Top = 312
Width = 88
Width = 72
Caption = 'Strikeout'
TabOrder = 8
end
object chkUnderLine: TCheckBox
Left = 592
Height = 24
Height = 20
Top = 336
Width = 98
Width = 81
Caption = 'UnderLine'
TabOrder = 9
end

View File

@ -1,55 +1,54 @@
{ Das ist eine automatisch erzeugte Lazarus-Ressourcendatei }
LazarusResources.Add('TfrmMain','FORMDATA',[
'TPF0'#8'TfrmMain'#7'frmMain'#4'Left'#3'3'#2#6'Height'#3#184#1#3'Top'#3'd'#1#5
+'Width'#3#202#2#18'HorzScrollBar.Page'#3#201#2#18'VertScrollBar.Page'#3#183#1
+#13'ActiveControl'#7#8'lbFamily'#7'Caption'#6#7'frmMain'#12'ClientHeight'#3
+#184#1#11'ClientWidth'#3#202#2#12'OnCloseQuery'#7#14'FormCloseQuery'#8'OnCre'
+'ate'#7#10'FormCreate'#6'OnShow'#7#8'FormShow'#8'ShowHint'#9#0#6'TLabel'#6'L'
+'abel3'#4'Left'#3'$'#2#6'Height'#2#17#3'Top'#3#1#1#5'Width'#2'$'#7'Caption'#6
+#6'Filtro'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#6'Label4'#4
+'Left'#3#216#0#6'Height'#2#17#3'Top'#2#16#5'Width'#2'^'#7'Caption'#6#14'Face'
+' font list'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#6'Label5'#4
+'Left'#3#168#1#6'Height'#2#17#3'Top'#2#11#5'Width'#2'-'#7'Caption'#6#6'Style'
+'s'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#5'Sizes'#4'Left'#3
+#136#2#6'Height'#2#17#3'Top'#2#11#5'Width'#2'('#7'Caption'#6#5'Sizes'#5'Colo'
+'r'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#10'lblCharset'#4'Left'#3#168
+#1#6'Height'#2#17#3'Top'#3#176#0#5'Width'#2'I'#7'Caption'#6#10'lblCharset'#5
+'Color'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#6'Label6'#4'Left'#2#11#6
+'Height'#2#17#3'Top'#2#16#5'Width'#2'$'#7'Caption'#6#6'Filter'#5'Color'#7#6
+'clNone'#11'ParentColor'#8#0#0#8'TListBox'#8'lbFamily'#4'Left'#3#216#0#6'Hei'
+'ght'#3#16#1#3'Top'#2' '#5'Width'#3#200#0#7'OnClick'#7#13'lbFamilyClick'#8'T'
+'abOrder'#2#0#8'TopIndex'#2#255#0#0#9'TComboBox'#9'cbCharset'#4'Left'#2#8#6
+'Height'#2#21#3'Top'#2'%'#5'Width'#3#194#0#16'AutoCompleteText'#11#22'cbactE'
+'ndOfLineComplete'#20'cbactSearchAscending'#0#9'MaxLength'#2#0#8'TabOrder'#2
+#1#4'Text'#6#12'ANSI_CHARSET'#0#0#7'TButton'#7'Button2'#4'Left'#2#8#6'Height'
+#2#25#3'Top'#2'`'#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'
+#6#12'apply filter'#7'OnClick'#7#12'Button2Click'#8'TabOrder'#2#2#0#0#8'TLis'
+'tBox'#8'lbStyles'#4'Left'#3#168#1#6'Height'#3#128#0#3'Top'#2' '#5'Width'#3
+#208#0#7'OnClick'#7#13'lbStylesClick'#8'TabOrder'#2#3#8'TopIndex'#2#255#0#0#8
+'TListBox'#7'lbSizes'#4'Left'#3#128#2#6'Height'#3#16#1#3'Top'#2' '#5'Width'#2
+'8'#7'OnClick'#7#12'lbSizesClick'#8'TabOrder'#2#4#8'TopIndex'#2#255#0#0#8'TL'
+'istBox'#9'lbCharset'#4'Left'#3#168#1#6'Height'#2'p'#3'Top'#3#192#0#5'Width'
+#3#208#0#7'OnClick'#7#14'lbCharsetClick'#8'TabOrder'#2#5#8'TopIndex'#2#255#0
+#0#9'TComboBox'#7'cbPitch'#4'Left'#2#8#6'Height'#2#21#3'Top'#2'='#5'Width'#3
+#194#0#16'AutoCompleteText'#11#22'cbactEndOfLineComplete'#20'cbactSearchAsce'
+'nding'#0#9'ItemIndex'#2#0#13'Items.Strings'#1#6#13'DEFAULT_PITCH'#6#11'FIXE'
+'D_PITCH'#6#14'VARIABLE_PITCH'#6#9'MONO_FONT'#0#9'MaxLength'#2#0#8'TabOrder'
+#2#6#4'Text'#6#13'DEFAULT_PITCH'#0#0#7'TButton'#10'BtnFontDlg'#4'Left'#2'8'#6
+'Height'#2'('#3'Top'#3'p'#1#5'Width'#3#152#0#25'BorderSpacing.InnerBorder'#2
+#4#7'Caption'#6#8'Font Dlg'#7'OnClick'#7#15'BtnFontDlgClick'#8'TabOrder'#2#7
+#0#0#9'TCheckBox'#9'chkStrike'#4'Left'#3'O'#2#6'Height'#2#24#3'Top'#3'8'#1#5
+'Width'#2'X'#7'Caption'#6#9'Strikeout'#8'TabOrder'#2#8#0#0#9'TCheckBox'#12'c'
+'hkUnderLine'#4'Left'#3'P'#2#6'Height'#2#24#3'Top'#3'P'#1#5'Width'#2'b'#7'Ca'
+'ption'#6#9'UnderLine'#8'TabOrder'#2#9#0#0#7'TButton'#7'Button1'#4'Left'#2'8'
+#6'Height'#2')'#3'Top'#3'8'#1#5'Width'#3#153#0#25'BorderSpacing.InnerBorder'
+#2#4#7'Caption'#6#17'Reset Sample Text'#7'OnClick'#7#12'Button1Click'#8'TabO'
+'rder'#2#10#0#0#11'TStringGrid'#4'grid'#4'Left'#3#216#0#6'Height'#2'x'#3'Top'
+#3'8'#1#5'Width'#3'p'#1#15'AutoFillColumns'#9#8'ColCount'#2#1#16'DefaultRowH'
+'eight'#2#17#10'FixedColor'#7#9'clBtnFace'#9'FixedCols'#2#0#9'FixedRows'#2#0
+#13'GridLineWidth'#2#0#7'Options'#11#15'goFixedVertLine'#15'goFixedHorzLine'
+#10'goVertLine'#10'goHorzLine'#13'goRangeSelect'#9'goEditing'#14'goSmoothScr'
+'oll'#0#8'RowCount'#2#5#10'ScrollBars'#7#10'ssAutoBoth'#8'TabOrder'#2#11#7'T'
+'abStop'#9#0#0#11'TFontDialog'#11'FontDialog1'#5'Title'#6#13'Select a font'#4
+'left'#3'8'#1#3'top'#3#128#1#0#0#0
'TPF0'#8'TfrmMain'#7'frmMain'#4'Left'#2'!'#6'Height'#3#184#1#3'Top'#2't'#5'Wi'
+'dth'#3#202#2#18'HorzScrollBar.Page'#3#201#2#18'VertScrollBar.Page'#3#183#1
+#13'ActiveControl'#7#8'lbFamily'#7'Caption'#6#7'frmMain'#12'OnCloseQuery'#7
+#14'FormCloseQuery'#8'OnCreate'#7#10'FormCreate'#6'OnShow'#7#8'FormShow'#8'S'
+'howHint'#9#0#6'TLabel'#6'Label3'#4'Left'#3'$'#2#6'Height'#2#13#3'Top'#3#1#1
+#5'Width'#2#29#7'Caption'#6#6'Filtro'#5'Color'#7#6'clNone'#11'ParentColor'#8
+#0#0#6'TLabel'#6'Label4'#4'Left'#3#216#0#6'Height'#2#13#3'Top'#2#16#5'Width'
+#2'I'#7'Caption'#6#14'Face font list'#5'Color'#7#6'clNone'#11'ParentColor'#8
+#0#0#6'TLabel'#6'Label5'#4'Left'#3#168#1#6'Height'#2#13#3'Top'#2#11#5'Width'
+#2'#'#7'Caption'#6#6'Styles'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#6'TL'
+'abel'#5'Sizes'#4'Left'#3#136#2#6'Height'#2#13#3'Top'#2#11#5'Width'#2#31#7'C'
+'aption'#6#5'Sizes'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#10
+'lblCharset'#4'Left'#3#168#1#6'Height'#2#13#3'Top'#3#176#0#5'Width'#2'9'#7'C'
+'aption'#6#10'lblCharset'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabe'
+'l'#6'Label6'#4'Left'#2#11#6'Height'#2#13#3'Top'#2#16#5'Width'#2#29#7'Captio'
+'n'#6#6'Filter'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#8'TListBox'#8'lbF'
+'amily'#4'Left'#3#216#0#6'Height'#3#16#1#3'Top'#2' '#5'Width'#3#200#0#7'OnCl'
+'ick'#7#13'lbFamilyClick'#8'TabOrder'#2#0#8'TopIndex'#2#255#0#0#9'TComboBox'
+#9'cbCharset'#4'Left'#2#8#6'Height'#2#21#3'Top'#2'%'#5'Width'#3#194#0#16'Aut'
+'oCompleteText'#11#22'cbactEndOfLineComplete'#20'cbactSearchAscending'#0#9'M'
+'axLength'#2#0#8'TabOrder'#2#1#4'Text'#6#12'ANSI_CHARSET'#0#0#7'TButton'#7'B'
+'utton2'#4'Left'#2#8#6'Height'#2#25#3'Top'#2'`'#5'Width'#2'K'#25'BorderSpaci'
+'ng.InnerBorder'#2#4#7'Caption'#6#12'apply filter'#7'OnClick'#7#12'Button2Cl'
+'ick'#8'TabOrder'#2#2#0#0#8'TListBox'#8'lbStyles'#4'Left'#3#168#1#6'Height'#3
+#128#0#3'Top'#2' '#5'Width'#3#208#0#7'OnClick'#7#13'lbStylesClick'#8'TabOrde'
+'r'#2#3#8'TopIndex'#2#255#0#0#8'TListBox'#7'lbSizes'#4'Left'#3#128#2#6'Heigh'
+'t'#3#16#1#3'Top'#2' '#5'Width'#2'8'#7'OnClick'#7#12'lbSizesClick'#8'TabOrde'
+'r'#2#4#8'TopIndex'#2#255#0#0#8'TListBox'#9'lbCharset'#4'Left'#3#168#1#6'Hei'
+'ght'#2'p'#3'Top'#3#192#0#5'Width'#3#208#0#7'OnClick'#7#14'lbCharsetClick'#8
+'TabOrder'#2#5#8'TopIndex'#2#255#0#0#9'TComboBox'#7'cbPitch'#4'Left'#2#8#6'H'
+'eight'#2#21#3'Top'#2'='#5'Width'#3#194#0#16'AutoCompleteText'#11#22'cbactEn'
+'dOfLineComplete'#20'cbactSearchAscending'#0#9'ItemIndex'#2#0#13'Items.Strin'
+'gs'#1#6#13'DEFAULT_PITCH'#6#11'FIXED_PITCH'#6#14'VARIABLE_PITCH'#6#9'MONO_F'
+'ONT'#0#9'MaxLength'#2#0#8'TabOrder'#2#6#4'Text'#6#13'DEFAULT_PITCH'#0#0#7'T'
+'Button'#10'BtnFontDlg'#4'Left'#2'8'#6'Height'#2'('#3'Top'#3'p'#1#5'Width'#3
+#152#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#8'Font Dlg'#7'OnClick'
+#7#15'BtnFontDlgClick'#8'TabOrder'#2#7#0#0#9'TCheckBox'#9'chkStrike'#4'Left'
+#3'O'#2#6'Height'#2#20#3'Top'#3'8'#1#5'Width'#2'H'#7'Caption'#6#9'Strikeout'
+#8'TabOrder'#2#8#0#0#9'TCheckBox'#12'chkUnderLine'#4'Left'#3'P'#2#6'Height'#2
+#20#3'Top'#3'P'#1#5'Width'#2'Q'#7'Caption'#6#9'UnderLine'#8'TabOrder'#2#9#0#0
+#7'TButton'#7'Button1'#4'Left'#2'8'#6'Height'#2')'#3'Top'#3'8'#1#5'Width'#3
+#153#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#17'Reset Sample Text'#7
+'OnClick'#7#12'Button1Click'#8'TabOrder'#2#10#0#0#11'TStringGrid'#4'grid'#4
+'Left'#3#216#0#6'Height'#2'x'#3'Top'#3'8'#1#5'Width'#3'p'#1#15'AutoFillColum'
+'ns'#9#8'ColCount'#2#1#16'DefaultRowHeight'#2#17#10'FixedColor'#7#9'clBtnFac'
+'e'#9'FixedCols'#2#0#9'FixedRows'#2#0#13'GridLineWidth'#2#0#7'Options'#11#15
+'goFixedVertLine'#15'goFixedHorzLine'#10'goVertLine'#10'goHorzLine'#13'goRan'
+'geSelect'#9'goEditing'#14'goSmoothScroll'#0#8'RowCount'#2#5#10'ScrollBars'#7
+#10'ssAutoBoth'#8'TabOrder'#2#11#7'TabStop'#9#0#0#11'TFontDialog'#11'FontDia'
+'log1'#5'Title'#6#13'Select a font'#4'left'#3'8'#1#3'top'#3#128#1#0#0#0
]);

View File

@ -418,7 +418,14 @@ begin
// but here, we have the list filtered by Charset
lf.lfCharSet := GetCharSet;
lf.lfFaceName := '';
lf.lfPitchAndFamily := 0;
case cbPitch.ItemIndex of
1: i:=FIXED_PITCH;
2: i:=VARIABLE_PITCH;
3: i:=MONO_FONT;
else
i:=DEFAULT_PITCH;
end;
lf.lfPitchAndFamily := i;
{$ifdef debug}
WriteLn('LoadFontList: for charset=',CharSetToString(lf.lfcharset));

View File

@ -3309,6 +3309,7 @@ type
var
Xlfd: TXLFD;
CharsetFilter: TStringList;
PitchFilter: TStringList;
EnumLogFont: TEnumLogFontEx;
Metric: TNewTextMetricEx;
@ -3373,6 +3374,24 @@ var
CharsetFilter.Add(s);
end;
end;
procedure QueuePitchFilter(Pitch: byte);
begin
if pitch and FIXED_PITCH = FIXED_PITCH then begin
PitchFilter.Add('m');
PitchFilter.Add('c'); // character cell it's also fixed pitch
end;
if pitch and VARIABLE_PITCH = VARIABLE_PITCH then
PitchFilter.Add('p');
if pitch and MONO_FONT = MONO_FONT then
PitchFilter.Add('m');
if PitchFilter.Count=0 then
PitchFilter.Add('*');
end;
function XLFDToCharset: byte;
const
@ -3572,7 +3591,7 @@ var
var
xFonts: PPChar;
FontList: TStringList;
I,J,N: Integer;
I,J,K,N: Integer;
Tmp,FandF: String;
begin
result := 0;
@ -3593,43 +3612,49 @@ begin
// foundry and family filter
FandF := FoundryAndFamilyFilter(lpLogFont^.lfFaceName);
// charset
// pitchandfamily
// todo: ignored atm
FontList := TStringlist.Create;
CharSetFilter := TStringList.Create;
PitchFilter := TStringList.Create;
PitchFilter.Duplicates := dupIgnore;
try
QueueCharSetFilter(lpLogFont^.lfCharSet);
QueuePitchFilter(lpLogFont^.lfPitchAndFamily);
{$ifdef verboseEnumFonts}
for j:=0 to CharSetFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-*-*-'+CharSetFilter[j];
DebugLn('EnumFontFamiliesEx: will enumerate fonts matching: ', tmp);
// pitch filter is guaranteed to have at least one element
for k:=0 to PitchFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-'+PitchFilter[k]+'-*-'+CharSetFilter[j];
DebugLn('EnumFontFamiliesEx: will enumerate fonts matching: ', tmp);
end;
end;
{$endif}
for j:=0 to CharSetFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-*-*-'+CharSetFilter[j];
{$ifdef UNIX}
XFonts := XListFonts(gdk_display, pchar(Tmp), 10000, @N);
{$else}
{$warning implement getting XFonts for this OS}
N:=0;
{$endif}
try
{$ifdef VerboseEnumFonts}
DebugLn('EnumFontFamiliesEx: found ',dbgs(N),' fonts matching: ', tmp);
{$endif}
for i:=0 to N-1 do
if XFonts[i]<>nil then
if ProcessXFont(i, XFonts[i], FontList) then
break;
finally
for k:=0 to PitchFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-'+PitchFilter[k]+'-*-'+CharSetFilter[j];
{$ifdef UNIX}
XFreeFontNames(XFonts);
XFonts := XListFonts(gdk_display, pchar(Tmp), 10000, @N);
{$else}
{$warning implement getting XFonts for this OS}
N:=0;
{$endif}
try
{$ifdef VerboseEnumFonts}
DebugLn('EnumFontFamiliesEx: found ',dbgs(N),' fonts matching: ', tmp);
{$endif}
for i:=0 to N-1 do
if XFonts[i]<>nil then
if ProcessXFont(i, XFonts[i], FontList) then
break;
finally
{$ifdef UNIX}
XFreeFontNames(XFonts);
{$endif}
end;
end;
end;
finally
PitchFilter.Free;
Fontlist.Free;
CharSetFilter.Free;
end;