1、字体设置保存为String
Function TForm..FontToString(Font:TFont);
begin
With Fontdo
Result:= Format(‘%.8x%.8x%.4x%.4x%.1x%.2x%.1x%.4x%S’,[Color,Height,Size,PixelsPerInch,Byte(Pitch),Charset,Byte(Style),Length(Name),Name]);
end;
2.String转换成字体
Function TForm..StringToFont(Str:String;Font:TFont);
Var
Buff:String;
begin
If Length(Str) < 33 then
raise Exception.Create(‘Error Font Format String’);
Buff := Copy(Str,1,8);
Font..Color := StrToInt(‘$’+Buff);
Buff := Copy(Str,9,8);
Font..Height := StrToInt(‘$’+Buff);
Buff := Copy(Str,17,4);
Font..Size := StrToInt(‘$’+Buff);
Buff := Copy(Str,21,4);
Font..PixelsPerInch := StrToInt(‘$’+Buff);
Buff := Copy(Str,25,1);
Font..Picth := TfontPitch(StrToInt(‘$’+Buff));
Buff := Copy(Str,26,2);
Font..Charset := TfontCharset(StrToInt(‘$’+Buff));
Buff := Copy(Str,28,1);
Font..Style := TfontStyles(Byte(StrToInt(‘$’+Buff)));
Buff := Copy(Str,29,4);
Font..Name := Copy(Str,33,StrToInt(‘$’+Buff));
end;