in plugin/:
[moon.git] / src / fontmanager.h
blobff59d6843731c695c338ebfbb9e8c450b8b3c2ca
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * fontmanager.h:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2009 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #ifndef __FONT_MANAGER_H__
14 #define __FONT_MANAGER_H__
16 #include <glib.h>
17 #include <ft2build.h>
18 #include FT_FREETYPE_H
20 #include "moon-path.h"
21 #include "enums.h"
23 struct ManagedStreamCallbacks;
24 class FontManager;
25 class FontFace;
27 bool FontWeightIsBold (FontWeights weight);
29 struct GlyphMetrics {
30 double horiBearingX;
31 //double horiBearingY;
32 double horiAdvance;
33 //double height;
34 //double width;
37 struct GlyphInfo {
38 GlyphMetrics metrics;
39 gunichar unichar;
40 guint32 index;
41 moon_path *path;
42 FontFace *face;
43 gint64 atime;
46 struct FontFaceExtents {
47 double underline_thickness;
48 double underline_position;
49 double descent;
50 double ascent;
51 double height;
55 class FontFace {
56 FontManager *manager;
57 double cur_size;
58 int ref_count;
59 FT_Face face;
60 char *key;
62 public:
63 FontFace (FontManager *manager, FT_Face face, char *key);
64 ~FontFace ();
66 void ref ();
67 void unref ();
69 const char *GetFamilyName ();
70 const char *GetStyleName ();
72 bool IsScalable ();
73 bool IsItalic ();
74 bool IsBold ();
76 gunichar GetCharFromIndex (guint32 index);
77 guint32 GetCharIndex (gunichar unichar);
78 bool HasChar (gunichar unichar);
80 void GetExtents (double size, FontFaceExtents *extents);
81 double Kerning (double size, guint32 left, guint32 right);
82 bool LoadGlyph (double size, GlyphInfo *glyph, StyleSimulations simulate = StyleSimulationsNone);
85 class FontManager {
86 friend class FontFace;
88 GHashTable *resources;
89 GHashTable *faces;
90 FT_Library libft2;
91 char *root;
92 double dpi;
94 FontFace *OpenFontResource (const char *resource, const char *family, int index, FontStretches stretch, FontWeights weight, FontStyles style);
95 FontFace *OpenSystemFont (const char *family, FontStretches stretch, FontWeights weight, FontStyles style);
96 FontFace *OpenFontFace (const char *filename, const char *guid, int index);
98 public:
99 FontManager ();
100 ~FontManager ();
102 void AddResource (const char *resource, const char *path);
103 char *AddResource (ManagedStreamCallbacks *stream);
105 FontFace *OpenFont (const char *name, FontStretches stretch, FontWeights weight, FontStyles style);
106 FontFace *OpenFont (const char *name, int index);
109 #endif /* __FONT_MANAGER_H__ */