Example #1
0
void SdlPlatform::Compile(Font *obj)
{
	bfs::create_directories(obj->GetOutputPath().parent_path());
	IResource *res = const_cast<IResource *>(obj->GetResource());
	Image *img = static_cast<Image *>(res);

	std::ostringstream cmd;
	bfs::path toolPath(this->GetName());
	toolPath /= PLATFORM_SDL_FONTGEN_COMMAND;

	cmd << toolPath.string() << " \""; // file_string
	cmd << obj->GetInputPath() << "\"";
	cmd << " \"" << obj->GetName() << "\" " << obj->GetCharacters() << " ";
	cmd << obj->GetGlyphWidth() << " " << obj->GetGlyphHeight();

	if (obj->IsUsingAtlas())
	{
		cmd << " \"" << res->GetFilename() << "\" " << img->GetX() << " " << img->GetY();
	}
	RUN_COMMAND(cmd);

	// current cache dump
	pCache->Dump();

	bfs::path fontXML("tmp/font.xml");

	cmd.str("");
	cmd << e->bfsExeName.string() << " -i " << fontXML << " -p " << this->GetName();
	RUN_COMMAND(cmd);

	// updated cache reload
	pCache->Reset();
	pCache->Load();

	bfs::path fontSprite = obj->GetOutputPath();
	fontSprite.replace_extension(".sprite");
	//bfs::remove(fontXML);

	obj->SetSprite(fontSprite);
	obj->AddFilePath(fontSprite);

	/* build extension tables for languages */
	DictionaryMap dict = e->GetDictionaries();
	DictionaryMapIterator it = dict.begin();
	DictionaryMapIterator end = dict.end();
	for (; it != end; ++it)
	{
		Dictionary *dict = (*it).second;
		u32 size = dict->GetExtensionTableSize();
		if (size)
		{
			//std::ostringstream extname;
			//extname << "l10n/" << dict->pcGetLanguage() << "/" << obj->GetFilename() << "_ext";
			//extname << res->GetName() << "_ext";

			std::string extname(res->GetName());
			extname += "_ext";
			IResource *ext = e->GetResource(extname.c_str(), dict->pcGetLanguage());

			//IResource *ext = e->GetResource(res->GetName(), dict->pcGetLanguage());
			if (ext)
			{
				//std::string x(res->GetFilename());
				std::ostringstream x;
				//x << "l10n/" << dict->pcGetLanguage() << "/" << res->GetName() << "_ext.tga";
				x << res->GetName() << "_ext.tga";
				bfs::path xx(e->GetOutputPath());
				xx /= x.str();
				//pCache->AddFilename(xx.string().c_str());
				obj->SetExtId(pCache->GetFilenameId(xx.string().c_str()));

				std::ostringstream x2;
				//x2 << "l10n/" << dict->pcGetLanguage() << "/" << res->GetName() << "_ext.sprite";
				x2 << res->GetName() << "_ext.sprite";
				xx = e->GetOutputPath();
				xx /= x2.str();
				pCache->AddFilename(xx.string().c_str());
				obj->SetExtId(pCache->GetFilenameId(xx.string().c_str()));


				//bfs::path sprite = this->ProcessFont(obj, ext, size);
				//obj->AddFilePath(sprite);
				this->ProcessFont(obj, ext, size);
				std::ostringstream x3;
				x3 << "l10n/" << dict->pcGetLanguage() << "/" << res->GetName() << "_ext.sprite";
				xx = e->GetOutputPath();
				xx /= x3.str();
				obj->AddFilePath(xx.string().c_str());
			}
			else
			{
				//Error(ERROR_UNKNOWN, TAG "Needed language '%s' resource extension table %s for font %s not found.", dict->pcGetLanguage(), extname.c_str(), obj->GetName());
				//Error(ERROR_UNKNOWN, TAG "Needed language '%s' specific resource for font %s not found.", dict->pcGetLanguage(), obj->GetName());
			}
		}
	}
}
Example #2
0
void WiiPlatform::Compile(Font *obj)
{
	bfs::create_directories(obj->GetOutputPath().parent_path());
	IResource *res = const_cast<IResource *>(obj->GetResource());
	Image *img = static_cast<Image *>(res);

	std::ostringstream cmd;
	bfs::path toolPath(this->GetName());
	toolPath /= PLATFORM_WII_FONTGEN_COMMAND;

	cmd << toolPath.string() << " \""; // file_string
	cmd << obj->GetInputPath() << "\"";
	cmd << " \"" << obj->GetName() << "\" " << obj->GetCharacters();

	if (obj->IsUsingAtlas())
	{
		cmd << " \"" << res->GetFilename() << "\" " << img->GetX() << " " << img->GetY();
	}
	RUN_COMMAND(cmd);

	// current cache dump
	pCache->Dump();

	bfs::path fontXML("tmp/font.xml");

	cmd.str("");
	cmd << e->bfsExeName.string() << " -i " << fontXML << " -p " << this->GetName();
	RUN_COMMAND(cmd);

	// updated cache reload
	pCache->Reset();
	pCache->Load();

	bfs::path fontSprite = obj->GetOutputPath();
	fontSprite.replace_extension(".sprite");
	bfs::remove(fontXML);

	obj->SetSprite(fontSprite);
	obj->AddFilePath(fontSprite);

	/*if (e->IsCompressionEnabled())
	{
		// .font
		bfs::path pathNewExtension = obj->GetOutputPath();
		pathNewExtension.replace_extension(".lzf");
		cmd.str("");
		cmd << (wiiToolPath / LZFTOOL).string() << " \"" << obj->GetOutputPath() << "\" \"" << pathNewExtension << "\""; // file_string

		DebugInfo("CMD: %s\n", cmd.str().c_str());
		cmdRetCode = system(cmd.str().c_str());
		if (cmdRetCode)
		{
			fprintf(stderr, "%s didn't execute properly. Return code: %d.\n", LZFTOOL, cmdRetCode);
			//exit(EXIT_FAILURE);
		}

		bfs::remove(obj->GetOutputPath());
		bfs::rename(pathNewExtension, obj->GetOutputPath());

		// .sprite
		pathNewExtension = fontSprite;
		pathNewExtension.replace_extension(".lzf");

		cmd.str("");
		cmd << (wiiToolPath / LZFTOOL).string() << " \"" << fontSprite << "\" \"" << pathNewExtension << "\""; // file_string

		DebugInfo("CMD: %s\n", cmd.str().c_str());
		cmdRetCode = system(cmd.str().c_str());
		if (cmdRetCode)
		{
			fprintf(stderr, "%s didn't execute properly. Return code: %d.\n", LZFTOOL, cmdRetCode);
			//exit(EXIT_FAILURE);
		}

		bfs::remove(fontSprite);
		bfs::rename(pathNewExtension, fontSprite);
	}*/

	/* build extension tables for languages */
	DictionaryMap dict = e->GetDictionaries();
	DictionaryMapIterator it = dict.begin();
	DictionaryMapIterator end = dict.end();
	for (; it != end; ++it)
	{
		Dictionary *dict = (*it).second;
		u32 size = dict->GetExtensionTableSize();
		if (size)
		{
			//std::ostringstream extname;
			//extname << "l10n/" << dict->pcGetLanguage() << "/" << obj->GetFilename() << "_ext";
			//IResource *ext = e->GetResource(extname.str().c_str());

			std::string extname(res->GetName());
			extname += "_ext";
			IResource *ext = e->GetResource(extname.c_str(), dict->pcGetLanguage());

			//IResource *ext = e->GetResource(res->GetName(), dict->pcGetLanguage());
			if (ext)
			{
				std::string x(res->GetFilename());
				x += "_ext.tpl";
				bfs::path xx(e->GetOutputPath());
				xx /= x;
				pCache->AddFilename(xx.string().c_str());
				obj->SetExtId(pCache->GetFilenameId(xx.string().c_str()));

				x = res->GetFilename();
				x += "_ext.sprite";
				xx = e->GetOutputPath();
				xx /= x;
				pCache->AddFilename(xx.string().c_str());
				obj->SetExtId(pCache->GetFilenameId(xx.string().c_str()));


				bfs::path sprite = this->ProcessFont(obj, ext, size);
				obj->AddFilePath(sprite);
			}
			else
			{
				//Error(ERROR_UNKNOWN, TAG "Needed language '%s' resource extension table %s for font %s not found.", dict->pcGetLanguage(), extname.c_str(), obj->GetName());
				Error(ERROR_UNKNOWN, TAG "Needed language '%s' specific resource for font %s not found.", dict->pcGetLanguage(), obj->GetName());
			}
		}
	}
}