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);
55
56 //Select the existing font or create a new one and select it.
58
59private:
60
61 //We have "two symbolic" fonts, both of them use the same symbol.ttf (index 11),
62 //but the second one (index
63 CTFontRef SelectSymbolFont(Float_t fontSize, unsigned fontIndex);
64
66
67 //These are fonts for GUI. Weird map, as I can see now.
68 std::map<CTFontRef, CTFontGuard_t> fLoadedFonts;
69 typedef std::map<CTFontRef, CTFontGuard_t>::iterator font_iterator;
70 typedef std::map<CTFontRef, CTFontGuard_t>::const_iterator const_font_iterator;
71
72 //Fonts for TPad's graphics.
73 typedef std::map<UInt_t, CTFontGuard_t> FontMap_t;
74 typedef FontMap_t::iterator font_map_iterator;
75 typedef FontMap_t::const_iterator const_font_map_iterator;
76
78 CTFontRef fSelectedFont;
79
80 //FontList can be requested by TGCocoa::ListFonts,
81 //the return value is char **, and later it's freed by
82 //TGCocoa::FreeFontNames, again using char **.
83 //In my case, I have to somehow map char ** to two
84 //data sets - char ** itself + real strings, whose
85 //addresses are in char **.
86 //fList, after it's filled and returned by TGCocoa,
87 //is immutable, so later I can find this FontList
88 //comparing char ** and &fList[0].
89 struct FontList {
90 std::vector<char *> fList;
91 std::vector<char> fStringData;
92 };
93
94 std::list<FontList> fFontLists;//list of "lists" of fonts :)
96
97 typedef std::map<std::string, std::string> PSNameMap_t;
99
102
104};
105
106}
107}
108}
109
110#endif
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:40
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
short Font_t
Font number (short)
Definition RtypesCore.h:96
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:366
std::map< UInt_t, CTFontGuard_t > FontMap_t
Definition FontCache.h:73
void GetFontProperties(FontStruct_t font, int &maxAscent, int &maxDescent)
Definition FontCache.mm:415
std::map< CTFontRef, CTFontGuard_t >::iterator font_iterator
Definition FontCache.h:69
FontCache & operator=(const FontCache &rhs)
FontCache(const FontCache &rhs)
unsigned GetTextWidth(FontStruct_t font, const char *text, int nChars)
Definition FontCache.mm:382
CTFontRef SelectSymbolFont(Float_t fontSize, unsigned fontIndex)
Definition FontCache.mm:467
FontMap_t::const_iterator const_font_map_iterator
Definition FontCache.h:75
std::map< CTFontRef, CTFontGuard_t >::const_iterator const_font_iterator
Definition FontCache.h:70
Util::CFStrongReference< CTFontRef > CTFontGuard_t
Definition FontCache.h:65
std::list< FontList > fFontLists
Definition FontCache.h:94
std::map< std::string, std::string > PSNameMap_t
Definition FontCache.h:97
std::map< CTFontRef, CTFontGuard_t > fLoadedFonts
Definition FontCache.h:68
FontStruct_t LoadFont(const X11::XLFDName &xlfd)
Definition FontCache.mm:221
void UnloadFont(FontStruct_t font)
Definition FontCache.mm:265
CTFontRef SelectFont(Font_t fontIndex, Float_t fontSize)
Definition FontCache.mm:431
FontMap_t::iterator font_map_iterator
Definition FontCache.h:74
FontMap_t fFonts[nPadFonts]
Definition FontCache.h:77