diff --git a/Core/GDCore/Events/ExpressionMetadata.cpp b/Core/GDCore/Events/ExpressionMetadata.cpp index 8173d71df5..75b0017eb6 100644 --- a/Core/GDCore/Events/ExpressionMetadata.cpp +++ b/Core/GDCore/Events/ExpressionMetadata.cpp @@ -24,6 +24,7 @@ fullname(fullname_), description(description_), group(group_), shown(true), +returnUtf8(true), smallIconFilename(smallicon_), extensionNamespace(extensionNamespace_) { diff --git a/Core/GDCore/Events/ExpressionMetadata.h b/Core/GDCore/Events/ExpressionMetadata.h index e276738a70..13679e7ac8 100644 --- a/Core/GDCore/Events/ExpressionMetadata.h +++ b/Core/GDCore/Events/ExpressionMetadata.h @@ -132,6 +132,27 @@ public: return *this; }; + /** + * \brief Declare the last added paramete not able to receivre UTF8 strings. + * + * \see AddParameter + */ + ExpressionMetadata & CantUseUtf8() + { + if ( !parameters.empty() ) parameters.back().canUseUtf8 = false; + return *this; + }; + + /** + * \brief Declare that the expression returns a locale string (not encoded in UTF8) + */ + ExpressionMetadata & DontReturnUtf8() + { + returnUtf8 = false; + return *this; + }; + bool returnUtf8; + ExpressionCodeGenerationInformation codeExtraInformation; /** Don't use this constructor. Only here to fullfil std::map requirements @@ -152,6 +173,7 @@ private: std::string description; std::string group; bool shown; + #if !defined(GD_NO_WX_GUI) wxBitmap smallicon; #endif diff --git a/Core/GDCore/Events/ExpressionsCodeGeneration.cpp b/Core/GDCore/Events/ExpressionsCodeGeneration.cpp index 8f7528d497..fa88463063 100644 --- a/Core/GDCore/Events/ExpressionsCodeGeneration.cpp +++ b/Core/GDCore/Events/ExpressionsCodeGeneration.cpp @@ -75,7 +75,13 @@ void CallbacksForGeneratingExpressionCode::OnStaticFunction(string functionName, parametersStr += parametersCode[i]; } + if(GetReturnType() == "string" && !expressionInfo.returnUtf8) + plainExpression += "utf8::FromLocaleString("; //Add the conversion function if the expression returns locale strings + plainExpression += expressionInfo.codeExtraInformation.functionCallName+"("+parametersStr+")"; + + if(GetReturnType() == "string" && !expressionInfo.returnUtf8) + plainExpression += ")"; }; void CallbacksForGeneratingExpressionCode::OnObjectFunction(string functionName, const std::vector & parameters, const gd::ExpressionMetadata & expressionInfo) @@ -115,7 +121,13 @@ void CallbacksForGeneratingExpressionCode::OnObjectFunction(string functionName, output = codeGenerator.GenerateObjectFunctionCall(realObjects[i], objInfo, expressionInfo.codeExtraInformation, parametersStr, output, context); } + if(GetReturnType() == "string" && !expressionInfo.returnUtf8) + plainExpression += "utf8::FromLocaleString("; //Add the conversion function if the expression returns locale strings + plainExpression += output; + + if(GetReturnType() == "string" && !expressionInfo.returnUtf8) + plainExpression += ")"; }; void CallbacksForGeneratingExpressionCode::OnObjectAutomatismFunction(string functionName, const std::vector & parameters, const gd::ExpressionMetadata & expressionInfo) @@ -156,7 +168,13 @@ void CallbacksForGeneratingExpressionCode::OnObjectAutomatismFunction(string fun output = codeGenerator.GenerateObjectAutomatismFunctionCall(realObjects[i], parameters[1].GetPlainString(), autoInfo, expressionInfo.codeExtraInformation, parametersStr, output, context); } + if(GetReturnType() == "string" && !expressionInfo.returnUtf8) + plainExpression += "utf8::FromLocaleString("; //Add the conversion function if the expression returns locale strings + plainExpression += output; + + if(GetReturnType() == "string" && !expressionInfo.returnUtf8) + plainExpression += ")"; }; bool CallbacksForGeneratingExpressionCode::OnSubMathExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::Expression & expression) diff --git a/Core/GDCore/Events/InstructionMetadata.cpp b/Core/GDCore/Events/InstructionMetadata.cpp index 3c87ac1da4..bad33b491b 100644 --- a/Core/GDCore/Events/InstructionMetadata.cpp +++ b/Core/GDCore/Events/InstructionMetadata.cpp @@ -54,6 +54,7 @@ usageComplexity(5) ParameterMetadata::ParameterMetadata() : optional(false), +canUseUtf8(true), codeOnly(false) { } diff --git a/Core/GDCore/Events/InstructionMetadata.h b/Core/GDCore/Events/InstructionMetadata.h index 00d03443ce..b5245049a6 100644 --- a/Core/GDCore/Events/InstructionMetadata.h +++ b/Core/GDCore/Events/InstructionMetadata.h @@ -50,6 +50,11 @@ public: */ bool IsOptional() const { return optional; } + /** + * \brief Return true if the parameter can receive an UTF8 string. + */ + bool CanUseUtf8() const { return canUseUtf8; } + /** * \brief Return the description of the parameter */ @@ -69,6 +74,7 @@ public: std::string type; ///< Parameter type std::string supplementaryInformation; ///< Used if needed bool optional; ///< True if the parameter is optional + bool canUseUtf8; ///< True if the parameter can receive an UTF8 string std::string description; ///< Description shown in editor bool codeOnly; ///< True if parameter is relative to code generation only, i.e. must not be shown in editor @@ -176,6 +182,17 @@ public: return *this; }; + /** + * \brief Declare the last added parameter not able to receivre UTF8 strings. + * + * \see AddParameter + */ + InstructionMetadata & CantUseUtf8() + { + if ( !parameters.empty() ) parameters.back().canUseUtf8 = false; + return *this; + }; + /** * \brief Consider that the instruction is easy for an user to understand. */ diff --git a/Extensions/TextObject/Extension.cpp b/Extensions/TextObject/Extension.cpp index fd496eac17..82d5922cfb 100644 --- a/Extensions/TextObject/Extension.cpp +++ b/Extensions/TextObject/Extension.cpp @@ -64,7 +64,7 @@ void DeclareTextObjectExtension(gd::PlatformExtension & extension) "res/actions/font24.png", "res/actions/font.png") .AddParameter("object", _("Object"), "Text", false) - .AddParameter("police", _("Font")) + .AddParameter("police", _("Font")).CantUseUtf8() .codeExtraInformation.SetFunctionName("ChangeFont").SetIncludeFile("TextObject/TextObject.h"); obj.AddAction("Size", diff --git a/Extensions/TextObject/TextObject.cpp b/Extensions/TextObject/TextObject.cpp index df17ac37c5..d58fdb597c 100644 --- a/Extensions/TextObject/TextObject.cpp +++ b/Extensions/TextObject/TextObject.cpp @@ -274,7 +274,7 @@ void RuntimeTextObject::ChangeFont(const std::string & fontName_) { if ( !text.getFont() || fontName_ != fontName ) { - fontName = utf8::ToLocaleString(fontName_); ///< TODO : Remove and find a way to tell if instructions want locale strings or utf8 strings + fontName = fontName_; text.setFont(*FontManager::Get()->GetFont(fontName)); text.setOrigin(text.getLocalBounds().width/2, text.getLocalBounds().height/2); OnPositionChanged(); diff --git a/GDCpp/GDCpp/Events/EventsCodeGenerator.cpp b/GDCpp/GDCpp/Events/EventsCodeGenerator.cpp index 9351ecc461..833963c804 100644 --- a/GDCpp/GDCpp/Events/EventsCodeGenerator.cpp +++ b/GDCpp/GDCpp/Events/EventsCodeGenerator.cpp @@ -402,7 +402,15 @@ std::string EventsCodeGenerator::GenerateParameterCodes(const std::string & para } } else - return gd::EventsCodeGenerator::GenerateParameterCodes(parameter, metadata, context, previousParameter, supplementaryParametersTypes); + { + if( !metadata.canUseUtf8 ) + argOutput = "utf8::ToLocaleString("; //Add the conversion function for string parameters which doesn't support UTF8 + + argOutput += gd::EventsCodeGenerator::GenerateParameterCodes(parameter, metadata, context, previousParameter, supplementaryParametersTypes); + + if( !metadata.canUseUtf8 ) + argOutput += ")"; //End of the conversion function + } return argOutput; } @@ -422,7 +430,7 @@ string EventsCodeGenerator::GenerateSceneEventsCompleteCode(gd::Project & projec //Generate default code around events: //Includes - output += "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \"GDCpp/RuntimeContext.h\"\n#include \"GDCpp/RuntimeObject.h\"\n"; + output += "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \"GDCpp/RuntimeContext.h\"\n#include \"GDCpp/Utf8Tools.h\"\n#include \"GDCpp/RuntimeObject.h\"\n"; for ( set::iterator include = codeGenerator.GetIncludeFiles().begin() ; include != codeGenerator.GetIncludeFiles().end(); ++include ) output += "#include \""+*include+"\"\n";