| 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 "bvedit.h" |
| 31 |
#include "cvimages.h" |
| 32 |
#include "cvundoes.h" |
| 33 |
#include "fontforgeui.h" |
| 34 |
#include "fvimportbdf.h" |
| 35 |
#include "gkeysym.h" |
| 36 |
#include "sd.h" |
| 37 |
#include "spiro.h" |
| 38 |
#include "splinefill.h" |
| 39 |
#include "ustring.h" |
| 40 |
#include "utype.h" |
| 41 |
|
| 42 |
#include <dirent.h> |
| 43 |
#include <math.h> |
| 44 |
#include <sys/types.h> |
| 45 |
|
| 46 |
#define CID_AccTar 1000 |
| 47 |
#define CID_JoinLimitVal 1001 |
| 48 |
|
| 49 |
static void ImportPS(CharView *cv,char *path,ImportParams *ip) { |
| 50 |
FILE *ps = fopen(path,"r"); |
| 51 |
|
| 52 |
if ( ps==NULL ) |
| 53 |
return; |
| 54 |
SCImportPSFile(cv->b.sc,CVLayer((CharViewBase *) cv),ps,false,ip); |
| 55 |
fclose(ps); |
| 56 |
} |
| 57 |
|
| 58 |
static void ImportPDF(CharView *cv,char *path,ImportParams *ip) { |
| 59 |
FILE *pdf = fopen(path,"r"); |
| 60 |
|
| 61 |
if ( pdf==NULL ) |
| 62 |
return; |
| 63 |
SCImportPDFFile(cv->b.sc,CVLayer((CharViewBase *) cv),pdf,false,ip); |
| 64 |
fclose(pdf); |
| 65 |
} |
| 66 |
|
| 67 |
static void ImportPlate(CharView *cv,char *path,ImportParams *ip) { |
| 68 |
FILE *plate = fopen(path,"r"); |
| 69 |
|
| 70 |
if ( plate==NULL ) |
| 71 |
return; |
| 72 |
SCImportPlateFile(cv->b.sc,CVLayer((CharViewBase *) cv),plate,false,ip); |
| 73 |
fclose(plate); |
| 74 |
} |
| 75 |
|
| 76 |
static void ImportSVG(CharView *cv,char *path,ImportParams *ip) { |
| 77 |
SCImportSVG(cv->b.sc,CVLayer((CharViewBase *) cv),path,NULL,0,false,ip); |
| 78 |
} |
| 79 |
|
| 80 |
static void ImportGlif(CharView *cv,char *path,ImportParams *ip) { |
| 81 |
SCImportGlif(cv->b.sc,CVLayer((CharViewBase *) cv),path,NULL,0,false,ip); |
| 82 |
} |
| 83 |
|
| 84 |
static void ImportFig(CharView *cv,char *path,ImportParams *ip) { |
| 85 |
SCImportFig(cv->b.sc,CVLayer((CharViewBase *) cv),path,false,ip); |
| 86 |
} |
| 87 |
|
| 88 |
static void ImportImage(CharView *cv,char *path,ImportParams *ip) { |
| 89 |
GImage *image; |
| 90 |
int layer; |
| 91 |
|
| 92 |
image = GImageRead(path); |
| 93 |
if ( image==NULL ) { |
| 94 |
ff_post_error(_("Bad image file"),_("Bad image file: %.100s"), path); |
| 95 |
return; |
| 96 |
} |
| 97 |
layer = ly_back; |
| 98 |
if ( cv->b.drawmode!=dm_grid ) { |
| 99 |
if ( cv->b.sc->parent->multilayer ) |
| 100 |
layer = cv->b.drawmode-dm_back + ly_back; |
| 101 |
else if ( cv->b.layerheads[cv->b.drawmode]->background ) |
| 102 |
layer = CVLayer( (CharViewBase *) cv); |
| 103 |
} |
| 104 |
SCAddScaleImage(cv->b.sc,image,false,layer,ip); |
| 105 |
} |
| 106 |
|
| 107 |
static int BVImportImage(BitmapView *bv,char *path) { |
| 108 |
GImage *image; |
| 109 |
struct _GImage *base; |
| 110 |
int tot; |
| 111 |
uint8_t *pt, *end; |
| 112 |
BDFChar *bc = bv->bc; |
| 113 |
int i, j; |
| 114 |
|
| 115 |
image = GImageRead(path); |
| 116 |
if ( image==NULL ) { |
| 117 |
ff_post_error(_("Bad image file"),_("Bad image file: %.100s"), path); |
| 118 |
return(false); |
| 119 |
} |
| 120 |
base = image->list_len==0?image->u.image:image->u.images[0]; |
| 121 |
BCPreserveState(bc); |
| 122 |
BCFlattenFloat(bc); |
| 123 |
free(bc->bitmap); |
| 124 |
bc->xmin = bc->ymin = 0; |
| 125 |
bc->xmax = base->width-1; bc->ymax = base->height-1; |
| 126 |
if ( !bc->byte_data && base->image_type==it_mono ) { |
| 127 |
bc->bitmap = base->data; |
| 128 |
bc->bytes_per_line = base->bytes_per_line; |
| 129 |
|
| 130 |
|
| 131 |
tot = bc->bytes_per_line*(bc->ymax-bc->ymin+1); |
| 132 |
for ( pt = bc->bitmap, end = pt+tot; pt<end; *pt++ ^= 0xff ); |
| 133 |
|
| 134 |
base->data = NULL; |
| 135 |
} else if ( base->image_type==it_mono ) { |
| 136 |
int set = (1<<BDFDepth(bv->bdf))-1; |
| 137 |
bc->bytes_per_line = base->width; |
| 138 |
bc->bitmap = calloc(base->height,base->width); |
| 139 |
for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) { |
| 140 |
if ( !(base->data[i*base->bytes_per_line+(j>>3)]&(0x80>>(j&7))) ) |
| 141 |
bc->bitmap[i*bc->bytes_per_line+j] = set; |
| 142 |
} |
| 143 |
} else if ( !bc->byte_data && base->image_type==it_true ) { |
| 144 |
bc->bytes_per_line = (base->width>>3)+1; |
| 145 |
bc->bitmap = calloc(base->height,bc->bytes_per_line); |
| 146 |
for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) { |
| 147 |
int col = ((Color *) (base->data+i*base->bytes_per_line))[j]; |
| 148 |
col = (3*COLOR_RED(col)+6*COLOR_GREEN(col)+COLOR_BLUE(col)); |
| 149 |
if ( col<=5*256 ) |
| 150 |
bc->bitmap[i*bc->bytes_per_line+(j>>3)] |= (0x80>>(j&7)); |
| 151 |
} |
| 152 |
} else if ( base->image_type==it_true ) { |
| 153 |
int div = 255/((1<<BDFDepth(bv->bdf))-1); |
| 154 |
bc->bytes_per_line = base->width; |
| 155 |
bc->bitmap = calloc(base->height,base->width); |
| 156 |
for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) { |
| 157 |
int col = ((Color *) (base->data+i*base->bytes_per_line))[j]; |
| 158 |
col = 255-(3*COLOR_RED(col)+6*COLOR_GREEN(col)+COLOR_BLUE(col)+5)/10; |
| 159 |
bc->bitmap[i*bc->bytes_per_line+j] = col/div; |
| 160 |
} |
| 161 |
} else if ( bc->byte_data ) { |
| 162 |
int div = 255/((1<<BDFDepth(bv->bdf))-1); |
| 163 |
bc->bitmap = base->data; |
| 164 |
bc->bytes_per_line = base->bytes_per_line; |
| 165 |
for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) { |
| 166 |
int col = base->clut->clut[base->data[i*base->bytes_per_line+j]]; |
| 167 |
col = 255-(3*COLOR_RED(col)+6*COLOR_GREEN(col)+COLOR_BLUE(col)+5)/10; |
| 168 |
base->data[i*base->bytes_per_line+j] = col/div; |
| 169 |
} |
| 170 |
base->data = NULL; |
| 171 |
} else { |
| 172 |
bc->bytes_per_line = (base->width>>3)+1; |
| 173 |
bc->bitmap = calloc(base->height,bc->bytes_per_line); |
| 174 |
for ( i=0; i<base->height; ++i ) for ( j=0; j<base->width; ++j ) { |
| 175 |
int col = base->clut->clut[base->data[i*base->bytes_per_line+j]]; |
| 176 |
col = (3*COLOR_RED(col)+6*COLOR_GREEN(col)+COLOR_BLUE(col)); |
| 177 |
if ( col<=5*256 ) |
| 178 |
bc->bitmap[i*bc->bytes_per_line+(j>>3)] |= (0x80>>(j&7)); |
| 179 |
} |
| 180 |
} |
| 181 |
GImageDestroy(image); |
| 182 |
if ( bc->sc!=NULL ) |
| 183 |
bc->sc->widthset = true; |
| 184 |
BCCharChangedUpdate(bc); |
| 185 |
return( true ); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
static unichar_t wildimg[] = { '*', '.', '{', |
| 190 |
#ifndef _NO_LIBUNGIF |
| 191 |
'g','i','f',',', |
| 192 |
#endif |
| 193 |
#ifndef _NO_LIBPNG |
| 194 |
'p','n','g',',', |
| 195 |
#endif |
| 196 |
#ifndef _NO_LIBTIFF |
| 197 |
't','i','f','f',',', |
| 198 |
't','i','f',',', |
| 199 |
#endif |
| 200 |
#ifndef _NO_LIBJPEG |
| 201 |
'j','p','e','g',',', |
| 202 |
'j','p','g',',', |
| 203 |
#endif |
| 204 |
'x','p','m',',', 'x','b','m',',', 'b','m','p', '}', '\0' }; |
| 205 |
static unichar_t wildtemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', '{', |
| 206 |
#ifndef _NO_LIBUNGIF |
| 207 |
'g','i','f',',', |
| 208 |
#endif |
| 209 |
#ifndef _NO_LIBPNG |
| 210 |
'p','n','g',',', |
| 211 |
#endif |
| 212 |
#ifndef _NO_LIBTIFF |
| 213 |
't','i','f','f',',', |
| 214 |
't','i','f',',', |
| 215 |
#endif |
| 216 |
'x','p','m',',', 'x','b','m',',', 'b','m','p', '}', '\0' }; |
| 217 |
|
| 218 |
static unichar_t wildepstemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', '{', 'p','s',',', 'e','p','s',',','a','r','t','}', 0 }; |
| 219 |
static unichar_t wildpdftemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', 'p', 'd','f', 0 }; |
| 220 |
static unichar_t wildsvgtemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', 's', 'v','g', 0 }; |
| 221 |
static unichar_t wildgliftemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', 'g', 'l','i','f', 0 }; |
| 222 |
static unichar_t wildplatetemplate[] = { '{','u','n','i',',','u',',','c','i','d',',','e','n','c','}','[','0','-','9','a','-','f','A','-','F',']','*', '.', 'p','l','a','t','e', 0 }; |
| 223 |
static unichar_t wildps[] = { '*', '.', '{', 'p','s',',', 'e','p','s',',', 'a','r','t','}', '\0' }; |
| 224 |
static unichar_t wildpdf[] = { '*', '.', 'p','d','f', '\0' }; |
| 225 |
static unichar_t wildsvg[] = { '*', '.', 's','v','g', '\0' }; |
| 226 |
static unichar_t wildplate[] = { '*', '.', 'p','l','a','t','e', '\0' }; |
| 227 |
static unichar_t wildglif[] = { '*', '.', 'g','l','i','f', '\0' }; |
| 228 |
static unichar_t wildfig[] = { '*', '.', '{', 'f','i','g',',','x','f','i','g','}', '\0' }; |
| 229 |
static unichar_t wildbdf[] = { '*', '.', 'b', 'd','{', 'f', ',','f','.','g','z',',','f','.','Z',',','f','.','b','z','2','}', '\0' }; |
| 230 |
static unichar_t wildpcf[] = { '*', '.', 'p', '{', 'c',',','m','}','{', 'f', ',','f','.','g','z',',','f','.','Z',',','f','.','b','z','2','}', '\0' }; |
| 231 |
static unichar_t wildttf[] = { '*', '.', '{', 't', 't','f',',','o','t','f',',','o','t','b',',','t','t','c','}', '\0' }; |
| 232 |
static unichar_t wildpk[] = { '*', '{', 'p', 'k', ',', 'g', 'f', '}', '\0' }; |
| 233 |
static unichar_t wildmac[] = { '*', '{', 'b', 'i', 'n', ',', 'h', 'q', 'x', ',', 'd','f','o','n','t', '}', '\0' }; |
| 234 |
static unichar_t wildwin[] = { '*', '{', 'f', 'o', 'n', ',', 'f', 'n', 't', '}', '\0' }; |
| 235 |
static unichar_t wildpalm[] = { '*', 'p', 'd', 'b', '\0' }; |
| 236 |
|
| 237 |
static unichar_t *wildfmt[] = { wildbdf, wildttf, wildpk, wildpcf, wildmac, |
| 238 |
wildwin, wildpalm, |
| 239 |
wildimg, wildtemplate, wildps, wildepstemplate, |
| 240 |
wildpdf, wildpdftemplate, |
| 241 |
wildplate, wildplatetemplate, |
| 242 |
wildsvg, wildsvgtemplate, |
| 243 |
wildglif, wildgliftemplate, |
| 244 |
wildfig |
| 245 |
}; |
| 246 |
|
| 247 |
static int IMPP_OK(GGadget *g, GEvent *e) { |
| 248 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) |
| 249 |
*(int *) GDrawGetUserData(GGadgetGetWindow(g)) = true; |
| 250 |
return( true ); |
| 251 |
} |
| 252 |
|
| 253 |
static int impp_e_h(GWindow gw, GEvent *event) { |
| 254 |
if ( event->type==et_close ) { |
| 255 |
*(int *) GDrawGetUserData(gw) = true; |
| 256 |
} else if ( event->type == et_char ) { |
| 257 |
if ( event->u.chr.keysym == GK_F1 || event->u.chr.keysym == GK_Help ) { |
| 258 |
help("ui/menus/filemenu.html", "#filemenu-type3-import"); |
| 259 |
return( true ); |
| 260 |
} |
| 261 |
return( false ); |
| 262 |
} |
| 263 |
return( true ); |
| 264 |
} |
| 265 |
|
| 266 |
void _ImportParamsDlg(ImportParams *ip) { |
| 267 |
GRect pos; |
| 268 |
GWindow gw; |
| 269 |
GWindowAttrs wattrs; |
| 270 |
GGadgetCreateData gcd[13], boxes[4], *hvarray[13][4], *barray[10]; |
| 271 |
GTextInfo label[13]; |
| 272 |
char accbuf[20], jlbuf[20]; |
| 273 |
int done = false, err = false; |
| 274 |
int k, he_k, cd_k, si_k, sc_k, cl_k, di_k, al_k; |
| 275 |
|
| 276 |
if ( no_windowing_ui ) |
| 277 |
return; |
| 278 |
|
| 279 |
memset(&wattrs,0,sizeof(wattrs)); |
| 280 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict; |
| 281 |
wattrs.event_masks = ~(1<<et_charup); |
| 282 |
wattrs.restrict_input_to_me = 1; |
| 283 |
wattrs.undercursor = 1; |
| 284 |
wattrs.cursor = ct_pointer; |
| 285 |
wattrs.utf8_window_title = _("Import Parameters"); |
| 286 |
wattrs.is_dlg = true; |
| 287 |
pos.x = pos.y = 0; |
| 288 |
pos.width = GGadgetScale(GDrawPointsToPixels(NULL,200)); |
| 289 |
pos.height = GDrawPointsToPixels(NULL,200); |
| 290 |
gw = GDrawCreateTopWindow(NULL,&pos,impp_e_h,&done,&wattrs); |
| 291 |
|
| 292 |
memset(&label,0,sizeof(label)); |
| 293 |
memset(&gcd,0,sizeof(gcd)); |
| 294 |
memset(&boxes,0,sizeof(boxes)); |
| 295 |
|
| 296 |
k = 0; |
| 297 |
label[k].text = (unichar_t *) _("The following options influence how files are imported.\n" |
| 298 |
"Most are specific to one or more formats."); |
| 299 |
label[k].text_is_1byte = true; |
| 300 |
gcd[k].gd.label = &label[k]; |
| 301 |
gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = 6; |
| 302 |
gcd[k].gd.flags = gg_enabled | gg_visible; |
| 303 |
gcd[k++].creator = GLabelCreate; |
| 304 |
hvarray[0][0] = &gcd[k-1]; |
| 305 |
hvarray[0][1] = GCD_ColSpan; |
| 306 |
hvarray[0][2] = GCD_ColSpan; |
| 307 |
hvarray[0][3] = NULL; |
| 308 |
|
| 309 |
cd_k = k; |
| 310 |
label[k].text = (unichar_t *) _("_Correct Direction (PS/EPS)"); |
| 311 |
label[k].text_is_1byte = true; |
| 312 |
label[k].text_in_resource = true; |
| 313 |
gcd[k].gd.label = &label[k]; |
| 314 |
gcd[k].gd.pos.x = gcd[k-1].gd.pos.x; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+15; |
| 315 |
gcd[k].gd.flags = gg_enabled | gg_visible | (ip->correct_direction?gg_cb_on:0); |
| 316 |
gcd[k++].creator = GCheckBoxCreate; |
| 317 |
hvarray[1][0] = &gcd[k-1]; |
| 318 |
hvarray[1][1] = GCD_ColSpan; |
| 319 |
hvarray[1][2] = GCD_ColSpan; |
| 320 |
hvarray[1][3] = NULL; |
| 321 |
|
| 322 |
he_k = k; |
| 323 |
label[k].text = (unichar_t *) _("Handle Erasers (PS/EPS)"); |
| 324 |
label[k].text_is_1byte = true; |
| 325 |
gcd[k].gd.label = &label[k]; |
| 326 |
gcd[k].gd.pos.x = gcd[k-1].gd.pos.x; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+15; |
| 327 |
gcd[k].gd.flags = gg_enabled | gg_visible| |
| 328 |
(ip->erasers?gg_cb_on:0); |
| 329 |
gcd[k].gd.popup_msg = _("Certain programs use pens with white ink as erasers\nThis option attempts to simulate that effect."); |
| 330 |
gcd[k++].creator = GCheckBoxCreate; |
| 331 |
hvarray[2][0] = &gcd[k-1]; |
| 332 |
hvarray[2][1] = GCD_ColSpan; |
| 333 |
hvarray[2][2] = GCD_ColSpan; |
| 334 |
hvarray[2][3] = NULL; |
| 335 |
|
| 336 |
si_k = k; |
| 337 |
label[k].text = (unichar_t *) _("Simplify Stroke (SVG/PS/EPS)"); |
| 338 |
label[k].text_is_1byte = true; |
| 339 |
gcd[k].gd.label = &label[k]; |
| 340 |
gcd[k].gd.pos.x = gcd[k-1].gd.pos.x; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+15; |
| 341 |
gcd[k].gd.flags = gg_enabled | gg_visible| |
| 342 |
(ip->simplify?gg_cb_on:0); |
| 343 |
gcd[k].gd.popup_msg = _("Run Simplify after expanding stroked paths\nto reduce the number of points."); |
| 344 |
gcd[k++].creator = GCheckBoxCreate; |
| 345 |
hvarray[3][0] = &gcd[k-1]; |
| 346 |
hvarray[3][1] = GCD_ColSpan; |
| 347 |
hvarray[3][2] = GCD_ColSpan; |
| 348 |
hvarray[3][3] = NULL; |
| 349 |
|
| 350 |
cl_k = k; |
| 351 |
label[k].text = (unichar_t *) _("Use Clip-paths (SVG)"); |
| 352 |
label[k].text_is_1byte = true; |
| 353 |
gcd[k].gd.label = &label[k]; |
| 354 |
gcd[k].gd.pos.x = gcd[k-1].gd.pos.x; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+15; |
| 355 |
gcd[k].gd.flags = gg_visible| |
| 356 |
(ip->clip?gg_cb_on:0); |
| 357 |
gcd[k++].creator = GCheckBoxCreate; |
| 358 |
hvarray[4][0] = &gcd[k-1]; |
| 359 |
hvarray[4][1] = GCD_ColSpan; |
| 360 |
hvarray[4][2] = GCD_ColSpan; |
| 361 |
hvarray[4][3] = NULL; |
| 362 |
|
| 363 |
sc_k = k; |
| 364 |
label[k].text = (unichar_t *) _("Scale to fit (Misc)"); |
| 365 |
label[k].text_is_1byte = true; |
| 366 |
gcd[k].gd.label = &label[k]; |
| 367 |
gcd[k].gd.pos.x = gcd[k-1].gd.pos.x; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+15; |
| 368 |
gcd[k].gd.flags = gg_enabled | gg_visible| |
| 369 |
(ip->scale?gg_cb_on:0); |
| 370 |
gcd[k++].creator = GCheckBoxCreate; |
| 371 |
hvarray[5][0] = &gcd[k-1]; |
| 372 |
hvarray[5][1] = GCD_ColSpan; |
| 373 |
hvarray[5][2] = GCD_ColSpan; |
| 374 |
hvarray[5][3] = NULL; |
| 375 |
|
| 376 |
di_k = k; |
| 377 |
label[k].text = (unichar_t *) _("Infer glyph width (Misc)"); |
| 378 |
label[k].text_is_1byte = true; |
| 379 |
gcd[k].gd.label = &label[k]; |
| 380 |
gcd[k].gd.pos.x = gcd[k-1].gd.pos.x; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+15; |
| 381 |
gcd[k].gd.flags = gg_enabled | gg_visible| |
| 382 |
(ip->dimensions?gg_cb_on:0); |
| 383 |
gcd[k++].creator = GCheckBoxCreate; |
| 384 |
hvarray[6][0] = &gcd[k-1]; |
| 385 |
hvarray[6][1] = GCD_ColSpan; |
| 386 |
hvarray[6][2] = GCD_ColSpan; |
| 387 |
hvarray[6][3] = NULL; |
| 388 |
|
| 389 |
label[k].text = (unichar_t *) _("Default Join Limit (PS/EPS/SVG):"); |
| 390 |
label[k].text_is_1byte = true; |
| 391 |
label[k].text_in_resource = true; |
| 392 |
gcd[k].gd.label = &label[k]; |
| 393 |
gcd[k].gd.flags = gg_visible | gg_enabled; |
| 394 |
gcd[k++].creator = GLabelCreate; |
| 395 |
hvarray[7][0] = &gcd[k-1]; |
| 396 |
|
| 397 |
sprintf( jlbuf, "%g", (double) (ip->default_joinlimit) ); |
| 398 |
label[k].text = (unichar_t *) jlbuf; |
| 399 |
label[k].text_is_1byte = true; |
| 400 |
gcd[k].gd.label = &label[k]; |
| 401 |
gcd[k].gd.cid = CID_JoinLimitVal; |
| 402 |
gcd[k].gd.flags = gg_visible | gg_enabled; |
| 403 |
gcd[k].gd.popup_msg = _( |
| 404 |
"The length limit for Miter and Arcs joins in units\n" |
| 405 |
"of 1/2 stroke-width. Set to -1 to use the format-\n" |
| 406 |
"specific limits of 10.0 for PostScript and 4.0 for SVG."); |
| 407 |
gcd[k++].creator = GTextFieldCreate; |
| 408 |
hvarray[7][1] = &gcd[k-1]; |
| 409 |
hvarray[7][2] = GCD_Glue; |
| 410 |
hvarray[7][3] = NULL; |
| 411 |
|
| 412 |
label[k].text = (unichar_t *) _("Accuracy _Target:"); |
| 413 |
label[k].text_is_1byte = true; |
| 414 |
label[k].text_in_resource = true; |
| 415 |
gcd[k].gd.label = &label[k]; |
| 416 |
gcd[k].gd.flags = gg_visible | gg_enabled; |
| 417 |
gcd[k++].creator = GLabelCreate; |
| 418 |
hvarray[8][0] = &gcd[k-1]; |
| 419 |
|
| 420 |
sprintf( accbuf, "%g", (double) (ip->accuracy_target) ); |
| 421 |
label[k].text = (unichar_t *) accbuf; |
| 422 |
label[k].text_is_1byte = true; |
| 423 |
gcd[k].gd.label = &label[k]; |
| 424 |
gcd[k].gd.cid = CID_AccTar; |
| 425 |
gcd[k].gd.flags = gg_visible | gg_enabled; |
| 426 |
gcd[k].gd.popup_msg = _( |
| 427 |
"The Expand Stroke algorithm will attempt to be (at\n" |
| 428 |
"least) this accurate, but there may be exceptions."); |
| 429 |
gcd[k++].creator = GTextFieldCreate; |
| 430 |
hvarray[8][1] = &gcd[k-1]; |
| 431 |
hvarray[8][2] = GCD_Glue; |
| 432 |
hvarray[8][3] = NULL; |
| 433 |
|
| 434 |
al_k = k; |
| 435 |
label[k].text = (unichar_t *) _("_Always raise this dialog when importing"); |
| 436 |
label[k].text_is_1byte = true; |
| 437 |
label[k].text_in_resource = true; |
| 438 |
gcd[k].gd.label = &label[k]; |
| 439 |
gcd[k].gd.flags = gg_enabled | gg_visible | (ip->show_always?gg_cb_on:0); |
| 440 |
gcd[k++].creator = GCheckBoxCreate; |
| 441 |
hvarray[9][0] = &gcd[k-1]; |
| 442 |
hvarray[9][1] = GCD_ColSpan; |
| 443 |
hvarray[9][2] = GCD_ColSpan; |
| 444 |
hvarray[9][3] = NULL; |
| 445 |
|
| 446 |
gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 447 |
label[k].text = (unichar_t *) _("_OK"); |
| 448 |
label[k].text_is_1byte = true; |
| 449 |
label[k].text_in_resource = true; |
| 450 |
gcd[k].gd.label = &label[k]; |
| 451 |
gcd[k].gd.handle_controlevent = IMPP_OK; |
| 452 |
gcd[k++].creator = GButtonCreate; |
| 453 |
barray[0] = GCD_Glue; |
| 454 |
barray[1] = &gcd[k-1]; |
| 455 |
barray[2] = GCD_Glue; |
| 456 |
barray[3] = NULL; |
| 457 |
|
| 458 |
boxes[2].gd.flags = gg_enabled | gg_visible; |
| 459 |
boxes[2].gd.u.boxelements = barray; |
| 460 |
boxes[2].creator = GHBoxCreate; |
| 461 |
hvarray[10][0] = GCD_Glue; |
| 462 |
hvarray[10][1] = GCD_ColSpan; |
| 463 |
hvarray[10][2] = GCD_ColSpan; |
| 464 |
hvarray[10][3] = NULL; |
| 465 |
hvarray[11][0] = &boxes[2]; |
| 466 |
hvarray[11][1] = GCD_ColSpan; |
| 467 |
hvarray[11][2] = GCD_ColSpan; |
| 468 |
hvarray[11][3] = NULL; |
| 469 |
hvarray[12][0] = NULL; |
| 470 |
|
| 471 |
boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2; |
| 472 |
boxes[0].gd.flags = gg_enabled | gg_visible; |
| 473 |
boxes[0].gd.u.boxelements = hvarray[0]; |
| 474 |
boxes[0].creator = GHVGroupCreate; |
| 475 |
|
| 476 |
GGadgetsCreate(gw,boxes); |
| 477 |
GHVBoxSetExpandableRow(boxes[0].ret,gb_expandglue); |
| 478 |
GHVBoxSetExpandableCol(boxes[2].ret,gb_expandgluesame); |
| 479 |
GHVBoxFitWindow(boxes[0].ret); |
| 480 |
|
| 481 |
GDrawSetVisible(gw,true); |
| 482 |
|
| 483 |
while ( !done ) |
| 484 |
GDrawProcessOneEvent(NULL); |
| 485 |
|
| 486 |
ip->correct_direction = GGadgetIsChecked(gcd[cd_k].ret); |
| 487 |
ip->erasers = GGadgetIsChecked(gcd[he_k].ret); |
| 488 |
ip->simplify = GGadgetIsChecked(gcd[si_k].ret); |
| 489 |
ip->clip = GGadgetIsChecked(gcd[cl_k].ret); |
| 490 |
ip->scale = GGadgetIsChecked(gcd[sc_k].ret); |
| 491 |
ip->dimensions = GGadgetIsChecked(gcd[di_k].ret); |
| 492 |
ip->default_joinlimit = GetReal8(gw,CID_JoinLimitVal,_("Default Join Limit (PS/EPS/SVG):"),&err); |
| 493 |
if ( err ) { |
| 494 |
ip->default_joinlimit = JLIMIT_INHERITED; |
| 495 |
err = false; |
| 496 |
} |
| 497 |
ip->accuracy_target = GetReal8(gw,CID_AccTar,_("Accuracy Target:"),&err); |
| 498 |
if ( err ) |
| 499 |
ip->accuracy_target = 0.25; |
| 500 |
ip->show_always = GGadgetIsChecked(gcd[al_k].ret); |
| 501 |
|
| 502 |
GDrawDestroyWindow(gw); |
| 503 |
} |
| 504 |
|
| 505 |
static void ShowImportOptions(ImportParams *ip, int shown, |
| 506 |
enum shown_params type) { |
| 507 |
if ( !shown && (!(ip->shown_mask & type) || ip->show_always) ) |
| 508 |
_ImportParamsDlg(ip); |
| 509 |
ip->shown_mask |= type; |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
static int last_format, flast_format, last_lpos, flast_lpos; |
| 515 |
struct gfc_data { |
| 516 |
int done; |
| 517 |
int ret; |
| 518 |
int opts_shown; |
| 519 |
GGadget *gfc; |
| 520 |
GGadget *format; |
| 521 |
GGadget *background; |
| 522 |
CharView *cv; |
| 523 |
BitmapView *bv; |
| 524 |
FontView *fv; |
| 525 |
}; |
| 526 |
|
| 527 |
static GTextInfo formats[] = { |
| 528 |
{ (unichar_t *) N_("Image"), NULL, 0, 0, (void *) fv_image, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 529 |
{ (unichar_t *) N_("EPS"), NULL, 0, 0, (void *) fv_eps, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 530 |
{ (unichar_t *) N_("PDF page graphics"), NULL, 0, 0, (void *) fv_pdf, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 531 |
{ (unichar_t *) N_("SVG"), NULL, 0, 0, (void *) fv_svg, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 532 |
{ (unichar_t *) N_("Glif"), NULL, 0, 0, (void *) fv_glif, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 533 |
{ (unichar_t *) N_("Raph's plate files"), NULL, 0, 0, (void *) fv_plate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 534 |
{ (unichar_t *) N_("XFig"), NULL, 0, 0, (void *) fv_fig, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 535 |
GTEXTINFO_EMPTY |
| 536 |
}; |
| 537 |
|
| 538 |
static GTextInfo fvformats[] = { |
| 539 |
{ (unichar_t *) N_("BDF"), NULL, 0, 0, (void *) fv_bdf, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, '\0' }, |
| 540 |
{ (unichar_t *) N_("TTF"), NULL, 0, 0, (void *) fv_ttf, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 541 |
{ (unichar_t *) NU_("΀ΔΧ Bitmap Fonts"), NULL, 0, 0, (void *) fv_pk, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 542 |
{ (unichar_t *) N_("PCF (pmf)"), NULL, 0, 0, (void *) fv_pcf, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 543 |
{ (unichar_t *) N_("Mac Bitmap"), NULL, 0, 0, (void *) fv_mac, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 544 |
{ (unichar_t *) N_("Win FON"), NULL, 0, 0, (void *) fv_win, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 545 |
{ (unichar_t *) N_("palm"), NULL, 0, 0, (void *) fv_palm, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 546 |
{ (unichar_t *) N_("Image"), NULL, 0, 0, (void *) fv_image, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 547 |
{ (unichar_t *) N_("Image Template"), NULL, 0, 0, (void *) fv_imgtemplate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 548 |
{ (unichar_t *) N_("EPS"), NULL, 0, 0, (void *) fv_eps, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 549 |
{ (unichar_t *) N_("EPS Template"), NULL, 0, 0, (void *) fv_epstemplate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 550 |
{ (unichar_t *) N_("PDF page graphics"), NULL, 0, 0, (void *) fv_pdf, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 551 |
{ (unichar_t *) N_("SVG"), NULL, 0, 0, (void *) fv_svg, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 552 |
{ (unichar_t *) N_("SVG Template"), NULL, 0, 0, (void *) fv_svgtemplate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 553 |
{ (unichar_t *) N_("Glif"), NULL, 0, 0, (void *) fv_glif, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 554 |
{ (unichar_t *) N_("Glif Template"), NULL, 0, 0, (void *) fv_gliftemplate, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, |
| 555 |
GTEXTINFO_EMPTY |
| 556 |
}; |
| 557 |
|
| 558 |
static int GFD_ImportOk(GGadget *g, GEvent *e) { |
| 559 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 560 |
struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 561 |
unichar_t *ret = GGadgetGetTitle(d->gfc); |
| 562 |
char *temp = u2def_copy(ret); |
| 563 |
int lpos = GGadgetGetFirstListSelectedItem(d->format); |
| 564 |
int format = (intptr_t) (GGadgetGetListItemSelected(d->format)->userdata); |
| 565 |
GGadget *tf; |
| 566 |
|
| 567 |
ImportParams *ip = ImportParamsState(); |
| 568 |
|
| 569 |
GFileChooserGetChildren(d->gfc,NULL,NULL,&tf); |
| 570 |
if ( *_GGadgetGetTitle(tf)=='\0' || !temp) |
| 571 |
return( true ); |
| 572 |
GDrawSetCursor(GGadgetGetWindow(g),ct_watch); |
| 573 |
if ( d->fv!=NULL ) { |
| 574 |
flast_format = format; |
| 575 |
flast_lpos = lpos; |
| 576 |
} else { |
| 577 |
last_format = format; |
| 578 |
last_lpos = lpos; |
| 579 |
} |
| 580 |
free(ret); |
| 581 |
if ( d->fv!=NULL ) { |
| 582 |
char** path_list = GFileChooserGetMultipleFiles(temp); |
| 583 |
int toback = GGadgetIsChecked(d->background); |
| 584 |
if ( toback && path_list[1]!=NULL && format<3 ) |
| 585 |
ff_post_error(_("Only One Font"),_("Only one font may be imported into the background")); |
| 586 |
else if ( format==fv_bdf ) |
| 587 |
d->done = FVImportBDFs((FontViewBase *) d->fv,path_list,false, toback); |
| 588 |
else if ( format==fv_ttf ) |
| 589 |
d->done = FVImportMult((FontViewBase *) d->fv,temp,toback,bf_ttf); |
| 590 |
else if ( format==fv_pk ) |
| 591 |
d->done = FVImportBDFs((FontViewBase *) d->fv,path_list,true, toback); |
| 592 |
else if ( format==fv_pcf ) |
| 593 |
d->done = FVImportBDFs((FontViewBase *) d->fv,path_list,2, toback); |
| 594 |
else if ( format==fv_mac ) |
| 595 |
d->done = FVImportMult((FontViewBase *) d->fv,temp,toback,bf_nfntmacbin); |
| 596 |
else if ( format==fv_win ) |
| 597 |
d->done = FVImportMult((FontViewBase *) d->fv,temp,toback,bf_fon); |
| 598 |
else if ( format==fv_palm ) |
| 599 |
d->done = FVImportMult((FontViewBase *) d->fv,temp,toback,bf_palm); |
| 600 |
else if ( format==fv_image ) { |
| 601 |
ShowImportOptions(ip, d->opts_shown, sp_scale); |
| 602 |
d->done = FVImportImages((FontViewBase *) d->fv,path_list,format,toback,true,ip); |
| 603 |
} else if ( format==fv_imgtemplate ) { |
| 604 |
ShowImportOptions(ip, d->opts_shown, sp_scale); |
| 605 |
d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,true,ip); |
| 606 |
} else if ( format==fv_eps ) { |
| 607 |
ShowImportOptions(ip, d->opts_shown, sp_eps); |
| 608 |
d->done = FVImportImages((FontViewBase *) d->fv,path_list,format,toback,true,ip); |
| 609 |
} else if ( format==fv_epstemplate ) { |
| 610 |
ShowImportOptions(ip, d->opts_shown, sp_eps); |
| 611 |
d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,true,ip); |
| 612 |
} else if ( format==fv_pdf ) { |
| 613 |
ShowImportOptions(ip, d->opts_shown, sp_eps); |
| 614 |
d->done = FVImportImages((FontViewBase *) d->fv,path_list,format,toback,true,ip); |
| 615 |
} else if ( format==fv_pdftemplate ) { |
| 616 |
ShowImportOptions(ip, d->opts_shown, sp_eps); |
| 617 |
d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,true,ip); |
| 618 |
} else if ( format==fv_svg ) { |
| 619 |
ShowImportOptions(ip, d->opts_shown, sp_svg); |
| 620 |
d->done = FVImportImages((FontViewBase *) d->fv,path_list,format,toback,true,ip); |
| 621 |
} else if ( format==fv_svgtemplate ) { |
| 622 |
ShowImportOptions(ip, d->opts_shown, sp_svg); |
| 623 |
d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,true,ip); |
| 624 |
} else if ( format==fv_glif ) |
| 625 |
d->done = FVImportImages((FontViewBase *) d->fv,path_list,format,toback,true,ip); |
| 626 |
else if ( format==fv_gliftemplate ) |
| 627 |
d->done = FVImportImageTemplate((FontViewBase *) d->fv,temp,format,toback,true,ip); |
| 628 |
else if ( format>=fv_pythonbase ) |
| 629 |
d->done = FVImportImages((FontViewBase *) d->fv,path_list,format,toback,true,ip); |
| 630 |
|
| 631 |
for (char** p_path = path_list; *p_path != NULL; ++p_path) |
| 632 |
free(*p_path); |
| 633 |
free(path_list); |
| 634 |
} else if ( d->bv!=NULL ) |
| 635 |
d->done = BVImportImage(d->bv,temp); |
| 636 |
else { |
| 637 |
d->done = true; |
| 638 |
if ( format==fv_image ) { |
| 639 |
ShowImportOptions(ip, d->opts_shown, sp_scale); |
| 640 |
ImportImage(d->cv,temp,ip); |
| 641 |
} else if ( format==fv_eps ) { |
| 642 |
ShowImportOptions(ip, d->opts_shown, sp_eps); |
| 643 |
ImportPS(d->cv,temp,ip); |
| 644 |
} else if ( format==fv_pdf ) { |
| 645 |
ShowImportOptions(ip, d->opts_shown, sp_eps); |
| 646 |
ImportPDF(d->cv,temp,ip); |
| 647 |
} else if ( format==fv_plate ) |
| 648 |
ImportPlate(d->cv,temp,ip); |
| 649 |
else if ( format==fv_svg ) { |
| 650 |
ShowImportOptions(ip, d->opts_shown, sp_svg); |
| 651 |
ImportSVG(d->cv,temp,ip); |
| 652 |
} else if ( format==fv_glif ) |
| 653 |
ImportGlif(d->cv,temp,ip); |
| 654 |
else if ( format==fv_fig ) { |
| 655 |
ImportFig(d->cv,temp,ip); |
| 656 |
} |
| 657 |
#ifndef _NO_PYTHON |
| 658 |
else if ( format>=fv_pythonbase ) |
| 659 |
PyFF_SCImport(d->cv->b.sc,format-fv_pythonbase,temp, |
| 660 |
CVLayer((CharViewBase *) d->cv), false); |
| 661 |
#endif |
| 662 |
} |
| 663 |
free(temp); |
| 664 |
GDrawSetCursor(GGadgetGetWindow(g),ct_pointer); |
| 665 |
} |
| 666 |
return( true ); |
| 667 |
} |
| 668 |
|
| 669 |
static int GFD_Cancel(GGadget *g, GEvent *e) { |
| 670 |
if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) { |
| 671 |
struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 672 |
d->done = true; |
| 673 |
d->ret = false; |
| 674 |
} |
| 675 |
return( true ); |
| 676 |
} |
| 677 |
|
| 678 |
static int GFD_Format(GGadget *g, GEvent *e) { |
| 679 |
if ( e->type==et_controlevent && e->u.control.subtype == et_listselected ) { |
| 680 |
struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 681 |
int format = (intptr_t) (GGadgetGetListItemSelected(d->format)->userdata); |
| 682 |
if ( format<fv_pythonbase ) |
| 683 |
GFileChooserSetFilterText(d->gfc,wildfmt[format]); |
| 684 |
#ifndef _NO_PYTHON |
| 685 |
else { |
| 686 |
char *text; |
| 687 |
char *ae = py_ie[format-fv_pythonbase].all_extensions; |
| 688 |
unichar_t *utext; |
| 689 |
text = malloc(strlen(ae)+10); |
| 690 |
if ( strchr(ae,',')) |
| 691 |
sprintf( text, "*.{%s}", ae ); |
| 692 |
else |
| 693 |
sprintf( text, "*.%s", ae ); |
| 694 |
utext = utf82u_copy(text); |
| 695 |
GFileChooserSetFilterText(d->gfc,utext); |
| 696 |
free(text); free(utext); |
| 697 |
} |
| 698 |
#endif |
| 699 |
GFileChooserRefreshList(d->gfc); |
| 700 |
if ( d->fv!=NULL ) { |
| 701 |
if ( format==fv_bdf || format==fv_ttf || format==fv_pcf || |
| 702 |
format==fv_mac || format==fv_win ) { |
| 703 |
GGadgetSetChecked(d->background,false); |
| 704 |
GGadgetSetEnabled(d->background,true); |
| 705 |
} else if ( format==fv_pk ) { |
| 706 |
GGadgetSetChecked(d->background,true); |
| 707 |
GGadgetSetEnabled(d->background,true); |
| 708 |
} else if ( format==fv_eps || format==fv_epstemplate || |
| 709 |
format==fv_pdf || format==fv_pdftemplate || |
| 710 |
format==fv_svg || format==fv_svgtemplate || |
| 711 |
format==fv_glif || format==fv_gliftemplate || |
| 712 |
format>=fv_pythonbase ) { |
| 713 |
GGadgetSetChecked(d->background,false); |
| 714 |
GGadgetSetEnabled(d->background,true); |
| 715 |
} else { |
| 716 |
GGadgetSetChecked(d->background,true); |
| 717 |
GGadgetSetEnabled(d->background,true); |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
return( true ); |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
static int GFD_Options(GGadget *g, GEvent *e) { |
| 726 |
if ( e->type==et_controlevent |
| 727 |
&& e->u.control.subtype == et_buttonactivate ) { |
| 728 |
struct gfc_data *d = GDrawGetUserData(GGadgetGetWindow(g)); |
| 729 |
_ImportParamsDlg(ImportParamsState()); |
| 730 |
d->opts_shown = true; |
| 731 |
} |
| 732 |
return true; |
| 733 |
} |
| 734 |
|
| 735 |
static int e_h(GWindow gw, GEvent *event) { |
| 736 |
if ( event->type==et_close ) { |
| 737 |
struct gfc_data *d = GDrawGetUserData(gw); |
| 738 |
d->done = true; |
| 739 |
d->ret = false; |
| 740 |
} else if ( event->type == et_char ) { |
| 741 |
return( false ); |
| 742 |
} else if ( event->type==et_map ) { |
| 743 |
GDrawRaise(gw); |
| 744 |
} else if ( event->type == et_mousemove || |
| 745 |
(event->type==et_mousedown && event->u.mouse.button==3 )) { |
| 746 |
struct gfc_data *d = GDrawGetUserData(gw); |
| 747 |
GFileChooserPopupCheck(d->gfc,event); |
| 748 |
} else if (( event->type==et_mouseup || event->type==et_mousedown ) && |
| 749 |
(event->u.mouse.button>=4 && event->u.mouse.button<=7) ) { |
| 750 |
struct gfc_data *d = GDrawGetUserData(gw); |
| 751 |
return( GGadgetDispatchEvent((GGadget *) (d->gfc),event)); |
| 752 |
} |
| 753 |
return( true ); |
| 754 |
} |
| 755 |
|
| 756 |
static void _Import(CharView *cv,BitmapView *bv,FontView *fv) { |
| 757 |
GRect pos; |
| 758 |
GWindow gw; |
| 759 |
GWindowAttrs wattrs; |
| 760 |
GGadgetCreateData gcd[10], boxes[4], *varray[9], *harray[7], *buttons[10]; |
| 761 |
GTextInfo label[9]; |
| 762 |
struct gfc_data d; |
| 763 |
int i, format, lpos; |
| 764 |
int bs = GIntGetResource(_NUM_Buttonsize), bsbigger, totwid, scalewid; |
| 765 |
static int done= false; |
| 766 |
GTextInfo *cur_formats; |
| 767 |
|
| 768 |
if ( !done ) { |
| 769 |
for ( i=0; formats[i].text!=NULL; ++i ) |
| 770 |
formats[i].text = (unichar_t *) _((char *) formats[i].text); |
| 771 |
for ( i=0; fvformats[i].text!=NULL; ++i ) |
| 772 |
fvformats[i].text = (unichar_t *) _((char *) fvformats[i].text); |
| 773 |
last_format = (int) fv_image; |
| 774 |
flast_format = (int) fv_bdf; |
| 775 |
done = true; |
| 776 |
} |
| 777 |
#ifndef _NO_PYTHON |
| 778 |
GTextInfo *base = cur_formats = fv==NULL?formats:fvformats; |
| 779 |
if ( py_ie!=NULL ) { |
| 780 |
int cnt, extras; |
| 781 |
for ( cnt=0; base[cnt].text!=NULL; ++cnt ); |
| 782 |
for ( i=extras=0; py_ie[i].name!=NULL; ++i ) |
| 783 |
if ( py_ie[i].py_import!=NULL ) |
| 784 |
++extras; |
| 785 |
if ( extras!=0 ) { |
| 786 |
cur_formats = calloc(extras+cnt+1,sizeof(GTextInfo)); |
| 787 |
for ( cnt=0; base[cnt].text!=NULL; ++cnt ) { |
| 788 |
cur_formats[cnt] = base[cnt]; |
| 789 |
cur_formats[cnt].text = (unichar_t *) copy( (char *) base[cnt].text ); |
| 790 |
} |
| 791 |
for ( i=extras=0; py_ie[i].name!=NULL; ++i ) { |
| 792 |
if ( py_ie[i].py_import!=NULL ) { |
| 793 |
cur_formats[cnt+extras].text = (unichar_t *) copy(py_ie[i].name); |
| 794 |
cur_formats[cnt+extras].text_is_1byte = true; |
| 795 |
cur_formats[cnt+extras].userdata = (void *) (intptr_t) (fv_pythonbase+i); |
| 796 |
++extras; |
| 797 |
} |
| 798 |
} |
| 799 |
} |
| 800 |
} |
| 801 |
#endif |
| 802 |
if ( !hasspiro()) { |
| 803 |
for ( i=0; cur_formats[i].text!=NULL; ++i ) |
| 804 |
if ( ((intptr_t) cur_formats[i].userdata)==fv_plate || |
| 805 |
((intptr_t) cur_formats[i].userdata)==fv_platetemplate ) |
| 806 |
cur_formats[i].disabled = true; |
| 807 |
} |
| 808 |
|
| 809 |
memset(&wattrs,0,sizeof(wattrs)); |
| 810 |
wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg; |
| 811 |
wattrs.event_masks = ~(1<<et_charup); |
| 812 |
wattrs.restrict_input_to_me = 1; |
| 813 |
wattrs.is_dlg = 1; |
| 814 |
wattrs.undercursor = 1; |
| 815 |
wattrs.cursor = ct_pointer; |
| 816 |
wattrs.utf8_window_title = _("Import"); |
| 817 |
pos.x = pos.y = 0; |
| 818 |
totwid = 240; |
| 819 |
if ( fv!=NULL ) totwid += 60; |
| 820 |
scalewid = GGadgetScale(totwid); |
| 821 |
bsbigger = 3*bs+4*14>scalewid; scalewid = bsbigger?3*bs+4*12:scalewid; |
| 822 |
pos.width = GDrawPointsToPixels(NULL,scalewid); |
| 823 |
pos.height = GDrawPointsToPixels(NULL,255); |
| 824 |
gw = GDrawCreateTopWindow(NULL,&pos,e_h,&d,&wattrs); |
| 825 |
|
| 826 |
memset(&label,0,sizeof(label)); |
| 827 |
memset(&gcd,0,sizeof(gcd)); |
| 828 |
memset(&boxes,0,sizeof(boxes)); |
| 829 |
gcd[0].gd.pos.x = 12; gcd[0].gd.pos.y = 6; gcd[0].gd.pos.width = totwid-24; gcd[0].gd.pos.height = 182; |
| 830 |
gcd[0].gd.flags = gg_visible | gg_enabled; |
| 831 |
if ( fv!=NULL ) |
| 832 |
gcd[0].gd.flags |= gg_file_multiple; |
| 833 |
gcd[0].creator = GFileChooserCreate; |
| 834 |
varray[0] = &gcd[0]; varray[1] = NULL; |
| 835 |
|
| 836 |
gcd[1].gd.pos.x = 12; gcd[1].gd.pos.y = 224-3; gcd[1].gd.pos.width = -1; gcd[1].gd.pos.height = 0; |
| 837 |
gcd[1].gd.flags = gg_visible | gg_enabled | gg_but_default; |
| 838 |
label[1].text = (unichar_t *) _("_Import"); |
| 839 |
label[1].text_is_1byte = true; |
| 840 |
label[1].text_in_resource = true; |
| 841 |
gcd[1].gd.label = &label[1]; |
| 842 |
gcd[1].gd.handle_controlevent = GFD_ImportOk; |
| 843 |
gcd[1].creator = GButtonCreate; |
| 844 |
buttons[0] = GCD_Glue; buttons[1] = &gcd[1]; buttons[2] = GCD_Glue; |
| 845 |
|
| 846 |
gcd[2].gd.pos.x = (totwid-bs)*100/GIntGetResource(_NUM_ScaleFactor)/2; gcd[2].gd.pos.y = 224; gcd[2].gd.pos.width = -1; gcd[2].gd.pos.height = 0; |
| 847 |
gcd[2].gd.flags = gg_visible | gg_enabled; |
| 848 |
label[2].text = (unichar_t *) _("_Filter"); |
| 849 |
label[2].text_is_1byte = true; |
| 850 |
label[2].text_in_resource = true; |
| 851 |
gcd[2].gd.mnemonic = 'F'; |
| 852 |
gcd[2].gd.label = &label[2]; |
| 853 |
gcd[2].gd.handle_controlevent = GFileChooserFilterEh; |
| 854 |
gcd[2].creator = GButtonCreate; |
| 855 |
buttons[3] = GCD_Glue; buttons[4] = &gcd[2]; buttons[5] = GCD_Glue; |
| 856 |
|
| 857 |
gcd[3].gd.pos.x = -gcd[1].gd.pos.x; gcd[3].gd.pos.y = 224; gcd[3].gd.pos.width = -1; gcd[3].gd.pos.height = 0; |
| 858 |
gcd[3].gd.flags = gg_visible | gg_enabled | gg_but_cancel; |
| 859 |
label[3].text = (unichar_t *) _("_Cancel"); |
| 860 |
label[3].text_is_1byte = true; |
| 861 |
label[3].text_in_resource = true; |
| 862 |
gcd[3].gd.label = &label[3]; |
| 863 |
gcd[3].gd.handle_controlevent = GFD_Cancel; |
| 864 |
gcd[3].creator = GButtonCreate; |
| 865 |
buttons[6] = GCD_Glue; buttons[7] = &gcd[3]; buttons[8] = GCD_Glue; |
| 866 |
buttons[9] = NULL; |
| 867 |
|
| 868 |
gcd[4].gd.pos.x = 12; gcd[4].gd.pos.y = 200; gcd[4].gd.pos.width = 0; gcd[4].gd.pos.height = 0; |
| 869 |
gcd[4].gd.flags = gg_visible | gg_enabled; |
| 870 |
label[4].text = (unichar_t *) _("Format:"); |
| 871 |
label[4].text_is_1byte = true; |
| 872 |
gcd[4].gd.label = &label[4]; |
| 873 |
gcd[4].creator = GLabelCreate; |
| 874 |
harray[0] = &gcd[4]; |
| 875 |
|
| 876 |
gcd[5].gd.pos.x = 55; gcd[5].gd.pos.y = 194; |
| 877 |
gcd[5].gd.flags = gg_visible | gg_enabled ; |
| 878 |
if ( bv!=NULL ) { |
| 879 |
gcd[5].gd.flags = gg_visible ; |
| 880 |
last_format=0; |
| 881 |
} |
| 882 |
format = fv==NULL?last_format:flast_format; |
| 883 |
lpos = fv==NULL?last_lpos:flast_lpos; |
| 884 |
gcd[5].gd.u.list = cur_formats; |
| 885 |
gcd[5].gd.label = &gcd[5].gd.u.list[lpos]; |
| 886 |
gcd[5].gd.handle_controlevent = GFD_Format; |
| 887 |
gcd[5].creator = GListButtonCreate; |
| 888 |
|
| 889 |
for ( i=0; gcd[5].gd.u.list[i].text!=NULL; ++i ) |
| 890 |
gcd[5].gd.u.list[i].selected = false; |
| 891 |
|
| 892 |
gcd[5].gd.u.list[lpos].selected = true; |
| 893 |
harray[1] = &gcd[5]; |
| 894 |
|
| 895 |
gcd[6].gd.flags = gg_visible | gg_enabled; |
| 896 |
label[6].text = (unichar_t *) _("_Options"); |
| 897 |
label[6].text_is_1byte = true; |
| 898 |
label[6].text_in_resource = true; |
| 899 |
gcd[6].gd.label = &label[6]; |
| 900 |
gcd[6].gd.handle_controlevent = GFD_Options; |
| 901 |
gcd[6].creator = GButtonCreate; |
| 902 |
harray[2] = &gcd[6]; harray[3] = GCD_Glue; |
| 903 |
|
| 904 |
if ( fv!=NULL ) { |
| 905 |
gcd[7].gd.flags = gg_visible | gg_enabled ; |
| 906 |
if ( format==fv_pk || format==fv_image || format==fv_imgtemplate ) |
| 907 |
gcd[7].gd.flags = gg_visible | gg_enabled | gg_cb_on; |
| 908 |
label[7].text = (unichar_t *) _("As Background"); |
| 909 |
label[7].text_is_1byte = true; |
| 910 |
gcd[7].gd.label = &label[7]; |
| 911 |
gcd[7].creator = GCheckBoxCreate; |
| 912 |
harray[4] = &gcd[7]; harray[5] = GCD_Glue; harray[6] = NULL; |
| 913 |
} else { |
| 914 |
harray[4] = GCD_Glue; harray[5] = NULL; |
| 915 |
} |
| 916 |
|
| 917 |
boxes[2].gd.flags = gg_enabled|gg_visible; |
| 918 |
boxes[2].gd.u.boxelements = harray; |
| 919 |
boxes[2].creator = GHBoxCreate; |
| 920 |
varray[2] = &boxes[2]; varray[3] = NULL; |
| 921 |
|
| 922 |
boxes[3].gd.flags = gg_enabled|gg_visible; |
| 923 |
boxes[3].gd.u.boxelements = buttons; |
| 924 |
boxes[3].creator = GHBoxCreate; |
| 925 |
varray[4] = GCD_Glue; varray[5] = NULL; |
| 926 |
varray[6] = &boxes[3]; varray[7] = NULL; |
| 927 |
varray[8] = NULL; |
| 928 |
|
| 929 |
boxes[0].gd.pos.x = boxes[0].gd.pos.y = 2; |
| 930 |
boxes[0].gd.flags = gg_enabled|gg_visible; |
| 931 |
boxes[0].gd.u.boxelements = varray; |
| 932 |
boxes[0].creator = GHVGroupCreate; |
| 933 |
|
| 934 |
GGadgetsCreate(gw,boxes); |
| 935 |
GHVBoxSetExpandableRow(boxes[0].ret,gb_expandglue); |
| 936 |
GHVBoxSetExpandableCol(boxes[3].ret,gb_expandgluesame); |
| 937 |
GHVBoxSetExpandableCol(boxes[2].ret,gb_expandglue); |
| 938 |
GGadgetSetUserData(gcd[2].ret,gcd[0].ret); |
| 939 |
|
| 940 |
GFileChooserConnectButtons(gcd[0].ret,gcd[1].ret,gcd[2].ret); |
| 941 |
GFileChooserSetFilterText(gcd[0].ret,wildfmt[format]); |
| 942 |
GFileChooserRefreshList(gcd[0].ret); |
| 943 |
GHVBoxFitWindow(boxes[0].ret); |
| 944 |
|
| 945 |
memset(&d,'\0',sizeof(d)); |
| 946 |
d.cv = cv; |
| 947 |
d.fv = fv; |
| 948 |
d.bv = bv; |
| 949 |
d.gfc = gcd[0].ret; |
| 950 |
d.format = gcd[5].ret; |
| 951 |
if ( fv!=NULL ) |
| 952 |
d.background = gcd[7].ret; |
| 953 |
|
| 954 |
if ( cur_formats!=formats && cur_formats!=fvformats ) |
| 955 |
GTextInfoListFree(cur_formats); |
| 956 |
|
| 957 |
GDrawSetVisible(gw,true); |
| 958 |
while ( !d.done ) |
| 959 |
GDrawProcessOneEvent(NULL); |
| 960 |
GDrawDestroyWindow(gw); |
| 961 |
} |
| 962 |
|
| 963 |
void CVImport(CharView *cv) { |
| 964 |
_Import(cv,NULL,NULL); |
| 965 |
} |
| 966 |
|
| 967 |
void BVImport(BitmapView *bv) { |
| 968 |
_Import(NULL,bv,NULL); |
| 969 |
} |
| 970 |
|
| 971 |
void FVImport(FontView *fv) { |
| 972 |
_Import(NULL,NULL,fv); |
| 973 |
} |