Code

sodipodi:docbase finally goes packing, along with a lauris comment
[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"
17 // the font_instance are the template of several raster_font; they provide metrics and outlines
18 // that are drawn by the raster_font, so the raster_font needs info relative to the way the 
19 // font need to be drawn. note that fontsize is a scale factor in the transform matrix
20 // of the style
21 // the various raster_font in use at a given time are held in a hash_map whose indices are the
22 // styles, hence the 2 following 'classes'
23 struct font_style_hash : public std::unary_function<font_style, size_t> {
24     size_t operator()(font_style const &x) const;
25 };
27 struct font_style_equal : public std::binary_function<font_style, font_style, bool> {
28     bool operator()(font_style const &a, font_style const &b);
29 };
31 class font_instance {
32 public:
33         // hashmap to get the raster_font for a given style
34     __gnu_cxx::hash_map<font_style, raster_font*, font_style_hash, font_style_equal>     loadedStyles;
35         // the real source of the font
36     PangoFont*            pFont;
37                 // depending on the rendering backend, different temporary data
39                 // that's the font's fingerprint; this particular PangoFontDescription gives the entry at which this font_instance
40                 // resides in the font_factory loadedFaces hash_map
41     PangoFontDescription* descr;
42                 // refcount
43     int                   refCount;
44                 // font_factory owning this font_instance
45     font_factory*         daddy;
47     // common glyph definitions for all the rasterfonts
48     std::map<int, int>    id_to_no;
49     int                   nbGlyph, maxGlyph;
50     font_glyph*           glyphs;
52     font_instance(void);
53     ~font_instance(void);
55     void                 Ref(void);
56     void                 Unref(void);
58     bool                 IsOutlineFont(void); // utility
59     void                 InstallFace(PangoFont* iFace); // utility; should reset the pFont field if loading failed
60                                         // in case the PangoFont is a bitmap font, for example. that way, the calling function 
61                                         // will be able to check the validity of the font before installing it in loadedFaces
62     void                 InitTheFace();
64     int                  MapUnicodeChar(gunichar c); // calls the relevant unicode->glyph index function
65     void                 LoadGlyph(int glyph_id);    // the main backend-dependent function
66                                         // loads the given glyph's info
67                 
68                 // nota: all coordinates returned by these functions are on a [0..1] scale; you need to multiply 
69                 // by the fontsize to get the real sizes
70     Path*                Outline(int glyph_id, Path *copyInto=NULL);
71                                         // queries the outline of the glyph (in livarot Path form), and copies it into copyInto instead
72                                         // of allocating a new Path if copyInto != NULL
73     void*                ArtBPath(int glyph_id);
74                                         // returns the artbpath for this glyph. no refcounting needed, it's deallocated when the
75                                                                                                                 // 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     NR::Maybe<NR::Rect>             BBox(int glyph_id);
83                 // creates a rasterfont for the given style
84     raster_font*         RasterFont(NR::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 :