Code

Fix compile error.
[inkscape.git] / src / libnrtype / FontFactory.h
1 /*
2  *  FontFactory.h
3  *  testICU
4  *
5  */
7 #ifndef my_font_factory
8 #define my_font_factory
10 #include <functional>
11 #include <algorithm>
12 #include <ext/hash_map>
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
17 #ifdef _WIN32
18 #define USE_PANGO_WIN32
19 #endif
21 #include <pango/pango.h>
22 #include "nr-type-primitives.h"
23 #include "nr-type-pos-def.h"
24 #include <libnrtype/nrtype-forward.h>
26 /* Freetype */
27 #ifdef USE_PANGO_WIN32
28 #include <pango/pangowin32.h>
29 #else
30 #include <pango/pangoft2.h>
31 #include <freetype/freetype.h>
32 #endif
34 // the font_factory keeps a hashmap of all the loaded font_instances, and uses the PangoFontDescription
35 // as index (nota: since pango already does that, using the PangoFont could work too)
36 struct font_descr_hash : public std::unary_function<PangoFontDescription*,size_t> {
37     size_t operator()(PangoFontDescription *const &x) const;
38 };
39 struct font_descr_equal : public std::binary_function<PangoFontDescription*, PangoFontDescription*, bool> {
40     bool operator()(PangoFontDescription *const &a, PangoFontDescription *const &b);
41 };
43 class font_factory {
44 public:
45     static font_factory *lUsine; /**< The default font_factory; i cannot think of why we would
46                                   *   need more than one.
47                                   *
48                                   *   ("l'usine" is french for "the factory".)
49                                   */
51     /** A little cache for fonts, so that you don't loose your time looking up fonts in the font list
52      *  each font in the cache is refcounted once (and deref'd when removed from the cache). */
53     struct font_entry {
54         font_instance *f;
55         double age;
56     };
57     int nbEnt;   ///< Number of entries.
58     int maxEnt;  ///< Cache size.
59     font_entry *ents;
61     // Pango data.  Backend-specific structures are cast to these opaque types.
62     PangoFontMap *fontServer;
63     PangoContext *fontContext;
64 #ifdef USE_PANGO_WIN32
65     PangoWin32FontCache *pangoFontCache;
66     HDC hScreenDC;
67 #endif
68     double fontSize; /**< The huge fontsize used as workaround for hinting.
69                       *   Different between freetype and win32. */
71     __gnu_cxx::hash_map<PangoFontDescription*, font_instance*, font_descr_hash, font_descr_equal> loadedFaces;
73     font_factory();
74     ~font_factory();
76     /// Returns the default font_factory.
77     static font_factory*  Default();
79     // Various functions to get a font_instance from different descriptions.
80     font_instance*        FaceFromDescr(char const *family, char const *style);
81     font_instance*        Face(PangoFontDescription *descr, bool canFail=true);
82     font_instance*        Face(char const *family,
83                                int variant=PANGO_VARIANT_NORMAL, int style=PANGO_STYLE_NORMAL,
84                                int weight=PANGO_WEIGHT_NORMAL, int stretch=PANGO_STRETCH_NORMAL,
85                                int size=10, int spacing=0);
86     font_instance*        Face(char const *family, NRTypePosDef apos);
88     /// Semi-private: tells the font_factory taht the font_instance 'who' has died and should be removed from loadedFaces
89     void                  UnrefFace(font_instance* who);
91     // Queries for the font-selector.
92     NRNameList*           Families(NRNameList *flist);
93     NRStyleList*           Styles(const gchar *family, NRStyleList *slist);
95     // internal
96     void                  AddInCache(font_instance *who);
97 };
100 #endif /* my_font_factory */
103 /*
104   Local Variables:
105   mode:c++
106   c-file-style:"stroustrup"
107   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
108   indent-tabs-mode:nil
109   fill-column:99
110   End:
111 */
112 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :