Ejemplo n.º 1
0
bool KHTMLReader::parse_font(DOM::Element e)
{
    // fixme don't hardcode 12 font size ...
    QString face = e.getAttribute("face").string();
    QColor color = parsecolor("#000000");
    if (!e.getAttribute("color").string().isEmpty())
        color = parsecolor(e.getAttribute("color").string());
    QString size = e.getAttribute("size").string();
    int isize = -1;
    if (size.startsWith('+'))
        isize = 12 + size.right(size.length() - 1).toInt();
    else if (size.startsWith('-'))
        isize = 12 - size.right(size.length() - 1).toInt();
    else
        isize = 12 + size.toInt();

    _writer->formatAttribute(state()->paragraph, "FONT", "name", face);
    if ((isize >= 0) && (isize != 12))
        _writer->formatAttribute(state()->paragraph, "SIZE", "value", QString("%1").arg(isize));

    _writer->formatAttribute(state()->paragraph, "COLOR", "red", QString("%1").arg(color.red()));
    _writer->formatAttribute(state()->paragraph, "COLOR", "green", QString("%1").arg(color.green()));
    _writer->formatAttribute(state()->paragraph, "COLOR", "blue", QString("%1").arg(color.blue()));
    return true;
}
Ejemplo n.º 2
0
void KHTMLReader::parseStyle(DOM::Element e)
{
    // styles are broken broken broken broken broken broken.
    // FIXME: use getComputedStyle - note: it only returns 0, but works nevertheless
    kDebug(30503) << "entering parseStyle";
    DOM::CSSStyleDeclaration s1 = e.style();
    DOM::Document doc = _html->document();
    DOM::CSSStyleDeclaration s2 = doc.defaultView().getComputedStyle(e, "");

    kDebug(30503) << "font-weight=" << s1.getPropertyValue("font-weight").string();
    if (s1.getPropertyValue("font-weight").string() == "bolder") {
        _writer->formatAttribute(state()->paragraph, "WEIGHT", "value", "75");
    }
    if (s1.getPropertyValue("font-weight").string() == "bold") {
        _writer->formatAttribute(state()->paragraph, "WEIGHT", "value", "75");
    }

    // process e.g. <style="color: #ffffff">
    if (! s1.getPropertyValue("color").string().isEmpty()) {
        QColor c = parsecolor(s1.getPropertyValue("color").string());
        _writer->formatAttribute(state()->paragraph, "COLOR", "red", QString::number(c.red()));
        _writer->formatAttribute(state()->paragraph, "COLOR", "green", QString::number(c.green()));
        _writer->formatAttribute(state()->paragraph, "COLOR", "blue", QString::number(c.blue()));
    } // done
    // process e.g. <style="font-size: 42">
    if (! s1.getPropertyValue("font-size").string().isEmpty()) {
        QString size = s1.getPropertyValue("font-size").string();
        if (size.endsWith("pt")) {
            size = size.left(size.length() - 2);
        }
        _writer->formatAttribute(state()->paragraph, "SIZE", "value", size);
    }
    // done
    // process e.g. <style="text-align: center">this is in the center</style>
    if (! s1.getPropertyValue("text-align").string().isEmpty()) {
        state()->layout = _writer->setLayout(state()->paragraph, state()->layout);
        _writer->layoutAttribute(state()->paragraph, "FLOW", "align", s1.getPropertyValue("text-align").string());
    }
    // done

    /*if (DOM::PROPV("font-weight") == "bolder")
    _writer->formatAttribute(state()->paragraph,"WEIGHT","value","75");
    */
    /*
         // debugging code.
         kDebug(30503) <<"e.style()";
         for (unsigned int i=0;i<s1.length();i++) {
            kDebug(30503) << QString("%1: %2").arg(s1.item(i).string()).arg(s1.getPropertyValue(s1.item(i)).string());
         }
         kDebug(30503) <<"override style";
         for (unsigned int i=0;i<s2.length();i++) {
            kDebug(30503) << QString("%1: %2").arg(s2.item(i).string()).arg(s2.getPropertyValue(s2.item(i)).string());
         }
    */
}
Ejemplo n.º 3
0
Archivo: color.c Proyecto: S010/misc
static int
color(char *color, const char *pattern)
{
	regmatch_t	 match;
	regex_t		 re;
	char		*line;
	size_t		 linesz;
	size_t		 len;
	const char	*esccolor;
	const char	 escreset[] = "\e[0m";
	int		 fg;
	int		 bg;
	int		 rc;
	regoff_t	 off;

	line = NULL;
	linesz = 0;

	parsecolor(color, &fg, &bg);
	esccolor = fmtesc(fg, bg, bflag);

	rc = regcomp(&re, pattern, REG_EXTENDED | (iflag ? REG_ICASE : 0));
	if (rc != 0)
		errx(EXIT_FAILURE, "``%s'': %s", pattern, strregerror(rc));

	errno = 0;
	while (getline(&line, &linesz, stdin) != -1) {
		for (off = 0; (rc = regexec(&re, line + off, 1, &match, 0)) != REG_NOMATCH; /* empty */ ) {
			if (rc != 0)
				errx(EXIT_FAILURE, "regexec: %s", strregerror(rc));
			match.rm_eo += ins(&line, &linesz, esccolor, match.rm_so + off);
			off += ins(&line, &linesz, escreset, match.rm_eo + off);
			off += match.rm_eo;
		}
		len = strlen(line);
		if (write(STDOUT_FILENO, line, len) != len)
			err(EXIT_FAILURE, "write");
		errno = 0;
	}
	if (errno != 0)
		err(EXIT_FAILURE, "getline");
	regfree(&re);
	free(line);

	return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
static void readoneconfig(char *fname, char *argv0, char *gamefile)
{
    FILE *f;
    char buf[1024];
    char *s;
    char *cmd, *arg;
    int accept = 1;
    int i;

    f = fopen(fname, "r");
    if (!f)
        return;

    while (1)
    {
        s = fgets(buf, sizeof buf, f);
        if (!s)
            break;

        /* kill newline */
        if (strlen(buf) && buf[strlen(buf)-1] == '\n')
            buf[strlen(buf)-1] = 0;

        if (!strlen(buf) || buf[0] == '#')
            continue;

        if (strchr(buf,'['))
        {
            for (i = 0; i < strlen(buf); i++)
                buf[i] = tolower(buf[i]);

            if (strstr(buf, argv0) || strstr(buf, gamefile))
                accept = 1;
            else
                accept = 0;
        }

        if (!accept)
            continue;

        cmd = strtok(buf, "\r\n\t ");
        if (!cmd)
            continue;

        if (!strcmp(cmd, "tcolor") || !strcmp(cmd, "gcolor"))
            arg = strtok(NULL, "\r\n#");
        else if (!strcmp(cmd, "tfont") || !strcmp(cmd, "gfont"))
            arg = strtok(NULL, "\r\n#");
        else if ((!strcmp(cmd, "monofont") || !strcmp(cmd, "propfont")))
            arg = strtok(NULL, "\r\n#");
        else if ((!strncmp(cmd, "mono", 4) || !strncmp(cmd, "prop", 4)) && strlen(cmd) == 5)
            arg = strtok(NULL, "\r\n#");
        else if (!strcmp(cmd, "moreprompt"))
            arg = strtok(NULL, "\r\n");
        else
            arg = strtok(NULL, "\r\n\t #");
        if (!arg)
            continue;

        if (!strcmp(cmd, "moreprompt"))
            gli_more_prompt = strdup(arg);

        if (!strcmp(cmd, "morecolor"))
        {
            parsecolor(arg, gli_more_color);
            parsecolor(arg, gli_more_save);
        }

        if (!strcmp(cmd, "morefont"))
            gli_more_font = font2idx(arg);
        if (!strcmp(cmd, "morealign"))
            gli_more_align = atoi(arg);

        if (!strcmp(cmd, "monoaspect"))
            gli_conf_monoaspect = atof(arg);
        if (!strcmp(cmd, "propaspect"))
            gli_conf_propaspect = atof(arg);

        if (!strcmp(cmd, "monosize"))
            gli_conf_monosize = atof(arg);
        if (!strcmp(cmd, "monor"))
            gli_conf_monor = trim(strdup(arg));
        if (!strcmp(cmd, "monob"))
            gli_conf_monob = trim(strdup(arg));
        if (!strcmp(cmd, "monoi"))
            gli_conf_monoi = trim(strdup(arg));
        if (!strcmp(cmd, "monoz"))
            gli_conf_monoz = trim(strdup(arg));
        if (!strcmp(cmd, "monofont"))
            gli_conf_monofont = trim(strdup(arg));

        if (!strcmp(cmd, "propsize"))
            gli_conf_propsize = atof(arg);
        if (!strcmp(cmd, "propr"))
            gli_conf_propr = trim(strdup(arg));
        if (!strcmp(cmd, "propb"))
            gli_conf_propb = trim(strdup(arg));
        if (!strcmp(cmd, "propi"))
            gli_conf_propi = trim(strdup(arg));
        if (!strcmp(cmd, "propz"))
            gli_conf_propz = trim(strdup(arg));
        if (!strcmp(cmd, "propfont"))
            gli_conf_propfont = trim(strdup(arg));

        if (!strcmp(cmd, "leading"))
            gli_leading = atof(arg) + 0.5;
        if (!strcmp(cmd, "baseline"))
            gli_baseline = atof(arg) + 0.5;

        if (!strcmp(cmd, "rows"))
            gli_rows = atoi(arg);
        if (!strcmp(cmd, "cols"))
            gli_cols = atoi(arg);

        if (!strcmp(cmd, "wpaddingx")) gli_wpaddingx = atoi(arg);
        if (!strcmp(cmd, "wpaddingy")) gli_wpaddingy = atoi(arg);
        if (!strcmp(cmd, "wmarginx")) gli_wmarginx = atoi(arg);
        if (!strcmp(cmd, "wmarginy")) gli_wmarginy = atoi(arg);
        if (!strcmp(cmd, "wborderx")) gli_wborderx = atoi(arg);
        if (!strcmp(cmd, "wbordery")) gli_wbordery = atoi(arg);
        if (!strcmp(cmd, "tmarginx")) gli_tmarginx = atoi(arg);
        if (!strcmp(cmd, "tmarginy")) gli_tmarginy = atoi(arg);

        if (!strcmp(cmd, "gamma"))
            gli_conf_gamma = atof(arg);

        if (!strcmp(cmd, "caretcolor"))
        {
            parsecolor(arg, gli_caret_color);
            parsecolor(arg, gli_caret_save);
        }

        if (!strcmp(cmd, "linkcolor"))
        {
            parsecolor(arg, gli_link_color);
            parsecolor(arg, gli_link_save);
        }

        if (!strcmp(cmd, "bordercolor"))
        {
            parsecolor(arg, gli_border_color);
            parsecolor(arg, gli_border_save);
        }

        if (!strcmp(cmd, "windowcolor"))
        {
            parsecolor(arg, gli_window_color);
            parsecolor(arg, gli_window_save);
        }

        if (!strcmp(cmd, "lcd"))
            gli_conf_lcd = atoi(arg);

        if (!strcmp(cmd, "caretshape"))
            gli_caret_shape = atoi(arg);

        if (!strcmp(cmd, "linkstyle"))
            gli_link_style = atoi(arg) ? 1 : 0;

        if (!strcmp(cmd, "scrollwidth"))
            gli_scroll_width = atoi(arg);
        if (!strcmp(cmd, "scrollbg"))
            parsecolor(arg, gli_scroll_bg);
        if (!strcmp(cmd, "scrollfg"))
            parsecolor(arg, gli_scroll_fg);

        if (!strcmp(cmd, "justify"))
            gli_conf_justify = atoi(arg);
        if (!strcmp(cmd, "quotes"))
            gli_conf_quotes = atoi(arg);
        if (!strcmp(cmd, "spaces"))
            gli_conf_spaces = atoi(arg);
        if (!strcmp(cmd, "caps"))
            gli_conf_caps = atoi(arg);

        if (!strcmp(cmd, "graphics"))
            gli_conf_graphics = atoi(arg);
        if (!strcmp(cmd, "sound"))
            gli_conf_sound = atoi(arg);
        if (!strcmp(cmd, "speak"))
            gli_conf_speak = atoi(arg);

        if (!strcmp(cmd, "stylehint"))
            gli_conf_stylehint = atoi(arg);

        if (!strcmp(cmd, "safeclicks"))
            gli_conf_safeclicks = atoi(arg);

        if (!strcmp(cmd, "tcolor") || !strcmp(cmd, "gcolor"))
        {
            char *style = strtok(arg, "\r\n\t ");
            char *fg = strtok(NULL, "\r\n\t ");
            char *bg = strtok(NULL, "\r\n\t ");
            int i = atoi(style);
            if (i < 0 || i >= style_NUMSTYLES)
                continue;
            if (!bg)
                bg = gli_window_color;
            if (cmd[0] == 't')
            {
                parsecolor(fg, gli_tstyles[i].fg);
                parsecolor(bg, gli_tstyles[i].bg);
            }
            else
            {
                parsecolor(fg, gli_gstyles[i].fg);
                parsecolor(bg, gli_gstyles[i].bg);
            }
        }

        if (!strcmp(cmd, "tfont") || !strcmp(cmd, "gfont"))
        {
            char *style = strtok(arg, "\r\n\t ");
            char *font = strtok(NULL, "\r\n\t ");
            int i = atoi(style);
            if (i < 0 || i >= style_NUMSTYLES)
                continue;
            if (cmd[0] == 't')
                gli_tstyles[i].font = font2idx(font);
            else
                gli_gstyles[i].font = font2idx(font);
        }
    }

    fclose(f);
}
Ejemplo n.º 5
0
bool	aart_post::toon::parse(const char * aline, FILE *)
{
	char c= * aline ;
	int	itmp ;

	generalstring::skip(aline) ;
	switch (tolower(c))
	{
		case 'c':	// curvatureLine
			c= * aline ;
			switch (tolower(c))
			{
				case 'h':	// hardness
					if (! parseval(cline_h, aline)) return false ;  break ;
				case 't':	// threshold
					if (! parseval(cline_t, aline)) return false ;  break ;
				case 'w':	// width
					if (! parseval(cline_w, aline)) return false ;  break ;
				default:
					generallog::message("unexpected attribute for curvatureLine (expected width|threshold|hardness)", GL::eWarning) ;
					return false ;
			}
			break ;
		case 't':	// trickLine
			c= * aline ;
			switch (tolower(c))
			{
				case 'h':	// hardness
					if (! parseval(tline_h, aline)) return false ;  break ;
				case 't':	// threshold
					if (! parseval(tline_t, aline)) return false ;  break ;
				case 'w':	// width
					if (! parseval(tline_w, aline)) return false ;  break ;
				default:
					generallog::message("unexpected attribute for trickLine (expected width|threshold|hardness)", GL::eWarning) ;
					return false ;
			}
			break ;
		case 'l':	// lineColor
			itmp= atoi(aline) ;
			if ((itmp < 1) || (itmp > 16))
			{
				generallog::message("lineColor out of range (1-16)", GL::eWarning) ;
				return false ;
			}

			generalstring::skip(aline) ;
			itmp -- ;
			if ('[' != * aline)
				return false ;

			aline ++ ;
			if (parsecolor(line[itmp], aline)) { luse |= (1 << itmp) ; }
				else return false ;
			break ;

		default:
			if (strncmp(aline, "# ---", 5))
				ignore(aline) ;
	}

	return true ;
}
Ejemplo n.º 6
0
bool KHTMLReader::parse_table(DOM::Element e)
{
    if (_writer->isInTable()) {
        // We are already inside of a table. Tables in tables are not supported
        // yet. So, just add that table-content as text.
        for (DOM::Node rows = e.firstChild().firstChild();!rows.isNull();rows = rows.nextSibling())
            if (!rows.isNull() && rows.nodeName().string().toLower() == "tr")
                for (DOM::Node cols = rows.firstChild();!cols.isNull();cols = cols.nextSibling())
                    if (!cols.isNull())
                        parseNode(cols);
        return false;
    }

    DOM::Element table_body = e.firstChild();
    if (table_body.isNull()) {
        // If the table_body is empty, we don't continue cause else
        // KHTML will throw a DOM::DOMException if we try to access
        // the null element.
        return true;
    }

    int tableno = _writer->createTable();
    int nrow = 0;
    int ncol = 0;
    bool has_borders = false;
    QColor bgcolor = parsecolor("#FFFFFF");

    if (!table_body.getAttribute("bgcolor").string().isEmpty())
        bgcolor = parsecolor(table_body.getAttribute("bgcolor").string());
    if ((e.getAttribute("border").string().toInt() > 0))
        has_borders = true;

    // fixme rewrite this proper
    //(maybe using computed sizes from khtml if thats once exported)
    for (DOM::Node rowsnode = table_body.firstChild();!rowsnode.isNull();rowsnode = rowsnode.nextSibling()) {
        DOM::Element rows = rowsnode;
        if (!rows.isNull() && rows.tagName().string().toLower() == "tr") {
            QColor obgcolor = bgcolor;
            if (!rows.getAttribute("bgcolor").string().isEmpty())
                bgcolor = parsecolor(rows.getAttribute("bgcolor").string());

            ncol = 0;
            for (DOM::Node colsnode = rows.firstChild();!colsnode.isNull();colsnode = colsnode.nextSibling()) {
                DOM::Element cols = colsnode;
                const QString nodename = cols.isNull() ? QString() : cols.nodeName().string().toLower();
                if (nodename == "td" || nodename == "th") {
                    QColor bbgcolor = bgcolor;
                    if (!cols.getAttribute("bgcolor").string().isEmpty())
                        bgcolor = parsecolor(cols.getAttribute("bgcolor").string());

                    pushNewState();
                    QRect colrect = cols.getRect();
                    state()->frameset = _writer->createTableCell(tableno, nrow, ncol, 1, colrect);
                    state()->frameset.firstChild().toElement().setAttribute("bkRed", bgcolor.red());
                    state()->frameset.firstChild().toElement().setAttribute("bkGreen", bgcolor.green());
                    state()->frameset.firstChild().toElement().setAttribute("bkBlue", bgcolor.blue());
                    if (has_borders) {
                        state()->frameset.firstChild().toElement().setAttribute("lWidth", 1);
                        state()->frameset.firstChild().toElement().setAttribute("rWidth", 1);
                        state()->frameset.firstChild().toElement().setAttribute("bWidth", 1);
                        state()->frameset.firstChild().toElement().setAttribute("tWidth", 1);
                    }

                    // fixme don't guess. get it right.
                    state()->paragraph = _writer->addParagraph(state()->frameset);
                    parseNode(cols);
                    _writer->cleanUpParagraph(state()->paragraph);
                    popState();
                    ncol++;
                    bgcolor = bbgcolor;
                }
            }
            nrow++;
            bgcolor = obgcolor;
        }
    }
    _writer->finishTable(tableno/*,0,0,r.right()-r.left(),r.bottom()-r.top()*/); // FIXME find something better.
    startNewParagraph(false, false);
    _writer->createInline(state()->paragraph, _writer->fetchTableCell(tableno, 0, 0));
    startNewParagraph(false, false);
    return false; // we do our own recursion
}
Ejemplo n.º 7
0
void menuselectionbgcolor(char *r, char *g, char *b, char *a)
{
    if(!menuselbgcolor) menuselbgcolor = new color;
    if(!r[0]) { DELETEP(menuselbgcolor); return; }
    parsecolor(menuselbgcolor, r, g, b, a);
}