fix [#28846] Relative paths on linked scene fails

This commit is contained in:
Campbell Barton 2011-10-08 11:02:58 +00:00
parent 9a51266f35
commit 011a3645bf
14 changed files with 43 additions and 35 deletions

@ -46,6 +46,7 @@ struct Curve;
struct objfnt;
struct TmpFont;
struct CharInfo;
struct Main;
struct chartrans {
float xof, yof;
@ -77,10 +78,10 @@ void BKE_font_register_builtin(void *mem, int size);
void free_vfont(struct VFont *sc);
void free_ttfont(void);
struct VFont *get_builtin_font(void);
struct VFont *load_vfont(const char *name);
struct VFont *load_vfont(struct Main *bmain, const char *name);
struct TmpFont *vfont_find_tmpfont(struct VFont *vfont);
struct chartrans *BKE_text_to_curve(struct Scene *scene, struct Object *ob, int mode);
struct chartrans *BKE_text_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode);
int BKE_font_getselection(struct Object *ob, int *start, int *end);

@ -45,7 +45,7 @@ struct ReportList;
struct VFont;
/* pack */
struct PackedFile *newPackedFile(struct ReportList *reports, const char *filename);
struct PackedFile *newPackedFile(struct ReportList *reports, const char *filename, const char *relabase);
struct PackedFile *newPackedFileMemory(void *mem, int memlen);
void packAll(struct Main *bmain, struct ReportList *reports);

@ -1514,7 +1514,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, i
/* in par the family name is stored, use this to find the other objects */
chartransdata= BKE_text_to_curve(scene, par, FO_DUPLI);
chartransdata= BKE_text_to_curve(G.main, scene, par, FO_DUPLI);
if(chartransdata==NULL) return;
cu= par->data;

@ -1207,7 +1207,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
if(cu->path) free_path(cu->path);
cu->path= NULL;
if(ob->type==OB_FONT) BKE_text_to_curve(scene, ob, 0);
if(ob->type==OB_FONT) BKE_text_to_curve(G.main, scene, ob, 0);
if(!forOrco) curve_calc_modifiers_pre(scene, ob, forRender, &originalVerts, &deformedVerts, &numVerts);

@ -284,7 +284,7 @@ struct TmpFont *vfont_find_tmpfont(VFont *vfont)
return tmpfnt;
}
static VFontData *vfont_get_data(VFont *vfont)
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
struct TmpFont *tmpfnt = NULL;
PackedFile *tpf;
@ -319,11 +319,11 @@ static VFontData *vfont_get_data(VFont *vfont)
BLI_addtail(&ttfdata, tmpfnt);
}
} else {
pf= newPackedFile(NULL, vfont->name);
pf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
if(!tmpfnt)
{
tpf= newPackedFile(NULL, vfont->name);
tpf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
// Add temporary packed file to globals
tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
@ -351,7 +351,7 @@ static VFontData *vfont_get_data(VFont *vfont)
return vfont->data;
}
VFont *load_vfont(const char *name)
VFont *load_vfont(Main *bmain, const char *name)
{
char filename[FILE_MAXFILE];
VFont *vfont= NULL;
@ -371,8 +371,8 @@ VFont *load_vfont(const char *name)
BLI_strncpy(dir, name, sizeof(dir));
BLI_splitdirstring(dir, filename);
pf= newPackedFile(NULL, name);
tpf= newPackedFile(NULL, name);
pf= newPackedFile(NULL, name, bmain->name);
tpf= newPackedFile(NULL, name, bmain->name);
is_builtin= 0;
}
@ -382,7 +382,7 @@ VFont *load_vfont(const char *name)
vfd= BLI_vfontdata_from_freetypefont(pf);
if (vfd) {
vfont = alloc_libblock(&G.main->vfont, ID_VF, filename);
vfont = alloc_libblock(&bmain->vfont, ID_VF, filename);
vfont->data = vfd;
/* if there's a font name, use it for the ID name */
@ -439,7 +439,7 @@ VFont *get_builtin_font(void)
if (strcmp(vf->name, FO_BUILTIN_NAME)==0)
return vf;
return load_vfont(FO_BUILTIN_NAME);
return load_vfont(G.main, FO_BUILTIN_NAME);
}
static VChar *find_vfont_char(VFontData *vfd, intptr_t character)
@ -500,7 +500,7 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i
}
static void buildchar(Curve *cu, unsigned long character, CharInfo *info, float ofsx, float ofsy, float rot, int charidx)
static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo *info, float ofsx, float ofsy, float rot, int charidx)
{
BezTriple *bezt1, *bezt2;
Nurb *nu1 = NULL, *nu2 = NULL;
@ -509,7 +509,7 @@ static void buildchar(Curve *cu, unsigned long character, CharInfo *info, float
VChar *che = NULL;
int i;
vfd= vfont_get_data(which_vfont(cu, info));
vfd= vfont_get_data(bmain, which_vfont(cu, info));
if (!vfd) return;
/*
@ -662,7 +662,7 @@ static float char_width(Curve *cu, VChar *che, CharInfo *info)
}
}
struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
struct chartrans *BKE_text_to_curve(Main *bmain, Scene *scene, Object *ob, int mode)
{
VFont *vfont, *oldvfont;
VFontData *vfd= NULL;
@ -714,7 +714,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
if (cu->tb==NULL)
cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "TextBox compat");
vfd= vfont_get_data(vfont);
vfd= vfont_get_data(bmain, vfont);
/* The VFont Data can not be found */
if(!vfd) {
@ -792,7 +792,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
}
if (vfont != oldvfont) {
vfd= vfont_get_data(vfont);
vfd= vfont_get_data(bmain, vfont);
oldvfont = vfont;
}
@ -1157,7 +1157,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
}
// We do not want to see any character for \n or \r
if(cha != '\n' && cha != '\r')
buildchar(cu, cha, info, ct->xof, ct->yof, ct->rot, i);
buildchar(bmain, cu, cha, info, ct->xof, ct->yof, ct->rot, i);
if ((info->flag & CU_CHINFO_UNDERLINE) && (cu->textoncurve == NULL) && (cha != '\n') && (cha != '\r')) {
float ulwidth, uloverlap= 0.0f;

@ -1480,7 +1480,7 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal)
/* try to repack file */
if(ima->packedfile) {
PackedFile *pf;
pf = newPackedFile(NULL, ima->name);
pf = newPackedFile(NULL, ima->name, ID_BLEND_PATH(G.main, &ima->id));
if (pf) {
freePackedFile(ima->packedfile);
ima->packedfile = pf;
@ -1860,7 +1860,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
/* make packed file for autopack */
if ((ima->packedfile == NULL) && (G.fileflags & G_AUTOPACK))
ima->packedfile = newPackedFile(NULL, str);
ima->packedfile = newPackedFile(NULL, str, ID_BLEND_PATH(G.main, &ima->id));
}
}
else

@ -168,7 +168,7 @@ PackedFile *newPackedFileMemory(void *mem, int memlen)
return pf;
}
PackedFile *newPackedFile(ReportList *reports, const char *filename)
PackedFile *newPackedFile(ReportList *reports, const char *filename, const char *basepath)
{
PackedFile *pf = NULL;
int file, filelen;
@ -185,7 +185,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename)
// convert relative filenames to absolute filenames
strcpy(name, filename);
BLI_path_abs(name, G.main->name);
BLI_path_abs(name, basepath);
// open the file
// and create a PackedFile structure
@ -224,7 +224,7 @@ void packAll(Main *bmain, ReportList *reports)
for(ima=bmain->image.first; ima; ima=ima->id.next) {
if(ima->packedfile == NULL && ima->id.lib==NULL) {
if(ima->source==IMA_SRC_FILE) {
ima->packedfile = newPackedFile(reports, ima->name);
ima->packedfile = newPackedFile(reports, ima->name, ID_BLEND_PATH(bmain, &ima->id));
}
else if(ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported.", ima->id.name+2);
@ -234,11 +234,11 @@ void packAll(Main *bmain, ReportList *reports)
for(vf=bmain->vfont.first; vf; vf=vf->id.next)
if(vf->packedfile == NULL && vf->id.lib==NULL && strcmp(vf->name, FO_BUILTIN_NAME) != 0)
vf->packedfile = newPackedFile(reports, vf->name);
vf->packedfile = newPackedFile(reports, vf->name, bmain->name);
for(sound=bmain->sound.first; sound; sound=sound->id.next)
if(sound->packedfile == NULL && sound->id.lib==NULL)
sound->packedfile = newPackedFile(reports, sound->name);
sound->packedfile = newPackedFile(reports, sound->name, bmain->name);
}

@ -259,6 +259,7 @@ static int insert_into_textbuf(Object *obedit, uintptr_t c)
static void text_update_edited(bContext *C, Scene *scene, Object *obedit, int recalc, int mode)
{
struct Main *bmain= CTX_data_main(C);
Curve *cu= obedit->data;
EditFont *ef= cu->editfont;
cu->curinfo = ef->textbufinfo[cu->pos?cu->pos-1:0];
@ -269,7 +270,7 @@ static void text_update_edited(bContext *C, Scene *scene, Object *obedit, int re
if(mode == FO_EDIT)
update_string(cu);
BKE_text_to_curve(scene, obedit, mode);
BKE_text_to_curve(bmain, scene, obedit, mode);
if(recalc)
DAG_id_tag_update(obedit->data, 0);
@ -928,9 +929,10 @@ static int move_cursor(bContext *C, int type, int select)
if(select == 0) {
if(cu->selstart) {
struct Main *bmain= CTX_data_main(C);
cu->selstart = cu->selend = 0;
update_string(cu);
BKE_text_to_curve(scene, obedit, FO_SELCHANGE);
BKE_text_to_curve(bmain, scene, obedit, FO_SELCHANGE);
}
}
@ -1644,13 +1646,14 @@ static int open_cancel(bContext *UNUSED(C), wmOperator *op)
static int open_exec(bContext *C, wmOperator *op)
{
struct Main *bmain= CTX_data_main(C);
VFont *font;
PropertyPointerRNA *pprop;
PointerRNA idptr;
char filepath[FILE_MAX];
RNA_string_get(op->ptr, "filepath", filepath);
font= load_vfont(filepath);
font= load_vfont(bmain, filepath);
if(!font) {
if(op->customdata) MEM_freeN(op->customdata);

@ -1221,7 +1221,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
cu1->vfontbi= cu->vfontbi;
id_us_plus((ID *)cu1->vfontbi);
BKE_text_to_curve(scene, base->object, 0); /* needed? */
BKE_text_to_curve(bmain, scene, base->object, 0); /* needed? */
BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family));

@ -519,6 +519,7 @@ static int sound_poll(bContext *C)
static int pack_exec(bContext *C, wmOperator *op)
{
Main *bmain= CTX_data_main(C);
Editing* ed = CTX_data_scene(C)->ed;
bSound* sound;
@ -530,7 +531,7 @@ static int pack_exec(bContext *C, wmOperator *op)
if(!sound || sound->packedfile)
return OPERATOR_CANCELLED;
sound->packedfile= newPackedFile(op->reports, sound->name);
sound->packedfile= newPackedFile(op->reports, sound->name, ID_BLEND_PATH(bmain, &sound->id));
sound_load(CTX_data_main(C), sound);
return OPERATOR_FINISHED;

@ -1567,6 +1567,7 @@ static int pack_test(bContext *C, wmOperator *op)
static int pack_exec(bContext *C, wmOperator *op)
{
struct Main *bmain= CTX_data_main(C);
Image *ima= CTX_data_edit_image(C);
ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
int as_png= RNA_boolean_get(op->ptr, "as_png");
@ -1582,7 +1583,7 @@ static int pack_exec(bContext *C, wmOperator *op)
if(as_png)
BKE_image_memorypack(ima);
else
ima->packedfile= newPackedFile(op->reports, ima->name);
ima->packedfile= newPackedFile(op->reports, ima->name, ID_BLEND_PATH(bmain, &ima->id));
WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, ima);

@ -206,6 +206,8 @@ typedef struct PreviewImage {
#define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM))
#define ID_BLEND_PATH(_bmain, _id) ((_id)->lib ? (_id)->lib->filepath : (_bmain)->name)
#ifdef GS
#undef GS
#endif

@ -142,7 +142,7 @@ static void rna_Image_pack(Image *image, ReportList *reports, int as_png)
BKE_image_memorypack(image);
}
else {
image->packedfile= newPackedFile(reports, image->name);
image->packedfile= newPackedFile(reports, image->name, ID_BLEND_PATH(G.main, &image->id));
}
}
}

@ -344,12 +344,12 @@ void rna_Main_metaballs_remove(Main *bmain, ReportList *reports, struct MetaBall
mb->id.name+2, ID_REAL_USERS(mb));
}
VFont *rna_Main_fonts_load(Main *UNUSED(bmain), ReportList *reports, const char *filepath)
VFont *rna_Main_fonts_load(Main *bmain, ReportList *reports, const char *filepath)
{
VFont *font;
errno= 0;
font= load_vfont(filepath);
font= load_vfont(bmain, filepath);
if(!font)
BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s", filepath,