Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rtext_font.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This macro demonstrate usage of existing ROOT fonts for RText.
5/// Also load of custom font is shown
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2021-07-07
11/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
12/// is welcome!
13/// \author Sergey Linev <s.linev@gsi.de>
14
15/*************************************************************************
16 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
17 * All rights reserved. *
18 * *
19 * For the licensing terms see $ROOTSYS/LICENSE. *
20 * For the list of contributors see $ROOTSYS/README/CREDITS. *
21 *************************************************************************/
22
23#include "ROOT/RCanvas.hxx"
24#include "ROOT/RText.hxx"
25#include "ROOT/RPadPos.hxx"
26
27using namespace ROOT::Experimental;
28
29void rtext_font()
30{
31 auto canvas = RCanvas::Create("RText fonts example");
32
33 double posy = 0.93;
34
35 auto drawText = [&canvas, &posy](RAttrFont::EFont font, bool is_comic = false) {
36 auto text = canvas->Add<RText>(RPadPos(0.35, posy), "ABCDEFGH abcdefgh 0123456789 @#$");
37 text->text.size = 0.04;
38 text->text.align = RAttrText::kLeftCenter;
39 if (is_comic)
40 text->text.font.family = "Comic";
41 else
42 text->text.font = font;
43
44 auto name = canvas->Add<RText>(RPadPos(0.33, posy), text->text.font.GetFullName());
45 name->text.size = 0.03;
46 name->text.align = RAttrText::kRightCenter;
47
48 posy -= 0.05;
49 };
50
51 drawText(RAttrFont::kTimes);
52 drawText(RAttrFont::kTimesItalic);
53 drawText(RAttrFont::kTimesBold);
54 drawText(RAttrFont::kTimesBoldItalic);
55
56 drawText(RAttrFont::kArial);
57 drawText(RAttrFont::kArialOblique);
58 drawText(RAttrFont::kArialBold);
59 drawText(RAttrFont::kArialBoldOblique);
60
61 drawText(RAttrFont::kCourier);
62 drawText(RAttrFont::kCourierOblique);
63 drawText(RAttrFont::kCourierBold);
64 drawText(RAttrFont::kCourierBoldOblique);
65
66 drawText(RAttrFont::kVerdana);
67 drawText(RAttrFont::kVerdanaItalic);
68 drawText(RAttrFont::kVerdanaBold);
69 drawText(RAttrFont::kVerdanaBoldItalic);
70
71 // now draw text with custom font
72
73 posy -= 0.03;
74 std::string fname = __FILE__;
75 auto pos = fname.find("rtext_font.cxx");
76 if (pos > 0) { fname.resize(pos); fname.append("comic.woff2"); }
77 else fname = "comic.woff2";
78 canvas->Draw<RFont>("Comic", fname);
79 drawText(RAttrFont::kTimes, true);
80
81 canvas->Show();
82}
char name[80]
Definition TGX11.cxx:110
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28
TText * text