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
 LayersCreateFromText + Angle>0 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
exchangeviews Posted - May 13 2015 : 04:33:00
Dear All,

I used following code to create a layer from text but the end of text is being cutoff if angle is greater than 0. Any help on how to increase height & width of layer in advance before calling following method?

ImageEnVect1.LayersCreateFromText('Test','Tahoma', 28, clRed, [],False,3,2,20,False);


Result is:

1   L A T E S T    R E P L I E S    (Newest First)
w2m Posted - May 13 2015 : 09:48:40
As best as I can determine, LayersCreateFromText does not adjust the dimensions of the layer to account for the pixel width of the rendered text and does not calculate the dimensions of the rotated rectangle before the text is rendered to the bitmap. Because the layer is created and the text is rendered without these adjustments I do not see any way to adjust this with the existing function. If there was an overloaded version of LayersCreateFromText that used an existing layer that was created to account for the length of the text, the font size and the rotation it might work better for rotated text. It appears that the existing function could also be changed to account for the text rotation as well, meaning if the angle is not 0 then the layer dimensions would be increased to account for the rotation before the text is rendered to the bitmap.

I tried adjusting the layer with:

ImageEnVect1.Layers[iLayer].Width := IETextWidthW(Canvas, 'Text');
ImageEnVect1.Layers[iLayer].Height := IETextHeightW(Canvas, 'Text');
ImageEnVect1.LayersFixSizes(iLayer);
ImageEnVect1.LayersFixRotations(iLayer);
ImageEnVect1.LayersFixBorders(iLayer);

but this will not work because adjustments to the dimensions of the layer have to be done before the text is rendered to the bitmap.

It turns out you can accomplish this if you write your own code:
procedure TForm1.TextOut1Click(Sender: TObject);
var
  iLayer: Integer;
  iText: string;
begin
  { Allow selection transparent layers }
  ImageEnVect1.SelectionOptions := ImageEnVect1.SelectionOptions +
    [iesoSelectTranspLayers];
  iText := 'Text';
  { Create a new layer }
  iLayer := ImageEnVect1.LayersAdd;
  { Fill the background with white }
  ImageEnVect1.IEBitmap.Fill(clWhite);
  { Set the layer position and dimensions }
  ImageEnVect1.Layers[iLayer].PosX := ImageEnVect1.ClientWidth div 2;
  ImageEnVect1.Layers[iLayer].PosY := ImageEnVect1.ClientHeight div 2;
  ImageEnVect1.Layers[iLayer].Width := 150;
  ImageEnVect1.Layers[iLayer].Height := 150;
  { Draw text onto new layer }
  ImageEnVect1.Proc.TextOut((ImageEnVect1.Layers[iLayer].Width div 2) +
  IETextWidthW(Canvas, iText), Align_Text_Vert_Center, iText, 'Tahoma', 45,
    clRed, [fsBold], 22, True, True);
  { Make the white background transparent }
  ImageEnVect1.Proc.SetTransparentColors(CreateRGB(255, 255, 255),
    CreateRGB(255, 255, 255), 0);
  ImageEnVect1.Update;
end;



This produces a much better result with rotated text than the LayersCreateFromText function as it does not crop the rotated text as shown in a screenshot of the layer above. Unfortunately I could not figure out how to align the text horizontally in the center of the layer. Maybe someone can figure out why. If you use Align_Text_Horz_Center as the X value the text is not rendered at all.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development