1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109:
| Uses SysUtils
const csfsBold = '|Bold'; csfsItalic = '|Italic'; csfsUnderline = '|Underline'; csfsStrikeout = '|Strikeout';
function FontToString(Font : TFont) : string; var sStyle : string; begin with Font do begin sStyle := '';
if( fsBold in Style )then sStyle := sStyle + csfsBold;
if( fsItalic in Style )then sStyle := sStyle + csfsItalic;
if( fsUnderline in Style )then sStyle := sStyle + csfsUnderline;
if( fsStrikeout in Style )then sStyle := sStyle + csfsStrikeout;
if( ( Length( sStyle ) > 0 ) and ( '|' = sStyle[ 1 ] ) )then begin sStyle := Copy( sStyle, 2, Length( sStyle ) - 1 ); end;
Result := Format( '"%s", %d, [%s], [%s]', [ Name, Size, sStyle, ColorToString( Color ) ] ); end; end;
procedure StringToFont( sFont : string; var Font : TFont ); var p : integer; sStyle : string; begin if Length(sFont)=0 then begin sFont := '"Arial", 10, [], [clWindowText]'; end; with Font do begin p := Pos( ',', sFont ); if p>0 then begin Name := Copy( sFont, 2, p-3 ); Delete( sFont, 1, p ); end; p := Pos( ',', sFont ); if p>0 then begin Size := StrToInt( Copy( sFont, 2, p-2 ) ); Delete( sFont, 1, p ); end; p := Pos( ',', sFont ); if p>0 then begin sStyle := '|' + Copy( sFont, 3, p-4 ); Delete( sFont, 1, p ); end; try Color := StringToColor( Copy( sFont, 3, Length( sFont ) - 3 ) ); except; end; Style := []; if( Pos( csfsBold, sStyle ) > 0 )then Style := Style + [ fsBold ];
if( Pos( csfsItalic, sStyle ) > 0 )then Style := Style + [ fsItalic ];
if( Pos( csfsUnderline, sStyle ) > 0 )then Style := Style + [ fsUnderline ];
if( Pos( csfsStrikeout, sStyle ) > 0 )then Style := Style + [ fsStrikeout ]; end; end; |