Advance PaintText For PrintPreview

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Advance PaintText For PrintPreview

Postby Mr.HTZ » June 6th, 2008, 8:40 am

Hello,
First, many thanks to Kambiz for creating such a great Delphi component.

New function for advance PaintText in PrintPreview Component

Capability:
Rect
BkColor
BiDiMode
WordWrap
TextLayout
Transparent
TextAlignment

Code: Select all
Procedure PaintText(Canvas: TCanvas; FText: String; FRect: TRect; FTransparent: Boolean = True; FColor: TColor = clWhite; FAlignment: TAlignment = taRightJustify; FWordWrap: Boolean = True; FLayout: TTextLayout = tlCenter; FBiDiMode: TBiDiMode = bdRightToLeft);
Const
  WordWraps: Array[Boolean] Of Word = (0, DT_WORDBREAK);
  Alignments: Array[TAlignment] Of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
Var
  DrawStyle: LongInt;
  ARect, CalcRect: TRect;

  Function DrawTextBiDiModeFlags(Flags: Longint): Longint;

    Function UseRightToLeftAlignment: Boolean;
    Begin
      Result := SysLocale.MiddleEast And (FBiDiMode = bdRightToLeft);
    End;

    Function UseRightToLeftReading: Boolean;
    Begin
      Result := SysLocale.MiddleEast And (FBiDiMode <> bdLeftToRight);
    End;

    Function DrawTextBiDiModeFlagsReadingOnly: Longint;
    Begin
      If UseRightToLeftReading Then
        Result := DT_RTLREADING
      Else
        Result := 0;
    End;

  Begin
    Result := Flags;
    { do not change center alignment }
    If UseRightToLeftAlignment Then
      If Result And DT_RIGHT = DT_RIGHT Then
        Result := Result And Not DT_RIGHT { removing DT_RIGHT, makes it DT_LEFT }
      Else
        If Not (Result And DT_CENTER = DT_CENTER) Then
          Result := Result Or DT_RIGHT;
    Result := Result Or DrawTextBiDiModeFlagsReadingOnly;
  End;

  Procedure DoDrawText(Var ARect: TRect; Flags: LongInt; AText: String);
  Const
    FShowAccelChar = True;
  Begin
    If (Flags And DT_CALCRECT <> 0) And ((AText = '') Or FShowAccelChar And
      (AText[1] = '&') And (AText[2] = #0)) Then AText := AText + ' ';
    If Not FShowAccelChar Then Flags := Flags Or DT_NOPREFIX;
    Flags := DrawTextBiDiModeFlags(Flags);
    DrawText(Canvas.Handle, PChar(AText), Length(AText), ARect, Flags);
  End;

Begin
  With Canvas Do
  Begin
    ARect := FRect;
    If Not FTransparent Then
    Begin
      Brush.Color := FColor;
      Brush.Style := bsSolid;
      FillRect(ARect);
    End;
    Brush.Style := bsClear;

    { DoDrawText takes care of BiDi alignments }
    DrawStyle := DT_EXPANDTABS Or WordWraps[FWordWrap] Or Alignments[FAlignment];
    { Calculate vertical layout }
    If FLayout <> tlTop Then
    Begin
      CalcRect := ARect;
      DoDrawText(CalcRect, DrawStyle Or DT_CALCRECT, FText);
      If FLayout = tlBottom Then
        OffsetRect(ARect, 0, ARect.Bottom - CalcRect.Bottom)
      Else
        OffsetRect(ARect, 0, (ARect.Bottom - CalcRect.Bottom) Shr 1);
    End;
    DoDrawText(ARect, DrawStyle, FText);
  End;
End;
Mr.HTZ
Member
Member
 
Posts: 1
Joined: June 6th, 2008, 8:09 am
Location: Qom, Iran

Postby Kambiz » June 6th, 2008, 9:54 am

Thank you very much.

I have some other modifications sent by another user. Seems it is time to release a new update.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron