The examples don't compile, but I have got to this stage:
mRect has been declared as a TRectF, so do I actually need to Create it as well. Either of the following still does not make the text appear.
mRect.Create(0, 0, 200, 270);
or
mRect.Left := 0;
mRect.Top := 0;
mRect.Width := 200;
mRect.Height := 270;
Canvas.FillText(mRect, 'Hello World', false, 100, [], TTextAlign.taLeading,TTextAlign.taCenter);
Nothing appears on the form. Any suggestions?
Regards
Graham
> {quote:title=Paul G. wrote:}{quote}
> Hello Graham,
>
> Try this code that works on my XE2:
>
>
> Canvas.BeginScene;
> Canvas.Fill.Color := claBlack;
> mRect.Create(0, 0, 200, 270);
> Canvas.FillText(mRect, 'Hello World', false, 100, [],
> TTextAlign.taLeading,TTextAlign.taCenter);
> Canvas.EndScene;
>
>
> I have added "Canvas.BeginScene", "Canvas.EndScene"
> and "Canvas.Fill.Color := claBlack;"
>
No difference. I just get a blank white form when I run it on Windows or on a MAC.
I have created this test project as a FireMonkey HD application and the above code is in the FormCreate event.
Any more clues.
Regards
Graham
> {quote:title=Paul G. wrote:}{quote}
> Try to place a TButton on the form
> and in the OnClick event insert the code.
OK, so that works now. I had already tried it in the OnShow event but maybe I hadn't used the BeginScene which appears essential.
The next strange issue is that if I keep pressing the button, the text "Hello World" appears to be getting bolder and bolder.
Regards
Graham
> {quote:title=Graham Powell wrote:}{quote}
> > {quote:title=Paul G. wrote:}{quote}
> > Try to place a TButton on the form
> > and in the OnClick event insert the code.
>
> OK, so that works now. I had already tried it in the OnShow event but maybe I hadn't used the BeginScene which appears essential.
> The next strange issue is that if I keep pressing the button, the text "Hello World" appears to be getting bolder and bolder.
>
> Regards
> Graham
And now I am trying to get this to work on the MAC. It doesn't.
So does the concept of Canvas.FillText not work on the MAC? If not, what is the correct command? And where do I find the documentation on this?
Graham
> {quote:title=Graham Powell wrote:}{quote}
> > {quote:title=Graham Powell wrote:}{quote}
> > > {quote:title=Paul G. wrote:}{quote}
> > > Try to place a TButton on the form
> > > and in the OnClick event insert the code.
> >
> > OK, so that works now. I had already tried it in the OnShow event but maybe I hadn't used the BeginScene which appears essential.
> > The next strange issue is that if I keep pressing the button, the text "Hello World" appears to be getting bolder and bolder.
> >
> > Regards
> > Graham
>
> And now I am trying to get this to work on the MAC. It doesn't.
>
> So does the concept of Canvas.FillText not work on the MAC? If not, what is the correct command? And where do I find the documentation on this?
>
> Graham
I do the same test, and same conclusion : Even if the code work on Windows (with the beginscene/EndScene) that will not work on mac.
I suspect the difference between the 2 systems in drawing sub system.
For fix that, I use Imagecontrol on the form, and drawing on : So, same code work on the both platform.
I'm very curious to see a direct drawing code working on OSX (and IOS) without tweaking via NSObject delegate stuff.
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 13-Oct-2011, at 5:28 PM EST
From: Vincent Gsell
Re: FireMonkey Draw Text on a Form's canvas [Edit]
> > And now I am trying to get this to work on the MAC. It doesn't.
> >
> > So does the concept of Canvas.FillText not work on the MAC? If not, what is the correct command? And where do I find the documentation on this?
> >
> > Graham
>
> I do the same test, and same conclusion : Even if the code work on Windows (with the beginscene/EndScene) that will not work on mac.
> I suspect the difference between the 2 systems in drawing sub system.
> For fix that, I use Imagecontrol on the form, and drawing on : So, same code work on the both platform.
>
> I'm very curious to see a direct drawing code working on OSX (and IOS) without tweaking via NSObject delegate stuff.
Have you tried using
Image.Bitmap.SetSize(Trunc(Image.Width), Trunc(Image.Height));
I haven't tried it on OSX but on Windows I found the FillText function (and other bitmap functions) unpredictable until I set the bitmap size to the Image size. Here is the code I used:
var
Rect: TRectF;
begin
with Image.Bitmap do
begin
SetSize(Trunc(Image.Width), Trunc(Image.Height));
Clear(TAlphaColors.White);
Canvas.BeginScene();
Canvas.Fill.Color := claDimGrey;
Canvas.Font.Size := 60;
Rect.Create(0, 0, 175, 80);
Canvas.FillText(Rect,
'My Text',
False,
100,
[],
TTextAlign.taCenter,
TTextAlign.taCenter);
Canvas.EndScene();
end;
end;
Michael
Edited by: Michael Brooks on Oct 20, 2011 8:34 PM
> {quote:title=Michael Brooks wrote:}{quote}
> > > And now I am trying to get this to work on the MAC. It doesn't.
> > >
> > > So does the concept of Canvas.FillText not work on the MAC? If not, what is the correct command? And where do I find the documentation on this?
> > >
> > > Graham
> >
> > I do the same test, and same conclusion : Even if the code work on Windows (with the beginscene/EndScene) that will not work on mac.
> > I suspect the difference between the 2 systems in drawing sub system.
> > For fix that, I use Imagecontrol on the form, and drawing on : So, same code work on the both platform.
> >
> > I'm very curious to see a direct drawing code working on OSX (and IOS) without tweaking via NSObject delegate stuff.
>
> Have you tried using
>
> Image.Bitmap.SetSize(Trunc(Image.Width), Trunc(Image.Height));
>
> I haven't tried it on OSX but on Windows I found the FillText function (and other bitmap functions) unpredictable until I set the bitmap size to the Image size. Here is the code I used:
>
> var
> Rect: TRectF;
> begin
> with Image.Bitmap do
> begin
> SetSize(Trunc(Image.Width), Trunc(Image.Height));
> Clear(TAlphaColors.White);
> Canvas.BeginScene();
> Canvas.Fill.Color := claDimGrey;
> Canvas.Font.Size := 60;
> Rect.Create(0, 0, 175, 80);
> Canvas.FillText(Rect,
> 'My Text',
> False,
> 100,
> [],
> TTextAlign.taCenter,
> TTextAlign.taCenter);
> Canvas.EndScene();
> end;
> end;
>
> Michael
>
> Edited by: Michael Brooks on Oct 20, 2011 8:34 PM
The idea of using the canvas of an Image.Bitmap (shown above) works on Windows and on the MAC.
I think FireMonkey is not as close to Delphi as we were all led to believe, unless FireMonkey is really still in the very early stages of development
Graham
> {quote:title=Graham Powell wrote:}{quote}
> And now I am trying to get this to work on the MAC. It doesn't.
>
> So does the concept of Canvas.FillText not work on the MAC? If not, what is the correct command? And where do I find the documentation on this?
Try adding "Canvas.Fill.Kind := TBrushKind.bkSolid"
Giel
> {quote:title=Graham Powell wrote:}{quote}
> > {quote:title=Paul G. wrote:}{quote}
> > Try to place a TButton on the form
> > and in the OnClick event insert the code.
>
> OK, so that works now. I had already tried it in the OnShow event but maybe I hadn't used the BeginScene which appears essential.
> The next strange issue is that if I keep pressing the button, the text "Hello World" appears to be getting bolder and bolder.
>
> Regards
> Graham
As the "getting bolder and bolder" is regarded: the text rendering is based on an anti-aliasing technique (ClearType or similar) which has border pixels with an alpha value less than 1. Thus you get an accumulative behaviour on those pixels - and *bingo* a bolder appearance !
BR
Carsten
> {quote:title=Carsten Moe wrote:}{quote}
> > {quote:title=Graham Powell wrote:}{quote}
> > > {quote:title=Paul G. wrote:}{quote}
> > > Try to place a TButton on the form
> > > and in the OnClick event insert the code.
> >
> > OK, so that works now. I had already tried it in the OnShow event but maybe I hadn't used the BeginScene which appears essential.
> > The next strange issue is that if I keep pressing the button, the text "Hello World" appears to be getting bolder and bolder.
> >
> > Regards
> > Graham
>
> As the "getting bolder and bolder" is regarded: the text rendering is based on an anti-aliasing technique (ClearType or similar) which has border pixels with an alpha value less than 1. Thus you get an accumulative behaviour on those pixels - and *bingo* a bolder appearance !
>
> BR
> Carsten
I've been trying to get FMX to draw lines and shapes on the canvas, so maybe it's the same for drawtext. From a QC response, I found that the draw commands seem to work reliably only if you put them in the OnPaint event for the form. Whatever is in OnPaint gets drawn each time the form is re-painted. To force a repaint, you use the Invalidate procedure (no parameters needed.) That will erase anything you've drawn, and repaint whatever is in the OnPaint event handler, without flicker.
Hope that helps. As best I can tell this is not documented.
Scott