Ejemplo n.º 1
0
void packAll(Main *bmain, ReportList *reports)
{
	Image *ima;
	VFont *vf;
	bSound *sound;
	
	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, 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);
			}
		}
	}

	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, 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, bmain->name);
}
Ejemplo n.º 2
0
VFont *BKE_vfont_load(Main *bmain, const char *name)
{
	char filename[FILE_MAXFILE];
	VFont *vfont = NULL;
	PackedFile *pf;
	PackedFile *temp_pf = NULL;
	int is_builtin;
	
	if (STREQ(name, FO_BUILTIN_NAME)) {
		BLI_strncpy(filename, name, sizeof(filename));
		
		pf = get_builtin_packedfile();
		is_builtin = TRUE;
	}
	else {
		BLI_split_file_part(name, filename, sizeof(filename));
		pf = newPackedFile(NULL, name, bmain->name);
		temp_pf = newPackedFile(NULL, name, bmain->name);
		
		is_builtin = FALSE;
	}

	if (pf) {
		VFontData *vfd;

		vfd = BLI_vfontdata_from_freetypefont(pf);
		if (vfd) {
			vfont = BKE_libblock_alloc(&bmain->vfont, ID_VF, filename);
			vfont->data = vfd;

			/* if there's a font name, use it for the ID name */
			if (vfd->name[0] != '\0') {
				BLI_strncpy(vfont->id.name + 2, vfd->name, sizeof(vfont->id.name) - 2);
			}
			BLI_strncpy(vfont->name, name, sizeof(vfont->name));

			/* if autopack is on store the packedfile in de font structure */
			if (!is_builtin && (G.fileflags & G_AUTOPACK)) {
				vfont->packedfile = pf;
			}

			/* Do not add FO_BUILTIN_NAME to temporary listbase */
			if (strcmp(filename, FO_BUILTIN_NAME)) {
				vfont->temp_pf = temp_pf;
			}
		}

		/* Free the packed file */
		if (!vfont || vfont->packedfile != pf) {
			freePackedFile(pf);
		}
	}
	
	return vfont;
}
Ejemplo n.º 3
0
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	if (vfont == NULL) {
		return NULL;
	}

	/* And then set the data */
	if (!vfont->data) {
		PackedFile *pf;

		if (BKE_vfont_is_builtin(vfont)) {
			pf = get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf = vfont->packedfile;

				/* We need to copy a tmp font to memory unless it is already there */
				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = dupPackedFile(pf);
				}
			}
			else {
				pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				/* DON'T DO THIS
				 * missing file shouldn't modifty path! - campbell */
#if 0
				strcpy(vfont->name, FO_BUILTIN_NAME);
#endif
				pf = get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data = BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}
	}
	
	return vfont->data;
}
Ejemplo n.º 4
0
static void rna_Image_pack(
        Image *image, Main *bmain, bContext *C, ReportList *reports,
        int as_png, const char *data, int data_len)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);

	if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
		BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
	}
	else {
		if (image->packedfile) {
			freePackedFile(image->packedfile);
			image->packedfile = NULL;
		}
		if (as_png) {
			BKE_image_memorypack(image);
		}
		else if (data) {
			char *data_dup = MEM_mallocN(sizeof(*data_dup) * (size_t)data_len, __func__);
			memcpy(data_dup, data, (size_t)data_len);
			image->packedfile = newPackedFileMemory(data_dup, data_len);
		}
		else {
			image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(bmain, &image->id));
		}
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
Ejemplo n.º 5
0
/* no libraries for now */
void packAll(Main *bmain, ReportList *reports, bool verbose)
{
	Image *ima;
	VFont *vfont;
	bSound *sound;
	int tot = 0;
	
	for (ima = bmain->image.first; ima; ima = ima->id.next) {
		if (BKE_image_has_packedfile(ima) == false && ima->id.lib == NULL) {
			if (ima->source == IMA_SRC_FILE) {
				BKE_image_packfiles(reports, ima, ID_BLEND_PATH(bmain, &ima->id));
				tot ++;
			}
			else if (BKE_image_is_animated(ima) && verbose) {
				BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported",
				            ima->id.name + 2);
			}
		}
	}

	for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) {
		if (vfont->packedfile == NULL && vfont->id.lib == NULL && BKE_vfont_is_builtin(vfont) == false) {
			vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name);
			tot ++;
		}
	}

	for (sound = bmain->sound.first; sound; sound = sound->id.next) {
		if (sound->packedfile == NULL && sound->id.lib == NULL) {
			sound->packedfile = newPackedFile(reports, sound->name, bmain->name);
			tot++;
		}
	}
	
	if (tot > 0)
		BKE_reportf(reports, RPT_INFO, "Packed %d files", tot);
	else if (verbose)
		BKE_report(reports, RPT_INFO, "No new files have been packed");


}
Ejemplo n.º 6
0
static void rna_Image_pack(Image *image, ReportList *reports, int as_png)
{
	ImBuf *ibuf = BKE_image_get_ibuf(image, NULL);

	if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
		BKE_reportf(reports, RPT_ERROR, "Can't pack edited image from disk, only as internal PNG");
	}
	else {
		if(as_png) {
			BKE_image_memorypack(image);
		}
		else {
			image->packedfile= newPackedFile(reports, image->name);
		}
	}
}
Ejemplo n.º 7
0
static void rna_Image_pack(Image *image, ReportList *reports, int as_png)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);

	if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
		BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
	}
	else {
		if (as_png) {
			BKE_image_memorypack(image);
		}
		else {
			image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(G.main, &image->id));
		}
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
}
Ejemplo n.º 8
0
void packLibraries(Main *bmain, ReportList *reports)
{
	Library *lib;
	
	/* test for relativenss */
	for (lib = bmain->library.first; lib; lib = lib->id.next)
		if (!BLI_path_is_rel(lib->name))
			break;
	
	if (lib) {
		BKE_reportf(reports, RPT_ERROR, "Cannot pack absolute file: '%s'", lib->name);
		return;
	}
	
	for (lib = bmain->library.first; lib; lib = lib->id.next)
		if (lib->packedfile == NULL)
			lib->packedfile = newPackedFile(reports, lib->name, bmain->name);
}
Ejemplo n.º 9
0
VFont *load_vfont(Main *bmain, const char *name)
{
	char filename[FILE_MAXFILE];
	VFont *vfont= NULL;
	PackedFile *pf;
	PackedFile *tpf = NULL;	
	int is_builtin;
	struct TmpFont *tmpfnt;
	
	if (strcmp(name, FO_BUILTIN_NAME)==0) {
		BLI_strncpy(filename, name, sizeof(filename));
		
		pf= get_builtin_packedfile();
		is_builtin= 1;
	}
	else {
		char dir[FILE_MAXDIR];
		
		BLI_strncpy(dir, name, sizeof(dir));
		BLI_splitdirstring(dir, filename);

		pf= newPackedFile(NULL, name, bmain->name);
		tpf= newPackedFile(NULL, name, bmain->name);
		
		is_builtin= 0;
	}

	if (pf) {
		VFontData *vfd;

		vfd= BLI_vfontdata_from_freetypefont(pf);
		if (vfd) {
			vfont = alloc_libblock(&bmain->vfont, ID_VF, filename);
			vfont->data = vfd;

			/* if there's a font name, use it for the ID name */
			if (vfd->name[0] != '\0') {
				BLI_strncpy(vfont->id.name+2, vfd->name, sizeof(vfont->id.name)-2);
			}
			BLI_strncpy(vfont->name, name, sizeof(vfont->name));

			// if autopack is on store the packedfile in de font structure
			if (!is_builtin && (G.fileflags & G_AUTOPACK)) {
				vfont->packedfile = pf;
			}
			
			// Do not add FO_BUILTIN_NAME to temporary listbase
			if (strcmp(filename, FO_BUILTIN_NAME)) {
				tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
				tmpfnt->pf= tpf;
				tmpfnt->vfont= vfont;
				BLI_addtail(&ttfdata, tmpfnt);
			}			
		}
		
		// Free the packed file
		if (!vfont || vfont->packedfile != pf) {
			freePackedFile(pf);
		}
	
		//XXX waitcursor(0);
	}
	
	return vfont;
}
Ejemplo n.º 10
0
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	struct TmpFont *tmpfnt = NULL;
	PackedFile *tpf;
	
	if (vfont==NULL) return NULL;
	
	// Try finding the font from font list
	tmpfnt = vfont_find_tmpfont(vfont);
	
	// And then set the data	
	if (!vfont->data) {
		PackedFile *pf;
		
		if (strcmp(vfont->name, FO_BUILTIN_NAME)==0) {
			pf= get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf= vfont->packedfile;
				
				// We need to copy a tmp font to memory unless it is already there
				if (!tmpfnt) {
					tpf= MEM_callocN(sizeof(*tpf), "PackedFile");
					tpf->data= MEM_mallocN(pf->size, "packFile");
					tpf->size= pf->size;
					memcpy(tpf->data, pf->data, pf->size);
					
					// Add temporary packed file to globals
					tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
					tmpfnt->pf= tpf;
					tmpfnt->vfont= vfont;
					BLI_addtail(&ttfdata, tmpfnt);
				}
			}
			else {
				pf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (!tmpfnt) {
					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");
					tmpfnt->pf= tpf;
					tmpfnt->vfont= vfont;
					BLI_addtail(&ttfdata, tmpfnt);
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				strcpy(vfont->name, FO_BUILTIN_NAME);
				pf= get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data= BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}
	}
	
	return vfont->data;	
}
Ejemplo n.º 11
0
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	if (vfont == NULL) {
		return NULL;
	}

	/* And then set the data */
	if (!vfont->data) {
		PackedFile *pf;

		BLI_mutex_lock(&vfont_mutex);

		if (vfont->data) {
			/* Check data again, since it might have been already
			 * initialized from other thread (previous check is
			 * not accurate or threading, just prevents unneeded
			 * lock if all the data is here for sure).
			 */
			BLI_mutex_unlock(&vfont_mutex);
			return vfont->data;
		}

		if (BKE_vfont_is_builtin(vfont)) {
			pf = get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf = vfont->packedfile;

				/* We need to copy a tmp font to memory unless it is already there */
				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = dupPackedFile(pf);
				}
			}
			else {
				pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				/* DON'T DO THIS
				 * missing file shouldn't modifty path! - campbell */
#if 0
				strcpy(vfont->name, FO_BUILTIN_NAME);
#endif
				pf = get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data = BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}

		BLI_mutex_unlock(&vfont_mutex);
	}

	return vfont->data;
}