fix [#28846] Relative paths on linked scene fails
authorCampbell Barton <ideasman42@gmail.com>
Sat, 8 Oct 2011 11:02:58 +0000 (11:02 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 8 Oct 2011 11:02:58 +0000 (11:02 +0000)
14 files changed:
source/blender/blenkernel/BKE_font.h
source/blender/blenkernel/BKE_packedFile.h
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/font.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/packedFile.c
source/blender/editors/curve/editfont.c
source/blender/editors/object/object_edit.c
source/blender/editors/sound/sound_ops.c
source/blender/editors/space_image/image_ops.c
source/blender/makesdna/DNA_ID.h
source/blender/makesrna/intern/rna_image_api.c
source/blender/makesrna/intern/rna_main_api.c

index 2195b37..e4e8805 100644 (file)
@@ -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);
 
index 541c581..556ff26 100644 (file)
@@ -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);
index 824bbb8..3accceb 100644 (file)
@@ -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;
index acc900d..6704d06 100644 (file)
@@ -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);
 
index 6898615..c82aa85 100644 (file)
@@ -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;
index d764826..834961b 100644 (file)
@@ -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
index ed729d8..4bc40bd 100644 (file)
@@ -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);
 }
 
 
index fcac070..d8257c5 100644 (file)
@@ -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);
index a50dd00..76cbfdc 100644 (file)
@@ -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));
index 5b72e87..d03c2b1 100644 (file)
@@ -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;
index 45bd1d5..33c3ae4 100644 (file)
@@ -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);
        
index f81a05f..9c8a023 100644 (file)
@@ -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
index b782798..50ce816 100644 (file)
@@ -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));
                }
        }
 }
index 54bae59..7b26a8c 100644 (file)
@@ -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,