FMX.TextLayout.TTextAttribute

De RAD Studio API Documentation
Aller à : navigation, rechercher

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() {}
};

Propriétés

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


Description

Contient les attributs de texte.

Font contient la fonte du texte. Color contient la couleur du texte.

TTextAttribute peut être créé de trois façons :

  • A partir d'une fonte et d'une couleur existantes
  • A partir d'un TTextAttribute existant avec une nouvelle couleur
  • A partir d'un TTextAttribute existant avec une nouvelle fonte


Remarque : Depuis RAD Studio 10.2 Seattle Release 3, la classe TTextLayout ne libère pas d'instance de TFont dans le premier constructeur. C'est le programme qui doit retirer l'instance de TFont.
Pour les plates-formes non ARC, y compris Windows et macOS, vous devez appeler la méthode Free manuellement lorsqu'une instance de fonte utilisant le premier paramètre de TTextAttribute.Create n'est plus utilisée.
Pour les plates-formes ARC, ARC retirera l'instance si elle n'est pas utilisée.

Voir l'exemple ci-dessous :

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;

Voir aussi