保存字体,加载字体

给你两个函数。
//保存字体
function SaveFont(MidFont:TFont;FileName,CtrName:String):Boolean;
var
    FontFile:TIniFile;
begin
  Result:=True;
  FontFile:=TIniFile.Create(FileName);
  FontFile.WriteString(CtrName, 'FontName', MidFont.Name);
  FontFile.WriteString(CtrName, 'FontStyle',SetFontStyle(MidFont.Style));
  FontFile.WriteInteger(CtrName, 'FontCharSet', MidFont.CharSet);
  FontFile.WriteInteger(CtrName, 'FontColor', MidFont.Color);
  FontFile.WriteInteger(CtrName, 'FontSize', MidFont.Size );
  FontFile.WriteInteger(CtrName, 'FontHeight',MidFont.Height);
  FontFile.Free;
end;

//加载字体
function LoadFont(FileName,CtrName:String;var MidFont:TFont):Boolean;
var
    FontFile:TIniFile;
begin
  Result:=True;
  FontFile:=TIniFile.Create(FileName);
  MidFont.Name:=FontFile.ReadString(CtrName,'FontName','宋体');
  MidFont.Style:=GetFontStyle(FontFile.ReadString(CtrName,'FontStyle','[]'));
  MidFont.CharSet:=FontFile.ReadInteger(CtrName,'FontCharSet',134);
  MidFont.Color:=FontFile.ReadInteger(CtrName,'FontColor',-2147483640);
  MidFont.Size:=FontFile.ReadInteger(CtrName,'FontSize',9);
  MidFont.Height:=FontFile.ReadInteger(CtrName,'FontHeight',-12);
  FontFile.Free;
end;

function GetFontStyle(sStyle: string): TFontStyles;
//»ñµÃ×ÖÌåÑùʽ
//sStyle : ×ÖÌå×Ö·û´®ÐÎʽ
//·µ»Ø   : ×ÖÌå¸ñʽ

var
  MyFS              : TFontStyles;
begin
  MyFS := [];
  if pos('fsBold', sStyle) > 0 then MyFS := MyFS + [fsBold];
  if Pos('fsItalic', sStyle) > 0 then MyFS := MyFS + [fsItalic];
  if Pos('fsUnderline', sStyle) > 0 then
    MyFS := MyFS + [fsUnderline];
  if Pos('fsStrikeOut', sStyle) > 0 then
    MyFS := MyFS + [fsStrikeOut];
  Result := MyFS;
end;

function SetFontStyle(FS: TFontStyles): string;
//»ñµÃ×ÖÌåÑùʽµÄ×Ö·û´®ÐÎʽ
//FS   : ×ÖÌå¸ñʽ
//·µ»Ø : ×ÖÌå×Ö·û´®ÐÎʽ

var
  Mystyle  : string;
begin
  Mystyle := '[';
  if fsBold in FS then MyStyle := MyStyle + 'fsBold';
  if fsItalic in FS then
    if MyStyle = '[' then
      MyStyle := MyStyle + 'fsItalic'
    else
      MyStyle := MyStyle + ',fsItalic';
  if fsUnderline in FS then
    if MyStyle = '[' then
      MyStyle := MyStyle + 'fsUnderline'
    else
      MyStyle := MyStyle + ',fsUnderline';
  if fsStrikeOut in FS then
    if MyStyle = '[' then
      MyStyle := MyStyle + 'fsStrikeOut'
    else
      MyStyle := MyStyle + ',fsStrikeOut';
  MyStyle := MyStyle + ']';
  Result := MyStyle;
end;

 

 

 

const
   fontstylevalue: array [tfontstyle] of dword = ($0001, $0002, $0004, $0008);
function fontstyletodword(fontstyles: tfontstyles): dword;
var
  fontstyle: tfontstyle;
begin
  result := 0;
  for fontstyle := low(tfontstyle) to high(tfontstyle) do
  begin
    if fontstyle in fontstyles then
      inc(result, fontstylevalue[fontstyle]);
  end;
end;
function dwordtofontstyle(value: dword): tfontstyles;
var
  fontstyle: tfontstyle;
begin
  result := [];
  for fontstyle := low(tfontstyle) to high(tfontstyle) do
  begin
    if (fontstylevalue[fontstyle] and value) = fontstylevalue[fontstyle] then
      result := result + [fontstyle];
  end;
end;
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值