2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
#include "libccs30/WidgetReader/RichTextReader/RichTextReader.h"
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
#include "2d/CCFontAtlasCache.h"
|
|
|
|
#include "ui/UIRichText.h"
|
|
|
|
#include "platform/CCFileUtils.h"
|
2020-10-17 16:32:16 +08:00
|
|
|
#include "libeditor/CocoLoader.h"
|
|
|
|
#include "libccs30/CSParseBinary_generated.h"
|
|
|
|
#include "libccs30/LocalizationManager.h"
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
#include "flatbuffers/flatbuffers.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace ui;
|
|
|
|
using namespace flatbuffers;
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
static RichTextReader* instanceTextBMFontReader = nullptr;
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS_NODE_READER_INFO(RichTextReader)
|
|
|
|
|
|
|
|
RichTextReader::RichTextReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RichTextReader::~RichTextReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RichTextReader* RichTextReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceTextBMFontReader)
|
|
|
|
{
|
|
|
|
instanceTextBMFontReader = new (std::nothrow) RichTextReader();
|
|
|
|
}
|
|
|
|
return instanceTextBMFontReader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RichTextReader::destroyInstance()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(instanceTextBMFontReader);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Offset<Table> RichTextReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
|
|
|
|
flatbuffers::FlatBufferBuilder *builder)
|
|
|
|
{
|
|
|
|
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
|
|
|
auto widgetOptions = *(Offset<WidgetOptions>*)(&temp);
|
|
|
|
|
|
|
|
std::string xmlDefinition = "RichText";
|
|
|
|
// bool isLocalized = false;
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
auto attribute = objectData.first_attribute();
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
std::string name = attribute.name();
|
|
|
|
std::string value = attribute.value();
|
|
|
|
|
|
|
|
if (name == "XmlDefinition")
|
|
|
|
{
|
|
|
|
xmlDefinition = value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*else if (name == "IsLocalized")
|
|
|
|
{
|
|
|
|
isLocalized = (value == "True") ? true : false;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto options = CreateRichTextOptions(*builder,
|
|
|
|
widgetOptions,
|
|
|
|
builder->CreateString(xmlDefinition)/*,
|
|
|
|
isLocalized*/);
|
|
|
|
|
|
|
|
return *(Offset<Table>*)(&options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RichTextReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table * richTextOptions)
|
|
|
|
{
|
|
|
|
auto ppnode = (Node**)(node);
|
|
|
|
auto options = (RichTextOptions*)richTextOptions;
|
|
|
|
|
|
|
|
auto implNode = ui::RichText::createWithXML(options->xmlDefinition()->c_str());
|
|
|
|
*ppnode = implNode;
|
|
|
|
|
|
|
|
auto widgetReader = WidgetReader::getInstance();
|
|
|
|
widgetReader->setPropsWithFlatBuffers(implNode, (Table*)options->widgetOptions());
|
|
|
|
|
|
|
|
// implNode->ignoreContentAdaptWithSize(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* RichTextReader::createNodeWithFlatBuffers(const flatbuffers::Table *options)
|
|
|
|
{
|
|
|
|
Node* node = nullptr;
|
|
|
|
// #Hack
|
|
|
|
setPropsWithFlatBuffers((Node*)(&node), (Table*)options);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|