Skip to content

Refactoring of TTF usage in ROOT - #23128

Open
linev wants to merge 21 commits into
root-project:masterfrom
linev:pp_drawtext
Open

Refactoring of TTF usage in ROOT#23128
linev wants to merge 21 commits into
root-project:masterfrom
linev:pp_drawtext

Conversation

@linev

@linev linev commented Aug 21, 2026

Copy link
Copy Markdown
Member

Handling of TrueType fonts implemented in different places.
This includes creation of glyphs, calculating of align parameters and finally rendering of produces images.
In fact, only last part is platform dependent - all preparation steps can be moved into one place.
This significantly simplifies text drawing on alternative platforms.

Therefore introduce special method in TVirtualX which just render TTF glyphs at specified position.
And use these methods from TPadPainterBase class.
Provide implementation for TGX11 and TWin32, Mac will continue use own text rendering.

Provide correspondent method in TPadPainterBase class. It invoked if usage of TrueType fonts enabled in the pad painter.

It is preparation for alternative graphics platforms like Qt6 or Gtk4. On these platforms TrueType font drawing will be used. And implementation will include just TPadPainterBase::DrawTTFglyphs() method - all variants of DrawText() and text metrics will be reused from TPadPainterBase class

Important part of PR is full separation of old static TTF class from new TTFhandle class. Now there is TTFhandle.h include which does not include any Freetype types forwarding and re-declarations. Thus usage of this class is much simpler and does require linking of Freetype library and does not need access to Freetype includes. TTF.h kept only for backward compatibility, can be removed at any time while no longer used in ROOT sources.

@linev linev self-assigned this Aug 21, 2026
@linev
linev marked this pull request as draft August 21, 2026 10:46
@linev linev changed the title Implement text drawing in TPadPainterBase Implement text drawing in TPadPainterBase Aug 21, 2026
@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

Test Results

    21 files      21 suites   3d 5h 19m 20s ⏱️
 3 836 tests  3 836 ✅ 0 💤 0 ❌
72 506 runs  72 506 ✅ 0 💤 0 ❌

Results for commit 43fc771.

♻️ This comment has been updated with latest results.

@linev
linev force-pushed the pp_drawtext branch 2 times, most recently from ecac485 to 49cea23 Compare August 21, 2026 13:52
@linev
linev marked this pull request as ready for review August 21, 2026 15:45
linev added 15 commits August 24, 2026 15:56
In `TPadPainterBase` class provides implementation of `DrawText` methods.
This implementation activated only when TTF supported and
new method DrawTTFglyphs is implemented.

While font metrics already calculated with TTF, now one can use drawing
based on TTF implementation.

Main aim is reduce number of methods which need to be implemented
in derived implementations. If backend support TTF - then just single
`DrawTTFglyphs` method need to be implemented for complete text rendering support.
Otherwise about 10 methods in TVirtualPadPainter need to be reimplemented.

Coordinates are always relative to current fPad
Now `TPadPainterBase` class has methods for text drawing and therefore
need to use `fPad` pointer to get dimensions of the pad. And as next also
use of gVirtualX methods can be activated
Provide API to directly draw TTF glyphs.
Idea to handle align, rotation, boundary checks in the
pad painter and only direct TTF drawing in TVirtualX
Use alligned text coordinates to check if output text will be visible
Just extract part of existing DrawTextW methods.
Invoke it from DrawTextW
Like in X11, move TTF handling in extra method
Text metrics with TTF already was implemented there,
now also text drawing via gVirtualX can be done already in TPadPainterBase

In case of TTF glyph drawing is implemented in the TPadPainter

In case of none-TTF gVirtualX used directly if window context is assigned
After TTF glyphs are produced one need to apply align and rotation shifts to text position.
This functionality requires usage of TrueType library,
therefore logically belongs to TTFhandle class which has access to this library.
So one can decouple TrueType from application code
In text drawing in the TPadPainterBase class use
new method for position calculation. Thus one gets normalized
position which can be used for further text drawings directly.

So one can remove linkage with `TrueType` library
It makes basic offset of coordinates for display of glyphs then
This enumeration was shared between TGX11 and TGX11TTF. Now it is not longer required for TTF rendering, therefore remove it from internal API
In many places direct operation with FT_BitmapGlyph are used.
This requires use of FreeType includes and libraries.
But one only uses several fields of produced bitmap.
Therefore provide special method which extract these fields
plus offset of glyph itself.

Also provide GetGlypsWidth and GetGlypsHeight methods
to avoid direct usage of TrueType box class.
Make implementation compact and independent from FreeType library
Also use GetGlypsWidth and GetGlypsHeight methods.
They only involved via libXft and included there.
Simplifies API between TTF and ASImage, remove dependency from Freetype library
linev added 2 commits August 25, 2026 13:17
Reuse common code now in MacOS
Skip Freetype library includes
Used for now only with wchar_t - typically in TMathText
Avoid direct usage of Freetype includes,
just common methods for align and bitmap manipulation
@linev linev changed the title Implement text drawing in TPadPainterBase Refactoring of TTF usage in ROOT Aug 25, 2026
linev added 4 commits August 25, 2026 17:07
TTF.h has special forward declaration for Freetype types,
which not really match to real implementation.

Therefore move TTFHandle from TTF.h and fully avoid
redefinition of Freetype types in header file.

Thus one can correctly use Freetype types and methods

Require immediate changes in TMathText and TPadPainterBase classes.
Like many other properties, set it when render string
Use true by default
To clearly see configuration and parsing methods
And then access to boundaries and produced bitmaps
In the ASImage and in TGQuartz

In none of the ROOT sources old static TTF interface is used now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant