Code

Connector tool: make connectors avoid the convex hull of shapes.
[inkscape.git] / src / libnrtype / font-instance.h
1 #ifndef SEEN_LIBNRTYPE_FONT_INSTANCE_H
2 #define SEEN_LIBNRTYPE_FONT_INSTANCE_H
4 #include <ext/hash_map>
5 #include <map>
6 #include <pango/pango-types.h>
7 #include <pango/pango-font.h>
8 #include <require-config.h>
9 #include "FontFactory.h"
11 #include <libnr/nr-forward.h>
12 #include <libnrtype/nrtype-forward.h>
13 #include <libnrtype/font-style.h>
14 #include <livarot/livarot-forward.h>
15 #include "libnr/nr-rect.h"
16 #include <2geom/d2.h>
18 // the font_instance are the template of several raster_font; they provide metrics and outlines
19 // that are drawn by the raster_font, so the raster_font needs info relative to the way the 
20 // font need to be drawn. note that fontsize is a scale factor in the transform matrix
21 // of the style
22 // the various raster_font in use at a given time are held in a hash_map whose indices are the
23 // styles, hence the 2 following 'classes'
24 struct font_style_hash : public std::unary_function<font_style, size_t> {
25     size_t operator()(font_style const &x) const;
26 };
28 struct font_style_equal : public std::binary_function<font_style, font_style, bool> {
29     bool operator()(font_style const &a, font_style const &b);
30 };
32 class font_instance {
33 public:
34         // hashmap to get the raster_font for a given style
35     __gnu_cxx::hash_map<font_style, raster_font*, font_style_hash, font_style_equal>     loadedStyles;
36         // the real source of the font
37     PangoFont*            pFont;
38                 // depending on the rendering backend, different temporary data
40                 // that's the font's fingerprint; this particular PangoFontDescription gives the entry at which this font_instance
41                 // resides in the font_factory loadedFaces hash_map
42     PangoFontDescription* descr;
43                 // refcount
44     int                   refCount;
45                 // font_factory owning this font_instance
46     font_factory*         daddy;
48     // common glyph definitions for all the rasterfonts
49     std::map<int, int>    id_to_no;
50     int                   nbGlyph, maxGlyph;
51     font_glyph*           glyphs;
53     font_instance(void);
54     virtual ~font_instance(void);
56     void                 Ref(void);
57     void                 Unref(void);
59     bool                 IsOutlineFont(void); // utility
60     void                 InstallFace(PangoFont* iFace); // utility; should reset the pFont field if loading failed
61                                         // in case the PangoFont is a bitmap font, for example. that way, the calling function 
62                                         // will be able to check the validity of the font before installing it in loadedFaces
63     void                 InitTheFace();
65     int                  MapUnicodeChar(gunichar c); // calls the relevant unicode->glyph index function
66     void                 LoadGlyph(int glyph_id);    // the main backend-dependent function
67                                         // loads the given glyph's info
68                 
69                 // nota: all coordinates returned by these functions are on a [0..1] scale; you need to multiply 
70                 // by the fontsize to get the real sizes
71     Path*                Outline(int glyph_id, Path *copyInto=NULL);
72                                         // queries the outline of the glyph (in livarot Path form), and copies it into copyInto instead
73                                         // of allocating a new Path if copyInto != NULL
74     Geom::PathVector*    PathVector(int glyph_id);
75                          // returns the 2geom-type pathvector for this glyph. no refcounting needed, it's deallocated when the font_instance dies
76     double               Advance(int glyph_id, bool vertical);
77                                         // nominal advance of the font.
78     bool                 FontMetrics(double &ascent, double &descent, double &leading);
79     bool                 FontSlope(double &run, double &rise);
80                                 // for generating slanted cursors for oblique fonts
81     Geom::OptRect             BBox(int glyph_id);
83                 // creates a rasterfont for the given style
84     raster_font*         RasterFont(Geom::Matrix const &trs, double stroke_width,
85                                     bool vertical = false, JoinType stroke_join = join_straight,
86                                     ButtType stroke_cap = butt_straight, float miter_limit = 4.0);
87                 // the dashes array in iStyle is copied
88     raster_font*         RasterFont(font_style const &iStyle);
89                 // private use: tells the font_instance that the raster_font 'who' has died
90     void                 RemoveRasterFont(raster_font *who);
92                 // attribute queries
93     unsigned             Name(gchar *str, unsigned size);
94     unsigned             PSName(gchar *str, unsigned size);
95     unsigned             Family(gchar *str, unsigned size);
96     unsigned             Attribute(gchar const *key, gchar *str, unsigned size);
98 private:
99     void                 FreeTheFace();
101 #ifdef USE_PANGO_WIN32
102     HFONT                 theFace;
103 #else
104     FT_Face               theFace; 
105                 // it's a pointer in fact; no worries to ref/unref it, pango does its magic
106                 // as long as pFont is valid, theFace is too
107 #endif
109 };
112 #endif /* !SEEN_LIBNRTYPE_FONT_INSTANCE_H */
114 /*
115   Local Variables:
116   mode:c++
117   c-file-style:"stroustrup"
118   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
119   indent-tabs-mode:nil
120   fill-column:99
121   End:
122 */
123 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :