Changeset 420 for trunk/Components


Ignore:
Timestamp:
Feb 28, 2019, 4:17:24 AM (6 years ago)
Author:
ataylor
Message:

Improve DBCS string width calculations, other small tweaks.

Location:
trunk/Components
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Components/CanvasFontManager.pas

    r418 r420  
    11341134  EnsureMetricsLoaded;
    11351135  GpiQueryTextBox( FCanvas.Handle, Length, S^, TXTBOX_COUNT, aptl[0] );
    1136   // The pad of 2.1 per character was chosen through experimentation, since the
    1137   // actual returned value always seems too narrow. I have no idea why. (ALT)
    1138   Result := ( 2.1 + aptl[ TXTBOX_BOTTOMRIGHT ].x) * FontWidthPrecisionFactor;
     1136  Result := aptl[ TXTBOX_CONCAT ].x * FontWidthPrecisionFactor;
    11391137end;
    11401138//
  • trunk/Components/RichTextDocumentUnit.pas

    r418 r420  
    143143                           const Codepage: LongInt ): boolean;
    144144
    145 // Adjusts the character position to the beginning of any multi-byte character.
     145// Adjusts the character position to the beginning or end of any multi-byte
     146// character.
    146147procedure MoveToCharacterBoundary(     TextPointer: PChar;
    147148                                   var Index:       LongInt;
    148149                                   var Offset:      LongInt;
    149150                                       RowStart:    LongInt;
    150                                        Codepage:    LongInt );
     151                                       Codepage:    LongInt;
     152                                       Advance:     Boolean; );
    151153//
    152154// ALT ends
     
    967969                                   var Offset:      LongInt;
    968970                                       RowStart:    LongInt;
    969                                        Codepage:    LongInt  );
     971                                       Codepage:    LongInt;
     972                                       Advance:     Boolean; );
    970973var
    971974  P:         PChar;
     
    989992      inc( RowStart );
    990993    end;
    991 {
     994
    992995    // We've reached the target position, and the current parsing state should
    993996    // be correctly set. So now we can safely determine the target byte's type.
    994997    Element := ExtractNextTextElement( P, NextP );
    995998    CheckSpecialElementType( Element.Character, Element.ElementType, InsideDBC, Codepage );
    996 }
    997999    if InsideDBC then
    9981000    begin
    999       // If this the first byte of a double byte character, move back by one.
    1000       dec( Index );
    1001       dec( Offset );
     1001      // If this the first byte of a double byte character, move position by one.
     1002      if Advance Then
     1003      Begin
     1004        inc( Index );
     1005        inc( Offset );
     1006      End
     1007      Else
     1008      Begin
     1009        dec( Index );
     1010        dec( Offset );
     1011      End
    10021012    end;
    10031013  end;
  • trunk/Components/RichTextLayoutUnit.pas

    r418 r420  
    834834  begin
    835835    Element := ExtractNextTextElement( P, NextP );
    836     CheckSpecialElementType( Element.Character, Element.ElementType, InsideDBC, Codepage );   // ALT
     836
     837    // ALT - handle double-byte characters
     838    if InsideDBC and ( P < EndP ) then
     839    begin
     840      P := NextP;
     841      Element := ExtractNextTextElement( P, NextP );
     842      InsideDBC := false;
     843    end;
     844    CheckSpecialElementType( Element.Character, Element.ElementType, InsideDBC, Codepage );
     845    // ALT done
    837846
    838847    case Element.ElementType of
  • trunk/Components/RichTextView.PAS

    r418 r420  
    472472  // ALT
    473473  Offset := FCursorOffset;
    474   MovetoCharacterBoundary( FText, SelectionStart, FCursorOffset, Offset, FLayout.Codepage );
     474  MoveToCharacterBoundary( FText, SelectionStart, FCursorOffset, Offset, FLayout.Codepage, false );
    475475
    476476  FSelectionStart := SelectionStart;
     
    493493  // ALT
    494494  Offset := FCursorOffset;
    495   MovetoCharacterBoundary( FText, SelectionEnd, FCursorOffset, Offset, FLayout.Codepage );
     495  MoveToCharacterBoundary( FText, SelectionEnd, FCursorOffset, Offset, FLayout.Codepage, false );
    496496
    497497  if FSelectionStart = -1 then
     
    12301230  Descender: longint;
    12311231  MaxDescender: longint;
     1232  Index: longint;       // ALT
     1233  RowStart: longint;    // ALT
    12321234begin
    12331235  RemoveCursor;
     
    12521254    // off top
    12531255    exit;
     1256
     1257  // ALT - move to nearest character boundary
     1258  Index := FLayout.GetCharIndex( Line.Text ) + FCursorOffset;
     1259  RowStart := FLayout.GetCharIndex( Line.Text );
     1260  MoveToCharacterBoundary( FText, Index, FCursorOffset, RowStart, FLayout.Codepage, false );
    12541261
    12551262  FLayout.GetXFromOffset( FCursorOffset, CursorRow, X );
     
    20352042//  InsideDBC: boolean;       // ALT
    20362043  RowStart: longint;        // ALT
     2044  MoveRight: boolean;       // ALT
    20372045  Index: longint;
    20382046begin
     
    20672075
    20682076  RowStart := FLayout.GetCharIndex( FLayout.FLines[ Row ].Text );
    2069   MoveToCharacterBoundary( FText, Index, Offset, RowStart, FLayout.Codepage );  // ALT
     2077
     2078  // ALT
     2079  if Offset = ( FCursorOffset + 1 ) then
     2080    MoveRight := true
     2081  else
     2082    MoveRight := false;
     2083  MoveToCharacterBoundary( FText, Index, Offset, RowStart, FLayout.Codepage, MoveRight );
    20702084
    20712085  FCursorOffset := Offset;
Note: See TracChangeset for help on using the changeset viewer.