Esempio n. 1
0
void SpellHighlighter::tag_start(const QString &tag, const list<QString> &opt)
{
    if ((tag == "img") || (tag == "br")){
        flush();
        m_pos++;
    }
    if (tag == "span"){
        m_fonts.push(m_bError);
        QString key;
        QString val;
        list<QString>::const_iterator it;
        for (it = opt.begin(); it != opt.end(); ++it){
            key = (*it);
            ++it;
            val = (*it);
            if (key == "style")
                break;
        }
        if (it != opt.end()){
            list<QString> styles = parseStyle(val);
            for (it = styles.begin(); it != styles.end(); ++it){
                key = (*it);
                ++it;
                val = (*it);
                if ((key == "color") && (val.lower() == "#ff0101")){
                    m_bError = true;
                    break;
                }
            }
        }
    }
}
Esempio n. 2
0
void KHTMLReader::parseNode(DOM::Node node)
{

    // check if this is a text node.
    DOM::Text t = node;
    if (!t.isNull()) {
        _writer->addText(state()->paragraph, t.data().string(), 1, state()->in_pre_mode);
        return; // no children anymore...
    }

    // is this really needed ? it can't do harm anyway.
    state()->format = _writer->currentFormat(state()->paragraph, true);
    state()->layout = _writer->currentLayout(state()->paragraph);
    pushNewState();

    DOM::Element e = node;

    bool go_recursive = true;

    if (!e.isNull()) {
        // get the CSS information
        parseStyle(e);
        // get the tag information
        go_recursive = parseTag(e);
    }
    if (go_recursive) {
        for (DOM::Node q = node.firstChild(); !q.isNull(); q = q.nextSibling()) {
            parseNode(q);
        }
    }
    popState();


}
Esempio n. 3
0
static void
parseStyle (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  xmlChar *content;
  xmlChar *prop;
  int start = fb->utf8_current_index;

  prop = xmlGetProp(cur, (const xmlChar *)"name");

  cur = cur->children;

  while (cur != NULL) {

    if (xmlNodeIsText(cur)) {
      content = xmlNodeGetContent(cur);
      if (content)
	bufferAppend(content, xmlStrlen(content), fb);
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"style")) {
      parseStyle(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"strong")) {
      content = xmlNodeGetContent(cur->children);
      if (content) {
	int st = fb->utf8_current_index;
	bufferAppend(content, xmlStrlen(content), fb);
	addMark(st, fb->utf8_current_index, STRONG_TYPE, NULL, fb);
      }
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"emphasis")) {
      content = xmlNodeGetContent(cur->children);
      if (content) {
	int st = fb->utf8_current_index;
	bufferAppend(content, xmlStrlen(content), fb);
	addMark(st, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb);
      }
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"a")) {
      parseLink(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"image")) {
      parseImage(doc, cur, fb);

    }

    cur = cur->next;
  }

  if (prop && (!xmlStrcmp(prop, (const xmlChar *)"italic"))) {
    addMark(start, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb);
    xmlFree(prop);
  }

  return;
}
Esempio n. 4
0
void TextStyleState::readAllStyles(const Common::String &txt) {
	int16 startTextPosition = -1;
	int16 endTextPosition = -1;

	for (uint16 i = 0; i < txt.size(); i++) {
		if (txt[i] == '<')
			startTextPosition = i;
		else if (txt[i] == '>') {
			endTextPosition = i;
			if (startTextPosition != -1) {
				if ((endTextPosition - startTextPosition - 1) > 0) {
					parseStyle(Common::String(txt.c_str() + startTextPosition + 1), endTextPosition - startTextPosition - 1);
				}
			}
		}

	}
}
Esempio n. 5
0
void YahooParser::tag_start(const QString &tag, const list<QString> &options)
{
    if (tag == "img") {
        QString src;
        for (list<QString>::const_iterator it = options.begin(); it != options.end(); ++it) {
            QString name = (*it);
            ++it;
            QString value = (*it);
            if (name == "src") {
                src = value;
                break;
            }
        }
        if (src.left(10) != "icon:smile")
            return;
        bool bOK;
        unsigned nSmile = src.mid(10).toUInt(&bOK, 16);
        if (!bOK)
            return;
        const smile *p = smiles(nSmile);
        if (p)
            text(p->paste);
        return;
    }
    if (tag == "br") {
        res += "\n";
        return;
    }
    style s = curStyle;
    s.tag = tag;
    tags.push(s);
    if (tag == "p") {
        if (!m_bFirst)
            res += "\n";
        m_bFirst = false;
    }
    if (tag == "font") {
        for (list<QString>::const_iterator it = options.begin(); it != options.end(); ++it) {
            QString name = *it;
            ++it;
            if (name == "color") {
                QColor c;
                c.setNamedColor(*it);
                s.color = c.rgb() & 0xFFFFFF;
            }
        }
    }
    if (tag == "b") {
        s.state |= 1;
        return;
    }
    if (tag == "i") {
        s.state |= 2;
        return;
    }
    if (tag == "u") {
        s.state |= 4;
        return;
    }
    for (list<QString>::const_iterator it = options.begin(); it != options.end(); ++it) {
        QString name = *it;
        ++it;
        if (name != "style")
            continue;
        list<QString> styles = parseStyle(*it);
        for (list<QString>::iterator its = styles.begin(); its != styles.end(); ++its) {
            QString name = *its;
            ++its;
            if (name == "color") {
                QColor c;
                c.setNamedColor(*its);
                s.color = c.rgb() & 0xFFFFFF;
            }
            if (name == "font-size") {
                unsigned size = atol((*its).latin1());
                if (size)
                    s.size = size;
            }
            if (name == "font-family")
                s.face = (*its);
            if (name == "font-weight")
                s.state &= ~1;
            if (atol((*its).latin1()) >= 600)
                s.state |= 1;
            if ((name == "font-style") && ((*its) == "italic"))
                s.state |= 2;
            if ((name == "text-decoration") && ((*its) == "underline"))
                s.state |= 4;
        }
    }
    set_style(s);
}
Esempio n. 6
0
KdmItem::KdmItem(QObject *parent, const QDomNode &node)
    : QObject(parent)
    , boxManager(0)
    , fixedManager(0)
    , myWidget(0)
    , m_showTypeInvert(false)
    , m_minScrWidth(0)
    , m_minScrHeight(0)
    , m_visible(true)
    , m_shown(true)
{
    QDomNode showNode = node.namedItem("show");
    if (!showNode.isNull()) {
        QDomElement sel = showNode.toElement();

        QString modes = sel.attribute("modes");
        if (!modes.isNull() &&
            (modes == "nowhere" ||
             (modes != "everywhere" &&
              !modes.split(",", QString::SkipEmptyParts).contains("console"))))
        {
            m_visible = false;
            return;
        }

        m_showType = sel.attribute("type");
        if (!m_showType.isNull()) {
            if (m_showType[0] == '!') {
                m_showType.remove(0, 1);
                m_showTypeInvert = true;
            }
            if (!m_showType.startsWith("plugin-") &&
                themer()->typeVisible(m_showType) == m_showTypeInvert)
            {
                m_visible = false;
                return;
            }
        }

        m_minScrWidth = sel.attribute("min-screen-width").toInt();
        m_minScrHeight = sel.attribute("min-screen-height").toInt();
    }

    // Set default layout for every item
    currentManager = MNone;
    geom.pos.x.type = geom.pos.y.type =
        geom.size.x.type = geom.size.y.type = DTnone;
    geom.minSize.x.type = geom.minSize.y.type =
        geom.maxSize.x.type = geom.maxSize.y.type = DTpixel;
    geom.minSize.x.val = geom.minSize.y.val = 0;
    geom.maxSize.x.val = geom.maxSize.y.val = 1000000;
    geom.anchor = "nw";
    geom.expand = 0;

    // Set defaults for derived item's properties
    state = Snormal;

    KdmItem *parentItem = qobject_cast<KdmItem *>(parent);
    if (!parentItem)
        style.frame = false, style.guistyle = 0;
    else
        style = parentItem->style;

    // Read the mandatory Pos tag. Other tags such as normal, prelighted,
    // etc.. are read under specific implementations.
    QDomNodeList childList = node.childNodes();
    for (int nod = 0; nod < childList.count(); nod++) {
        QDomNode child = childList.item(nod);
        QDomElement el = child.toElement();
        QString tagName = el.tagName();

        if (tagName == "pos") {
            parseSize(el.attribute("x", QString()), geom.pos.x);
            parseSize(el.attribute("y", QString()), geom.pos.y);
            parseSize(el.attribute("width", QString()), geom.size.x);
            parseSize(el.attribute("height", QString()), geom.size.y);
            parseSize(el.attribute("min-width", QString()), geom.minSize.x);
            parseSize(el.attribute("min-height", QString()), geom.minSize.y);
            parseSize(el.attribute("max-width", QString()), geom.maxSize.x);
            parseSize(el.attribute("max-height", QString()), geom.maxSize.y);
            geom.anchor = el.attribute("anchor", "nw");
            geom.expand = toBool(el.attribute("expand", "false"));
        } else if (tagName == "buddy") {
            buddy = el.attribute("idref", "");
        } else if (tagName == "style") {
            parseStyle(el, style);
        }
    }

    if (!style.font.present)
        parseFont("Sans 14", style.font);

    QDomElement el = node.toElement();
    setObjectName(el.attribute("id", QString::number((ulong)this, 16)));
    isButton = toBool(el.attribute("button", "false"));
    isBackground = toBool(el.attribute("background", "false"));
    QString screen = el.attribute("screen", isBackground ? "all" : "greeter");
    paintOnScreen =
        screen == "greeter" ? ScrGreeter :
        screen == "other" ? ScrOther : ScrAll;

    if (!parentItem)
        // The "toplevel" node (the screen) is really just like a fixed node
        setFixedLayout();
    else
        // Tell 'parent' to add 'me' to its children
        parentItem->addChildItem(this);
}
Esempio n. 7
0
void ViewParser::tag_start(const QString &tag, const list<QString> &attrs)
{
    // the tag that will be actually written out
    QString oTag = tag;

    if (m_bInHead)
        return;

    QString style;

    if (tag == "img"){
        QString src;
        for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){
            QString name = (*it).lower();
            ++it;
            QString value = *it;
            if (name == "src"){
                src = value;
                break;
            }
        }
        if (src.left(10) == "icon:smile"){
            bool bOK;
            unsigned nSmile = src.mid(10).toUInt(&bOK, 16);
            if (bOK){
                const smile *s = smiles(nSmile);
                if (s == NULL)
                    return;
                if (*s->exp == 0){
                    res += quoteString(s->paste);
                    return;
                }
            }
        }
    }else if (tag == "a"){
        m_bInLink = true;
    }else if (tag == "html"){ // we display as a part of a larger document
        return;
    }else if (tag == "head"){
        m_bInHead = 1;
        return;
    }else if (tag == "body"){ // we display as a part of a larger document
        oTag = "span";
    }else if (tag == "p"){
        bool bRTL = false;
        m_bParaEnd = false;
        for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){
            QString name = (*it).lower();
            ++it;
            QString value = *it;
            if ((name == "dir") && (value.lower() == "rtl"))
                bRTL = true;
        }
        if (m_bPara){
            if (bRTL == m_bRTL){
                res += "<br/>";
            }else{
                if (m_bParaStart)
                    res += "</p>";
                res += "<p dir=\"";
                res += bRTL ? "rtl" : "ltr";
                res += "\">";
                m_bParaStart = true;
            }
        }else{
            RTL     = bRTL;
            m_bRTL  = bRTL;
            m_bPara = true;
        }
        return;
    }
    if (m_bParaEnd){
        res += "<br/>";
        m_bParaEnd = false;
    }
    QString tagText;
    tagText += "<";
    tagText += oTag;
    for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){
        QString name = (*it).lower();
        ++it;
        QString value = *it;

        // Handling for attributes of specific tags.
        if (tag == "body"){
            if (name == "bgcolor"){
                style += "background-color:" + value + ";";
                continue;
            }
        }else if (tag == "font"){
            if (name == "color" && m_bIgnoreColors)
                continue;
        }

        // Handle for generic attributes.
        if (name == "style"){
            style += value;
            continue;
        }

        tagText += " ";
        tagText += name;
        if (!value.isEmpty()){
            tagText += "=\"";
            tagText += value;
            tagText += "\"";
        }
    }

    // Quite crude but working CSS to remove color styling.
    // It won't filter out colors as part of 'background', but life's tough.
    // (If it's any comfort, Qt probably won't display it either.)
    if (!style.isEmpty()){
        if (m_bIgnoreColors){
            list<QString> opt = parseStyle(style);
            list<QString> new_opt;
            for (list<QString>::iterator it = opt.begin(); it != opt.end(); ++it){
                QString name = *it;
                it++;
                if (it == opt.end())
                    break;
                QString value = *it;
                if ((name == "color") ||
                        (name == "background-color") ||
                        (name == "font-size") ||
                        (name == "font-style") ||
                        (name == "font-weight") ||
                        (name == "font-family"))
                    continue;
                new_opt.push_back(name);
                new_opt.push_back(value);
            }
            style = makeStyle(new_opt);
        }
        if (!style.isEmpty())
            tagText += " style=\"" + style + "\"";
    }
    tagText += ">";
    res += tagText;
}
Esempio n. 8
0
void ViewParser::tag_start(const QString &tag, const list<QString> &attrs)
{
    // the tag that will be actually written out
    QString oTag = tag;

    if (m_bInHead)
        return;

    QString style;

    if (tag == "img"){
        QString src;
        for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){
            QString name = (*it).lower();
            ++it;
            QString value = *it;
            if (name == "src"){
                src = value;
                break;
            }
        }
        if (src.left(10) == "icon:smile"){
            bool bOK;
            unsigned nSmile = src.mid(10).toUInt(&bOK, 16);
            if (bOK && (nSmile < 26)){
                QString s = def_smiles[nSmile];
                res += getIcons()->parseSmiles(s);
				return;
            }
        }
    }else if (tag == "a"){
        m_bInLink = true;
    }else if (tag == "p"){
        m_bInParagraph = true;
        m_paragraphDir = DirAuto;
    }else if (tag == "html"){ // we display as a part of a larger document
        return;
    }else if (tag == "head"){
        m_bInHead = 1;
        return;
    }else if (tag == "body"){ // we display as a part of a larger document
        oTag = "span";
    }

    QString tagText;
    tagText += "<";
    tagText += oTag;

    if (tag == "p")
    {
        m_paraDirInsertionPos = res.length() + tagText.length();
    }

    for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){
        QString name = (*it).lower();
        ++it;
        QString value = *it;

        // Handling for attributes of specific tags.
        if (tag == "body"){
            if (name == "bgcolor"){
                style += "background-color:" + value + ";";
                continue;
            }
        }else if (tag == "p"){
            if (name == "dir"){
                QString dir = value.lower();
                if (dir == "ltr")
                    m_paragraphDir = DirLTR;
                else if (dir == "rtl")
                    m_paragraphDir = DirRTL;
                else
                    m_paragraphDir = DirUnknown;
            }
        }else if (tag == "font"){
            if (name == "color" && m_bIgnoreColors)
                continue;
        }

        // Handle for generic attributes.
        if (name == "style"){
            style += value;
            continue;
        }

        tagText += " ";
        tagText += name;
        if (!value.isEmpty()){
            tagText += "=\"";
            tagText += value;
            tagText += "\"";
        }
    }

    // Quite crude but working CSS to remove color styling.
    // It won't filter out colors as part of 'background', but life's tough.
    // (If it's any comfort, Qt probably won't display it either.)
    if (!style.isEmpty()){
        if (m_bIgnoreColors){
            list<QString> opt = parseStyle(style);
            list<QString> new_opt;
            for (list<QString>::iterator it = opt.begin(); it != opt.end(); ++it){
                QString name = *it;
                it++;
                if (it == opt.end())
                    break;
                QString value = *it;
                if ((name == "color") ||
                        (name == "background-color") ||
                        (name == "font-size") ||
                        (name == "font-style") ||
                        (name == "font-weight") ||
                        (name == "font-family"))
                    continue;
                new_opt.push_back(name);
                new_opt.push_back(value);
            }
            style = makeStyle(new_opt);
        }
        if (!style.isEmpty())
            tagText += " style=\"" + style + "\"";
    }
    tagText += ">";
    res += tagText;
}
Esempio n. 9
0
/* edge attributes:
 * label
 * graphics
 * LabelGraphics
 */
static void 
emitEdgeAttrs (Agraph_t* G, Agedge_t* ep, FILE* outFile, int ix)
{
    Agsym_t*  s;
    char* v;
    edge_attrs attrs;
    int doGraphics = 0;
    int doLabelGraphics = 0;
    char* label = 0;
    int style;

    /* First, process the attributes, saving the graphics attributes */
    memset(&attrs,0, sizeof(attrs));
    for (s = agnxtattr (G, AGEDGE, NULL); s; s = agnxtattr (G, AGEDGE, s)) {
	if (streq(s->name, "style")) { /* hasFill outlineStyle invis */
	    if (*(v = agxget (ep, s))) {
		style = parseStyle (v);
		if (style & INVIS)
		    attrs.flags |= INVIS;
		if (style & LINE)
		    attrs.flags |= LINE;
		if (style & DASH)
		    attrs.flags |= DASH;
		if (style & DOT)
		    attrs.flags |= DOT;
		if (style & BOLD)
		    attrs.width = "2";
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "label")) {
	    if (*(v = agxget (ep, s))) {
		label = v;
		emitAttr (s->name, label, outFile, ix);
		doLabelGraphics = 1;
	    }
	}
	else if (streq(s->name, "penwidth")) {
	    if (*(v = agxget (ep, s))) {
		attrs.width = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "pos")) {
	    if (*(v = agxget (ep, s))) {
		doGraphics = 1;
		attrs.pos = v;
	    }
	}
	else if (streq(s->name, "dir")) {
	    if (*(v = agxget (ep, s))) {
		doGraphics = 1;
		attrs.arrow = v;
	    }
	}
	else if (streq(s->name, "color")) {
	    if (*(v = agxget (ep, s))) {
		attrs.fill = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "pencolor")) {
	    if (*(v = agxget (ep, s))) {
		attrs.fill = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "arrowhead")) {
	    if (*(v = agxget (ep, s))) {
		attrs.arrowhead = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "arrowtail")) {
	    if (*(v = agxget (ep, s))) {
		attrs.arrowtail = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "fontname")) { /* fontName */
	    if (*(v = agxget (ep, s))) {
		attrs.fontName = v;
		doLabelGraphics = 1;
	    }
	}
	else if (streq(s->name, "fontsize")) { /* fontSize */
	    if (*(v = agxget (ep, s))) {
		attrs.fontSize = v;
		doLabelGraphics = 1;
	    }
	}
	else if (streq(s->name, "fontcolor")) { /* fontColor */
	    if (*(v = agxget (ep, s))) {
		attrs.fontColor = v;
		doLabelGraphics = 1;
	    }
	}
	else {
	    v = agxget (ep, s);
	    emitAttr (s->name, v, outFile, ix);
	}
    }

    /* Then, print them, if any */
    if (doGraphics) {
	fprintf (outFile, "    graphics [\n");
	if (attrs.pos) {
	    emitSpline (attrs.pos, outFile, ix+1);
	}
	if (attrs.flags & INVIS) {
	    emitInt ("visible", 0, outFile, ix+1);
	}
	if (attrs.fill) {
	    emitAttr ("fill", attrs.fill, outFile, ix+1);
	}
	if (attrs.width) {
	    emitAttr ("width", attrs.width, outFile, ix+1);
	}
	if (attrs.arrowhead) {
	    emitAttr ("targetArrow", attrs.arrowhead, outFile, ix+1);
	}
	if (attrs.arrowtail) {
	    emitAttr ("sourceArrow", attrs.arrowtail, outFile, ix+1);
	}
	if (attrs.flags & DASH) {
	    emitAttr ("style", "dashed", outFile, ix+1);
	}
	else if (attrs.flags & DOT) {
	    emitAttr ("style", "dotted", outFile, ix+1);
	}
	else if (attrs.flags & LINE) {
	    emitAttr ("style", "line", outFile, ix+1);
	}
	if (attrs.arrow) {
	    if (streq(attrs.arrow,"forward"))
		emitAttr ("arrow", "first", outFile, ix+1);
	    else if (streq(attrs.arrow,"back"))
		emitAttr ("arrow", "last", outFile, ix+1);
	    else if (streq(attrs.arrow,"both"))
		emitAttr ("arrow", "both", outFile, ix+1);
	    else if (streq(attrs.arrow,"none"))
		emitAttr ("arrow", "none", outFile, ix+1);
	}
	fprintf (outFile, "    ]\n");
    }

    if (doLabelGraphics) {
	fprintf (outFile, "    LabelGraphics [\n");
	if (label) emitAttr ("text", label, outFile, ix+1);
	if (attrs.fontColor) {
	    emitAttr ("fontColor", attrs.fontColor, outFile, ix+1);
	}
	if (attrs.fontSize) {
	    emitAttr ("fontSize", attrs.fontSize, outFile, ix+1);
	}
	if (attrs.fontName) {
	    emitAttr ("fontName", attrs.fontName, outFile, ix+1);
	}
	fprintf (outFile, "    ]\n");
    }
}
Esempio n. 10
0
/* node attributes:
 * label
 * graphics
 * LabelGraphics
 */
static void 
emitNodeAttrs (Agraph_t* G, Agnode_t* np, FILE* outFile, int ix)
{
    Agsym_t*  s;
    char* v;
    node_attrs attrs;
    int doGraphics = 0;
    int doLabelGraphics = 0;
    char* label = 0;
    int style;
    double x, y;

    /* First, process the attributes, saving the graphics attributes */
    memset(&attrs,0, sizeof(attrs));
    for (s = agnxtattr (G, AGNODE, NULL); s; s = agnxtattr (G, AGNODE, s)) {
	if (streq(s->name, "style")) { /* hasFill outlineStyle invis */
	    if (*(v = agxget (np, s))) {
		style = parseStyle (v);
		if (style & INVIS)
		    attrs.flags |= INVIS;
		if (style & FILL)
		    attrs.flags |= FILL;
		if (style & LINE)
		    attrs.outlineStyle = "line";
		if (style & DASH)
		    attrs.outlineStyle = "dashed";
		if (style & DOT)
		    attrs.outlineStyle = "dotted";
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "label")) {
	    v = agxget (np, s);
	    if (streq("\\N", v)) {
		label = agnameof(np);
		emitAttr (s->name, label, outFile, ix);
		doLabelGraphics = 1;
	    }
	    else if (*v) {
		label = v;
		emitAttr (s->name, label, outFile, ix);
		doLabelGraphics = 1;
	    }
	}
	else if (streq(s->name, "penwidth")) {
	    if (*(v = agxget (np, s))) {
		attrs.width = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "width")) {
	    v = agxget (np, s);
	    if (*v) {
		attrs.w = 72.0*atof (v);
		attrs.flags |= W_SET;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "height")) {
	    v = agxget (np, s);
	    if (*v) {
		attrs.h = 72.0*atof (v);
		attrs.flags |= H_SET;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "pos")) {
	    v = agxget (np, s);
	    if (sscanf (v, "%lf,%lf", &x, &y) == 2) {
		doGraphics = 1;
		attrs.x = x;
		attrs.y = y;
		attrs.flags |= POS_SET;
	    }
	}
	else if (streq(s->name, "shape")) { /* type */
	    if (*(v = agxget (np, s))) {
		attrs.type = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "color")) {
	    if (*(v = agxget (np, s))) {
		attrs.fill = v;
		attrs.outline = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "fillcolor")) {
	    if (*(v = agxget (np, s))) {
		attrs.fill = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "pencolor")) {
	    if (*(v = agxget (np, s))) {
		attrs.outline = v;
		doGraphics = 1;
	    }
	}
	else if (streq(s->name, "fontname")) { /* fontName */
	    if (*(v = agxget (np, s))) {
		attrs.fontName = v;
		doLabelGraphics = 1;
	    }
	}
	else if (streq(s->name, "fontsize")) { /* fontSize */
	    if (*(v = agxget (np, s))) {
		attrs.fontSize = v;
		doLabelGraphics = 1;
	    }
	}
	else if (streq(s->name, "fontcolor")) { /* fontColor */
	    if (*(v = agxget (np, s))) {
		attrs.fontColor = v;
		doLabelGraphics = 1;
	    }
	}
	else {
	    v = agxget (np, s);
	    emitAttr (s->name, v, outFile, ix);
	}
    }

    /* Then, print them, if any */
    if (doGraphics) {
	fprintf (outFile, "    graphics [\n");
	if (attrs.flags & POS_SET) {
	    emitReal ("x", attrs.x, outFile, ix+1);
	    emitReal ("y", attrs.y, outFile, ix+1);
	}
	if (attrs.flags & W_SET) {
	    emitReal ("w", attrs.w, outFile, ix+1);
	}
	if (attrs.flags & H_SET) {
	    emitReal ("H", attrs.h, outFile, ix+1);
	}
	if (attrs.flags & INVIS) {
	    emitInt ("visible", 0, outFile, ix+1);
	}
	if (attrs.flags & FILL) {
	    emitInt ("hasFill", 1, outFile, ix+1);
	}
	if (attrs.type) {
	    emitAttr ("type", attrs.type, outFile, ix+1);
	}
	if (attrs.image) {
	    emitAttr ("image", attrs.image, outFile, ix+1);
	}
	if (attrs.fill) {
	    emitAttr ("fill", attrs.fill, outFile, ix+1);
	}
	if (attrs.outline) {
	    emitAttr ("outline", attrs.outline, outFile, ix+1);
	}
	if (attrs.width) {
	    emitAttr ("width", attrs.width, outFile, ix+1);
	}
	if (attrs.outlineStyle) {
	    emitAttr ("outlineStyle", attrs.outlineStyle, outFile, ix+1);
	}
	fprintf (outFile, "    ]\n");
    }

    if (doLabelGraphics) {
	fprintf (outFile, "    LabelGraphics [\n");
	if (label) emitAttr ("text", label, outFile, ix+1);
	if (attrs.fontColor) {
	    emitAttr ("fontColor", attrs.fontColor, outFile, ix+1);
	}
	if (attrs.fontSize) {
	    emitAttr ("fontSize", attrs.fontSize, outFile, ix+1);
	}
	if (attrs.fontName) {
	    emitAttr ("fontName", attrs.fontName, outFile, ix+1);
	}
	fprintf (outFile, "    ]\n");
    }
}
Esempio n. 11
0
bool
WayPointFileSeeYou::parseLine(const TCHAR* line, const unsigned linenum,
                              Waypoints &way_points, 
                              const RasterTerrain *terrain)
{
  TCHAR ctemp[255];
  const TCHAR *params[20];
  size_t n_params;

  static unsigned iName = 0, iCode = 1, iCountry = 2;
  static unsigned iLatitude = 3, iLongitude = 4, iElevation = 5;
  static unsigned iStyle = 6, iRWDir = 7, iRWLen = 8;
  static unsigned iFrequency = 9, iDescription = 10;

  static bool ignore_following = false;

  // If (end-of-file or comment)
  if (line[0] == '\0' || line[0] == 0x1a ||
      _tcsstr(line, _T("**")) == line ||
      _tcsstr(line, _T("*")) == line)
    // -> return without error condition
    return true;

  if (_tcslen(line) >= sizeof(ctemp) / sizeof(ctemp[0]))
    /* line too long for buffer */
    return false;

  // Parse first line holding field order
  /// @todo linenum == 0 should be the first
  /// (not ignored) line, not just line 0
  if (linenum == 0) {
    // Get fields
    n_params = extractParameters(line, ctemp, params, 20);

    // Iterate through fields and save the field order
    for (unsigned i = 0; i < n_params; i++) {
      const TCHAR* value = params[i];

      if (!_tcscmp(value, _T("name")))
        iName = i;
      else if (!_tcscmp(value, _T("code")))
        iCode = i;
      else if (!_tcscmp(value, _T("country")))
        iCountry = i;
      else if (!_tcscmp(value, _T("lat")))
        iLatitude = i;
      else if (!_tcscmp(value, _T("lon")))
        iLongitude = i;
      else if (!_tcscmp(value, _T("elev")))
        iElevation = i;
      else if (!_tcscmp(value, _T("style")))
        iStyle = i;
      else if (!_tcscmp(value, _T("rwdir")))
        iRWDir = i;
      else if (!_tcscmp(value, _T("rwlen")))
        iRWLen = i;
      else if (!_tcscmp(value, _T("freq")))
        iFrequency = i;
      else if (!_tcscmp(value, _T("desc")))
        iDescription = i;
    }
    ignore_following = false;

    return true;
  }

  // If task marker is reached ignore all following lines
  if (_tcsstr(line, _T("-----Related Tasks-----")) == line)
    ignore_following = true;
  if (ignore_following)
    return true;

  // Get fields
  n_params = extractParameters(line, ctemp, params, 20);

  // Check if the basic fields are provided
  if (iName >= n_params)
    return false;
  if (iLatitude >= n_params)
    return false;
  if (iLongitude >= n_params)
    return false;

  GeoPoint location;

  // Latitude (e.g. 5115.900N)
  if (!parseAngle(params[iLatitude], location.Latitude, true))
    return false;

  // Longitude (e.g. 00715.900W)
  if (!parseAngle(params[iLongitude], location.Longitude, false))
    return false;

  Waypoint new_waypoint(location);
  new_waypoint.FileNum = file_num;

  // Name (e.g. "Some Turnpoint", with quotes)
  if (!parseString(params[iName], new_waypoint.Name))
    return false;

  // Elevation (e.g. 458.0m)
  /// @todo configurable behaviour
  bool alt_ok = iElevation < n_params &&
    parseAltitude(params[iElevation], new_waypoint.Altitude);
  check_altitude(new_waypoint, terrain, alt_ok);

  // Description (e.g. "Some Turnpoint", with quotes)
  /// @todo include frequency and rwdir/len
  if (iDescription < n_params)
    parseString(params[iDescription], new_waypoint.Comment);

  // Style (e.g. 5)
  /// @todo include peaks with peak symbols etc.
  if (iStyle < n_params)
    parseStyle(params[iStyle], new_waypoint.Flags);

  // If the Style attribute did not state that this is an airport
  if (!new_waypoint.Flags.Airport) {
    // -> parse the runway length
    fixed rwlen;
    // Runway length (e.g. 546.0m)
    if (iRWLen < n_params && parseAltitude(params[iRWLen], rwlen)) {
      // If runway length is between 100m and 300m -> landpoint
      if (rwlen > fixed(100) && rwlen <= fixed(300))
        new_waypoint.Flags.LandPoint = true;
      // If runway length is higher then 300m -> airport
      if (rwlen > fixed(300))
        new_waypoint.Flags.Airport = true;
    }
  }

  add_waypoint(way_points, new_waypoint);
  return true;
}
Esempio n. 12
0
static void
parseLink (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  xmlChar *content;
  xmlChar *href_prop, *note_prop;
  int start = fb->utf8_current_index;

  /* id */
  href_prop = xmlGetProp(cur, (const xmlChar *)"href");
  /* type="note" */
  note_prop = xmlGetProp(cur, (const xmlChar *)"type");
  if (note_prop && (!xmlStrcmp(note_prop, (const xmlChar *)"note")))
    bufferAppend("[", 1, fb);

  cur = cur->children;

  /*bufferAppend("[", 1, fb);*/

  while (cur != NULL) {

    if (xmlNodeIsText(cur)) {
      content = xmlNodeGetContent(cur);
      if (content)
	bufferAppend(content, xmlStrlen(content), fb);
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"style")) {
      parseStyle(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"strong")) {
      content = xmlNodeGetContent(cur->children);
      if (content) {
	int st = fb->utf8_current_index;
	bufferAppend(content, xmlStrlen(content), fb);
	addMark(st, fb->utf8_current_index, STRONG_TYPE, NULL, fb);
      }
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"emphasis")) {
      content = xmlNodeGetContent(cur->children);
      if (content) {
	int st = fb->utf8_current_index;
	bufferAppend(content, xmlStrlen(content), fb);
	addMark(st, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb);
      }
      xmlFree(content);

    }

    cur = cur->next;
  }

  if (href_prop) {
    if (note_prop && (!xmlStrcmp(note_prop, (const xmlChar *)"note"))) {
      bufferAppend("]", 1, fb);
      addMark(start, fb->utf8_current_index, NOTE_TYPE, href_prop, fb);
      xmlFree(note_prop);
    } else {
      addMark(start, fb->utf8_current_index, LINK_TYPE, href_prop, fb);
    }
    xmlFree(href_prop);
  }

  return;
}
Esempio n. 13
0
static void
parseP (xmlDocPtr doc, xmlNodePtr cur, int add_tab, FB2Content *fb)
{
  xmlChar *content;
  FB2Mark *mark;

  mark = getLink(cur, fb);

  cur = cur->children;

  if (add_tab)
    bufferAppend("\t", 1, fb);

  while (cur != NULL) {

    if (xmlNodeIsText(cur)) {
      content = xmlNodeGetContent(cur);
      if (content) {
	/*
	int len;
	len = removeSpaces(content, xmlStrlen(content));
	bufferAppend(content, len, fb);
	*/
	bufferAppend(content, xmlStrlen(content), fb);
      }
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"style")) {
      parseStyle(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"strong")) {
      content = xmlNodeGetContent(cur->children);
      if (content) {
	int start = fb->utf8_current_index;
	bufferAppend(content, xmlStrlen(content), fb);
	addMark(start, fb->utf8_current_index, STRONG_TYPE, NULL, fb);
      }
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"emphasis")) {
      content = xmlNodeGetContent(cur->children);
      if (content) {
	int start = fb->utf8_current_index;
	bufferAppend(content, xmlStrlen(content), fb);
	addMark(start, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb);
      }
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"a")) {
      parseLink(doc, cur, fb);

    }

    cur = cur->next;
  }

  bufferAppend("\n", 1, fb);

  if (mark)
    mark->link_end = fb->text_current_index;

  return;
}