| 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 |
#include <fontforge-config.h> |
| 29 |
|
| 30 |
#include "fontforgeui.h" |
| 31 |
#include "gkeysym.h" |
| 32 |
#include "lookups.h" |
| 33 |
#include "splineutil.h" |
| 34 |
#include "ustring.h" |
| 35 |
#include "utype.h" |
| 36 |
|
| 37 |
#include <math.h> |
| 38 |
|
| 39 |
extern GTextInfo scripts[], languages[]; |
| 40 |
|
| 41 |
static char *JSTF_GlyphDlg(GGadget *, int r, int c); |
| 42 |
static char *JSTF_LookupListDlg(GGadget *, int r, int c); |
| 43 |
static char *JSTF_Langs(GGadget *, int r, int c); |
| 44 |
|
| 45 |
static struct col_init glyph_ci[] = { |
| 46 |
{ me_string , NULL, NULL, NULL, N_("Glyph Names") }, |
| 47 |
COL_INIT_EMPTY |
| 48 |
}; |
| 49 |
|
| 50 |
static struct col_init lookup_ci[] = { |
| 51 |
{ me_enum , NULL, NULL, NULL, N_("Lookups") }, |
| 52 |
COL_INIT_EMPTY |
| 53 |
}; |
| 54 |
|
| 55 |
static struct col_init jstf_lang_ci[] = { |
| 56 |
{ me_stringchoicetag , NULL, languages, NULL, N_("Language") }, |
| 57 |
{ me_funcedit, JSTF_LookupListDlg, NULL, NULL, N_("Extend Lookups On") }, |
| 58 |
{ me_funcedit, JSTF_LookupListDlg, NULL, NULL, N_("Extend Lookups Off") }, |
| 59 |
{ me_funcedit, JSTF_LookupListDlg, NULL, NULL, N_("Extend Max Lookups") }, |
| 60 |
{ me_funcedit, JSTF_LookupListDlg, NULL, NULL, N_("Shrink Lookups On") }, |
| 61 |
{ me_funcedit, JSTF_LookupListDlg, NULL, NULL, N_("Shrink Lookups Off") }, |
| 62 |
{ me_funcedit, JSTF_LookupListDlg, NULL, NULL, N_("Shrink Max Lookups") }, |
| 63 |
COL_INIT_EMPTY |
| 64 |
}; |
| 65 |
|
| 66 |
static struct col_init justify_ci[] = { |
| 67 |
{ me_stringchoicetag , NULL, scripts, NULL, N_("writing system|Script") }, |
| 68 |
{ me_funcedit, JSTF_GlyphDlg, NULL, NULL, N_("Extenders") }, |
| 69 |
{ me_button, JSTF_Langs, NULL, NULL, N_("Language info") }, |
| 70 |
{ me_addr, NULL, NULL, NULL, N_("Hidden") }, |
| 71 |
COL_INIT_EMPTY |
| 72 |
}; |
| 73 |
|
| 74 |
struct glyph_list_dlg { |
| 75 |
int done; |
| 76 |
char *ret; |
| 77 |
GWindow gw; |
| 78 |
SplineFont *sf; |
| 79 |
}; |
| 80 |
|
| 81 |
typedef struct jstf_dlg { |
| 82 |
int done, ldone; |
| 83 |
GWindow gw, lgw; |
| 84 |
SplineFont *sf; |
| 85 |
struct jstf_lang **here; |
| 86 |
} Jstf_Dlg; |
| 87 |
|
| 88 |
#define CID_OK 1001 |
| 89 |
#define CID_Cancel 1002 |
| 90 |
|
| 91 |
#define CID_Glyphs 2001 |
| 92 |
#define CID_Lookups 2002 |
| 93 |
#define CID_Languages 2003 |
| 94 |
#define CID_Scripts 2004 |
| 95 |
|
| 96 |
static void JustUIInit(void) { |
| 97 |
static int done = false; |
| 98 |
int i, j; |
| 99 |
static struct col_init *needswork[] = { |
| 100 |
justify_ci, jstf_lang_ci, lookup_ci, glyph_ci, |
| 101 |
NULL |
| 102 |
}; |
| 103 |
|
| 104 |
if ( done ) |
| 105 |
return; |
| 106 |
done = true; |
| 107 |
for ( j=0; needswork[j]!=NULL; ++j ) { |
| 108 |
for ( i=0; needswork[j][i].title!=NULL; ++i ) |
| 109 |
if ( needswork[j][i].title!=NULL ) |
| 110 |
needswork[j][i].title = S_(needswork[j][i].title); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
static unichar_t **JSTF_Glyph_Completion(GGadget *t,int from_tab) { |
| 119 |
struct glyph_list_dlg *gld = GDrawGetUserData(GDrawGetParentWindow(GGadgetGetWindow(t))); |
| 120 |
SplineFont *sf = gld->sf; |
| 121 |
|
| 122 |
return( SFGlyphNameCompletion(sf,t,from_tab,false)); |
| 123 |
} |
| 124 |
|
| 125 |
static void GlyphMatrixInit(struct matrixinit *mi,char *glyphstr,SplineFont *sf) { |
| 126 |
struct matrix_data *md; |
| 127 |
int k, cnt; |
| 128 |
char *start, *end; |
| 129 |
|
| 130 |
memset(mi,0,sizeof(*mi)); |
| 131 |
mi->col_cnt = 1; |
| 132 |
mi->col_init = glyph_ci; |
| 133 |
|
| 134 |
md = NULL; |
| 135 |
for ( k=0; k<2; ++k ) { |
| 136 |
cnt = 0; |
| 137 |
if ( glyphstr!=NULL ) for ( start = glyphstr; *start; ) { |
| 138 |
for ( end=start; *end!='\0' && *end!=' ' && *end!=','; ++end ); |
| 139 |
if ( k ) { |
| 140 |
char *str = copyn(start,end-start); |
| 141 |
md[1*cnt+0].u.md_str = SFNameList2NameUni(sf,str); |
| 142 |
free(str); |
| 143 |
} |
| 144 |
++cnt; |
| 145 |
while ( *end==' ' || *end==',' ) ++end; |
| 146 |
start = end; |
| 147 |
} |
| 148 |
if ( md==NULL ) |
| 149 |
md = calloc(1*(cnt+10),sizeof(struct matrix_data)); |
| 150 |
} |
| 151 |
mi->matrix_data = md; |
| 152 |
mi->initial_row_cnt = cnt; |
| 153 |
} |
| 154 |
|
| 155 |
static int JSTF_Glyph_OK(GGadget *g, GEvent *e) { |
| 156 |
|
| 157 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 158 |
struct glyph_list_dlg *gld = GDrawGetUserData(GGadgetGetWindow(g)); |
| 159 |
int rows, i, len; |
| 160 |
struct matrix_data *strings = GMatrixEditGet(GWidgetGetControl(gld->gw,CID_Glyphs), &rows); |
| 161 |
char *ret; |
| 162 |
|
| 163 |
if ( rows==0 ) |
| 164 |
gld->ret = NULL; |
| 165 |
else { |
| 166 |
len = 0; |
| 167 |
for ( i=0; i<rows; ++i ) |
| 168 |
len += strlen(strings[1*i+0].u.md_str) +1; |
| 169 |
ret = malloc(len+1); |
| 170 |
for ( i=0; i<rows; ++i ) { |
| 171 |
strcpy(ret,strings[1*i+0].u.md_str); |
| 172 |
strcat(ret," "); |
| 173 |
ret += strlen(ret); |
| 174 |
} |
| 175 |
if ( ret>gld->ret && ret[-1] == ' ' ) |
| 176 |
ret[-1] = '\0'; |
| 177 |
gld->ret = GlyphNameListDeUnicode(ret); |
| 178 |
free(ret); |
| 179 |
} |
| 180 |
gld->done = true; |
| 181 |
} |
| 182 |
return( true ); |
| 183 |
} |
| 184 |
|
| 185 |
static int JSTF_Glyph_Cancel(GGadget *g, GEvent *e) { |
| 186 |
|
| 187 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 188 |
struct glyph_list_dlg *gld = GDrawGetUserData(GGadgetGetWindow(g)); |
| 189 |
gld->done = true; |
| 190 |
gld->ret = NULL; |
| 191 |
} |
| 192 |
return( true ); |
| 193 |
} |
| 194 |
|
| 195 |
static int glyph_e_h(GWindow gw, GEvent *event) { |
| 196 |
|
| 197 |
if ( event->type==et_close ) { |
| 198 |
struct glyph_list_dlg *gld = GDrawGetUserData(gw); |
| 199 |
gld->done = true; |
| 200 |
gld->ret = NULL; |
| 201 |
} else if ( event->type == et_char ) { |
| 202 |
if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) { |
| 203 |
help("ui/dialogs/justify.html", "#justify-glyphs-dlg"); |
| 204 |
return( true ); |
| 205 |
} |
| 206 |
return( false ); |
| 207 |
} |
| 208 |
|
| 209 |
return( true ); |
| 210 |
} |
| 211 |
|
| 212 |
char *GlyphListDlg(SplineFont *sf, char *glyphstr) { |
| 213 |
int i, k, j; |
| 214 |
GRect pos; |
| 215 |
GWindow gw; |
| 216 |
GWindowAttrs wattrs; |
| 217 |
GGadgetCreateData gcd[4], boxes[3]; |
| 218 |
GGadgetCreateData *varray[6], *harray3[8]; |
| 219 |
GTextInfo label[4]; |
| 220 |
struct matrixinit mi; |
| 221 |
struct glyph_list_dlg gld; |
| 222 |
|
| 223 |
memset(&gld,0,sizeof(gld)); |
| 224 |
gld.sf = sf; |
| 225 |
|
| 226 |
memset(&wattrs,0,sizeof(wattrs)); |
| 227 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; |
| 228 |
wattrs.event_masks = ~(1<<et_charup); |
| 229 |
wattrs.is_dlg = true; |
| 230 |
wattrs.restrict_input_to_me = 1; |
| 231 |
wattrs.undercursor = 1; |
| 232 |
wattrs.cursor = ct_pointer; |
| 233 |
wattrs.utf8_window_title = _("Extender Glyphs (kashidas, etc.)"); |
| 234 |
pos.x = pos.y = 0; |
| 235 |
pos.width =GDrawPointsToPixels(NULL,GGadgetScale(268)); |
| 236 |
pos.height = GDrawPointsToPixels(NULL,375); |
| 237 |
gld.gw = gw = GDrawCreateTopWindow(NULL,&pos,glyph_e_h,&gld,&wattrs); |
| 238 |
|
| 239 |
GlyphMatrixInit(&mi,glyphstr,sf); |
| 240 |
|
| 241 |
memset(&gcd,0,sizeof(gcd)); |
| 242 |
memset(&boxes,0,sizeof(boxes)); |
| 243 |
memset(&label,0,sizeof(label)); |
| 244 |
k=j=0; |
| 245 |
gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[1].gd.pos.y+14; |
| 246 |
gcd[k].gd.flags = gg_enabled | gg_visible; |
| 247 |
gcd[k].gd.cid = CID_Glyphs; |
| 248 |
gcd[k].gd.u.matrix = &mi; |
| 249 |
gcd[k].gd.popup_msg = _( "A list of glyph names"); |
| 250 |
gcd[k].creator = GMatrixEditCreate; |
| 251 |
varray[j++] = &gcd[k++]; varray[j++] = NULL; |
| 252 |
|
| 253 |
gcd[k].gd.pos.x = 30-3; |
| 254 |
gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0; |
| 255 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 256 |
label[k].text = (unichar_t *) _("_OK"); |
| 257 |
label[k].text_is_1byte = true; |
| 258 |
label[k].text_in_resource = true; |
| 259 |
gcd[k].gd.label = &label[k]; |
| 260 |
gcd[k].gd.handle_controlevent = JSTF_Glyph_OK; |
| 261 |
gcd[k].gd.cid = CID_OK; |
| 262 |
gcd[k++].creator = GButtonCreate; |
| 263 |
|
| 264 |
gcd[k].gd.pos.x = -30; |
| 265 |
gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0; |
| 266 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 267 |
label[k].text = (unichar_t *) _("_Cancel"); |
| 268 |
label[k].text_is_1byte = true; |
| 269 |
label[k].text_in_resource = true; |
| 270 |
gcd[k].gd.label = &label[k]; |
| 271 |
gcd[k].gd.handle_controlevent = JSTF_Glyph_Cancel; |
| 272 |
gcd[k].gd.cid = CID_Cancel; |
| 273 |
gcd[k++].creator = GButtonCreate; |
| 274 |
|
| 275 |
harray3[0] = harray3[2] = harray3[3] = harray3[4] = harray3[6] = GCD_Glue; |
| 276 |
harray3[7] = NULL; |
| 277 |
harray3[1] = &gcd[k-2]; harray3[5] = &gcd[k-1]; |
| 278 |
|
| 279 |
boxes[0].gd.flags = gg_enabled|gg_visible; |
| 280 |
boxes[0].gd.u.boxelements = harray3; |
| 281 |
boxes[0].creator = GHBoxCreate; |
| 282 |
varray[j++] = &boxes[0]; varray[j++] = NULL; varray[j] = NULL; |
| 283 |
|
| 284 |
boxes[1].gd.pos.x = boxes[1].gd.pos.y = 2; |
| 285 |
boxes[1].gd.flags = gg_enabled|gg_visible; |
| 286 |
boxes[1].gd.u.boxelements = varray; |
| 287 |
boxes[1].creator = GHVGroupCreate; |
| 288 |
|
| 289 |
GGadgetsCreate(gw,boxes+1); |
| 290 |
|
| 291 |
for ( i=0; i<mi.initial_row_cnt; ++i ) { |
| 292 |
free( mi.matrix_data[2*i+0].u.md_str ); |
| 293 |
} |
| 294 |
free( mi.matrix_data ); |
| 295 |
|
| 296 |
GMatrixEditSetNewText(gcd[0].ret,S_("GlyphName|New")); |
| 297 |
GMatrixEditSetColumnCompletion(gcd[0].ret, 0, JSTF_Glyph_Completion ); |
| 298 |
GHVBoxSetExpandableCol(boxes[0].ret,gb_expandgluesame); |
| 299 |
|
| 300 |
GHVBoxFitWindow(boxes[1].ret); |
| 301 |
|
| 302 |
GDrawSetVisible(gw,true); |
| 303 |
while ( !gld.done ) |
| 304 |
GDrawProcessOneEvent(NULL); |
| 305 |
GDrawDestroyWindow(gw); |
| 306 |
return( gld.ret ); |
| 307 |
} |
| 308 |
|
| 309 |
static char *JSTF_GlyphDlg(GGadget *g, int r, int c) { |
| 310 |
int rows; |
| 311 |
struct matrix_data *strings = GMatrixEditGet(g, &rows); |
| 312 |
int cols = GMatrixEditGetColCnt(g); |
| 313 |
char *glyphstr = strings[cols*r+c].u.md_str; |
| 314 |
Jstf_Dlg *jd = GDrawGetUserData(GGadgetGetWindow(g)); |
| 315 |
|
| 316 |
return( GlyphListDlg(jd->sf,glyphstr)); |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
static void LookupMatrixInit(struct matrixinit *mi,char *lookupstr, |
| 324 |
SplineFont *sf, int col) { |
| 325 |
struct matrix_data *md; |
| 326 |
int j, k, cnt; |
| 327 |
char *temp; |
| 328 |
char *start, *end; |
| 329 |
|
| 330 |
memset(mi,0,sizeof(*mi)); |
| 331 |
mi->col_cnt = 1; |
| 332 |
mi->col_init = lookup_ci; |
| 333 |
|
| 334 |
lookup_ci[0].enum_vals = SFLookupArrayFromMask(sf,col==3 || col==6 ? (gpos_single_mask|gpos_pair_mask) : 0 ); |
| 335 |
|
| 336 |
md = NULL; |
| 337 |
for ( k=0; k<2; ++k ) { |
| 338 |
cnt = 0; |
| 339 |
if ( lookupstr!=NULL ) for ( start = lookupstr; *start; ) { |
| 340 |
for ( end=start; *end!='\0' && *end!=','; ++end ); |
| 341 |
if ( k ) { |
| 342 |
for ( j=0; (temp=(char *) (lookup_ci[0].enum_vals[j].text))!=NULL; ++j ) |
| 343 |
if ( strlen(temp)==end-start && strncmp(temp,start,end-start)==0 ) { |
| 344 |
md[1*cnt++ + 0].u.md_ival = (intptr_t) lookup_ci[0].enum_vals[j].userdata; |
| 345 |
break; |
| 346 |
} |
| 347 |
} else |
| 348 |
++cnt; |
| 349 |
while ( *end==' ' || *end==',') ++end; |
| 350 |
start = end; |
| 351 |
} |
| 352 |
if ( md==NULL ) |
| 353 |
md = calloc(1*(cnt+10),sizeof(struct matrix_data)); |
| 354 |
} |
| 355 |
mi->matrix_data = md; |
| 356 |
mi->initial_row_cnt = cnt; |
| 357 |
} |
| 358 |
|
| 359 |
static int JSTF_Lookup_OK(GGadget *g, GEvent *e) { |
| 360 |
|
| 361 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 362 |
struct glyph_list_dlg *gld = GDrawGetUserData(GGadgetGetWindow(g)); |
| 363 |
int rows, i, len; |
| 364 |
struct matrix_data *strings = GMatrixEditGet(GWidgetGetControl(gld->gw,CID_Lookups), &rows); |
| 365 |
char *ret; |
| 366 |
|
| 367 |
if ( rows==0 ) |
| 368 |
gld->ret = NULL; |
| 369 |
else { |
| 370 |
len = 0; |
| 371 |
for ( i=0; i<rows; ++i ) { |
| 372 |
OTLookup *otl = (OTLookup *) strings[1*i+0].u.md_ival; |
| 373 |
len += strlen(otl->lookup_name) +2; |
| 374 |
} |
| 375 |
gld->ret = ret = malloc(len+1); |
| 376 |
for ( i=0; i<rows; ++i ) { |
| 377 |
OTLookup *otl = (OTLookup *) strings[1*i+0].u.md_ival; |
| 378 |
strcpy(ret,otl->lookup_name); |
| 379 |
strcat(ret,", "); |
| 380 |
ret += strlen(ret); |
| 381 |
} |
| 382 |
if ( ret>gld->ret && ret[-1] == ' ' ) |
| 383 |
*--ret = '\0'; |
| 384 |
if ( ret>gld->ret && ret[-1] == ',' ) |
| 385 |
*--ret = '\0'; |
| 386 |
} |
| 387 |
gld->done = true; |
| 388 |
} |
| 389 |
return( true ); |
| 390 |
} |
| 391 |
|
| 392 |
static int lookup_e_h(GWindow gw, GEvent *event) { |
| 393 |
|
| 394 |
if ( event->type==et_close ) { |
| 395 |
struct glyph_list_dlg *gld = GDrawGetUserData(gw); |
| 396 |
gld->done = true; |
| 397 |
gld->ret = NULL; |
| 398 |
} else if ( event->type == et_char ) { |
| 399 |
if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) { |
| 400 |
help("ui/dialogs/justify.html", "#justify-lookup-dlg"); |
| 401 |
return( true ); |
| 402 |
} |
| 403 |
return( false ); |
| 404 |
} |
| 405 |
|
| 406 |
return( true ); |
| 407 |
} |
| 408 |
|
| 409 |
static char *JSTF_LookupListDlg(GGadget *g, int r, int c) { |
| 410 |
int rows, k, j; |
| 411 |
struct matrix_data *strings = GMatrixEditGet(g, &rows); |
| 412 |
int cols = GMatrixEditGetColCnt(g); |
| 413 |
char *lookupstr = strings[cols*r+c].u.md_str; |
| 414 |
Jstf_Dlg *jd = GDrawGetUserData(GGadgetGetWindow(g)); |
| 415 |
GRect pos; |
| 416 |
GWindow gw; |
| 417 |
GWindowAttrs wattrs; |
| 418 |
GGadgetCreateData gcd[4], boxes[3]; |
| 419 |
GGadgetCreateData *varray[6], *harray3[8]; |
| 420 |
GTextInfo label[4]; |
| 421 |
struct matrixinit mi; |
| 422 |
struct glyph_list_dlg gld; |
| 423 |
|
| 424 |
memset(&gld,0,sizeof(gld)); |
| 425 |
gld.sf = jd->sf; |
| 426 |
|
| 427 |
memset(&wattrs,0,sizeof(wattrs)); |
| 428 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; |
| 429 |
wattrs.event_masks = ~(1<<et_charup); |
| 430 |
wattrs.is_dlg = true; |
| 431 |
wattrs.restrict_input_to_me = 1; |
| 432 |
wattrs.undercursor = 1; |
| 433 |
wattrs.cursor = ct_pointer; |
| 434 |
wattrs.utf8_window_title = |
| 435 |
c==1 ? _("Lookups turned ON to extend a line") : |
| 436 |
c==2 ? _("Lookups turned OFF to extend a line") : |
| 437 |
c==3 ? _("Lookups which specify the maximum size by which a glyph may grow") : |
| 438 |
c==4 ? _("Lookups turned ON to shrink a line") : |
| 439 |
c==5 ? _("Lookups turned OFF to shrink a line") : |
| 440 |
_("Lookups which specify the maximum size by which a glyph may shrink"); |
| 441 |
pos.x = pos.y = 0; |
| 442 |
pos.width =GDrawPointsToPixels(NULL,GGadgetScale(268)); |
| 443 |
pos.height = GDrawPointsToPixels(NULL,375); |
| 444 |
gld.gw = gw = GDrawCreateTopWindow(NULL,&pos,lookup_e_h,&gld,&wattrs); |
| 445 |
|
| 446 |
LookupMatrixInit(&mi,lookupstr,gld.sf,c); |
| 447 |
|
| 448 |
memset(&gcd,0,sizeof(gcd)); |
| 449 |
memset(&boxes,0,sizeof(boxes)); |
| 450 |
memset(&label,0,sizeof(label)); |
| 451 |
k=j=0; |
| 452 |
gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[1].gd.pos.y+14; |
| 453 |
gcd[k].gd.flags = gg_enabled | gg_visible; |
| 454 |
gcd[k].gd.cid = CID_Lookups; |
| 455 |
gcd[k].gd.u.matrix = &mi; |
| 456 |
gcd[k].gd.popup_msg = _( "A list of lookup names"); |
| 457 |
gcd[k].creator = GMatrixEditCreate; |
| 458 |
varray[j++] = &gcd[k++]; varray[j++] = NULL; |
| 459 |
|
| 460 |
gcd[k].gd.pos.x = 30-3; |
| 461 |
gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0; |
| 462 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 463 |
label[k].text = (unichar_t *) _("_OK"); |
| 464 |
label[k].text_is_1byte = true; |
| 465 |
label[k].text_in_resource = true; |
| 466 |
gcd[k].gd.label = &label[k]; |
| 467 |
gcd[k].gd.handle_controlevent = JSTF_Lookup_OK; |
| 468 |
gcd[k].gd.cid = CID_OK; |
| 469 |
gcd[k++].creator = GButtonCreate; |
| 470 |
|
| 471 |
gcd[k].gd.pos.x = -30; |
| 472 |
gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0; |
| 473 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 474 |
label[k].text = (unichar_t *) _("_Cancel"); |
| 475 |
label[k].text_is_1byte = true; |
| 476 |
label[k].text_in_resource = true; |
| 477 |
gcd[k].gd.label = &label[k]; |
| 478 |
gcd[k].gd.handle_controlevent = JSTF_Glyph_Cancel; |
| 479 |
gcd[k].gd.cid = CID_Cancel; |
| 480 |
gcd[k++].creator = GButtonCreate; |
| 481 |
|
| 482 |
harray3[0] = harray3[2] = harray3[3] = harray3[4] = harray3[6] = GCD_Glue; |
| 483 |
harray3[7] = NULL; |
| 484 |
harray3[1] = &gcd[k-2]; harray3[5] = &gcd[k-1]; |
| 485 |
|
| 486 |
boxes[0].gd.flags = gg_enabled|gg_visible; |
| 487 |
boxes[0].gd.u.boxelements = harray3; |
| 488 |
boxes[0].creator = GHBoxCreate; |
| 489 |
varray[j++] = &boxes[0]; varray[j++] = NULL; varray[j] = NULL; |
| 490 |
|
| 491 |
boxes[1].gd.pos.x = boxes[1].gd.pos.y = 2; |
| 492 |
boxes[1].gd.flags = gg_enabled|gg_visible; |
| 493 |
boxes[1].gd.u.boxelements = varray; |
| 494 |
boxes[1].creator = GHVGroupCreate; |
| 495 |
|
| 496 |
GGadgetsCreate(gw,boxes+1); |
| 497 |
|
| 498 |
free( mi.matrix_data ); |
| 499 |
|
| 500 |
GMatrixEditSetNewText(gcd[0].ret,S_("LookupName|New")); |
| 501 |
GHVBoxSetExpandableCol(boxes[0].ret,gb_expandgluesame); |
| 502 |
|
| 503 |
GHVBoxFitWindow(boxes[1].ret); |
| 504 |
|
| 505 |
GDrawSetVisible(gw,true); |
| 506 |
while ( !gld.done ) |
| 507 |
GDrawProcessOneEvent(NULL); |
| 508 |
GDrawDestroyWindow(gw); |
| 509 |
GTextInfoListFree(lookup_ci[0].enum_vals); |
| 510 |
lookup_ci[0].enum_vals = NULL; |
| 511 |
return( gld.ret ); |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
static char *Tag2Str(uint32_t tag) { |
| 518 |
static char foo[8]; |
| 519 |
foo[0] = tag>>24; |
| 520 |
foo[1] = tag>>16; |
| 521 |
foo[2] = tag>>8; |
| 522 |
foo[3] = tag; |
| 523 |
foo[4] = 0; |
| 524 |
return( foo ); |
| 525 |
} |
| 526 |
|
| 527 |
static uint32_t Str2Tag(char *str) { |
| 528 |
unsigned char foo[4]; |
| 529 |
|
| 530 |
memset(foo,' ',4); |
| 531 |
if ( str!=NULL && *str!='\0' ) { |
| 532 |
foo[0] = *str; |
| 533 |
if ( str[1]!='\0' ) { |
| 534 |
foo[1] = str[1]; |
| 535 |
if ( str[2]!='\0' ) { |
| 536 |
foo[2] = str[2]; |
| 537 |
if ( str[3]!='\0' ) |
| 538 |
foo[3] = str[3]; |
| 539 |
} |
| 540 |
} |
| 541 |
} |
| 542 |
return( (foo[0]<<24) | (foo[1]<<16) | (foo[2]<<8) | foo[3] ); |
| 543 |
} |
| 544 |
|
| 545 |
static char *OTList2Str(OTLookup **otll) { |
| 546 |
char *ret, *pt; |
| 547 |
int len, i; |
| 548 |
|
| 549 |
if ( otll==NULL ) |
| 550 |
return( NULL ); |
| 551 |
len = 0; |
| 552 |
for ( i=0; otll[i]!=NULL; ++i ) |
| 553 |
len += strlen(otll[i]->lookup_name) +2; |
| 554 |
if ( len==0 ) |
| 555 |
return( copy( "" )); |
| 556 |
|
| 557 |
ret = pt = malloc(len+1); |
| 558 |
for ( i=0; otll[i]!=NULL; ++i ) { |
| 559 |
strcpy(pt,otll[i]->lookup_name); |
| 560 |
strcat(pt,", "); |
| 561 |
pt += strlen(pt); |
| 562 |
} |
| 563 |
pt[-2] = '\0'; |
| 564 |
return( ret ); |
| 565 |
} |
| 566 |
|
| 567 |
static OTLookup **Str2OTLList(SplineFont *sf,char *str ) { |
| 568 |
int cnt; |
| 569 |
char *pt, *ept; |
| 570 |
OTLookup **ret; |
| 571 |
|
| 572 |
if ( str==NULL ) |
| 573 |
return( NULL ); |
| 574 |
while ( *str==' ' ) |
| 575 |
++str; |
| 576 |
if ( *str=='\0' ) |
| 577 |
return( NULL ); |
| 578 |
|
| 579 |
pt = str; |
| 580 |
cnt = 0; |
| 581 |
while ( (pt = strchr(pt+1,','))!=NULL ) |
| 582 |
++cnt; |
| 583 |
|
| 584 |
ret = malloc( (cnt+2)*sizeof(OTLookup *)); |
| 585 |
pt = str; |
| 586 |
cnt = 0; |
| 587 |
while ( (ept = strchr(pt,','))!=NULL ) { |
| 588 |
*ept = '\0'; |
| 589 |
ret[cnt] = SFFindLookup(sf,pt); |
| 590 |
if ( ret[cnt]==NULL ) { |
| 591 |
ff_post_error(_("Unknown lookup"), _("Unknown lookup name: %60.60s"), |
| 592 |
pt ); |
| 593 |
*ept = ','; |
| 594 |
free(ret); |
| 595 |
return( (OTLookup **) -1 ); |
| 596 |
} |
| 597 |
*ept = ','; |
| 598 |
++cnt; |
| 599 |
pt = ept; |
| 600 |
while ( *pt==',' || *pt==' ' ) ++pt; |
| 601 |
if ( *pt=='\0' ) |
| 602 |
break; |
| 603 |
} |
| 604 |
if ( *pt!='\0' ) { |
| 605 |
ret[cnt] = SFFindLookup(sf,pt); |
| 606 |
if ( ret[cnt]==NULL ) { |
| 607 |
ff_post_error(_("Unknown lookup"), _("Unknown lookup name: %60.60s"), |
| 608 |
pt ); |
| 609 |
free(ret); |
| 610 |
return( (OTLookup **) -1 ); |
| 611 |
} |
| 612 |
++cnt; |
| 613 |
} |
| 614 |
ret[cnt] = NULL; |
| 615 |
return( ret ); |
| 616 |
} |
| 617 |
|
| 618 |
static void JLanguageMatrixInit(struct matrixinit *mi, struct jstf_lang *jl) { |
| 619 |
struct matrix_data *md; |
| 620 |
int i, cnt; |
| 621 |
struct jstf_lang *jlang; |
| 622 |
|
| 623 |
memset(mi,0,sizeof(*mi)); |
| 624 |
mi->col_cnt = 7; |
| 625 |
mi->col_init = jstf_lang_ci; |
| 626 |
|
| 627 |
md = NULL; |
| 628 |
cnt = 0; |
| 629 |
for ( jlang = jl; jlang!=NULL; jlang=jlang->next ) |
| 630 |
cnt += jlang->cnt; |
| 631 |
md = calloc(mi->col_cnt*(cnt+10),sizeof(struct matrix_data)); |
| 632 |
cnt = 0; |
| 633 |
for ( jlang = jl; jlang!=NULL; jlang=jlang->next ) { |
| 634 |
for ( i=0; i<jlang->cnt; ++i ) { |
| 635 |
md[7*cnt+0].u.md_str = copy(Tag2Str(jl->lang)); |
| 636 |
md[7*cnt+1].u.md_str = OTList2Str(jl->prios[i].enableExtend); |
| 637 |
md[7*cnt+2].u.md_str = OTList2Str(jl->prios[i].disableExtend); |
| 638 |
md[7*cnt+3].u.md_str = OTList2Str(jl->prios[i].maxExtend); |
| 639 |
md[7*cnt+4].u.md_str = OTList2Str(jl->prios[i].enableShrink); |
| 640 |
md[7*cnt+5].u.md_str = OTList2Str(jl->prios[i].disableShrink); |
| 641 |
md[7*cnt+6].u.md_str = OTList2Str(jl->prios[i].maxShrink); |
| 642 |
++cnt; |
| 643 |
} |
| 644 |
} |
| 645 |
mi->matrix_data = md; |
| 646 |
mi->initial_row_cnt = cnt; |
| 647 |
} |
| 648 |
|
| 649 |
static int JSTF_Language_OK(GGadget *g, GEvent *e) { |
| 650 |
|
| 651 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 652 |
Jstf_Dlg *jd = GDrawGetUserData(GGadgetGetWindow(g)); |
| 653 |
int rows, i, j, k, cnt; |
| 654 |
struct matrix_data *strings = GMatrixEditGet(GWidgetGetControl(jd->lgw,CID_Languages), &rows); |
| 655 |
int cols = GMatrixEditGetColCnt(GWidgetGetControl(jd->lgw,CID_Languages)); |
| 656 |
struct jstf_lang *head=NULL, *last=NULL, *cur; |
| 657 |
|
| 658 |
for ( i=0; i<rows; ++i ) if ( !(strings[i*cols+0].u.md_str[0]&0x80) ) { |
| 659 |
for ( j=i, cnt=0; j<rows; ++j ) |
| 660 |
if ( strcmp(strings[j*cols+0].u.md_str, strings[i*cols+0].u.md_str)==0 ) |
| 661 |
++cnt; |
| 662 |
cur = chunkalloc(sizeof(struct jstf_lang)); |
| 663 |
if ( head==NULL ) |
| 664 |
head = cur; |
| 665 |
else |
| 666 |
last->next = cur; |
| 667 |
last = cur; |
| 668 |
cur->lang = Str2Tag(strings[i*cols+0].u.md_str); |
| 669 |
cur->cnt = cnt; |
| 670 |
cur->prios=calloc(cnt,sizeof(struct jstf_prio)); |
| 671 |
for ( j=i, cnt=0; j<rows; ++j ) { |
| 672 |
if ( strcmp(strings[j*cols+0].u.md_str, strings[i*cols+0].u.md_str)==0 ) { |
| 673 |
cur->prios[cnt].enableExtend = Str2OTLList(jd->sf,strings[j*cols+1].u.md_str ); |
| 674 |
cur->prios[cnt].disableExtend = Str2OTLList(jd->sf,strings[j*cols+2].u.md_str ); |
| 675 |
cur->prios[cnt].maxExtend = Str2OTLList(jd->sf,strings[j*cols+3].u.md_str ); |
| 676 |
cur->prios[cnt].enableShrink = Str2OTLList(jd->sf,strings[j*cols+4].u.md_str ); |
| 677 |
cur->prios[cnt].disableShrink = Str2OTLList(jd->sf,strings[j*cols+5].u.md_str ); |
| 678 |
cur->prios[cnt].maxShrink = Str2OTLList(jd->sf,strings[j*cols+6].u.md_str ); |
| 679 |
if ( cur->prios[cnt].enableExtend == (OTLookup **) -1 || |
| 680 |
cur->prios[cnt].disableExtend == (OTLookup **) -1 || |
| 681 |
cur->prios[cnt].maxExtend == (OTLookup **) -1 || |
| 682 |
cur->prios[cnt].enableShrink == (OTLookup **) -1 || |
| 683 |
cur->prios[cnt].disableShrink == (OTLookup **) -1 || |
| 684 |
cur->prios[cnt].maxShrink == (OTLookup **) -1 ) { |
| 685 |
JstfLangFree(head); |
| 686 |
for ( k=0; k<rows; ++k ) |
| 687 |
strings[k*cols+0].u.md_str[0] &= ~0x80; |
| 688 |
return( true ); |
| 689 |
} |
| 690 |
++cnt; |
| 691 |
} |
| 692 |
} |
| 693 |
for ( j=rows-1; j>=i; --j ) |
| 694 |
if ( strcmp(strings[j*cols+0].u.md_str, strings[i*cols+0].u.md_str)==0 ) |
| 695 |
strings[j*cols+0].u.md_str[0] |= 0x80; |
| 696 |
} |
| 697 |
JstfLangFree( *jd->here ); |
| 698 |
*jd->here = head; |
| 699 |
jd->ldone = true; |
| 700 |
} |
| 701 |
return( true ); |
| 702 |
} |
| 703 |
|
| 704 |
static int JSTF_Language_Cancel(GGadget *g, GEvent *e) { |
| 705 |
|
| 706 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 707 |
Jstf_Dlg *jd = GDrawGetUserData(GGadgetGetWindow(g)); |
| 708 |
jd->ldone = true; |
| 709 |
} |
| 710 |
return( true ); |
| 711 |
} |
| 712 |
|
| 713 |
static int langs_e_h(GWindow gw, GEvent *event) { |
| 714 |
|
| 715 |
if ( event->type==et_close ) { |
| 716 |
Jstf_Dlg *jd = GDrawGetUserData(gw); |
| 717 |
jd->ldone = true; |
| 718 |
} else if ( event->type == et_char ) { |
| 719 |
if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) { |
| 720 |
help("ui/dialogs/justify.html", "#justify-language-dlg"); |
| 721 |
return( true ); |
| 722 |
} |
| 723 |
return( false ); |
| 724 |
} |
| 725 |
|
| 726 |
return( true ); |
| 727 |
} |
| 728 |
|
| 729 |
static char *JSTF_Langs(GGadget *g, int r, int c) { |
| 730 |
int rows, i, k, j; |
| 731 |
struct matrix_data *strings = GMatrixEditGet(g, &rows); |
| 732 |
int cols = GMatrixEditGetColCnt(g); |
| 733 |
Jstf_Dlg *jd = GDrawGetUserData(GGadgetGetWindow(g)); |
| 734 |
GRect pos; |
| 735 |
GWindow gw; |
| 736 |
GWindowAttrs wattrs; |
| 737 |
GGadgetCreateData gcd[4], boxes[3]; |
| 738 |
GGadgetCreateData *varray[6], *harray3[8]; |
| 739 |
GTextInfo label[4]; |
| 740 |
struct matrixinit mi; |
| 741 |
|
| 742 |
jd->ldone = false; |
| 743 |
jd->here = (struct jstf_lang **) &strings[cols*r+3].u.md_addr; |
| 744 |
|
| 745 |
memset(&wattrs,0,sizeof(wattrs)); |
| 746 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; |
| 747 |
wattrs.event_masks = ~(1<<et_charup); |
| 748 |
wattrs.is_dlg = true; |
| 749 |
wattrs.restrict_input_to_me = 1; |
| 750 |
wattrs.undercursor = 1; |
| 751 |
wattrs.cursor = ct_pointer; |
| 752 |
wattrs.utf8_window_title = _("Justified Languages"); |
| 753 |
pos.x = pos.y = 0; |
| 754 |
pos.width =GDrawPointsToPixels(NULL,GGadgetScale(268)); |
| 755 |
pos.height = GDrawPointsToPixels(NULL,375); |
| 756 |
jd->lgw = gw = GDrawCreateTopWindow(NULL,&pos,langs_e_h,jd,&wattrs); |
| 757 |
|
| 758 |
memset(&gcd,0,sizeof(gcd)); |
| 759 |
memset(&boxes,0,sizeof(boxes)); |
| 760 |
memset(&label,0,sizeof(label)); |
| 761 |
k=j=0; |
| 762 |
JLanguageMatrixInit(&mi,*jd->here); |
| 763 |
gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[1].gd.pos.y+14; |
| 764 |
gcd[k].gd.pos.width = 900; |
| 765 |
gcd[k].gd.flags = gg_enabled | gg_visible; |
| 766 |
gcd[k].gd.cid = CID_Languages; |
| 767 |
gcd[k].gd.u.matrix = &mi; |
| 768 |
gcd[k].gd.popup_msg = _( |
| 769 |
"A list of languages and the lookups turned on and off\n" |
| 770 |
"for each to accomplish justification. A language may\n" |
| 771 |
"appear more than once, in which case second (or third,\n" |
| 772 |
"etc.) will be tried if the first fails."); |
| 773 |
gcd[k].creator = GMatrixEditCreate; |
| 774 |
varray[j++] = &gcd[k++]; varray[j++] = NULL; |
| 775 |
|
| 776 |
gcd[k].gd.pos.x = 30-3; |
| 777 |
gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0; |
| 778 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 779 |
label[k].text = (unichar_t *) _("_OK"); |
| 780 |
label[k].text_is_1byte = true; |
| 781 |
label[k].text_in_resource = true; |
| 782 |
gcd[k].gd.label = &label[k]; |
| 783 |
gcd[k].gd.handle_controlevent = JSTF_Language_OK; |
| 784 |
gcd[k].gd.cid = CID_OK; |
| 785 |
gcd[k++].creator = GButtonCreate; |
| 786 |
|
| 787 |
gcd[k].gd.pos.x = -30; |
| 788 |
gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0; |
| 789 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 790 |
label[k].text = (unichar_t *) _("_Cancel"); |
| 791 |
label[k].text_is_1byte = true; |
| 792 |
label[k].text_in_resource = true; |
| 793 |
gcd[k].gd.label = &label[k]; |
| 794 |
gcd[k].gd.handle_controlevent = JSTF_Language_Cancel; |
| 795 |
gcd[k].gd.cid = CID_Cancel; |
| 796 |
gcd[k++].creator = GButtonCreate; |
| 797 |
|
| 798 |
harray3[0] = harray3[2] = harray3[3] = harray3[4] = harray3[6] = GCD_Glue; |
| 799 |
harray3[7] = NULL; |
| 800 |
harray3[1] = &gcd[k-2]; harray3[5] = &gcd[k-1]; |
| 801 |
|
| 802 |
boxes[0].gd.flags = gg_enabled|gg_visible; |
| 803 |
boxes[0].gd.u.boxelements = harray3; |
| 804 |
boxes[0].creator = GHBoxCreate; |
| 805 |
varray[j++] = &boxes[0]; varray[j++] = NULL; varray[j] = NULL; |
| 806 |
|
| 807 |
boxes[1].gd.pos.x = boxes[1].gd.pos.y = 2; |
| 808 |
boxes[1].gd.flags = gg_enabled|gg_visible; |
| 809 |
boxes[1].gd.u.boxelements = varray; |
| 810 |
boxes[1].creator = GHVGroupCreate; |
| 811 |
|
| 812 |
GGadgetsCreate(gw,boxes+1); |
| 813 |
|
| 814 |
for ( i=0; i<mi.initial_row_cnt; ++i ) { |
| 815 |
free( mi.matrix_data[2*i+0].u.md_str ); |
| 816 |
} |
| 817 |
free( mi.matrix_data ); |
| 818 |
|
| 819 |
GMatrixEditSetNewText(gcd[0].ret,S_("Language|New")); |
| 820 |
GMatrixEditSetUpDownVisible(gcd[0].ret,true); |
| 821 |
GHVBoxSetExpandableCol(boxes[0].ret,gb_expandgluesame); |
| 822 |
|
| 823 |
GHVBoxFitWindow(boxes[1].ret); |
| 824 |
|
| 825 |
GDrawSetVisible(gw,true); |
| 826 |
while ( !jd->ldone ) |
| 827 |
GDrawProcessOneEvent(NULL); |
| 828 |
GDrawDestroyWindow(gw); |
| 829 |
return( NULL ); |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
static void JScriptMatrixInit(struct matrixinit *mi,Justify *js) { |
| 837 |
struct matrix_data *md; |
| 838 |
int k, cnt; |
| 839 |
Justify *jscript; |
| 840 |
|
| 841 |
memset(mi,0,sizeof(*mi)); |
| 842 |
mi->col_cnt = 4; |
| 843 |
mi->col_init = justify_ci; |
| 844 |
|
| 845 |
md = NULL; |
| 846 |
for ( k=0; k<2; ++k ) { |
| 847 |
cnt = 0; |
| 848 |
for ( jscript=js; jscript!=NULL; jscript = jscript->next ) { |
| 849 |
if ( k ) { |
| 850 |
md[4*cnt+0].u.md_str = copy(Tag2Str(jscript->script)); |
| 851 |
md[4*cnt+1].u.md_str = copy(jscript->extenders); |
| 852 |
|
| 853 |
md[4*cnt+3].u.md_addr = JstfLangsCopy(jscript->langs); |
| 854 |
} |
| 855 |
++cnt; |
| 856 |
} |
| 857 |
if ( md==NULL ) |
| 858 |
md = calloc(4*(cnt+10),sizeof(struct matrix_data)); |
| 859 |
} |
| 860 |
mi->matrix_data = md; |
| 861 |
mi->initial_row_cnt = cnt; |
| 862 |
} |
| 863 |
|
| 864 |
static int JSTF_Script_OK(GGadget *g, GEvent *e) { |
| 865 |
|
| 866 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 867 |
Jstf_Dlg *jd = GDrawGetUserData(GGadgetGetWindow(g)); |
| 868 |
SplineFont *sf = jd->sf; |
| 869 |
Justify *head=NULL, *last=NULL, *cur; |
| 870 |
int rows, i; |
| 871 |
int cols = GMatrixEditGetColCnt(GWidgetGetControl(jd->gw,CID_Scripts)); |
| 872 |
struct matrix_data *strings = GMatrixEditGet(GWidgetGetControl(jd->gw,CID_Scripts), &rows); |
| 873 |
|
| 874 |
for ( i=0; i<rows; ++i ) { |
| 875 |
cur = chunkalloc(sizeof(Justify)); |
| 876 |
cur->script = Str2Tag(strings[cols*i+0].u.md_str); |
| 877 |
cur->extenders = copy(strings[cols*i+1].u.md_str); |
| 878 |
cur->langs = strings[cols*i+3].u.md_addr; |
| 879 |
if ( head==NULL ) |
| 880 |
head = cur; |
| 881 |
else |
| 882 |
last->next = cur; |
| 883 |
last = cur; |
| 884 |
} |
| 885 |
JustifyFree(sf->justify); |
| 886 |
sf->justify = head; |
| 887 |
jd->done = true; |
| 888 |
} |
| 889 |
return( true ); |
| 890 |
} |
| 891 |
|
| 892 |
static void Jstf_Cancel(Jstf_Dlg *jd) { |
| 893 |
int rows, i; |
| 894 |
int cols = GMatrixEditGetColCnt(GWidgetGetControl(jd->gw,CID_Scripts)); |
| 895 |
struct matrix_data *strings = GMatrixEditGet(GWidgetGetControl(jd->gw,CID_Scripts), &rows); |
| 896 |
|
| 897 |
for ( i=0; i<rows; ++i ) { |
| 898 |
JstfLangFree(strings[cols*i+3].u.md_addr); |
| 899 |
} |
| 900 |
jd->done = true; |
| 901 |
} |
| 902 |
|
| 903 |
static int Justify_Cancel(GGadget *g, GEvent *e) { |
| 904 |
|
| 905 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 906 |
Jstf_Dlg *jd = GDrawGetUserData(GGadgetGetWindow(g)); |
| 907 |
Jstf_Cancel(jd); |
| 908 |
} |
| 909 |
return( true ); |
| 910 |
} |
| 911 |
|
| 912 |
static int jscripts_e_h(GWindow gw, GEvent *event) { |
| 913 |
|
| 914 |
if ( event->type==et_close ) { |
| 915 |
Jstf_Dlg *jd = GDrawGetUserData(gw); |
| 916 |
Jstf_Cancel(jd); |
| 917 |
} else if ( event->type == et_char ) { |
| 918 |
if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) { |
| 919 |
help("ui/dialogs/justify.html", NULL); |
| 920 |
return( true ); |
| 921 |
} |
| 922 |
return( false ); |
| 923 |
} |
| 924 |
|
| 925 |
return( true ); |
| 926 |
} |
| 927 |
|
| 928 |
void JustifyDlg(SplineFont *sf) { |
| 929 |
Jstf_Dlg jd; |
| 930 |
GRect pos; |
| 931 |
GWindow gw; |
| 932 |
GWindowAttrs wattrs; |
| 933 |
GGadgetCreateData gcd[4], boxes[3]; |
| 934 |
GGadgetCreateData *varray[6], *harray3[8]; |
| 935 |
GTextInfo label[4]; |
| 936 |
struct matrixinit mi; |
| 937 |
int i,j,k; |
| 938 |
|
| 939 |
LookupUIInit(); |
| 940 |
JustUIInit(); |
| 941 |
|
| 942 |
memset(&jd,0,sizeof(jd)); |
| 943 |
jd.sf = sf; |
| 944 |
|
| 945 |
memset(&wattrs,0,sizeof(wattrs)); |
| 946 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; |
| 947 |
wattrs.event_masks = ~(1<<et_charup); |
| 948 |
wattrs.is_dlg = true; |
| 949 |
wattrs.restrict_input_to_me = 1; |
| 950 |
wattrs.undercursor = 1; |
| 951 |
wattrs.cursor = ct_pointer; |
| 952 |
wattrs.utf8_window_title = _("Justified Scripts"); |
| 953 |
pos.x = pos.y = 0; |
| 954 |
pos.width =GDrawPointsToPixels(NULL,GGadgetScale(268)); |
| 955 |
pos.height = GDrawPointsToPixels(NULL,375); |
| 956 |
jd.gw = gw = GDrawCreateTopWindow(NULL,&pos,jscripts_e_h,&jd,&wattrs); |
| 957 |
|
| 958 |
JScriptMatrixInit(&mi,sf->justify); |
| 959 |
|
| 960 |
memset(&gcd,0,sizeof(gcd)); |
| 961 |
memset(&boxes,0,sizeof(boxes)); |
| 962 |
memset(&label,0,sizeof(label)); |
| 963 |
k=j=0; |
| 964 |
gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[1].gd.pos.y+14; |
| 965 |
gcd[k].gd.flags = gg_enabled | gg_visible; |
| 966 |
gcd[k].gd.cid = CID_Scripts; |
| 967 |
gcd[k].gd.u.matrix = &mi; |
| 968 |
gcd[k].gd.popup_msg = _( "A list of scripts with special justification needs"); |
| 969 |
gcd[k].creator = GMatrixEditCreate; |
| 970 |
varray[j++] = &gcd[k++]; varray[j++] = NULL; |
| 971 |
|
| 972 |
gcd[k].gd.pos.x = 30-3; |
| 973 |
gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0; |
| 974 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 975 |
label[k].text = (unichar_t *) _("_OK"); |
| 976 |
label[k].text_is_1byte = true; |
| 977 |
label[k].text_in_resource = true; |
| 978 |
gcd[k].gd.label = &label[k]; |
| 979 |
gcd[k].gd.handle_controlevent = JSTF_Script_OK; |
| 980 |
gcd[k].gd.cid = CID_OK; |
| 981 |
gcd[k++].creator = GButtonCreate; |
| 982 |
|
| 983 |
gcd[k].gd.pos.x = -30; |
| 984 |
gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0; |
| 985 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 986 |
label[k].text = (unichar_t *) _("_Cancel"); |
| 987 |
label[k].text_is_1byte = true; |
| 988 |
label[k].text_in_resource = true; |
| 989 |
gcd[k].gd.label = &label[k]; |
| 990 |
gcd[k].gd.handle_controlevent = Justify_Cancel; |
| 991 |
gcd[k].gd.cid = CID_Cancel; |
| 992 |
gcd[k++].creator = GButtonCreate; |
| 993 |
|
| 994 |
harray3[0] = harray3[2] = harray3[3] = harray3[4] = harray3[6] = GCD_Glue; |
| 995 |
harray3[7] = NULL; |
| 996 |
harray3[1] = &gcd[k-2]; harray3[5] = &gcd[k-1]; |
| 997 |
|
| 998 |
boxes[0].gd.flags = gg_enabled|gg_visible; |
| 999 |
boxes[0].gd.u.boxelements = harray3; |
| 1000 |
boxes[0].creator = GHBoxCreate; |
| 1001 |
varray[j++] = &boxes[0]; varray[j++] = NULL; varray[j] = NULL; |
| 1002 |
|
| 1003 |
boxes[1].gd.pos.x = boxes[1].gd.pos.y = 2; |
| 1004 |
boxes[1].gd.flags = gg_enabled|gg_visible; |
| 1005 |
boxes[1].gd.u.boxelements = varray; |
| 1006 |
boxes[1].creator = GHVGroupCreate; |
| 1007 |
|
| 1008 |
GGadgetsCreate(gw,boxes+1); |
| 1009 |
|
| 1010 |
for ( i=0; i<mi.initial_row_cnt; ++i ) { |
| 1011 |
free( mi.matrix_data[2*i+0].u.md_str ); |
| 1012 |
} |
| 1013 |
free( mi.matrix_data ); |
| 1014 |
|
| 1015 |
GMatrixEditSetNewText(gcd[0].ret,S_("Script|New")); |
| 1016 |
GMatrixEditSetUpDownVisible(gcd[0].ret,true); |
| 1017 |
GMatrixEditShowColumn(gcd[0].ret,3,false); |
| 1018 |
GHVBoxSetExpandableCol(boxes[0].ret,gb_expandgluesame); |
| 1019 |
|
| 1020 |
GHVBoxFitWindow(boxes[1].ret); |
| 1021 |
|
| 1022 |
GDrawSetVisible(gw,true); |
| 1023 |
while ( !jd.done ) |
| 1024 |
GDrawProcessOneEvent(NULL); |
| 1025 |
GDrawDestroyWindow(gw); |
| 1026 |
} |