ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 TextLayer rotation problem
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

975 Posts

Posted - Apr 30 2025 :  13:01:25  Show Profile  Reply
I have a TextLayer in TImageEnView:



Unfortunately, when rotating the TextLayer with the mouse, the shape border does not automatically rotate along with the text.

So I wrote some code in the TImageEnView.OnLayerNotify event handler:

procedure TForm1.ImageEnView1LayerNotify(Sender: TObject; layer: Integer; event: TIELayerEvent);
var
  TextLayer: iexLayers.TIETextLayer;
begin
  if (ImageEnView1.Layers[layer] is iexLayers.TIETextLayer) and
     (event = imageenview.ielRotated) then
  begin
    TextLayer := iexLayers.TIETextLayer(ImageEnView1.Layers[layer]);

    // Synchronize border rotation with text rotation
    TextLayer.BorderRotate := TextLayer.Rotate;
    TextLayer.SizeToText();

    ImageEnView1.Update();
  end;
end;


This is the result:



How to obtain a better result?

PeterPanino

975 Posts

Posted - Apr 30 2025 :  14:29:32  Show Profile  Reply
I have now created a workaround:

procedure TformInsertInternalImage.ImageEnViewInsertInternalLayerNotify(Sender: TObject; layer: Integer; event: TIELayerEvent);
var
  TextLayer: iexLayers.TIETextLayer;
  RotationAngle: Double;
begin
  if (ImageEnViewInsertInternal.Layers[layer] is iexLayers.TIETextLayer) and
     (event = imageenview.ielRotated) then
  begin
    TextLayer:= iexLayers.TIETextLayer(ImageEnViewInsertInternal.Layers[layer]);

    // 1. Store the rotation that was just applied
    RotationAngle := TextLayer.Rotate;

    // 2. Reset the rotation to convert unrotated text
    TextLayer.Rotate := 0;

    // 3. Convert to image layer (flatten text)
    TextLayer.ConvertToImageLayer(
      1.0,   // QualityFactor: 1 = screen-size render (recommended for text)
      True   // CropAlpha: remove extra transparent border
    );
 
    // Test - Unfortunately, a Resample-Filter does not increase the quality of the result:
    TIEImageLayer(ImageEnViewInsertInternal.CurrentLayer).ResampleFilter := rfLanczos3;
    TIEImageLayer(ImageEnViewInsertInternal.CurrentLayer).UseResampleFilter := True;
    ImageEnViewInsertInternal.Update();

    // 4. Reapply the rotation to the now bitmap-based image layer
    ImageEnViewInsertInternal.Layers[layer].Rotate := RotationAngle;

    // 5. Set active layer and refresh
    ImageEnViewInsertInternal.LayersCurrent := layer;
    ImageEnViewInsertInternal.Update;
  end;
end;


This is the result:



The disadvantage of this method is that the text cannot be edited anymore afterwards, and there is a noticeable decrease in quality.
Go to Top of Page

xequte

39007 Posts

Posted - Apr 30 2025 :  18:51:59  Show Profile  Reply
Hi Peter

Please enable AspectRatioLocked:

// Add a rectangular border at 30 deg. CCW rotation
TIETextLayer( ImageEnView1.CurrentLayer ).BorderShape  := iesRectangle;
TIETextLayer( ImageEnView1.CurrentLayer ).Alignment    := iejCenter;
TIETextLayer( ImageEnView1.CurrentLayer ).Layout       := ielCenter;
TIETextLayer( ImageEnView1.CurrentLayer ).AspectRatioLocked := True;
TIETextLayer( ImageEnView1.CurrentLayer ).BorderRotate := 30;
ImageEnView1.Update();


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

975 Posts

Posted - May 01 2025 :  04:03:28  Show Profile  Reply
Hi Nigel,

Thank you for the hint!

AspectRatioLocked alleviates the problem but does not solve it:



procedure TformInsertInternalImage.ImageEnViewInsertInternalLayerNotify(Sender: TObject; layer: Integer; event: TIELayerEvent);
var
  TextLayer: iexLayers.TIETextLayer;
begin
  if (ImageEnViewInsertInternal.Layers[layer] is iexLayers.TIETextLayer) and
     (event = imageenview.ielRotated) then
  begin
    TextLayer := iexLayers.TIETextLayer(ImageEnViewInsertInternal.Layers[layer]);

    // Synchronize border rotation with text rotation
    TextLayer.Alignment := iejCenter;
    TextLayer.Layout    := ielCenter;
    TextLayer.AspectRatioLocked := True;
    TextLayer.SizeToText();
    TextLayer.BorderRotate := TextLayer.Rotate;

    ImageEnViewInsertInternal.Update();
  end;
end;


By the way, why do you have to go to all this trouble in OnLayerNotify? Shouldn't rotating a TextLayer with the mouse work automatically?
Go to Top of Page

xequte

39007 Posts

Posted - May 01 2025 :  16:14:44  Show Profile  Reply
Hi Peter

You can set all those properties in OnLayerCreate.

To make rotating the text, also rotate the shape, set LayersTextRotateMode:

https://www.imageen.com/help/TImageEnView.LayersTextRotateMode.html

Unfortunately SizeToText() and AutoSize do not consider the border shape (because of the difficulty of handling all the shapes), so the layer may need to be enlarged for some shapes.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: