Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-glyph.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifdef HAVE_CONFIG_H
3#endif
4
5/*
6 * SVG <glyph> element implementation
7 *
8 * Author:
9 * Felipe C. da S. Sanches <juca@members.fsf.org>
10 * Abhishek Sharma
11 *
12 * Copyright (C) 2008, Felipe C. da S. Sanches
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#include "sp-glyph.h"
18
19#include "attributes.h" // for SPAttr
20#include "object/sp-object.h" // for SP_OBJECT_MODIFIED_FLAG, SPObject, SPC...
21#include "xml/document.h" // for Document
22#include "xml/node.h" // for Node
23
24class SPDocument;
25
27 : SPObject()
28//TODO: correct these values:
29 , d(nullptr)
30 , orientation(GLYPH_ORIENTATION_BOTH)
31 , arabic_form(GLYPH_ARABIC_FORM_INITIAL)
32 , lang(nullptr)
33 , horiz_adv_x(0)
34 , vert_origin_x(0)
35 , vert_origin_y(0)
36 , vert_adv_y(0)
37{
38}
39
55
59
60static glyphArabicForm sp_glyph_read_arabic_form(gchar const *value){
61 if (!value) {
62 return GLYPH_ARABIC_FORM_INITIAL; //TODO: verify which is the default default (for me, the spec is not clear)
63 }
64
65 switch(value[0]){
66 case 'i':
67 if (strncmp(value, "initial", 7) == 0) {
69 }
70
71 if (strncmp(value, "isolated", 8) == 0) {
73 }
74 break;
75 case 'm':
76 if (strncmp(value, "medial", 6) == 0) {
78 }
79 break;
80 case 't':
81 if (strncmp(value, "terminal", 8) == 0) {
83 }
84 break;
85 }
86
87 return GLYPH_ARABIC_FORM_INITIAL; //TODO: VERIFY DEFAULT!
88}
89
91{
92 if (!value) {
94 }
95
96 switch(value[0]){
97 case 'h':
99 break;
100 case 'v':
102 break;
103 }
104
105//ERROR? TODO: VERIFY PROPER ERROR HANDLING
107}
108
109void SPGlyph::set(SPAttr key, const gchar *value)
110{
111 switch (key) {
112 case SPAttr::UNICODE:
113 {
114 this->unicode.clear();
115
116 if (value) {
117 this->unicode.append(value);
118 }
119
120 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
121 break;
122 }
124 {
125 this->glyph_name.clear();
126
127 if (value) {
128 this->glyph_name.append(value);
129 }
130
131 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
132 break;
133 }
134 case SPAttr::D:
135 {
136 if (this->d) {
137 g_free(this->d);
138 }
139
140 this->d = g_strdup(value);
141 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
142 break;
143 }
145 {
147
148 if (this->orientation != orient){
149 this->orientation = orient;
150 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
151 }
152 break;
153 }
155 {
157
158 if (this->arabic_form != form){
159 this->arabic_form = form;
160 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
161 }
162 break;
163 }
164 case SPAttr::LANG:
165 {
166 if (this->lang) {
167 g_free(this->lang);
168 }
169
170 this->lang = g_strdup(value);
171 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
172 break;
173 }
175 {
176 double number = value ? g_ascii_strtod(value, nullptr) : 0;
177
178 if (number != this->horiz_adv_x){
179 this->horiz_adv_x = number;
180 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
181 }
182 break;
183 }
185 {
186 double number = value ? g_ascii_strtod(value, nullptr) : 0;
187
188 if (number != this->vert_origin_x){
189 this->vert_origin_x = number;
190 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
191 }
192 break;
193 }
195 {
196 double number = value ? g_ascii_strtod(value, nullptr) : 0;
197
198 if (number != this->vert_origin_y){
199 this->vert_origin_y = number;
200 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
201 }
202 break;
203 }
205 {
206 double number = value ? g_ascii_strtod(value, nullptr) : 0;
207
208 if (number != this->vert_adv_y){
209 this->vert_adv_y = number;
210 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
211 }
212 break;
213 }
214 default:
215 {
216 SPObject::set(key, value);
217 break;
218 }
219 }
220}
221
225void SPGlyph::update(SPCtx *ctx, guint flags)
226{
227 if (flags & SP_OBJECT_MODIFIED_FLAG) {
228 /* do something to trigger redisplay, updates? */
231 this->readAttr(SPAttr::D);
234 this->readAttr(SPAttr::LANG);
239 }
240
241 SPObject::update(ctx, flags);
242}
243
244#define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
245
247{
248 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
249 repr = xml_doc->createElement("svg:glyph");
250 }
251
252 /* I am commenting out this part because I am not certain how does it work. I will have to study it later. Juca
253 repr->setAttribute("unicode", glyph->unicode);
254 repr->setAttribute("glyph-name", glyph->glyph_name);
255 repr->setAttribute("d", glyph->d);
256 repr->setAttributeSvgDouble("orientation", (double) glyph->orientation);
257 repr->setAttributeSvgDouble("arabic-form", (double) glyph->arabic_form);
258 repr->setAttribute("lang", glyph->lang);
259 repr->setAttributeSvgDouble("horiz-adv-x", glyph->horiz_adv_x);
260 repr->setAttributeSvgDouble("vert-origin-x", glyph->vert_origin_x);
261 repr->setAttributeSvgDouble("vert-origin-y", glyph->vert_origin_y);
262 repr->setAttributeSvgDouble("vert-adv-y", glyph->vert_adv_y);
263 */
264
265 if (repr != this->getRepr()) {
266 // All the COPY_ATTR functions below use
267 // XML Tree directly while they shouldn't.
268 COPY_ATTR(repr, this->getRepr(), "unicode");
269 COPY_ATTR(repr, this->getRepr(), "glyph-name");
270 COPY_ATTR(repr, this->getRepr(), "d");
271 COPY_ATTR(repr, this->getRepr(), "orientation");
272 COPY_ATTR(repr, this->getRepr(), "arabic-form");
273 COPY_ATTR(repr, this->getRepr(), "lang");
274 COPY_ATTR(repr, this->getRepr(), "horiz-adv-x");
275 COPY_ATTR(repr, this->getRepr(), "vert-origin-x");
276 COPY_ATTR(repr, this->getRepr(), "vert-origin-y");
277 COPY_ATTR(repr, this->getRepr(), "vert-adv-y");
278 }
279
280 SPObject::write(xml_doc, repr, flags);
281
282 return repr;
283}
284
285/*
286 Local Variables:
287 mode:c++
288 c-file-style:"stroustrup"
289 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
290 indent-tabs-mode:nil
291 fill-column:99
292 End:
293*/
294// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
@ VERT_ADV_Y
@ GLYPH_NAME
@ ARABIC_FORM
@ ORIENTATION
@ VERT_ORIGIN_Y
@ VERT_ORIGIN_X
@ HORIZ_ADV_X
Interface for refcounted XML nodes.
Definition node.h:80
Typed SVG document implementation.
Definition document.h:101
void release() override
Definition sp-glyph.cpp:56
Glib::ustring glyph_name
Definition sp-glyph.h:41
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Definition sp-glyph.cpp:40
Glib::ustring unicode
Definition sp-glyph.h:40
double vert_origin_x
Definition sp-glyph.h:47
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) override
Definition sp-glyph.cpp:246
char * d
Definition sp-glyph.h:42
double horiz_adv_x
Definition sp-glyph.h:46
double vert_adv_y
Definition sp-glyph.h:49
char * lang
Definition sp-glyph.h:45
void set(SPAttr key, const char *value) override
Definition sp-glyph.cpp:109
void update(SPCtx *ctx, unsigned int flags) override
Receives update notifications.
Definition sp-glyph.cpp:225
glyphArabicForm arabic_form
Definition sp-glyph.h:44
double vert_origin_y
Definition sp-glyph.h:48
glyphOrientation orientation
Definition sp-glyph.h:43
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Inkscape::XML::Node * repr
Definition sp-object.h:193
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
SPDocument * document
Definition sp-object.h:188
virtual void set(SPAttr key, const char *value)
virtual Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags)
virtual void update(SPCtx *ctx, unsigned int flags)
virtual void release()
void readAttr(char const *key)
Read value of key attribute from XML node into object.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
static cairo_user_data_key_t key
static glyphOrientation sp_glyph_read_orientation(gchar const *value)
Definition sp-glyph.cpp:90
static glyphArabicForm sp_glyph_read_arabic_form(gchar const *value)
Definition sp-glyph.cpp:60
glyphArabicForm
Definition sp-glyph.h:16
@ GLYPH_ARABIC_FORM_ISOLATED
Definition sp-glyph.h:20
@ GLYPH_ARABIC_FORM_INITIAL
Definition sp-glyph.h:17
@ GLYPH_ARABIC_FORM_TERMINAL
Definition sp-glyph.h:19
@ GLYPH_ARABIC_FORM_MEDIAL
Definition sp-glyph.h:18
glyphOrientation
Definition sp-glyph.h:23
@ GLYPH_ORIENTATION_VERTICAL
Definition sp-glyph.h:25
@ GLYPH_ORIENTATION_BOTH
Definition sp-glyph.h:26
@ GLYPH_ORIENTATION_HORIZONTAL
Definition sp-glyph.h:24
Interface for XML documents.
Definition document.h:43
virtual Node * createElement(char const *name)=0
Unused.
Definition sp-object.h:94
Interface for XML documents.
Interface for XML nodes.