Code

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