3D Text

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

3D Text

Post by standay »

Hi Sergey,

I use an rve as a "cover page" in my app. It can have any background color. I also put text on that cover page and I thought it would be nice if I could display the text in "3D" so that text would show up no matter what color the background was. So, I came up with the code below that worked great and did just what I needed:

Code: Select all

procedure TForm1.CoverRVEStyleDrawStyleText(Sender: TRVStyle;
  const s: TRVUnicodeString; Canvas: TCanvas; StyleNo, SpaceAtLeft, ALeft, ATop,
  AWidth, AHeight, BaseLine, TextWidth, SpaceCount: Integer;
  DrawState: TRVTextDrawStates; Printing, PreviewCorrection,
  ForMetafile: Boolean; ColorMode: TRVColorMode; DefBiDiMode: TRVBiDiMode;
  RefCanvas: TCanvas; LeftNoExpIndex, RightNoExpIndex: Integer;
  PSaD: PRVScreenAndDevice; var DoDefault: Boolean);
var
  FColor: TColor;
begin

  //Draws coverRVE text as "3D"

  DoDefault := false;
  FColor := Canvas.Font.Color; //store default original color

  //Draw text shadow using a +1 offset:
  Canvas.Font.Color := clBlack;
  if FColor < 1 then //we don't want black on black text
    Canvas.Font.Color := clGrayText;
  Canvas.TextOut( ALeft + SpaceAtLeft + 1, BaseLine + 1, s );

  //Draw normal text on top of shadow text at default text pos:
  Canvas.Font.Color := FColor;
  Canvas.TextOut( ALeft + SpaceAtLeft, BaseLine, s );

end;
Other users might find that code useful to display "3D" text.

However, I was also thinking it would be helpful if I there was an option for this in regular text styles as well so it could be saved and printed this way. I was thinking you'd need 2 vars: ShadowOffset and ShadowColor. ShadowOffset would default to 0 (no shadow). A negative value would draw the shadow to the left and above the original text, a positive value would draw the shadow to the right and below the original text.

It might be too dificult to implement, but I thought I'd ask about it.

Thanks Sergey

Stan
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: 3D Text

Post by Sergey Tkachenko »

Probably in future...

Please note that for text drawing you should use Sender.TextStyles[StyleNo].Draw(..) instead of Canvas.TextOut(...)
(all other parameters of OnDrawStyleText must be passed to Sender.TextStyles[StyleNo].Draw(..))

PS: you can also see the example https://www.trichview.com/support/files ... operty.zip
It shows how to add new properties to items of TextStyles, specifically a shadow.
It is a very old example (created more than 10 years), so parameters of some methods must be changed.
Let me know if you need a modern version of this demo.
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: 3D Text

Post by standay »

Hi Sergey,

For my limited purpose, textout would probably have worked, but I changed Canvas.TextOut to Sender.TextStyles[StyleNo].Draw anyway.

I'll take a look at the example later today.

Thanks Sergey

Stan
Post Reply