本文整理汇总了C++中TagStack::pushNew方法的典型用法代码示例。如果您正苦于以下问题:C++ TagStack::pushNew方法的具体用法?C++ TagStack::pushNew怎么用?C++ TagStack::pushNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TagStack
的用法示例。
在下文中一共展示了TagStack::pushNew方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
string RTFGenParser::parse(const QString &text)
{
res = "";
m_res_size = 0;
m_codec = getContacts()->getCodec(m_contact);
int charset = 0;
for (const ENCODING *c = getContacts()->getEncodings(); c->language; c++){
if (!strcasecmp(c->codec, m_codec->name())){
charset = c->rtf_code;
break;
}
}
#ifdef WIN32
if ((charset == 0) && !strcasecmp(m_codec->name(), "system")){
char buff[256];
int res = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, (char*)&buff, sizeof(buff));
if (res){
unsigned codepage = atol(buff);
if (codepage){
for (const rtf_cp *c = rtf_cps; c->cp; c++){
if (c->cp == codepage)
charset = c->charset;
}
}
}
}
#endif
unsigned ansicpg = 0;
const char *send_encoding = 0;
m_codec = NULL;
if (charset){
for (const ENCODING *c = getContacts()->getEncodings(); c->language; c++){
if ((c->rtf_code == charset) && c->bMain){
send_encoding = c->codec;
m_codec = getContacts()->getCodecByName(send_encoding);
ansicpg = c->cp_code;
break;
}
}
}
// Add defaults to the tables
m_fontFaces.push_back("MS Sans Serif");
m_colors.push_back(m_foreColor);
// Create a "fake" tag which'll serve as the default style
CharStyle style;
style.faceIdx = 0;
style.colorIdx = 1; // colors are 1-based (0 = default)
style.sizePt = 12; // default according to Microsoft
Tag& tag = *(m_tags.pushNew());
tag.setCharStyle(style);
// Assume we go immediately after a tag.
m_bSpace = true;
HTMLParser::parse(text);
string s;
s = "{\\rtf1\\ansi";
if (ansicpg){
s += "\\ansicpg";
s += number(ansicpg);
}
s += "\\deff0\r\n";
s += "{\\fonttbl";
unsigned n = 0;
for (list<QString>::iterator it_face = m_fontFaces.begin(); it_face != m_fontFaces.end(); it_face++, n++){
s += "{\\f";
s += number(n);
QString face = (*it_face);
if (face.find("Times") >= 0){
s += "\\froman";
}else if (face.find("Courier") >= 0){
s += "\\fmodern";
}else{
s += "\\fswiss";
}
if (charset){
s += "\\fcharset";
s += number(charset);
}
s += " ";
int pos = face.find(QRegExp(" +["));
if (pos > 0)
face = face.left(pos);
s += static_cast<string>(face.toLatin1());
s += ";}";
}
s += "}\r\n";
s += "{\\colortbl ;";
for (list<QColor>::iterator it_colors = m_colors.begin(); it_colors != m_colors.end(); ++it_colors){
QColor c = *it_colors;
s += "\\red";
s += number(c.red());
s += "\\green";
s += number(c.green());
s += "\\blue";
s += number(c.blue());
s += ";";
}
s += "}\r\n";
//.........这里部分代码省略.........
示例2: tag_start
//.........这里部分代码省略.........
// Process attributes which all tags share.
for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){
QString name = (*it).lower();
++it;
QString value = (*it);
// Any tag might have a STYLE.
if (name == "style"){
// A really crude CSS parser goes here:
QRegExp cssReNum("[0-9]+");
list<QString> cssProp = parseStyle(value);
for (list<QString>::iterator it = cssProp.begin(); it != cssProp.end(); ++it){
QString cssPropName = *it;
++it;
if (it == cssProp.end())
break;
QString cssPropValue = *it;
if (cssPropName == "font-family")
{
style.faceIdx = getFontFaceIdx(cssPropValue);
}
else if (cssPropName == "font-size")
{
cssPropValue = cssPropValue.lower();
int length;
if (cssReNum.indexIn(cssPropValue, 0) == 0){
length = cssReNum.matchedLength();
float number = cssPropValue.left(length).toFloat();
QString type = cssPropValue.mid(length);
if (type == "pt")
{
style.sizePt = static_cast<int>(number);
}
else if (type == "px")
{
// for now, handle like 'pt', though it's wrong
style.sizePt = static_cast<int>(number);
}
else if (type == "%")
{
style.sizePt = static_cast<int>(parentStyle.sizePt * (number/100));
}
// We don't handle 'cm', 'em' etc.
}
else if (cssPropValue == "smaller")
{
// FONT SIZE=3 is 'normal', 2 is 'smaller'
style.sizePt = htmlFontSizeToPt(2, parentStyle.sizePt);
}
else if (cssPropValue == "larger")
{
// FONT SIZE=3 is 'normal', 4 is 'larger'
style.sizePt = htmlFontSizeToPt(4, parentStyle.sizePt);
}
// We don't handle 'small', 'medium' etc. It goes too far
// beyond our basic implementation.
// Also, empty 'type' would be invalid CSS, thus ignored.
}
else if (cssPropName == "font-style")
{
style.italic = (cssPropValue.lower() == "italic");
}
else if (cssPropName == "font-weight")
{
style.bold = (cssPropValue.toInt() >= 600);
}
else if (cssPropName == "text-decoration")
{
style.underline = (cssPropValue.lower() == "underline");
}
else if (cssPropName == "color")
{
style.colorIdx = getColorIdx(cssPropValue);
}
else if (cssPropName == "background-color")
{
style.bgColorIdx = getColorIdx(cssPropValue);
}
}
}
}
Tag& tag = *(m_tags.pushNew());
tag.name = tagName;
// Check if anything changed in the style.
// Only then the tag deserves getting a charStyle.
if (parentStyle != style)
{
QString rtf = style.getDiffRTF(parentStyle);
if (!rtf.isEmpty())
{
res += static_cast<string>(rtf.toUtf8());
m_bSpace = true;
}
tag.setCharStyle(style);
}
}
示例3: tag_start
//.........这里部分代码省略.........
}
// Process attributes which all tags share.
for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){
QString name = (*it).lower();
++it;
QString value = (*it);
// Any tag might have a STYLE.
if (name == "style"){
// A really crude CSS parser goes here:
QRegExp cssReNum("[0-9]+");
list<QString> cssProp = parseStyle(value);
for (list<QString>::iterator it = cssProp.begin(); it != cssProp.end(); ++it){
QString cssPropName = *it;
++it;
if (it == cssProp.end())
break;
QString cssPropValue = *it;
if (cssPropName == "font-family")
{
style.faceIdx = getFontFaceIdx(cssPropValue);
}
else if (cssPropName == "font-size")
{
cssPropValue = cssPropValue.lower();
int length;
if (cssReNum.match(cssPropValue, 0, &length) == 0){
float number = cssPropValue.left(length).toFloat();
QString type = cssPropValue.mid(length);
if (type == "pt")
{
style.sizePt = static_cast<int>(number);
}
else if (type == "px")
{
// for now, handle like 'pt', though it's wrong
style.sizePt = static_cast<int>(number);
}
else if (type == "%")
{
style.sizePt = static_cast<int>(parentStyle.sizePt * (number/100));
}
// We don't handle 'cm', 'em' etc.
}
else if (cssPropValue == "smaller")
{
// FONT SIZE=3 is 'normal', 2 is 'smaller'
style.sizePt = htmlFontSizeToPt(2, parentStyle.sizePt);
}
else if (cssPropValue == "larger")
{
// FONT SIZE=3 is 'normal', 4 is 'larger'
style.sizePt = htmlFontSizeToPt(4, parentStyle.sizePt);
}
// We don't handle 'small', 'medium' etc. It goes too far
// beyond our basic implementation.
// Also, empty 'type' would be invalid CSS, thus ignored.
}
else if (cssPropName == "font-style")
{
style.italic = (cssPropValue.lower() == "italic");
}
else if (cssPropName == "font-weight")
{
style.bold = (cssPropValue.toInt() >= 600);
}
else if (cssPropName == "text-decoration")
{
style.underline = (cssPropValue.lower() == "underline");
}
else if (cssPropName == "color")
{
style.colorIdx = getColorIdx(cssPropValue);
}
else if (cssPropName == "background-color")
{
style.bgColorIdx = getColorIdx(cssPropValue);
}
}
}
}
Tag& tag = *(m_tags.pushNew());
tag.name = tagName;
// Check if anything changed in the style.
// Only then the tag deserves getting a charStyle.
if (parentStyle != style)
{
QString rtf = style.getDiffRTF(parentStyle);
if (!rtf.isEmpty())
{
res += rtf.utf8();
m_bSpace = true;
}
tag.setCharStyle(style);
}
}