~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/curve/editfont.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: editfont.c 30585 2010-07-21 14:11:19Z blendix $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
25
23
 * ***** END GPL LICENSE BLOCK *****
26
24
 */
27
25
 
 
26
/** \file blender/editors/curve/editfont.c
 
27
 *  \ingroup edcurve
 
28
 */
 
29
 
 
30
 
28
31
#include <stdlib.h>
29
32
#include <string.h>
30
33
#include <fcntl.h>
40
43
 
41
44
#include "BLI_blenlib.h"
42
45
#include "BLI_math.h"
 
46
#include "BLI_utildefines.h"
43
47
 
44
48
#include "DNA_curve_types.h"
45
49
#include "DNA_object_types.h"
51
55
#include "BKE_curve.h"
52
56
#include "BKE_depsgraph.h"
53
57
#include "BKE_font.h"
54
 
#include "BKE_global.h"
55
58
#include "BKE_library.h"
56
 
#include "BKE_main.h"
57
59
#include "BKE_object.h"
58
60
#include "BKE_report.h"
59
 
#include "BKE_utildefines.h"
60
61
 
61
62
#include "RNA_access.h"
62
63
#include "RNA_define.h"
64
65
#include "WM_api.h"
65
66
#include "WM_types.h"
66
67
 
 
68
#include "ED_curve.h"
67
69
#include "ED_object.h"
68
70
#include "ED_screen.h"
69
71
#include "ED_util.h"
80
82
{
81
83
        char new= 0;
82
84
        
83
 
        if(char1=='a') {
84
 
                if(code=='`') new= 224;
85
 
                else if(code==39) new= 225;
86
 
                else if(code=='^') new= 226;
87
 
                else if(code=='~') new= 227;
88
 
                else if(code=='"') new= 228;
89
 
                else if(code=='o') new= 229;
90
 
                else if(code=='e') new= 230;
91
 
                else if(code=='-') new= 170;
92
 
        }
93
 
        else if(char1=='c') {
94
 
                if(code==',') new= 231;
95
 
                if(code=='|') new= 162;
96
 
        }
97
 
        else if(char1=='e') {
98
 
                if(code=='`') new= 232;
99
 
                else if(code==39) new= 233;
100
 
                else if(code=='^') new= 234;
101
 
                else if(code=='"') new= 235;
102
 
        }
103
 
        else if(char1=='i') {
104
 
                if(code=='`') new= 236;
105
 
                else if(code==39) new= 237;
106
 
                else if(code=='^') new= 238;
107
 
                else if(code=='"') new= 239;
108
 
        }
109
 
        else if(char1=='n') {
110
 
                if(code=='~') new= 241;
111
 
        }
112
 
        else if(char1=='o') {
113
 
                if(code=='`') new= 242;
114
 
                else if(code==39) new= 243;
115
 
                else if(code=='^') new= 244;
116
 
                else if(code=='~') new= 245;
117
 
                else if(code=='"') new= 246;
118
 
                else if(code=='/') new= 248;
119
 
                else if(code=='-') new= 186;
120
 
                else if(code=='e') new= 143;
121
 
        }
122
 
        else if(char1=='s') {
123
 
                if(code=='s') new= 167;
124
 
        }
125
 
        else if(char1=='u') {
126
 
                if(code=='`') new= 249;
127
 
                else if(code==39) new= 250;
128
 
                else if(code=='^') new= 251;
129
 
                else if(code=='"') new= 252;
130
 
        }
131
 
        else if(char1=='y') {
132
 
                if(code==39) new= 253;
133
 
                else if(code=='"') new= 255;
134
 
        }
135
 
        else if(char1=='A') {
136
 
                if(code=='`') new= 192;
137
 
                else if(code==39) new= 193;
138
 
                else if(code=='^') new= 194;
139
 
                else if(code=='~') new= 195;
140
 
                else if(code=='"') new= 196;
141
 
                else if(code=='o') new= 197;
142
 
                else if(code=='e') new= 198;
143
 
        }
144
 
        else if(char1=='C') {
145
 
                if(code==',') new= 199;
146
 
        }
147
 
        else if(char1=='E') {
148
 
                if(code=='`') new= 200;
149
 
                else if(code==39) new= 201;
150
 
                else if(code=='^') new= 202;
151
 
                else if(code=='"') new= 203;
152
 
        }
153
 
        else if(char1=='I') {
154
 
                if(code=='`') new= 204;
155
 
                else if(code==39) new= 205;
156
 
                else if(code=='^') new= 206;
157
 
                else if(code=='"') new= 207;
158
 
        }
159
 
        else if(char1=='N') {
160
 
                if(code=='~') new= 209;
161
 
        }
162
 
        else if(char1=='O') {
163
 
                if(code=='`') new= 210;
164
 
                else if(code==39) new= 211;
165
 
                else if(code=='^') new= 212;
166
 
                else if(code=='~') new= 213;
167
 
                else if(code=='"') new= 214;
168
 
                else if(code=='/') new= 216;
169
 
                else if(code=='e') new= 141;
170
 
        }
171
 
        else if(char1=='U') {
172
 
                if(code=='`') new= 217;
173
 
                else if(code==39) new= 218;
174
 
                else if(code=='^') new= 219;
175
 
                else if(code=='"') new= 220;
176
 
        }
177
 
        else if(char1=='Y') {
178
 
                if(code==39) new= 221;
179
 
        }
180
 
        else if(char1=='1') {
181
 
                if(code=='4') new= 188;
182
 
                if(code=='2') new= 189;
183
 
        }
184
 
        else if(char1=='3') {
185
 
                if(code=='4') new= 190;
186
 
        }
187
 
        else if(char1==':') {
188
 
                if(code=='-') new= 247;
189
 
        }
190
 
        else if(char1=='-') {
191
 
                if(code==':') new= 247;
192
 
                if(code=='|') new= 135;
193
 
                if(code=='+') new= 177;
194
 
        }
195
 
        else if(char1=='|') {
196
 
                if(code=='-') new= 135;
197
 
                if(code=='=') new= 136;
198
 
        }
199
 
        else if(char1=='=') {
200
 
                if(code=='|') new= 136;
201
 
        }
202
 
        else if(char1=='+') {
203
 
                if(code=='-') new= 177;
 
85
        if (char1=='a') {
 
86
                if (code=='`') new= 224;
 
87
                else if (code==39) new= 225;
 
88
                else if (code=='^') new= 226;
 
89
                else if (code=='~') new= 227;
 
90
                else if (code=='"') new= 228;
 
91
                else if (code=='o') new= 229;
 
92
                else if (code=='e') new= 230;
 
93
                else if (code=='-') new= 170;
 
94
        }
 
95
        else if (char1=='c') {
 
96
                if (code==',') new= 231;
 
97
                if (code=='|') new= 162;
 
98
        }
 
99
        else if (char1=='e') {
 
100
                if (code=='`') new= 232;
 
101
                else if (code==39) new= 233;
 
102
                else if (code=='^') new= 234;
 
103
                else if (code=='"') new= 235;
 
104
        }
 
105
        else if (char1=='i') {
 
106
                if (code=='`') new= 236;
 
107
                else if (code==39) new= 237;
 
108
                else if (code=='^') new= 238;
 
109
                else if (code=='"') new= 239;
 
110
        }
 
111
        else if (char1=='n') {
 
112
                if (code=='~') new= 241;
 
113
        }
 
114
        else if (char1=='o') {
 
115
                if (code=='`') new= 242;
 
116
                else if (code==39) new= 243;
 
117
                else if (code=='^') new= 244;
 
118
                else if (code=='~') new= 245;
 
119
                else if (code=='"') new= 246;
 
120
                else if (code=='/') new= 248;
 
121
                else if (code=='-') new= 186;
 
122
                else if (code=='e') new= 143;
 
123
        }
 
124
        else if (char1=='s') {
 
125
                if (code=='s') new= 167;
 
126
        }
 
127
        else if (char1=='u') {
 
128
                if (code=='`') new= 249;
 
129
                else if (code==39) new= 250;
 
130
                else if (code=='^') new= 251;
 
131
                else if (code=='"') new= 252;
 
132
        }
 
133
        else if (char1=='y') {
 
134
                if (code==39) new= 253;
 
135
                else if (code=='"') new= 255;
 
136
        }
 
137
        else if (char1=='A') {
 
138
                if (code=='`') new= 192;
 
139
                else if (code==39) new= 193;
 
140
                else if (code=='^') new= 194;
 
141
                else if (code=='~') new= 195;
 
142
                else if (code=='"') new= 196;
 
143
                else if (code=='o') new= 197;
 
144
                else if (code=='e') new= 198;
 
145
        }
 
146
        else if (char1=='C') {
 
147
                if (code==',') new= 199;
 
148
        }
 
149
        else if (char1=='E') {
 
150
                if (code=='`') new= 200;
 
151
                else if (code==39) new= 201;
 
152
                else if (code=='^') new= 202;
 
153
                else if (code=='"') new= 203;
 
154
        }
 
155
        else if (char1=='I') {
 
156
                if (code=='`') new= 204;
 
157
                else if (code==39) new= 205;
 
158
                else if (code=='^') new= 206;
 
159
                else if (code=='"') new= 207;
 
160
        }
 
161
        else if (char1=='N') {
 
162
                if (code=='~') new= 209;
 
163
        }
 
164
        else if (char1=='O') {
 
165
                if (code=='`') new= 210;
 
166
                else if (code==39) new= 211;
 
167
                else if (code=='^') new= 212;
 
168
                else if (code=='~') new= 213;
 
169
                else if (code=='"') new= 214;
 
170
                else if (code=='/') new= 216;
 
171
                else if (code=='e') new= 141;
 
172
        }
 
173
        else if (char1=='U') {
 
174
                if (code=='`') new= 217;
 
175
                else if (code==39) new= 218;
 
176
                else if (code=='^') new= 219;
 
177
                else if (code=='"') new= 220;
 
178
        }
 
179
        else if (char1=='Y') {
 
180
                if (code==39) new= 221;
 
181
        }
 
182
        else if (char1=='1') {
 
183
                if (code=='4') new= 188;
 
184
                if (code=='2') new= 189;
 
185
        }
 
186
        else if (char1=='3') {
 
187
                if (code=='4') new= 190;
 
188
        }
 
189
        else if (char1==':') {
 
190
                if (code=='-') new= 247;
 
191
        }
 
192
        else if (char1=='-') {
 
193
                if (code==':') new= 247;
 
194
                if (code=='|') new= 135;
 
195
                if (code=='+') new= 177;
 
196
        }
 
197
        else if (char1=='|') {
 
198
                if (code=='-') new= 135;
 
199
                if (code=='=') new= 136;
 
200
        }
 
201
        else if (char1=='=') {
 
202
                if (code=='|') new= 136;
 
203
        }
 
204
        else if (char1=='+') {
 
205
                if (code=='-') new= 177;
204
206
        }
205
207
        
206
 
        if(new) return new;
 
208
        if (new) return new;
207
209
        else return char1;
208
210
}
209
211
 
210
212
 
211
 
void update_string(Curve *cu)
 
213
static void update_string(Curve *cu)
212
214
{
213
215
        EditFont *ef= cu->editfont;
214
216
        int len;
217
219
        MEM_freeN(cu->str);
218
220
 
219
221
        // Calculate the actual string length in UTF-8 variable characters
220
 
        len = wcsleninu8(ef->textbuf);
 
222
        len = BLI_wstrlen_utf8(ef->textbuf);
221
223
 
222
224
        // Alloc memory for UTF-8 variable char length string
223
225
        cu->str = MEM_callocN(len + sizeof(wchar_t), "str");
224
226
 
225
227
        // Copy the wchar to UTF-8
226
 
        wcs2utf8s(cu->str, ef->textbuf);
 
228
        BLI_strncpy_wchar_as_utf8(cu->str, ef->textbuf, len + 1);
227
229
}
228
230
 
229
231
static int insert_into_textbuf(Object *obedit, uintptr_t c)
230
232
{
231
233
        Curve *cu= obedit->data;
232
234
        
233
 
        if(cu->len<MAXTEXT-1) {
 
235
        if (cu->len<MAXTEXT-1) {
234
236
                EditFont *ef= cu->editfont;
235
237
                int x;
236
238
 
237
 
                for(x= cu->len; x>cu->pos; x--) ef->textbuf[x]= ef->textbuf[x-1];
238
 
                for(x= cu->len; x>cu->pos; x--) ef->textbufinfo[x]= ef->textbufinfo[x-1];               
 
239
                for (x= cu->len; x>cu->pos; x--) ef->textbuf[x]= ef->textbuf[x-1];
 
240
                for (x= cu->len; x>cu->pos; x--) ef->textbufinfo[x]= ef->textbufinfo[x-1];              
239
241
                ef->textbuf[cu->pos]= c;
240
242
                ef->textbufinfo[cu->pos] = cu->curinfo;
241
243
                ef->textbufinfo[cu->pos].kern = 0;
242
 
                if(obedit->actcol>0)
243
 
                        ef->textbufinfo[cu->pos].mat_nr = obedit->actcol;
244
 
                else
245
 
                        ef->textbufinfo[cu->pos].mat_nr = 0;
 
244
                ef->textbufinfo[cu->pos].mat_nr = obedit->actcol;
246
245
                                        
247
246
                cu->pos++;
248
247
                cu->len++;
258
257
 
259
258
static void text_update_edited(bContext *C, Scene *scene, Object *obedit, int recalc, int mode)
260
259
{
 
260
        struct Main *bmain= CTX_data_main(C);
261
261
        Curve *cu= obedit->data;
262
262
        EditFont *ef= cu->editfont;
263
 
 
264
 
        if(cu->pos)
265
 
                cu->curinfo = ef->textbufinfo[cu->pos-1];
266
 
        else
267
 
                cu->curinfo = ef->textbufinfo[0];
 
263
        cu->curinfo = ef->textbufinfo[cu->pos?cu->pos-1:0];
268
264
        
269
 
        if(obedit->totcol>0)
270
 
                obedit->actcol= ef->textbufinfo[cu->pos-1].mat_nr;
271
 
 
272
 
        update_string(cu);
273
 
        BKE_text_to_curve(scene, obedit, mode);
274
 
 
275
 
        if(recalc)
276
 
                DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
 
265
        if (obedit->totcol > 0) {
 
266
                obedit->actcol= ef->textbufinfo[cu->pos?cu->pos-1:0].mat_nr;
 
267
 
 
268
                /* since this array is calloc'd, it can be 0 even though we try ensure
 
269
                 * (mat_nr > 0) almost everywhere */
 
270
                if (obedit->actcol < 1) {
 
271
                        obedit->actcol= 1;
 
272
                }
 
273
        }
 
274
 
 
275
        if (mode == FO_EDIT)
 
276
                update_string(cu);
 
277
 
 
278
        BKE_text_to_curve(bmain, scene, obedit, mode);
 
279
 
 
280
        if (recalc)
 
281
                DAG_id_tag_update(obedit->data, 0);
277
282
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
278
283
}
279
284
 
280
285
/********************** insert lorem operator *********************/
281
286
 
282
 
static int insert_lorem_exec(bContext *C, wmOperator *op)
 
287
static int insert_lorem_exec(bContext *C, wmOperator *UNUSED(op))
283
288
{
284
289
        Object *obedit= CTX_data_edit_object(C);
285
 
        char *p, *p2;
 
290
        const char *p, *p2;
286
291
        int i;
287
 
        static char *lastlorem;
 
292
        static const char *lastlorem;
288
293
        
289
 
        if(lastlorem)
 
294
        if (lastlorem)
290
295
                p= lastlorem;
291
296
        else
292
297
                p= ED_lorem;
293
298
        
294
299
        i= rand()/(RAND_MAX/6)+4;       
295
300
                
296
 
        for(p2=p; *p2 && i; p2++) {
 
301
        for (p2=p; *p2 && i; p2++) {
297
302
                insert_into_textbuf(obedit, *p2);
298
303
 
299
 
                if(*p2=='.')
 
304
                if (*p2=='.')
300
305
                        i--;
301
306
        }
302
307
 
303
308
        lastlorem = p2+1;
304
 
        if(strlen(lastlorem)<5)
 
309
        if (strlen(lastlorem)<5)
305
310
                lastlorem = ED_lorem;
306
311
        
307
312
        insert_into_textbuf(obedit, '\n');
308
313
        insert_into_textbuf(obedit, '\n');      
309
314
 
310
 
        DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
 
315
        DAG_id_tag_update(obedit->data, 0);
311
316
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
312
317
 
313
318
        return OPERATOR_FINISHED;
316
321
void FONT_OT_insert_lorem(wmOperatorType *ot)
317
322
{
318
323
        /* identifiers */
319
 
        ot->name= "Insert Lorem";
320
 
        ot->description= "Insert placeholder text";
321
 
        ot->idname= "FONT_OT_insert_lorem";
 
324
        ot->name = "Insert Lorem";
 
325
        ot->description = "Insert placeholder text";
 
326
        ot->idname = "FONT_OT_insert_lorem";
322
327
        
323
328
        /* api callbacks */
324
 
        ot->exec= insert_lorem_exec;
325
 
        ot->poll= ED_operator_editfont;
 
329
        ot->exec = insert_lorem_exec;
 
330
        ot->poll = ED_operator_editfont;
326
331
        
327
332
        /* flags */
328
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
333
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
329
334
}
330
335
 
331
336
/******************* paste file operator ********************/
333
338
/* note this handles both ascii and utf8 unicode, previously
334
339
 * there were 3 functions that did effectively the same thing. */
335
340
 
336
 
static int paste_file(bContext *C, ReportList *reports, char *filename)
 
341
static int paste_file(bContext *C, ReportList *reports, const char *filename)
337
342
{
338
343
        Scene *scene= CTX_data_scene(C);
339
344
        Object *obedit= CTX_data_edit_object(C);
343
348
        int filelen;
344
349
        char *strp;
345
350
 
346
 
        fp= fopen(filename, "r");
 
351
        fp= BLI_fopen(filename, "r");
347
352
 
348
 
        if(!fp) {
349
 
                if(reports)
350
 
                        BKE_reportf(reports, RPT_ERROR, "Failed to open file %s.", filename);
 
353
        if (!fp) {
 
354
                if (reports)
 
355
                        BKE_reportf(reports, RPT_ERROR, "Failed to open file %s", filename);
351
356
                return OPERATOR_CANCELLED;
352
357
        }
353
358
 
363
368
        fclose(fp);
364
369
        strp[filelen]= 0;
365
370
 
366
 
        if(cu->len+filelen<MAXTEXT) {
 
371
        if (cu->len+filelen<MAXTEXT) {
367
372
                int tmplen;
368
373
                wchar_t *mem = MEM_callocN((sizeof(wchar_t)*filelen)+(4*sizeof(wchar_t)), "temporary");
369
 
                tmplen = utf8towchar(mem, strp);
 
374
                tmplen = BLI_strncpy_wchar_from_utf8(mem, strp, filelen + 1);
370
375
                wcscat(ef->textbuf, mem);
371
376
                MEM_freeN(mem);
372
377
                cu->len += tmplen;
374
379
        }
375
380
        MEM_freeN(strp);
376
381
 
377
 
        text_update_edited(C, scene, obedit, 1, 0);
 
382
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
378
383
 
379
384
        return OPERATOR_FINISHED;
380
385
}
391
396
        return retval;
392
397
}
393
398
 
394
 
static int paste_file_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
399
static int paste_file_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
395
400
{
396
 
        if(RNA_property_is_set(op->ptr, "filepath"))
 
401
        if (RNA_struct_property_is_set(op->ptr, "filepath"))
397
402
                return paste_file_exec(C, op);
398
403
 
399
404
        WM_event_add_fileselect(C, op); 
404
409
void FONT_OT_file_paste(wmOperatorType *ot)
405
410
{
406
411
        /* identifiers */
407
 
        ot->name= "Paste File";
408
 
        ot->description= "Paste contents from file";
409
 
        ot->idname= "FONT_OT_file_paste";
 
412
        ot->name = "Paste File";
 
413
        ot->description = "Paste contents from file";
 
414
        ot->idname = "FONT_OT_file_paste";
410
415
        
411
416
        /* api callbacks */
412
 
        ot->exec= paste_file_exec;
413
 
        ot->invoke= paste_file_invoke;
414
 
        ot->poll= ED_operator_editfont;
 
417
        ot->exec = paste_file_exec;
 
418
        ot->invoke = paste_file_invoke;
 
419
        ot->poll = ED_operator_editfont;
415
420
        
416
421
        /* flags */
417
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
422
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
418
423
 
419
424
        /* properties */
420
 
        WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH);
421
 
}
422
 
 
423
 
/******************* paste buffer operator ********************/
424
 
 
425
 
static int paste_buffer_exec(bContext *C, wmOperator *op)
426
 
{
427
 
        char *filename;
428
 
 
429
 
#ifdef WIN32
430
 
        filename= "C:\\windows\\temp\\cutbuf.txt";
431
 
 
432
 
//      The following is more likely to work on all Win32 installations.
433
 
//      suggested by Douglas Toltzman. Needs windows include files...
434
 
/*
435
 
        char tempFileName[MAX_PATH];
436
 
        DWORD pathlen;
437
 
        static const char cutbufname[]="cutbuf.txt";
438
 
 
439
 
        if((pathlen=GetTempPath(sizeof(tempFileName),tempFileName)) > 0 &&
440
 
                pathlen + sizeof(cutbufname) <= sizeof(tempFileName))
441
 
        {
442
 
                strcat(tempFileName,cutbufname);
443
 
                filename= tempFilename;
444
 
        }
445
 
*/
446
 
#else
447
 
        filename= "/tmp/.cutbuffer";
448
 
#endif
449
 
 
450
 
        return paste_file(C, NULL, filename);
451
 
}
452
 
 
453
 
void FONT_OT_buffer_paste(wmOperatorType *ot)
454
 
{
455
 
        /* identifiers */
456
 
        ot->name= "Paste Buffer";
457
 
        ot->description= "Paste text from OS buffer";
458
 
        ot->idname= "FONT_OT_buffer_paste";
459
 
        
460
 
        /* api callbacks */
461
 
        ot->exec= paste_buffer_exec;
462
 
        ot->poll= ED_operator_editfont;
463
 
        
464
 
        /* flags */
465
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
425
        WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
466
426
}
467
427
 
468
428
/******************* text to object operator ********************/
492
452
        cu->vfont= get_builtin_font();
493
453
        cu->vfont->id.us++;
494
454
 
495
 
        for(tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++)
 
455
        for (tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++)
496
456
                nchars += strlen(tmp->line) + 1;
497
457
 
498
 
        if(cu->str) MEM_freeN(cu->str);
499
 
        if(cu->strinfo) MEM_freeN(cu->strinfo); 
 
458
        if (cu->str) MEM_freeN(cu->str);
 
459
        if (cu->strinfo) MEM_freeN(cu->strinfo);        
500
460
 
501
461
        cu->str= MEM_callocN(nchars+4, "str");
502
462
        cu->strinfo= MEM_callocN((nchars+4)*sizeof(CharInfo), "strinfo");
505
465
        cu->len= 0;
506
466
        cu->pos= 0;
507
467
        
508
 
        for(tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++) {
 
468
        for (tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++) {
509
469
                strcat(cu->str, tmp->line);
510
470
                cu->len+= strlen(tmp->line);
511
471
 
512
 
                if(tmp->next) {
 
472
                if (tmp->next) {
513
473
                        strcat(cu->str, "\n");
514
474
                        cu->len++;
515
475
                }
527
487
        float offset[3];
528
488
        int linenum= 0;
529
489
 
530
 
        if(!text || !text->lines.first) return;
 
490
        if (!text || !text->lines.first) return;
531
491
 
532
 
        if(split_lines) {
533
 
                for(line=text->lines.first; line; line=line->next) {
 
492
        if (split_lines) {
 
493
                for (line=text->lines.first; line; line=line->next) {
534
494
                        /* skip lines with no text, but still make space for them */
535
 
                        if(line->line[0] == '\0') {
 
495
                        if (line->line[0] == '\0') {
536
496
                                linenum++;
537
497
                                continue;
538
498
                        }
542
502
                        offset[1] = -linenum;
543
503
                        offset[2] = 0;
544
504
        
545
 
                        if(rv3d)
 
505
                        if (rv3d)
546
506
                                mul_mat3_m4_v3(rv3d->viewinv, offset);
547
507
 
548
508
                        txt_add_object(C, line, 1, offset);
564
524
static short next_word(Curve *cu)
565
525
{
566
526
        short s;
567
 
        for(s=cu->pos; (cu->str[s]) && (cu->str[s]!=' ') && (cu->str[s]!='\n') &&
 
527
        for (s=cu->pos; (cu->str[s]) && (cu->str[s]!=' ') && (cu->str[s]!='\n') &&
568
528
                                        (cu->str[s]!=1) && (cu->str[s]!='\r'); s++);
569
 
        if(cu->str[s]) return(s+1); else return(s);
 
529
        if (cu->str[s]) return(s+1); else return(s);
570
530
}
571
531
 
572
532
static short prev_word(Curve *cu)
573
533
{
574
534
        short s;
575
535
        
576
 
        if(cu->pos==0) return(0);
577
 
        for(s=cu->pos-2; (cu->str[s]) && (cu->str[s]!=' ') && (cu->str[s]!='\n') &&
 
536
        if (cu->pos==0) return(0);
 
537
        for (s=cu->pos-2; (cu->str[s]) && (cu->str[s]!=' ') && (cu->str[s]!='\n') &&
578
538
                                        (cu->str[s]!=1) && (cu->str[s]!='\r'); s--);
579
 
        if(cu->str[s]) return(s+1); else return(s);
 
539
        if (cu->str[s]) return(s+1); else return(s);
580
540
}
581
541
 
582
542
static int kill_selection(Object *obedit, int ins)      /* 1 == new character */
588
548
        int getfrom;
589
549
 
590
550
        direction = BKE_font_getselection(obedit, &selstart, &selend);
591
 
        if(direction) {
 
551
        if (direction) {
592
552
                int size;
593
 
                if(ins) offset = 1;
594
 
                if(cu->pos >= selstart) cu->pos = selstart+offset;
595
 
                if((direction == -1) && ins) {
 
553
                if (ins) offset = 1;
 
554
                if (cu->pos >= selstart) cu->pos = selstart+offset;
 
555
                if ((direction == -1) && ins) {
596
556
                        selstart++;
597
557
                        selend++;
598
558
                }
599
559
                getfrom = selend+offset;
600
 
                if(ins==0) getfrom++;
 
560
                if (ins==0) getfrom++;
601
561
                size = (cu->len * sizeof(wchar_t)) - (selstart * sizeof(wchar_t)) + (offset*sizeof(wchar_t));
602
562
                memmove(ef->textbuf+selstart, ef->textbuf+getfrom, size);
603
563
                memmove(ef->textbufinfo+selstart, ef->textbufinfo+getfrom, ((cu->len-selstart)+offset)*sizeof(CharInfo));
617
577
        {CU_CHINFO_SMALLCAPS, "SMALL_CAPS", 0, "Small Caps", ""},
618
578
        {0, NULL, 0, NULL, NULL}};
619
579
 
620
 
static int set_style(bContext *C, int style, int clear)
 
580
static int set_style(bContext *C, const int style, const int clear)
621
581
{
622
582
        Object *obedit= CTX_data_edit_object(C);
623
583
        Curve *cu= obedit->data;
624
584
        EditFont *ef= cu->editfont;
625
585
        int i, selstart, selend;
626
586
 
627
 
        if(!BKE_font_getselection(obedit, &selstart, &selend))
 
587
        if (!BKE_font_getselection(obedit, &selstart, &selend))
628
588
                return OPERATOR_CANCELLED;
629
589
 
630
 
        for(i=selstart; i<=selend; i++) {
631
 
                if(clear)
 
590
        for (i=selstart; i<=selend; i++) {
 
591
                if (clear)
632
592
                        ef->textbufinfo[i].flag &= ~style;
633
593
                else
634
594
                        ef->textbufinfo[i].flag |= style;
635
595
        }
636
596
 
637
 
        DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
 
597
        DAG_id_tag_update(obedit->data, 0);
638
598
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
639
599
 
640
600
        return OPERATOR_FINISHED;
642
602
 
643
603
static int set_style_exec(bContext *C, wmOperator *op)
644
604
{
645
 
        int style, clear;
646
 
 
647
 
        style= RNA_enum_get(op->ptr, "style");
648
 
        clear= RNA_enum_get(op->ptr, "clear");
 
605
        const int style= RNA_enum_get(op->ptr, "style");
 
606
        const int clear= RNA_boolean_get(op->ptr, "clear");
649
607
 
650
608
        return set_style(C, style, clear);
651
609
}
653
611
void FONT_OT_style_set(wmOperatorType *ot)
654
612
{
655
613
        /* identifiers */
656
 
        ot->name= "Set Style";
657
 
        ot->description= "Set font style";
658
 
        ot->idname= "FONT_OT_style_set";
 
614
        ot->name = "Set Style";
 
615
        ot->description = "Set font style";
 
616
        ot->idname = "FONT_OT_style_set";
659
617
        
660
618
        /* api callbacks */
661
 
        ot->exec= set_style_exec;
662
 
        ot->poll= ED_operator_editfont;
 
619
        ot->exec = set_style_exec;
 
620
        ot->poll = ED_operator_editfont;
663
621
        
664
622
        /* flags */
665
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
623
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
666
624
 
667
625
        /* properties */
668
 
        RNA_def_enum(ot->srna, "style", style_items, CU_CHINFO_BOLD, "Style", "Style to set selection to.");
669
 
        RNA_def_boolean(ot->srna, "clear", 0, "Clear", "Clear style rather than setting it.");
 
626
        RNA_def_enum(ot->srna, "style", style_items, CU_CHINFO_BOLD, "Style", "Style to set selection to");
 
627
        RNA_def_boolean(ot->srna, "clear", 0, "Clear", "Clear style rather than setting it");
670
628
}
671
629
 
672
630
/******************* toggle style operator ********************/
677
635
        Curve *cu= obedit->data;
678
636
        int style, clear, selstart, selend;
679
637
 
680
 
        if(!BKE_font_getselection(obedit, &selstart, &selend))
 
638
        if (!BKE_font_getselection(obedit, &selstart, &selend))
681
639
                return OPERATOR_CANCELLED;
682
640
        
683
641
        style= RNA_enum_get(op->ptr, "style");
691
649
void FONT_OT_style_toggle(wmOperatorType *ot)
692
650
{
693
651
        /* identifiers */
694
 
        ot->name= "Toggle Style";
695
 
        ot->description= "Toggle font style";
696
 
        ot->idname= "FONT_OT_style_toggle";
 
652
        ot->name = "Toggle Style";
 
653
        ot->description = "Toggle font style";
 
654
        ot->idname = "FONT_OT_style_toggle";
697
655
        
698
656
        /* api callbacks */
699
 
        ot->exec= toggle_style_exec;
700
 
        ot->poll= ED_operator_editfont;
 
657
        ot->exec = toggle_style_exec;
 
658
        ot->poll = ED_operator_editfont;
701
659
        
702
660
        /* flags */
703
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
661
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
704
662
 
705
663
        /* properties */
706
 
        RNA_def_enum(ot->srna, "style", style_items, CU_CHINFO_BOLD, "Style", "Style to set selection to.");
 
664
        RNA_def_enum(ot->srna, "style", style_items, CU_CHINFO_BOLD, "Style", "Style to set selection to");
707
665
}
708
666
 
709
667
/******************* copy text operator ********************/
712
670
{
713
671
        int selstart, selend;
714
672
        
715
 
        if(BKE_font_getselection(obedit, &selstart, &selend)) {
 
673
        if (BKE_font_getselection(obedit, &selstart, &selend)) {
716
674
                Curve *cu= obedit->data;
717
675
                EditFont *ef= cu->editfont;
718
676
                
722
680
        }
723
681
}
724
682
 
725
 
static int copy_text_exec(bContext *C, wmOperator *op)
 
683
static int copy_text_exec(bContext *C, wmOperator *UNUSED(op))
726
684
{
727
685
        Object *obedit= CTX_data_edit_object(C);
728
686
 
734
692
void FONT_OT_text_copy(wmOperatorType *ot)
735
693
{
736
694
        /* identifiers */
737
 
        ot->name= "Copy Text";
738
 
        ot->description= "Copy selected text to clipboard";
739
 
        ot->idname= "FONT_OT_text_copy";
 
695
        ot->name = "Copy Text";
 
696
        ot->description = "Copy selected text to clipboard";
 
697
        ot->idname = "FONT_OT_text_copy";
740
698
        
741
699
        /* api callbacks */
742
 
        ot->exec= copy_text_exec;
743
 
        ot->poll= ED_operator_editfont;
 
700
        ot->exec = copy_text_exec;
 
701
        ot->poll = ED_operator_editfont;
744
702
}
745
703
 
746
704
/******************* cut text operator ********************/
747
705
 
748
 
static int cut_text_exec(bContext *C, wmOperator *op)
 
706
static int cut_text_exec(bContext *C, wmOperator *UNUSED(op))
749
707
{
750
708
        Scene *scene= CTX_data_scene(C);
751
709
        Object *obedit= CTX_data_edit_object(C);
752
710
        int selstart, selend;
753
711
 
754
 
        if(!BKE_font_getselection(obedit, &selstart, &selend))
 
712
        if (!BKE_font_getselection(obedit, &selstart, &selend))
755
713
                return OPERATOR_CANCELLED;
756
714
 
757
715
        copy_selection(obedit);
758
716
        kill_selection(obedit, 0);
759
717
 
760
 
        text_update_edited(C, scene, obedit, 1, 0);
 
718
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
761
719
 
762
720
        return OPERATOR_FINISHED;
763
721
}
765
723
void FONT_OT_text_cut(wmOperatorType *ot)
766
724
{
767
725
        /* identifiers */
768
 
        ot->name= "Cut Text";
769
 
        ot->description= "Cut selected text to clipboard";
770
 
        ot->idname= "FONT_OT_text_cut";
 
726
        ot->name = "Cut Text";
 
727
        ot->description = "Cut selected text to clipboard";
 
728
        ot->idname = "FONT_OT_text_cut";
771
729
        
772
730
        /* api callbacks */
773
 
        ot->exec= cut_text_exec;
774
 
        ot->poll= ED_operator_editfont;
 
731
        ot->exec = cut_text_exec;
 
732
        ot->poll = ED_operator_editfont;
775
733
 
776
734
        /* flags */
777
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
735
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
778
736
}
779
737
 
780
738
/******************* paste text operator ********************/
786
744
        int len= wcslen(ef->copybuf);
787
745
 
788
746
        // Verify that the copy buffer => [copy buffer len] + cu->len < MAXTEXT
789
 
        if(cu->len + len <= MAXTEXT) {
790
 
                if(len) {       
 
747
        if (cu->len + len <= MAXTEXT) {
 
748
                if (len) {      
791
749
                        int size = (cu->len * sizeof(wchar_t)) - (cu->pos*sizeof(wchar_t)) + sizeof(wchar_t);
792
750
                        memmove(ef->textbuf+cu->pos+len, ef->textbuf+cu->pos, size);
793
751
                        memcpy(ef->textbuf+cu->pos, ef->copybuf, len * sizeof(wchar_t));
802
760
                }
803
761
        }
804
762
        else
805
 
                BKE_report(reports, RPT_WARNING, "Text too long.");
 
763
                BKE_report(reports, RPT_WARNING, "Text too long");
806
764
        
807
765
        return 0;
808
766
}
812
770
        Scene *scene= CTX_data_scene(C);
813
771
        Object *obedit= CTX_data_edit_object(C);
814
772
 
815
 
        if(!paste_selection(obedit, op->reports))
 
773
        if (!paste_selection(obedit, op->reports))
816
774
                return OPERATOR_CANCELLED;
817
775
 
818
 
        text_update_edited(C, scene, obedit, 1, 0);
 
776
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
819
777
 
820
778
        return OPERATOR_FINISHED;
821
779
}
823
781
void FONT_OT_text_paste(wmOperatorType *ot)
824
782
{
825
783
        /* identifiers */
826
 
        ot->name= "Paste Text";
827
 
        ot->description= "Paste text from clipboard";
828
 
        ot->idname= "FONT_OT_text_paste";
 
784
        ot->name = "Paste Text";
 
785
        ot->description = "Paste text from clipboard";
 
786
        ot->idname = "FONT_OT_text_paste";
829
787
        
830
788
        /* api callbacks */
831
 
        ot->exec= paste_text_exec;
832
 
        ot->poll= ED_operator_editfont;
 
789
        ot->exec = paste_text_exec;
 
790
        ot->poll = ED_operator_editfont;
833
791
 
834
792
        /* flags */
835
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
793
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
836
794
}
837
795
 
838
796
/************************ move operator ************************/
856
814
        Object *obedit= CTX_data_edit_object(C);
857
815
        Curve *cu= obedit->data;
858
816
        EditFont *ef= cu->editfont;
859
 
        int cursmove= 0;
 
817
        int cursmove= -1;
860
818
 
861
819
        switch(type) {
862
820
                case LINE_BEGIN:
863
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
864
 
                        while(cu->pos>0) {
865
 
                                if(ef->textbuf[cu->pos-1]=='\n') break;
866
 
                                if(ef->textbufinfo[cu->pos-1].flag & CU_CHINFO_WRAP) break;                             
 
821
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
822
                        while (cu->pos>0) {
 
823
                                if (ef->textbuf[cu->pos-1]=='\n') break;
 
824
                                if (ef->textbufinfo[cu->pos-1].flag & CU_CHINFO_WRAP) break;                            
867
825
                                cu->pos--;
868
826
                        }               
869
827
                        cursmove=FO_CURS;
870
828
                        break;
871
829
                        
872
830
                case LINE_END:
873
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;                
874
 
                        while(cu->pos<cu->len) {
875
 
                                if(ef->textbuf[cu->pos]==0) break;
876
 
                                if(ef->textbuf[cu->pos]=='\n') break;
877
 
                                if(ef->textbufinfo[cu->pos].flag & CU_CHINFO_WRAP ) break;
 
831
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;               
 
832
                        while (cu->pos<cu->len) {
 
833
                                if (ef->textbuf[cu->pos]==0) break;
 
834
                                if (ef->textbuf[cu->pos]=='\n') break;
 
835
                                if (ef->textbufinfo[cu->pos].flag & CU_CHINFO_WRAP ) break;
878
836
                                cu->pos++;
879
837
                        }
880
838
                        cursmove=FO_CURS;
881
839
                        break;
882
840
 
883
841
                case PREV_WORD:
884
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
842
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
885
843
                        cu->pos= prev_word(cu);
886
844
                        cursmove= FO_CURS;
887
845
                        break;
888
846
 
889
847
                case NEXT_WORD:
890
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
848
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
891
849
                        cu->pos= next_word(cu);
892
850
                        cursmove= FO_CURS;                              
893
851
                        break;
894
852
 
895
853
                case PREV_CHAR:
896
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
854
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
897
855
                        cu->pos--;
898
856
                        cursmove=FO_CURS;
899
857
                        break;
900
858
 
901
859
                case NEXT_CHAR: 
902
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
860
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
903
861
                        cu->pos++;
904
862
                        cursmove= FO_CURS;                              
905
863
 
906
864
                        break;
907
865
 
908
866
                case PREV_LINE:
909
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
867
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
910
868
                        cursmove=FO_CURSUP;
911
869
                        break;
912
870
                        
913
871
                case NEXT_LINE:
914
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
872
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
915
873
                        cursmove= FO_CURSDOWN;
916
874
                        break;
917
875
 
918
876
                case PREV_PAGE:
919
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
877
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
920
878
                        cursmove=FO_PAGEUP;
921
879
                        break;
922
880
 
923
881
                case NEXT_PAGE:
924
 
                        if((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
882
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
925
883
                        cursmove=FO_PAGEDOWN;
926
884
                        break;
927
885
        }
928
886
                
929
 
        if(!cursmove)
 
887
        if (cursmove == -1)
930
888
                return OPERATOR_CANCELLED;
931
889
 
932
 
        if(select == 0) {
933
 
                if(cu->selstart) {
 
890
        if (select == 0) {
 
891
                if (cu->selstart) {
 
892
                        struct Main *bmain= CTX_data_main(C);
934
893
                        cu->selstart = cu->selend = 0;
935
894
                        update_string(cu);
936
 
                        BKE_text_to_curve(scene, obedit, FO_SELCHANGE);
 
895
                        BKE_text_to_curve(bmain, scene, obedit, FO_SELCHANGE);
937
896
                }
938
897
        }
939
898
 
940
 
        if(cu->pos>cu->len) cu->pos= cu->len;
941
 
        else if(cu->pos>=MAXTEXT) cu->pos= MAXTEXT;
942
 
        else if(cu->pos<0) cu->pos= 0;
 
899
        if (cu->pos>cu->len) cu->pos= cu->len;
 
900
        else if (cu->pos>=MAXTEXT) cu->pos= MAXTEXT;
 
901
        else if (cu->pos<0) cu->pos= 0;
943
902
 
944
903
        text_update_edited(C, scene, obedit, select, cursmove);
945
904
 
946
 
        if(select)
 
905
        if (select)
947
906
                cu->selend = cu->pos;
948
907
 
949
908
        return OPERATOR_FINISHED;
959
918
void FONT_OT_move(wmOperatorType *ot)
960
919
{
961
920
        /* identifiers */
962
 
        ot->name= "Move Cursor";
963
 
        ot->description= "Move cursor to position type";
964
 
        ot->idname= "FONT_OT_move";
 
921
        ot->name = "Move Cursor";
 
922
        ot->description = "Move cursor to position type";
 
923
        ot->idname = "FONT_OT_move";
965
924
        
966
925
        /* api callbacks */
967
 
        ot->exec= move_exec;
968
 
        ot->poll= ED_operator_editfont;
 
926
        ot->exec = move_exec;
 
927
        ot->poll = ED_operator_editfont;
969
928
 
970
929
        /* flags */
971
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
930
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
972
931
 
973
932
        /* properties */
974
 
        RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to.");
 
933
        RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to");
975
934
}
976
935
 
977
936
/******************* move select operator ********************/
986
945
void FONT_OT_move_select(wmOperatorType *ot)
987
946
{
988
947
        /* identifiers */
989
 
        ot->name= "Move Select";
990
 
        ot->description= "Make selection from current cursor position to new cursor position type";
991
 
        ot->idname= "FONT_OT_move_select";
 
948
        ot->name = "Move Select";
 
949
        ot->description = "Make selection from current cursor position to new cursor position type";
 
950
        ot->idname = "FONT_OT_move_select";
992
951
        
993
952
        /* api callbacks */
994
 
        ot->exec= move_select_exec;
995
 
        ot->poll= ED_operator_editfont;
 
953
        ot->exec = move_select_exec;
 
954
        ot->poll = ED_operator_editfont;
996
955
 
997
956
        /* flags */
998
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
957
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
999
958
 
1000
959
        /* properties */
1001
 
        RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to, to make a selection.");
 
960
        RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to, to make a selection");
1002
961
}
1003
962
 
1004
963
/************************* change spacing **********************/
1015
974
        kern += delta;
1016
975
        CLAMP(kern, -20, 20);
1017
976
 
1018
 
        if(ef->textbufinfo[cu->pos-1].kern == kern)
 
977
        if (ef->textbufinfo[cu->pos-1].kern == kern)
1019
978
                return OPERATOR_CANCELLED;
1020
979
 
1021
980
        ef->textbufinfo[cu->pos-1].kern = kern;
1022
981
 
1023
 
        text_update_edited(C, scene, obedit, 1, 0);
 
982
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1024
983
 
1025
984
        return OPERATOR_FINISHED;
1026
985
}
1028
987
void FONT_OT_change_spacing(wmOperatorType *ot)
1029
988
{
1030
989
        /* identifiers */
1031
 
        ot->name= "Change Spacing";
1032
 
        ot->description= "Change font spacing";
1033
 
        ot->idname= "FONT_OT_change_spacing";
 
990
        ot->name = "Change Spacing";
 
991
        ot->description = "Change font spacing";
 
992
        ot->idname = "FONT_OT_change_spacing";
1034
993
        
1035
994
        /* api callbacks */
1036
 
        ot->exec= change_spacing_exec;
1037
 
        ot->poll= ED_operator_editfont;
 
995
        ot->exec = change_spacing_exec;
 
996
        ot->poll = ED_operator_editfont;
1038
997
 
1039
998
        /* flags */
1040
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
999
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1041
1000
 
1042
1001
        /* properties */
1043
 
        RNA_def_int(ot->srna, "delta", 1, -20, 20, "Delta", "Amount to decrease or increasing character spacing with.", -20, 20);
 
1002
        RNA_def_int(ot->srna, "delta", 1, -20, 20, "Delta", "Amount to decrease or increase character spacing with", -20, 20);
1044
1003
}
1045
1004
 
1046
1005
/************************* change character **********************/
1053
1012
        EditFont *ef= cu->editfont;
1054
1013
        int character, delta= RNA_int_get(op->ptr, "delta");
1055
1014
 
1056
 
        if(cu->pos <= 0)
 
1015
        if (cu->pos <= 0)
1057
1016
                return OPERATOR_CANCELLED;
1058
1017
 
1059
1018
        character= ef->textbuf[cu->pos - 1];
1060
1019
        character += delta;
1061
1020
        CLAMP(character, 0, 255);
1062
1021
 
1063
 
        if(character == ef->textbuf[cu->pos - 1])
 
1022
        if (character == ef->textbuf[cu->pos - 1])
1064
1023
                return OPERATOR_CANCELLED;
1065
1024
 
1066
1025
        ef->textbuf[cu->pos - 1]= character;
1067
1026
 
1068
 
        text_update_edited(C, scene, obedit, 1, 0);
 
1027
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1069
1028
 
1070
1029
        return OPERATOR_FINISHED;
1071
1030
}
1073
1032
void FONT_OT_change_character(wmOperatorType *ot)
1074
1033
{
1075
1034
        /* identifiers */
1076
 
        ot->name= "Change Character";
1077
 
        ot->description= "Change font character code";
1078
 
        ot->idname= "FONT_OT_change_character";
 
1035
        ot->name = "Change Character";
 
1036
        ot->description = "Change font character code";
 
1037
        ot->idname = "FONT_OT_change_character";
1079
1038
        
1080
1039
        /* api callbacks */
1081
 
        ot->exec= change_character_exec;
1082
 
        ot->poll= ED_operator_editfont;
 
1040
        ot->exec = change_character_exec;
 
1041
        ot->poll = ED_operator_editfont;
1083
1042
 
1084
1043
        /* flags */
1085
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1044
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1086
1045
 
1087
1046
        /* properties */
1088
 
        RNA_def_int(ot->srna, "delta", 1, -255, 255, "Delta", "Number to increase or decrease character code with.", -255, 255);
 
1047
        RNA_def_int(ot->srna, "delta", 1, -255, 255, "Delta", "Number to increase or decrease character code with", -255, 255);
1089
1048
}
1090
1049
 
1091
1050
/******************* line break operator ********************/
1096
1055
        Object *obedit= CTX_data_edit_object(C);
1097
1056
        Curve *cu= obedit->data;
1098
1057
        EditFont *ef= cu->editfont;
1099
 
        int ctrl= RNA_enum_get(op->ptr, "ctrl");
 
1058
        const int ctrl= RNA_boolean_get(op->ptr, "ctrl");
1100
1059
 
1101
 
        if(ctrl) {
 
1060
        if (ctrl) {
1102
1061
                insert_into_textbuf(obedit, 1);
1103
 
                if(ef->textbuf[cu->pos]!='\n')
 
1062
                if (ef->textbuf[cu->pos]!='\n')
1104
1063
                        insert_into_textbuf(obedit, '\n');
1105
1064
        }
1106
1065
        else
1108
1067
 
1109
1068
        cu->selstart = cu->selend = 0;
1110
1069
 
1111
 
        text_update_edited(C, scene, obedit, 1, 0);
 
1070
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1112
1071
 
1113
1072
        return OPERATOR_FINISHED;
1114
1073
}
1116
1075
void FONT_OT_line_break(wmOperatorType *ot)
1117
1076
{
1118
1077
        /* identifiers */
1119
 
        ot->name= "Line Break";
1120
 
        ot->description= "Insert line break at cursor position";
1121
 
        ot->idname= "FONT_OT_line_break";
 
1078
        ot->name = "Line Break";
 
1079
        ot->description = "Insert line break at cursor position";
 
1080
        ot->idname = "FONT_OT_line_break";
1122
1081
        
1123
1082
        /* api callbacks */
1124
 
        ot->exec= line_break_exec;
1125
 
        ot->poll= ED_operator_editfont;
 
1083
        ot->exec = line_break_exec;
 
1084
        ot->poll = ED_operator_editfont;
1126
1085
 
1127
1086
        /* flags */
1128
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1087
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1129
1088
 
1130
1089
        /* properties */
1131
1090
        RNA_def_boolean(ot->srna, "ctrl", 0, "Ctrl", ""); // XXX what is this?
1150
1109
        EditFont *ef= cu->editfont;
1151
1110
        int x, selstart, selend, type= RNA_enum_get(op->ptr, "type");
1152
1111
 
1153
 
        if(cu->len == 0)
 
1112
        if (cu->len == 0)
1154
1113
                return OPERATOR_CANCELLED;
1155
1114
 
1156
 
        if(BKE_font_getselection(obedit, &selstart, &selend)) {
1157
 
                if(type == DEL_NEXT_SEL) type= DEL_SELECTION;
1158
 
                else if(type == DEL_PREV_SEL) type= DEL_SELECTION;
 
1115
        if (BKE_font_getselection(obedit, &selstart, &selend)) {
 
1116
                if (type == DEL_NEXT_SEL) type= DEL_SELECTION;
 
1117
                else if (type == DEL_PREV_SEL) type= DEL_SELECTION;
1159
1118
        }
1160
1119
        else {
1161
 
                if(type == DEL_NEXT_SEL) type= DEL_NEXT_CHAR;
1162
 
                else if(type == DEL_PREV_SEL) type= DEL_PREV_CHAR;
 
1120
                if (type == DEL_NEXT_SEL) type= DEL_NEXT_CHAR;
 
1121
                else if (type == DEL_PREV_SEL) type= DEL_PREV_CHAR;
1163
1122
        }
1164
1123
 
1165
1124
        switch(type) {
1168
1127
                        ef->textbuf[0]= 0;
1169
1128
                        break;
1170
1129
                case DEL_SELECTION:
1171
 
                        if(!kill_selection(obedit, 0))
 
1130
                        if (!kill_selection(obedit, 0))
1172
1131
                                return OPERATOR_CANCELLED;
1173
1132
                        break;
1174
1133
                case DEL_PREV_CHAR:
1175
 
                        if(cu->pos<=0)
 
1134
                        if (cu->pos<=0)
1176
1135
                                return OPERATOR_CANCELLED;
1177
1136
 
1178
 
                        for(x=cu->pos;x<=cu->len;x++)
 
1137
                        for (x=cu->pos;x<=cu->len;x++)
1179
1138
                                ef->textbuf[x-1]= ef->textbuf[x];
1180
 
                        for(x=cu->pos;x<=cu->len;x++)
 
1139
                        for (x=cu->pos;x<=cu->len;x++)
1181
1140
                                ef->textbufinfo[x-1]= ef->textbufinfo[x];                                       
1182
1141
 
1183
1142
                        cu->pos--;
1184
1143
                        ef->textbuf[--cu->len]='\0';
1185
1144
                        break;
1186
1145
                case DEL_NEXT_CHAR:
1187
 
                        if(cu->pos>=cu->len)
 
1146
                        if (cu->pos>=cu->len)
1188
1147
                                return OPERATOR_CANCELLED;
1189
1148
 
1190
 
                        for(x=cu->pos;x<cu->len;x++)
 
1149
                        for (x=cu->pos;x<cu->len;x++)
1191
1150
                                ef->textbuf[x]= ef->textbuf[x+1];
1192
 
                        for(x=cu->pos;x<cu->len;x++)
 
1151
                        for (x=cu->pos;x<cu->len;x++)
1193
1152
                                ef->textbufinfo[x]= ef->textbufinfo[x+1];                                       
1194
1153
 
1195
1154
                        ef->textbuf[--cu->len]='\0';
1198
1157
                        return OPERATOR_CANCELLED;
1199
1158
        }
1200
1159
 
1201
 
        text_update_edited(C, scene, obedit, 1, 0);
 
1160
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1202
1161
 
1203
1162
        return OPERATOR_FINISHED;
1204
1163
}
1206
1165
void FONT_OT_delete(wmOperatorType *ot)
1207
1166
{
1208
1167
        /* identifiers */
1209
 
        ot->name= "Delete";
1210
 
        ot->description= "Delete text by cursor position";
1211
 
        ot->idname= "FONT_OT_delete";
 
1168
        ot->name = "Delete";
 
1169
        ot->description = "Delete text by cursor position";
 
1170
        ot->idname = "FONT_OT_delete";
1212
1171
        
1213
1172
        /* api callbacks */
1214
 
        ot->exec= delete_exec;
1215
 
        ot->poll= ED_operator_editfont;
 
1173
        ot->exec = delete_exec;
 
1174
        ot->poll = ED_operator_editfont;
1216
1175
 
1217
1176
        /* flags */
1218
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1177
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1219
1178
 
1220
1179
        /* properties */
1221
 
        RNA_def_enum(ot->srna, "type", delete_type_items, DEL_ALL, "Type", "Which part of the text to delete.");
 
1180
        RNA_def_enum(ot->srna, "type", delete_type_items, DEL_ALL, "Type", "Which part of the text to delete");
1222
1181
}
1223
1182
 
1224
1183
/*********************** insert text operator *************************/
1228
1187
        Scene *scene= CTX_data_scene(C);
1229
1188
        Object *obedit= CTX_data_edit_object(C);
1230
1189
        char *inserted_utf8;
1231
 
        wchar_t *inserted_text, first;
 
1190
        wchar_t *inserted_text;
1232
1191
        int a, len;
1233
1192
 
1234
 
        if(!RNA_property_is_set(op->ptr, "text"))
 
1193
        if (!RNA_struct_property_is_set(op->ptr, "text"))
1235
1194
                return OPERATOR_CANCELLED;
1236
1195
        
1237
1196
        inserted_utf8= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
1238
 
        len= strlen(inserted_utf8);
 
1197
        len= BLI_strlen_utf8(inserted_utf8);
1239
1198
 
1240
1199
        inserted_text= MEM_callocN(sizeof(wchar_t)*(len+1), "FONT_insert_text");
1241
 
        utf8towchar(inserted_text, inserted_utf8);
1242
 
        first= inserted_text[0];
 
1200
        BLI_strncpy_wchar_from_utf8(inserted_text, inserted_utf8, len+1);
1243
1201
 
1244
 
        for(a=0; a<len; a++)
 
1202
        for (a=0; a<len; a++)
1245
1203
                insert_into_textbuf(obedit, inserted_text[a]);
1246
1204
 
1247
1205
        MEM_freeN(inserted_text);
1248
1206
        MEM_freeN(inserted_utf8);
1249
1207
 
1250
1208
        kill_selection(obedit, 1);
1251
 
        text_update_edited(C, scene, obedit, 1, 0);
 
1209
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1252
1210
 
1253
1211
        return OPERATOR_FINISHED;
1254
1212
}
1265
1223
        int event= evt->type, val= evt->val;
1266
1224
        wchar_t inserted_text[2]= {0};
1267
1225
 
1268
 
        if(RNA_property_is_set(op->ptr, "text"))
 
1226
        if (RNA_struct_property_is_set(op->ptr, "text"))
1269
1227
                return insert_text_exec(C, op);
 
1228
 
 
1229
        if (RNA_struct_property_is_set(op->ptr, "accent")) {
 
1230
                if (cu->len!=0 && cu->pos>0)
 
1231
                        accentcode= 1;
 
1232
                return OPERATOR_FINISHED;
 
1233
        }
1270
1234
        
1271
1235
        /* tab should exit editmode, but we allow it to be typed using modifier keys */
1272
 
        if(event==TABKEY) {
1273
 
                if((alt||ctrl||shift) == 0)
 
1236
        if (event==TABKEY) {
 
1237
                if ((alt||ctrl||shift) == 0)
1274
1238
                        return OPERATOR_PASS_THROUGH;
1275
1239
                else
1276
1240
                        ascii= 9;
1277
1241
        }
1278
 
        else if(event==BACKSPACEKEY)
 
1242
        else if (event==BACKSPACEKEY)
1279
1243
                ascii= 0;
1280
1244
 
1281
 
        if(val && ascii) {
 
1245
        if (val && (ascii || evt->utf8_buf[0])) {
1282
1246
                /* handle case like TAB (== 9) */
1283
 
                if((ascii > 31 && ascii < 254 && ascii != 127) || (ascii==13) || (ascii==10) || (ascii==8)) {
1284
 
                        if(accentcode) {
1285
 
                                if(cu->pos>0) {
 
1247
                if (     (ascii > 31 && ascii < 254 && ascii != 127) ||
 
1248
                        (ascii==13) ||
 
1249
                        (ascii==10) ||
 
1250
                        (ascii==8)  ||
 
1251
                        (evt->utf8_buf[0]))
 
1252
                {
 
1253
 
 
1254
                        if (evt->utf8_buf[0]) {
 
1255
                                BLI_strncpy_wchar_from_utf8(inserted_text, evt->utf8_buf, 1);
 
1256
                                ascii= inserted_text[0];
 
1257
                                insert_into_textbuf(obedit, ascii);
 
1258
                                accentcode= 0;
 
1259
                        }
 
1260
                        else if (accentcode) {
 
1261
                                if (cu->pos>0) {
1286
1262
                                        inserted_text[0]= findaccent(ef->textbuf[cu->pos-1], ascii);
1287
1263
                                        ef->textbuf[cu->pos-1]= inserted_text[0];
1288
1264
                                }
1289
1265
                                accentcode= 0;
1290
1266
                        }
1291
 
                        else if(cu->len<MAXTEXT-1) {
1292
 
                                if(alt) {
 
1267
                        else if (cu->len<MAXTEXT-1) {
 
1268
                                if (alt) {
1293
1269
                                        /* might become obsolete, apple has default values for this, other OS's too? */
1294
 
                                        if(ascii=='t') ascii= 137;
1295
 
                                        else if(ascii=='c') ascii= 169;
1296
 
                                        else if(ascii=='f') ascii= 164;
1297
 
                                        else if(ascii=='g') ascii= 176;
1298
 
                                        else if(ascii=='l') ascii= 163;
1299
 
                                        else if(ascii=='r') ascii= 174;
1300
 
                                        else if(ascii=='s') ascii= 223;
1301
 
                                        else if(ascii=='y') ascii= 165;
1302
 
                                        else if(ascii=='.') ascii= 138;
1303
 
                                        else if(ascii=='1') ascii= 185;
1304
 
                                        else if(ascii=='2') ascii= 178;
1305
 
                                        else if(ascii=='3') ascii= 179;
1306
 
                                        else if(ascii=='%') ascii= 139;
1307
 
                                        else if(ascii=='?') ascii= 191;
1308
 
                                        else if(ascii=='!') ascii= 161;
1309
 
                                        else if(ascii=='x') ascii= 215;
1310
 
                                        else if(ascii=='>') ascii= 187;
1311
 
                                        else if(ascii=='<') ascii= 171;
 
1270
                                        if (ascii=='t') ascii= 137;
 
1271
                                        else if (ascii=='c') ascii= 169;
 
1272
                                        else if (ascii=='f') ascii= 164;
 
1273
                                        else if (ascii=='g') ascii= 176;
 
1274
                                        else if (ascii=='l') ascii= 163;
 
1275
                                        else if (ascii=='r') ascii= 174;
 
1276
                                        else if (ascii=='s') ascii= 223;
 
1277
                                        else if (ascii=='y') ascii= 165;
 
1278
                                        else if (ascii=='.') ascii= 138;
 
1279
                                        else if (ascii=='1') ascii= 185;
 
1280
                                        else if (ascii=='2') ascii= 178;
 
1281
                                        else if (ascii=='3') ascii= 179;
 
1282
                                        else if (ascii=='%') ascii= 139;
 
1283
                                        else if (ascii=='?') ascii= 191;
 
1284
                                        else if (ascii=='!') ascii= 161;
 
1285
                                        else if (ascii=='x') ascii= 215;
 
1286
                                        else if (ascii=='>') ascii= 187;
 
1287
                                        else if (ascii=='<') ascii= 171;
1312
1288
                                }
1313
1289
 
1314
1290
                                inserted_text[0]= ascii;
1316
1292
                        }
1317
1293
                        
1318
1294
                        kill_selection(obedit, 1);
1319
 
                        text_update_edited(C, scene, obedit, 1, 0);
 
1295
                        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1320
1296
                }
1321
1297
                else {
1322
1298
                        inserted_text[0]= ascii;
1323
1299
                        insert_into_textbuf(obedit, ascii);
1324
 
                        text_update_edited(C, scene, obedit, 1, 0);
 
1300
                        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1325
1301
                }
1326
1302
        }
1327
 
        else if(val && event == BACKSPACEKEY) {
1328
 
                if(alt && cu->len!=0 && cu->pos>0)
 
1303
        else if (val && event == BACKSPACEKEY) {
 
1304
                if (alt && cu->len!=0 && cu->pos>0)
1329
1305
                        accentcode= 1;
1330
1306
 
1331
1307
                return OPERATOR_PASS_THROUGH;
1333
1309
        else
1334
1310
                return OPERATOR_PASS_THROUGH;
1335
1311
 
1336
 
        if(inserted_text[0]) {
 
1312
        if (inserted_text[0]) {
1337
1313
                /* store as utf8 in RNA string */
1338
1314
                char inserted_utf8[8] = {0};
1339
1315
 
1340
 
                wcs2utf8s(inserted_utf8, inserted_text);
 
1316
                BLI_strncpy_wchar_as_utf8(inserted_utf8, inserted_text, sizeof(inserted_utf8));
1341
1317
                RNA_string_set(op->ptr, "text", inserted_utf8);
1342
1318
        }
1343
1319
 
 
1320
        /* reset property? */
 
1321
        accentcode= 0;
 
1322
        
1344
1323
        return OPERATOR_FINISHED;
1345
1324
}
1346
1325
 
1347
1326
void FONT_OT_text_insert(wmOperatorType *ot)
1348
1327
{
1349
1328
        /* identifiers */
1350
 
        ot->name= "Insert Text";
1351
 
        ot->description= "Insert text at cursor position";
1352
 
        ot->idname= "FONT_OT_text_insert";
 
1329
        ot->name = "Insert Text";
 
1330
        ot->description = "Insert text at cursor position";
 
1331
        ot->idname = "FONT_OT_text_insert";
1353
1332
        
1354
1333
        /* api callbacks */
1355
 
        ot->exec= insert_text_exec;
1356
 
        ot->invoke= insert_text_invoke;
1357
 
        ot->poll= ED_operator_editfont;
 
1334
        ot->exec = insert_text_exec;
 
1335
        ot->invoke = insert_text_invoke;
 
1336
        ot->poll = ED_operator_editfont;
1358
1337
        
1359
1338
        /* flags */
1360
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1339
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1361
1340
 
1362
1341
        /* properties */
1363
 
        RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position.");
 
1342
        RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position");
 
1343
        RNA_def_boolean(ot->srna, "accent", 0, "Accent mode", "Next typed character will strike through previous, for special character input");
1364
1344
}
1365
1345
 
1366
1346
 
1367
1347
/*********************** textbox add operator *************************/
1368
 
static int textbox_poll(bContext *C)
1369
 
{
1370
 
        Object *ob = CTX_data_active_object(C);
1371
 
        
1372
 
        if (!ED_operator_object_active_editable(C) ) return 0;
1373
 
        if (ob->type != OB_FONT) return 0;
1374
 
        
1375
 
        return 1;
1376
 
}
1377
 
 
1378
 
static int textbox_add_exec(bContext *C, wmOperator *op)
 
1348
static int textbox_add_exec(bContext *C, wmOperator *UNUSED(op))
1379
1349
{
1380
1350
        Object *obedit= CTX_data_active_object(C);
1381
1351
        Curve *cu= obedit->data;
1395
1365
void FONT_OT_textbox_add(wmOperatorType *ot)
1396
1366
{
1397
1367
        /* identifiers */
1398
 
        ot->name= "Add Textbox";
1399
 
        ot->description= "Add a new text box";
1400
 
        ot->idname= "FONT_OT_textbox_add";
 
1368
        ot->name = "Add Textbox";
 
1369
        ot->description = "Add a new text box";
 
1370
        ot->idname = "FONT_OT_textbox_add";
1401
1371
        
1402
1372
        /* api callbacks */
1403
 
        ot->exec= textbox_add_exec;
1404
 
        ot->poll= textbox_poll;
1405
 
        
 
1373
        ot->exec = textbox_add_exec;
 
1374
        ot->poll = ED_operator_object_active_editable_font;
 
1375
 
1406
1376
        /* flags */
1407
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1377
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1408
1378
        
1409
1379
        
1410
1380
}
1438
1408
void FONT_OT_textbox_remove(wmOperatorType *ot)
1439
1409
{
1440
1410
        /* identifiers */
1441
 
        ot->name= "Remove Textbox";
1442
 
        ot->description= "Remove the textbox";
1443
 
        ot->idname= "FONT_OT_textbox_remove";
 
1411
        ot->name = "Remove Textbox";
 
1412
        ot->description = "Remove the textbox";
 
1413
        ot->idname = "FONT_OT_textbox_remove";
1444
1414
        
1445
1415
        /* api callbacks */
1446
 
        ot->exec= textbox_remove_exec;
1447
 
        ot->poll= textbox_poll;
 
1416
        ot->exec = textbox_remove_exec;
 
1417
        ot->poll = ED_operator_object_active_editable_font;
1448
1418
        
1449
1419
        /* flags */
1450
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1451
 
        
1452
 
        RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "The current text box.", 0, INT_MAX);
1453
 
        
1454
 
        
 
1420
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1421
        
 
1422
        RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "The current text box", 0, INT_MAX);
1455
1423
}
1456
1424
 
1457
1425
 
1463
1431
        Curve *cu= obedit->data;
1464
1432
        EditFont *ef= cu->editfont;
1465
1433
        
1466
 
        if(ef==NULL) {
 
1434
        if (ef==NULL) {
1467
1435
                ef= cu->editfont= MEM_callocN(sizeof(EditFont), "editfont");
1468
1436
        
1469
1437
                ef->textbuf= MEM_callocN((MAXTEXT+4)*sizeof(wchar_t), "texteditbuf");
1475
1443
        }
1476
1444
        
1477
1445
        // Convert the original text to wchar_t
1478
 
        utf8towchar(ef->textbuf, cu->str);
 
1446
        BLI_strncpy_wchar_from_utf8(ef->textbuf, cu->str, MAXTEXT+4); /* length is bogus */
1479
1447
        wcscpy(ef->oldstr, ef->textbuf);
1480
1448
                
1481
1449
        cu->len= wcslen(ef->textbuf);
1483
1451
        memcpy(ef->textbufinfo, cu->strinfo, (cu->len)*sizeof(CharInfo));
1484
1452
        memcpy(ef->oldstrinfo, cu->strinfo, (cu->len)*sizeof(CharInfo));
1485
1453
 
1486
 
        if(cu->pos>cu->len) cu->pos= cu->len;
 
1454
        if (cu->pos>cu->len) cu->pos= cu->len;
1487
1455
 
1488
 
        if(cu->pos)
 
1456
        if (cu->pos)
1489
1457
                cu->curinfo = ef->textbufinfo[cu->pos-1];
1490
1458
        else
1491
1459
                cu->curinfo = ef->textbufinfo[0];
1506
1474
        
1507
1475
        update_string(cu);
1508
1476
        
1509
 
        if(cu->strinfo)
 
1477
        if (cu->strinfo)
1510
1478
                MEM_freeN(cu->strinfo);
1511
1479
        cu->strinfo= MEM_callocN((cu->len+4)*sizeof(CharInfo), "texteditinfo");
1512
1480
        memcpy(cu->strinfo, ef->textbufinfo, (cu->len)*sizeof(CharInfo));
1515
1483
        
1516
1484
        /* this memory system is weak... */
1517
1485
        
1518
 
        if(cu->selboxes) {
 
1486
        if (cu->selboxes) {
1519
1487
                MEM_freeN(cu->selboxes);
1520
1488
                cu->selboxes= NULL;
1521
1489
        }
1544
1512
        
1545
1513
        len= wcslen(ef->textbuf);
1546
1514
        str= ef->textbuf;
1547
 
        while(len) {
1548
 
                if(*str>='a' && *str<='z')
 
1515
        while (len) {
 
1516
                if (*str>='a' && *str<='z')
1549
1517
                        *str-= 32;
1550
1518
                len--;
1551
1519
                str++;
1552
1520
        }
1553
1521
        
1554
 
        if(ccase == CASE_LOWER) {
 
1522
        if (ccase == CASE_LOWER) {
1555
1523
                len= wcslen(ef->textbuf);
1556
1524
                str= ef->textbuf;
1557
 
                while(len) {
1558
 
                        if(*str>='A' && *str<='Z') {
 
1525
                while (len) {
 
1526
                        if (*str>='A' && *str<='Z') {
1559
1527
                                *str+= 32;
1560
1528
                        }
1561
1529
                        len--;
1563
1531
                }
1564
1532
        }
1565
1533
 
1566
 
        text_update_edited(C, scene, obedit, 1, 0);
 
1534
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1567
1535
 
1568
1536
        return OPERATOR_FINISHED;
1569
1537
}
1576
1544
void FONT_OT_case_set(wmOperatorType *ot)
1577
1545
{
1578
1546
        /* identifiers */
1579
 
        ot->name= "Set Case";
1580
 
        ot->description= "Set font case";
1581
 
        ot->idname= "FONT_OT_case_set";
 
1547
        ot->name = "Set Case";
 
1548
        ot->description = "Set font case";
 
1549
        ot->idname = "FONT_OT_case_set";
1582
1550
        
1583
1551
        /* api callbacks */
1584
 
        ot->exec= set_case_exec;
1585
 
        ot->poll= ED_operator_editfont;
 
1552
        ot->exec = set_case_exec;
 
1553
        ot->poll = ED_operator_editfont;
1586
1554
 
1587
1555
        /* flags */
1588
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1556
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1589
1557
 
1590
1558
        /* properties */
1591
 
        RNA_def_enum(ot->srna, "case", case_items, CASE_LOWER, "Case", "Lower or upper case.");
 
1559
        RNA_def_enum(ot->srna, "case", case_items, CASE_LOWER, "Case", "Lower or upper case");
1592
1560
}
1593
1561
 
1594
1562
/********************** toggle case operator *********************/
1595
1563
 
1596
 
static int toggle_case_exec(bContext *C, wmOperator *op)
 
1564
static int toggle_case_exec(bContext *C, wmOperator *UNUSED(op))
1597
1565
{
1598
1566
        Object *obedit= CTX_data_edit_object(C);
1599
1567
        Curve *cu= obedit->data;
1603
1571
        
1604
1572
        len= wcslen(ef->textbuf);
1605
1573
        str= ef->textbuf;
1606
 
        while(len) {
1607
 
                if(*str>='a' && *str<='z') {
 
1574
        while (len) {
 
1575
                if (*str>='a' && *str<='z') {
1608
1576
                        ccase= CASE_LOWER;
1609
1577
                        break;
1610
1578
                }
1619
1587
void FONT_OT_case_toggle(wmOperatorType *ot)
1620
1588
{
1621
1589
        /* identifiers */
1622
 
        ot->name= "Toggle Case";
1623
 
        ot->description= "Toggle font case";
1624
 
        ot->idname= "FONT_OT_case_toggle";
 
1590
        ot->name = "Toggle Case";
 
1591
        ot->description = "Toggle font case";
 
1592
        ot->idname = "FONT_OT_case_toggle";
1625
1593
        
1626
1594
        /* api callbacks */
1627
 
        ot->exec= toggle_case_exec;
1628
 
        ot->poll= ED_operator_editfont;
 
1595
        ot->exec = toggle_case_exec;
 
1596
        ot->poll = ED_operator_editfont;
1629
1597
 
1630
1598
        /* flags */
1631
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1599
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1632
1600
}
1633
1601
 
1634
1602
/* **************** Open Font ************** */
1635
1603
 
1636
 
static void open_init(bContext *C, wmOperator *op)
 
1604
static void font_ui_template_init(bContext *C, wmOperator *op)
1637
1605
{
1638
1606
        PropertyPointerRNA *pprop;
1639
1607
        
1641
1609
        uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
1642
1610
}
1643
1611
 
1644
 
static int open_cancel(bContext *C, wmOperator *op)
 
1612
static int font_open_cancel(bContext *UNUSED(C), wmOperator *op)
1645
1613
{
1646
1614
        MEM_freeN(op->customdata);
1647
1615
        op->customdata= NULL;
1648
1616
        return OPERATOR_CANCELLED;
1649
1617
}
1650
1618
 
1651
 
static int open_exec(bContext *C, wmOperator *op)
 
1619
static int font_open_exec(bContext *C, wmOperator *op)
1652
1620
{
1653
 
        Object *ob = CTX_data_active_object(C);
1654
 
        Curve *cu;
 
1621
        struct Main *bmain= CTX_data_main(C);
1655
1622
        VFont *font;
1656
1623
        PropertyPointerRNA *pprop;
1657
1624
        PointerRNA idptr;
1658
 
        char str[FILE_MAX];
1659
 
        
1660
 
        RNA_string_get(op->ptr, "filepath", str);
1661
 
 
1662
 
        font = load_vfont(str);
1663
 
        
1664
 
        if(!font) {
1665
 
                if(op->customdata) MEM_freeN(op->customdata);
 
1625
        char filepath[FILE_MAX];
 
1626
        RNA_string_get(op->ptr, "filepath", filepath);
 
1627
 
 
1628
        font= load_vfont(bmain, filepath);
 
1629
 
 
1630
        if (!font) {
 
1631
                if (op->customdata) MEM_freeN(op->customdata);
1666
1632
                return OPERATOR_CANCELLED;
1667
1633
        }
1668
 
        
1669
 
        if(!op->customdata)
1670
 
                open_init(C, op);
 
1634
 
 
1635
        if (!op->customdata)
 
1636
                font_ui_template_init(C, op);
1671
1637
        
1672
1638
        /* hook into UI */
1673
1639
        pprop= op->customdata;
1674
 
        
1675
 
        if(pprop->prop) {
 
1640
 
 
1641
        if (pprop->prop) {
1676
1642
                /* when creating new ID blocks, use is already 1, but RNA
1677
1643
                 * pointer se also increases user, so this compensates it */
1678
1644
                font->id.us--;
1679
 
                
 
1645
        
1680
1646
                RNA_id_pointer_create(&font->id, &idptr);
1681
1647
                RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
1682
1648
                RNA_property_update(C, &pprop->ptr, pprop->prop);
1683
 
        } else if(ob && ob->type == OB_FONT) {
1684
 
                cu = ob->data;
1685
 
                id_us_min(&cu->vfont->id);
1686
 
                cu->vfont = font;
1687
1649
        }
1688
 
        
1689
 
        DAG_id_flush_update(ob->data, OB_RECALC_DATA);
1690
 
        WM_event_add_notifier(C, NC_GEOM|ND_DATA|NA_EDITED, ob->data);
1691
 
        
 
1650
 
1692
1651
        MEM_freeN(op->customdata);
1693
 
        
 
1652
 
1694
1653
        return OPERATOR_FINISHED;
1695
1654
}
1696
1655
 
1697
 
static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
1656
static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1698
1657
{
1699
 
        Object *ob = CTX_data_active_object(C);
1700
 
        Curve *cu;
1701
1658
        VFont *font=NULL;
1702
1659
        char *path;
1703
 
        if (ob && ob->type == OB_FONT) {
1704
 
                cu = ob->data;
1705
 
                font = cu->vfont;
 
1660
 
 
1661
        PointerRNA idptr;
 
1662
        PropertyPointerRNA *pprop;
 
1663
 
 
1664
        font_ui_template_init(C, op);
 
1665
 
 
1666
        /* hook into UI */
 
1667
        pprop= op->customdata;
 
1668
 
 
1669
        if (pprop->prop) {
 
1670
                idptr= RNA_property_pointer_get((PointerRNA *)pprop, pprop->prop);
 
1671
                font= idptr.id.data;
1706
1672
        }
1707
 
        path = (font && font->name)? font->name: U.fontdir;
1708
 
         
1709
 
        if(RNA_property_is_set(op->ptr, "filepath"))
1710
 
                return open_exec(C, op);
1711
 
        
1712
 
        open_init(C, op);
1713
 
        
 
1673
 
 
1674
        path = (font && strcmp(font->name, FO_BUILTIN_NAME) != 0)? font->name: U.fontdir;
 
1675
 
 
1676
        if (RNA_struct_property_is_set(op->ptr, "filepath"))
 
1677
                return font_open_exec(C, op);
 
1678
 
1714
1679
        RNA_string_set(op->ptr, "filepath", path);
1715
1680
        WM_event_add_fileselect(C, op); 
1716
1681
 
1720
1685
void FONT_OT_open(wmOperatorType *ot)
1721
1686
{
1722
1687
        /* identifiers */
1723
 
        ot->name= "Open";
1724
 
        ot->idname= "FONT_OT_open";
 
1688
        ot->name = "Open Font";
 
1689
        ot->idname = "FONT_OT_open";
1725
1690
        
1726
1691
        /* api callbacks */
1727
 
        ot->exec= open_exec;
1728
 
        ot->invoke= open_invoke;
1729
 
        ot->cancel= open_cancel;
 
1692
        ot->exec = font_open_exec;
 
1693
        ot->invoke = open_invoke;
 
1694
        ot->cancel = font_open_cancel;
1730
1695
        
1731
1696
        /* flags */
1732
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1697
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1733
1698
        
1734
1699
        /* properties */
1735
 
        WM_operator_properties_filesel(ot, FOLDERFILE|FTFONTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH);
 
1700
        WM_operator_properties_filesel(ot, FOLDERFILE|FTFONTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY);
1736
1701
}
1737
1702
 
1738
1703
/******************* delete operator *********************/
1739
 
static int font_unlink_poll(bContext *C)
1740
 
{
1741
 
        Object *ob = CTX_data_active_object(C);
1742
 
        Curve *cu;
1743
 
        
1744
 
        if (!ED_operator_object_active_editable(C) ) return 0;
1745
 
        if (ob->type != OB_FONT) return 0;
1746
 
        
1747
 
        cu = ob->data;
1748
 
        if (cu && strcmp(cu->vfont->name, "<builtin>")==0) return 0;
1749
 
        return 1;
1750
 
}
1751
1704
 
1752
1705
static int font_unlink_exec(bContext *C, wmOperator *op)
1753
1706
{
1754
 
        Object *ob = CTX_data_active_object(C);
1755
 
        Curve *cu;
1756
 
        VFont *font, *builtin_font;
1757
 
                
1758
 
        cu = ob->data;
1759
 
        font = cu->vfont;
 
1707
        VFont *builtin_font;
 
1708
 
 
1709
        PointerRNA idptr;
 
1710
        PropertyPointerRNA pprop;
 
1711
 
 
1712
        uiIDContextProperty(C, &pprop.ptr, &pprop.prop);
1760
1713
        
1761
 
        if (!font) {
1762
 
                BKE_report(op->reports, RPT_ERROR, "No font datablock available to unlink.");
 
1714
        if (pprop.prop==NULL) {
 
1715
                BKE_report(op->reports, RPT_ERROR, "Incorrect context for running font unlink");
1763
1716
                return OPERATOR_CANCELLED;
1764
1717
        }
1765
 
        
1766
 
        if (strcmp(font->name, "<builtin>")==0) {
1767
 
                BKE_report(op->reports, RPT_WARNING, "Can't unlink the default builtin font.");
1768
 
                return OPERATOR_FINISHED;
1769
 
        }
1770
1718
 
1771
 
        /* revert back to builtin font */
1772
1719
        builtin_font = get_builtin_font();
1773
1720
 
1774
 
        cu->vfont = builtin_font;
1775
 
        id_us_plus(&cu->vfont->id);
1776
 
        id_us_min(&font->id);
1777
 
        
1778
 
        DAG_id_flush_update(ob->data, OB_RECALC_DATA);
1779
 
        WM_event_add_notifier(C, NC_GEOM|ND_DATA|NA_EDITED, ob->data);
1780
 
        
 
1721
        RNA_id_pointer_create(&builtin_font->id, &idptr);
 
1722
        RNA_property_pointer_set(&pprop.ptr, pprop.prop, idptr);
 
1723
        RNA_property_update(C, &pprop.ptr, pprop.prop);
 
1724
 
1781
1725
        return OPERATOR_FINISHED;
1782
1726
}
1783
1727
 
1784
1728
void FONT_OT_unlink(wmOperatorType *ot)
1785
1729
{
1786
1730
        /* identifiers */
1787
 
        ot->name= "Unlink";
1788
 
        ot->idname= "FONT_OT_unlink";
1789
 
        ot->description= "Unlink active font data block";
 
1731
        ot->name = "Unlink";
 
1732
        ot->idname = "FONT_OT_unlink";
 
1733
        ot->description = "Unlink active font data block";
1790
1734
        
1791
1735
        /* api callbacks */
1792
 
        ot->exec= font_unlink_exec;
1793
 
        ot->poll= font_unlink_poll;
 
1736
        ot->exec = font_unlink_exec;
1794
1737
}
1795
1738
 
1796
1739
 
1797
1740
/* **************** undo for font object ************** */
1798
1741
 
1799
 
static void undoFont_to_editFont(void *strv, void *ecu)
 
1742
static void undoFont_to_editFont(void *strv, void *ecu, void *UNUSED(obdata))
1800
1743
{
1801
1744
        Curve *cu= (Curve *)ecu;
1802
1745
        EditFont *ef= cu->editfont;
1813
1756
        update_string(cu);
1814
1757
}
1815
1758
 
1816
 
static void *editFont_to_undoFont(void *ecu)
 
1759
static void *editFont_to_undoFont(void *ecu, void *UNUSED(obdata))
1817
1760
{
1818
1761
        Curve *cu= (Curve *)ecu;
1819
1762
        EditFont *ef= cu->editfont;
1840
1783
static void *get_undoFont(bContext *C)
1841
1784
{
1842
1785
        Object *obedit= CTX_data_edit_object(C);
1843
 
        if(obedit && obedit->type==OB_FONT) {
 
1786
        if (obedit && obedit->type==OB_FONT) {
1844
1787
                return obedit->data;
1845
1788
        }
1846
1789
        return NULL;
1847
1790
}
1848
1791
 
1849
1792
/* and this is all the undo system needs to know */
1850
 
void undo_push_font(bContext *C, char *name)
 
1793
void undo_push_font(bContext *C, const char *name)
1851
1794
{
1852
1795
        undo_editmode_push(C, name, get_undoFont, free_undoFont, undoFont_to_editFont, editFont_to_undoFont, NULL);
1853
1796
}