Changeset 418 for trunk/Components/RichTextLayoutUnit.pas
- Timestamp:
- Feb 25, 2019, 8:34:42 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/RichTextLayoutUnit.pas
r395 r418 73 73 74 74 FRichTextSettings: TRichTextSettings; 75 76 Codepage: ULong; // ALT 75 77 76 78 // Drawing functions … … 169 171 var 170 172 DefaultFontSpec: TFontSpec; 173 CpSize: ULong; // ALT 171 174 Begin 172 175 Inherited Create; … … 199 202 DefaultFontSpec ); 200 203 FFontManager.DefaultFontSpec := DefaultFontSpec; 204 205 DosQueryCp( sizeof( Codepage ), Codepage, CpSize ); // ALT 201 206 202 207 Layout; … … 284 289 NextP: PChar; 285 290 NextP2: PChar; 291 NextP3: PChar; 286 292 287 293 WordStart: PChar; … … 307 313 308 314 DoWrap: boolean; 315 316 InsideDBC: Boolean; // ALT 309 317 310 318 // Nested procedure … … 383 391 WordStarted := false; 384 392 DisplayedCharsSinceFontChange := false; 393 InsideDBC := false; 385 394 386 395 repeat 387 396 CurrentElement := ExtractNextTextElement( P, NextP ); 388 397 assert( NextP > P ); 398 CheckSpecialElementType( CurrentElement.Character, CurrentElement.ElementType, InsideDBC, Codepage ); // ALT 389 399 390 400 OnBreak := false; … … 395 405 CurrentCharWidth := FFontManager.CharWidth( ' ' ); 396 406 OnBreak := true; 407 InsideDBC := false; 397 408 end; 398 409 … … 404 415 WordStart := NextP; 405 416 WordX := 0; 417 InsideDBC := false; 406 418 407 419 P := NextP; … … 413 425 begin 414 426 DoLine( P, NextP, WordStartX + WordX ); 427 InsideDBC := false; 415 428 416 429 // end of text, done … … 446 459 CurrentCharWidth := FFontManager.CharWidth( CurrentElement.Character ); 447 460 WordStarted := true; 448 end; 461 InsideDBC := false; 462 end; 463 464 // ALT begins 465 // 466 teWrapChar: 467 begin 468 // This is a legal break character, but not a space (so we still display it). 469 CurrentCharWidth := FFontManager.CharWidth( CurrentElement.Character ); 470 471 // Treat as the start of a new word (for the sake of wrapping). 472 WordStarted := true; 473 inc( WordStartX, WordX + CurrentCharWidth ); 474 WordX := 0; 475 WordStart := NextP; 476 end; 477 478 teLeadByte: 479 begin 480 // Leading byte of a double-byte character. 481 // Get the complete character width for our wrapping calculations. 482 if ( NextP > P ) then 483 CurrentCharWidth := FFontManager.CJKTextWidth( 2, P ) 484 else 485 CurrentCharWidth := FFontManager.CJKCharWidth; 486 WordStarted := true; 487 end; 488 489 teSecondByte: 490 begin 491 // Secondary byte of a double-byte character. 492 // The full character width was already assigned to the leading byte. 493 CurrentCharWidth := 0; 494 495 // We treat each double-byte character as a complete word for the sake 496 // of the wrapping algorithm. 497 inc( LineWordsCompleted ); 498 WordStarted := true; 499 inc( WordStartX, WordX + CurrentCharWidth ); 500 WordX := 0; 501 WordStart := NextP; 502 end; 503 // 504 // ALT ends 449 505 450 506 teStyle: 451 507 begin 508 InsideDBC := false; 452 509 case CurrentElement.Tag.TagType of 453 510 ttBeginLink: … … 582 639 + WordX 583 640 + CurrentCharWidth 584 >= WrapX then641 >= WrapX then 585 642 begin 586 643 // reached right hand side before finding end of word … … 588 645 // always wrap after at least one word displayed 589 646 DoWrap := true 590 else if not FRichTextSettings.AtLeastOneWordBeforeWrap then 647 648 else if ( CurrentElement.ElementType = teWrapChar ) or 649 ( CurrentElement.ElementType = teLeadByte ) then 650 DoWrap := true // ALT 651 652 else if ( not FRichTextSettings.AtLeastOneWordBeforeWrap ) then 591 653 // only wrap during the first word, if the "at least 1 word" flag is not set. 592 654 DoWrap := true; … … 606 668 607 669 NextElement := ExtractNextTextElement( NextP, NextP2 ); 670 671 // ALT 672 if InsideDBC then 673 begin 674 // we're in the middle of a double-byte character, so keep the next byte too 675 InsideDBC := false; 676 NextP := NextP2; 677 NextElement := ExtractNextTextElement( NextP2, NextP3 ); 678 NextP2 := NextP3; 679 end; 680 // /ALT 681 608 682 if NextElement.ElementType <> teLineBreak then 609 683 // there is still more on the line... … … 645 719 CurrentLine.Wrapped := true; 646 720 647 // take the width of the last space of the 648 // previous word off the line width 649 DoLine( WordStart, // current line ends at start of this word 650 WordStart, // next line starts at start of this word 651 WordStartX - FFontManager.CharWidth( ' ' ) ); 652 if CurrentElement.ElementType = teImage then 653 if Bitmap <> nil then 654 if BitmapHeight > CurrentLine.Height then 655 CurrentLine.Height := BitmapHeight; 721 722 if ( CurrentElement.ElementType = teLeadByte ) or 723 ( CurrentElement.ElementType = teWrapChar ) then // ALT 724 begin 725 // draw up to but not including this 'word' (ALT) 726 DoLine( WordStart, 727 WordStart, 728 WordStartX ); 729 end 730 else 731 begin // ALT 732 // take the width of the last space of the 733 // previous word off the line width 734 DoLine( WordStart, // current line ends at start of this word 735 WordStart, // next line starts at start of this word 736 WordStartX - FFontManager.CharWidth( ' ' ) ); 737 if CurrentElement.ElementType = teImage then 738 if Bitmap <> nil then 739 if BitmapHeight > CurrentLine.Height then 740 CurrentLine.Height := BitmapHeight; 741 end; // ALT 656 742 657 743 // do NOT reset WordX to zero; as we are continuing … … 727 813 NewMarginX: longint; 728 814 StartedDrawing: boolean; 815 InsideDBC: boolean; // ALT 729 816 begin 730 817 Line := FLines[ LineIndex ]; … … 736 823 737 824 StartedDrawing := false; 825 InsideDBC := false; // ALT 738 826 739 827 Link := ''; … … 746 834 begin 747 835 Element := ExtractNextTextElement( P, NextP ); 836 CheckSpecialElementType( Element.Character, Element.ElementType, InsideDBC, Codepage ); // ALT 748 837 749 838 case Element.ElementType of 750 839 teWordBreak, 751 840 teText, 841 teLeadByte, // ALT 842 teWrapChar, // ALT 752 843 teImage: 753 844 begin … … 772 863 773 864 // Now find out how wide the thing is 774 inc( X, GetElementWidth( Element ) ); 865 if (( Element.ElementType = teLeadByte ) And ( EndP > P )) then // ALT 866 inc( X, FFontManager.CJKTextWidth( 2, P )) 867 else 868 inc( X, GetElementWidth( Element ) ); 775 869 776 870 if X div FontWidthPrecisionFactor … … 1023 1117 end; 1024 1118 1025 teText, teWordBreak :1119 teText, teWordBreak, teWrapChar: // ALT 1026 1120 Result := FFontManager.CharWidth( Element.Character ); 1121 1122 teLeadByte: // ALT - should not be reached 1123 Result := FFontManager.CJKCharWidth; 1124 1125 teSecondByte: // ALT 1126 Result := 0; 1027 1127 1028 1128 else
Note:
See TracChangeset
for help on using the changeset viewer.