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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 TextLayer rotation problem

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Apr 30 2025 : 13:01:25
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?
4   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - May 01 2025 : 16:14:44
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
PeterPanino Posted - May 01 2025 : 04:03:28
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?
xequte Posted - Apr 30 2025 : 18:51:59
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
PeterPanino Posted - Apr 30 2025 : 14:29:32
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.