Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
DelphiRAD Studio

Learn To Add Custom Text Rendering And Formatting Capabilities To Your Delphi FMX Controls Quickly

Most applications demand high-quality text rendering, resolution-independent outline fonts, and full Unicode text and layout support. Looking for a device-independent text layout system that improves text readability in documents and in UI for Your Delphi/C++ applications? How to build such Text Rendering Capabilities to your FireMonkey controls? This post will guide you. (e.g) Let’s see how to enhance the TLabel control with Rendering and formatting capabilities for the Text in HTML Tags.

How to create:
1. Create a descendant of TLabel that supports a limited selection of HTML tags. Parse the label for HTML tags every time the text changes.
2. Override its Dochanged method to parse the text for HTML tags
3. Use Firemonkey’s TTextLayout class to apply formatting attributes to parts of the text.
Note: No need to use HTML for formatting instead we can use TTextlayout.

  • TTextLayout is an abstract class that provides mechanisms to render text quickly. Such rendering systems are supported by DirectWrite API (Windows) and Core Text framework (OS X). Also used to calculate glyph positions, measure text, draw text, and covert to curves for path effects and 3D extrusion.
  • To create this class, use TTextLayoutManager – In charge of choosing the appropriate layout class type for the current running platform.
  • Use AddAttribute to assign text block properties like TTextRange (starting position and length) and TTextAttribute (font and color).
  • When changing several properties of the layout, you should use the BeginUpdate and EndUpdate procedures.
  • Use RenderLayout to render the text on a canvas.
  • The PositionAtPoint method returns the position in the text by the position’s coordinates.
  • The RegionForRange method returns the array of the rectangles surrounding the range of the text specified in ARange.
  • Another feature is the ability to convert text to a TPathData object by calling the ConvertToPath procedure.

Check out the full Video of creating a Simple FMX HTML control below.

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES