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
 LayersCreateFromText + Angle>0 Problem.
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

exchangeviews

India
39 Posts

Posted - May 13 2015 :  04:33:00  Show Profile  Reply
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:

w2m

USA
1990 Posts

Posted - May 13 2015 :  09:48:40  Show Profile  Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: