1.

#ifndef SuperRichText_hpp

#define SuperRichText_hpp

#include <stdio.h>

#include "cocos2d.h"

#include "ui/UIRichText.h"

#include "tinyxml2/tinyxml2.h"

USING_NS_CC;

struct FontInfo{

std::string fontName;

float fontSize;

Color3B color;

GLubyte opacity;

};

class SuperRichText:public ui::Widget

{

protected:

std::vector<FontInfo> _fontList;

std::vector<ui::RichText*> _lineList;

ui::RichText* _line;

public:

SuperRichText();

virtual ~SuperRichText();

CREATE_FUNC(SuperRichText);

virtual void renderHtml(const char* html);

virtual void renderNode(tinyxml2::XMLNode* node);

void addNewLine();

void updateLine();

};

#endif /* SuperRichText_hpp */

#include "SuperRichText.hpp"

SuperRichText::SuperRichText(){

FontInfo defaultFont;

defaultFont.color=Color3B(255,255,255);

defaultFont.fontSize=24.0f;

defaultFont.opacity=255;

defaultFont.fontName="";

_fontList.push_back(defaultFont);

addNewLine();

}

SuperRichText::~SuperRichText(){

this->removeAllChildren();

}

void SuperRichText::renderHtml(const char *html){

tinyxml2::XMLDocument xml;

xml.Parse(html);

renderNode(xml.FirstChild());

updateLine();

}

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

while (node!=nullptr) {

if (node->ToText()) {

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

}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("字体标签");

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

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

CCLOG("图片标签");

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

CCLOG("换行标签");

}

}

node=node->NextSibling();

}

}

void SuperRichText::addNewLine(){

_line=ui::RichText::create();

_lineList.push_back(_line);

addChild(_line);

}

void SuperRichText::updateLine(){

}

2.

bool HelloWorld::init()

{

if ( !Layer::init() )

{

return false;

}

Size visibleSize = Director::getInstance()->getVisibleSize();

Vec2 origin = Director::getInstance()->getVisibleOrigin();

auto richText=SuperRichText::create();

richText->setPosition(visibleSize/2);

richText->renderHtml("\

<font color='ffffff' size='60' opacity='255'>\

你好<img src='CloseNormal.png'/>daochong\

<br/>\

</font>");

return true;

}

cocos2d-x之利用富文本控件遍历xml的更多相关文章

  1. cocos2d-x之 利用富文本控件解析xhml标签(文字标签,图片标签,换行标签,标签属性)

    执行后效果: 前端使用: 后台SuperRichText解析code void SuperRichText::renderNode(tinyxml2::XMLNode *node){ while (n ...

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

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

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

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

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

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

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

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

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

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

  9. Android开发:文本控件详解——TextView(一)基本属性

    一.简单实例: 新建的Android项目初始自带的Hello World!其实就是一个TextView. 在activity_main.xml中可以新建TextView,从左侧组件里拖拽到右侧预览界面 ...

随机推荐

  1. SQL Server 诊断查询-(5)

    Query #57 Buffer Usage -- Breaks down buffers used by current database by object (table, index) in t ...

  2. Entity FrameWork 延迟加载的本质(一)

    1.集合的标准查询运算符方法,是来自于System.Linq.Enumerable里给IEnumerable接口添加的扩展方法 2.EF上下文里的DBSet<T>里的标准查询运算符方法,来 ...

  3. 设计模式--适配器(Adapter)模式

    今天学习另一个设计模式,适配器(Adapter)模式,这是一个共同方向,但有特殊要求,就应用到此设计模式.写到这里,想起很久以前,有写过一篇<ASP.NET的适配器设计模式(Adapter)&g ...

  4. android图片拖动缩放

    这篇图片拖拽缩放也是我在项目中用到的,今天整理一下,将源码奉献给大家,希望对大家以后碰到相似的问题有帮助.android 大图片拖拽缩放 这篇就不做过多介绍了,直接上源码: public class ...

  5. 关于iPhone多点触控

    虽然这个问题很简单,但是对于我这接触两天的菜鸟来说也弄了很久,网上又找不到相关的解决方法,避免其他人和我一样,还是记录一下 一般网上找到的教程是这么教: -(void )touchesBegin:(N ...

  6. HTML5实现屏幕手势解锁(转载)

    来源:https://github.com/lvming6816077/H5lockhttp://threejs.org/examples/http://www.inf.usi.ch/phd/wett ...

  7. C# 发邮件

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  8. 一些java的书籍

    netty in action 中文版:http://pan.baidu.com/s/1pLnEKZL spring security-3.0.1:http://pan.baidu.com/s/1bp ...

  9. PHP Warning: Module 'modulename' already loaded in Unknown on line 0

    问题 当在命令行运行PHP的CLI版本时,您可能会收到类似以下错误: [root@myserver /root]$ php -v PHP Warning: Module 'pcre' already ...

  10. css中的定位和框模型问题

    和定位有关的元素属性如下 position  元素的定位类型   绝对定位会相对于最近定位的祖先元素的位置来定位,而不会影响其他框的位置 固定定位 相对定位 z-index   元素的堆叠顺序 值越大 ...