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