Browse Source

fix font import path on windows, closes #1675

Juan Linietsky 10 years ago
parent
commit
2a02d3f96f

+ 8 - 3
core/ustring.cpp

@@ -3297,8 +3297,11 @@ String String::path_to_file(const String& p_path) const {
 
 	String src=this->replace("\\","/").get_base_dir();
 	String dst=p_path.replace("\\","/").get_base_dir();
-
-	return src.path_to(dst)+p_path.get_file();
+	String rel = src.path_to(dst);
+	if (rel==dst) // failed
+		return p_path;
+	else
+		return rel+p_path.get_file();
 }
 
 String String::path_to(const String& p_path) const {
@@ -3333,7 +3336,9 @@ String String::path_to(const String& p_path) const {
 		String src_begin=src.get_slice("/",0);
 		String dst_begin=dst.get_slice("/",0);
 
-		ERR_FAIL_COND_V(src_begin!=dst_begin,p_path); //return dst absolute path
+		if (src_begin!=dst_begin)
+			return p_path; //impossible to do this
+
 		base=src_begin;
 		src=src.substr(src_begin.length(),src.length());
 		dst=dst.substr(dst_begin.length(),dst.length());

+ 0 - 1
scene/gui/file_dialog.cpp

@@ -92,7 +92,6 @@ void FileDialog::_file_entered(const String& p_file) {
 }
 
 void FileDialog::_save_confirm_pressed() {
-	
 	String f=dir_access->get_current_dir().plus_file(file->get_text());
 	emit_signal("file_selected",f);
 	hide();		

+ 1 - 0
tools/editor/editor_import_export.cpp

@@ -47,6 +47,7 @@ String EditorImportPlugin::validate_source_path(const String& p_path) {
 	String rp = Globals::get_singleton()->get_resource_path();
 	if (!rp.ends_with("/"))
 		rp+="/";
+
 	return rp.path_to_file(gp);
 }
 

+ 5 - 2
tools/editor/io_plugins/editor_font_import_plugin.cpp

@@ -406,7 +406,10 @@ class EditorFontImportDialog : public ConfirmationDialog {
 			imd->set_option(opt,v);
 		}
 
-		imd->add_source(EditorImportPlugin::validate_source_path(source->get_line_edit()->get_text()));
+		String src_path = EditorImportPlugin::validate_source_path(source->get_line_edit()->get_text());
+		//print_line("pre src path "+source->get_line_edit()->get_text());
+		//print_line("src path "+src_path);
+		imd->add_source(src_path);
 		imd->set_option("font/size",font_size->get_val());
 
 		return imd;
@@ -1018,7 +1021,7 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata
 		int h = slot->bitmap.rows;
 		int p = slot->bitmap.pitch;
 
-		print_line("W: "+itos(w)+" P: "+itos(slot->bitmap.pitch));
+		//print_line("W: "+itos(w)+" P: "+itos(slot->bitmap.pitch));
 
 		if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) {