Logo ROOT  
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 #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 
35 namespace ROOT {
36 namespace MacOSX {
37 namespace Details {
38 
39 class FontCache {
40 public:
41  enum Details {
42  nPadFonts = 15
43  };
44 
45  FontCache();
46 
47  FontStruct_t LoadFont(const X11::XLFDName &xlfd);
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 
72 private:
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
ROOT::MacOSX::Details::FontCache::GetAscent
double GetAscent() const
Definition: FontCache.mm:619
ROOT::MacOSX::Details::FontCache::const_font_iterator
std::map< CTFontRef, CTFontGuard_t >::const_iterator const_font_iterator
Definition: FontCache.h:107
CocoaUtils.h
ROOT::MacOSX::Details::FontCache::FontCache
FontCache()
Definition: FontCache.mm:252
ROOT::MacOSX::Details::FontCache::GetDescent
double GetDescent() const
Definition: FontCache.mm:657
ROOT::MacOSX::Details::FontCache::const_font_map_iterator
FontMap_t::const_iterator const_font_map_iterator
Definition: FontCache.h:112
FontStruct_t
Handle_t FontStruct_t
Definition: GuiTypes.h:38
ROOT::MacOSX::Details::FontCache::LoadFont
FontStruct_t LoadFont(const X11::XLFDName &xlfd)
Definition: FontCache.mm:262
Float_t
float Float_t
Definition: RtypesCore.h:57
ROOT::MacOSX::Details::FontCache::CTFontGuard_t
Util::CFStrongReference< CTFontRef > CTFontGuard_t
Definition: FontCache.h:102
ROOT::MacOSX::Details::FontCache::fSymbolFontRegistered
bool fSymbolFontRegistered
Definition: FontCache.h:140
Font_t
short Font_t
Definition: RtypesCore.h:79
ROOT::MacOSX::X11::XLFDName
Definition: XLFDParser.h:57
ROOT::MacOSX::Details::FontCache::SelectSymbolFont
CTFontRef SelectSymbolFont(Float_t fontSize, unsigned fontIndex)
Definition: FontCache.mm:518
XLFDParser.h
ROOT::MacOSX::Details::FontCache
Definition: FontCache.h:57
ROOT::MacOSX::Details::FontCache::FontList
Definition: FontCache.h:126
ROOT::MacOSX::Details::FontCache::fDummyList
FontList fDummyList
Definition: FontCache.h:132
text
TText * text
Definition: entrylist_figure1.C:10
ROOT::MacOSX::Details::FontCache::fXLFDtoPostscriptNames
PSNameMap_t fXLFDtoPostscriptNames
Definition: FontCache.h:135
ROOT::MacOSX::Details::FontCache::FreeFontNames
void FreeFontNames(char **fontList)
Definition: FontCache.mm:420
ROOT::MacOSX::Details::FontCache::fFonts
FontMap_t fFonts[nPadFonts]
Definition: FontCache.h:114
ROOT::MacOSX::Details::FontCache::font_iterator
std::map< CTFontRef, CTFontGuard_t >::iterator font_iterator
Definition: FontCache.h:106
h
#define h(i)
Definition: RSha256.hxx:124
GuiTypes.h
ROOT::MacOSX::Details::FontCache::UnloadFont
void UnloadFont(FontStruct_t font)
Definition: FontCache.mm:306
ROOT::MacOSX::Details::FontCache::nPadFonts
@ nPadFonts
Definition: FontCache.h:72
ROOT::MacOSX::Details::FontCache::GetTextBounds
void GetTextBounds(UInt_t &w, UInt_t &h, const char *text) const
Definition: FontCache.mm:591
ROOT::MacOSX::Details::FontCache::GetFontProperties
void GetFontProperties(FontStruct_t font, int &maxAscent, int &maxDescent)
Definition: FontCache.mm:466
ROOT::MacOSX::Details::FontCache::GetLeading
double GetLeading() const
Definition: FontCache.mm:695
unsigned int
ROOT::MacOSX::Details::FontCache::fSelectedFont
CTFontRef fSelectedFont
Definition: FontCache.h:115
ROOT::MacOSX::Details
Definition: TMacOSXSystem.h:42
ROOT::MacOSX::Util::CFStrongReference
Definition: CocoaUtils.h:211
ROOT::MacOSX::Details::FontCache::operator=
FontCache & operator=(const FontCache &rhs)
ROOT::MacOSX::Details::FontCache::ListFonts
char ** ListFonts(const X11::XLFDName &xlfd, int maxNames, int &count)
Definition: FontCache.mm:317
ROOT::MacOSX::Details::FontCache::PSNameMap_t
std::map< std::string, std::string > PSNameMap_t
Definition: FontCache.h:134
ROOT::MacOSX::Details::FontCache::GetTextWidth
unsigned GetTextWidth(FontStruct_t font, const char *text, int nChars)
Definition: FontCache.mm:436
ROOT::MacOSX::Details::FontCache::font_map_iterator
FontMap_t::iterator font_map_iterator
Definition: FontCache.h:111
ROOT::MacOSX::Details::FontCache::FontMap_t
std::map< UInt_t, CTFontGuard_t > FontMap_t
Definition: FontCache.h:110
ROOT::MacOSX::Details::FontCache::FontList::fList
std::vector< char * > fList
Definition: FontCache.h:127
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::MacOSX::Details::FontCache::FontList::fStringData
std::vector< char > fStringData
Definition: FontCache.h:128
ROOT::MacOSX::Details::FontCache::SelectFont
CTFontRef SelectFont(Font_t fontIndex, Float_t fontSize)
Definition: FontCache.mm:482
ROOT::MacOSX::Details::FontCache::fLoadedFonts
std::map< CTFontRef, CTFontGuard_t > fLoadedFonts
Definition: FontCache.h:105
ROOT::MacOSX::Details::FontCache::fFontLists
std::list< FontList > fFontLists
Definition: FontCache.h:131