Beispiel #1
0
KdmLabel::KdmLabel( QObject *parent, const QDomNode &node )
	: KdmItem( parent, node )
	, action( 0 )
{
	itemType = "label";

	// Set default values for label (note: strings are already Null)
	label.normal.font = label.active.font = label.prelight.font = style.font;
	label.normal.color = label.active.color = label.prelight.color =
		style.palette.isBrushSet( QPalette::Normal, QPalette::WindowText ) ?
			style.palette.color( QPalette::Normal, QPalette::WindowText ) :
			QColor( Qt::white );
	label.active.present = false;
	label.prelight.present = false;

	const QString locale = KGlobal::locale()->language();

	// Read LABEL TAGS
	QDomNodeList childList = node.childNodes();
	bool stockUsed = false;
	for (int nod = 0; nod < childList.count(); nod++) {
		QDomNode child = childList.item( nod );
		QDomElement el = child.toElement();
		QString tagName = el.tagName();

		if (tagName == "normal") {
			parseColor( el, label.normal.color );
			parseFont( el, label.normal.font );
		} else if (tagName == "active") {
			label.active.present = true;
			parseColor( el, label.active.color );
			parseFont( el, label.active.font );
		} else if (tagName == "prelight") {
			label.prelight.present = true;
			parseColor( el, label.prelight.color );
			parseFont( el, label.prelight.font );
		} else if (tagName == "text" && el.attributes().count() == 0 && !stockUsed) {
			label.text = el.text();
		} else if (tagName == "text" && !stockUsed) {
			QString lang = el.attribute( "xml:lang", "" );
			if (lang == locale)
				label.text = el.text();
		} else if (tagName == "stock") {
			label.text = lookupStock( el.attribute( "type", "" ) );
			stockUsed = true;
		}
	}

	// Check if this is a timer label
	label.isTimer = label.text.indexOf( "%c" ) >= 0;
	if (label.isTimer) {
		timer = new QTimer( this );
		timer->start( 1000 );
		connect( timer, SIGNAL(timeout()), SLOT(update()) );
	}
	label.text.replace( '\n', ' ' );
	setCText( lookupText( label.text ) );
}
Beispiel #2
0
void
KdmRect::init( const TQDomNode &node, const char * )
{
	itemType = "rect";

	// Set default values for rect (note: strings are already Null)
	rect.normal.alpha = 1;
	rect.active.present = false;
	rect.prelight.present = false;
	rect.hasBorder = false;

	// A rect can have no properties (defaults to parent ones)
	if (node.isNull()) {
		return;
	}

	// Read RECT ID
	TQDomNode n = node;
	TQDomElement elRect = n.toElement();

	// Read RECT TAGS
	TQDomNodeList childList = node.childNodes();
	for (uint nod = 0; nod < childList.count(); nod++) {
		TQDomNode child = childList.item( nod );
		TQDomElement el = child.toElement();
		TQString tagName = el.tagName();

		if (tagName == "normal") {
			parseColor( el.attribute( "color", TQString::null ), rect.normal.color );
			rect.normal.alpha = el.attribute( "alpha", "1.0" ).toFloat();
			parseFont( el.attribute( "font", "Sans 14" ), rect.normal.font );
		}
		else if (tagName == "active") {
			rect.active.present = true;
			parseColor( el.attribute( "color", TQString::null ), rect.active.color );
			rect.active.alpha = el.attribute( "alpha", "1.0" ).toFloat();
			parseFont( el.attribute( "font", "Sans 14" ), rect.active.font );
		}
		else if (tagName == "prelight") {
			rect.prelight.present = true;
			parseColor( el.attribute( "color", TQString::null ), rect.prelight.color );
			rect.prelight.alpha = el.attribute( "alpha", "1.0" ).toFloat();
			parseFont( el.attribute( "font", "Sans 14" ), rect.prelight.font );
		}
		else if (tagName == "border") {
			rect.hasBorder = true;
		}
	}
}
Beispiel #3
0
void DataValue::parse(const ustring &text, DataType type, void *value) {
	switch(type) {
		case data_int:
		case data_combo:
		case data_flags:
		case data_comboEx:
			*(int *)value = atoi(text.c_str());
			break;
		case data_str:
			if(text[0] == '"')
				((ustring*)value)->assign(text, 1, text.length() - 2);
			else if(text[0] == '#')
				parseStrList(text, value);
			else
				*(ustring*)value = text;
			break;
		case data_stock:
		case data_element:
			if(text[0] == '"')
				((ustring*)value)->assign(text, 1, text.length() - 2);
			else
				*(ustring*)value = text;
			break;
		case data_real:
			*(double *)value = atof(text.c_str());
			break;
		case data_data: {
			int i;
			static const int dtypes[] = { data_int, data_str, data_real };

			for(int t = 0; t < 3; t++)
				if(strncmp(text.c_str(), dataNames[dtypes[t]], i = strlen(dataNames[dtypes[t]])) == 0) {
					ustring s = ustring(text, i+1, text.length() - i - 2);
					switch(t) {
						case 0: *(TData*)value = atoi(s.c_str()); break;
						case 1: *(TData*)value = s; break;
						case 2: *(TData*)value = atof(s.c_str()); break;
					}
				}
			break;
		}
		case data_list:
			parseStrList(text, value);
			break;
		case data_pixbuf:
			parsePixbuf(text, value);
			break;
		case data_array:
			parseArray(text, value);
			break;
		case data_color:
			((TypeColor*)value)->set(text);
			break;
		case data_font:
			parseFont(text, value);
			break;
		default:
			;
	}
}
	bool FontExportSerializer::deserialization(pugi::xml_document& _doc)
	{
		if (_doc.select_single_node("MyGUI[@type=\"Resource\"]").node().empty())
			return false;

		pugi::xpath_node_set nodes = _doc.select_nodes("MyGUI/Resource[@type=\"ResourceTrueTypeFont\"]");
		for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++)
			parseFont((*node).node());

		return true;
	}
Beispiel #5
0
/* Add font to set */
void tcAddFont(tcCtx g, long flags) {
    tcprivCtx h = g->ctx.tcpriv;
    Font *font = dnaNEXT(h->set);

    if (flags & TC_SMALLMEMORY && g->cb.tmpOpen == NULL) {
        tcFatal(g, "callbacks not supplied for SMALLMEMORY mode");
    }

    g->flags = flags;
    font->filename = (g->cb.psId == NULL) ? "?" : g->cb.psId(g->cb.ctx);
    parseFont(g, font);
}
bool CanvasFontCache::getFontUsingDefaultStyle(const String& fontString, Font& resolvedFont)
{
    HashMap<String, Font>::iterator i = m_fontsResolvedUsingDefaultStyle.find(fontString);
    if (i != m_fontsResolvedUsingDefaultStyle.end()) {
        ASSERT(m_fontLRUList.contains(fontString));
        m_fontLRUList.remove(fontString);
        m_fontLRUList.add(fontString);
        resolvedFont = i->value;
        return true;
    }

    // Addition to LRU list taken care of inside parseFont
    MutableStylePropertySet* parsedStyle = parseFont(fontString);
    if (!parsedStyle)
        return false;

    RefPtr<ComputedStyle> fontStyle = ComputedStyle::clone(*m_defaultFontStyle.get());
    m_document->ensureStyleResolver().computeFont(fontStyle.get(), *parsedStyle);
    m_fontsResolvedUsingDefaultStyle.add(fontString, fontStyle->font());
    resolvedFont = m_fontsResolvedUsingDefaultStyle.find(fontString)->value;
    return true;
}
Beispiel #7
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);
}
Beispiel #8
0
/// convert bmp with font to a c-header file:
int bmp2font(const char *bmpFile, const char *varName, const char *dstFile)
{
	std::vector<std::vector<char> > fontGrid;
	uint32_t biHeight;

	//load BMP into a 2D-array:
	parseBMP(bmpFile, fontGrid, &biHeight);

	if(fontGrid.size() == 0)
		return -1;

/*	//print debug:
	printf("fontGrid = \n");
	for(int y=0; y < 16; y++)
	{
		for(int x=0; x< 79; x++)
			printf("%c", zo[fontGrid[y][x] == '1'] );
		printf("\n");
	}*/

	//get font height:
	int vStart, vStop;
	int extent = getVpos(fontGrid, vStart, vStop);

	printf("font '%s' has vertical range of %i .. %i\n", bmpFile, vStart, vStop);

	//extract glyphs from bitmap data:
	font_s fontOut = parseFont( fontGrid, vStart, vStop );

	//debug: print glyphs to screen:
	char testString[] = "ab1";
	char buffer[80*32];
	memset(buffer, 0, sizeof(buffer) );
	int dx = 0;
	for(int c=0; c < (int)strlen(testString) ; c++)
	{
		dx += fontOut.render( buffer + dx, 80-dx-1, 80, testString[c]) + 1;
		if(dx >= 80)
			break;
	}

/*	printf("\nfontOut '%s' = \n", testString);
	char zo[] = " #";
	for(int y=0; y < 16; y++)
	{
		for(int x=0; x< 79; x++)
			printf("%c", zo[buffer[y*80 + x]] );
		printf("\n");
	}*/

	//print font into a header file:
	FILE *fh = fopen(dstFile, "w");

	//print offset table
	//int offsets[257];
	fprintf(fh,"\nunsigned short %s_offset[] = ", varName);
	printCinitializer(fh, fontOut.nrGlyphs + 1, fontOut.offset);
	fprintf(fh,";\n" );
	
	//print raw bitmap data
	fprintf(fh,"\nchar %s_data[] = ", varName);
	printCinitializer(fh, fontOut.offset[fontOut.nrGlyphs] , fontOut.data );
	fprintf(fh,";\n" );

	//print font structure:
	fprintf(fh,"\nfont_s %s = {%i, %i, %s_offset, %s_data };\n", varName, fontOut.nrGlyphs, fontOut.height, varName, varName );

	fclose(fh);


	return fontOut.nrGlyphs;
}
Beispiel #9
0
void Parser::startTag(const string& name_, StringPairList& attribs, bool simple) {
	auto name = boost::algorithm::trim_copy(name_);

	if(name == "br") {
		ret += _T("\\line\n");
	}

	if(simple) {
		return;
	}

	contexts.push_back(contexts.back());
	ScopedFunctor([this] { ret += contexts.back().getBegin(); });

	if(name == "b") {
		contexts.back().setFlag(Context::Bold);
	} else if(name == "i") {
		contexts.back().setFlag(Context::Italic);
	} else if(name == "u") {
		contexts.back().setFlag(Context::Underlined);
	}

	if(attribs.empty()) {
		return;
	}

	if(name == "a") {
		const auto& link = getAttrib(attribs, "href", 0);
		if(!link.empty()) {
			auto& context = contexts.back();
			context.link = link;
			if ((WinUtil::m_TextStyleURL.dwMask & CFE_UNDERLINE) == CFE_UNDERLINE)
				context.setFlag(Context::Underlined);
			context.textColor = addColor(WinUtil::m_TextStyleURL.crTextColor); /// @todo move to styles
		}
	}

	const auto& style = getAttrib(attribs, "style", 0);

	enum { Declaration, Font, Decoration, TextColor, BgColor, FontSize, Unknown } state = Declaration;

	string tmp;
	size_t i = 0, j;
	while((j = style.find_first_of(":;", i)) != string::npos) {
		tmp = style.substr(i, j - i);
		i = j + 1;

		boost::algorithm::trim(tmp);

		switch(state) {
		case Declaration:
			{
				if(tmp == "font") { state = Font; }
				else if(tmp == "color") { state = TextColor; }
				else if(tmp == "text-decoration") { state = Decoration; }
				else if(tmp == "background-color") { state = BgColor; }
				else if(tmp == "font-size") { state = FontSize; }
				else { state = Unknown; }
				break;
			}

		case Font:
			{
				parseFont(tmp);
				state = Declaration;
				break;
			}
		case FontSize:
			{
				parseFontSize(tmp);
				state = Declaration;
				break;
			}

		case Decoration:
			{
				parseDecoration(tmp);
				state = Declaration;
				break;
			}

		case TextColor:
			{
				parseColor(contexts.back().textColor, tmp);
				state = Declaration;
				break;
			}

		case BgColor:
			{
				parseColor(contexts.back().bgColor, tmp);
				state = Declaration;
				break;
			}

		case Unknown:
			{
				state = Declaration;
				break;
			}
		}
	}
}