Code

Resolves the year 1 problem on the calendar render extension.
[inkscape.git] / src / libnrtype / font-instance.h
1 #ifndef SEEN_LIBNRTYPE_FONT_INSTANCE_H
2 #define SEEN_LIBNRTYPE_FONT_INSTANCE_H
4 #include <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>
14 #include "libnr/nr-rect.h"
15 #include <2geom/d2.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 class font_instance {
22 public:
23     // the real source of the font
24     PangoFont*            pFont;
25     // depending on the rendering backend, different temporary data
27     // that's the font's fingerprint; this particular PangoFontDescription gives the entry at which this font_instance
28     // resides in the font_factory loadedFaces unordered_map
29     PangoFontDescription* descr;
30     // refcount
31     int                   refCount;
32     // font_factory owning this font_instance
33     font_factory*         daddy;
35     // common glyph definitions for all the rasterfonts
36     std::map<int, int>    id_to_no;
37     int                   nbGlyph, maxGlyph;
38     font_glyph*           glyphs;
40     font_instance(void);
41     virtual ~font_instance(void);
43     void                 Ref(void);
44     void                 Unref(void);
46     bool                 IsOutlineFont(void); // utility
47     void                 InstallFace(PangoFont* iFace); // utility; should reset the pFont field if loading failed
48     // in case the PangoFont is a bitmap font, for example. that way, the calling function
49     // will be able to check the validity of the font before installing it in loadedFaces
50     void                 InitTheFace();
52     int                  MapUnicodeChar(gunichar c); // calls the relevant unicode->glyph index function
53     void                 LoadGlyph(int glyph_id);    // the main backend-dependent function
54     // loads the given glyph's info
56     // nota: all coordinates returned by these functions are on a [0..1] scale; you need to multiply
57     // by the fontsize to get the real sizes
58     Path*                Outline(int glyph_id, Path *copyInto=NULL);
59     // queries the outline of the glyph (in livarot Path form), and copies it into copyInto instead
60     // of allocating a new Path if copyInto != NULL
61     Geom::PathVector*    PathVector(int glyph_id);
62                          // returns the 2geom-type pathvector for this glyph. no refcounting needed, it's deallocated when the font_instance dies
63     double               Advance(int glyph_id, bool vertical);
64     // nominal advance of the font.
65     bool                 FontMetrics(double &ascent, double &descent, double &leading);
66     bool                 FontSlope(double &run, double &rise);
67                                 // for generating slanted cursors for oblique fonts
68     Geom::OptRect             BBox(int glyph_id);
70     // creates a rasterfont for the given style
71     raster_font*         RasterFont(Geom::Matrix const &trs, double stroke_width,
72                                     bool vertical = false, JoinType stroke_join = join_straight,
73                                     ButtType stroke_cap = butt_straight, float miter_limit = 4.0);
74     // the dashes array in iStyle is copied
75     raster_font*         RasterFont(font_style const &iStyle);
76     // private use: tells the font_instance that the raster_font 'who' has died
77     void                 RemoveRasterFont(raster_font *who);
79     // attribute queries
80     unsigned             Name(gchar *str, unsigned size);
81     unsigned             PSName(gchar *str, unsigned size);
82     unsigned             Family(gchar *str, unsigned size);
83     unsigned             Attribute(gchar const *key, gchar *str, unsigned size);
85 private:
86     void                 FreeTheFace();
88     // hashmap to get the raster_font for a given style
89     void*                loadedPtr;
91 #ifdef USE_PANGO_WIN32
92     HFONT                 theFace;
93 #else
94     FT_Face               theFace;
95                 // it's a pointer in fact; no worries to ref/unref it, pango does its magic
96                 // as long as pFont is valid, theFace is too
97 #endif
99 };
102 #endif /* !SEEN_LIBNRTYPE_FONT_INSTANCE_H */
104 /*
105   Local Variables:
106   mode:c++
107   c-file-style:"stroustrup"
108   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
109   indent-tabs-mode:nil
110   fill-column:99
111   End:
112 */
113 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :