7
#ifndef my_font_factory
8
#define my_font_factory
10
//#include <glibmm/ustring.h>
19
#define USE_PANGO_WIN32
22
#include <pango/pango.h>
23
#include "nr-type-primitives.h"
24
#include "nr-type-pos-def.h"
25
#include "font-style-to-pos.h"
26
#include <libnrtype/nrtype-forward.h>
30
#ifdef USE_PANGO_WIN32
31
#include <pango/pangowin32.h>
33
#include <pango/pangoft2.h>
34
#include <freetype/freetype.h>
42
// the font_factory keeps a hashmap of all the loaded font_instances, and uses the PangoFontDescription
43
// as index (nota: since pango already does that, using the PangoFont could work too)
44
struct font_descr_hash : public std::unary_function<PangoFontDescription*,size_t> {
45
size_t operator()(PangoFontDescription *const &x) const;
47
struct font_descr_equal : public std::binary_function<PangoFontDescription*, PangoFontDescription*, bool> {
48
bool operator()(PangoFontDescription *const &a, PangoFontDescription *const &b) const;
51
// Comparison functions for style names
52
int style_name_compare(char const *aa, char const *bb);
53
int family_name_compare(char const *a, char const *b);
55
// Map type for gathering UI family and style strings
56
typedef std::map<Glib::ustring, std::list<Glib::ustring> > FamilyToStylesMap;
60
static font_factory *lUsine; /**< The default font_factory; i cannot think of why we would
63
* ("l'usine" is french for "the factory".)
66
/** A little cache for fonts, so that you don't loose your time looking up fonts in the font list
67
* each font in the cache is refcounted once (and deref'd when removed from the cache). */
72
int nbEnt; ///< Number of entries.
73
int maxEnt; ///< Cache size.
76
// Pango data. Backend-specific structures are cast to these opaque types.
77
PangoFontMap *fontServer;
78
PangoContext *fontContext;
79
#ifdef USE_PANGO_WIN32
80
PangoWin32FontCache *pangoFontCache;
83
double fontSize; /**< The huge fontsize used as workaround for hinting.
84
* Different between freetype and win32. */
87
virtual ~font_factory();
89
/// Returns the default font_factory.
90
static font_factory* Default();
92
/// Constructs a pango string for use with the fontStringMap (see below)
93
Glib::ustring ConstructFontSpecification(PangoFontDescription *font);
94
Glib::ustring ConstructFontSpecification(font_instance *font);
96
/// Returns strings to be used in the UI for family and face (or "style" as the column is labeled)
97
Glib::ustring GetUIFamilyString(PangoFontDescription const *fontDescr);
98
Glib::ustring GetUIStyleString(PangoFontDescription const *fontDescr);
100
/// Modifiers for the font specification (returns new font specification)
101
Glib::ustring ReplaceFontSpecificationFamily(const Glib::ustring & fontSpec, const Glib::ustring & newFamily);
102
Glib::ustring FontSpecificationSetItalic(const Glib::ustring & fontSpec, bool turnOn);
103
Glib::ustring FontSpecificationSetBold(const Glib::ustring & fontSpec, bool turnOn);
105
Glib::ustring FontSpecificationBestMatch(const Glib::ustring& fontSpec );
107
// Gathers all strings needed for UI while storing pango information in
108
// fontInstanceMap and fontStringMap
109
void GetUIFamiliesAndStyles(FamilyToStylesMap *map);
111
/// Retrieve a font_instance from a style object, first trying to use the font-specification, the CSS information
112
font_instance* FaceFromStyle(SPStyle const *style);
114
// Various functions to get a font_instance from different descriptions.
115
font_instance* FaceFromDescr(char const *family, char const *style);
116
font_instance* FaceFromUIStrings(char const *uiFamily, char const *uiStyle);
117
font_instance* FaceFromPangoString(char const *pangoString);
118
font_instance* FaceFromFontSpecification(char const *fontSpecification);
119
font_instance* Face(PangoFontDescription *descr, bool canFail=true);
120
font_instance* Face(char const *family,
121
int variant=PANGO_VARIANT_NORMAL, int style=PANGO_STYLE_NORMAL,
122
int weight=PANGO_WEIGHT_NORMAL, int stretch=PANGO_STRETCH_NORMAL,
123
int size=10, int spacing=0);
124
font_instance* Face(char const *family, NRTypePosDef apos);
126
/// Semi-private: tells the font_factory taht the font_instance 'who' has died and should be removed from loadedFaces
127
void UnrefFace(font_instance* who);
130
void AddInCache(font_instance *who);
135
// These two maps are used for translating between what's in the UI and a pango
136
// font description. This is necessary because Pango cannot always
137
// reproduce these structures from the names it gave us in the first place.
139
// Key: A string produced by font_factory::ConstructFontSpecification
140
// Value: The associated PangoFontDescription
141
typedef std::map<Glib::ustring, PangoFontDescription *> PangoStringToDescrMap;
142
PangoStringToDescrMap fontInstanceMap;
144
// Key: Family name in UI + Style name in UI
145
// Value: The associated string that should be produced with font_factory::ConstructFontSpecification
146
typedef std::map<Glib::ustring, Glib::ustring> UIStringToPangoStringMap;
147
UIStringToPangoStringMap fontStringMap;
151
#endif /* my_font_factory */
157
c-file-style:"stroustrup"
158
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
163
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :