| 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 "fvfonts.h" |
| 32 |
#include "gfile.h" |
| 33 |
#include "splineutil.h" |
| 34 |
#include "ustring.h" |
| 35 |
#include "utype.h" |
| 36 |
|
| 37 |
static void MergeAskFilename(FontView *fv,int preserveCrossFontKerning) { |
| 38 |
char *filename = GetPostScriptFontName(NULL,true,true); |
| 39 |
SplineFont *sf; |
| 40 |
char *eod, *fpt, *file, *full; |
| 41 |
|
| 42 |
if ( filename==NULL ) |
| 43 |
return; |
| 44 |
eod = strrchr(filename,'/'); |
| 45 |
*eod = '\0'; |
| 46 |
file = eod+1; |
| 47 |
do { |
| 48 |
fpt = strstr(file,"; "); |
| 49 |
if ( fpt!=NULL ) *fpt = '\0'; |
| 50 |
full = malloc(strlen(filename)+1+strlen(file)+1); |
| 51 |
strcpy(full,filename); strcat(full,"/"); strcat(full,file); |
| 52 |
sf = LoadSplineFont(full,0); |
| 53 |
if ( sf!=NULL && sf->fv==NULL ) |
| 54 |
EncMapFree(sf->map); |
| 55 |
free(full); |
| 56 |
if ( sf==NULL ) |
| 57 |
; |
| 58 |
else if ( sf->fv==(FontViewBase *) fv ) |
| 59 |
ff_post_error(_("Merging Problem"),_("Merging a font with itself achieves nothing")); |
| 60 |
else { |
| 61 |
if ( preserveCrossFontKerning==-1 ) { |
| 62 |
char *buts[4]; |
| 63 |
int ret; |
| 64 |
buts[0] = _("_Yes"); buts[1] = _("_No"); buts[2] = _("_Cancel"); buts[3]=NULL; |
| 65 |
ret = gwwv_ask(_("Kerning"),(const char **) buts,0,2, |
| 66 |
_("Do you want to retain kerning information from the selected font\nwhen one of the glyphs being kerned will come from the base font?")); |
| 67 |
if ( ret==2 ) { |
| 68 |
free(filename); |
| 69 |
return; |
| 70 |
} |
| 71 |
preserveCrossFontKerning = ret==0; |
| 72 |
} |
| 73 |
MergeFont((FontViewBase *) fv,sf,preserveCrossFontKerning); |
| 74 |
} |
| 75 |
file = fpt+2; |
| 76 |
} while ( fpt!=NULL ); |
| 77 |
free(filename); |
| 78 |
} |
| 79 |
|
| 80 |
GTextInfo *BuildFontList(FontView *except) { |
| 81 |
FontView *fv; |
| 82 |
int cnt=0; |
| 83 |
GTextInfo *tf; |
| 84 |
|
| 85 |
for ( fv=fv_list; fv!=NULL; fv = (FontView *) (fv->b.next) ) |
| 86 |
++cnt; |
| 87 |
tf = calloc(cnt+3,sizeof(GTextInfo)); |
| 88 |
for ( fv=fv_list, cnt=0; fv!=NULL; fv = (FontView *) (fv->b.next) ) if ( fv!=except ) { |
| 89 |
tf[cnt].fg = tf[cnt].bg = COLOR_DEFAULT; |
| 90 |
tf[cnt].text = (unichar_t *) fv->b.sf->fontname; |
| 91 |
tf[cnt].text_is_1byte = true; |
| 92 |
++cnt; |
| 93 |
} |
| 94 |
tf[cnt++].line = true; |
| 95 |
tf[cnt].fg = tf[cnt].bg = COLOR_DEFAULT; |
| 96 |
tf[cnt].text_is_1byte = true; |
| 97 |
tf[cnt++].text = (unichar_t *) _("Other ..."); |
| 98 |
return( tf ); |
| 99 |
} |
| 100 |
|
| 101 |
void TFFree(GTextInfo *tf) { |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
free(tf); |
| 110 |
} |
| 111 |
|
| 112 |
struct mf_data { |
| 113 |
int done; |
| 114 |
FontView *fv; |
| 115 |
GGadget *other; |
| 116 |
GGadget *amount; |
| 117 |
}; |
| 118 |
#define CID_Preserve 1001 |
| 119 |
|
| 120 |
static int MF_OK(GGadget *g, GEvent *e) { |
| 121 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 122 |
GWindow gw = GGadgetGetWindow(g); |
| 123 |
struct mf_data *d = GDrawGetUserData(gw); |
| 124 |
int i, index = GGadgetGetFirstListSelectedItem(d->other); |
| 125 |
int preserve = GGadgetIsChecked(GWidgetGetControl(gw,CID_Preserve)); |
| 126 |
FontView *fv; |
| 127 |
for ( i=0, fv=fv_list; fv!=NULL; fv=(FontView *) (fv->b.next) ) { |
| 128 |
if ( fv==d->fv ) |
| 129 |
continue; |
| 130 |
if ( i==index ) |
| 131 |
break; |
| 132 |
++i; |
| 133 |
} |
| 134 |
if ( fv==NULL ) |
| 135 |
MergeAskFilename(d->fv,preserve); |
| 136 |
else |
| 137 |
MergeFont((FontViewBase *) d->fv,fv->b.sf,preserve); |
| 138 |
d->done = true; |
| 139 |
} |
| 140 |
return( true ); |
| 141 |
} |
| 142 |
|
| 143 |
static int MF_Cancel(GGadget *g, GEvent *e) { |
| 144 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 145 |
GWindow gw = GGadgetGetWindow(g); |
| 146 |
struct mf_data *d = GDrawGetUserData(gw); |
| 147 |
d->done = true; |
| 148 |
} |
| 149 |
return( true ); |
| 150 |
} |
| 151 |
|
| 152 |
static int mv_e_h(GWindow gw, GEvent *event) { |
| 153 |
if ( event->type==et_close ) { |
| 154 |
struct mf_data *d = GDrawGetUserData(gw); |
| 155 |
d->done = true; |
| 156 |
} else if ( event->type == et_char ) { |
| 157 |
return( false ); |
| 158 |
} |
| 159 |
return( true ); |
| 160 |
} |
| 161 |
|
| 162 |
void FVMergeFonts(FontView *fv) { |
| 163 |
GRect pos; |
| 164 |
GWindow gw; |
| 165 |
GWindowAttrs wattrs; |
| 166 |
GGadgetCreateData gcd[7], *varray[9], *barray[8], boxes[4]; |
| 167 |
GTextInfo label[7]; |
| 168 |
struct mf_data d; |
| 169 |
char buffer[80]; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
if ( fv_list==fv && fv_list->b.next==NULL ) |
| 175 |
MergeAskFilename(fv,-1); |
| 176 |
else { |
| 177 |
memset(&wattrs,0,sizeof(wattrs)); |
| 178 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg; |
| 179 |
wattrs.event_masks = ~(1<<et_charup); |
| 180 |
wattrs.restrict_input_to_me = 1; |
| 181 |
wattrs.is_dlg = 1; |
| 182 |
wattrs.undercursor = 1; |
| 183 |
wattrs.cursor = ct_pointer; |
| 184 |
wattrs.utf8_window_title = _("Merge Fonts"); |
| 185 |
pos.x = pos.y = 0; |
| 186 |
pos.width = GGadgetScale(GDrawPointsToPixels(NULL,150)); |
| 187 |
pos.height = GDrawPointsToPixels(NULL,88); |
| 188 |
gw = GDrawCreateTopWindow(NULL,&pos,mv_e_h,&d,&wattrs); |
| 189 |
|
| 190 |
memset(&label,0,sizeof(label)); |
| 191 |
memset(&gcd,0,sizeof(gcd)); |
| 192 |
memset(&boxes,0,sizeof(boxes)); |
| 193 |
|
| 194 |
sprintf( buffer, _("Font to merge into %.20s"), fv->b.sf->fontname ); |
| 195 |
label[0].text = (unichar_t *) buffer; |
| 196 |
label[0].text_is_1byte = true; |
| 197 |
gcd[0].gd.label = &label[0]; |
| 198 |
gcd[0].gd.pos.x = 12; gcd[0].gd.pos.y = 6; |
| 199 |
gcd[0].gd.flags = gg_visible | gg_enabled; |
| 200 |
gcd[0].creator = GLabelCreate; |
| 201 |
varray[0] = &gcd[0]; varray[1] = NULL; |
| 202 |
|
| 203 |
gcd[1].gd.pos.x = 15; gcd[1].gd.pos.y = 21; |
| 204 |
gcd[1].gd.pos.width = 120; |
| 205 |
gcd[1].gd.flags = gg_visible | gg_enabled; |
| 206 |
gcd[1].gd.u.list = BuildFontList(fv); |
| 207 |
gcd[1].gd.label = &gcd[1].gd.u.list[0]; |
| 208 |
gcd[1].gd.u.list[0].selected = true; |
| 209 |
gcd[1].creator = GListButtonCreate; |
| 210 |
varray[2] = &gcd[1]; varray[3] = NULL; |
| 211 |
|
| 212 |
label[2].text = (unichar_t *) _("Preserve cross-font kerning"); |
| 213 |
label[2].text_is_1byte = true; |
| 214 |
gcd[2].gd.label = &label[2]; |
| 215 |
gcd[2].gd.pos.x = 12; gcd[2].gd.pos.y = 6; |
| 216 |
gcd[2].gd.flags = gg_visible | gg_enabled | gg_cb_on; |
| 217 |
gcd[2].gd.cid = CID_Preserve; |
| 218 |
gcd[2].creator = GCheckBoxCreate; |
| 219 |
varray[4] = &gcd[2]; varray[5] = NULL; |
| 220 |
|
| 221 |
gcd[3].gd.pos.x = 15-3; gcd[3].gd.pos.y = 55-3; |
| 222 |
gcd[3].gd.pos.width = -1; gcd[3].gd.pos.height = 0; |
| 223 |
gcd[3].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 224 |
label[3].text = (unichar_t *) _("_OK"); |
| 225 |
label[3].text_is_1byte = true; |
| 226 |
label[3].text_in_resource = true; |
| 227 |
gcd[3].gd.mnemonic = 'O'; |
| 228 |
gcd[3].gd.label = &label[3]; |
| 229 |
gcd[3].gd.handle_controlevent = MF_OK; |
| 230 |
gcd[3].creator = GButtonCreate; |
| 231 |
|
| 232 |
gcd[4].gd.pos.x = -15; gcd[4].gd.pos.y = 55; |
| 233 |
gcd[4].gd.pos.width = -1; gcd[4].gd.pos.height = 0; |
| 234 |
gcd[4].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 235 |
label[4].text = (unichar_t *) _("_Cancel"); |
| 236 |
label[4].text_is_1byte = true; |
| 237 |
label[4].text_in_resource = true; |
| 238 |
gcd[4].gd.label = &label[4]; |
| 239 |
gcd[4].gd.mnemonic = 'C'; |
| 240 |
gcd[4].gd.handle_controlevent = MF_Cancel; |
| 241 |
gcd[4].creator = GButtonCreate; |
| 242 |
barray[0] = barray[2] = barray[3] = barray[4] = barray[6] = GCD_Glue; barray[7] = NULL; |
| 243 |
barray[1] = &gcd[3]; barray[5] = &gcd[4]; |
| 244 |
|
| 245 |
boxes[2].gd.flags = gg_enabled|gg_visible; |
| 246 |
boxes[2].gd.u.boxelements = barray; |
| 247 |
boxes[2].creator = GHBoxCreate; |
| 248 |
varray[6] = &boxes[2]; varray[7] = NULL; |
| 249 |
varray[8] = NULL; |
| 250 |
|
| 251 |
boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2; |
| 252 |
boxes[0].gd.flags = gg_enabled|gg_visible; |
| 253 |
boxes[0].gd.u.boxelements = varray; |
| 254 |
boxes[0].creator = GHVGroupCreate; |
| 255 |
|
| 256 |
GGadgetsCreate(gw,boxes); |
| 257 |
GHVBoxSetExpandableCol(boxes[2].ret,gb_expandgluesame); |
| 258 |
GHVBoxFitWindow(boxes[0].ret); |
| 259 |
|
| 260 |
memset(&d,'\0',sizeof(d)); |
| 261 |
d.other = gcd[1].ret; |
| 262 |
d.fv = fv; |
| 263 |
|
| 264 |
GDrawSetVisible(gw,true); |
| 265 |
while ( !d.done ) |
| 266 |
GDrawProcessOneEvent(NULL); |
| 267 |
GDrawDestroyWindow(gw); |
| 268 |
TFFree(gcd[1].gd.u.list); |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
static void InterAskFilename(FontView *fv, real amount) { |
| 277 |
char *filename = GetPostScriptFontName(NULL,false,true); |
| 278 |
SplineFont *sf; |
| 279 |
|
| 280 |
if ( filename==NULL ) |
| 281 |
return; |
| 282 |
sf = LoadSplineFont(filename,0); |
| 283 |
if ( sf!=NULL && sf->fv==NULL ) |
| 284 |
EncMapFree(sf->map); |
| 285 |
free(filename); |
| 286 |
if ( sf==NULL ) |
| 287 |
return; |
| 288 |
FontViewCreate(InterpolateFont(fv->b.sf,sf,amount,fv->b.map->enc),false); |
| 289 |
} |
| 290 |
|
| 291 |
#define CID_Amount 1000 |
| 292 |
static double last_amount=50; |
| 293 |
|
| 294 |
static int IF_OK(GGadget *g, GEvent *e) { |
| 295 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 296 |
GWindow gw = GGadgetGetWindow(g); |
| 297 |
struct mf_data *d = GDrawGetUserData(gw); |
| 298 |
int i, index = GGadgetGetFirstListSelectedItem(d->other); |
| 299 |
FontView *fv; |
| 300 |
int err=false; |
| 301 |
real amount; |
| 302 |
|
| 303 |
amount = GetReal8(gw,CID_Amount, _("Amount"),&err); |
| 304 |
if ( err ) |
| 305 |
return( true ); |
| 306 |
last_amount = amount; |
| 307 |
for ( i=0, fv=fv_list; fv!=NULL; fv=(FontView *) (fv->b.next) ) { |
| 308 |
if ( fv==d->fv ) |
| 309 |
continue; |
| 310 |
if ( i==index ) |
| 311 |
break; |
| 312 |
++i; |
| 313 |
} |
| 314 |
if ( fv==NULL ) |
| 315 |
InterAskFilename(d->fv,last_amount/100.0); |
| 316 |
else |
| 317 |
FontViewCreate(InterpolateFont(d->fv->b.sf,fv->b.sf,last_amount/100.0,d->fv->b.map->enc),false); |
| 318 |
d->done = true; |
| 319 |
} |
| 320 |
return( true ); |
| 321 |
} |
| 322 |
|
| 323 |
void FVInterpolateFonts(FontView *fv) { |
| 324 |
GRect pos; |
| 325 |
GWindow gw; |
| 326 |
GWindowAttrs wattrs; |
| 327 |
GGadgetCreateData gcd[8]; |
| 328 |
GTextInfo label[8]; |
| 329 |
struct mf_data d; |
| 330 |
char buffer[80]; char buf2[30]; |
| 331 |
|
| 332 |
memset(&wattrs,0,sizeof(wattrs)); |
| 333 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg; |
| 334 |
wattrs.event_masks = ~(1<<et_charup); |
| 335 |
wattrs.restrict_input_to_me = 1; |
| 336 |
wattrs.is_dlg = 1; |
| 337 |
wattrs.undercursor = 1; |
| 338 |
wattrs.cursor = ct_pointer; |
| 339 |
wattrs.utf8_window_title = _("Interpolate Fonts"); |
| 340 |
pos.x = pos.y = 0; |
| 341 |
pos.width = GGadgetScale(GDrawPointsToPixels(NULL,200)); |
| 342 |
pos.height = GDrawPointsToPixels(NULL,118); |
| 343 |
gw = GDrawCreateTopWindow(NULL,&pos,mv_e_h,&d,&wattrs); |
| 344 |
|
| 345 |
memset(&label,0,sizeof(label)); |
| 346 |
memset(&gcd,0,sizeof(gcd)); |
| 347 |
|
| 348 |
sprintf( buffer, _("Interpolating between %.20s and:"), fv->b.sf->fontname ); |
| 349 |
label[0].text = (unichar_t *) buffer; |
| 350 |
label[0].text_is_1byte = true; |
| 351 |
gcd[0].gd.label = &label[0]; |
| 352 |
gcd[0].gd.pos.x = 12; gcd[0].gd.pos.y = 6; |
| 353 |
gcd[0].gd.flags = gg_visible | gg_enabled; |
| 354 |
gcd[0].creator = GLabelCreate; |
| 355 |
|
| 356 |
gcd[1].gd.pos.x = 20; gcd[1].gd.pos.y = 21; |
| 357 |
gcd[1].gd.pos.width = 110; |
| 358 |
gcd[1].gd.flags = gg_visible | gg_enabled; |
| 359 |
gcd[1].gd.u.list = BuildFontList(fv); |
| 360 |
if ( gcd[1].gd.u.list[0].text!=NULL ) { |
| 361 |
gcd[1].gd.label = &gcd[1].gd.u.list[0]; |
| 362 |
gcd[1].gd.u.list[0].selected = true; |
| 363 |
} else { |
| 364 |
gcd[1].gd.label = &gcd[1].gd.u.list[1]; |
| 365 |
gcd[1].gd.u.list[1].selected = true; |
| 366 |
gcd[1].gd.flags = gg_visible; |
| 367 |
} |
| 368 |
gcd[1].creator = GListButtonCreate; |
| 369 |
|
| 370 |
sprintf( buf2, "%g", last_amount ); |
| 371 |
label[2].text = (unichar_t *) buf2; |
| 372 |
label[2].text_is_1byte = true; |
| 373 |
gcd[2].gd.pos.x = 20; gcd[2].gd.pos.y = 51; |
| 374 |
gcd[2].gd.pos.width = 40; |
| 375 |
gcd[2].gd.flags = gg_visible | gg_enabled; |
| 376 |
gcd[2].gd.label = &label[2]; |
| 377 |
gcd[2].gd.cid = CID_Amount; |
| 378 |
gcd[2].creator = GTextFieldCreate; |
| 379 |
|
| 380 |
gcd[3].gd.pos.x = 5; gcd[3].gd.pos.y = 51+6; |
| 381 |
gcd[3].gd.flags = gg_visible | gg_enabled; |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
label[3].text = (unichar_t *) _("by"); |
| 388 |
label[3].text_is_1byte = true; |
| 389 |
gcd[3].gd.label = &label[3]; |
| 390 |
gcd[3].creator = GLabelCreate; |
| 391 |
|
| 392 |
gcd[4].gd.pos.x = 20+40+3; gcd[4].gd.pos.y = 51+6; |
| 393 |
gcd[4].gd.flags = gg_visible | gg_enabled; |
| 394 |
label[4].text = (unichar_t *) "%"; |
| 395 |
label[4].text_is_1byte = true; |
| 396 |
gcd[4].gd.label = &label[4]; |
| 397 |
gcd[4].creator = GLabelCreate; |
| 398 |
|
| 399 |
gcd[5].gd.pos.x = 15-3; gcd[5].gd.pos.y = 85-3; |
| 400 |
gcd[5].gd.pos.width = -1; gcd[5].gd.pos.height = 0; |
| 401 |
gcd[5].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 402 |
label[5].text = (unichar_t *) _("_OK"); |
| 403 |
label[5].text_is_1byte = true; |
| 404 |
label[5].text_in_resource = true; |
| 405 |
gcd[5].gd.mnemonic = 'O'; |
| 406 |
gcd[5].gd.label = &label[5]; |
| 407 |
gcd[5].gd.handle_controlevent = IF_OK; |
| 408 |
gcd[5].creator = GButtonCreate; |
| 409 |
|
| 410 |
gcd[6].gd.pos.x = -15; gcd[6].gd.pos.y = 85; |
| 411 |
gcd[6].gd.pos.width = -1; gcd[6].gd.pos.height = 0; |
| 412 |
gcd[6].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 413 |
label[6].text = (unichar_t *) _("_Cancel"); |
| 414 |
label[6].text_is_1byte = true; |
| 415 |
label[6].text_in_resource = true; |
| 416 |
gcd[6].gd.label = &label[6]; |
| 417 |
gcd[6].gd.mnemonic = 'C'; |
| 418 |
gcd[6].gd.handle_controlevent = MF_Cancel; |
| 419 |
gcd[6].creator = GButtonCreate; |
| 420 |
|
| 421 |
GGadgetsCreate(gw,gcd); |
| 422 |
|
| 423 |
memset(&d,'\0',sizeof(d)); |
| 424 |
d.other = gcd[1].ret; |
| 425 |
d.fv = fv; |
| 426 |
|
| 427 |
GDrawSetVisible(gw,true); |
| 428 |
while ( !d.done ) |
| 429 |
GDrawProcessOneEvent(NULL); |
| 430 |
GDrawDestroyWindow(gw); |
| 431 |
TFFree(gcd[1].gd.u.list); |
| 432 |
} |