75
75
#include "curve_intern.h"
79
79
/************************* utilities ******************************/
81
81
static char findaccent(char char1, unsigned int code)
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;
95
else if (char1=='c') {
96
if (code==',') new= 231;
97
if (code=='|') new= 162;
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;
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;
111
else if (char1=='n') {
112
if (code=='~') new= 241;
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;
124
else if (char1=='s') {
125
if (code=='s') new= 167;
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;
133
else if (char1=='y') {
134
if (code==39) new= 253;
135
else if (code=='"') new= 255;
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;
146
else if (char1=='C') {
147
if (code==',') new= 199;
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;
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;
161
else if (char1=='N') {
162
if (code=='~') new= 209;
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;
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;
179
else if (char1=='Y') {
180
if (code==39) new= 221;
182
else if (char1=='1') {
183
if (code=='4') new= 188;
184
if (code=='2') new= 189;
186
else if (char1=='3') {
187
if (code=='4') new= 190;
189
else if (char1==':') {
190
if (code=='-') new= 247;
192
else if (char1=='-') {
193
if (code==':') new= 247;
194
if (code=='|') new= 135;
195
if (code=='+') new= 177;
197
else if (char1=='|') {
198
if (code=='-') new= 135;
199
if (code=='=') new= 136;
201
else if (char1=='=') {
202
if (code=='|') new= 136;
204
else if (char1=='+') {
205
if (code=='-') new= 177;
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;
95
else if (char1 == 'c') {
96
if (code == ',') new = 231;
97
else if (code == '|') new = 162;
98
else if (code == 'o') new = 169;
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;
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;
112
else if (char1 == 'n') {
113
if (code == '~') new = 241;
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;
127
else if (char1 == 'r') {
128
if (code == 'o') new = 174;
130
else if (char1 == 's') {
131
if (code == 's') new = 167;
133
else if (char1 == 't') {
134
if (code == 'm') new = 153;
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;
142
else if (char1 == 'y') {
143
if (code == 39) new = 253;
144
else if (code == '"') new = 255;
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;
155
else if (char1 == 'C') {
156
if (code == ',') new = 199;
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;
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;
170
else if (char1 == 'N') {
171
if (code == '~') new = 209;
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;
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;
188
else if (char1 == 'Y') {
189
if (code == 39) new = 221;
191
else if (char1 == '1') {
192
if (code == '4') new = 188;
193
if (code == '2') new = 189;
195
else if (char1 == '3') {
196
if (code == '4') new = 190;
198
else if (char1 == ':') {
199
if (code == '-') new = 247;
201
else if (char1 == '-') {
202
if (code == ':') new = 247;
203
if (code == '|') new = 135;
204
if (code == '+') new = 177;
206
else if (char1 == '|') {
207
if (code == '-') new = 135;
208
if (code == '=') new = 136;
210
else if (char1 == '=') {
211
if (code == '|') new = 136;
213
else if (char1 == '+') {
214
if (code == '-') new = 177;
208
217
if (new) return new;
213
222
static void update_string(Curve *cu)
215
EditFont *ef= cu->editfont;
224
EditFont *ef = cu->editfont;
218
// Free the old curve string
227
/* Free the old curve string */
219
228
MEM_freeN(cu->str);
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);
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");
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);
231
240
static int insert_into_textbuf(Object *obedit, uintptr_t c)
233
Curve *cu= obedit->data;
242
Curve *cu = obedit->data;
235
if (cu->len<MAXTEXT-1) {
236
EditFont *ef= cu->editfont;
244
if (cu->len < MAXTEXT - 1) {
245
EditFont *ef = cu->editfont;
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;
248
ef->textbuf[cu->len]='\0';
257
ef->textbuf[cu->len] = '\0';
250
259
update_string(cu);
258
267
static void text_update_edited(bContext *C, Scene *scene, Object *obedit, int recalc, int mode)
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];
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;
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) {
275
284
if (mode == FO_EDIT)
276
285
update_string(cu);
278
BKE_text_to_curve(bmain, scene, obedit, mode);
287
BKE_vfont_to_curve(bmain, scene, obedit, mode);
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);
285
294
/********************** insert lorem operator *********************/
287
296
static int insert_lorem_exec(bContext *C, wmOperator *UNUSED(op))
289
Object *obedit= CTX_data_edit_object(C);
298
Object *obedit = CTX_data_edit_object(C);
290
299
const char *p, *p2;
292
301
static const char *lastlorem;
299
i= rand()/(RAND_MAX/6)+4;
308
i = rand() / (RAND_MAX / 6) + 4;
301
for (p2=p; *p2 && i; p2++) {
310
for (p2 = p; *p2 && i; p2++) {
302
311
insert_into_textbuf(obedit, *p2);
309
if (strlen(lastlorem)<5)
318
if (strlen(lastlorem) < 5)
310
319
lastlorem = ED_lorem;
312
321
insert_into_textbuf(obedit, '\n');
313
insert_into_textbuf(obedit, '\n');
322
insert_into_textbuf(obedit, '\n');
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);
318
327
return OPERATOR_FINISHED;
437
447
int nchars = 0, a;
438
448
float rot[3] = {0.f, 0.f, 0.f};
440
obedit= add_object(scene, OB_FONT);
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;
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);
456
BKE_object_where_is_calc(scene, obedit);
447
458
obedit->loc[0] += offset[0];
448
459
obedit->loc[1] += offset[1];
449
460
obedit->loc[2] += offset[2];
452
cu->vfont= get_builtin_font();
463
cu->vfont = BKE_vfont_builtin_get();
453
464
cu->vfont->id.us++;
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;
458
469
if (cu->str) MEM_freeN(cu->str);
459
if (cu->strinfo) MEM_freeN(cu->strinfo);
461
cu->str= MEM_callocN(nchars+4, "str");
462
cu->strinfo= MEM_callocN((nchars+4)*sizeof(CharInfo), "strinfo");
470
if (cu->strinfo) MEM_freeN(cu->strinfo);
472
cu->str = MEM_callocN(nchars + 4, "str");
473
cu->strinfo = MEM_callocN((nchars + 4) * sizeof(CharInfo), "strinfo");
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);
473
484
strcat(cu->str, "\n");
480
WM_event_add_notifier(C, NC_OBJECT|NA_ADDED, obedit);
491
WM_event_add_notifier(C, NC_OBJECT | NA_ADDED, obedit);
483
494
void ED_text_to_object(bContext *C, Text *text, int split_lines)
485
RegionView3D *rv3d= CTX_wm_region_view3d(C);
496
RegionView3D *rv3d = CTX_wm_region_view3d(C);
490
501
if (!text || !text->lines.first) return;
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') {
518
529
txt_add_object(C, text->lines.first, BLI_countlist(&text->lines), offset);
522
533
/********************** utilities ***************************/
524
534
static short next_word(Curve *cu)
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'));
544
return cu->str[s] ? (s + 1) : s;
532
547
static short prev_word(Curve *cu)
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'));
559
return cu->str[s] ? (s + 1) : s;
542
static int kill_selection(Object *obedit, int ins) /* 1 == new character */
562
static int kill_selection(Object *obedit, int ins) /* 1 == new character */
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;
550
direction = BKE_font_getselection(obedit, &selstart, &selend);
570
direction = BKE_vfont_select_get(obedit, &selstart, &selend);
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) {
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;
571
591
/******************* set style operator ********************/
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}
580
601
static int set_style(bContext *C, const int style, const int clear)
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;
587
if (!BKE_font_getselection(obedit, &selstart, &selend))
608
if (!BKE_vfont_select_get(obedit, &selstart, &selend))
588
609
return OPERATOR_CANCELLED;
590
for (i=selstart; i<=selend; i++) {
611
for (i = selstart; i <= selend; i++) {
592
613
ef->textbufinfo[i].flag &= ~style;
732
753
ot->poll = ED_operator_editfont;
735
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
756
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
738
759
/******************* paste text operator ********************/
740
761
static int paste_selection(Object *obedit, ReportList *reports)
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);
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) {
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));
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));
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));
811
832
static int move_cursor(bContext *C, int type, int select)
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;
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;
821
if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
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;
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;
842
if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
843
cu->pos= prev_word(cu);
863
if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
864
cu->pos = prev_word(cu);
848
if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
849
cu->pos= next_word(cu);
869
if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
870
cu->pos = next_word(cu);
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;
860
if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
881
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;
888
if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
889
cursmove = FO_CURSUP;
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;
877
if ((select) && (cu->selstart==0)) cu->selstart = cu->selend = cu->pos+1;
898
if ((select) && (cu->selstart == 0)) cu->selstart = cu->selend = cu->pos + 1;
899
cursmove = FO_PAGEUP;
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;
965
986
static int change_spacing_exec(bContext *C, wmOperator *op)
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");
973
kern = ef->textbufinfo[cu->pos-1].kern;
994
kern = ef->textbufinfo[cu->pos - 1].kern;
975
996
CLAMP(kern, -20, 20);
977
if (ef->textbufinfo[cu->pos-1].kern == kern)
998
if (ef->textbufinfo[cu->pos - 1].kern == kern)
978
999
return OPERATOR_CANCELLED;
980
ef->textbufinfo[cu->pos-1].kern = kern;
1001
ef->textbufinfo[cu->pos - 1].kern = kern;
982
1003
text_update_edited(C, scene, obedit, 1, FO_EDIT);
1007
1028
static int change_character_exec(bContext *C, wmOperator *op)
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");
1015
1036
if (cu->pos <= 0)
1016
1037
return OPERATOR_CANCELLED;
1018
character= ef->textbuf[cu->pos - 1];
1039
character = ef->textbuf[cu->pos - 1];
1019
1040
character += delta;
1020
1041
CLAMP(character, 0, 255);
1022
1043
if (character == ef->textbuf[cu->pos - 1])
1023
1044
return OPERATOR_CANCELLED;
1025
ef->textbuf[cu->pos - 1]= character;
1046
ef->textbuf[cu->pos - 1] = character;
1027
1048
text_update_edited(C, scene, obedit, 1, FO_EDIT);
1104
1125
static int delete_exec(bContext *C, wmOperator *op)
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");
1112
1133
if (cu->len == 0)
1113
1134
return OPERATOR_CANCELLED;
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;
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;
1126
1147
cu->len = cu->pos = 0;
1129
1150
case DEL_SELECTION:
1130
1151
if (!kill_selection(obedit, 0))
1131
1152
return OPERATOR_CANCELLED;
1133
1154
case DEL_PREV_CHAR:
1135
1156
return OPERATOR_CANCELLED;
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];
1143
ef->textbuf[--cu->len]='\0';
1164
ef->textbuf[--cu->len] = '\0';
1145
1166
case DEL_NEXT_CHAR:
1146
if (cu->pos>=cu->len)
1167
if (cu->pos >= cu->len)
1147
1168
return OPERATOR_CANCELLED;
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];
1154
ef->textbuf[--cu->len]='\0';
1175
ef->textbuf[--cu->len] = '\0';
1157
1178
return OPERATOR_CANCELLED;
1214
1235
static int insert_text_invoke(bContext *C, wmOperator *op, wmEvent *evt)
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};
1226
1247
if (RNA_struct_property_is_set(op->ptr, "text"))
1227
1248
return insert_text_exec(C, op);
1229
1250
if (RNA_struct_property_is_set(op->ptr, "accent")) {
1230
if (cu->len!=0 && cu->pos>0)
1251
if (cu->len != 0 && cu->pos > 0)
1232
1253
return OPERATOR_FINISHED;
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;
1242
else if (event==BACKSPACEKEY)
1264
if (event == BACKSPACEKEY) {
1265
if (alt && cu->len != 0 && cu->pos > 0)
1267
return OPERATOR_PASS_THROUGH;
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) ||
1254
if (evt->utf8_buf[0]) {
1281
inserted_text[0] = findaccent(ef->textbuf[cu->pos - 1], ascii);
1282
ef->textbuf[cu->pos - 1] = inserted_text[0];
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);
1260
else if (accentcode) {
1262
inserted_text[0]= findaccent(ef->textbuf[cu->pos-1], ascii);
1263
ef->textbuf[cu->pos-1]= inserted_text[0];
1267
else if (cu->len<MAXTEXT-1) {
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;
1290
inserted_text[0]= ascii;
1291
insert_into_textbuf(obedit, ascii);
1288
ascii = inserted_text[0];
1289
insert_into_textbuf(obedit, ascii);
1293
insert_into_textbuf(obedit, ascii);
1294
1300
kill_selection(obedit, 1);
1295
1301
text_update_edited(C, scene, obedit, 1, FO_EDIT);
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);
1303
else if (val && event == BACKSPACEKEY) {
1304
if (alt && cu->len!=0 && cu->pos>0)
1307
return OPERATOR_PASS_THROUGH;
1310
1310
return OPERATOR_PASS_THROUGH;
1429
1430
void make_editText(Object *obedit)
1431
Curve *cu= obedit->data;
1432
EditFont *ef= cu->editfont;
1435
ef= cu->editfont= MEM_callocN(sizeof(EditFont), "editfont");
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;
1436
ef = cu->editfont = MEM_callocN(sizeof(EditFont), "editfont");
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");
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);
1449
cu->len= wcslen(ef->textbuf);
1451
memcpy(ef->textbufinfo, cu->strinfo, (cu->len)*sizeof(CharInfo));
1452
memcpy(ef->oldstrinfo, cu->strinfo, (cu->len)*sizeof(CharInfo));
1454
if (cu->pos>cu->len) cu->pos= cu->len;
1450
cu->len = wcslen(ef->textbuf);
1452
memcpy(ef->textbufinfo, cu->strinfo, (cu->len) * sizeof(CharInfo));
1453
memcpy(ef->oldstrinfo, cu->strinfo, (cu->len) * sizeof(CharInfo));
1455
if (cu->pos > cu->len) cu->pos = cu->len;
1457
cu->curinfo = ef->textbufinfo[cu->pos-1];
1458
cu->curinfo = ef->textbufinfo[cu->pos - 1];
1459
1460
cu->curinfo = ef->textbufinfo[0];
1462
/* Convert to UTF-8 */
1462
1463
update_string(cu);
1465
1466
void load_editText(Object *obedit)
1467
Curve *cu= obedit->data;
1468
EditFont *ef= cu->editfont;
1468
Curve *cu = obedit->data;
1469
EditFont *ef = cu->editfont;
1470
1471
MEM_freeN(ef->oldstr);
1472
1473
MEM_freeN(ef->oldstrinfo);
1473
ef->oldstrinfo= NULL;
1474
ef->oldstrinfo = NULL;
1475
1476
update_string(cu);
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));
1482
cu->len= strlen(cu->str);
1483
cu->len = strlen(cu->str);
1484
1485
/* this memory system is weak... */
1486
1487
if (cu->selboxes) {
1487
1488
MEM_freeN(cu->selboxes);
1489
cu->selboxes = NULL;
1492
1493
void free_editText(Object *obedit)
1494
BKE_free_editfont((Curve *)obedit->data);
1495
BKE_curve_editfont_free((Curve *)obedit->data);
1497
1498
/********************** set case operator *********************/
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}};
1504
1505
static int set_case(bContext *C, int ccase)
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;
1513
len= wcslen(ef->textbuf);
1514
len = wcslen(ef->textbuf);
1516
if (*str>='a' && *str<='z')
1517
if (*str >= 'a' && *str <= 'z')
1522
1523
if (ccase == CASE_LOWER) {
1523
len= wcslen(ef->textbuf);
1524
len = wcslen(ef->textbuf);
1526
if (*str>='A' && *str<='Z') {
1527
if (*str >= 'A' && *str <= 'Z') {
1759
1762
static void *editFont_to_undoFont(void *ecu, void *UNUSED(obdata))
1761
Curve *cu= (Curve *)ecu;
1762
EditFont *ef= cu->editfont;
1764
Curve *cu = (Curve *)ecu;
1765
EditFont *ef = cu->editfont;
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");
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));
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");
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));
1775
*((short *)str) = cu->pos;
1776
*((short *)(str + 2)) = cu->len;