~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
 
75
75
#include "curve_intern.h"
76
76
 
77
 
#define MAXTEXT 32766
 
77
#define MAXTEXT 32766
78
78
 
79
79
/************************* utilities ******************************/
80
80
 
81
81
static char findaccent(char char1, unsigned int code)
82
82
{
83
 
        char new= 0;
 
83
        char new = 0;
84
84
        
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;
 
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
                else if (code == '|') new = 162;
 
98
                else if (code == 'o') new = 169;
 
99
        }
 
100
        else if (char1 == 'e') {
 
101
                if (code == '`') new = 232;
 
102
                else if (code == 39) new = 233;
 
103
                else if (code == '^') new = 234;
 
104
                else if (code == '"') new = 235;
 
105
        }
 
106
        else if (char1 == 'i') {
 
107
                if (code == '`') new = 236;
 
108
                else if (code == 39) new = 237;
 
109
                else if (code == '^') new = 238;
 
110
                else if (code == '"') new = 239;
 
111
        }
 
112
        else if (char1 == 'n') {
 
113
                if (code == '~') new = 241;
 
114
        }
 
115
        else if (char1 == 'o') {
 
116
                if (code == '`') new = 242;
 
117
                else if (code == 39) new = 243;
 
118
                else if (code == '^') new = 244;
 
119
                else if (code == '~') new = 245;
 
120
                else if (code == '"') new = 246;
 
121
                else if (code == '/') new = 248;
 
122
                else if (code == '-') new = 186;
 
123
                else if (code == 'e') new = 143;
 
124
                else if (code == 'c') new = 169;
 
125
                else if (code == 'r') new = 174;
 
126
        }
 
127
        else if (char1 == 'r') {
 
128
                if (code == 'o') new = 174;
 
129
        }
 
130
        else if (char1 == 's') {
 
131
                if (code == 's') new = 167;
 
132
        }
 
133
        else if (char1 == 't') {
 
134
                if (code == 'm') new = 153;
 
135
        }
 
136
        else if (char1 == 'u') {
 
137
                if (code == '`') new = 249;
 
138
                else if (code == 39) new = 250;
 
139
                else if (code == '^') new = 251;
 
140
                else if (code == '"') new = 252;
 
141
        }
 
142
        else if (char1 == 'y') {
 
143
                if (code == 39) new = 253;
 
144
                else if (code == '"') new = 255;
 
145
        }
 
146
        else if (char1 == 'A') {
 
147
                if (code == '`') new = 192;
 
148
                else if (code == 39) new = 193;
 
149
                else if (code == '^') new = 194;
 
150
                else if (code == '~') new = 195;
 
151
                else if (code == '"') new = 196;
 
152
                else if (code == 'o') new = 197;
 
153
                else if (code == 'e') new = 198;
 
154
        }
 
155
        else if (char1 == 'C') {
 
156
                if (code == ',') new = 199;
 
157
        }
 
158
        else if (char1 == 'E') {
 
159
                if (code == '`') new = 200;
 
160
                else if (code == 39) new = 201;
 
161
                else if (code == '^') new = 202;
 
162
                else if (code == '"') new = 203;
 
163
        }
 
164
        else if (char1 == 'I') {
 
165
                if (code == '`') new = 204;
 
166
                else if (code == 39) new = 205;
 
167
                else if (code == '^') new = 206;
 
168
                else if (code == '"') new = 207;
 
169
        }
 
170
        else if (char1 == 'N') {
 
171
                if (code == '~') new = 209;
 
172
        }
 
173
        else if (char1 == 'O') {
 
174
                if (code == '`') new = 210;
 
175
                else if (code == 39) new = 211;
 
176
                else if (code == '^') new = 212;
 
177
                else if (code == '~') new = 213;
 
178
                else if (code == '"') new = 214;
 
179
                else if (code == '/') new = 216;
 
180
                else if (code == 'e') new = 141;
 
181
        }
 
182
        else if (char1 == 'U') {
 
183
                if (code == '`') new = 217;
 
184
                else if (code == 39) new = 218;
 
185
                else if (code == '^') new = 219;
 
186
                else if (code == '"') new = 220;
 
187
        }
 
188
        else if (char1 == 'Y') {
 
189
                if (code == 39) new = 221;
 
190
        }
 
191
        else if (char1 == '1') {
 
192
                if (code == '4') new = 188;
 
193
                if (code == '2') new = 189;
 
194
        }
 
195
        else if (char1 == '3') {
 
196
                if (code == '4') new = 190;
 
197
        }
 
198
        else if (char1 == ':') {
 
199
                if (code == '-') new = 247;
 
200
        }
 
201
        else if (char1 == '-') {
 
202
                if (code == ':') new = 247;
 
203
                if (code == '|') new = 135;
 
204
                if (code == '+') new = 177;
 
205
        }
 
206
        else if (char1 == '|') {
 
207
                if (code == '-') new = 135;
 
208
                if (code == '=') new = 136;
 
209
        }
 
210
        else if (char1 == '=') {
 
211
                if (code == '|') new = 136;
 
212
        }
 
213
        else if (char1 == '+') {
 
214
                if (code == '-') new = 177;
206
215
        }
207
216
        
208
217
        if (new) return new;
212
221
 
213
222
static void update_string(Curve *cu)
214
223
{
215
 
        EditFont *ef= cu->editfont;
 
224
        EditFont *ef = cu->editfont;
216
225
        int len;
217
226
 
218
 
        // Free the old curve string    
 
227
        /* Free the old curve string */
219
228
        MEM_freeN(cu->str);
220
229
 
221
 
        // Calculate the actual string length in UTF-8 variable characters
 
230
        /* Calculate the actual string length in UTF-8 variable characters */
222
231
        len = BLI_wstrlen_utf8(ef->textbuf);
223
232
 
224
 
        // Alloc memory for UTF-8 variable char length string
 
233
        /* Alloc memory for UTF-8 variable char length string */
225
234
        cu->str = MEM_callocN(len + sizeof(wchar_t), "str");
226
235
 
227
 
        // Copy the wchar to UTF-8
 
236
        /* Copy the wchar to UTF-8 */
228
237
        BLI_strncpy_wchar_as_utf8(cu->str, ef->textbuf, len + 1);
229
238
}
230
239
 
231
240
static int insert_into_textbuf(Object *obedit, uintptr_t c)
232
241
{
233
 
        Curve *cu= obedit->data;
 
242
        Curve *cu = obedit->data;
234
243
        
235
 
        if (cu->len<MAXTEXT-1) {
236
 
                EditFont *ef= cu->editfont;
 
244
        if (cu->len < MAXTEXT - 1) {
 
245
                EditFont *ef = cu->editfont;
237
246
                int x;
238
247
 
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];              
241
 
                ef->textbuf[cu->pos]= c;
 
248
                for (x = cu->len; x > cu->pos; x--) ef->textbuf[x] = ef->textbuf[x - 1];
 
249
                for (x = cu->len; x > cu->pos; x--) ef->textbufinfo[x] = ef->textbufinfo[x - 1];
 
250
                ef->textbuf[cu->pos] = c;
242
251
                ef->textbufinfo[cu->pos] = cu->curinfo;
243
252
                ef->textbufinfo[cu->pos].kern = 0;
244
253
                ef->textbufinfo[cu->pos].mat_nr = obedit->actcol;
245
254
                                        
246
255
                cu->pos++;
247
256
                cu->len++;
248
 
                ef->textbuf[cu->len]='\0';
 
257
                ef->textbuf[cu->len] = '\0';
249
258
 
250
259
                update_string(cu);
251
260
 
257
266
 
258
267
static void text_update_edited(bContext *C, Scene *scene, Object *obedit, int recalc, int mode)
259
268
{
260
 
        struct Main *bmain= CTX_data_main(C);
261
 
        Curve *cu= obedit->data;
262
 
        EditFont *ef= cu->editfont;
263
 
        cu->curinfo = ef->textbufinfo[cu->pos?cu->pos-1:0];
 
269
        struct Main *bmain = CTX_data_main(C);
 
270
        Curve *cu = obedit->data;
 
271
        EditFont *ef = cu->editfont;
 
272
        cu->curinfo = ef->textbufinfo[cu->pos ? cu->pos - 1 : 0];
264
273
        
265
274
        if (obedit->totcol > 0) {
266
 
                obedit->actcol= ef->textbufinfo[cu->pos?cu->pos-1:0].mat_nr;
 
275
                obedit->actcol = ef->textbufinfo[cu->pos ? cu->pos - 1 : 0].mat_nr;
267
276
 
268
277
                /* since this array is calloc'd, it can be 0 even though we try ensure
269
278
                 * (mat_nr > 0) almost everywhere */
270
279
                if (obedit->actcol < 1) {
271
 
                        obedit->actcol= 1;
 
280
                        obedit->actcol = 1;
272
281
                }
273
282
        }
274
283
 
275
284
        if (mode == FO_EDIT)
276
285
                update_string(cu);
277
286
 
278
 
        BKE_text_to_curve(bmain, scene, obedit, mode);
 
287
        BKE_vfont_to_curve(bmain, scene, obedit, mode);
279
288
 
280
289
        if (recalc)
281
290
                DAG_id_tag_update(obedit->data, 0);
282
 
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
291
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
283
292
}
284
293
 
285
294
/********************** insert lorem operator *********************/
286
295
 
287
296
static int insert_lorem_exec(bContext *C, wmOperator *UNUSED(op))
288
297
{
289
 
        Object *obedit= CTX_data_edit_object(C);
 
298
        Object *obedit = CTX_data_edit_object(C);
290
299
        const char *p, *p2;
291
300
        int i;
292
301
        static const char *lastlorem;
293
302
        
294
303
        if (lastlorem)
295
 
                p= lastlorem;
 
304
                p = lastlorem;
296
305
        else
297
 
                p= ED_lorem;
 
306
                p = ED_lorem;
298
307
        
299
 
        i= rand()/(RAND_MAX/6)+4;       
 
308
        i = rand() / (RAND_MAX / 6) + 4;
300
309
                
301
 
        for (p2=p; *p2 && i; p2++) {
 
310
        for (p2 = p; *p2 && i; p2++) {
302
311
                insert_into_textbuf(obedit, *p2);
303
312
 
304
 
                if (*p2=='.')
 
313
                if (*p2 == '.')
305
314
                        i--;
306
315
        }
307
316
 
308
 
        lastlorem = p2+1;
309
 
        if (strlen(lastlorem)<5)
 
317
        lastlorem = p2 + 1;
 
318
        if (strlen(lastlorem) < 5)
310
319
                lastlorem = ED_lorem;
311
320
        
312
321
        insert_into_textbuf(obedit, '\n');
313
 
        insert_into_textbuf(obedit, '\n');      
 
322
        insert_into_textbuf(obedit, '\n');
314
323
 
315
324
        DAG_id_tag_update(obedit->data, 0);
316
 
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
325
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
317
326
 
318
327
        return OPERATOR_FINISHED;
319
328
}
330
339
        ot->poll = ED_operator_editfont;
331
340
        
332
341
        /* flags */
333
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
342
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
334
343
}
335
344
 
336
345
/******************* paste file operator ********************/
340
349
 
341
350
static int paste_file(bContext *C, ReportList *reports, const char *filename)
342
351
{
343
 
        Scene *scene= CTX_data_scene(C);
344
 
        Object *obedit= CTX_data_edit_object(C);
345
 
        Curve *cu= obedit->data;
346
 
        EditFont *ef= cu->editfont;
 
352
        Scene *scene = CTX_data_scene(C);
 
353
        Object *obedit = CTX_data_edit_object(C);
 
354
        Curve *cu = obedit->data;
 
355
        EditFont *ef = cu->editfont;
347
356
        FILE *fp;
348
357
        int filelen;
349
358
        char *strp;
350
359
 
351
 
        fp= BLI_fopen(filename, "r");
 
360
        fp = BLI_fopen(filename, "r");
352
361
 
353
362
        if (!fp) {
354
363
                if (reports)
360
369
        filelen = ftell(fp);
361
370
        fseek(fp, 0L, SEEK_SET);
362
371
 
363
 
        strp= MEM_callocN(filelen+4, "tempstr");
 
372
        strp = MEM_callocN(filelen + 4, "tempstr");
364
373
 
365
 
        // fread() instead of read(), because windows read() converts text
366
 
        // to DOS \r\n linebreaks, causing double linebreaks in the 3d text
 
374
        /* fread() instead of read(), because windows read() converts text
 
375
         * to DOS \r\n linebreaks, causing double linebreaks in the 3d text */
367
376
        filelen = fread(strp, 1, filelen, fp);
368
377
        fclose(fp);
369
 
        strp[filelen]= 0;
 
378
        strp[filelen] = 0;
370
379
 
371
 
        if (cu->len+filelen<MAXTEXT) {
 
380
        if (cu->len + filelen < MAXTEXT) {
372
381
                int tmplen;
373
 
                wchar_t *mem = MEM_callocN((sizeof(wchar_t)*filelen)+(4*sizeof(wchar_t)), "temporary");
 
382
                wchar_t *mem = MEM_callocN((sizeof(wchar_t) * filelen) + (4 * sizeof(wchar_t)), "temporary");
374
383
                tmplen = BLI_strncpy_wchar_from_utf8(mem, strp, filelen + 1);
375
384
                wcscat(ef->textbuf, mem);
376
385
                MEM_freeN(mem);
377
386
                cu->len += tmplen;
378
 
                cu->pos= cu->len;
 
387
                cu->pos = cu->len;
379
388
        }
380
389
        MEM_freeN(strp);
381
390
 
389
398
        char *path;
390
399
        int retval;
391
400
        
392
 
        path= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
393
 
        retval= paste_file(C, op->reports, path);
 
401
        path = RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
 
402
        retval = paste_file(C, op->reports, path);
394
403
        MEM_freeN(path);
395
404
 
396
405
        return retval;
419
428
        ot->poll = ED_operator_editfont;
420
429
        
421
430
        /* flags */
422
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
431
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
423
432
 
424
433
        /* properties */
425
 
        WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
 
434
        WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE, FILE_SPECIAL, FILE_OPENFILE,
 
435
                                       WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
426
436
}
427
437
 
428
438
/******************* text to object operator ********************/
429
439
 
430
440
static void txt_add_object(bContext *C, TextLine *firstline, int totline, float offset[3])
431
441
{
432
 
        Scene *scene= CTX_data_scene(C);
 
442
        Scene *scene = CTX_data_scene(C);
433
443
        Curve *cu;
434
444
        Object *obedit;
435
445
        Base *base;
437
447
        int nchars = 0, a;
438
448
        float rot[3] = {0.f, 0.f, 0.f};
439
449
        
440
 
        obedit= add_object(scene, OB_FONT);
441
 
        base= scene->basact;
442
 
 
443
 
        
444
 
        ED_object_base_init_transform(C, base, NULL, rot); /* seems to assume view align ? TODO - look into this, could be an operator option */
445
 
        where_is_object(scene, obedit);
 
450
        obedit = BKE_object_add(scene, OB_FONT);
 
451
        base = scene->basact;
 
452
 
 
453
        /* seems to assume view align ? TODO - look into this, could be an operator option */
 
454
        ED_object_base_init_transform(C, base, NULL, rot);
 
455
 
 
456
        BKE_object_where_is_calc(scene, obedit);
446
457
 
447
458
        obedit->loc[0] += offset[0];
448
459
        obedit->loc[1] += offset[1];
449
460
        obedit->loc[2] += offset[2];
450
461
 
451
 
        cu= obedit->data;
452
 
        cu->vfont= get_builtin_font();
 
462
        cu = obedit->data;
 
463
        cu->vfont = BKE_vfont_builtin_get();
453
464
        cu->vfont->id.us++;
454
465
 
455
 
        for (tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++)
 
466
        for (tmp = firstline, a = 0; cu->len < MAXTEXT && a < totline; tmp = tmp->next, a++)
456
467
                nchars += strlen(tmp->line) + 1;
457
468
 
458
469
        if (cu->str) MEM_freeN(cu->str);
459
 
        if (cu->strinfo) MEM_freeN(cu->strinfo);        
460
 
 
461
 
        cu->str= MEM_callocN(nchars+4, "str");
462
 
        cu->strinfo= MEM_callocN((nchars+4)*sizeof(CharInfo), "strinfo");
463
 
 
464
 
        cu->str[0]= '\0';
465
 
        cu->len= 0;
466
 
        cu->pos= 0;
 
470
        if (cu->strinfo) MEM_freeN(cu->strinfo);
 
471
 
 
472
        cu->str = MEM_callocN(nchars + 4, "str");
 
473
        cu->strinfo = MEM_callocN((nchars + 4) * sizeof(CharInfo), "strinfo");
 
474
 
 
475
        cu->str[0] = '\0';
 
476
        cu->len = 0;
 
477
        cu->pos = 0;
467
478
        
468
 
        for (tmp=firstline, a=0; cu->len<MAXTEXT && a<totline; tmp=tmp->next, a++) {
 
479
        for (tmp = firstline, a = 0; cu->len < MAXTEXT && a < totline; tmp = tmp->next, a++) {
469
480
                strcat(cu->str, tmp->line);
470
 
                cu->len+= strlen(tmp->line);
 
481
                cu->len += strlen(tmp->line);
471
482
 
472
483
                if (tmp->next) {
473
484
                        strcat(cu->str, "\n");
474
485
                        cu->len++;
475
486
                }
476
487
 
477
 
                cu->pos= cu->len;
 
488
                cu->pos = cu->len;
478
489
        }
479
490
 
480
 
        WM_event_add_notifier(C, NC_OBJECT|NA_ADDED, obedit);
 
491
        WM_event_add_notifier(C, NC_OBJECT | NA_ADDED, obedit);
481
492
}
482
493
 
483
494
void ED_text_to_object(bContext *C, Text *text, int split_lines)
484
495
{
485
 
        RegionView3D *rv3d= CTX_wm_region_view3d(C);
 
496
        RegionView3D *rv3d = CTX_wm_region_view3d(C);
486
497
        TextLine *line;
487
498
        float offset[3];
488
 
        int linenum= 0;
 
499
        int linenum = 0;
489
500
 
490
501
        if (!text || !text->lines.first) return;
491
502
 
492
503
        if (split_lines) {
493
 
                for (line=text->lines.first; line; line=line->next) {
 
504
                for (line = text->lines.first; line; line = line->next) {
494
505
                        /* skip lines with no text, but still make space for them */
495
506
                        if (line->line[0] == '\0') {
496
507
                                linenum++;
511
522
                }
512
523
        }
513
524
        else {
514
 
                offset[0]= 0.0f;
515
 
                offset[1]= 0.0f;
516
 
                offset[2]= 0.0f;
 
525
                offset[0] = 0.0f;
 
526
                offset[1] = 0.0f;
 
527
                offset[2] = 0.0f;
517
528
 
518
529
                txt_add_object(C, text->lines.first, BLI_countlist(&text->lines), offset);
519
530
        }
520
531
}
521
532
 
522
533
/********************** utilities ***************************/
523
 
 
524
534
static short next_word(Curve *cu)
525
535
{
526
536
        short s;
527
 
        for (s=cu->pos; (cu->str[s]) && (cu->str[s]!=' ') && (cu->str[s]!='\n') &&
528
 
                                        (cu->str[s]!=1) && (cu->str[s]!='\r'); s++);
529
 
        if (cu->str[s]) return(s+1); else return(s);
 
537
        for (s = cu->pos; ((cu->str[s]) && (cu->str[s] != ' ') && (cu->str[s] != '\n') &&
 
538
                           (cu->str[s] != 1) && (cu->str[s] != '\r'));
 
539
             s++)
 
540
        {
 
541
                /* pass */
 
542
        }
 
543
 
 
544
        return cu->str[s] ? (s + 1) : s;
530
545
}
531
546
 
532
547
static short prev_word(Curve *cu)
533
548
{
534
549
        short s;
535
550
        
536
 
        if (cu->pos==0) return(0);
537
 
        for (s=cu->pos-2; (cu->str[s]) && (cu->str[s]!=' ') && (cu->str[s]!='\n') &&
538
 
                                        (cu->str[s]!=1) && (cu->str[s]!='\r'); s--);
539
 
        if (cu->str[s]) return(s+1); else return(s);
 
551
        if (cu->pos == 0) return(0);
 
552
        for (s = cu->pos - 2; ((cu->str[s]) && (cu->str[s] != ' ') && (cu->str[s] != '\n') &&
 
553
                               (cu->str[s] != 1) && (cu->str[s] != '\r'));
 
554
             s--)
 
555
        {
 
556
                /* pass */
 
557
        }
 
558
 
 
559
        return cu->str[s] ? (s + 1) : s;
540
560
}
541
561
 
542
 
static int kill_selection(Object *obedit, int ins)      /* 1 == new character */
 
562
static int kill_selection(Object *obedit, int ins)  /* 1 == new character */
543
563
{
544
 
        Curve *cu= obedit->data;
545
 
        EditFont *ef= cu->editfont;
 
564
        Curve *cu = obedit->data;
 
565
        EditFont *ef = cu->editfont;
546
566
        int selend, selstart, direction;
547
567
        int offset = 0;
548
568
        int getfrom;
549
569
 
550
 
        direction = BKE_font_getselection(obedit, &selstart, &selend);
 
570
        direction = BKE_vfont_select_get(obedit, &selstart, &selend);
551
571
        if (direction) {
552
572
                int size;
553
573
                if (ins) offset = 1;
554
 
                if (cu->pos >= selstart) cu->pos = selstart+offset;
 
574
                if (cu->pos >= selstart) cu->pos = selstart + offset;
555
575
                if ((direction == -1) && ins) {
556
576
                        selstart++;
557
577
                        selend++;
558
578
                }
559
 
                getfrom = selend+offset;
560
 
                if (ins==0) getfrom++;
561
 
                size = (cu->len * sizeof(wchar_t)) - (selstart * sizeof(wchar_t)) + (offset*sizeof(wchar_t));
562
 
                memmove(ef->textbuf+selstart, ef->textbuf+getfrom, size);
563
 
                memmove(ef->textbufinfo+selstart, ef->textbufinfo+getfrom, ((cu->len-selstart)+offset)*sizeof(CharInfo));
564
 
                cu->len -= (selend-selstart)+offset;
 
579
                getfrom = selend + offset;
 
580
                if (ins == 0) getfrom++;
 
581
                size = (cu->len * sizeof(wchar_t)) - (selstart * sizeof(wchar_t)) + (offset * sizeof(wchar_t));
 
582
                memmove(ef->textbuf + selstart, ef->textbuf + getfrom, size);
 
583
                memmove(ef->textbufinfo + selstart, ef->textbufinfo + getfrom, ((cu->len - selstart) + offset) * sizeof(CharInfo));
 
584
                cu->len -= (selend - selstart) + offset;
565
585
                cu->selstart = cu->selend = 0;
566
586
        }
567
587
 
570
590
 
571
591
/******************* set style operator ********************/
572
592
 
573
 
static EnumPropertyItem style_items[]= {
 
593
static EnumPropertyItem style_items[] = {
574
594
        {CU_CHINFO_BOLD, "BOLD", 0, "Bold", ""},
575
595
        {CU_CHINFO_ITALIC, "ITALIC", 0, "Italic", ""},
576
596
        {CU_CHINFO_UNDERLINE, "UNDERLINE", 0, "Underline", ""},
577
597
        {CU_CHINFO_SMALLCAPS, "SMALL_CAPS", 0, "Small Caps", ""},
578
 
        {0, NULL, 0, NULL, NULL}};
 
598
        {0, NULL, 0, NULL, NULL}
 
599
};
579
600
 
580
601
static int set_style(bContext *C, const int style, const int clear)
581
602
{
582
 
        Object *obedit= CTX_data_edit_object(C);
583
 
        Curve *cu= obedit->data;
584
 
        EditFont *ef= cu->editfont;
 
603
        Object *obedit = CTX_data_edit_object(C);
 
604
        Curve *cu = obedit->data;
 
605
        EditFont *ef = cu->editfont;
585
606
        int i, selstart, selend;
586
607
 
587
 
        if (!BKE_font_getselection(obedit, &selstart, &selend))
 
608
        if (!BKE_vfont_select_get(obedit, &selstart, &selend))
588
609
                return OPERATOR_CANCELLED;
589
610
 
590
 
        for (i=selstart; i<=selend; i++) {
 
611
        for (i = selstart; i <= selend; i++) {
591
612
                if (clear)
592
613
                        ef->textbufinfo[i].flag &= ~style;
593
614
                else
595
616
        }
596
617
 
597
618
        DAG_id_tag_update(obedit->data, 0);
598
 
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
619
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
599
620
 
600
621
        return OPERATOR_FINISHED;
601
622
}
602
623
 
603
624
static int set_style_exec(bContext *C, wmOperator *op)
604
625
{
605
 
        const int style= RNA_enum_get(op->ptr, "style");
606
 
        const int clear= RNA_boolean_get(op->ptr, "clear");
 
626
        const int style = RNA_enum_get(op->ptr, "style");
 
627
        const int clear = RNA_boolean_get(op->ptr, "clear");
607
628
 
608
629
        return set_style(C, style, clear);
609
630
}
620
641
        ot->poll = ED_operator_editfont;
621
642
        
622
643
        /* flags */
623
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
644
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
624
645
 
625
646
        /* properties */
626
647
        RNA_def_enum(ot->srna, "style", style_items, CU_CHINFO_BOLD, "Style", "Style to set selection to");
631
652
 
632
653
static int toggle_style_exec(bContext *C, wmOperator *op)
633
654
{
634
 
        Object *obedit= CTX_data_edit_object(C);
635
 
        Curve *cu= obedit->data;
 
655
        Object *obedit = CTX_data_edit_object(C);
 
656
        Curve *cu = obedit->data;
636
657
        int style, clear, selstart, selend;
637
658
 
638
 
        if (!BKE_font_getselection(obedit, &selstart, &selend))
 
659
        if (!BKE_vfont_select_get(obedit, &selstart, &selend))
639
660
                return OPERATOR_CANCELLED;
640
661
        
641
 
        style= RNA_enum_get(op->ptr, "style");
 
662
        style = RNA_enum_get(op->ptr, "style");
642
663
 
643
664
        cu->curinfo.flag ^= style;
644
 
        clear= (cu->curinfo.flag & style) == 0;
 
665
        clear = (cu->curinfo.flag & style) == 0;
645
666
 
646
667
        return set_style(C, style, clear);
647
668
}
658
679
        ot->poll = ED_operator_editfont;
659
680
        
660
681
        /* flags */
661
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
682
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
662
683
 
663
684
        /* properties */
664
685
        RNA_def_enum(ot->srna, "style", style_items, CU_CHINFO_BOLD, "Style", "Style to set selection to");
670
691
{
671
692
        int selstart, selend;
672
693
        
673
 
        if (BKE_font_getselection(obedit, &selstart, &selend)) {
674
 
                Curve *cu= obedit->data;
675
 
                EditFont *ef= cu->editfont;
 
694
        if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
 
695
                Curve *cu = obedit->data;
 
696
                EditFont *ef = cu->editfont;
676
697
                
677
 
                memcpy(ef->copybuf, ef->textbuf+selstart, ((selend-selstart)+1)*sizeof(wchar_t));
678
 
                ef->copybuf[(selend-selstart)+1]=0;
679
 
                memcpy(ef->copybufinfo, ef->textbufinfo+selstart, ((selend-selstart)+1)*sizeof(CharInfo));      
 
698
                memcpy(ef->copybuf, ef->textbuf + selstart, ((selend - selstart) + 1) * sizeof(wchar_t));
 
699
                ef->copybuf[(selend - selstart) + 1] = 0;
 
700
                memcpy(ef->copybufinfo, ef->textbufinfo + selstart, ((selend - selstart) + 1) * sizeof(CharInfo));
680
701
        }
681
702
}
682
703
 
683
704
static int copy_text_exec(bContext *C, wmOperator *UNUSED(op))
684
705
{
685
 
        Object *obedit= CTX_data_edit_object(C);
 
706
        Object *obedit = CTX_data_edit_object(C);
686
707
 
687
708
        copy_selection(obedit);
688
709
 
705
726
 
706
727
static int cut_text_exec(bContext *C, wmOperator *UNUSED(op))
707
728
{
708
 
        Scene *scene= CTX_data_scene(C);
709
 
        Object *obedit= CTX_data_edit_object(C);
 
729
        Scene *scene = CTX_data_scene(C);
 
730
        Object *obedit = CTX_data_edit_object(C);
710
731
        int selstart, selend;
711
732
 
712
 
        if (!BKE_font_getselection(obedit, &selstart, &selend))
 
733
        if (!BKE_vfont_select_get(obedit, &selstart, &selend))
713
734
                return OPERATOR_CANCELLED;
714
735
 
715
736
        copy_selection(obedit);
732
753
        ot->poll = ED_operator_editfont;
733
754
 
734
755
        /* flags */
735
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
756
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
736
757
}
737
758
 
738
759
/******************* paste text operator ********************/
739
760
 
740
761
static int paste_selection(Object *obedit, ReportList *reports)
741
762
{
742
 
        Curve *cu= obedit->data;
743
 
        EditFont *ef= cu->editfont;
744
 
        int len= wcslen(ef->copybuf);
 
763
        Curve *cu = obedit->data;
 
764
        EditFont *ef = cu->editfont;
 
765
        int len = wcslen(ef->copybuf);
745
766
 
746
 
        // Verify that the copy buffer => [copy buffer len] + cu->len < MAXTEXT
 
767
        /* Verify that the copy buffer => [copy buffer len] + cu->len < MAXTEXT */
747
768
        if (cu->len + len <= MAXTEXT) {
748
 
                if (len) {      
749
 
                        int size = (cu->len * sizeof(wchar_t)) - (cu->pos*sizeof(wchar_t)) + sizeof(wchar_t);
750
 
                        memmove(ef->textbuf+cu->pos+len, ef->textbuf+cu->pos, size);
751
 
                        memcpy(ef->textbuf+cu->pos, ef->copybuf, len * sizeof(wchar_t));
 
769
                if (len) {
 
770
                        int size = (cu->len * sizeof(wchar_t)) - (cu->pos * sizeof(wchar_t)) + sizeof(wchar_t);
 
771
                        memmove(ef->textbuf + cu->pos + len, ef->textbuf + cu->pos, size);
 
772
                        memcpy(ef->textbuf + cu->pos, ef->copybuf, len * sizeof(wchar_t));
752
773
                
753
 
                        memmove(ef->textbufinfo+cu->pos+len, ef->textbufinfo+cu->pos, (cu->len-cu->pos+1)*sizeof(CharInfo));
754
 
                        memcpy(ef->textbufinfo+cu->pos, ef->copybufinfo, len*sizeof(CharInfo)); 
 
774
                        memmove(ef->textbufinfo + cu->pos + len, ef->textbufinfo + cu->pos, (cu->len - cu->pos + 1) * sizeof(CharInfo));
 
775
                        memcpy(ef->textbufinfo + cu->pos, ef->copybufinfo, len * sizeof(CharInfo));
755
776
                
756
777
                        cu->len += len;
757
778
                        cu->pos += len;
767
788
 
768
789
static int paste_text_exec(bContext *C, wmOperator *op)
769
790
{
770
 
        Scene *scene= CTX_data_scene(C);
771
 
        Object *obedit= CTX_data_edit_object(C);
 
791
        Scene *scene = CTX_data_scene(C);
 
792
        Object *obedit = CTX_data_edit_object(C);
772
793
 
773
794
        if (!paste_selection(obedit, op->reports))
774
795
                return OPERATOR_CANCELLED;
790
811
        ot->poll = ED_operator_editfont;
791
812
 
792
813
        /* flags */
793
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
814
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
794
815
}
795
816
 
796
817
/************************ move operator ************************/
797
818
 
798
 
static EnumPropertyItem move_type_items[]= {
 
819
static EnumPropertyItem move_type_items[] = {
799
820
        {LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""},
800
821
        {LINE_END, "LINE_END", 0, "Line End", ""},
801
822
        {PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
810
831
 
811
832
static int move_cursor(bContext *C, int type, int select)
812
833
{
813
 
        Scene *scene= CTX_data_scene(C);
814
 
        Object *obedit= CTX_data_edit_object(C);
815
 
        Curve *cu= obedit->data;
816
 
        EditFont *ef= cu->editfont;
817
 
        int cursmove= -1;
 
834
        Scene *scene = CTX_data_scene(C);
 
835
        Object *obedit = CTX_data_edit_object(C);
 
836
        Curve *cu = obedit->data;
 
837
        EditFont *ef = cu->editfont;
 
838
        int cursmove = -1;
818
839
 
819
 
        switch(type) {
 
840
        switch (type) {
820
841
                case LINE_BEGIN:
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;                            
 
842
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
 
843
                        while (cu->pos > 0) {
 
844
                                if (ef->textbuf[cu->pos - 1] == '\n') break;
 
845
                                if (ef->textbufinfo[cu->pos - 1].flag & CU_CHINFO_WRAP) break;
825
846
                                cu->pos--;
826
 
                        }               
827
 
                        cursmove=FO_CURS;
 
847
                        }
 
848
                        cursmove = FO_CURS;
828
849
                        break;
829
850
                        
830
851
                case LINE_END:
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;
 
852
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
 
853
                        while (cu->pos < cu->len) {
 
854
                                if (ef->textbuf[cu->pos] == 0) break;
 
855
                                if (ef->textbuf[cu->pos] == '\n') break;
 
856
                                if (ef->textbufinfo[cu->pos].flag & CU_CHINFO_WRAP) break;
836
857
                                cu->pos++;
837
858
                        }
838
 
                        cursmove=FO_CURS;
 
859
                        cursmove = FO_CURS;
839
860
                        break;
840
861
 
841
862
                case PREV_WORD:
842
 
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
843
 
                        cu->pos= prev_word(cu);
844
 
                        cursmove= FO_CURS;
 
863
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
 
864
                        cu->pos = prev_word(cu);
 
865
                        cursmove = FO_CURS;
845
866
                        break;
846
867
 
847
868
                case NEXT_WORD:
848
 
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
849
 
                        cu->pos= next_word(cu);
850
 
                        cursmove= FO_CURS;                              
 
869
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
 
870
                        cu->pos = next_word(cu);
 
871
                        cursmove = FO_CURS;
851
872
                        break;
852
873
 
853
874
                case PREV_CHAR:
854
 
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
875
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
855
876
                        cu->pos--;
856
 
                        cursmove=FO_CURS;
 
877
                        cursmove = FO_CURS;
857
878
                        break;
858
879
 
859
 
                case NEXT_CHAR: 
860
 
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
 
880
                case NEXT_CHAR:
 
881
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
861
882
                        cu->pos++;
862
 
                        cursmove= FO_CURS;                              
 
883
                        cursmove = FO_CURS;
863
884
 
864
885
                        break;
865
886
 
866
887
                case PREV_LINE:
867
 
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
868
 
                        cursmove=FO_CURSUP;
 
888
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
 
889
                        cursmove = FO_CURSUP;
869
890
                        break;
870
891
                        
871
892
                case NEXT_LINE:
872
 
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
873
 
                        cursmove= FO_CURSDOWN;
 
893
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
 
894
                        cursmove = FO_CURSDOWN;
874
895
                        break;
875
896
 
876
897
                case PREV_PAGE:
877
 
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
878
 
                        cursmove=FO_PAGEUP;
 
898
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
 
899
                        cursmove = FO_PAGEUP;
879
900
                        break;
880
901
 
881
902
                case NEXT_PAGE:
882
 
                        if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
883
 
                        cursmove=FO_PAGEDOWN;
 
903
                        if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
 
904
                        cursmove = FO_PAGEDOWN;
884
905
                        break;
885
906
        }
886
907
                
889
910
 
890
911
        if (select == 0) {
891
912
                if (cu->selstart) {
892
 
                        struct Main *bmain= CTX_data_main(C);
 
913
                        struct Main *bmain = CTX_data_main(C);
893
914
                        cu->selstart = cu->selend = 0;
894
915
                        update_string(cu);
895
 
                        BKE_text_to_curve(bmain, scene, obedit, FO_SELCHANGE);
 
916
                        BKE_vfont_to_curve(bmain, scene, obedit, FO_SELCHANGE);
896
917
                }
897
918
        }
898
919
 
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;
 
920
        if (cu->pos > cu->len) cu->pos = cu->len;
 
921
        else if (cu->pos >= MAXTEXT) cu->pos = MAXTEXT;
 
922
        else if (cu->pos < 0) cu->pos = 0;
902
923
 
903
924
        text_update_edited(C, scene, obedit, select, cursmove);
904
925
 
910
931
 
911
932
static int move_exec(bContext *C, wmOperator *op)
912
933
{
913
 
        int type= RNA_enum_get(op->ptr, "type");
 
934
        int type = RNA_enum_get(op->ptr, "type");
914
935
 
915
936
        return move_cursor(C, type, 0);
916
937
}
927
948
        ot->poll = ED_operator_editfont;
928
949
 
929
950
        /* flags */
930
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
951
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
931
952
 
932
953
        /* properties */
933
954
        RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to");
937
958
 
938
959
static int move_select_exec(bContext *C, wmOperator *op)
939
960
{
940
 
        int type= RNA_enum_get(op->ptr, "type");
 
961
        int type = RNA_enum_get(op->ptr, "type");
941
962
 
942
963
        return move_cursor(C, type, 1);
943
964
}
954
975
        ot->poll = ED_operator_editfont;
955
976
 
956
977
        /* flags */
957
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
978
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
958
979
 
959
980
        /* properties */
960
981
        RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to, to make a selection");
964
985
 
965
986
static int change_spacing_exec(bContext *C, wmOperator *op)
966
987
{
967
 
        Scene *scene= CTX_data_scene(C);
968
 
        Object *obedit= CTX_data_edit_object(C);
969
 
        Curve *cu= obedit->data;
970
 
        EditFont *ef= cu->editfont;
971
 
        int kern, delta= RNA_int_get(op->ptr, "delta");
 
988
        Scene *scene = CTX_data_scene(C);
 
989
        Object *obedit = CTX_data_edit_object(C);
 
990
        Curve *cu = obedit->data;
 
991
        EditFont *ef = cu->editfont;
 
992
        int kern, delta = RNA_int_get(op->ptr, "delta");
972
993
 
973
 
        kern = ef->textbufinfo[cu->pos-1].kern;
 
994
        kern = ef->textbufinfo[cu->pos - 1].kern;
974
995
        kern += delta;
975
996
        CLAMP(kern, -20, 20);
976
997
 
977
 
        if (ef->textbufinfo[cu->pos-1].kern == kern)
 
998
        if (ef->textbufinfo[cu->pos - 1].kern == kern)
978
999
                return OPERATOR_CANCELLED;
979
1000
 
980
 
        ef->textbufinfo[cu->pos-1].kern = kern;
 
1001
        ef->textbufinfo[cu->pos - 1].kern = kern;
981
1002
 
982
1003
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
983
1004
 
996
1017
        ot->poll = ED_operator_editfont;
997
1018
 
998
1019
        /* flags */
999
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1020
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1000
1021
 
1001
1022
        /* properties */
1002
1023
        RNA_def_int(ot->srna, "delta", 1, -20, 20, "Delta", "Amount to decrease or increase character spacing with", -20, 20);
1006
1027
 
1007
1028
static int change_character_exec(bContext *C, wmOperator *op)
1008
1029
{
1009
 
        Scene *scene= CTX_data_scene(C);
1010
 
        Object *obedit= CTX_data_edit_object(C);
1011
 
        Curve *cu= obedit->data;
1012
 
        EditFont *ef= cu->editfont;
1013
 
        int character, delta= RNA_int_get(op->ptr, "delta");
 
1030
        Scene *scene = CTX_data_scene(C);
 
1031
        Object *obedit = CTX_data_edit_object(C);
 
1032
        Curve *cu = obedit->data;
 
1033
        EditFont *ef = cu->editfont;
 
1034
        int character, delta = RNA_int_get(op->ptr, "delta");
1014
1035
 
1015
1036
        if (cu->pos <= 0)
1016
1037
                return OPERATOR_CANCELLED;
1017
1038
 
1018
 
        character= ef->textbuf[cu->pos - 1];
 
1039
        character = ef->textbuf[cu->pos - 1];
1019
1040
        character += delta;
1020
1041
        CLAMP(character, 0, 255);
1021
1042
 
1022
1043
        if (character == ef->textbuf[cu->pos - 1])
1023
1044
                return OPERATOR_CANCELLED;
1024
1045
 
1025
 
        ef->textbuf[cu->pos - 1]= character;
 
1046
        ef->textbuf[cu->pos - 1] = character;
1026
1047
 
1027
1048
        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1028
1049
 
1041
1062
        ot->poll = ED_operator_editfont;
1042
1063
 
1043
1064
        /* flags */
1044
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1065
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1045
1066
 
1046
1067
        /* properties */
1047
1068
        RNA_def_int(ot->srna, "delta", 1, -255, 255, "Delta", "Number to increase or decrease character code with", -255, 255);
1051
1072
 
1052
1073
static int line_break_exec(bContext *C, wmOperator *op)
1053
1074
{
1054
 
        Scene *scene= CTX_data_scene(C);
1055
 
        Object *obedit= CTX_data_edit_object(C);
1056
 
        Curve *cu= obedit->data;
1057
 
        EditFont *ef= cu->editfont;
1058
 
        const int ctrl= RNA_boolean_get(op->ptr, "ctrl");
 
1075
        Scene *scene = CTX_data_scene(C);
 
1076
        Object *obedit = CTX_data_edit_object(C);
 
1077
        Curve *cu = obedit->data;
 
1078
        EditFont *ef = cu->editfont;
 
1079
        const int ctrl = RNA_boolean_get(op->ptr, "ctrl");
1059
1080
 
1060
1081
        if (ctrl) {
1061
1082
                insert_into_textbuf(obedit, 1);
1062
 
                if (ef->textbuf[cu->pos]!='\n')
 
1083
                if (ef->textbuf[cu->pos] != '\n')
1063
1084
                        insert_into_textbuf(obedit, '\n');
1064
1085
        }
1065
1086
        else
1084
1105
        ot->poll = ED_operator_editfont;
1085
1106
 
1086
1107
        /* flags */
1087
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1108
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1088
1109
 
1089
1110
        /* properties */
1090
1111
        RNA_def_boolean(ot->srna, "ctrl", 0, "Ctrl", ""); // XXX what is this?
1092
1113
 
1093
1114
/******************* delete operator **********************/
1094
1115
 
1095
 
static EnumPropertyItem delete_type_items[]= {
 
1116
static EnumPropertyItem delete_type_items[] = {
1096
1117
        {DEL_ALL, "ALL", 0, "All", ""},
1097
1118
        {DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
1098
1119
        {DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
1103
1124
 
1104
1125
static int delete_exec(bContext *C, wmOperator *op)
1105
1126
{
1106
 
        Scene *scene= CTX_data_scene(C);
1107
 
        Object *obedit= CTX_data_edit_object(C);
1108
 
        Curve *cu= obedit->data;
1109
 
        EditFont *ef= cu->editfont;
1110
 
        int x, selstart, selend, type= RNA_enum_get(op->ptr, "type");
 
1127
        Scene *scene = CTX_data_scene(C);
 
1128
        Object *obedit = CTX_data_edit_object(C);
 
1129
        Curve *cu = obedit->data;
 
1130
        EditFont *ef = cu->editfont;
 
1131
        int x, selstart, selend, type = RNA_enum_get(op->ptr, "type");
1111
1132
 
1112
1133
        if (cu->len == 0)
1113
1134
                return OPERATOR_CANCELLED;
1114
1135
 
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;
 
1136
        if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
 
1137
                if (type == DEL_NEXT_SEL) type = DEL_SELECTION;
 
1138
                else if (type == DEL_PREV_SEL) type = DEL_SELECTION;
1118
1139
        }
1119
1140
        else {
1120
 
                if (type == DEL_NEXT_SEL) type= DEL_NEXT_CHAR;
1121
 
                else if (type == DEL_PREV_SEL) type= DEL_PREV_CHAR;
 
1141
                if (type == DEL_NEXT_SEL) type = DEL_NEXT_CHAR;
 
1142
                else if (type == DEL_PREV_SEL) type = DEL_PREV_CHAR;
1122
1143
        }
1123
1144
 
1124
 
        switch(type) {
 
1145
        switch (type) {
1125
1146
                case DEL_ALL:
1126
1147
                        cu->len = cu->pos = 0;
1127
 
                        ef->textbuf[0]= 0;
 
1148
                        ef->textbuf[0] = 0;
1128
1149
                        break;
1129
1150
                case DEL_SELECTION:
1130
1151
                        if (!kill_selection(obedit, 0))
1131
1152
                                return OPERATOR_CANCELLED;
1132
1153
                        break;
1133
1154
                case DEL_PREV_CHAR:
1134
 
                        if (cu->pos<=0)
 
1155
                        if (cu->pos <= 0)
1135
1156
                                return OPERATOR_CANCELLED;
1136
1157
 
1137
 
                        for (x=cu->pos;x<=cu->len;x++)
1138
 
                                ef->textbuf[x-1]= ef->textbuf[x];
1139
 
                        for (x=cu->pos;x<=cu->len;x++)
1140
 
                                ef->textbufinfo[x-1]= ef->textbufinfo[x];                                       
 
1158
                        for (x = cu->pos; x <= cu->len; x++)
 
1159
                                ef->textbuf[x - 1] = ef->textbuf[x];
 
1160
                        for (x = cu->pos; x <= cu->len; x++)
 
1161
                                ef->textbufinfo[x - 1] = ef->textbufinfo[x];
1141
1162
 
1142
1163
                        cu->pos--;
1143
 
                        ef->textbuf[--cu->len]='\0';
 
1164
                        ef->textbuf[--cu->len] = '\0';
1144
1165
                        break;
1145
1166
                case DEL_NEXT_CHAR:
1146
 
                        if (cu->pos>=cu->len)
 
1167
                        if (cu->pos >= cu->len)
1147
1168
                                return OPERATOR_CANCELLED;
1148
1169
 
1149
 
                        for (x=cu->pos;x<cu->len;x++)
1150
 
                                ef->textbuf[x]= ef->textbuf[x+1];
1151
 
                        for (x=cu->pos;x<cu->len;x++)
1152
 
                                ef->textbufinfo[x]= ef->textbufinfo[x+1];                                       
 
1170
                        for (x = cu->pos; x < cu->len; x++)
 
1171
                                ef->textbuf[x] = ef->textbuf[x + 1];
 
1172
                        for (x = cu->pos; x < cu->len; x++)
 
1173
                                ef->textbufinfo[x] = ef->textbufinfo[x + 1];
1153
1174
 
1154
 
                        ef->textbuf[--cu->len]='\0';
 
1175
                        ef->textbuf[--cu->len] = '\0';
1155
1176
                        break;
1156
1177
                default:
1157
1178
                        return OPERATOR_CANCELLED;
1174
1195
        ot->poll = ED_operator_editfont;
1175
1196
 
1176
1197
        /* flags */
1177
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1198
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1178
1199
 
1179
1200
        /* properties */
1180
1201
        RNA_def_enum(ot->srna, "type", delete_type_items, DEL_ALL, "Type", "Which part of the text to delete");
1184
1205
 
1185
1206
static int insert_text_exec(bContext *C, wmOperator *op)
1186
1207
{
1187
 
        Scene *scene= CTX_data_scene(C);
1188
 
        Object *obedit= CTX_data_edit_object(C);
 
1208
        Scene *scene = CTX_data_scene(C);
 
1209
        Object *obedit = CTX_data_edit_object(C);
1189
1210
        char *inserted_utf8;
1190
1211
        wchar_t *inserted_text;
1191
1212
        int a, len;
1193
1214
        if (!RNA_struct_property_is_set(op->ptr, "text"))
1194
1215
                return OPERATOR_CANCELLED;
1195
1216
        
1196
 
        inserted_utf8= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
1197
 
        len= BLI_strlen_utf8(inserted_utf8);
1198
 
 
1199
 
        inserted_text= MEM_callocN(sizeof(wchar_t)*(len+1), "FONT_insert_text");
1200
 
        BLI_strncpy_wchar_from_utf8(inserted_text, inserted_utf8, len+1);
1201
 
 
1202
 
        for (a=0; a<len; a++)
 
1217
        inserted_utf8 = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
 
1218
        len = BLI_strlen_utf8(inserted_utf8);
 
1219
 
 
1220
        inserted_text = MEM_callocN(sizeof(wchar_t) * (len + 1), "FONT_insert_text");
 
1221
        BLI_strncpy_wchar_from_utf8(inserted_text, inserted_utf8, len + 1);
 
1222
 
 
1223
        for (a = 0; a < len; a++)
1203
1224
                insert_into_textbuf(obedit, inserted_text[a]);
1204
1225
 
1205
1226
        MEM_freeN(inserted_text);
1213
1234
 
1214
1235
static int insert_text_invoke(bContext *C, wmOperator *op, wmEvent *evt)
1215
1236
{
1216
 
        Scene *scene= CTX_data_scene(C);
1217
 
        Object *obedit= CTX_data_edit_object(C);
1218
 
        Curve *cu= obedit->data;
1219
 
        EditFont *ef= cu->editfont;
1220
 
        static int accentcode= 0;
 
1237
        Scene *scene = CTX_data_scene(C);
 
1238
        Object *obedit = CTX_data_edit_object(C);
 
1239
        Curve *cu = obedit->data;
 
1240
        EditFont *ef = cu->editfont;
 
1241
        static int accentcode = 0;
1221
1242
        uintptr_t ascii = evt->ascii;
1222
 
        int alt= evt->alt, shift= evt->shift, ctrl= evt->ctrl;
1223
 
        int event= evt->type, val= evt->val;
1224
 
        wchar_t inserted_text[2]= {0};
 
1243
        int alt = evt->alt, shift = evt->shift, ctrl = evt->ctrl;
 
1244
        int event = evt->type, val = evt->val;
 
1245
        wchar_t inserted_text[2] = {0};
1225
1246
 
1226
1247
        if (RNA_struct_property_is_set(op->ptr, "text"))
1227
1248
                return insert_text_exec(C, op);
1228
1249
 
1229
1250
        if (RNA_struct_property_is_set(op->ptr, "accent")) {
1230
 
                if (cu->len!=0 && cu->pos>0)
1231
 
                        accentcode= 1;
 
1251
                if (cu->len != 0 && cu->pos > 0)
 
1252
                        accentcode = 1;
1232
1253
                return OPERATOR_FINISHED;
1233
1254
        }
1234
1255
        
1235
1256
        /* tab should exit editmode, but we allow it to be typed using modifier keys */
1236
 
        if (event==TABKEY) {
1237
 
                if ((alt||ctrl||shift) == 0)
 
1257
        if (event == TABKEY) {
 
1258
                if ((alt || ctrl || shift) == 0)
1238
1259
                        return OPERATOR_PASS_THROUGH;
1239
1260
                else
1240
 
                        ascii= 9;
1241
 
        }
1242
 
        else if (event==BACKSPACEKEY)
1243
 
                ascii= 0;
 
1261
                        ascii = 9;
 
1262
        }
 
1263
        
 
1264
        if (event == BACKSPACEKEY) {
 
1265
                if (alt && cu->len != 0 && cu->pos > 0)
 
1266
                        accentcode = 1;
 
1267
                return OPERATOR_PASS_THROUGH;
 
1268
        }
1244
1269
 
1245
1270
        if (val && (ascii || evt->utf8_buf[0])) {
1246
1271
                /* handle case like TAB (== 9) */
1247
1272
                if (     (ascii > 31 && ascii < 254 && ascii != 127) ||
1248
 
                        (ascii==13) ||
1249
 
                        (ascii==10) ||
1250
 
                        (ascii==8)  ||
1251
 
                        (evt->utf8_buf[0]))
 
1273
                         (ascii == 13) ||
 
1274
                         (ascii == 10) ||
 
1275
                         (ascii == 8)  ||
 
1276
                         (evt->utf8_buf[0]))
1252
1277
                {
1253
1278
 
1254
 
                        if (evt->utf8_buf[0]) {
 
1279
                        if (accentcode) {
 
1280
                                if (cu->pos > 0) {
 
1281
                                        inserted_text[0] = findaccent(ef->textbuf[cu->pos - 1], ascii);
 
1282
                                        ef->textbuf[cu->pos - 1] = inserted_text[0];
 
1283
                                }
 
1284
                                accentcode = 0;
 
1285
                        }
 
1286
                        else if (evt->utf8_buf[0]) {
1255
1287
                                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) {
1262
 
                                        inserted_text[0]= findaccent(ef->textbuf[cu->pos-1], ascii);
1263
 
                                        ef->textbuf[cu->pos-1]= inserted_text[0];
1264
 
                                }
1265
 
                                accentcode= 0;
1266
 
                        }
1267
 
                        else if (cu->len<MAXTEXT-1) {
1268
 
                                if (alt) {
1269
 
                                        /* might become obsolete, apple has default values for this, other OS's too? */
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;
1288
 
                                }
1289
 
 
1290
 
                                inserted_text[0]= ascii;
1291
 
                                insert_into_textbuf(obedit, ascii);
 
1288
                                ascii = inserted_text[0];
 
1289
                                insert_into_textbuf(obedit, ascii);
 
1290
                                accentcode = 0;
 
1291
                        }
 
1292
                        else if (ascii) {
 
1293
                                insert_into_textbuf(obedit, ascii);
 
1294
                                accentcode = 0;
 
1295
                        }
 
1296
                        else {
 
1297
                                BLI_assert(0);
1292
1298
                        }
1293
1299
                        
1294
1300
                        kill_selection(obedit, 1);
1295
1301
                        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1296
1302
                }
1297
1303
                else {
1298
 
                        inserted_text[0]= ascii;
 
1304
                        inserted_text[0] = ascii;
1299
1305
                        insert_into_textbuf(obedit, ascii);
1300
1306
                        text_update_edited(C, scene, obedit, 1, FO_EDIT);
1301
1307
                }
1302
1308
        }
1303
 
        else if (val && event == BACKSPACEKEY) {
1304
 
                if (alt && cu->len!=0 && cu->pos>0)
1305
 
                        accentcode= 1;
1306
 
 
1307
 
                return OPERATOR_PASS_THROUGH;
1308
 
        }
1309
1309
        else
1310
1310
                return OPERATOR_PASS_THROUGH;
1311
1311
 
1318
1318
        }
1319
1319
 
1320
1320
        /* reset property? */
1321
 
        accentcode= 0;
 
1321
        if (val == 0)
 
1322
                accentcode = 0;
1322
1323
        
1323
1324
        return OPERATOR_FINISHED;
1324
1325
}
1336
1337
        ot->poll = ED_operator_editfont;
1337
1338
        
1338
1339
        /* flags */
1339
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1340
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1340
1341
 
1341
1342
        /* properties */
1342
1343
        RNA_def_string(ot->srna, "text", "", 0, "Text", "Text to insert at the cursor position");
1347
1348
/*********************** textbox add operator *************************/
1348
1349
static int textbox_add_exec(bContext *C, wmOperator *UNUSED(op))
1349
1350
{
1350
 
        Object *obedit= CTX_data_active_object(C);
1351
 
        Curve *cu= obedit->data;
 
1351
        Object *obedit = CTX_data_active_object(C);
 
1352
        Curve *cu = obedit->data;
1352
1353
        int i;
1353
1354
        
1354
1355
        if (cu->totbox < 256) {
1355
 
                for (i = cu->totbox; i>cu->actbox; i--) cu->tb[i]= cu->tb[i-1];
1356
 
                cu->tb[cu->actbox]= cu->tb[cu->actbox-1];
 
1356
                for (i = cu->totbox; i > cu->actbox; i--) cu->tb[i] = cu->tb[i - 1];
 
1357
                cu->tb[cu->actbox] = cu->tb[cu->actbox - 1];
1357
1358
                cu->actbox++;
1358
1359
                cu->totbox++;
1359
1360
        }
1360
1361
        
1361
 
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
1362
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
1362
1363
        return OPERATOR_FINISHED;
1363
1364
}
1364
1365
 
1374
1375
        ot->poll = ED_operator_object_active_editable_font;
1375
1376
 
1376
1377
        /* flags */
1377
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1378
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1378
1379
        
1379
1380
        
1380
1381
}
1387
1388
 
1388
1389
static int textbox_remove_exec(bContext *C, wmOperator *op)
1389
1390
{
1390
 
        Object *obedit= CTX_data_active_object(C);
1391
 
        Curve *cu= obedit->data;
 
1391
        Object *obedit = CTX_data_active_object(C);
 
1392
        Curve *cu = obedit->data;
1392
1393
        int i;
1393
1394
        int index = RNA_int_get(op->ptr, "index");
1394
1395
        
1395
1396
        
1396
1397
        if (cu->totbox > 1) {
1397
 
                for (i = index; i < cu->totbox; i++) cu->tb[i]= cu->tb[i+1];
 
1398
                for (i = index; i < cu->totbox; i++) cu->tb[i] = cu->tb[i + 1];
1398
1399
                cu->totbox--;
1399
1400
                if (cu->actbox >= index)
1400
1401
                        cu->actbox--;
1401
1402
        }
1402
1403
        
1403
 
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
1404
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
1404
1405
        
1405
1406
        return OPERATOR_FINISHED;
1406
1407
}
1417
1418
        ot->poll = ED_operator_object_active_editable_font;
1418
1419
        
1419
1420
        /* flags */
1420
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1421
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1421
1422
        
1422
1423
        RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "The current text box", 0, INT_MAX);
1423
1424
}
1428
1429
 
1429
1430
void make_editText(Object *obedit)
1430
1431
{
1431
 
        Curve *cu= obedit->data;
1432
 
        EditFont *ef= cu->editfont;
1433
 
        
1434
 
        if (ef==NULL) {
1435
 
                ef= cu->editfont= MEM_callocN(sizeof(EditFont), "editfont");
1436
 
        
1437
 
                ef->textbuf= MEM_callocN((MAXTEXT+4)*sizeof(wchar_t), "texteditbuf");
1438
 
                ef->textbufinfo= MEM_callocN((MAXTEXT+4)*sizeof(CharInfo), "texteditbufinfo");
1439
 
                ef->copybuf= MEM_callocN((MAXTEXT+4)*sizeof(wchar_t), "texteditcopybuf");
1440
 
                ef->copybufinfo= MEM_callocN((MAXTEXT+4)*sizeof(CharInfo), "texteditcopybufinfo");      
1441
 
                ef->oldstr= MEM_callocN((MAXTEXT+4)*sizeof(wchar_t), "oldstrbuf");
1442
 
                ef->oldstrinfo= MEM_callocN((MAXTEXT+4)*sizeof(CharInfo), "oldstrbuf");
 
1432
        Curve *cu = obedit->data;
 
1433
        EditFont *ef = cu->editfont;
 
1434
        
 
1435
        if (ef == NULL) {
 
1436
                ef = cu->editfont = MEM_callocN(sizeof(EditFont), "editfont");
 
1437
        
 
1438
                ef->textbuf = MEM_callocN((MAXTEXT + 4) * sizeof(wchar_t), "texteditbuf");
 
1439
                ef->textbufinfo = MEM_callocN((MAXTEXT + 4) * sizeof(CharInfo), "texteditbufinfo");
 
1440
                ef->copybuf = MEM_callocN((MAXTEXT + 4) * sizeof(wchar_t), "texteditcopybuf");
 
1441
                ef->copybufinfo = MEM_callocN((MAXTEXT + 4) * sizeof(CharInfo), "texteditcopybufinfo");
 
1442
                ef->oldstr = MEM_callocN((MAXTEXT + 4) * sizeof(wchar_t), "oldstrbuf");
 
1443
                ef->oldstrinfo = MEM_callocN((MAXTEXT + 4) * sizeof(CharInfo), "oldstrbuf");
1443
1444
        }
1444
1445
        
1445
 
        // Convert the original text to wchar_t
1446
 
        BLI_strncpy_wchar_from_utf8(ef->textbuf, cu->str, MAXTEXT+4); /* length is bogus */
 
1446
        /* Convert the original text to wchar_t */
 
1447
        BLI_strncpy_wchar_from_utf8(ef->textbuf, cu->str, MAXTEXT + 4); /* length is bogus */
1447
1448
        wcscpy(ef->oldstr, ef->textbuf);
1448
 
                
1449
 
        cu->len= wcslen(ef->textbuf);
1450
 
        
1451
 
        memcpy(ef->textbufinfo, cu->strinfo, (cu->len)*sizeof(CharInfo));
1452
 
        memcpy(ef->oldstrinfo, cu->strinfo, (cu->len)*sizeof(CharInfo));
1453
 
 
1454
 
        if (cu->pos>cu->len) cu->pos= cu->len;
 
1449
 
 
1450
        cu->len = wcslen(ef->textbuf);
 
1451
 
 
1452
        memcpy(ef->textbufinfo, cu->strinfo, (cu->len) * sizeof(CharInfo));
 
1453
        memcpy(ef->oldstrinfo, cu->strinfo, (cu->len) * sizeof(CharInfo));
 
1454
 
 
1455
        if (cu->pos > cu->len) cu->pos = cu->len;
1455
1456
 
1456
1457
        if (cu->pos)
1457
 
                cu->curinfo = ef->textbufinfo[cu->pos-1];
 
1458
                cu->curinfo = ef->textbufinfo[cu->pos - 1];
1458
1459
        else
1459
1460
                cu->curinfo = ef->textbufinfo[0];
1460
 
        
1461
 
        // Convert to UTF-8
 
1461
 
 
1462
        /* Convert to UTF-8 */
1462
1463
        update_string(cu);
1463
1464
}
1464
1465
 
1465
1466
void load_editText(Object *obedit)
1466
1467
{
1467
 
        Curve *cu= obedit->data;
1468
 
        EditFont *ef= cu->editfont;
 
1468
        Curve *cu = obedit->data;
 
1469
        EditFont *ef = cu->editfont;
1469
1470
        
1470
1471
        MEM_freeN(ef->oldstr);
1471
 
        ef->oldstr= NULL;
 
1472
        ef->oldstr = NULL;
1472
1473
        MEM_freeN(ef->oldstrinfo);
1473
 
        ef->oldstrinfo= NULL;
 
1474
        ef->oldstrinfo = NULL;
1474
1475
        
1475
1476
        update_string(cu);
1476
1477
        
1477
1478
        if (cu->strinfo)
1478
1479
                MEM_freeN(cu->strinfo);
1479
 
        cu->strinfo= MEM_callocN((cu->len+4)*sizeof(CharInfo), "texteditinfo");
1480
 
        memcpy(cu->strinfo, ef->textbufinfo, (cu->len)*sizeof(CharInfo));
 
1480
        cu->strinfo = MEM_callocN((cu->len + 4) * sizeof(CharInfo), "texteditinfo");
 
1481
        memcpy(cu->strinfo, ef->textbufinfo, (cu->len) * sizeof(CharInfo));
1481
1482
 
1482
 
        cu->len= strlen(cu->str);
 
1483
        cu->len = strlen(cu->str);
1483
1484
        
1484
1485
        /* this memory system is weak... */
1485
1486
        
1486
1487
        if (cu->selboxes) {
1487
1488
                MEM_freeN(cu->selboxes);
1488
 
                cu->selboxes= NULL;
 
1489
                cu->selboxes = NULL;
1489
1490
        }
1490
1491
}
1491
1492
 
1492
1493
void free_editText(Object *obedit)
1493
1494
{
1494
 
        BKE_free_editfont((Curve *)obedit->data);
 
1495
        BKE_curve_editfont_free((Curve *)obedit->data);
1495
1496
}
1496
1497
 
1497
1498
/********************** set case operator *********************/
1498
1499
 
1499
 
static EnumPropertyItem case_items[]= {
 
1500
static EnumPropertyItem case_items[] = {
1500
1501
        {CASE_LOWER, "LOWER", 0, "Lower", ""},
1501
1502
        {CASE_UPPER, "UPPER", 0, "Upper", ""},
1502
1503
        {0, NULL, 0, NULL, NULL}};
1503
1504
 
1504
1505
static int set_case(bContext *C, int ccase)
1505
1506
{
1506
 
        Scene *scene= CTX_data_scene(C);
1507
 
        Object *obedit= CTX_data_edit_object(C);
1508
 
        Curve *cu= obedit->data;
1509
 
        EditFont *ef= cu->editfont;
 
1507
        Scene *scene = CTX_data_scene(C);
 
1508
        Object *obedit = CTX_data_edit_object(C);
 
1509
        Curve *cu = obedit->data;
 
1510
        EditFont *ef = cu->editfont;
1510
1511
        wchar_t *str;
1511
1512
        int len;
1512
1513
        
1513
 
        len= wcslen(ef->textbuf);
1514
 
        str= ef->textbuf;
 
1514
        len = wcslen(ef->textbuf);
 
1515
        str = ef->textbuf;
1515
1516
        while (len) {
1516
 
                if (*str>='a' && *str<='z')
1517
 
                        *str-= 32;
 
1517
                if (*str >= 'a' && *str <= 'z')
 
1518
                        *str -= 32;
1518
1519
                len--;
1519
1520
                str++;
1520
1521
        }
1521
1522
        
1522
1523
        if (ccase == CASE_LOWER) {
1523
 
                len= wcslen(ef->textbuf);
1524
 
                str= ef->textbuf;
 
1524
                len = wcslen(ef->textbuf);
 
1525
                str = ef->textbuf;
1525
1526
                while (len) {
1526
 
                        if (*str>='A' && *str<='Z') {
1527
 
                                *str+= 32;
 
1527
                        if (*str >= 'A' && *str <= 'Z') {
 
1528
                                *str += 32;
1528
1529
                        }
1529
1530
                        len--;
1530
1531
                        str++;
1553
1554
        ot->poll = ED_operator_editfont;
1554
1555
 
1555
1556
        /* flags */
1556
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1557
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1557
1558
 
1558
1559
        /* properties */
1559
1560
        RNA_def_enum(ot->srna, "case", case_items, CASE_LOWER, "Case", "Lower or upper case");
1563
1564
 
1564
1565
static int toggle_case_exec(bContext *C, wmOperator *UNUSED(op))
1565
1566
{
1566
 
        Object *obedit= CTX_data_edit_object(C);
1567
 
        Curve *cu= obedit->data;
1568
 
        EditFont *ef= cu->editfont;
 
1567
        Object *obedit = CTX_data_edit_object(C);
 
1568
        Curve *cu = obedit->data;
 
1569
        EditFont *ef = cu->editfont;
1569
1570
        wchar_t *str;
1570
 
        int len, ccase= CASE_UPPER;
 
1571
        int len, ccase = CASE_UPPER;
1571
1572
        
1572
 
        len= wcslen(ef->textbuf);
1573
 
        str= ef->textbuf;
 
1573
        len = wcslen(ef->textbuf);
 
1574
        str = ef->textbuf;
1574
1575
        while (len) {
1575
 
                if (*str>='a' && *str<='z') {
1576
 
                        ccase= CASE_LOWER;
 
1576
                if (*str >= 'a' && *str <= 'z') {
 
1577
                        ccase = CASE_LOWER;
1577
1578
                        break;
1578
1579
                }
1579
1580
 
1596
1597
        ot->poll = ED_operator_editfont;
1597
1598
 
1598
1599
        /* flags */
1599
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1600
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1600
1601
}
1601
1602
 
1602
1603
/* **************** Open Font ************** */
1605
1606
{
1606
1607
        PropertyPointerRNA *pprop;
1607
1608
        
1608
 
        op->customdata= pprop= MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
 
1609
        op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
1609
1610
        uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
1610
1611
}
1611
1612
 
1612
1613
static int font_open_cancel(bContext *UNUSED(C), wmOperator *op)
1613
1614
{
1614
1615
        MEM_freeN(op->customdata);
1615
 
        op->customdata= NULL;
 
1616
        op->customdata = NULL;
1616
1617
        return OPERATOR_CANCELLED;
1617
1618
}
1618
1619
 
1619
1620
static int font_open_exec(bContext *C, wmOperator *op)
1620
1621
{
1621
 
        struct Main *bmain= CTX_data_main(C);
 
1622
        struct Main *bmain = CTX_data_main(C);
1622
1623
        VFont *font;
1623
1624
        PropertyPointerRNA *pprop;
1624
1625
        PointerRNA idptr;
1625
1626
        char filepath[FILE_MAX];
1626
1627
        RNA_string_get(op->ptr, "filepath", filepath);
1627
1628
 
1628
 
        font= load_vfont(bmain, filepath);
 
1629
        font = BKE_vfont_load(bmain, filepath);
1629
1630
 
1630
1631
        if (!font) {
1631
1632
                if (op->customdata) MEM_freeN(op->customdata);
1636
1637
                font_ui_template_init(C, op);
1637
1638
        
1638
1639
        /* hook into UI */
1639
 
        pprop= op->customdata;
 
1640
        pprop = op->customdata;
1640
1641
 
1641
1642
        if (pprop->prop) {
1642
1643
                /* when creating new ID blocks, use is already 1, but RNA
1655
1656
 
1656
1657
static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1657
1658
{
1658
 
        VFont *font=NULL;
 
1659
        VFont *vfont = NULL;
1659
1660
        char *path;
1660
1661
 
1661
1662
        PointerRNA idptr;
1664
1665
        font_ui_template_init(C, op);
1665
1666
 
1666
1667
        /* hook into UI */
1667
 
        pprop= op->customdata;
 
1668
        pprop = op->customdata;
1668
1669
 
1669
1670
        if (pprop->prop) {
1670
 
                idptr= RNA_property_pointer_get((PointerRNA *)pprop, pprop->prop);
1671
 
                font= idptr.id.data;
 
1671
                idptr = RNA_property_pointer_get((PointerRNA *)pprop, pprop->prop);
 
1672
                vfont = idptr.id.data;
1672
1673
        }
1673
1674
 
1674
 
        path = (font && strcmp(font->name, FO_BUILTIN_NAME) != 0)? font->name: U.fontdir;
 
1675
        path = (vfont && !BKE_vfont_is_builtin(vfont)) ? vfont->name : U.fontdir;
1675
1676
 
1676
1677
        if (RNA_struct_property_is_set(op->ptr, "filepath"))
1677
1678
                return font_open_exec(C, op);
1687
1688
        /* identifiers */
1688
1689
        ot->name = "Open Font";
1689
1690
        ot->idname = "FONT_OT_open";
 
1691
        ot->description = "Load a new font from a file";
1690
1692
        
1691
1693
        /* api callbacks */
1692
1694
        ot->exec = font_open_exec;
1694
1696
        ot->cancel = font_open_cancel;
1695
1697
        
1696
1698
        /* flags */
1697
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1699
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1698
1700
        
1699
1701
        /* properties */
1700
 
        WM_operator_properties_filesel(ot, FOLDERFILE|FTFONTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY);
 
1702
        WM_operator_properties_filesel(ot, FOLDERFILE | FTFONTFILE, FILE_SPECIAL, FILE_OPENFILE,
 
1703
                                       WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY);
1701
1704
}
1702
1705
 
1703
1706
/******************* delete operator *********************/
1711
1714
 
1712
1715
        uiIDContextProperty(C, &pprop.ptr, &pprop.prop);
1713
1716
        
1714
 
        if (pprop.prop==NULL) {
 
1717
        if (pprop.prop == NULL) {
1715
1718
                BKE_report(op->reports, RPT_ERROR, "Incorrect context for running font unlink");
1716
1719
                return OPERATOR_CANCELLED;
1717
1720
        }
1718
1721
 
1719
 
        builtin_font = get_builtin_font();
 
1722
        builtin_font = BKE_vfont_builtin_get();
1720
1723
 
1721
1724
        RNA_id_pointer_create(&builtin_font->id, &idptr);
1722
1725
        RNA_property_pointer_set(&pprop.ptr, pprop.prop, idptr);
1741
1744
 
1742
1745
static void undoFont_to_editFont(void *strv, void *ecu, void *UNUSED(obdata))
1743
1746
{
1744
 
        Curve *cu= (Curve *)ecu;
1745
 
        EditFont *ef= cu->editfont;
1746
 
        char *str= strv;
1747
 
 
1748
 
        cu->pos= *((short *)str);
1749
 
        cu->len= *((short *)(str+2));
1750
 
 
1751
 
        memcpy(ef->textbuf, str+4, (cu->len+1)*sizeof(wchar_t));
1752
 
        memcpy(ef->textbufinfo, str+4 + (cu->len+1)*sizeof(wchar_t), cu->len*sizeof(CharInfo));
 
1747
        Curve *cu = (Curve *)ecu;
 
1748
        EditFont *ef = cu->editfont;
 
1749
        char *str = strv;
 
1750
 
 
1751
        cu->pos = *((short *)str);
 
1752
        cu->len = *((short *)(str + 2));
 
1753
 
 
1754
        memcpy(ef->textbuf, str + 4, (cu->len + 1) * sizeof(wchar_t));
 
1755
        memcpy(ef->textbufinfo, str + 4 + (cu->len + 1) * sizeof(wchar_t), cu->len * sizeof(CharInfo));
1753
1756
        
1754
1757
        cu->selstart = cu->selend = 0;
1755
1758
        
1758
1761
 
1759
1762
static void *editFont_to_undoFont(void *ecu, void *UNUSED(obdata))
1760
1763
{
1761
 
        Curve *cu= (Curve *)ecu;
1762
 
        EditFont *ef= cu->editfont;
 
1764
        Curve *cu = (Curve *)ecu;
 
1765
        EditFont *ef = cu->editfont;
1763
1766
        char *str;
1764
1767
        
1765
 
        // The undo buffer includes [MAXTEXT+6]=actual string and [MAXTEXT+4]*sizeof(CharInfo)=charinfo
1766
 
        str= MEM_callocN((MAXTEXT+6)*sizeof(wchar_t) + (MAXTEXT+4)*sizeof(CharInfo), "string undo");
1767
 
 
1768
 
        // Copy the string and string information
1769
 
        memcpy(str+4, ef->textbuf, (cu->len+1)*sizeof(wchar_t));
1770
 
        memcpy(str+4 + (cu->len+1)*sizeof(wchar_t), ef->textbufinfo, cu->len*sizeof(CharInfo));
1771
 
 
1772
 
        *((short *)str)= cu->pos;
1773
 
        *((short *)(str+2))= cu->len;   
 
1768
        /* The undo buffer includes [MAXTEXT+6]=actual string and [MAXTEXT+4]*sizeof(CharInfo)=charinfo */
 
1769
        str = MEM_callocN((MAXTEXT + 6) * sizeof(wchar_t) + (MAXTEXT + 4) * sizeof(CharInfo), "string undo");
 
1770
 
 
1771
        /* Copy the string and string information */
 
1772
        memcpy(str + 4, ef->textbuf, (cu->len + 1) * sizeof(wchar_t));
 
1773
        memcpy(str + 4 + (cu->len + 1) * sizeof(wchar_t), ef->textbufinfo, cu->len * sizeof(CharInfo));
 
1774
 
 
1775
        *((short *)str) = cu->pos;
 
1776
        *((short *)(str + 2)) = cu->len;
1774
1777
        
1775
1778
        return str;
1776
1779
}
1782
1785
 
1783
1786
static void *get_undoFont(bContext *C)
1784
1787
{
1785
 
        Object *obedit= CTX_data_edit_object(C);
1786
 
        if (obedit && obedit->type==OB_FONT) {
 
1788
        Object *obedit = CTX_data_edit_object(C);
 
1789
        if (obedit && obedit->type == OB_FONT) {
1787
1790
                return obedit->data;
1788
1791
        }
1789
1792
        return NULL;