Achieving Gradient and Bitmap Fill and Stroke in Text in Firemonkey. While Firemonkey offers rich Graphical capabilities through TBrush and TStrokeBrush objects which enable you give high quality Fill and Border effects to your components. TBrush and TStorkeBrush offer gradient and bitmap brush apart from Solid colors. In TText TBrush and TStrokeBrush are missing. In this example I shall demonstrate an alternative method of achieving Fills and stroke using TBrush and TStrokeBrush in TText. The solution is to extend the component TPath. TPath has both Fill (TBrush) and Stroke (TStrokeBrush) properties. The first step is extend TPath and create a property text in the extended class. Next create the path from the assigned text using function TextToPath in TCanvas class. create a Path with desired text using TPath component. TPath component has both TBrush and TStrokeBrush properties.

Below is the Code:

class PACKAGE pathtextclass : public Fmx::Objects::TPath {
          String ftext;
          bool fautosize;
          TFont *ffont;
          TBrush *fbfill;
          TStrokeBrush *fbstroke;
          __fastcall pathtextclass(TComponent* Owner);
          __fastcall ~pathtextclass();
          __property String text={read=ftext,write=settext};
           __property bool autosize={read=fautosize,write=setautosize}; //,default=true};
           __property TFont *font={read=ffont,write=ffont};
           __property TBrush *bfill={read=fbfill,write=fbfill}; //background Fill and Stroke
           __property TStrokeBrush *bstroke={read=fbstroke,write=fbstroke};
           void __fastcall settext(String pt);
           void __fastcall dosettext();
           void __fastcall onchangedeh(TObject *Sender); //used in font, bfill, bsbrush
           void __fastcall onresizeeh(TObject *Sender);
           void __fastcall setautosize(bool pa);
           void __fastcall Paint();
__fastcall pathtextclass::pathtextclass(TComponent* Owner) : TPath(Owner)
          //fautosize = true;
           ffont = new TFont;
           ffont->Family = "Arial";
           ffont->Size = 15;
           ffont->OnChanged = onchangedeh;
           OnResize = onresizeeh;
           fbfill = new TBrush(TBrushKind::bkNone,(fmxcolor)0xff000000);
           fbfill->OnChanged = onchangedeh;
           fbstroke = new TStrokeBrush(TBrushKind::bkNone,(fmxcolor)0xff000000);
           fbstroke->OnChanged = onchangedeh;
           tagd = 0;
void __fastcall pathtextclass::settext(String pt)
           if (pt != ftext) {
           if (pt.IsEmpty())
           ftext = pt;
           dosettext(); }
__fastcall pathtextclass::~pathtextclass()
           delete ffont;
           delete fbfill;
           delete fbstroke;
Function dosettext actually converts the given Text to Path using the Given Font information.
void __fastcall pathtextclass::dosettext()
           Data->Clear(); //clear the already present path data
           if (ftext.IsEmpty())
           if (ffont != NULL)
           TRectF rf(ShapeRect.left,,ShapeRect.right,ShapeRect.bottom);
          //convert the given text to path and draw on canvas: Data is the Data property of TPath class //which
           if (autosize) {
            Width = Canvas->TextWidth(ftext);
            Height = Canvas->TextHeight(ftext); }fmx chitrakoot42
void __fastcall pathtextclass::onchangedeh(TObject *Sender)
void __fastcall pathtextclass::onresizeeh(TObject *Sender)
void __fastcall pathtextclass::setautosize(bool pa)
           if (fautosize != pa) {
           fautosize = pa;
           dosettext(); }
Override the default Paint Function to incorporate Background Fill & Stroke
void __fastcall pathtextclass::Paint()
           if (bfill->Kind != TBrushKind::bkNone) {
            Canvas->FillRect(ShapeRect,0.0,0.0,TCorners(),1.0); }
           if (bstroke->Kind != TBrushKind::bkNone) {
            Canvas->DrawRect(ShapeRect,0.0,0.0,TCorners(),1.0); }
void __fastcall pathtextclass::center(bool pv,bool ph)
           TControl *par = dynamic_cast(Parent);
           if (par != NULL) {
            if (pv)
                     Position->X = (par->Width - Width)/2;
            if (ph)
                     Position->Y = (par->Height - Height)/2; }
Below is the resulting text with Gradient Brush

Below is the resulting text with Bitmap Fill. The bitmap used is the image Chrysanthemum.jpg taken Sample Pictures of Windows 7 Ultimdate.

Pathtext   30/07/2016