Upload tizen 2.0 beta source
[external/pango1.0.git] / pango / pangoatsui.c
1 /* Pango
2  * pangatsui.c
3  *
4  * Copyright (C) 2005-2007 Imendio AB
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include "config.h"
23
24 #include "pangoatsui.h"
25 #include "pangoatsui-private.h"
26
27 G_DEFINE_TYPE (PangoATSUIFont, pango_atsui_font, PANGO_TYPE_FONT);
28
29 struct _PangoATSUIFontPrivate
30 {
31   PangoATSUIFace *face;
32   PangoFontDescription *desc;
33   gpointer context_key;
34
35   CGFontRef font_id;
36
37   PangoFontMap *fontmap;
38 };
39
40 static void
41 pango_atsui_font_finalize (GObject *object)
42 {
43   PangoATSUIFont *afont = (PangoATSUIFont *)object;
44   PangoATSUIFontPrivate *priv = afont->priv;
45
46   pango_font_description_free (priv->desc);
47
48   g_assert (priv->fontmap != NULL);
49   g_object_remove_weak_pointer (G_OBJECT (priv->fontmap), (gpointer *) (gpointer) &priv->fontmap);
50   priv->fontmap = NULL;
51
52   G_OBJECT_CLASS (pango_atsui_font_parent_class)->finalize (object);
53 }
54
55 static PangoFontDescription *
56 pango_atsui_font_describe (PangoFont *font)
57 {
58   PangoATSUIFont *afont = (PangoATSUIFont *)font;
59   PangoATSUIFontPrivate *priv = afont->priv;
60
61   return pango_font_description_copy (priv->desc);
62 }
63
64 static PangoCoverage *
65 pango_atsui_font_get_coverage (PangoFont     *font,
66                                PangoLanguage *language)
67 {
68   PangoATSUIFont *afont = (PangoATSUIFont *)font;
69   PangoATSUIFontPrivate *priv = afont->priv;
70
71   return pango_coverage_ref (_pango_atsui_face_get_coverage (priv->face,
72                                                              language));
73 }
74
75 static PangoEngineShape *
76 pango_atsui_font_find_shaper (PangoFont     *font,
77                               PangoLanguage *language,
78                               guint32        ch)
79 {
80   /* FIXME: Implement */
81   return NULL;
82 }
83
84 static PangoFontMap *
85 pango_atsui_font_get_font_map (PangoFont *font)
86 {
87   PangoATSUIFont *afont = (PangoATSUIFont *)font;
88
89   return afont->priv->fontmap;
90 }
91
92 static void
93 pango_atsui_font_init (PangoATSUIFont *afont)
94 {
95   afont->priv = G_TYPE_INSTANCE_GET_PRIVATE (afont,
96                                              PANGO_TYPE_ATSUI_FONT,
97                                              PangoATSUIFontPrivate);
98 }
99
100 static void
101 pango_atsui_font_class_init (PangoATSUIFontClass *class)
102 {
103   GObjectClass *object_class = G_OBJECT_CLASS (class);
104   PangoFontClass *font_class = PANGO_FONT_CLASS (class);
105
106   object_class->finalize = pango_atsui_font_finalize;
107
108   font_class->describe = pango_atsui_font_describe;
109   font_class->get_coverage = pango_atsui_font_get_coverage;
110   font_class->find_shaper = pango_atsui_font_find_shaper;
111   font_class->get_font_map = pango_atsui_font_get_font_map;
112
113   g_type_class_add_private (object_class, sizeof (PangoATSUIFontPrivate));
114 }
115
116 void
117 _pango_atsui_font_set_font_description (PangoATSUIFont             *font,
118                                         const PangoFontDescription *desc)
119 {
120   PangoATSUIFontPrivate *priv = font->priv;
121
122   priv->desc = pango_font_description_copy (desc);
123 }
124
125 PangoFontDescription *
126 _pango_atsui_font_get_font_description (PangoATSUIFont *font)
127 {
128   PangoATSUIFontPrivate *priv = font->priv;
129
130   return priv->desc;
131 }
132
133 void
134 _pango_atsui_font_set_font_map (PangoATSUIFont    *font,
135                                 PangoATSUIFontMap *fontmap)
136 {
137   PangoATSUIFontPrivate *priv = font->priv;
138
139   g_assert (priv->fontmap == NULL);
140   priv->fontmap = (PangoFontMap *) fontmap;
141   g_object_add_weak_pointer (G_OBJECT (priv->fontmap), (gpointer *) (gpointer) &priv->fontmap);
142 }
143
144 void
145 _pango_atsui_font_set_face (PangoATSUIFont *afont, 
146                             PangoATSUIFace *face)
147 {
148   PangoATSUIFontPrivate *priv = afont->priv;
149
150   priv->face = face;
151 }
152
153 PangoATSUIFace *
154 _pango_atsui_font_get_face (PangoATSUIFont *afont)
155 {
156   PangoATSUIFontPrivate *priv = afont->priv;
157
158   return priv->face;
159 }
160
161 gpointer
162 _pango_atsui_font_get_context_key (PangoATSUIFont *afont)
163 {
164   PangoATSUIFontPrivate *priv = afont->priv;
165
166   return priv->context_key;
167 }
168
169 void
170 _pango_atsui_font_set_context_key (PangoATSUIFont *afont,
171                                    gpointer        context_key)
172 {
173   PangoATSUIFontPrivate *priv = afont->priv;
174
175   priv->context_key = context_key;
176 }
177
178 void
179 _pango_atsui_font_set_cgfont (PangoATSUIFont *font,
180                                     CGFontRef      font_id)
181 {
182   PangoATSUIFontPrivate *priv = font->priv;
183
184   priv->font_id = font_id;
185 }
186
187 /**
188  * pango_atsui_font_get_cgfont:
189  * @font: A #PangoATSUIFont
190  *
191  * Returns the CGFontRef of a font.
192  *
193  * Return value: the CGFontRef associated to @font.
194  *
195  * Since: 1.18
196  */
197 CGFontRef
198 pango_atsui_font_get_cgfont (PangoATSUIFont *font)
199 {
200   PangoATSUIFontPrivate *priv = font->priv;
201
202   return priv->font_id;
203 }