执行后效果:

前端使用:

后台SuperRichText解析code

void SuperRichText::renderNode(tinyxml2::XMLNode *node){

while (node!=nullptr) {

if (node->ToText()) {

CCLOG("文本信息:%s",node->ToText()->Value());

auto n=node->ToText();

std::u16string text;

StringUtils::UTF8ToUTF16(n->Value(),text);

std::u16string::size_type pos=0;

pos=text.find('\n');

while ((pos!=std::u16string::npos)) {

text.erase(pos,1);

pos=text.find('\n',pos);

}

pos=0;

pos=text.find('\r');

while ((pos!=std::u16string::npos)) {

text.erase(pos,1);

pos=text.find('\r',pos);

}

std::string utf8Text;

StringUtils::UTF16ToUTF8(text,utf8Text);

auto font=_fontList[_fontList.size()-1];

auto textElement=ui::RichElementText::create(0,font.color,font.opacity,utf8Text,font.fontName,font.fontSize);

_line->pushBackElement(textElement);

}else if (node->ToElement()){

auto n=node->ToElement();

std::string name=n->Name();

std::transform(name.begin(),name.end(),name.begin(),::toupper);

if (name=="FONT") {

CCLOG("字体标签");

auto attr=n->FirstAttribute();

FontInfo newFont=_fontList[_fontList.size()-1];

while (attr!=nullptr) {

//遍历所有属性

std::string attrName=attr->Name();

std::transform(attrName.begin(),attrName.end(),attrName.begin(),::toupper);

if (attrName=="FACE") {

//设置字体

newFont.fontName=attr->Value();

}else if (attrName=="COLOR"){

//设置颜色

newFont.color=charToColor3B(attr->Value());

}else if(attrName=="SIZE"){

//设置大小

newFont.fontSize=attr->IntValue();

}else if (attrName=="OPACITY"){

//设置不透明度

newFont.opacity=attr->IntValue();

}

attr=attr->Next();

}

_fontList.push_back(newFont);//添加新字体

renderNode(n->FirstChild());//继续渲染子集

_fontList.pop_back();//移除新字体

}else if (name=="IMG") {

CCLOG("图片标签");

//图片标签的属性

auto attr=n->FirstAttribute();

const char *src;

Color3B col(255,255,255);

GLubyte opacity=255;

while (attr!=nullptr) {

//遍历所有属性

std::string attrName=attr->Name();

std::transform(attrName.begin(),attrName.end(),attrName.begin(),::toupper);

if (attrName=="SRC") {

//设置图片路径

src=attr->Value();

}else if (attrName=="COLOR"){

//设置颜色

col=charToColor3B(attr->Value());

}else if (attrName=="OPACITY"){

//设置不透明度

opacity=attr->IntValue();

}

attr=attr->Next();

}

auto img=ui::RichElementImage::create(0,col,opacity,src);

_line->pushBackElement(img);

}else if (name=="BR") {

CCLOG("换行标签");

addNewLine();

}

}

node=node->NextSibling();

}

}

cocos2d-x之 利用富文本控件解析xhml标签(文字标签,图片标签,换行标签,标签属性)的更多相关文章

  1. cocos2d-x之利用富文本控件遍历xml

    1. #ifndef SuperRichText_hpp #define SuperRichText_hpp #include <stdio.h> #include "cocos ...

  2. ASP.NET MVC 页面使用富文本控件的XSS漏洞问题

    目前在做的项目存在XSS安全漏洞! 原因是有一些页面使用了富文本编辑框,为了使得其内容可以提交,为相关action设置了[ValidateInput(false)] 特性: [HttpPost] [V ...

  3. ASP.NET MVC或者.net Core mvc 页面使用富文本控件的 保存问题

    https://blog.csdn.net/leftfist/article/details/69629394 目前在做的项目存在XSS安全漏洞! 原因是有一些页面使用了富文本编辑框,为了使得其内容可 ...

  4. MFC入门(三)-- MFC图片/文字控件(循环显示文字和图片的小程序)

    惯例附上前几个博客的链接: MFC入门(一)简单配置:http://blog.csdn.net/zmdsjtu/article/details/52311107 MFC入门(二)读取输入字符:http ...

  5. [寒江孤叶丶的Cocos2d-x之旅_33]RichTextEx一款通过HTML标签控制文字样式的富文本控件

    RichTextEx一款通过HTML标签控制文字样式的富文本控件 原创文章,欢迎转载.转载请注明:文章来自[寒江孤叶丶的Cocos2d-x之旅系列] 博客地址:http://blog.csdn.net ...

  6. 解决方案:带格式化文本控件( RichText)的模板如果在InfoPath的浏览器中加载可能出现 COM 组件的80040154错误

      建议大家在微软的组件出现问题时,在GOOGLE上搜索解决方案,一般来说,总有结果:  带格式化文本控件( RichText)的模板如果在InfoPath的浏览器中加载,可能出现 COM 组件的80 ...

  7. WCF学习(二)对控件简单了解以及4个文本控件的简介

    WPF基础控件 系统默认提供的基础控件: 文本控件介绍与用法 Label控件 label控件:一般用户描述性文字显示. 在Label控件使用时,一般给予用户提示.用法上没有什么很特殊的,label控件 ...

  8. 重新想象 Windows 8 Store Apps (1) - 控件之文本控件: TextBlock, TextBox, PasswordBox, RichEditBox, RichTextBlock, RichTextBlockOverflow

    原文:重新想象 Windows 8 Store Apps (1) - 控件之文本控件: TextBlock, TextBox, PasswordBox, RichEditBox, RichTextBl ...

  9. wxPython中按钮、文本控件的简单运用

    本节学习图形用户界面 ------------------------ 本节介绍如何创建python程序的图形用户界面(GUI),也就是那些带有按钮和文本框的窗口.这里介绍wxPython : 下载地 ...

随机推荐

  1. 如何安装node.js支持插件

    在eclipse插件中,node.js插件中比较知名的是nodeclipse. 从HBuilder6.3起,工具-插件安装,可直接选择nodeclipse插件安装.安装完毕后重启HBuilder新建n ...

  2. C++转换构造函数与类型转换构造函数

    转换构造函数: 转换构造函数的只有一个形参: Student(float s) { score = s; age = ; } 如果已经在上面定义了构造函数: Student(); //建立对象c1,由 ...

  3. SQL join中on与where区别

    本文导读: 数据库在通过连接两张或多张表来返回记录时,都会生成一张中间的临时表,然后再将这张临时表返回给用户.例如在使用left jion时,on条件是在生成临时表时使用的条件,它不管on中的条件是否 ...

  4. Servlet获取request的变量方法.

    1.String   localAddr = request.getLocalAddr();   // 获取本地IP,即服务器 IP 2.setAttribute(String name,Object ...

  5. jstl标签2

    我们前面讲的是ArrayList集合迭代,Hashmap/Hashset的情况下 举例: <h3>对map和set的迭代</h3> 放入字符串 <% //模拟 Map m ...

  6. SQL查询数据的几大方法

    有你,查询数据我什么都不怕.快快掌握!! 出大招的工具: 1.使用LIKE.BETWEEN.IN进行模糊查询 eg1: SELECT * FROM Students WHERE 姓名 like '张% ...

  7. atom编辑markdown之上传图片

    01atom编辑markdown之上传图片 :first-child { margin-top: 0px; } .markdown-preview:not([data-use-github-style ...

  8. 原生JS:String对象详解

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  9. ie7下<a></a>标签中<input />时不反应

    <a href="News?id=@dr["id"].CInt()" ><input type="button" valu ...

  10. Ridge Regression(岭回归)

    Ridge Regression岭回归 数值计算方法的"稳定性"是指在计算过程中舍入误差是可以控制的. 对于有些矩阵,矩阵中某个元素的一个很小的变动,会引起最后计算结果误差很大,这 ...