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

View File

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

View File

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

View File

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

View File

@ -3309,6 +3309,7 @@ type
var var
Xlfd: TXLFD; Xlfd: TXLFD;
CharsetFilter: TStringList; CharsetFilter: TStringList;
PitchFilter: TStringList;
EnumLogFont: TEnumLogFontEx; EnumLogFont: TEnumLogFontEx;
Metric: TNewTextMetricEx; Metric: TNewTextMetricEx;
@ -3374,6 +3375,24 @@ var
end; end;
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; function XLFDToCharset: byte;
const const
CharsetPriority: array[1..19] of byte = CharsetPriority: array[1..19] of byte =
@ -3572,7 +3591,7 @@ var
var var
xFonts: PPChar; xFonts: PPChar;
FontList: TStringList; FontList: TStringList;
I,J,N: Integer; I,J,K,N: Integer;
Tmp,FandF: String; Tmp,FandF: String;
begin begin
result := 0; result := 0;
@ -3593,22 +3612,26 @@ begin
// foundry and family filter // foundry and family filter
FandF := FoundryAndFamilyFilter(lpLogFont^.lfFaceName); FandF := FoundryAndFamilyFilter(lpLogFont^.lfFaceName);
// charset
// pitchandfamily
// todo: ignored atm
FontList := TStringlist.Create; FontList := TStringlist.Create;
CharSetFilter := TStringList.Create; CharSetFilter := TStringList.Create;
PitchFilter := TStringList.Create;
PitchFilter.Duplicates := dupIgnore;
try try
QueueCharSetFilter(lpLogFont^.lfCharSet); QueueCharSetFilter(lpLogFont^.lfCharSet);
QueuePitchFilter(lpLogFont^.lfPitchAndFamily);
{$ifdef verboseEnumFonts} {$ifdef verboseEnumFonts}
for j:=0 to CharSetFilter.Count-1 do begin for j:=0 to CharSetFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-*-*-'+CharSetFilter[j]; // 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); DebugLn('EnumFontFamiliesEx: will enumerate fonts matching: ', tmp);
end; end;
end;
{$endif} {$endif}
for j:=0 to CharSetFilter.Count-1 do begin for j:=0 to CharSetFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-*-*-'+CharSetFilter[j]; for k:=0 to PitchFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-'+PitchFilter[k]+'-*-'+CharSetFilter[j];
{$ifdef UNIX} {$ifdef UNIX}
XFonts := XListFonts(gdk_display, pchar(Tmp), 10000, @N); XFonts := XListFonts(gdk_display, pchar(Tmp), 10000, @N);
{$else} {$else}
@ -3629,7 +3652,9 @@ begin
{$endif} {$endif}
end; end;
end; end;
end;
finally finally
PitchFilter.Free;
Fontlist.Free; Fontlist.Free;
CharSetFilter.Free; CharSetFilter.Free;
end; end;