| [15] | 1 | Unit RichTextStyleUnit;
|
|---|
| 2 |
|
|---|
| 3 | Interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| [214] | 6 | Forms,
|
|---|
| 7 | Classes,
|
|---|
| 8 | Graphics,
|
|---|
| 9 | CanvasFontManager,
|
|---|
| 10 | RichTextDocumentUnit;
|
|---|
| [15] | 11 |
|
|---|
| 12 | type
|
|---|
| 13 | TTextDrawStyle = record
|
|---|
| 14 | Font: TFontSpec;
|
|---|
| 15 | Color: TColor;
|
|---|
| 16 | BackgroundColor: TColor;
|
|---|
| 17 | Alignment: TTextAlignment;
|
|---|
| 18 | Wrap: boolean;
|
|---|
| 19 | LeftMargin: longint;
|
|---|
| 20 | RightMargin: longint;
|
|---|
| 21 | end;
|
|---|
| 22 |
|
|---|
| 23 | TMarginSizeStyle = ( msAverageCharWidth, msMaximumCharWidth, msSpecifiedChar );
|
|---|
| 24 |
|
|---|
| 25 | TRichTextSettings = class( TComponent )
|
|---|
| 26 | protected
|
|---|
| 27 | FHeading1Font: TFont;
|
|---|
| 28 | FHeading2Font: TFont;
|
|---|
| 29 | FHeading3Font: TFont;
|
|---|
| 30 |
|
|---|
| 31 | FFixedFont: TFont;
|
|---|
| 32 | FNormalFont: TFont;
|
|---|
| 33 |
|
|---|
| 34 | FDefaultBackgroundColor: TColor;
|
|---|
| 35 | FDefaultColor: TColor;
|
|---|
| 36 |
|
|---|
| 37 | FDefaultAlignment: TTextAlignment;
|
|---|
| 38 | FDefaultWrap: boolean;
|
|---|
| 39 |
|
|---|
| 40 | FAtLeastOneWordBeforeWrap: boolean;
|
|---|
| 41 |
|
|---|
| 42 | FMarginSizeStyle: TMarginSizeStyle;
|
|---|
| 43 | FMarginChar: longint;
|
|---|
| 44 |
|
|---|
| 45 | FOnChange: TNotifyEvent;
|
|---|
| 46 |
|
|---|
| 47 | FMargins: TRect;
|
|---|
| 48 |
|
|---|
| 49 | FUpdateCount: longint;
|
|---|
| 50 | FChangesPending: boolean;
|
|---|
| 51 |
|
|---|
| 52 | Procedure Change;
|
|---|
| 53 |
|
|---|
| 54 | Procedure SetNormalFont( NewFont: TFont );
|
|---|
| 55 | Procedure SetFixedFont( NewFont: TFont );
|
|---|
| 56 | Procedure SetHeading1Font( NewFont: TFont );
|
|---|
| 57 | Procedure SetHeading2Font( NewFont: TFont );
|
|---|
| 58 | Procedure SetHeading3Font( NewFont: TFont );
|
|---|
| 59 |
|
|---|
| 60 | Procedure SetDefaultColor( NewColor: TColor );
|
|---|
| 61 | Procedure SetDefaultBackgroundColor( NewColor: TColor );
|
|---|
| 62 |
|
|---|
| 63 | Procedure SetDefaultAlignment( Alignment: TTextAlignment );
|
|---|
| 64 | Procedure SetDefaultWrap( Wrap: boolean );
|
|---|
| 65 | Procedure SetAtLeastOneWordBeforeWrap( NewValue: boolean );
|
|---|
| 66 |
|
|---|
| 67 | Procedure SetMarginSizeStyle( NewValue: TMarginSizeStyle );
|
|---|
| 68 | Procedure SetMarginChar( NewValue: longint );
|
|---|
| 69 |
|
|---|
| 70 | Procedure SetMargins( const NewMargins: TRect );
|
|---|
| 71 |
|
|---|
| 72 | function GetMargin_Left: longint;
|
|---|
| 73 | Procedure SetMargin_Left( NewValue: longint );
|
|---|
| 74 | function GetMargin_Bottom: longint;
|
|---|
| 75 | Procedure SetMargin_Bottom( NewValue: longint );
|
|---|
| 76 | function GetMargin_Right: longint;
|
|---|
| 77 | Procedure SetMargin_Right( NewValue: longint );
|
|---|
| 78 | function GetMargin_Top: longint;
|
|---|
| 79 | Procedure SetMargin_Top( NewValue: longint );
|
|---|
| 80 |
|
|---|
| 81 | Procedure SetupComponent; override;
|
|---|
| 82 | destructor Destroy; override;
|
|---|
| 83 |
|
|---|
| 84 | Procedure AssignFont( Var Font: TFont;
|
|---|
| 85 | NewFont: TFont );
|
|---|
| 86 |
|
|---|
| 87 | // Hide properties...
|
|---|
| 88 | property Name;
|
|---|
| 89 |
|
|---|
| 90 | public
|
|---|
| 91 | property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
|---|
| 92 |
|
|---|
| 93 | procedure BeginUpdate;
|
|---|
| 94 | procedure EndUpdate;
|
|---|
| 95 |
|
|---|
| 96 | // Stream in/out
|
|---|
| 97 | Procedure ReadSCUResource( Const ResName: TResourceName;
|
|---|
| 98 | Var Data;
|
|---|
| 99 | DataLen: LongInt ); override;
|
|---|
| 100 | Function WriteSCUResource( Stream: TResourceStream ): boolean; override;
|
|---|
| 101 |
|
|---|
| 102 | property Margins: TRect read FMargins write SetMargins;
|
|---|
| 103 |
|
|---|
| 104 | property Heading1Font: TFont read FHeading1Font write SetHeading1Font;
|
|---|
| 105 | property Heading2Font: TFont read FHeading2Font write SetHeading2Font;
|
|---|
| 106 | property Heading3Font: TFont read FHeading3Font write SetHeading3Font;
|
|---|
| 107 | property FixedFont: TFont read FFixedFont write SetFixedFont;
|
|---|
| 108 | property NormalFont: TFont read FNormalFont write SetNormalFont;
|
|---|
| 109 |
|
|---|
| 110 | published
|
|---|
| 111 |
|
|---|
| 112 | property DefaultBackgroundColor: TColor read FDefaultBackgroundColor write SetDefaultBackgroundColor;
|
|---|
| 113 | property DefaultColor: TColor read FDefaultColor write SetDefaultColor;
|
|---|
| 114 |
|
|---|
| 115 | property DefaultAlignment: TTextAlignment read FDefaultAlignment write SetDefaultAlignment;
|
|---|
| 116 | property DefaultWrap: boolean read FDefaultWrap write SetDefaultWrap;
|
|---|
| 117 | property AtLeastOneWordBeforeWrap: boolean read FAtLeastOneWordBeforeWrap write SetAtLeastOneWordBeforeWrap;
|
|---|
| 118 |
|
|---|
| 119 | property MarginSizeStyle: TMarginSizeStyle read FMarginSizeStyle write SeTMarginSizeStyle;
|
|---|
| 120 | property MarginChar: longint read FMarginChar write SetMarginChar;
|
|---|
| 121 |
|
|---|
| 122 | // margins are exposed as individual properties here
|
|---|
| 123 | // since the Sibyl IDE cannot cope with editing a record property
|
|---|
| 124 | // within a class property (as in RichTextView)
|
|---|
| 125 | property Margin_Left: longint read GetMargin_Left write SetMargin_Left;
|
|---|
| 126 | property Margin_Bottom: longint read GetMargin_Bottom write SetMargin_Bottom;
|
|---|
| 127 | property Margin_Right: longint read GetMargin_Right write SetMargin_Right;
|
|---|
| 128 | property Margin_Top: longint read GetMargin_Top write SetMargin_Top;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | // pRichTextSettings = ^TRichTextSettings;
|
|---|
| 132 | Procedure ApplyStyle( const Style: TTextDrawStyle;
|
|---|
| 133 | FontManager: TCanvasFontManager );
|
|---|
| 134 |
|
|---|
| 135 | Procedure ApplyStyleTag( const Tag: TTag;
|
|---|
| 136 | Var Style: TTextDrawStyle;
|
|---|
| 137 | FontManager: TCanvasFontManager;
|
|---|
| 138 | const Settings: TRichTextSettings;
|
|---|
| 139 | const X: longint );
|
|---|
| 140 |
|
|---|
| 141 | function GetDefaultStyle( const Settings: TRichTextSettings ): TTextDrawStyle;
|
|---|
| 142 |
|
|---|
| 143 | Exports
|
|---|
| 144 | TRichTextSettings,'User','';
|
|---|
| 145 |
|
|---|
| 146 | Implementation
|
|---|
| 147 |
|
|---|
| 148 | uses
|
|---|
| 149 | SysUtils,
|
|---|
| [214] | 150 | StringUtilsUnit;
|
|---|
| [15] | 151 |
|
|---|
| 152 | Procedure ApplyStyle( const Style: TTextDrawStyle;
|
|---|
| 153 | FontManager: TCanvasFontManager );
|
|---|
| 154 | begin
|
|---|
| 155 | FontManager.SetFont( Style.Font );
|
|---|
| 156 | FontManager.Canvas.Pen.Color := Style.Color;
|
|---|
| 157 | end;
|
|---|
| 158 |
|
|---|
| 159 | Procedure ApplyStyleTag( Const Tag: TTag;
|
|---|
| 160 | Var Style: TTextDrawStyle;
|
|---|
| 161 | FontManager: TCanvasFontManager;
|
|---|
| 162 | const Settings: TRichTextSettings;
|
|---|
| 163 | const X: longint );
|
|---|
| 164 | var
|
|---|
| 165 | MarginParam1: string;
|
|---|
| 166 | MarginParam2: string;
|
|---|
| 167 | NewMargin: longint;
|
|---|
| 168 | FontFaceName: string;
|
|---|
| 169 | FontSizeString: string;
|
|---|
| 170 | NewStyle: TTextDrawStyle;
|
|---|
| 171 | ParseIndex: longint;
|
|---|
| 172 | XSizeStr: string;
|
|---|
| 173 | YSizeStr: string;
|
|---|
| [214] | 174 | tmpFontParts : TStringList;
|
|---|
| [15] | 175 |
|
|---|
| 176 | MarginSize: longint;
|
|---|
| 177 | ParsePoint: longint;
|
|---|
| 178 | begin
|
|---|
| 179 | case Tag.TagType of
|
|---|
| 180 | ttBold:
|
|---|
| 181 | Include( Style.Font.Attributes, faBold );
|
|---|
| 182 | ttBoldOff:
|
|---|
| 183 | Exclude( Style.Font.Attributes, faBold );
|
|---|
| 184 | ttItalic:
|
|---|
| 185 | Include( Style.Font.Attributes, faItalic );
|
|---|
| 186 | ttItalicOff:
|
|---|
| 187 | Exclude( Style.Font.Attributes, faItalic );
|
|---|
| 188 | ttUnderline:
|
|---|
| 189 | Include( Style.Font.Attributes, faUnderscore );
|
|---|
| 190 | ttUnderlineOff:
|
|---|
| 191 | Exclude( Style.Font.Attributes, faUnderscore );
|
|---|
| 192 |
|
|---|
| 193 | ttFixedWidthOn:
|
|---|
| 194 | SibylFontToFontSpec( Settings.FFixedFont, Style.Font );
|
|---|
| 195 | ttFixedWidthOff:
|
|---|
| 196 | SibylFontToFontSpec( Settings.FNormalFont, Style.Font );
|
|---|
| 197 |
|
|---|
| 198 | ttHeading1:
|
|---|
| 199 | SibylFontToFontSpec( Settings.FHeading1Font, Style.Font );
|
|---|
| 200 | ttHeading2:
|
|---|
| 201 | SibylFontToFontSpec( Settings.FHeading2Font, Style.Font );
|
|---|
| 202 | ttHeading3:
|
|---|
| 203 | SibylFontToFontSpec( Settings.FHeading3Font, Style.Font );
|
|---|
| 204 | ttHeadingOff:
|
|---|
| 205 | SibylFontToFontSpec( Settings.FNormalFont, Style.Font );
|
|---|
| 206 |
|
|---|
| 207 | ttFont:
|
|---|
| 208 | begin
|
|---|
| [214] | 209 | tmpFontParts := TStringList.Create;
|
|---|
| 210 | StrExtractStringsQuoted(tmpFontParts, Tag.Arguments);
|
|---|
| 211 | FontFaceName := tmpFontParts[0];
|
|---|
| 212 | FontSizeString := tmpFontParts[1];
|
|---|
| 213 | tmpFontParts.Destroy;
|
|---|
| 214 |
|
|---|
| [15] | 215 | NewStyle := Style;
|
|---|
| 216 | try
|
|---|
| 217 | NewStyle.Font.FaceName := FontFaceName;
|
|---|
| 218 |
|
|---|
| 219 | if Pos( 'x', FontSizeString ) > 0 then
|
|---|
| 220 | begin
|
|---|
| [214] | 221 | tmpFontParts := TStringList.Create;
|
|---|
| 222 | StrExtractStrings(tmpFontParts, FontSizeString, ['x'], #0);
|
|---|
| 223 | XSizeStr := tmpFontParts[0];
|
|---|
| 224 | YSizeStr := tmpFontParts[1];
|
|---|
| 225 | tmpFontParts.Destroy;
|
|---|
| 226 |
|
|---|
| [15] | 227 | NewStyle.Font.XSize := StrToInt( XSizeStr );
|
|---|
| 228 | NewStyle.Font.YSize := StrToInt( YSizeStr );
|
|---|
| 229 | NewStyle.Font.PointSize := 0;
|
|---|
| 230 | end
|
|---|
| 231 | else
|
|---|
| 232 | begin
|
|---|
| 233 | NewStyle.Font.PointSize := StrToInt( FontSizeString );
|
|---|
| 234 | end;
|
|---|
| 235 |
|
|---|
| 236 | if ( NewStyle.Font.FaceName <> '' )
|
|---|
| 237 | and ( NewStyle.Font.PointSize >= 1 ) then
|
|---|
| 238 | begin
|
|---|
| 239 | Style := NewStyle;
|
|---|
| 240 | end;
|
|---|
| 241 |
|
|---|
| 242 | except
|
|---|
| 243 | end;
|
|---|
| 244 | end;
|
|---|
| 245 |
|
|---|
| 246 | ttFontOff:
|
|---|
| 247 | // restore default
|
|---|
| 248 | SibylFontToFontSpec( Settings.FNormalFont, Style.Font );
|
|---|
| 249 |
|
|---|
| 250 | ttColor:
|
|---|
| 251 | GetTagColor( Tag.Arguments, Style.Color );
|
|---|
| 252 | ttColorOff:
|
|---|
| 253 | Style.Color := Settings.FDefaultColor;
|
|---|
| 254 | ttBackgroundColor:
|
|---|
| 255 | GetTagColor( Tag.Arguments, Style.BackgroundColor );
|
|---|
| 256 | ttBackgroundColorOff:
|
|---|
| 257 | Style.BackgroundColor := Settings.FDefaultBackgroundColor;
|
|---|
| 258 |
|
|---|
| 259 | ttRed:
|
|---|
| 260 | Style.Color := clRed;
|
|---|
| 261 | ttBlue:
|
|---|
| 262 | Style.Color := clBlue;
|
|---|
| 263 | ttGreen:
|
|---|
| 264 | Style.Color := clGreen;
|
|---|
| 265 | ttBlack:
|
|---|
| 266 | Style.Color := clBlack;
|
|---|
| 267 |
|
|---|
| 268 | ttAlign:
|
|---|
| 269 | Style.Alignment := GetTagTextAlignment( Tag.Arguments,
|
|---|
| 270 | Settings.FDefaultAlignment );
|
|---|
| 271 |
|
|---|
| 272 | ttWrap:
|
|---|
| 273 | Style.Wrap := GetTagTextWrap( Tag.Arguments );
|
|---|
| 274 |
|
|---|
| 275 | ttSetLeftMargin,
|
|---|
| 276 | ttSetRightMargin:
|
|---|
| 277 | begin
|
|---|
| [214] | 278 | tmpFontParts := TStringList.Create;
|
|---|
| 279 | StrExtractStrings(tmpFontParts, Tag.Arguments, [' '], #0);
|
|---|
| 280 | MarginParam1 := tmpFontParts[0];
|
|---|
| 281 | tmpFontParts.Destroy;
|
|---|
| 282 |
|
|---|
| [15] | 283 | ParsePoint := 1;
|
|---|
| 284 | if ( Tag.TagType = ttSetLeftMargin )
|
|---|
| 285 | and ( MarginParam1 = 'here' ) then
|
|---|
| 286 | begin
|
|---|
| 287 | Style.LeftMargin := X div FontWidthPrecisionFactor;
|
|---|
| 288 | end
|
|---|
| 289 | else
|
|---|
| 290 | begin
|
|---|
| 291 | try
|
|---|
| 292 | MarginSize := StrToInt( MarginParam1 );
|
|---|
| [214] | 293 | MarginParam2 := tmpFontParts[1];
|
|---|
| [15] | 294 | if MarginParam2 = 'pixels' then
|
|---|
| 295 | NewMargin := MarginSize
|
|---|
| 296 |
|
|---|
| 297 | else if MarginParam2 = 'deffont' then
|
|---|
| 298 | NewMargin := MarginSize
|
|---|
| 299 | * Settings.NormalFont.Width
|
|---|
| 300 |
|
|---|
| 301 | else
|
|---|
| 302 | begin
|
|---|
| 303 | case Settings.MarginSizeStyle of
|
|---|
| 304 | msAverageCharWidth:
|
|---|
| 305 | NewMargin := MarginSize * FontManager.AverageCharWidth;
|
|---|
| 306 | msMaximumCharWidth:
|
|---|
| 307 | NewMargin := MarginSize * FontManager.MaximumCharWidth;
|
|---|
| 308 | msSpecifiedChar:
|
|---|
| 309 | NewMargin := MarginSize
|
|---|
| 310 | * FontManager.CharWidth( Chr( Settings.MarginChar ) )
|
|---|
| 311 | div FontWidthPrecisionFactor;
|
|---|
| 312 | end;
|
|---|
| 313 | end;
|
|---|
| 314 | except
|
|---|
| 315 | NewMargin := 0;
|
|---|
| 316 | end;
|
|---|
| 317 |
|
|---|
| 318 | if Tag.TagType = ttSetLeftMargin then
|
|---|
| 319 | Style.LeftMargin := Settings.Margins.Left
|
|---|
| 320 | + NewMargin
|
|---|
| 321 | else
|
|---|
| 322 | Style.RightMargin := Settings.Margins.Right
|
|---|
| 323 | + NewMargin;
|
|---|
| 324 | end;
|
|---|
| 325 | end;
|
|---|
| 326 |
|
|---|
| 327 | end;
|
|---|
| 328 |
|
|---|
| 329 | ApplyStyle( Style, FontManager );
|
|---|
| 330 |
|
|---|
| 331 | end;
|
|---|
| 332 |
|
|---|
| 333 | function GetDefaultStyle( const Settings: TRichTextSettings ): TTextDrawStyle;
|
|---|
| 334 | begin
|
|---|
| 335 | SibylFontToFontSpec( Settings.FNormalFont, Result.Font );
|
|---|
| 336 | Result.Alignment := Settings.FDefaultAlignment;
|
|---|
| 337 | Result.Wrap := Settings.FDefaultWrap;
|
|---|
| 338 | Result.Color := Settings.FDefaultColor;
|
|---|
| 339 | Result.BackgroundColor := Settings.FDefaultBackgroundColor;
|
|---|
| 340 | Result.LeftMargin := Settings.Margins.Left;
|
|---|
| 341 | Result.RightMargin := Settings.Margins.Right;
|
|---|
| 342 | end;
|
|---|
| 343 |
|
|---|
| 344 | Procedure GetStartupFont( Var Font: TFont;
|
|---|
| 345 | Const Face: string;
|
|---|
| 346 | Const Size: longint );
|
|---|
| 347 | begin
|
|---|
| 348 | Font := Screen.CreateCompatibleFont( Screen.GetFontFromPointSize( Face, Size ) );
|
|---|
| 349 | ReferenceFont( Font );
|
|---|
| 350 | Font.AutoDestroy := true;
|
|---|
| 351 | end;
|
|---|
| 352 |
|
|---|
| 353 | Procedure TRichTextSettings.SetupComponent;
|
|---|
| 354 | begin
|
|---|
| 355 | inherited SetupComponent;
|
|---|
| 356 |
|
|---|
| 357 | Name := 'RichTextSettings';
|
|---|
| 358 |
|
|---|
| 359 | GetStartupFont( FNormalFont, 'Helv', 8 );
|
|---|
| 360 | GetStartupFont( FFixedFont, 'Courier', 8 );
|
|---|
| 361 | GetStartupFont( FHeading1Font, 'Helv', 18 );
|
|---|
| 362 | GetStartupFont( FHeading2Font, 'Helv', 12 );
|
|---|
| 363 | GetStartupFont( FHeading3Font, 'Helv', 8 );
|
|---|
| 364 | FHeading3Font.Attributes := [ faBold ];
|
|---|
| 365 |
|
|---|
| 366 | FDefaultColor := clBlack;
|
|---|
| 367 | FDefaultBackgroundColor := clWhite;
|
|---|
| 368 |
|
|---|
| 369 | FDefaultAlignment := taLeft;
|
|---|
| 370 | FDefaultWrap := true;
|
|---|
| 371 | FAtLeastOneWordBeforeWrap := false;
|
|---|
| 372 |
|
|---|
| 373 | FMarginSizeStyle := msMaximumCharWidth;
|
|---|
| 374 | FMarginChar := Ord( ' ' );
|
|---|
| 375 |
|
|---|
| 376 | FMargins.Left := 0;
|
|---|
| 377 | FMargins.Right := 0;
|
|---|
| 378 | FMargins.Top := 0;
|
|---|
| 379 | FMargins.Bottom := 0;
|
|---|
| 380 |
|
|---|
| 381 | FUpdateCount := 0;
|
|---|
| 382 | FChangesPending := false;
|
|---|
| 383 | end;
|
|---|
| 384 |
|
|---|
| 385 | destructor TRichTextSettings.Destroy;
|
|---|
| 386 | begin
|
|---|
| 387 | DereferenceFont( FNormalFont );
|
|---|
| 388 | DereferenceFont( FFixedFont );
|
|---|
| 389 | DereferenceFont( FHeading1Font );
|
|---|
| 390 | DereferenceFont( FHeading2Font );
|
|---|
| 391 | DereferenceFont( FHeading3Font );
|
|---|
| 392 |
|
|---|
| 393 | Inherited Destroy;
|
|---|
| 394 | end;
|
|---|
| 395 |
|
|---|
| 396 | // Font read/write from SCU. I have NO IDEA why I have to do this manually. But
|
|---|
| 397 | // this way works and everything else I tried doesn't
|
|---|
| 398 | Procedure TRichTextSettings.ReadSCUResource( Const ResName: TResourceName;
|
|---|
| 399 | Var Data;
|
|---|
| 400 | DataLen: LongInt );
|
|---|
| 401 | Begin
|
|---|
| 402 | If ResName = 'Heading1Font' Then
|
|---|
| 403 | Begin
|
|---|
| 404 | If DataLen <> 0 Then
|
|---|
| 405 | FHeading1Font := ReadSCUFont( Data, DataLen );
|
|---|
| 406 | End
|
|---|
| 407 | Else If ResName = 'Heading2Font' Then
|
|---|
| 408 | Begin
|
|---|
| 409 | If DataLen <> 0 Then
|
|---|
| 410 | FHeading2Font := ReadSCUFont( Data, DataLen );
|
|---|
| 411 | End
|
|---|
| 412 | Else If ResName = 'Heading3Font' Then
|
|---|
| 413 | Begin
|
|---|
| 414 | If DataLen <> 0 Then
|
|---|
| 415 | FHeading3Font := ReadSCUFont( Data, DataLen );
|
|---|
| 416 | End
|
|---|
| 417 | Else If ResName = 'FixedFont' Then
|
|---|
| 418 | Begin
|
|---|
| 419 | If DataLen <> 0 Then
|
|---|
| 420 | FFixedFont := ReadSCUFont( Data, DataLen );
|
|---|
| 421 | End
|
|---|
| 422 | Else if ResName = 'NormalFont' then
|
|---|
| 423 | Begin
|
|---|
| 424 | If DataLen <> 0 Then
|
|---|
| 425 | FNormalFont := ReadSCUFont( Data, DataLen );
|
|---|
| 426 | End
|
|---|
| 427 | Else
|
|---|
| 428 | Inherited ReadSCUResource( ResName, Data, DataLen );
|
|---|
| 429 | End;
|
|---|
| 430 |
|
|---|
| 431 | Function TRichTextSettings.WriteSCUResource( Stream: TResourceStream ): boolean;
|
|---|
| 432 | begin
|
|---|
| 433 | Result := Inherited WriteSCUResource( Stream );
|
|---|
| 434 | If Not Result Then
|
|---|
| 435 | Exit;
|
|---|
| 436 |
|
|---|
| 437 | If FHeading1Font <> Nil then
|
|---|
| 438 | Result := FHeading1Font.WriteSCUResourceName( Stream, 'Heading1Font' );
|
|---|
| 439 | If FHeading2Font <> Nil then
|
|---|
| 440 | Result := FHeading2Font.WriteSCUResourceName( Stream, 'Heading2Font' );
|
|---|
| 441 | If FHeading3Font <> Nil then
|
|---|
| 442 | Result := FHeading3Font.WriteSCUResourceName( Stream, 'Heading3Font' );
|
|---|
| 443 | If FFixedFont <> Nil then
|
|---|
| 444 | Result := FFixedFont.WriteSCUResourceName( Stream, 'FixedFont' );
|
|---|
| 445 | If FNormalFont <> Nil then
|
|---|
| 446 | Result := FNormalFont.WriteSCUResourceName( Stream, 'NormalFont' );
|
|---|
| 447 |
|
|---|
| 448 | end;
|
|---|
| 449 |
|
|---|
| 450 | Procedure TRichTextSettings.Change;
|
|---|
| 451 | begin
|
|---|
| 452 | if FUpdateCount > 0 then
|
|---|
| 453 | begin
|
|---|
| 454 | FChangesPending := true;
|
|---|
| 455 | exit;
|
|---|
| 456 | end;
|
|---|
| 457 |
|
|---|
| 458 | if FOnChange <> nil then
|
|---|
| 459 | FOnChange( self );
|
|---|
| 460 | end;
|
|---|
| 461 |
|
|---|
| 462 | Procedure TRichTextSettings.SetDefaultAlignment( Alignment: TTextAlignment );
|
|---|
| 463 | begin
|
|---|
| 464 | if Alignment = FDefaultAlignment then
|
|---|
| 465 | exit; // no change
|
|---|
| 466 |
|
|---|
| 467 | FDefaultAlignment := Alignment;
|
|---|
| 468 | Change;
|
|---|
| 469 | end;
|
|---|
| 470 |
|
|---|
| 471 | Procedure TRichTextSettings.SetDefaultWrap( Wrap: boolean );
|
|---|
| 472 | begin
|
|---|
| 473 | if Wrap = FDefaultWrap then
|
|---|
| 474 | exit; // no change
|
|---|
| 475 |
|
|---|
| 476 | FDefaultWrap := Wrap;
|
|---|
| 477 | Change;
|
|---|
| 478 | end;
|
|---|
| 479 |
|
|---|
| 480 | Procedure TRichTextSettings.SetAtLeastOneWordBeforeWrap( NewValue: boolean );
|
|---|
| 481 | begin
|
|---|
| 482 | if NewValue = FAtLeastOneWordBeforeWrap then
|
|---|
| 483 | exit; // no change
|
|---|
| 484 |
|
|---|
| 485 | FAtLeastOneWordBeforeWrap := NewValue;
|
|---|
| 486 | Change;
|
|---|
| 487 | end;
|
|---|
| 488 |
|
|---|
| 489 | Procedure TRichTextSettings.SetMarginChar( NewValue: longint );
|
|---|
| 490 | begin
|
|---|
| 491 | if NewValue = FMarginChar then
|
|---|
| 492 | exit; // no change
|
|---|
| 493 |
|
|---|
| 494 | FMarginChar := NewValue;
|
|---|
| 495 |
|
|---|
| 496 | if FMarginSizeStyle <> msSpecifiedChar then
|
|---|
| 497 | // doesn't matter, will be ignored
|
|---|
| 498 | exit;
|
|---|
| 499 | Change;
|
|---|
| 500 | end;
|
|---|
| 501 |
|
|---|
| 502 | Procedure TRichTextSettings.SetMarginSizeStyle( NewValue: TMarginSizeStyle );
|
|---|
| 503 | begin
|
|---|
| 504 | if NewValue = FMarginSizeStyle then
|
|---|
| 505 | exit; // no change
|
|---|
| 506 |
|
|---|
| 507 | FMarginSizeStyle := NewValue;
|
|---|
| 508 | Change;
|
|---|
| 509 | end;
|
|---|
| 510 |
|
|---|
| 511 | Function FontSame( FontA: TFont; FontB: TFont ): boolean;
|
|---|
| 512 | begin
|
|---|
| 513 | if ( FontA = nil )
|
|---|
| 514 | or ( FontB = nil ) then
|
|---|
| 515 | begin
|
|---|
| 516 | Result := FontA = FontB;
|
|---|
| 517 | exit;
|
|---|
| 518 | end;
|
|---|
| 519 |
|
|---|
| 520 | Result := ( FontA.FaceName = FontB.FaceName )
|
|---|
| 521 | and ( FontA.PointSize = FontB.PointSize )
|
|---|
| 522 | and ( FontA.Attributes = FontB.Attributes );
|
|---|
| 523 | end;
|
|---|
| 524 |
|
|---|
| 525 | Procedure TRichTextSettings.AssignFont( Var Font: TFont;
|
|---|
| 526 | NewFont: TFont );
|
|---|
| 527 | begin
|
|---|
| 528 | If NewFont = Nil Then
|
|---|
| 529 | NewFont := Screen.DefaultFont;
|
|---|
| 530 |
|
|---|
| 531 | if FontSame( NewFont, Font ) then
|
|---|
| 532 | exit; // no change
|
|---|
| 533 |
|
|---|
| 534 | DereferenceFont( Font );
|
|---|
| 535 | Font := NewFont;
|
|---|
| 536 | ReferenceFont( Font );
|
|---|
| 537 |
|
|---|
| 538 | Change;
|
|---|
| 539 | End;
|
|---|
| 540 |
|
|---|
| 541 | Procedure TRichTextSettings.SetHeading1Font( NewFont: TFont );
|
|---|
| 542 | begin
|
|---|
| [39] | 543 | // ProfileEvent( 'TRichTextSettings.SetHeading1Font' );
|
|---|
| [15] | 544 | AssignFont( FHeading1Font, NewFont );
|
|---|
| 545 |
|
|---|
| [39] | 546 | // if FHeading1FOnt = nil then
|
|---|
| 547 | // ProfileEvent( ' Set to nil' );
|
|---|
| [15] | 548 |
|
|---|
| 549 | end;
|
|---|
| 550 |
|
|---|
| 551 | Procedure TRichTextSettings.SetHeading2Font( NewFont: TFont );
|
|---|
| 552 | begin
|
|---|
| 553 | AssignFont( FHeading2Font, NewFont );
|
|---|
| 554 | End;
|
|---|
| 555 |
|
|---|
| 556 | Procedure TRichTextSettings.SetHeading3Font( NewFont: TFont );
|
|---|
| 557 | begin
|
|---|
| 558 | AssignFont( FHeading3Font, NewFont );
|
|---|
| 559 | End;
|
|---|
| 560 |
|
|---|
| 561 | Procedure TRichTextSettings.SetFixedFont( NewFont: TFont );
|
|---|
| 562 | begin
|
|---|
| 563 | AssignFont( FFixedFont, NewFont );
|
|---|
| 564 | end;
|
|---|
| 565 |
|
|---|
| 566 | Procedure TRichTextSettings.SetNormalFont( NewFont: TFont );
|
|---|
| 567 | begin
|
|---|
| 568 | AssignFont( FNormalFont, NewFont );
|
|---|
| 569 | end;
|
|---|
| 570 |
|
|---|
| 571 | Procedure TRichTextSettings.SetMargins( const NewMargins: TRect );
|
|---|
| 572 | begin
|
|---|
| 573 | if NewMargins = FMargins then
|
|---|
| 574 | exit; // no change
|
|---|
| 575 | FMargins := NewMargins;
|
|---|
| 576 | Change;
|
|---|
| 577 | end;
|
|---|
| 578 |
|
|---|
| 579 | function TRichTextSettings.GetMargin_Left: longint;
|
|---|
| 580 | begin
|
|---|
| 581 | Result := FMargins.Left;
|
|---|
| 582 | end;
|
|---|
| 583 |
|
|---|
| 584 | Procedure TRichTextSettings.SetMargin_Left( NewValue: longint );
|
|---|
| 585 | begin
|
|---|
| 586 | Margins.Left := NewValue;
|
|---|
| 587 | end;
|
|---|
| 588 |
|
|---|
| 589 | function TRichTextSettings.GetMargin_Bottom: longint;
|
|---|
| 590 | begin
|
|---|
| 591 | Result := FMargins.Bottom;
|
|---|
| 592 | end;
|
|---|
| 593 |
|
|---|
| 594 | Procedure TRichTextSettings.SetMargin_Bottom( NewValue: longint );
|
|---|
| 595 | begin
|
|---|
| 596 | Margins.Bottom := NewValue;
|
|---|
| 597 | end;
|
|---|
| 598 |
|
|---|
| 599 | function TRichTextSettings.GetMargin_Right: longint;
|
|---|
| 600 | begin
|
|---|
| 601 | Result := FMargins.Right;
|
|---|
| 602 | end;
|
|---|
| 603 |
|
|---|
| 604 | Procedure TRichTextSettings.SetMargin_Right( NewValue: longint );
|
|---|
| 605 | begin
|
|---|
| 606 | Margins.Right := NewValue;
|
|---|
| 607 | end;
|
|---|
| 608 |
|
|---|
| 609 | function TRichTextSettings.GetMargin_Top: longint;
|
|---|
| 610 | begin
|
|---|
| 611 | Result := FMargins.Top;
|
|---|
| 612 | end;
|
|---|
| 613 |
|
|---|
| 614 | Procedure TRichTextSettings.SetMargin_Top( NewValue: longint );
|
|---|
| 615 | begin
|
|---|
| 616 | Margins.Top := NewValue;
|
|---|
| 617 | end;
|
|---|
| 618 |
|
|---|
| 619 | Procedure TRichTextSettings.SetDefaultColor( NewColor: TColor );
|
|---|
| 620 | begin
|
|---|
| 621 | if NewColor = FDefaultColor then
|
|---|
| 622 | exit;
|
|---|
| 623 | FDefaultColor := NewColor;
|
|---|
| 624 | Change;
|
|---|
| 625 | end;
|
|---|
| 626 |
|
|---|
| 627 | Procedure TRichTextSettings.SetDefaultBackgroundColor( NewColor: TColor );
|
|---|
| 628 | begin
|
|---|
| 629 | if NewColor = FDefaultBackgroundColor then
|
|---|
| 630 | exit;
|
|---|
| 631 | FDefaultBackgroundColor := NewColor;
|
|---|
| 632 | Change;
|
|---|
| 633 | end;
|
|---|
| 634 |
|
|---|
| 635 | procedure TRichTextSettings.BeginUpdate;
|
|---|
| 636 | begin
|
|---|
| 637 | inc( FUpdateCount );
|
|---|
| 638 | end;
|
|---|
| 639 |
|
|---|
| 640 | procedure TRichTextSettings.EndUpdate;
|
|---|
| 641 | begin
|
|---|
| 642 | if FUpdateCount = 0 then
|
|---|
| 643 | exit;
|
|---|
| 644 |
|
|---|
| 645 | dec( FUpdateCount );
|
|---|
| 646 | if FUpdateCount = 0 then
|
|---|
| 647 | begin
|
|---|
| 648 | if FChangesPending then
|
|---|
| 649 | begin
|
|---|
| 650 | Change;
|
|---|
| 651 | FChangesPending := false;
|
|---|
| 652 | end;
|
|---|
| 653 | end;
|
|---|
| 654 | end;
|
|---|
| 655 |
|
|---|
| 656 | Initialization
|
|---|
| 657 | RegisterClasses( [ TRichTextSettings ] );
|
|---|
| 658 | End.
|
|---|