ROOT  6.06/09
Reference Guide
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 #ifndef ROOT_XLFDParser
23 #include "XLFDParser.h"
24 #endif
25 #ifndef ROOT_GuiTypes
26 #include "GuiTypes.h"
27 #endif
28 
29 //////////////////////////////////////////////////////////////////
30 // //
31 // FontCache class: //
32 // ROOT's GUI relies on TVirtualX to create and use fonts, //
33 // fonts are referenced by integer identifiers. //
34 // //
35 //////////////////////////////////////////////////////////////////
36 
37 namespace ROOT {
38 namespace MacOSX {
39 namespace Details {
40 
41 class FontCache {
42 public:
43  enum Details {
44  nPadFonts = 15
45  };
46 
47  FontCache();
48 
49  FontStruct_t LoadFont(const X11::XLFDName &xlfd);
50  void UnloadFont(FontStruct_t font);
51 
52  char **ListFonts(const X11::XLFDName &xlfd, int maxNames, int &count);
53  void FreeFontNames(char **fontList);
54 
55  unsigned GetTextWidth(FontStruct_t font, const char *text, int nChars);
56  void GetFontProperties(FontStruct_t font, int &maxAscent, int &maxDescent);
57 
58  //Select the existing font or create a new one and select it.
59  CTFontRef SelectFont(Font_t fontIndex, Float_t fontSize);
60 
61  //Typographical bounds (whatever it means),
62  //for the current selected font and text.
63  void GetTextBounds(UInt_t &w, UInt_t &h, const char *text)const;
64  void GetTextBounds(UInt_t &w, UInt_t &h, const std::vector<UniChar> & unichars)const;
65  //
66  double GetAscent()const;
67  double GetAscent(const char *text)const;
68  double GetAscent(const std::vector<UniChar> & unichars)const;
69  double GetDescent()const;
70  double GetDescent(const char *text)const;
71  double GetDescent(const std::vector<UniChar> & unichars)const;
72  double GetLeading()const;
73 
74 private:
75 
76  //We have "two symbolic" fonts, both of them use the same symbol.ttf (index 11),
77  //but the second one (index
78  CTFontRef SelectSymbolFont(Float_t fontSize, unsigned fontIndex);
79 
81 
82  //These are fonts for GUI. Weird map, as I can see now.
83  std::map<CTFontRef, CTFontGuard_t> fLoadedFonts;
84  typedef std::map<CTFontRef, CTFontGuard_t>::iterator font_iterator;
85  typedef std::map<CTFontRef, CTFontGuard_t>::const_iterator const_font_iterator;
86 
87  //Fonts for TPad's graphics.
88  typedef std::map<UInt_t, CTFontGuard_t> FontMap_t;
89  typedef FontMap_t::iterator font_map_iterator;
90  typedef FontMap_t::const_iterator const_font_map_iterator;
91 
92  FontMap_t fFonts[nPadFonts];
93  CTFontRef fSelectedFont;
94 
95  //FontList can be requested by TGCocoa::ListFonts,
96  //the return value is char **, and later it's freed by
97  //TGCocoa::FreeFontNames, again using char **.
98  //In my case, I have to somehow map char ** to two
99  //data sets - char ** itself + real strings, whose
100  //addresses are in char **.
101  //fList, after it's filled and returned by TGCocoa,
102  //is immutable, so later I can find this FontList
103  //comparing char ** and &fList[0].
104  struct FontList {
105  std::vector<char *> fList;
106  std::vector<char> fStringData;
107  };
108 
109  std::list<FontList> fFontLists;//list of "lists" of fonts :)
111 
112  typedef std::map<std::string, std::string> PSNameMap_t;
114 
115  FontCache(const FontCache &rhs);
116  FontCache &operator = (const FontCache &rhs);
117 
119 };
120 
121 }
122 }
123 }
124 
125 #endif
char ** ListFonts(const X11::XLFDName &xlfd, int maxNames, int &count)
Definition: FontCache.mm:298
Handle_t FontStruct_t
Definition: GuiTypes.h:40
Util::CFStrongReference< CTFontRef > CTFontGuard_t
Definition: FontCache.h:80
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
FontStruct_t LoadFont(const X11::XLFDName &xlfd)
Definition: FontCache.mm:243
FontMap_t fFonts[nPadFonts]
Definition: FontCache.h:92
float Float_t
Definition: RtypesCore.h:53
std::map< std::string, std::string > PSNameMap_t
Definition: FontCache.h:112
FontCache & operator=(const FontCache &rhs)
TH1 * h
Definition: legend2.C:5
std::map< CTFontRef, CTFontGuard_t > fLoadedFonts
Definition: FontCache.h:83
unsigned GetTextWidth(FontStruct_t font, const char *text, int nChars)
Definition: FontCache.mm:417
short Font_t
Definition: RtypesCore.h:75
std::map< CTFontRef, CTFontGuard_t >::const_iterator const_font_iterator
Definition: FontCache.h:85
std::map< CTFontRef, CTFontGuard_t >::iterator font_iterator
Definition: FontCache.h:84
FontMap_t::const_iterator const_font_map_iterator
Definition: FontCache.h:90
void GetTextBounds(UInt_t &w, UInt_t &h, const char *text) const
Definition: FontCache.mm:572
void FreeFontNames(char **fontList)
Definition: FontCache.mm:401
std::map< UInt_t, CTFontGuard_t > FontMap_t
Definition: FontCache.h:88
unsigned int UInt_t
Definition: RtypesCore.h:42
std::list< FontList > fFontLists
Definition: FontCache.h:109
FontMap_t::iterator font_map_iterator
Definition: FontCache.h:89
void GetFontProperties(FontStruct_t font, int &maxAscent, int &maxDescent)
Definition: FontCache.mm:447
TText * text
CTFontRef SelectFont(Font_t fontIndex, Float_t fontSize)
Definition: FontCache.mm:463
void UnloadFont(FontStruct_t font)
Definition: FontCache.mm:287
CTFontRef SelectSymbolFont(Float_t fontSize, unsigned fontIndex)
Definition: FontCache.mm:499