FMX.TextLayout.TTextAttribute

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

  TTextAttribute = record
  public
    Font: TFont;
    Color: TAlphaColor;
    constructor Create(const AFont: TFont;
                       AColor : TAlphaColor); overload;
    constructor Create(const AExisting: TTextAttribute;
                       const ANewFont: TFont); overload;
    constructor Create(const AExisting: TTextAttribute;
                       ANewColor: TAlphaColor); overload;
  end;

C++

struct DECLSPEC_DRECORD TTextAttribute
{
public:
    Fmx::Graphics::TFont* Font;
    System::Uitypes::TAlphaColor Color;
    __fastcall TTextAttribute(Fmx::Graphics::TFont* const AFont, System::Uitypes::TAlphaColor AColor)/* overload */;
    __fastcall TTextAttribute(const TTextAttribute &AExisting, Fmx::Graphics::TFont* const ANewFont)/* overload */;
    __fastcall TTextAttribute(const TTextAttribute &AExisting, System::Uitypes::TAlphaColor ANewColor)/* overload */;
    TTextAttribute() {}
};

Properties

Type Visibility Source Unit Parent
record
struct
public
FMX.TextLayout.pas
FMX.TextLayout.hpp
FMX.TextLayout FMX.TextLayout

Description

Holds text attributes.

Font keeps the font of the text. Color keeps the color of the text.

TTextAttribute can be created in three ways:

  • From an existing font and color
  • From an existing TTextAttribute, with a new color
  • From an existing TTextAttribute, with a new font


Note: Starting with RAD Studio 10.2 Tokyo Release 3, TTextLayout class does not free a TFont instance in the first constructor; instead, the program has to remove the TFont instance.
For non-ARC platforms, including Windows and macOS, you have to call Free method manually when a font instance using the first parameter of TTextAttribute.Create is no longer used.
For ARC platforms, ARC will remove the instance if it is not used.

See example below:

Layout := TTextLayoutManager.TextLayoutByCanvas(self.Canvas.ClassType).Create;
try
 BoldFont := TFont.Create;
 try
   ATTR1 := TTextAttribute.Create(BoldFont,TAlphaColorRec.Blue); 
   ATTR2 := TTextAttribute.Create(ATTR1,TAlphaColorRec.Red);


   Layout.AddAttribute(TTextRange.Create(0,5), ATTR1);
   Layout.AddAttribute(TTextRange.Create(12,5), ATTR2);


 finally
   BoldFont.Free;  // for ARC platform, Free method does nothing. This code keeps single source for all platforms.
 end;
finally
 FreeAndNIL(Layout);
end;

See Also