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
 Textout
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

exchangeviews

India
39 Posts

Posted - Dec 14 2014 :  12:14:20  Show Profile  Reply
Hi,

I am trying to use textout but getting white around text. I m using follwing code:
ImageEnViewTxt.Bitmap.Canvas.TextOut(Xalign,Yalign, 'New Text Layer')

Output is:


However it should be like this:


I also tried all ResampleFilters on this new layer one by one but without luck. Any help? Thanks in advance.

xequte

39140 Posts

Posted - Dec 14 2014 :  12:57:01  Show Profile  Reply
Hi

That is because Windows is trying to smooth the font. If you use TCanvas.TextOut then you must decrease the font quality.

You would be better to use ImageEnViewTxt.Proc.TextOut:

http://www.imageen.com/help/TImageEnProc.TextOut.html

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

exchangeviews

India
39 Posts

Posted - Dec 14 2014 :  13:43:20  Show Profile  Reply
Hi Nigel,

thanks for update. I used the Proc.TextOut and it is working fine if I draw a multiline memo text left align. Issue raised if center align or right align is used. See the following code:
for i := 0 to Memo1.Lines.Count - 1 do
Begin
if btnLeftAlign.Down then
    Xalign:=0
    else if btnCenterAlign.Down then
    Xalign:=Round((iTextWidth - ImageEnViewTxt.Iebitmap.Canvas.TextWidth(Memo1.Lines[i]))/2)
    else if btnRightAlign.Down then
    Xalign:=ImageEnViewTxt.CurrentLayer.Width - ImageEnViewTxt.Iebitmap.Canvas.TextWidth(Memo1.Lines[i]);

   // ImageEnViewTxt.Bitmap.Canvas.TextOut(Xalign,i * iTextHeight, Memo1.Lines[i]); // draw text on second layer

    ImageEnViewTxt.Proc.TextOut(Xalign,i * iTextHeight,Memo1.Lines[i],FontName, FontSize,
    FontColor, Style,StrToInt(editRotation.Text), False);
End;


See result:







Same code works fine on center align and right align if I draw using canvas.textout but white around the text. Please help. Where is the problem?
Go to Top of Page

xequte

39140 Posts

Posted - Dec 14 2014 :  22:02:15  Show Profile  Reply
Hi

There looks to be an issue in your code.

Here:
Xalign := Round((iTextWidth - ImageEnViewTxt.Iebitmap.Canvas.TextWidth(Memo1.Lines[i]))/2)


You call TextWidth. TextWidth returns the width for text using the current font of the canvas. You do not appear to be setting the canvas font to that which is passed to TextOut.

Try setting the ImageEnViewTxt.IEBitmap.Canvas.Font to match the specified properties, then call:
ImageEnViewTxt.Proc.TextOut(Xalign, i * iTextHeight, Memo1.Lines[i], nil, StrToInt(editRotation.Text), False);




Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

xequte

39140 Posts

Posted - Dec 14 2014 :  22:09:32  Show Profile  Reply
Also, why not just set XAlign to Align_Text_Right or Align_Text_Horz_Center?


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

exchangeviews

India
39 Posts

Posted - Dec 15 2014 :  00:00:01  Show Profile  Reply
Hi Nigel,

Thanks. Align_Text_Right or Align_Text_Horz_Center worked great. Is there any workaround to avoid chop off the tail when font style is italic and Align_Text_Right is used? See image:


See the char 'r' and 'd' is chopped off.

Thanks in advance.
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Dec 15 2014 :  14:52:53  Show Profile  Reply
The simplest workaround for this situations is to add a blank on the end of each line.

I use this trick often, especially when moving single line of text around the canvas and if I want mouse cursor to be in the center of text line. If text is in italic, I add one blank at then beginning of the line and one at the end...so the mouse cursor is always in the middle and output text is not cropped.
Go to Top of Page

exchangeviews

India
39 Posts

Posted - Dec 28 2014 :  04:06:05  Show Profile  Reply
Hi Nigel,
Here is the code I am using:

ImageEnViewTxt.LayersAdd; // add a new layer
ImageEnViewTxt.CurrentLayer.PosX:=StrToInt(editXoffset.Text);
ImageEnViewTxt.CurrentLayer.PosY:=StrToInt(editYoffset.Text);
ImageEnViewTxt.Bitmap.Canvas.Font.Name:=FontName;
ImageEnViewTxt.Bitmap.Canvas.Font.Style:=Style;
ImageEnViewTxt.Bitmap.Canvas.Font.Size:=FontSize;
ImageEnViewTxt.Bitmap.Canvas.pen.Color:=clRed;
ImageEnViewTxt.Bitmap.Canvas.Pen.Width:=2;
ImageEnViewTxt.Bitmap.Canvas.Font.Color:=FontColor;
ImageEnViewTxt.EnableInteractionHints:=False;

iTextHeight:= ImageEnViewTxt.ieBitmap.Canvas.TextHeight(Memo1.Lines[0]);
ImageEnViewTxt.Proc.Fill(CreateRGB(255, 255, 255));
iTextWidth:=0;
for i := 0 to Memo1.Lines.Count - 1 do
Begin
if iTextWidth < ImageEnViewTxt.Iebitmap.Canvas.TextWidth(Memo1.Lines[i])  then
iTextWidth:=ImageEnViewTxt.Iebitmap.Canvas.TextWidth(Memo1.Lines[i]);
ImageEnViewTxt.Iebitmap.Width:=iTextWidth;
End;
ImageEnViewTxt.Iebitmap.height:=iTextHeight*Memo1.Lines.Count;
for i := 0 to Memo1.Lines.Count - 1 do
Begin
  if iTextWidth>0 then
  Begin
    if btnLeftAlign.Down then
    Begin
    Xalign:= 0;
    End
    else if btnCenterAlign.Down then
    Begin
    Xalign:=Align_Text_Horz_Center
    End
    else if btnRightAlign.Down then
    Begin
    Xalign:=Align_Text_Right;
    End;


      if i=0 then
        Yalign:= i * iTextHeight
      else
        Yalign:= i * (iTextHeight + UpDownLineSpace.Position);


   ImageEnViewTxt.CurrentLayer.Rotate:=StrToInt(EditRotation.Text);
   ImageEnViewTxt.Proc.TextOut(Xalign, Yalign, Memo1.Lines[i], FontName, FontSize, FontColor, Style, 0, False);


  End;
End;

ImageEnViewTxt.CurrentLayer.ResampleFilter:=ResampleFilter[ComboBoxResampleFilter.ItemIndex];
ImageEnViewTxt.CurrentLayer.UseResampleFilter:=True;
ImageEnViewTxt.Proc.SetTransparentColors(CreateRGB(255,255,255),CreateRGB(255,255,255),0); // remove the white

Please assist how to calculate the layer width in advance if Proc.TextOut is going to draw an italic text?
Go to Top of Page

xequte

39140 Posts

Posted - Jan 01 2015 :  18:56:42  Show Profile  Reply
Hi

Unfortunately, Canvas.TextWidth, TextExtent etc, return the incorrect value for italicized fonts (failing to take into account the overhang):

http://msdn.microsoft.com/en-us/library/dd183418.aspx

The simplest solution would be to append a space if the font is italicized.

Otherwise you will need to use GetCharABCWidths to determine the size of the overhang:

http://www.delphigroups.info/2/d6/210469.html


Also, for creation of layers from text see:

http://www.imageen.com/help/TImageEnView.LayersCreateFromText.html


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