1/* Pango
2 * pango-fontset-simple.c:
3 *
4 * Copyright (C) 2001 Red Hat Software
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/*
25 * PangoFontset
26 */
27
28#include "pango-types.h"
29#include "pango-font-private.h"
30#include "pango-fontset-simple-private.h"
31#include "pango-impl-utils.h"
32
33/* {{{ PangoFontset implementation */
34
35#define PANGO_FONTSET_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_FONTSET_SIMPLE, PangoFontsetSimpleClass))
36#define PANGO_IS_FONTSET_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_FONTSET_SIMPLE))
37#define PANGO_FONTSET_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_FONTSET_SIMPLE, PangoFontsetSimpleClass))
38
39
40G_DEFINE_TYPE (PangoFontsetSimple, pango_fontset_simple, PANGO_TYPE_FONTSET);
41
42static void
43pango_fontset_simple_init (PangoFontsetSimple *fontset)
44{
45 fontset->fonts = g_ptr_array_new_with_free_func (element_free_func: g_object_unref);
46 fontset->language = NULL;
47}
48
49static void
50pango_fontset_simple_finalize (GObject *object)
51{
52 PangoFontsetSimple *fontset = PANGO_FONTSET_SIMPLE (object);
53
54 g_ptr_array_free (array: fontset->fonts, TRUE);
55
56 G_OBJECT_CLASS (pango_fontset_simple_parent_class)->finalize (object);
57}
58
59static PangoFont *
60pango_fontset_simple_get_font (PangoFontset *fontset,
61 guint wc)
62{
63 PangoFontsetSimple *simple = PANGO_FONTSET_SIMPLE (fontset);
64 unsigned int i;
65
66 for (i = 0; i < simple->fonts->len; i++)
67 {
68 PangoFont *font = g_ptr_array_index (simple->fonts, i);
69
70 if (pango_font_has_char (font, wc))
71 return g_object_ref (font);
72 }
73
74 return NULL;
75}
76
77static PangoFontMetrics *
78pango_fontset_simple_get_metrics (PangoFontset *fontset)
79{
80 PangoFontsetSimple *simple = PANGO_FONTSET_SIMPLE (fontset);
81
82 if (simple->fonts->len == 1)
83 {
84 PangoFont *font = g_ptr_array_index (simple->fonts, 0);
85
86 return pango_font_get_metrics (font, language: simple->language);
87 }
88
89 return PANGO_FONTSET_CLASS (pango_fontset_simple_parent_class)->get_metrics (fontset);
90}
91
92static PangoLanguage *
93pango_fontset_simple_get_language (PangoFontset *fontset)
94{
95 PangoFontsetSimple *simple = PANGO_FONTSET_SIMPLE (fontset);
96
97 return simple->language;
98}
99
100static void
101pango_fontset_simple_foreach (PangoFontset *fontset,
102 PangoFontsetForeachFunc func,
103 gpointer data)
104{
105 PangoFontsetSimple *simple = PANGO_FONTSET_SIMPLE (fontset);
106 unsigned int i;
107
108 for (i = 0; i < simple->fonts->len; i++)
109 {
110 PangoFont *font = g_ptr_array_index (simple->fonts, i);
111
112 if ((*func) (fontset, font, data))
113 return;
114 }
115}
116
117static void
118pango_fontset_simple_class_init (PangoFontsetSimpleClass *class)
119{
120 GObjectClass *object_class = G_OBJECT_CLASS (class);
121 PangoFontsetClass *fontset_class = PANGO_FONTSET_CLASS (class);
122
123 object_class->finalize = pango_fontset_simple_finalize;
124
125 fontset_class->get_font = pango_fontset_simple_get_font;
126 fontset_class->get_metrics = pango_fontset_simple_get_metrics;
127 fontset_class->get_language = pango_fontset_simple_get_language;
128 fontset_class->foreach = pango_fontset_simple_foreach;
129}
130
131/* }}} */
132/* {{{ Public API */
133
134/**
135 * pango_fontset_simple_new:
136 * @language: a `PangoLanguage` tag
137 *
138 * Creates a new `PangoFontsetSimple` for the given language.
139 *
140 * Return value: the newly allocated `PangoFontsetSimple`
141 */
142PangoFontsetSimple *
143pango_fontset_simple_new (PangoLanguage *language)
144{
145 PangoFontsetSimple *fontset;
146
147 fontset = g_object_new (PANGO_TYPE_FONTSET_SIMPLE, NULL);
148 fontset->language = language;
149
150 return fontset;
151}
152
153/**
154 * pango_fontset_simple_append:
155 * @fontset: a `PangoFontsetSimple`.
156 * @font: (transfer full): a `PangoFont`.
157 *
158 * Adds a font to the fontset.
159 *
160 * The fontset takes ownership of @font.
161 */
162void
163pango_fontset_simple_append (PangoFontsetSimple *fontset,
164 PangoFont *font)
165{
166 g_ptr_array_add (array: fontset->fonts, data: font);
167}
168
169/**
170 * pango_fontset_simple_size:
171 * @fontset: a `PangoFontsetSimple`.
172 *
173 * Returns the number of fonts in the fontset.
174 *
175 * Return value: the size of @fontset
176 */
177int
178pango_fontset_simple_size (PangoFontsetSimple *fontset)
179{
180 return fontset->fonts->len;
181}
182
183/* }}} */
184
185/* vim:set foldmethod=marker expandtab: */
186

source code of gtk/subprojects/pango/pango/pango-fontset-simple.c