| 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 |
#include <fontforge-config.h> |
| 30 |
|
| 31 |
#include "fontforgeui.h" |
| 32 |
#include "namelist.h" |
| 33 |
#include "scripting.h" |
| 34 |
|
| 35 |
#include "gdraw.h" |
| 36 |
#include "ggadget.h" |
| 37 |
#include "gwidget.h" |
| 38 |
#include "ustring.h" |
| 39 |
|
| 40 |
#include <stdlib.h> |
| 41 |
#include <string.h> |
| 42 |
|
| 43 |
extern NameList *force_names_when_opening; |
| 44 |
int default_font_filter_index=0; |
| 45 |
struct openfilefilters *user_font_filters = NULL; |
| 46 |
|
| 47 |
#ifdef FONTFORGE_CAN_USE_WOFF2 |
| 48 |
|
| 49 |
# define WOFF_EXT ",woff2,woff" |
| 50 |
#else |
| 51 |
# define WOFF_EXT ",woff" |
| 52 |
#endif |
| 53 |
|
| 54 |
struct openfilefilters def_font_filters[] = { |
| 55 |
{ |
| 56 |
N_("All Fonts"), |
| 57 |
|
| 58 |
"*.{" |
| 59 |
"pfa," |
| 60 |
"pfb," |
| 61 |
"pt3," |
| 62 |
"t42," |
| 63 |
"sfd," |
| 64 |
"ufo," |
| 65 |
"ttf," |
| 66 |
"bdf," |
| 67 |
"otf," |
| 68 |
"otb," |
| 69 |
"cff," |
| 70 |
"cef," |
| 71 |
"gai," |
| 72 |
"svg," |
| 73 |
"ufo," |
| 74 |
"pf3," |
| 75 |
"ttc," |
| 76 |
"gsf," |
| 77 |
"cid," |
| 78 |
"bin," |
| 79 |
"hqx," |
| 80 |
"dfont," |
| 81 |
"mf," |
| 82 |
"ik," |
| 83 |
"fon," |
| 84 |
"fnt," |
| 85 |
"pcf," |
| 86 |
"pmf," |
| 87 |
"[0-9]*pk," |
| 88 |
|
| 89 |
"[0-9]*gf," |
| 90 |
"pdb" |
| 91 |
WOFF_EXT |
| 92 |
"}" |
| 93 |
|
| 94 |
"{.gz,.Z,.bz2,.lzma,}" |
| 95 |
}, |
| 96 |
{ |
| 97 |
N_("Outline Fonts"), |
| 98 |
"*.{" |
| 99 |
"pfa," |
| 100 |
"pfb," |
| 101 |
"pt3," |
| 102 |
"t42," |
| 103 |
"sfd," |
| 104 |
"ufo," |
| 105 |
"ttf," |
| 106 |
"otf," |
| 107 |
"cff," |
| 108 |
"cef," |
| 109 |
"gai," |
| 110 |
"svg," |
| 111 |
"ufo," |
| 112 |
"pf3," |
| 113 |
"ttc," |
| 114 |
"gsf," |
| 115 |
"cid," |
| 116 |
"bin," |
| 117 |
"hqx," |
| 118 |
"dfont," |
| 119 |
"mf," |
| 120 |
"ik" |
| 121 |
WOFF_EXT |
| 122 |
"}" |
| 123 |
"{.gz,.Z,.bz2,.lzma,}" |
| 124 |
}, |
| 125 |
{ |
| 126 |
N_("Bitmap Fonts"), |
| 127 |
"*.{" |
| 128 |
"bdf," |
| 129 |
"otb," |
| 130 |
"bin," |
| 131 |
"hqx," |
| 132 |
"fon," |
| 133 |
"fnt," |
| 134 |
"pcf," |
| 135 |
"pmf," |
| 136 |
"*pk," |
| 137 |
"*gf," |
| 138 |
"pdb" |
| 139 |
"}" |
| 140 |
"{.gz,.Z,.bz2,.lzma,}" |
| 141 |
}, |
| 142 |
{ NU_("ΤεΧ Bitmap Fonts"), "*{pk,gf}" }, |
| 143 |
{ N_("PostScript"), "*.{pfa,pfb,t42,otf,cef,cff,gai,pf3,pt3,gsf,cid}{.gz,.Z,.bz,.bz2,.lzma,}" }, |
| 144 |
{ N_("TrueType"), "*.{ttf,t42,ttc}{.gz,.Z,.bz,.bz2,.lzma,}" }, |
| 145 |
{ N_("OpenType"), "*.{ttf,otf" WOFF_EXT "}{.gz,.Z,.bz,.bz2,.lzma,}" }, |
| 146 |
{ N_("Type1"), "*.{pfa,pfb,gsf,cid}{.gz,.Z,.bz2,.lzma,}" }, |
| 147 |
{ N_("Type2"), "*.{otf,cef,cff,gai}{.gz,.Z,.bz2,.lzma,}" }, |
| 148 |
{ N_("Type3"), "*.{pf3,pt3}{.gz,.Z,.bz2,.lzma,}" }, |
| 149 |
{ N_("SVG"), "*.svg{.gz,.Z,.bz2,.lzma,}" }, |
| 150 |
{ N_("Unified Font Object"), "*.ufo" }, |
| 151 |
{ N_("FontForge's SFD"), "*.sfd{.gz,.Z,.bz2,.lzma,}" }, |
| 152 |
{ N_("Backup SFD"), "*.sfd~" }, |
| 153 |
{ N_("Extract from PDF"), "*.pdf{.gz,.Z,.bz2,.lzma,}" }, |
| 154 |
{ "-", NULL }, |
| 155 |
{ N_("Archives"), "*.{zip,tgz,tbz,tbz2,tar.gz,tar.bz,tar.bz2,tar}" }, |
| 156 |
{ N_("All Files"), "*" }, |
| 157 |
{ NULL, NULL } |
| 158 |
}; |
| 159 |
|
| 160 |
static GTextInfo **StandardFilters(void) { |
| 161 |
int k, cnt, i; |
| 162 |
GTextInfo **ti; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
for ( k=0; k<2; ++k ) { |
| 171 |
cnt = 0; |
| 172 |
for ( i=0; def_font_filters[i].name!=NULL; ++i ) { |
| 173 |
if ( k ) { |
| 174 |
ti[cnt] = calloc(1,sizeof(GTextInfo)); |
| 175 |
ti[cnt]->userdata = def_font_filters[i].filter; |
| 176 |
ti[cnt]->fg = ti[cnt]->bg = COLOR_DEFAULT; |
| 177 |
if ( *(char *) def_font_filters[i].name == '-' ) |
| 178 |
ti[cnt]->line = true; |
| 179 |
else |
| 180 |
ti[cnt]->text = utf82u_copy(_(def_font_filters[i].name)); |
| 181 |
} |
| 182 |
++cnt; |
| 183 |
} |
| 184 |
if ( user_font_filters!=NULL ) { |
| 185 |
if ( k ) { |
| 186 |
ti[cnt] = calloc(1,sizeof(GTextInfo)); |
| 187 |
ti[cnt]->fg = ti[cnt]->bg = COLOR_DEFAULT; |
| 188 |
|
| 189 |
ti[cnt]->line = true; |
| 190 |
} |
| 191 |
++cnt; |
| 192 |
for ( i=0; user_font_filters[i].name!=NULL; ++i ) { |
| 193 |
if ( k ) { |
| 194 |
ti[cnt] = calloc(1,sizeof(GTextInfo)); |
| 195 |
ti[cnt]->userdata = user_font_filters[i].filter; |
| 196 |
ti[cnt]->fg = ti[cnt]->bg = COLOR_DEFAULT; |
| 197 |
|
| 198 |
if ( *(char *) user_font_filters[i].name == '-' ) |
| 199 |
ti[cnt]->line = true; |
| 200 |
else |
| 201 |
ti[cnt]->text = utf82u_copy(user_font_filters[i].name); |
| 202 |
} |
| 203 |
++cnt; |
| 204 |
} |
| 205 |
} |
| 206 |
if ( k ) { |
| 207 |
ti[cnt] = calloc(1,sizeof(GTextInfo)); |
| 208 |
ti[cnt]->fg = ti[cnt]->bg = COLOR_DEFAULT; |
| 209 |
ti[cnt++]->line = true; |
| 210 |
ti[cnt] = calloc(1,sizeof(GTextInfo)); |
| 211 |
ti[cnt]->userdata = (void *) -1; |
| 212 |
ti[cnt]->fg = ti[cnt]->bg = COLOR_DEFAULT; |
| 213 |
ti[cnt++]->text = utf82u_copy(_("Edit Filter List")); |
| 214 |
ti[cnt] = calloc(1,sizeof(GTextInfo)); |
| 215 |
} else |
| 216 |
ti = malloc((cnt+3)*sizeof(GTextInfo *)); |
| 217 |
} |
| 218 |
ti[default_font_filter_index]->selected = true; |
| 219 |
return( ti ); |
| 220 |
} |
| 221 |
|
| 222 |
struct filter_d { |
| 223 |
int done; |
| 224 |
GGadget *gme; |
| 225 |
}; |
| 226 |
|
| 227 |
static int Filter_Cancel(GGadget *g, GEvent *e) { |
| 228 |
GWindow gw; |
| 229 |
struct filter_d *d; |
| 230 |
|
| 231 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 232 |
gw = GGadgetGetWindow(g); |
| 233 |
d = GDrawGetUserData(gw); |
| 234 |
d->done = true; |
| 235 |
} |
| 236 |
return( true ); |
| 237 |
} |
| 238 |
|
| 239 |
static int Filter_OK(GGadget *g, GEvent *e) { |
| 240 |
struct filter_d *d; |
| 241 |
struct matrix_data *md; |
| 242 |
int rows,i,cnt; |
| 243 |
|
| 244 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 245 |
if ( user_font_filters!=NULL ) { |
| 246 |
for ( i=0; user_font_filters[i].name!=NULL; ++i ) { |
| 247 |
free(user_font_filters[i].name); |
| 248 |
free(user_font_filters[i].filter); |
| 249 |
} |
| 250 |
free(user_font_filters); |
| 251 |
user_font_filters = NULL; |
| 252 |
} |
| 253 |
d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 254 |
md = GMatrixEditGet(d->gme,&rows); |
| 255 |
for ( i=cnt=0; i<rows; ++i ) |
| 256 |
if ( !md[2*i].frozen ) |
| 257 |
++cnt; |
| 258 |
if ( cnt!=0 ) { |
| 259 |
user_font_filters = malloc((cnt+1)*sizeof(struct openfilefilters)); |
| 260 |
for ( i=cnt=0; i<rows; ++i ) if ( !md[2*i].frozen ) { |
| 261 |
user_font_filters[cnt].name = copy(md[2*i].u.md_str); |
| 262 |
user_font_filters[cnt].filter = copy(md[2*i+1].u.md_str); |
| 263 |
++cnt; |
| 264 |
} |
| 265 |
user_font_filters[cnt].name = user_font_filters[cnt].filter = NULL; |
| 266 |
} |
| 267 |
SavePrefs(true); |
| 268 |
d->done = true; |
| 269 |
} |
| 270 |
return( true ); |
| 271 |
} |
| 272 |
|
| 273 |
static int filter_e_h(GWindow gw, GEvent *event) { |
| 274 |
if ( event->type==et_close ) { |
| 275 |
struct filter_d *d = GDrawGetUserData(gw); |
| 276 |
d->done = true; |
| 277 |
} else if ( event->type == et_char ) { |
| 278 |
return( false ); |
| 279 |
} |
| 280 |
return( true ); |
| 281 |
} |
| 282 |
|
| 283 |
static int filter_candelete(GGadget *g, int r) { |
| 284 |
struct matrix_data *md; |
| 285 |
int rows; |
| 286 |
|
| 287 |
md = GMatrixEditGet(g,&rows); |
| 288 |
if ( r>=rows ) |
| 289 |
return( false ); |
| 290 |
|
| 291 |
return( !md[2*r].frozen ); |
| 292 |
} |
| 293 |
|
| 294 |
static void FilterDlg(void) { |
| 295 |
static struct col_init cols[] = { |
| 296 |
{ me_string, NULL, NULL, NULL, N_("Name") }, |
| 297 |
{ me_string, NULL, NULL, NULL, N_("Filter") } |
| 298 |
}; |
| 299 |
static int inited = false; |
| 300 |
static struct matrixinit mi = { |
| 301 |
2, cols, |
| 302 |
0, NULL, |
| 303 |
NULL, |
| 304 |
filter_candelete, |
| 305 |
NULL, |
| 306 |
NULL, |
| 307 |
NULL, |
| 308 |
NULL |
| 309 |
}; |
| 310 |
struct matrix_data *md; |
| 311 |
int k, cnt, i, ptwidth; |
| 312 |
GGadgetCreateData gcd[3], boxes[3], *varray[7], *harray[7]; |
| 313 |
GTextInfo label[3]; |
| 314 |
GRect pos; |
| 315 |
GWindow gw; |
| 316 |
GWindowAttrs wattrs; |
| 317 |
struct filter_d d; |
| 318 |
|
| 319 |
if ( !inited ) { |
| 320 |
inited = true; |
| 321 |
cols[0].title = _(cols[0].title); |
| 322 |
cols[1].title = _(cols[1].title); |
| 323 |
} |
| 324 |
|
| 325 |
for ( k=0; k<2; ++k ) { |
| 326 |
cnt = 0; |
| 327 |
for ( i=0; def_font_filters[i].name!=NULL; ++i ) { |
| 328 |
if ( *(char *) def_font_filters[i].name != '-' ) { |
| 329 |
if ( k ) { |
| 330 |
md[2*cnt].u.md_str = copy(_(def_font_filters[i].name)); |
| 331 |
md[2*cnt].frozen = true; |
| 332 |
md[2*cnt+1].u.md_str = copy(def_font_filters[i].filter); |
| 333 |
md[2*cnt+1].frozen = true; |
| 334 |
} |
| 335 |
++cnt; |
| 336 |
} |
| 337 |
} |
| 338 |
if ( user_font_filters!=NULL ) { |
| 339 |
for ( i=0; user_font_filters[i].name!=NULL; ++i ) { |
| 340 |
if ( *(char *) user_font_filters[i].name != '-' ) { |
| 341 |
if ( k ) { |
| 342 |
md[2*cnt].u.md_str = copy(user_font_filters[i].name); |
| 343 |
md[2*cnt].frozen = false; |
| 344 |
md[2*cnt+1].u.md_str = copy(user_font_filters[i].filter); |
| 345 |
md[2*cnt+1].frozen = false; |
| 346 |
} |
| 347 |
++cnt; |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
if ( !k ) |
| 352 |
md = calloc(2*cnt,sizeof(struct matrix_data)); |
| 353 |
} |
| 354 |
mi.initial_row_cnt = cnt; |
| 355 |
mi.matrix_data = md; |
| 356 |
|
| 357 |
|
| 358 |
memset(&d,'\0',sizeof(d)); |
| 359 |
|
| 360 |
memset(&wattrs,0,sizeof(wattrs)); |
| 361 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg; |
| 362 |
wattrs.event_masks = ~(1<<et_charup); |
| 363 |
wattrs.restrict_input_to_me = 1; |
| 364 |
wattrs.is_dlg = true; |
| 365 |
wattrs.undercursor = 1; |
| 366 |
wattrs.cursor = ct_pointer; |
| 367 |
wattrs.utf8_window_title = _("Edit Font Filters"); |
| 368 |
pos.x = pos.y = 0; |
| 369 |
ptwidth = 2*GIntGetResource(_NUM_Buttonsize)+GGadgetScale(60); |
| 370 |
pos.width =GDrawPointsToPixels(NULL,ptwidth); |
| 371 |
pos.height = GDrawPointsToPixels(NULL,90); |
| 372 |
gw = GDrawCreateTopWindow(NULL,&pos,filter_e_h,&d,&wattrs); |
| 373 |
|
| 374 |
|
| 375 |
memset(&label,0,sizeof(label)); |
| 376 |
memset(&gcd,0,sizeof(gcd)); |
| 377 |
memset(&boxes,0,sizeof(boxes)); |
| 378 |
|
| 379 |
gcd[0].gd.pos.x = 10; gcd[0].gd.pos.y = 6; |
| 380 |
gcd[0].gd.pos.width = 300; gcd[0].gd.pos.height = 200; |
| 381 |
gcd[0].gd.flags = gg_visible | gg_enabled; |
| 382 |
gcd[0].creator = GMatrixEditCreate; |
| 383 |
gcd[0].gd.u.matrix = &mi; |
| 384 |
varray[0] = &gcd[0]; varray[1] = NULL; |
| 385 |
|
| 386 |
gcd[1].gd.pos.x = 20-3; gcd[1].gd.pos.y = 90-35-3; |
| 387 |
gcd[1].gd.pos.width = -1; gcd[1].gd.pos.height = 0; |
| 388 |
gcd[1].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 389 |
label[1].text = (unichar_t *) _("_OK"); |
| 390 |
label[1].text_is_1byte = true; |
| 391 |
label[1].text_in_resource = true; |
| 392 |
gcd[1].gd.label = &label[1]; |
| 393 |
gcd[1].gd.handle_controlevent = Filter_OK; |
| 394 |
gcd[1].creator = GButtonCreate; |
| 395 |
harray[0] = GCD_Glue; harray[1] = &gcd[1]; harray[2] = GCD_Glue; |
| 396 |
|
| 397 |
gcd[2].gd.pos.x = -20; gcd[2].gd.pos.y = 90-35; |
| 398 |
gcd[2].gd.pos.width = -1; gcd[2].gd.pos.height = 0; |
| 399 |
gcd[2].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 400 |
label[2].text = (unichar_t *) _("_Cancel"); |
| 401 |
label[2].text_is_1byte = true; |
| 402 |
label[2].text_in_resource = true; |
| 403 |
gcd[2].gd.label = &label[2]; |
| 404 |
gcd[2].gd.handle_controlevent = Filter_Cancel; |
| 405 |
gcd[2].creator = GButtonCreate; |
| 406 |
harray[3] = GCD_Glue; harray[4] = &gcd[2]; harray[5] = GCD_Glue; |
| 407 |
harray[6] = NULL; |
| 408 |
varray[2] = &boxes[2]; varray[3] = NULL; |
| 409 |
varray[4] = NULL; |
| 410 |
|
| 411 |
boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2; |
| 412 |
boxes[0].gd.flags = gg_enabled|gg_visible; |
| 413 |
boxes[0].gd.u.boxelements = varray; |
| 414 |
boxes[0].creator = GHVGroupCreate; |
| 415 |
|
| 416 |
boxes[2].gd.flags = gg_enabled|gg_visible; |
| 417 |
boxes[2].gd.u.boxelements = harray; |
| 418 |
boxes[2].creator = GHBoxCreate; |
| 419 |
|
| 420 |
|
| 421 |
GGadgetsCreate(gw,boxes); |
| 422 |
GHVBoxSetExpandableRow(boxes[0].ret,0); |
| 423 |
GHVBoxSetExpandableCol(boxes[2].ret,gb_expandgluesame); |
| 424 |
GHVBoxFitWindow(boxes[0].ret); |
| 425 |
GMatrixEditSetNewText(gcd[0].ret,S_("Filter|New")); |
| 426 |
d.gme = gcd[0].ret; |
| 427 |
|
| 428 |
GDrawSetVisible(gw,true); |
| 429 |
while ( !d.done ) |
| 430 |
GDrawProcessOneEvent(NULL); |
| 431 |
GDrawDestroyWindow(gw); |
| 432 |
|
| 433 |
for ( i=0; i<cnt; ++i ) { |
| 434 |
free(md[2*i].u.md_str); |
| 435 |
free(md[2*i+1].u.md_str); |
| 436 |
} |
| 437 |
free(md); |
| 438 |
} |
| 439 |
|
| 440 |
struct gfc_data { |
| 441 |
int done; |
| 442 |
unichar_t *ret; |
| 443 |
GGadget *gfc; |
| 444 |
GGadget *rename; |
| 445 |
int filename_popup_pos; |
| 446 |
unichar_t *lastpopupfontname; |
| 447 |
}; |
| 448 |
|
| 449 |
static int GFD_Ok(GGadget *g, GEvent *e) { |
| 450 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 451 |
struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 452 |
GGadget *tf; |
| 453 |
GFileChooserGetChildren(d->gfc,NULL,NULL,&tf); |
| 454 |
if ( *_GGadgetGetTitle(tf)!='\0' ) { |
| 455 |
extern int allow_utf8_glyphnames; |
| 456 |
GTextInfo *ti = GGadgetGetListItemSelected(d->rename); |
| 457 |
char *nlname = u2utf8_copy(ti->text); |
| 458 |
force_names_when_opening = NameListByName(nlname); |
| 459 |
free(nlname); |
| 460 |
if ( force_names_when_opening!=NULL && force_names_when_opening->uses_unicode && |
| 461 |
!allow_utf8_glyphnames) { |
| 462 |
ff_post_error(_("Namelist contains non-ASCII names"),_("Glyph names should be limited to characters in the ASCII character set, but there are names in this namelist which use characters outside that range.")); |
| 463 |
return(true); |
| 464 |
} |
| 465 |
d->done = true; |
| 466 |
d->ret = GGadgetGetTitle(d->gfc); |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
int tmplen = u_strlen( d->ret ); |
| 471 |
if( tmplen > 0 ) { |
| 472 |
if( d->ret[ tmplen-1 ] == '/' ) { |
| 473 |
unichar_t* tmp = u_copy( d->ret ); |
| 474 |
tmp[ tmplen-1 ] = '\0'; |
| 475 |
GGadgetSetTitle(d->gfc, tmp); |
| 476 |
free(tmp); |
| 477 |
d->ret = GGadgetGetTitle(d->gfc); |
| 478 |
} |
| 479 |
} |
| 480 |
} |
| 481 |
} |
| 482 |
return( true ); |
| 483 |
} |
| 484 |
|
| 485 |
static int GFD_New(GGadget *g, GEvent *e) { |
| 486 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 487 |
struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 488 |
d->done = true; |
| 489 |
GDrawSetVisible(GGadgetGetWindow(g),false); |
| 490 |
FontNew(); |
| 491 |
} |
| 492 |
return( true ); |
| 493 |
} |
| 494 |
|
| 495 |
static int GFD_Cancel(GGadget *g, GEvent *e) { |
| 496 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 497 |
struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 498 |
d->done = true; |
| 499 |
} |
| 500 |
return( true ); |
| 501 |
} |
| 502 |
|
| 503 |
static int GFD_FilterSelected(GGadget *g, GEvent *e) { |
| 504 |
if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) { |
| 505 |
struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 506 |
GTextInfo *ti = GGadgetGetListItemSelected(g); |
| 507 |
if ( ti->userdata==NULL ) |
| 508 |
; |
| 509 |
else if ( ti->userdata == (void *) -1 ) { |
| 510 |
FilterDlg(); |
| 511 |
GGadgetSetList(g,StandardFilters(),true); |
| 512 |
} else { |
| 513 |
unichar_t *temp = utf82u_copy(ti->userdata); |
| 514 |
GFileChooserSetFilterText(d->gfc,temp); |
| 515 |
free(temp); |
| 516 |
temp = GFileChooserGetDir(d->gfc); |
| 517 |
GFileChooserSetDir(d->gfc,temp); |
| 518 |
free(temp); |
| 519 |
default_font_filter_index = GGadgetGetFirstListSelectedItem(g); |
| 520 |
SavePrefs(true); |
| 521 |
} |
| 522 |
} |
| 523 |
return( true ); |
| 524 |
} |
| 525 |
|
| 526 |
static int WithinList(struct gfc_data *d,GEvent *event) { |
| 527 |
GGadget *list; |
| 528 |
int32_t pos; |
| 529 |
unichar_t *ufile; |
| 530 |
char *file, **fontnames; |
| 531 |
int cnt, len; |
| 532 |
unichar_t *msg; |
| 533 |
|
| 534 |
if ( event->type!=et_mousemove ) |
| 535 |
return( false ); |
| 536 |
|
| 537 |
GFileChooserGetChildren(d->gfc,NULL, &list, NULL); |
| 538 |
if ( list==NULL ) |
| 539 |
return( false ); |
| 540 |
if ( !GGadgetWithin(list,event->u.mouse.x,event->u.mouse.y) ) |
| 541 |
return( false ); |
| 542 |
pos = GListIndexFromY(list,event->u.mouse.y); |
| 543 |
if ( pos == d->filename_popup_pos ) |
| 544 |
return( pos!=-1 ); |
| 545 |
if ( pos==-1 || GFileChooserPosIsDir(d->gfc,pos)) { |
| 546 |
d->filename_popup_pos = -1; |
| 547 |
return( pos!=-1 ); |
| 548 |
} |
| 549 |
ufile = GFileChooserFileNameOfPos(d->gfc,pos); |
| 550 |
if ( ufile==NULL ) |
| 551 |
return( true ); |
| 552 |
file = u2def_copy(ufile); |
| 553 |
free(ufile); |
| 554 |
|
| 555 |
fontnames = GetFontNames(file, 0); |
| 556 |
if ( fontnames==NULL || fontnames[0]==NULL ) |
| 557 |
msg = uc_copy( "???" ); |
| 558 |
else { |
| 559 |
len = 0; |
| 560 |
for ( cnt=0; fontnames[cnt]!=NULL; ++cnt ) |
| 561 |
len += strlen(fontnames[cnt])+1; |
| 562 |
msg = malloc((len+2)*sizeof(unichar_t)); |
| 563 |
len = 0; |
| 564 |
for ( cnt=0; fontnames[cnt]!=NULL; ++cnt ) { |
| 565 |
uc_strcpy(msg+len,fontnames[cnt]); |
| 566 |
len += strlen(fontnames[cnt]); |
| 567 |
msg[len++] = '\n'; |
| 568 |
} |
| 569 |
msg[len-1] = '\0'; |
| 570 |
} |
| 571 |
GGadgetPreparePopup(GGadgetGetWindow(d->gfc),msg); |
| 572 |
if ( fontnames!=NULL ) { |
| 573 |
for ( cnt=0; fontnames[cnt]!=NULL; ++cnt ) { |
| 574 |
free(fontnames[cnt]); |
| 575 |
} |
| 576 |
free(fontnames); |
| 577 |
} |
| 578 |
free(file); |
| 579 |
free(d->lastpopupfontname); |
| 580 |
d->lastpopupfontname = msg; |
| 581 |
return( true ); |
| 582 |
} |
| 583 |
|
| 584 |
static int e_h(GWindow gw, GEvent *event) { |
| 585 |
if ( event->type==et_close ) { |
| 586 |
struct gfc_data *d = GDrawGetUserData(gw); |
| 587 |
d->done = true; |
| 588 |
} else if ( event->type == et_map ) { |
| 589 |
|
| 590 |
GDrawRaise(gw); |
| 591 |
} else if ( event->type == et_char ) { |
| 592 |
return( false ); |
| 593 |
} else if ( event->type == et_mousemove || |
| 594 |
(event->type==et_mousedown && event->u.mouse.button==3 )) { |
| 595 |
struct gfc_data *d = GDrawGetUserData(gw); |
| 596 |
if ( !WithinList(d,event) ) |
| 597 |
GFileChooserPopupCheck(d->gfc,event); |
| 598 |
} else if (( event->type==et_mouseup || event->type==et_mousedown ) && |
| 599 |
(event->u.mouse.button>=4 && event->u.mouse.button<=7) ) { |
| 600 |
struct gfc_data *d = GDrawGetUserData(gw); |
| 601 |
return( GGadgetDispatchEvent((GGadget *) (d->gfc),event)); |
| 602 |
} else if ( event->type == et_resize ) { |
| 603 |
GRect r, size; |
| 604 |
struct gfc_data *d = GDrawGetUserData(gw); |
| 605 |
if ( d->gfc!=NULL ) { |
| 606 |
GDrawGetSize(gw,&size); |
| 607 |
GGadgetGetSize(d->gfc,&r); |
| 608 |
GGadgetResize(d->gfc,size.width-2*r.x,r.height); |
| 609 |
} |
| 610 |
} |
| 611 |
return( event->type!=et_char ); |
| 612 |
} |
| 613 |
|
| 614 |
static unichar_t *FVOpenFont(char *title, const char *defaultfile, bool mult, bool modal) { |
| 615 |
GRect pos; |
| 616 |
int i, filter, renamei; |
| 617 |
GWindow gw; |
| 618 |
GWindowAttrs wattrs; |
| 619 |
GGadgetCreateData gcd[11], boxes[5], *varray[9], *harray1[7], *harray2[4], *harray3[9]; |
| 620 |
GTextInfo label[10]; |
| 621 |
struct gfc_data d; |
| 622 |
int bs = GIntGetResource(_NUM_Buttonsize), bsbigger, totwid, spacing; |
| 623 |
GGadget *tf; |
| 624 |
unichar_t *temp; |
| 625 |
char **nlnames; |
| 626 |
GTextInfo *namelistnames, **filts; |
| 627 |
int cnt; |
| 628 |
|
| 629 |
memset(&d,'\0',sizeof(d)); |
| 630 |
|
| 631 |
memset(&wattrs,0,sizeof(wattrs)); |
| 632 |
if (modal) { |
| 633 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; |
| 634 |
wattrs.restrict_input_to_me = 1; |
| 635 |
wattrs.is_dlg = true; |
| 636 |
wattrs.undercursor = 1; |
| 637 |
} else { |
| 638 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle; |
| 639 |
} |
| 640 |
wattrs.event_masks = ~(1<<et_charup); |
| 641 |
wattrs.cursor = ct_pointer; |
| 642 |
wattrs.utf8_window_title = title; |
| 643 |
|
| 644 |
pos.x = pos.y = 0; |
| 645 |
|
| 646 |
totwid = GGadgetScale(295); |
| 647 |
bsbigger = 4*bs+4*14>totwid; totwid = bsbigger?4*bs+4*12:totwid; |
| 648 |
spacing = (totwid-4*bs-2*12)/3; |
| 649 |
|
| 650 |
pos.width = GDrawPointsToPixels(NULL,totwid); |
| 651 |
pos.height = GDrawPointsToPixels(NULL,247); |
| 652 |
gw = GDrawCreateTopWindow(NULL,&pos,e_h,&d,&wattrs); |
| 653 |
|
| 654 |
memset(&label,0,sizeof(label)); |
| 655 |
memset(&gcd,0,sizeof(gcd)); |
| 656 |
memset(&boxes,0,sizeof(boxes)); |
| 657 |
i=0; |
| 658 |
gcd[i].gd.pos.x = 12; gcd[i].gd.pos.y = 6; gcd[i].gd.pos.width = totwid*100/GIntGetResource(_NUM_ScaleFactor)-24; gcd[i].gd.pos.height = 180; |
| 659 |
gcd[i].gd.flags = gg_visible | gg_enabled; |
| 660 |
if ( RecentFiles[0]!=NULL ) |
| 661 |
gcd[i].gd.flags = gg_visible | gg_enabled | gg_file_pulldown; |
| 662 |
if ( mult ) |
| 663 |
gcd[i].gd.flags |= gg_file_multiple; |
| 664 |
varray[0] = &gcd[i]; varray[1] = NULL; |
| 665 |
gcd[i++].creator = GFileChooserCreate; |
| 666 |
|
| 667 |
label[i].text = (unichar_t *) _("Filter:"); |
| 668 |
label[i].text_is_1byte = true; |
| 669 |
gcd[i].gd.label = &label[i]; |
| 670 |
gcd[i].gd.pos.x = 8; gcd[i].gd.pos.y = 188+6; |
| 671 |
gcd[i].gd.flags = gg_visible | gg_enabled; |
| 672 |
gcd[i].gd.popup_msg = _("Display files of this type" ); |
| 673 |
harray1[0] = GCD_Glue; harray1[1] = &gcd[i]; |
| 674 |
gcd[i++].creator = GLabelCreate; |
| 675 |
|
| 676 |
gcd[i].gd.pos.x = 0; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y-6; |
| 677 |
gcd[i].gd.flags = gg_visible | gg_enabled; |
| 678 |
gcd[i].gd.popup_msg = _("Display files of this type"); |
| 679 |
gcd[i].gd.handle_controlevent = GFD_FilterSelected; |
| 680 |
harray1[2] = &gcd[i]; harray1[3] = GCD_Glue; harray1[4] = GCD_Glue; harray1[5] = GCD_Glue; harray1[6] = NULL; |
| 681 |
gcd[i++].creator = GListButtonCreate; |
| 682 |
|
| 683 |
boxes[2].gd.flags = gg_visible | gg_enabled; |
| 684 |
boxes[2].gd.u.boxelements = harray1; |
| 685 |
boxes[2].creator = GHBoxCreate; |
| 686 |
varray[2] = &boxes[2]; varray[3] = NULL; |
| 687 |
|
| 688 |
label[i].text = (unichar_t *) _("Force glyph names to:"); |
| 689 |
label[i].text_is_1byte = true; |
| 690 |
gcd[i].gd.label = &label[i]; |
| 691 |
gcd[i].gd.pos.x = 8; gcd[i].gd.pos.y = 188+6; |
| 692 |
gcd[i].gd.flags = gg_visible | gg_enabled; |
| 693 |
gcd[i].gd.popup_msg = _("In the saved font, force all glyph names to match those in the specified namelist"); |
| 694 |
harray2[0] = &gcd[i]; |
| 695 |
gcd[i++].creator = GLabelCreate; |
| 696 |
|
| 697 |
renamei = i; |
| 698 |
gcd[i].gd.pos.x = 0; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y-6; |
| 699 |
gcd[i].gd.flags = gg_visible | gg_enabled; |
| 700 |
gcd[i].gd.popup_msg = _("In the saved font, force all glyph names to match those in the specified namelist"); |
| 701 |
gcd[i].creator = GListButtonCreate; |
| 702 |
nlnames = AllNamelistNames(); |
| 703 |
for ( cnt=0; nlnames[cnt]!=NULL; ++cnt); |
| 704 |
namelistnames = calloc(cnt+3,sizeof(GTextInfo)); |
| 705 |
namelistnames[0].text = (unichar_t *) _("No Rename"); |
| 706 |
namelistnames[0].text_is_1byte = true; |
| 707 |
if ( force_names_when_opening==NULL ) { |
| 708 |
namelistnames[0].selected = true; |
| 709 |
gcd[i].gd.label = &namelistnames[0]; |
| 710 |
} |
| 711 |
namelistnames[1].line = true; |
| 712 |
for ( cnt=0; nlnames[cnt]!=NULL; ++cnt) { |
| 713 |
namelistnames[cnt+2].text = (unichar_t *) nlnames[cnt]; |
| 714 |
namelistnames[cnt+2].text_is_1byte = true; |
| 715 |
if ( force_names_when_opening!=NULL && |
| 716 |
strcmp(_(force_names_when_opening->title),nlnames[cnt])==0 ) { |
| 717 |
namelistnames[cnt+2].selected = true; |
| 718 |
gcd[i].gd.label = &namelistnames[cnt+2]; |
| 719 |
} |
| 720 |
} |
| 721 |
harray2[1] = &gcd[i]; harray2[2] = GCD_Glue; harray2[3] = NULL; |
| 722 |
gcd[i++].gd.u.list = namelistnames; |
| 723 |
|
| 724 |
boxes[3].gd.flags = gg_visible | gg_enabled; |
| 725 |
boxes[3].gd.u.boxelements = harray2; |
| 726 |
boxes[3].creator = GHBoxCreate; |
| 727 |
varray[4] = &boxes[3]; varray[5] = NULL; |
| 728 |
|
| 729 |
gcd[i].gd.pos.x = 12; gcd[i].gd.pos.y = 216-3; |
| 730 |
gcd[i].gd.pos.width = -1; |
| 731 |
gcd[i].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 732 |
label[i].text = (unichar_t *) _("_OK"); |
| 733 |
label[i].text_is_1byte = true; |
| 734 |
label[i].text_in_resource = true; |
| 735 |
gcd[i].gd.mnemonic = 'O'; |
| 736 |
gcd[i].gd.label = &label[i]; |
| 737 |
gcd[i].gd.handle_controlevent = GFD_Ok; |
| 738 |
harray3[0] = GCD_Glue; harray3[1] = &gcd[i]; |
| 739 |
gcd[i++].creator = GButtonCreate; |
| 740 |
|
| 741 |
gcd[i].gd.pos.x = -(spacing+bs)*100/GIntGetResource(_NUM_ScaleFactor)-12; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y+3; |
| 742 |
gcd[i].gd.pos.width = -1; |
| 743 |
gcd[i].gd.flags = gg_visible | gg_enabled; |
| 744 |
label[i].text = (unichar_t *) S_("Font|_New"); |
| 745 |
label[i].text_is_1byte = true; |
| 746 |
label[i].text_in_resource = true; |
| 747 |
gcd[i].gd.mnemonic = 'N'; |
| 748 |
gcd[i].gd.label = &label[i]; |
| 749 |
gcd[i].gd.handle_controlevent = GFD_New; |
| 750 |
harray3[2] = GCD_Glue; harray3[3] = &gcd[i]; |
| 751 |
gcd[i++].creator = GButtonCreate; |
| 752 |
|
| 753 |
filter = i; |
| 754 |
gcd[i].gd.pos.x = (spacing+bs)*100/GIntGetResource(_NUM_ScaleFactor)+12; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y; |
| 755 |
gcd[i].gd.pos.width = -1; |
| 756 |
gcd[i].gd.flags = gg_enabled; |
| 757 |
label[i].text = (unichar_t *) _("_Filter"); |
| 758 |
label[i].text_is_1byte = true; |
| 759 |
label[i].text_in_resource = true; |
| 760 |
gcd[i].gd.mnemonic = 'F'; |
| 761 |
gcd[i].gd.label = &label[i]; |
| 762 |
gcd[i].gd.handle_controlevent = GFileChooserFilterEh; |
| 763 |
harray3[4] = &gcd[i]; |
| 764 |
gcd[i++].creator = GButtonCreate; |
| 765 |
|
| 766 |
gcd[i].gd.pos.x = -12; gcd[i].gd.pos.y = gcd[i-1].gd.pos.y; |
| 767 |
gcd[i].gd.pos.width = -1; |
| 768 |
gcd[i].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 769 |
label[i].text = (unichar_t *) _("_Cancel"); |
| 770 |
label[i].text_is_1byte = true; |
| 771 |
label[i].text_in_resource = true; |
| 772 |
gcd[i].gd.label = &label[i]; |
| 773 |
gcd[i].gd.mnemonic = 'C'; |
| 774 |
gcd[i].gd.handle_controlevent = GFD_Cancel; |
| 775 |
harray3[5] = GCD_Glue; harray3[6] = &gcd[i]; harray3[7] = GCD_Glue; harray3[8] = NULL; |
| 776 |
gcd[i++].creator = GButtonCreate; |
| 777 |
|
| 778 |
boxes[4].gd.flags = gg_visible | gg_enabled; |
| 779 |
boxes[4].gd.u.boxelements = harray3; |
| 780 |
boxes[4].creator = GHBoxCreate; |
| 781 |
varray[6] = &boxes[4]; varray[7] = NULL; |
| 782 |
varray[8] = NULL; |
| 783 |
|
| 784 |
boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2; |
| 785 |
boxes[0].gd.flags = gg_visible | gg_enabled; |
| 786 |
boxes[0].gd.u.boxelements = varray; |
| 787 |
boxes[0].creator = GHVGroupCreate; |
| 788 |
|
| 789 |
gcd[i].gd.pos.x = 2; gcd[i].gd.pos.y = 2; |
| 790 |
gcd[i].gd.pos.width = pos.width-4; gcd[i].gd.pos.height = pos.height-4; |
| 791 |
gcd[i].gd.flags = gg_enabled | gg_visible | gg_pos_in_pixels; |
| 792 |
gcd[i++].creator = GGroupCreate; |
| 793 |
|
| 794 |
GGadgetsCreate(gw,boxes); |
| 795 |
|
| 796 |
d.gfc = gcd[0].ret; |
| 797 |
d.rename = gcd[renamei].ret; |
| 798 |
|
| 799 |
filts = StandardFilters(); |
| 800 |
GGadgetSetList(harray1[2]->ret,filts,true); |
| 801 |
GHVBoxSetExpandableRow(boxes[0].ret,0); |
| 802 |
GHVBoxSetExpandableCol(boxes[2].ret,gb_expandglue); |
| 803 |
GHVBoxSetExpandableCol(boxes[3].ret,gb_expandglue); |
| 804 |
GHVBoxSetExpandableCol(boxes[4].ret,gb_expandgluesame); |
| 805 |
GHVBoxFitWindow(boxes[0].ret); |
| 806 |
free(namelistnames); |
| 807 |
GGadgetSetUserData(gcd[filter].ret,gcd[0].ret); |
| 808 |
|
| 809 |
GFileChooserConnectButtons(gcd[0].ret,harray3[1]->ret,gcd[filter].ret); |
| 810 |
temp = utf82u_copy(filts[default_font_filter_index]->userdata); |
| 811 |
GFileChooserSetFilterText(gcd[0].ret,temp); |
| 812 |
free(temp); |
| 813 |
GFileChooserGetChildren(gcd[0].ret,NULL, NULL, &tf); |
| 814 |
if ( RecentFiles[0]!=NULL ) { |
| 815 |
GGadgetSetList(tf,GTextInfoFromChars(RecentFiles,RECENT_MAX),false); |
| 816 |
} |
| 817 |
GGadgetSetTitle8(gcd[0].ret,defaultfile); |
| 818 |
|
| 819 |
GDrawSetVisible(gw,true); |
| 820 |
while ( !d.done ) |
| 821 |
GDrawProcessOneEvent(NULL); |
| 822 |
GDrawDestroyWindow(gw); |
| 823 |
GDrawProcessPendingEvents(NULL); |
| 824 |
GDrawSync(NULL); |
| 825 |
GDrawProcessPendingEvents(NULL); |
| 826 |
free( d.lastpopupfontname ); |
| 827 |
GTextInfoArrayFree(filts); |
| 828 |
for ( cnt=0; nlnames[cnt]!=NULL; ++cnt) { |
| 829 |
free(nlnames[cnt]); |
| 830 |
} |
| 831 |
free(nlnames); |
| 832 |
return(d.ret); |
| 833 |
} |
| 834 |
|
| 835 |
char *GetPostScriptFontName(char *dir, bool mult, bool modal) { |
| 836 |
unichar_t *ret; |
| 837 |
char *u_dir; |
| 838 |
char *temp; |
| 839 |
|
| 840 |
u_dir = def2utf8_copy(dir); |
| 841 |
ret = FVOpenFont(_("Open Font"), u_dir, mult, modal); |
| 842 |
temp = u2def_copy(ret); |
| 843 |
|
| 844 |
free(ret); |
| 845 |
return( temp ); |
| 846 |
} |
| 847 |
|