~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/sp-font.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_CONFIG_H
 
2
# include <config.h>
 
3
#endif
 
4
 
 
5
#ifdef ENABLE_SVG_FONTS
 
6
 
 
7
/*
 
8
 * SVG <font> element implementation
 
9
 *
 
10
 * Author:
 
11
 *   Felipe C. da S. Sanches <felipe.sanches@gmail.com>
 
12
 *
 
13
 * Copyright (C) 2008, Felipe C. da S. Sanches
 
14
 *
 
15
 * Released under GNU GPL, read the file 'COPYING' for more information
 
16
 */
 
17
 
 
18
#include "xml/repr.h"
 
19
#include "attributes.h"
 
20
#include "sp-font.h"
 
21
#include "sp-glyph.h"
 
22
#include "sp-missing-glyph.h"
 
23
#include "document.h"
 
24
#include "helper-fns.h"
 
25
 
 
26
#include "display/nr-svgfonts.h"
 
27
 
 
28
static void sp_font_class_init(SPFontClass *fc);
 
29
static void sp_font_init(SPFont *font);
 
30
 
 
31
static void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
 
32
static void sp_font_release(SPObject *object);
 
33
static void sp_font_set(SPObject *object, unsigned int key, const gchar *value);
 
34
static Inkscape::XML::Node *sp_font_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
35
 
 
36
static void sp_font_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
 
37
static void sp_font_remove_child(SPObject *object, Inkscape::XML::Node *child);
 
38
static void sp_font_update(SPObject *object, SPCtx *ctx, guint flags);
 
39
 
 
40
// static gchar *sp_font_description(SPItem *item);
 
41
 
 
42
static SPObjectClass *parent_class;
 
43
 
 
44
GType sp_font_get_type(void)
 
45
{
 
46
    static GType type = 0;
 
47
 
 
48
    if (!type) {
 
49
        GTypeInfo info = {
 
50
            sizeof(SPFontClass),
 
51
            NULL,       /* base_init */
 
52
            NULL,       /* base_finalize */
 
53
            (GClassInitFunc) sp_font_class_init,
 
54
            NULL,       /* class_finalize */
 
55
            NULL,       /* class_data */
 
56
            sizeof(SPFont),
 
57
            16, /* n_preallocs */
 
58
            (GInstanceInitFunc) sp_font_init,
 
59
            NULL,       /* value_table */
 
60
        };
 
61
        type = g_type_register_static(SP_TYPE_OBJECT, "SPFont", &info, (GTypeFlags) 0);
 
62
    }
 
63
 
 
64
    return type;
 
65
}
 
66
 
 
67
static void sp_font_class_init(SPFontClass *fc)
 
68
{
 
69
    SPObjectClass *sp_object_class = (SPObjectClass *) fc;
 
70
 
 
71
    parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
 
72
 
 
73
    sp_object_class->build = sp_font_build;
 
74
    sp_object_class->release = sp_font_release;
 
75
    sp_object_class->set = sp_font_set;
 
76
    sp_object_class->write = sp_font_write;
 
77
    sp_object_class->child_added = sp_font_child_added;
 
78
    sp_object_class->remove_child = sp_font_remove_child;
 
79
    sp_object_class->update = sp_font_update;
 
80
}
 
81
 
 
82
static void sp_font_init(SPFont *font)
 
83
{
 
84
    font->horiz_origin_x = 0;
 
85
    font->horiz_origin_y = 0;
 
86
    font->horiz_adv_x = 0;
 
87
//I think we should have extra stuff here and in the set method in order to set default value as specified at http://www.w3.org/TR/SVG/fonts.html
 
88
    font->vert_origin_x = 0;
 
89
    font->vert_origin_y = 0;
 
90
    font->vert_adv_y = 0;
 
91
}
 
92
 
 
93
static void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
 
94
{
 
95
    if (((SPObjectClass *) (parent_class))->build) {
 
96
        ((SPObjectClass *) (parent_class))->build(object, document, repr);
 
97
    }
 
98
 
 
99
    sp_object_read_attr(object, "horiz-origin-x");
 
100
    sp_object_read_attr(object, "horiz-origin-y");
 
101
    sp_object_read_attr(object, "horiz-adv-x");
 
102
    sp_object_read_attr(object, "vert-origin-x");
 
103
    sp_object_read_attr(object, "vert-origin-y");
 
104
    sp_object_read_attr(object, "vert-adv-y");
 
105
 
 
106
    sp_document_add_resource(document, "font", object);
 
107
}
 
108
 
 
109
 
 
110
static void sp_font_children_modified(SPFont */*sp_font*/)
 
111
{
 
112
}
 
113
 
 
114
/**
 
115
 * Callback for child_added event.
 
116
 */
 
117
static void
 
118
sp_font_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
 
119
{
 
120
    SPFont *f = SP_FONT(object);
 
121
 
 
122
    if (((SPObjectClass *) parent_class)->child_added)
 
123
        (* ((SPObjectClass *) parent_class)->child_added)(object, child, ref);
 
124
 
 
125
    sp_font_children_modified(f);
 
126
    object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
127
}
 
128
 
 
129
 
 
130
/**
 
131
 * Callback for remove_child event.
 
132
 */
 
133
static void
 
134
sp_font_remove_child(SPObject *object, Inkscape::XML::Node *child)
 
135
{
 
136
    SPFont *f = SP_FONT(object);
 
137
 
 
138
    if (((SPObjectClass *) parent_class)->remove_child)
 
139
        (* ((SPObjectClass *) parent_class)->remove_child)(object, child);
 
140
 
 
141
    sp_font_children_modified(f);
 
142
    object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
143
}
 
144
 
 
145
static void sp_font_release(SPObject *object)
 
146
{
 
147
    //SPFont *font = SP_FONT(object);
 
148
    sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "font", object);
 
149
 
 
150
    if (((SPObjectClass *) parent_class)->release) {
 
151
        ((SPObjectClass *) parent_class)->release(object);
 
152
    }
 
153
}
 
154
 
 
155
static void sp_font_set(SPObject *object, unsigned int key, const gchar *value)
 
156
{
 
157
    SPFont *font = SP_FONT(object);
 
158
    double number;
 
159
 
 
160
    switch (key) {
 
161
        case SP_ATTR_HORIZ_ORIGIN_X:
 
162
            number = helperfns_read_number(value);
 
163
            if (number != font->horiz_origin_x){
 
164
                font->horiz_origin_x = number;
 
165
                object->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
166
            }
 
167
            break;
 
168
        case SP_ATTR_HORIZ_ORIGIN_Y:
 
169
            number = helperfns_read_number(value);
 
170
            if (number != font->horiz_origin_y){
 
171
                font->horiz_origin_y = number;
 
172
                object->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
173
            }
 
174
            break;
 
175
        case SP_ATTR_HORIZ_ADV_X:
 
176
            number = helperfns_read_number(value);
 
177
            if (number != font->horiz_adv_x){
 
178
                font->horiz_adv_x = number;
 
179
                object->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
180
            }
 
181
            break;
 
182
        case SP_ATTR_VERT_ORIGIN_X:
 
183
            number = helperfns_read_number(value);
 
184
            if (number != font->vert_origin_x){
 
185
                font->vert_origin_x = number;
 
186
                object->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
187
            }
 
188
            break;
 
189
        case SP_ATTR_VERT_ORIGIN_Y:
 
190
            number = helperfns_read_number(value);
 
191
            if (number != font->vert_origin_y){
 
192
                font->vert_origin_y = number;
 
193
                object->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
194
            }
 
195
            break;
 
196
        case SP_ATTR_VERT_ADV_Y:
 
197
            number = helperfns_read_number(value);
 
198
            if (number != font->vert_adv_y){
 
199
                font->vert_adv_y = number;
 
200
                object->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
201
            }
 
202
            break;
 
203
        default:
 
204
            if (((SPObjectClass *) (parent_class))->set) {
 
205
                ((SPObjectClass *) (parent_class))->set(object, key, value);
 
206
            }
 
207
            break;
 
208
    }
 
209
}
 
210
 
 
211
/**
 
212
 * Receives update notifications.
 
213
 */
 
214
static void
 
215
sp_font_update(SPObject *object, SPCtx *ctx, guint flags)
 
216
{
 
217
    if (flags & (SP_OBJECT_MODIFIED_FLAG)) {
 
218
        sp_object_read_attr(object, "horiz-origin-x");
 
219
        sp_object_read_attr(object, "horiz-origin-y");
 
220
        sp_object_read_attr(object, "horiz-adv-x");
 
221
        sp_object_read_attr(object, "vert-origin-x");
 
222
        sp_object_read_attr(object, "vert-origin-y");
 
223
        sp_object_read_attr(object, "vert-adv-y");
 
224
    }
 
225
 
 
226
    if (((SPObjectClass *) parent_class)->update) {
 
227
        ((SPObjectClass *) parent_class)->update(object, ctx, flags);
 
228
    }
 
229
}
 
230
 
 
231
#define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
 
232
 
 
233
static Inkscape::XML::Node *sp_font_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
 
234
{
 
235
    SPFont *font = SP_FONT(object);
 
236
 
 
237
    if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
 
238
        repr = xml_doc->createElement("svg:font");
 
239
    }
 
240
 
 
241
    sp_repr_set_svg_double(repr, "horiz-origin-x", font->horiz_origin_x);
 
242
    sp_repr_set_svg_double(repr, "horiz-origin-y", font->horiz_origin_y);
 
243
    sp_repr_set_svg_double(repr, "horiz-adv-x", font->horiz_adv_x);
 
244
    sp_repr_set_svg_double(repr, "vert-origin-x", font->vert_origin_x);
 
245
    sp_repr_set_svg_double(repr, "vert-origin-y", font->vert_origin_y);
 
246
    sp_repr_set_svg_double(repr, "vert-adv-y", font->vert_adv_y);
 
247
 
 
248
    if (repr != SP_OBJECT_REPR(object)) {
 
249
        COPY_ATTR(repr, object->repr, "horiz-origin-x");
 
250
        COPY_ATTR(repr, object->repr, "horiz-origin-y");
 
251
        COPY_ATTR(repr, object->repr, "horiz-adv-x");
 
252
        COPY_ATTR(repr, object->repr, "vert-origin-x");
 
253
        COPY_ATTR(repr, object->repr, "vert-origin-y");
 
254
        COPY_ATTR(repr, object->repr, "vert-adv-y");
 
255
    }
 
256
 
 
257
    if (((SPObjectClass *) (parent_class))->write) {
 
258
        ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
 
259
    }
 
260
 
 
261
    return repr;
 
262
}
 
263
#endif //#ifdef ENABLE_SVG_FONTS
 
264
/*
 
265
  Local Variables:
 
266
  mode:c++
 
267
  c-file-style:"stroustrup"
 
268
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
269
  indent-tabs-mode:nil
 
270
  fill-column:99
 
271
  End:
 
272
*/
 
273
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :