{ "cells": [ { "cell_type": "markdown", "id": "b60b3a1c", "metadata": {}, "source": [ "# fonts_ttf\n", "Usage of TTF fonts in web canvas.\n", "\n", "One can load TTF font file and specify it for usage in the web canvas\n", "Produced drawing also can be saved in PDF files.\n", "\n", "Functionality available only in web-based graphics\n", "\n", "\n", "\n", "\n", "**Author:** Sergey Linev \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:38 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "f8c30c36", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:53.543157Z", "iopub.status.busy": "2026-05-19T20:38:53.543047Z", "iopub.status.idle": "2026-05-19T20:38:54.012661Z", "shell.execute_reply": "2026-05-19T20:38:54.012031Z" } }, "outputs": [], "source": [ "TString fontdir = TROOT::GetDataDir() + \"/fonts/\";\n", "\n", "auto fontid = TWebCanvas::AddFont(\"UserBold\", fontdir + \"trebuc.ttf\");\n", "auto fontid_bold = TWebCanvas::AddFont(\"UserBold\", fontdir + \"trebucbd.ttf\");\n", "auto fontid_bold_italic = TWebCanvas::AddFont(\"UserBoldItalic\", fontdir + \"trebucbi.ttf\");\n", "auto fontid_italic = TWebCanvas::AddFont(\"UserItalic\", fontdir + \"trebucit.ttf\");\n", "\n", "if ((fontid < 0) || (fontid_bold < 0) || (fontid_bold_italic < 0) || (fontid_italic < 0))\n", " ::Error(\"fonts_ttf.cxx\", \"fail to load ttf fonts from %s\", fontdir.Data());\n", "\n", "auto c1 = new TCanvas(\"c1\", \"c1\", 1000, 600);\n", "\n", "if (!gROOT->IsBatch() && !c1->IsWeb())\n", " ::Warning(\"fonts_ttf.cxx\", \"macro will not work without enabling web-based canvas\");\n", "\n", "auto l1 = new TLatex(0.5, 0.8, \"Custom font from trebuc.ttf\");\n", "l1->SetTextFont(fontid);\n", "l1->SetTextAlign(22);\n", "l1->SetTextSize(0.1);\n", "c1->Add(l1);\n", "\n", "auto l2 = new TLatex(0.5, 0.6, \"Custom bold font from trebucbd.ttf\");\n", "l2->SetTextFont(fontid_bold);\n", "l2->SetTextAlign(22);\n", "l2->SetTextSize(0.1);\n", "c1->Add(l2);\n", "\n", "auto l3 = new TLatex(0.5, 0.4, \"Custom bold italic font from trebucbi.ttf\");\n", "l3->SetTextFont(fontid_bold_italic);\n", "l3->SetTextAlign(22);\n", "l3->SetTextSize(0.1);\n", "c1->Add(l3);\n", "\n", "auto l4 = new TLatex(0.5, 0.2, \"Custom italic font from trebucit.ttf\");\n", "l4->SetTextFont(fontid_italic);\n", "l4->SetTextAlign(22);\n", "l4->SetTextSize(0.1);\n", "c1->Add(l4);" ] }, { "cell_type": "markdown", "id": "c132e195", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 2, "id": "63f29852", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:54.014803Z", "iopub.status.busy": "2026-05-19T20:38:54.014669Z", "iopub.status.idle": "2026-05-19T20:38:54.251276Z", "shell.execute_reply": "2026-05-19T20:38:54.250623Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%jsroot on\n", "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }