Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
rtext_font.cxx File Reference

Detailed Description

This macro demonstrate usage of existing ROOT fonts for RText.

Also load of custom font is shown

/*************************************************************************
* Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "ROOT/RCanvas.hxx"
#include "ROOT/RText.hxx"
#include "ROOT/RPadPos.hxx"
using namespace ROOT::Experimental;
void rtext_font()
{
auto canvas = RCanvas::Create("RText fonts example");
double posy = 0.93;
auto drawText = [&canvas, &posy](RAttrFont::EFont font, bool is_comic = false) {
auto text = canvas->Add<RText>(RPadPos(0.35, posy), "ABCDEFGH abcdefgh 0123456789 @#$");
text->text.size = 0.04;
if (is_comic)
text->text.font.family = "Comic";
else
text->text.font = font;
auto name = canvas->Add<RText>(RPadPos(0.33, posy), text->text.font.GetFullName());
name->text.size = 0.03;
posy -= 0.05;
};
drawText(RAttrFont::kTimes);
drawText(RAttrFont::kArial);
// now draw text with custom font
posy -= 0.03;
std::string fname = __FILE__;
auto pos = fname.find("rtext_font.cxx");
if (pos > 0) {
fname.resize(pos);
fname.append("comic.woff2");
} else
fname = "comic.woff2";
canvas->Draw<RFont>("Comic", fname);
drawText(RAttrFont::kTimes, true);
canvas->Show();
}
char name[80]
Definition TGX11.cxx:148
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition RCanvas.cxx:89
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28
TText * text
Namespace for ROOT features in testing.
Definition TROOT.h:100
Date
2021-07-07
Warning
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Author
Sergey Linev s.lin.nosp@m.ev@g.nosp@m.si.de

Definition in file rtext_font.cxx.