Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FontCache.h
Go to the documentation of this file.
1// @(#)root/graf2d:$Id$
2// Author: Timur Pocheptsov 19/03/2012
3
4/*************************************************************************
5 * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_FontCache
13#define ROOT_FontCache
14
15#include <string>
16#include <vector>
17#include <list>
18#include <map>
19
20#include <ApplicationServices/ApplicationServices.h>
21
22#include "XLFDParser.h"
23#include "GuiTypes.h"
24
25#include "CocoaUtils.h"
26
27//////////////////////////////////////////////////////////////////
28// //
29// FontCache class: //
30// ROOT's GUI relies on TVirtualX to create and use fonts, //
31// fonts are referenced by integer identifiers. //
32// //
33//////////////////////////////////////////////////////////////////
34
35namespace ROOT {
36namespace MacOSX {
37namespace Details {
38
39class FontCache {
40public:
41 enum Details {
42 nPadFonts = 15
43 };
44
45 FontCache();
46
48 void UnloadFont(FontStruct_t font);
49
50 char **ListFonts(const X11::XLFDName &xlfd, int maxNames, int &count);
51 void FreeFontNames(char **fontList);
52
53 unsigned GetTextWidth(FontStruct_t font, const char *text, int nChars);
54 void GetFontProperties(FontStruct_t font, int &maxAscent, int &maxDescent);
55
56 //Select the existing font or create a new one and select it.
57 CTFontRef SelectFont(Font_t fontIndex, Float_t fontSize);
58
59 //Typographical bounds (whatever it means),
60 //for the current selected font and text.
61 void GetTextBounds(UInt_t &w, UInt_t &h, const char *text)const;
62 void GetTextBounds(UInt_t &w, UInt_t &h, const std::vector<UniChar> & unichars)const;
63 //
64 double GetAscent()const;
65 double GetAscent(const char *text)const;
66 double GetAscent(const std::vector<UniChar> & unichars)const;
67 double GetDescent()const;
68 double GetDescent(const char *text)const;
69 double GetDescent(const std::vector<UniChar> & unichars)const;
70 double GetLeading()const;
71
72private:
73
74 //We have "two symbolic" fonts, both of them use the same symbol.ttf (index 11),
75 //but the second one (index
76 CTFontRef SelectSymbolFont(Float_t fontSize, unsigned fontIndex);
77
79
80 //These are fonts for GUI. Weird map, as I can see now.
81 std::map<CTFontRef, CTFontGuard_t> fLoadedFonts;
82 typedef std::map<CTFontRef, CTFontGuard_t>::iterator font_iterator;
83 typedef std::map<CTFontRef, CTFontGuard_t>::const_iterator const_font_iterator;
84
85 //Fonts for TPad's graphics.
86 typedef std::map<UInt_t, CTFontGuard_t> FontMap_t;
87 typedef FontMap_t::iterator font_map_iterator;
88 typedef FontMap_t::const_iterator const_font_map_iterator;
89
91 CTFontRef fSelectedFont;
92
93 //FontList can be requested by TGCocoa::ListFonts,
94 //the return value is char **, and later it's freed by
95 //TGCocoa::FreeFontNames, again using char **.
96 //In my case, I have to somehow map char ** to two
97 //data sets - char ** itself + real strings, whose
98 //addresses are in char **.
99 //fList, after it's filled and returned by TGCocoa,
100 //is immutable, so later I can find this FontList
101 //comparing char ** and &fList[0].
102 struct FontList {
103 std::vector<char *> fList;
104 std::vector<char> fStringData;
105 };
106
107 std::list<FontList> fFontLists;//list of "lists" of fonts :)
109
110 typedef std::map<std::string, std::string> PSNameMap_t;
112
113 FontCache(const FontCache &rhs);
115
117};
118
119}
120}
121}
122
123#endif
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
#define h(i)
Definition RSha256.hxx:106
float Float_t
Definition RtypesCore.h:57
short Font_t
Definition RtypesCore.h:81
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char ListFonts
Option_t Option_t TPoint TPoint const char text
void FreeFontNames(char **fontList)
Definition FontCache.mm:402
std::map< UInt_t, CTFontGuard_t > FontMap_t
Definition FontCache.h:86
void GetFontProperties(FontStruct_t font, int &maxAscent, int &maxDescent)
Definition FontCache.mm:451
std::map< CTFontRef, CTFontGuard_t >::iterator font_iterator
Definition FontCache.h:82
FontCache & operator=(const FontCache &rhs)
FontCache(const FontCache &rhs)
unsigned GetTextWidth(FontStruct_t font, const char *text, int nChars)
Definition FontCache.mm:418
CTFontRef SelectSymbolFont(Float_t fontSize, unsigned fontIndex)
Definition FontCache.mm:503
FontMap_t::const_iterator const_font_map_iterator
Definition FontCache.h:88
std::map< CTFontRef, CTFontGuard_t >::const_iterator const_font_iterator
Definition FontCache.h:83
Util::CFStrongReference< CTFontRef > CTFontGuard_t
Definition FontCache.h:78
std::list< FontList > fFontLists
Definition FontCache.h:107
void GetTextBounds(UInt_t &w, UInt_t &h, const char *text) const
Definition FontCache.mm:576
std::map< std::string, std::string > PSNameMap_t
Definition FontCache.h:110
std::map< CTFontRef, CTFontGuard_t > fLoadedFonts
Definition FontCache.h:81
FontStruct_t LoadFont(const X11::XLFDName &xlfd)
Definition FontCache.mm:244
void UnloadFont(FontStruct_t font)
Definition FontCache.mm:288
CTFontRef SelectFont(Font_t fontIndex, Float_t fontSize)
Definition FontCache.mm:467
FontMap_t::iterator font_map_iterator
Definition FontCache.h:87
FontMap_t fFonts[nPadFonts]
Definition FontCache.h:90
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...