Refactoring of TTF usage in ROOT - #23128
Open
linev wants to merge 21 commits into
Open
Conversation
linev
requested review from
bellenot,
couet,
dpiparo and
pcanal
as code owners
August 21, 2026 10:46
linev
marked this pull request as draft
August 21, 2026 10:46
TPadPainterBase
Test Results 21 files 21 suites 3d 5h 19m 20s ⏱️ Results for commit 43fc771. ♻️ This comment has been updated with latest results. |
linev
force-pushed
the
pp_drawtext
branch
2 times, most recently
from
August 21, 2026 13:52
ecac485 to
49cea23
Compare
linev
marked this pull request as ready for review
August 21, 2026 15:45
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
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
TPadPainterBaseTTF.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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
TVirtualXwhich just render TTF glyphs at specified position.And use these methods from
TPadPainterBaseclass.Provide implementation for
TGX11andTWin32, Mac will continue use own text rendering.Provide correspondent method in
TPadPainterBaseclass. 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 ofDrawText()and text metrics will be reused fromTPadPainterBaseclassImportant part of PR is full separation of old static
TTFclass from newTTFhandleclass. Now there isTTFhandle.hinclude which does not include anyFreetypetypes 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.hkept only for backward compatibility, can be removed at any time while no longer used in ROOT sources.