如何获得字体可用字号?(100分)

  • 主题发起人 主题发起人 3h
  • 开始时间 开始时间
3

3h

Unregistered / Unconfirmed
GUEST, unregistred user!
用SCREEN。FONTS可获得系统字体列表,但如何得到字体所能使用的字号吗?<br>象一些小字体smallfont只能用12以下的字号一样,其它的怎么知道?
 
Font.Size是可以任意设定的,对于TrueType字体是<br>这样,而点阵字体则可以在一定的大小以后变成<br>接近的True Type字体。
 
象一些字体,如MS sans是不允许有9的字号,但别的却行,那是什么道理?
 
MS sans是点阵字库,没有配备9点的字体。
 
你可以查阅RXLIB系列控件的源码对取得字型有详细的论述,它还有对TRUE TYPE字体<br>的检测功能,也可以查阅AHH系列控件,它有关于取得字号的代码<br>GOOD LUCK!
 
我不懂那些东西,帮我查查看要用什么命令,OK?
 
以下的函数GetFontSizeList用来取得字体名为FontName的字体的所<br>有可用尺寸,而EnumFontsSize是其中要用到的字体枚举回调函数:<br><br>function EnumFontsSize(var LogFont: TLogFont; var TextMetric: TTextMetric;<br>&nbsp; FontType: Integer; Data: Pointer): Integer; stdcall;<br>begin<br>&nbsp; TStrings( Data ).Add(IntToStr( LogFont.lfHeight) );<br>&nbsp; Result := 1;<br>end;<br><br>procedure GetFontSizeList( FontName : String; List : TStrings );<br>//FontName,是字体名;<br>//这种字体的所有可用尺寸将被填在List中。<br>var<br>&nbsp; DC: HDC;<br>begin<br>&nbsp; List.Clear;<br>&nbsp; DC := GetDC(0);<br>&nbsp;EnumFonts(DC, PChar(FontName), @EnumFontsSize, Pointer(List));<br>&nbsp; ReleaseDC(0, DC);<br>end;<br>
 
我用GetFontSizeList(comboBox1.TEXT, ComboBox2.Items)<br>结果得到的COMBOBOX2只有为数不多的项,只有在非TRUWTYPE时才有几个,一般<br>TRUETYPE只有一个很大值,象45什么。为什么?
 
Try this:(it's from LMD TFontsizeCombobox)<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; &nbsp;VRES:Integer;<br><br>const<br>&nbsp; MaxStdSizes=16;<br><br>function EnumFontFamiliesProc(var LogFont: TLogFont; var TextMetric: TTextMetric;<br>&nbsp; FontType: Integer; Data:Pointer): Integer; {$IFDEF WIN32} stdcall; {$ELSE} export; {$ENDIF}<br><br>&nbsp; procedure AddToList(const aValue:String);<br>&nbsp; var<br>&nbsp; &nbsp; j:Integer;<br>&nbsp; &nbsp; c:Boolean;<br>&nbsp; begin<br>&nbsp; &nbsp; j:=0;<br>&nbsp; &nbsp; c:=False;<br>&nbsp; &nbsp; with TListBox(Data) do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; while (j&lt;Items.Count) and not c do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if StrToInt(aValue)&gt;=StrToInt(Items[j]) then Inc(j) else c:=True;<br>&nbsp; &nbsp; &nbsp; &nbsp; Items.Insert(j, aValue);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br><br>var<br>&nbsp; i:Integer;<br>&nbsp; c:String;<br>const<br>&nbsp; csizes:array[0..MaxStdSizes-1] of Integer=(8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72);<br><br>begin<br>&nbsp; result:=0;<br>&nbsp; with TListBox(Data) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if (FontType and TRUETYPE_FONTTYPE=TRUETYPE_FONTTYPE) or (FontType in [0,2]) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For i:=0 to (MaxStdSizes-1) do Items.Add(IntToStr(Csizes));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result:=0<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; if (FontType and RASTER_FONTTYPE=RASTER_FONTTYPE)<br>&nbsp; &nbsp; &nbsp; {or (FontType and DEVICE_FONTTYPE=DEVICE_FONTTYPE)} then<br>&nbsp; &nbsp; &nbsp; &nbsp; with TextMetric do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c:=IntToStr(Round((tmHeight-tmInternalLeading)*72 / VRES));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Items.IndexOf(c)=-1 then AddToList(c);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result:=1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end<br>end;<br><br>procedure TForm1.DoList(FFontName:String);<br> var<br>&nbsp; &nbsp; buffer:array[0..255] of Char;<br>&nbsp; DC:HDC;<br>&nbsp; begin<br>&nbsp; ListBox1.Items.Clear;<br><br>&nbsp; &nbsp; DC:=GetDC(0);<br>&nbsp; &nbsp; StrPCopy(Buffer, FFontName);<br>&nbsp; &nbsp; vres:=GetDeviceCaps(DC, LOGPIXELSY);<br>&nbsp; &nbsp; EnumFontFamilies(DC, Buffer, @EnumFontFamiliesProc,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LongInt(ListBox1));<br>&nbsp; &nbsp; &nbsp;ReleaseDC(0, DC);<br>&nbsp; end;<br><br>
 
多人接受答案了。
 
后退
顶部