2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "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-21 10:12:00 +08:00
|
|
|
#include "CocoLoader.h"
|
|
|
|
#include "CSParseBinary_generated.h"
|
|
|
|
#include "LocalizationManager.h"
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
#include "flatbuffers/flatbuffers.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2019-11-24 23:15:56 +08:00
|
|
|
using namespace ui;
|
|
|
|
using namespace flatbuffers;
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
static RichTextReader* instanceTextBMFontReader = nullptr;
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS_NODE_READER_INFO(RichTextReader)
|
|
|
|
|
|
|
|
RichTextReader::RichTextReader() {}
|
|
|
|
|
|
|
|
RichTextReader::~RichTextReader() {}
|
|
|
|
|
|
|
|
RichTextReader* RichTextReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceTextBMFontReader)
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
instanceTextBMFontReader = new RichTextReader();
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return instanceTextBMFontReader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RichTextReader::destroyInstance()
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(instanceTextBMFontReader);
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view name = attribute.name();
|
|
|
|
std::string_view value = attribute.value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "XmlDefinition")
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
xmlDefinition = value;
|
|
|
|
break;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
/*else if (name == "IsLocalized")
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
isLocalized = (value == "True") ? true : false;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto options = CreateRichTextOptions(*builder,
|
2019-11-24 23:15:56 +08:00
|
|
|
widgetOptions,
|
|
|
|
builder->CreateString(xmlDefinition)/*,
|
|
|
|
isLocalized*/);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
return *(Offset<Table>*)(&options);
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void RichTextReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* richTextOptions)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
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);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Node* RichTextReader::createNodeWithFlatBuffers(const flatbuffers::Table* options)
|
|
|
|
{
|
|
|
|
Node* node = nullptr;
|
|
|
|
// #Hack
|
|
|
|
setPropsWithFlatBuffers((Node*)(&node), (Table*)options);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cocostudio
|