| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include <fontforge-config.h> |
| 31 |
|
| 32 |
#include "fvfonts.h" |
| 33 |
#include "ggadget.h" |
| 34 |
#include "gwidget.h" |
| 35 |
#include "uiinterface.h" |
| 36 |
#include "ustring.h" |
| 37 |
#include "wordlistparser.h" |
| 38 |
|
| 39 |
#include <ctype.h> |
| 40 |
#include <string.h> |
| 41 |
|
| 42 |
|
| 43 |
const char* Wordlist_getSCName( SplineChar* sc ) |
| 44 |
{ |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
static char ret[ 1024 ]; |
| 50 |
int simple = false; |
| 51 |
|
| 52 |
|
| 53 |
if( sc->unicodeenc != -1 ) { |
| 54 |
if( strlen( sc->name ) == 1 ) |
| 55 |
{ |
| 56 |
char ch = sc->name[0]; |
| 57 |
|
| 58 |
if( ch >= 'a' && ch <= 'z' ) |
| 59 |
simple = true; |
| 60 |
else if( ch >= '0' && ch <= '9' ) |
| 61 |
simple = true; |
| 62 |
if( ch >= 'A' && ch <= 'Z' ) |
| 63 |
simple = true; |
| 64 |
|
| 65 |
if( simple ) |
| 66 |
{ |
| 67 |
strcpy( ret, sc->name ); |
| 68 |
return ret; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
if( !strcmp( sc->name, "zero" )) |
| 73 |
return "0"; |
| 74 |
if( !strcmp( sc->name, "one" )) |
| 75 |
return "1"; |
| 76 |
if( !strcmp( sc->name, "two" )) |
| 77 |
return "2"; |
| 78 |
if( !strcmp( sc->name, "three" )) |
| 79 |
return "3"; |
| 80 |
if( !strcmp( sc->name, "four" )) |
| 81 |
return "4"; |
| 82 |
if( !strcmp( sc->name, "five" )) |
| 83 |
return "5"; |
| 84 |
if( !strcmp( sc->name, "six" )) |
| 85 |
return "6"; |
| 86 |
if( !strcmp( sc->name, "seven" )) |
| 87 |
return "7"; |
| 88 |
if( !strcmp( sc->name, "eight" )) |
| 89 |
return "8"; |
| 90 |
if( !strcmp( sc->name, "nine" )) |
| 91 |
return "9"; |
| 92 |
} |
| 93 |
|
| 94 |
snprintf( ret, 1024, "/%s", sc->name ); |
| 95 |
return ret; |
| 96 |
} |
| 97 |
|
| 98 |
static SplineChar* |
| 99 |
u_WordlistEscapedInputStringToRealString_readGlyphName( |
| 100 |
SplineFont *sf, unichar_t* in, unichar_t* in_end, |
| 101 |
unichar_t** updated_in, unichar_t* glyphname ) |
| 102 |
{ |
| 103 |
int startedWithBackSlash = (*in == '\\'); |
| 104 |
if( *in != '/' && *in != '\\' ) |
| 105 |
return 0; |
| 106 |
bool startsWithBackSlash = *in == '\\'; |
| 107 |
|
| 108 |
in++; |
| 109 |
unichar_t* startpos = in; |
| 110 |
|
| 111 |
|
| 112 |
memset( glyphname, '\0', PATH_MAX ); |
| 113 |
unichar_t* outname = glyphname; |
| 114 |
while( *in != '/' |
| 115 |
&& ( !startsWithBackSlash || *in != '\\' ) |
| 116 |
&& *in != ' ' && *in != ']' && in != in_end ) |
| 117 |
{ |
| 118 |
*outname = *in; |
| 119 |
++outname; |
| 120 |
in++; |
| 121 |
} |
| 122 |
bool FullMatchEndsOnSpace = 0; |
| 123 |
unichar_t* maxpos = in; |
| 124 |
unichar_t* endpos = maxpos-1; |
| 125 |
|
| 126 |
|
| 127 |
int loopCounter = 0; |
| 128 |
int firstLookup = 1; |
| 129 |
for( ; endpos >= startpos; endpos--, loopCounter++ ) |
| 130 |
{ |
| 131 |
|
| 132 |
SplineChar* sc = 0; |
| 133 |
|
| 134 |
if( startedWithBackSlash ) |
| 135 |
{ |
| 136 |
if( glyphname[0] == 'u' ) |
| 137 |
glyphname++; |
| 138 |
|
| 139 |
unichar_t* endptr = 0; |
| 140 |
long unicodepoint = u_strtoul( glyphname+1, &endptr, 16 ); |
| 141 |
TRACE("AAA glyphname:%s\n", u_to_c(glyphname+1) ); |
| 142 |
TRACE("AAA unicodepoint:%ld\n", unicodepoint ); |
| 143 |
sc = SFGetChar( sf, unicodepoint, 0 ); |
| 144 |
if( sc && endptr ) |
| 145 |
{ |
| 146 |
unichar_t* endofglyphname = glyphname + u_strlen(glyphname); |
| 147 |
|
| 148 |
|
| 149 |
for( ; endptr < endofglyphname; endptr++ ) |
| 150 |
--endpos; |
| 151 |
} |
| 152 |
if( !sc ) |
| 153 |
{ |
| 154 |
|
| 155 |
uc_strcpy(glyphname,"backslash"); |
| 156 |
sc = SFGetChar( sf, -1, u_to_c(glyphname) ); |
| 157 |
endpos = startpos; |
| 158 |
} |
| 159 |
} |
| 160 |
else |
| 161 |
{ |
| 162 |
if( uc_startswith( glyphname, "uni")) |
| 163 |
{ |
| 164 |
unichar_t* endptr = 0, *tmp_gn; |
| 165 |
int gn_len; |
| 166 |
long unicodepoint = u_strtoul( glyphname+3, &endptr, 16 ); |
| 167 |
SplineChar* tmp = 0; |
| 168 |
TRACE("uni prefix, codepoint: %ld\n", unicodepoint ); |
| 169 |
sc = SFGetChar( sf, unicodepoint, 0 ); |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
gn_len = u_strlen(glyphname); |
| 177 |
tmp_gn = malloc((gn_len+1)*sizeof(unichar_t)); |
| 178 |
u_strncpy(tmp_gn, glyphname, gn_len); |
| 179 |
for (int i = gn_len; i>0; i--) { |
| 180 |
tmp_gn[i] = 0; |
| 181 |
tmp = SFGetChar( sf, -1, u_to_c(tmp_gn) ); |
| 182 |
TRACE("looking for subst. char: %s\n", u_to_c(tmp_gn)); |
| 183 |
if (tmp != NULL) { |
| 184 |
TRACE("have subst. char: %s\n", tmp->name ); break; |
| 185 |
} |
| 186 |
} |
| 187 |
free(tmp_gn); |
| 188 |
|
| 189 |
if (tmp != NULL){ |
| 190 |
sc = tmp; |
| 191 |
} else { |
| 192 |
if( sc && endptr ) |
| 193 |
{ |
| 194 |
unichar_t* endofglyphname = glyphname + u_strlen(glyphname); |
| 195 |
|
| 196 |
for( ; endptr < endofglyphname; endptr++ ) --endpos; |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
if( firstLookup && glyphname[0] == '#' ) |
| 202 |
{ |
| 203 |
unichar_t* endptr = 0; |
| 204 |
long unicodepoint = u_strtoul( glyphname+1, &endptr, 16 ); |
| 205 |
|
| 206 |
sc = SFGetChar( sf, unicodepoint, 0 ); |
| 207 |
if( sc && endptr ) |
| 208 |
{ |
| 209 |
unichar_t* endofglyphname = glyphname + u_strlen(glyphname); |
| 210 |
|
| 211 |
for( ; endptr < endofglyphname; endptr++ ) |
| 212 |
--endpos; |
| 213 |
} |
| 214 |
} |
| 215 |
if( !sc ) |
| 216 |
{ |
| 217 |
|
| 218 |
sc = SFGetChar( sf, -1, u_to_c(glyphname) ); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
if( sc ) |
| 223 |
{ |
| 224 |
|
| 225 |
if( !loopCounter && FullMatchEndsOnSpace ) |
| 226 |
{ |
| 227 |
endpos++; |
| 228 |
} |
| 229 |
*updated_in = endpos; |
| 230 |
return sc; |
| 231 |
} |
| 232 |
if( glyphname[0] != '\0' ) |
| 233 |
glyphname[ u_strlen(glyphname)-1 ] = '\0'; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
*updated_in = endpos; |
| 238 |
|
| 239 |
|
| 240 |
return 0; |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
int WordlistEscapedInputStringToRealString_getFakeUnicodeAsScUnicodeEnc( SplineChar *sc, void* udata ) |
| 245 |
{ |
| 246 |
return( sc->unicodeenc ); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
void WordlistTrimTrailingSingleSlash( unichar_t* txt ) |
| 254 |
{ |
| 255 |
int len = u_strlen(txt); |
| 256 |
|
| 257 |
if( len >= 1 ) |
| 258 |
{ |
| 259 |
if( len >= 2 && txt[ len-1 ]=='/' && txt[ len-2 ]=='/' ) |
| 260 |
{ |
| 261 |
|
| 262 |
} |
| 263 |
else |
| 264 |
{ |
| 265 |
if( txt[ len-1 ]=='/' ) |
| 266 |
txt[ len-1 ] = '\0'; |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
int WordListLine_countSelected( WordListLine wll ) |
| 278 |
{ |
| 279 |
int ret = 0; |
| 280 |
for( ; wll->sc; wll++ ) { |
| 281 |
ret += wll->isSelected; |
| 282 |
} |
| 283 |
return ret; |
| 284 |
} |
| 285 |
|
| 286 |
WordListLine WordListLine_end( WordListLine wll ) |
| 287 |
{ |
| 288 |
for( ; wll->sc; wll++ ) { |
| 289 |
} |
| 290 |
return wll; |
| 291 |
} |
| 292 |
|
| 293 |
int WordListLine_size( WordListLine wll ) |
| 294 |
{ |
| 295 |
int ret = 0; |
| 296 |
for( ; wll->sc; wll++ ) { |
| 297 |
++ret; |
| 298 |
} |
| 299 |
return ret; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
WordListLine WordlistEscapedInputStringToParsedDataComplex( |
| 304 |
SplineFont* sf, |
| 305 |
const unichar_t* input_const, |
| 306 |
WordlistEscapedInputStringToRealString_getFakeUnicodeOfScFunc getUnicodeFunc, |
| 307 |
void* udata ) |
| 308 |
{ |
| 309 |
unichar_t* input = u_copy( input_const ); |
| 310 |
int input_len = u_strlen(input); |
| 311 |
WordListChar* ret = calloc( input_len+1, sizeof(WordListChar)); |
| 312 |
WordListChar* out = ret; |
| 313 |
unichar_t* in = input; |
| 314 |
unichar_t* in_end = input + input_len; |
| 315 |
|
| 316 |
{ |
| 317 |
unichar_t* p = input; |
| 318 |
while( p && p < in_end ) |
| 319 |
{ |
| 320 |
p = u_strchr( p, '#' ); |
| 321 |
if( p > input && *(p-1) == '/' ) |
| 322 |
{ |
| 323 |
p++; |
| 324 |
continue; |
| 325 |
} |
| 326 |
if( p ) |
| 327 |
*p = '\0'; |
| 328 |
break; |
| 329 |
} |
| 330 |
} |
| 331 |
in_end = input + u_strlen(input); |
| 332 |
|
| 333 |
int addingGlyphsToSelected = 0; |
| 334 |
int currentGlyphIndex = -1; |
| 335 |
for ( ; in < in_end; in++ ) |
| 336 |
{ |
| 337 |
unichar_t ch = *in; |
| 338 |
|
| 339 |
if( ch == '[' ) |
| 340 |
{ |
| 341 |
addingGlyphsToSelected = 1; |
| 342 |
continue; |
| 343 |
} |
| 344 |
if( ch == ']' ) |
| 345 |
{ |
| 346 |
addingGlyphsToSelected = 0; |
| 347 |
continue; |
| 348 |
} |
| 349 |
int isSelected = addingGlyphsToSelected; |
| 350 |
currentGlyphIndex++; |
| 351 |
|
| 352 |
if( ch == '/' || ch == '\\' ) |
| 353 |
{ |
| 354 |
|
| 355 |
unichar_t glyphname[ PATH_MAX+1 ]; |
| 356 |
unichar_t* updated_in = 0; |
| 357 |
SplineChar* sc = u_WordlistEscapedInputStringToRealString_readGlyphName( sf, in, in_end, &updated_in, glyphname ); |
| 358 |
if( sc ) |
| 359 |
{ |
| 360 |
in = updated_in; |
| 361 |
int n = getUnicodeFunc( sc, udata ); |
| 362 |
if( n == -1 ) |
| 363 |
{ |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
n = sf->map->backmap[sc->orig_pos]; |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
if ( (sf->map->enc->is_unicodebmp || sf->map->enc->is_unicodefull) && n < 65536 ) { |
| 378 |
TRACE("ToRealString: backmapped position does not match Unicode encoding\n"); |
| 379 |
TRACE("orig_pos: %d, backmap: %d, attached unicode enc: %d\n", sc->orig_pos, n, sc->unicodeenc ); |
| 380 |
TRACE("ToRealString: INVALID CHAR POSITION, name: %s\n", sc->name ); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
out->sc = sc; |
| 385 |
out->isSelected = isSelected; |
| 386 |
out->currentGlyphIndex = currentGlyphIndex; |
| 387 |
out->n = n; |
| 388 |
out++; |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
continue; |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
SplineChar* sc = SFGetOrMakeChar( sf, (int)ch, 0 ); |
| 398 |
out->sc = sc; |
| 399 |
out->isSelected = isSelected; |
| 400 |
out->currentGlyphIndex = currentGlyphIndex; |
| 401 |
out++; |
| 402 |
} |
| 403 |
|
| 404 |
free(input); |
| 405 |
return(ret); |
| 406 |
} |
| 407 |
|
| 408 |
WordListLine WordlistEscapedInputStringToParsedData( |
| 409 |
SplineFont* sf, |
| 410 |
unichar_t* input_const ) |
| 411 |
{ |
| 412 |
WordListLine ret = WordlistEscapedInputStringToParsedDataComplex( |
| 413 |
sf, input_const, |
| 414 |
WordlistEscapedInputStringToRealString_getFakeUnicodeAsScUnicodeEnc, 0 ); |
| 415 |
return ret; |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
static bool WordlistLoadFileToGTextInfo_IsLineBreak( char ch ) |
| 426 |
{ |
| 427 |
return ch == '\n' || ch == '\r'; |
| 428 |
} |
| 429 |
static bool WordlistLoadFileToGTextInfo_isLineAllWhiteSpace( char* buffer ) |
| 430 |
{ |
| 431 |
char* p = buffer; |
| 432 |
for( ; *p; ++p ) |
| 433 |
{ |
| 434 |
if( !isspace( *p )) |
| 435 |
return false; |
| 436 |
} |
| 437 |
|
| 438 |
return true; |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
GTextInfo** WordlistLoadFileToGTextInfoBasic( int words_max ) |
| 444 |
{ |
| 445 |
return WordlistLoadFileToGTextInfo( -1, words_max ); |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
GTextInfo** WordlistLoadFileToGTextInfo( int type, int words_max ) |
| 450 |
{ |
| 451 |
GTextInfo **words = 0; |
| 452 |
int cnt; |
| 453 |
char buffer[PATH_MAX]; |
| 454 |
char *filename, *temp; |
| 455 |
|
| 456 |
filename = gwwv_open_filename(type==-1 ? "File of Kerning Words":"File of glyphname lists",NULL,"*.txt",NULL); |
| 457 |
if ( !filename ) |
| 458 |
{ |
| 459 |
return 0; |
| 460 |
} |
| 461 |
temp = utf82def_copy(filename); |
| 462 |
GIOChannel* file = g_io_channel_new_file( temp, "r", 0 ); |
| 463 |
free(temp); |
| 464 |
if ( !file ) |
| 465 |
{ |
| 466 |
ff_post_error("Could not open", "Could not open %s", filename ); |
| 467 |
return 0; |
| 468 |
} |
| 469 |
free(filename); |
| 470 |
|
| 471 |
words = malloc( words_max * sizeof(GTextInfo *)); |
| 472 |
|
| 473 |
cnt = 0; |
| 474 |
if ( type==-1 ) |
| 475 |
{ |
| 476 |
|
| 477 |
while( true ) |
| 478 |
{ |
| 479 |
gsize len = 0; |
| 480 |
gchar* buffer = 0; |
| 481 |
GIOStatus status = g_io_channel_read_line( file, &buffer, &len, 0, 0 ); |
| 482 |
|
| 483 |
|
| 484 |
if( status != G_IO_STATUS_NORMAL ) |
| 485 |
break; |
| 486 |
|
| 487 |
chomp(buffer); |
| 488 |
if ( buffer[0]=='\0' |
| 489 |
|| WordlistLoadFileToGTextInfo_IsLineBreak(buffer[0]) |
| 490 |
|| WordlistLoadFileToGTextInfo_isLineAllWhiteSpace( buffer )) |
| 491 |
{ |
| 492 |
free(buffer); |
| 493 |
continue; |
| 494 |
} |
| 495 |
|
| 496 |
words[cnt] = calloc(1,sizeof(GTextInfo)); |
| 497 |
words[cnt]->fg = words[cnt]->bg = COLOR_DEFAULT; |
| 498 |
words[cnt]->text = (unichar_t *) utf82def_copy( buffer ); |
| 499 |
words[cnt++]->text_is_1byte = true; |
| 500 |
free(buffer); |
| 501 |
if( cnt >= words_max ) |
| 502 |
break; |
| 503 |
} |
| 504 |
} |
| 505 |
else |
| 506 |
{ |
| 507 |
|
| 508 |
strcpy(buffer,"");*/ |
| 509 |
gsize bytes_read = 0; |
| 510 |
while( G_IO_STATUS_NORMAL == g_io_channel_read_chars( file, |
| 511 |
buffer+3, |
| 512 |
sizeof(buffer)-3, |
| 513 |
&bytes_read, |
| 514 |
0 )) |
| 515 |
{ |
| 516 |
if ( buffer[3]=='\n' || buffer[3]=='#' ) |
| 517 |
continue; |
| 518 |
if ( cnt>1000-3 ) |
| 519 |
break; |
| 520 |
if ( buffer[strlen(buffer)-1]=='\n' ) |
| 521 |
buffer[strlen(buffer)-1] = '\0'; |
| 522 |
words[cnt] = calloc(1,sizeof(GTextInfo)); |
| 523 |
words[cnt]->fg = words[cnt]->bg = COLOR_DEFAULT; |
| 524 |
words[cnt]->text = (unichar_t *) copy( buffer ); |
| 525 |
words[cnt++]->text_is_1byte = true; |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
g_io_channel_shutdown( file, 1, 0 ); |
| 530 |
g_io_channel_unref( file ); |
| 531 |
if ( cnt!=0 ) |
| 532 |
{ |
| 533 |
words[cnt] = calloc(1,sizeof(GTextInfo)); |
| 534 |
words[cnt]->fg = words[cnt]->bg = COLOR_DEFAULT; |
| 535 |
words[cnt++]->line = true; |
| 536 |
words[cnt] = calloc(1,sizeof(GTextInfo)); |
| 537 |
words[cnt]->fg = words[cnt]->bg = COLOR_DEFAULT; |
| 538 |
words[cnt]->text = (unichar_t *) copy( _("Load Word List...") ); |
| 539 |
words[cnt]->text_is_1byte = true; |
| 540 |
words[cnt++]->userdata = (void *) -1; |
| 541 |
words[cnt] = calloc(1,sizeof(GTextInfo)); |
| 542 |
words[cnt]->fg = words[cnt]->bg = COLOR_DEFAULT; |
| 543 |
words[cnt]->text = (unichar_t *) copy( _("Load Glyph Name List...") ); |
| 544 |
words[cnt]->text_is_1byte = true; |
| 545 |
words[cnt++]->userdata = (void *) -2; |
| 546 |
words[cnt] = calloc(1,sizeof(GTextInfo)); |
| 547 |
} |
| 548 |
else |
| 549 |
{ |
| 550 |
free(words); |
| 551 |
words = 0; |
| 552 |
} |
| 553 |
return words; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
void Wordlist_MoveByOffset( GGadget* g, int* idx, int offset ) |
| 558 |
{ |
| 559 |
int cidx = *idx; |
| 560 |
if ( cidx!=-1 ) |
| 561 |
{ |
| 562 |
int32_t len; |
| 563 |
GGadgetGetList(g,&len); |
| 564 |
|
| 565 |
|
| 566 |
if ( cidx+offset >=0 && cidx+offset<len-3 ) |
| 567 |
{ |
| 568 |
cidx += offset; |
| 569 |
*idx = cidx; |
| 570 |
GGadgetSelectOneListItem( g, cidx ); |
| 571 |
} |
| 572 |
Wordlist_touch( g ); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
void Wordlist_touch( GGadget* g ) |
| 577 |
{ |
| 578 |
|
| 579 |
GEvent e; |
| 580 |
e.type=et_controlevent; |
| 581 |
e.u.control.subtype = et_textchanged; |
| 582 |
e.u.control.u.tf_changed.from_pulldown = GGadgetGetFirstListSelectedItem(g); |
| 583 |
GGadgetDispatchEvent( g, &e ); |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
void WordlistLoadToGTextInfo( GGadget* g, int* idx ) |
| 588 |
{ |
| 589 |
int words_max = 1024*128; |
| 590 |
GTextInfo** words = WordlistLoadFileToGTextInfoBasic( words_max ); |
| 591 |
if( !words ) |
| 592 |
{ |
| 593 |
GGadgetSetTitle8(g,""); |
| 594 |
return; |
| 595 |
} |
| 596 |
|
| 597 |
if( words[0] ) |
| 598 |
{ |
| 599 |
GGadgetSetList(g,words,true); |
| 600 |
GGadgetSetTitle8(g,(char *) (words[0]->text)); |
| 601 |
GTextInfoArrayFree(words); |
| 602 |
*idx = 0; |
| 603 |
GGadgetSelectOneListItem( g, *idx ); |
| 604 |
Wordlist_touch( g ); |
| 605 |
return; |
| 606 |
} |
| 607 |
return; |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
unichar_t* Wordlist_selectionClear( SplineFont* sf, EncMap *map, unichar_t* txtu ) |
| 613 |
{ |
| 614 |
static unichar_t ret[ PATH_MAX ]; |
| 615 |
memset( ret, 0, sizeof(unichar_t) * PATH_MAX ); |
| 616 |
|
| 617 |
unichar_t *dst = ret; |
| 618 |
const unichar_t *src_end = 0; |
| 619 |
const unichar_t *src = 0; |
| 620 |
src_end=txtu+u_strlen(txtu); |
| 621 |
for ( src=txtu; src < src_end; ++src ) |
| 622 |
{ |
| 623 |
if( *src != '[' && *src != ']' ) |
| 624 |
{ |
| 625 |
*dst = *src; |
| 626 |
dst++; |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
return ret; |
| 631 |
} |
| 632 |
|
| 633 |
unichar_t* Wordlist_selectionAdd( SplineFont* sf, EncMap *map, unichar_t* txtu, int offset ) |
| 634 |
{ |
| 635 |
int i = 0; |
| 636 |
static unichar_t ret[ PATH_MAX ]; |
| 637 |
memset( ret, 0, sizeof(unichar_t) * PATH_MAX ); |
| 638 |
|
| 639 |
WordlistTrimTrailingSingleSlash( txtu ); |
| 640 |
WordListLine wll = WordlistEscapedInputStringToParsedData( sf, txtu ); |
| 641 |
|
| 642 |
for( i = 0; wll->sc; wll++, i++ ) |
| 643 |
{ |
| 644 |
SplineChar* sc = wll->sc; |
| 645 |
int element_selected = wll->isSelected; |
| 646 |
|
| 647 |
if( i == offset ) |
| 648 |
element_selected = 1; |
| 649 |
|
| 650 |
if( element_selected ) |
| 651 |
{ |
| 652 |
int pos = map->backmap[ sc->orig_pos ]; |
| 653 |
TRACE("pos1:%d\n", pos ); |
| 654 |
TRACE("map:%d\n", map->map[ pos ] ); |
| 655 |
int gid = pos < 0 || pos >= map->enccount ? -2 : map->map[pos]; |
| 656 |
if( gid == -2 ) |
| 657 |
continue; |
| 658 |
if( gid==-1 || !sf->glyphs[gid] ) |
| 659 |
sc = SFMakeChar( sf, map, pos ); |
| 660 |
else |
| 661 |
sc = sf->glyphs[gid]; |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
if( element_selected ) |
| 666 |
uc_strcat( ret, "[" ); |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
uc_strcat( ret, Wordlist_getSCName( sc )); |
| 671 |
|
| 672 |
if( element_selected ) |
| 673 |
uc_strcat( ret, "]" ); |
| 674 |
} |
| 675 |
|
| 676 |
return ret; |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
unichar_t* Wordlist_advanceSelectedCharsBy( SplineFont* sf, EncMap *map, unichar_t* txtu, int offset ) |
| 681 |
{ |
| 682 |
unichar_t original_data[ PATH_MAX ]; |
| 683 |
static unichar_t ret[ PATH_MAX ]; |
| 684 |
int i = 0; |
| 685 |
|
| 686 |
u_strcpy( original_data, txtu ); |
| 687 |
TRACE("Wordlist_advanceSelectedCharsBy(1) %s\n", u_to_c( txtu )); |
| 688 |
WordlistTrimTrailingSingleSlash( txtu ); |
| 689 |
WordListLine wll = WordlistEscapedInputStringToParsedData( sf, txtu ); |
| 690 |
|
| 691 |
int selectedCount = WordListLine_countSelected( wll ); |
| 692 |
if( !selectedCount ) |
| 693 |
wll->isSelected = 1; |
| 694 |
|
| 695 |
memset( ret, 0, sizeof(unichar_t) * PATH_MAX ); |
| 696 |
for( i = 0; wll->sc; wll++, i++ ) |
| 697 |
{ |
| 698 |
SplineChar* sc = wll->sc; |
| 699 |
int element_selected = wll->isSelected; |
| 700 |
|
| 701 |
if( element_selected ) |
| 702 |
{ |
| 703 |
int pos = map->backmap[ sc->orig_pos ]; |
| 704 |
pos += offset; |
| 705 |
int gid = pos < 0 || pos >= map->enccount ? -2 : map->map[pos]; |
| 706 |
if( gid == -2 ) |
| 707 |
{ |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
pos -= offset; |
| 712 |
gid = pos < 0 || pos >= map->enccount ? -2 : map->map[pos]; |
| 713 |
if( gid == -2 ) |
| 714 |
{ |
| 715 |
|
| 716 |
u_strcpy( ret, original_data ); |
| 717 |
return ret; |
| 718 |
} |
| 719 |
} |
| 720 |
if( gid==-1 || !sf->glyphs[gid] ) |
| 721 |
sc = SFMakeChar( sf, map, pos ); |
| 722 |
else |
| 723 |
sc = sf->glyphs[gid]; |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
if( element_selected ) |
| 728 |
uc_strcat( ret, "[" ); |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
uc_strcat( ret, Wordlist_getSCName( sc )); |
| 733 |
|
| 734 |
if( element_selected ) |
| 735 |
uc_strcat( ret, "]" ); |
| 736 |
} |
| 737 |
|
| 738 |
return ret; |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
static unichar_t* Wordlist_selectionStringOnly( unichar_t* txtu, int* haveSelection ) |
| 747 |
{ |
| 748 |
static unichar_t ret[ PATH_MAX ]; |
| 749 |
memset( ret, 0, sizeof(unichar_t) * PATH_MAX ); |
| 750 |
*haveSelection = 0; |
| 751 |
|
| 752 |
int inSelection = 0; |
| 753 |
unichar_t *dst = ret; |
| 754 |
const unichar_t *src_end = 0; |
| 755 |
const unichar_t *src = 0; |
| 756 |
src_end=txtu+u_strlen(txtu); |
| 757 |
for ( src=txtu; src < src_end; ++src ) |
| 758 |
{ |
| 759 |
if( *src == '[' ) |
| 760 |
{ |
| 761 |
inSelection = 1; |
| 762 |
*haveSelection = 1; |
| 763 |
continue; |
| 764 |
} |
| 765 |
if( *src == ']' ) |
| 766 |
{ |
| 767 |
inSelection = 0; |
| 768 |
continue; |
| 769 |
} |
| 770 |
|
| 771 |
if( inSelection ) |
| 772 |
{ |
| 773 |
*dst = *src; |
| 774 |
dst++; |
| 775 |
} |
| 776 |
} |
| 777 |
|
| 778 |
return ret; |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
bool Wordlist_selectionsEqual( unichar_t* s1, unichar_t* s2 ) |
| 783 |
{ |
| 784 |
static unichar_t s1stripped[ PATH_MAX ]; |
| 785 |
static unichar_t s2stripped[ PATH_MAX ]; |
| 786 |
int s1HasSelection = 0; |
| 787 |
int s2HasSelection = 0; |
| 788 |
|
| 789 |
u_strcpy( s1stripped, Wordlist_selectionStringOnly( s1, &s1HasSelection )); |
| 790 |
u_strcpy( s2stripped, Wordlist_selectionStringOnly( s2, &s2HasSelection )); |
| 791 |
|
| 792 |
if( s1HasSelection && !s2HasSelection ) |
| 793 |
return false; |
| 794 |
if( !s1HasSelection && s2HasSelection ) |
| 795 |
return false; |
| 796 |
|
| 797 |
return !u_strcmp( s1stripped, s2stripped ); |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
unichar_t* WordListLine_toustr( WordListLine wll ) |
| 802 |
{ |
| 803 |
unichar_t* ret = calloc( WordListLine_size(wll)+1, sizeof(unichar_t)); |
| 804 |
unichar_t* p = ret; |
| 805 |
for( ; wll->sc; wll++, p++ ) { |
| 806 |
*p = wll->sc->unicodeenc; |
| 807 |
if (*p == -1) *p = wll->n; |
| 808 |
} |
| 809 |
return ret; |
| 810 |
} |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|