⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 region_node.cpp

📁 彩信浏览器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA/*  * @$Id: region_node.cpp,v 1.42 2007/02/12 14:15:15 jackjansen Exp $  */#include "ambulant/lib/logger.h"#include "ambulant/common/schema.h"#include "ambulant/common/region_eval.h"#include "ambulant/common/preferences.h"#include "ambulant/smil2/region_node.h"#ifndef AM_DBG#define AM_DBG if(0)#endifusing namespace ambulant;using namespace smil2;// Attribute names that cause needs_region_node() to return true// for a given body node// XXXX Not checked with SMIL2 standard yet!static char *subregionattrs[] = {	"left", "width", "right", "top", "height", "bottom",	"backgroundColor", "background-color",	"transparent",	"fit",	"soundLevel",	"soundAlign",	NULL};// Helper function: get region_dim value from an attributestatic common::region_dimget_regiondim_attr(const lib::node *rn, char *attrname){	const char *attrvalue = rn->get_attribute(attrname);	common::region_dim rd;	if (attrvalue == NULL || *attrvalue == '\0'	    || strcmp(attrvalue, "auto") == 0) {		// pass: region_dim are initialized as "auto"	} else {		int ivalue;		char *endptr;		ivalue = strtol(attrvalue, &endptr, 10);		if (*endptr == '\0' || strcmp(endptr, "px") == 0) {			rd = ivalue;		} else if (*endptr == '%') {			double fvalue;			fvalue = ivalue / 100.0;			rd = fvalue;		} else {			lib::logger::get_logger()->trace("%s: cannot parse %s=\"%s\"", rn->get_sig().c_str(), attrname, attrvalue);			lib::logger::get_logger()->warn(gettext("Syntax error in SMIL document"));		}	}	return rd;}bool region_node::needs_region_node(const lib::node *n) {	char **attrnamep = subregionattrs;	while (*attrnamep) {		if (n->get_attribute(*attrnamep))			return true;		attrnamep++;	}	return false;}// staticint region_node::node_counter = 0;region_node::region_node(const lib::node *n, dimension_inheritance di):	m_node(n),	m_dim_inherit(di),	m_fit(common::fit_default),	m_zindex(0),	m_bgcolor(lib::to_color(0,0,0)),	m_soundlevel(1.0),	m_soundalign(common::sa_default),	m_bgimage(NULL),	m_tiling(common::tiling_default),	m_transparent(true),	m_showbackground(true),	m_inherit_bgcolor(false),	m_surface_template(NULL),	m_is_subregion(false),	m_parent(NULL),	m_child(NULL),	m_next(NULL) {node_counter++;}region_node::~region_node() {	node_counter--;	lib::node_navigator<region_node>::delete_tree(this); 	}voidregion_node::fix_from_region_node(const region_node *parent){	set_soundlevel(parent->get_soundlevel());	set_soundalign(parent->get_soundalign());}boolregion_node::fix_from_dom_node(){	bool changed = false;		// For every node in the layout section we fill in the dimensions	AM_DBG lib::logger::get_logger()->debug("region_node::reset: adjusting %s %s", m_node->get_local_name().c_str(), m_node->get_attribute("id"));	common::region_dim_spec rdspec;	rdspec.left = get_regiondim_attr(m_node, "left");	rdspec.width = get_regiondim_attr(m_node, "width");	rdspec.right = get_regiondim_attr(m_node, "right");	rdspec.top = get_regiondim_attr(m_node, "top");	rdspec.height = get_regiondim_attr(m_node, "height");	rdspec.bottom = get_regiondim_attr(m_node, "bottom");#if !defined(AMBULANT_NO_IOSTREAMS) && !defined(AMBULANT_NO_OPERATORS_IN_NAMESPACE)	AM_DBG {		//lib::logger::ostream os = lib::logger::get_logger()->trace_stream();		// XXXX Why the &^%$#%& can't we use os << rdspec << lib::endl ??!??		//os << "region_node::reset: result=(" 		//	<< rdspec.left << ", " << rdspec.width << ", " << rdspec.right << ", "		//	<< rdspec.top << ", " << rdspec.height << ", " << rdspec.bottom << ")" << lib::endl;	}#endif	if (rdspec != m_rds) {		changed = true;		m_rds = rdspec;	}	m_display_rds = m_rds;		// Next we set background color	const char *bgcolor_attr = m_node->get_attribute("backgroundColor");	if (bgcolor_attr == NULL) bgcolor_attr = m_node->get_attribute("background-color");	if (bgcolor_attr == NULL) bgcolor_attr = "transparent";	lib::color_t bgcolor = lib::to_color(0, 0, 0);	bool transparent = true, inherit = false;	if (strcmp(bgcolor_attr, "transparent") == 0) transparent = true;	else if (strcmp(bgcolor_attr, "inherit") == 0) inherit = true;	else if (!lib::is_color(bgcolor_attr)) {		lib::logger::get_logger()->trace("%s: Invalid color: %s", m_node->get_sig().c_str(), bgcolor_attr);		lib::logger::get_logger()->warn(gettext("Ignoring minor errors in document"));	} else {		bgcolor = lib::to_color(bgcolor_attr);		transparent = false;	}	AM_DBG lib::logger::get_logger()->debug("region_node::reset: Background color 0x%x %d %d", (int)bgcolor, (int)transparent, (int)inherit);	if (bgcolor != m_bgcolor || transparent != m_transparent || inherit != m_inherit_bgcolor) {		changed = true;	}	set_bgcolor(bgcolor, transparent, inherit);		// showBackground	const char *sbg_attr = m_node->get_attribute("showBackground");	bool sbg = true;	if (sbg_attr) {		if (strcmp(sbg_attr, "whenActive") == 0) sbg = false;		else if (strcmp(sbg_attr, "always") == 0) sbg = true;		else {			lib::logger::get_logger()->error("%s: Invalid showBackground value: %s", m_node->get_sig().c_str(), sbg_attr);			lib::logger::get_logger()->warn(gettext("Ignoring minor errors in document"));		}	}	if (sbg != m_showbackground) {		changed = true;	}	set_showbackground(sbg);		// And fit	const char *fit_attr = m_node->get_attribute("fit");	common::fit_t fit = common::fit_default;	if (fit_attr) {		if (strcmp(fit_attr, "fill") == 0) fit = common::fit_fill;		else if (strcmp(fit_attr, "hidden") == 0) fit = common::fit_hidden;		else if (strcmp(fit_attr, "meet") == 0) fit = common::fit_meet;		else if (strcmp(fit_attr, "meetBest") == 0) fit = common::fit_meetbest;		else if (strcmp(fit_attr, "scroll") == 0) fit = common::fit_scroll;		else if (strcmp(fit_attr, "slice") == 0) fit = common::fit_slice;		else {			lib::logger::get_logger()->trace("%s: Invalid fit value: %s", m_node->get_sig().c_str(), fit_attr);			lib::logger::get_logger()->warn(gettext("Ignoring minor errors in document"));		}	}	if (fit != m_fit) {		changed = true;	}	set_fit(fit);		// And z-index.	// XXXX Note that the implementation of z-index isn't 100% correct SMIL 2.0:	// we interpret missing z-index as zero, but the standard says "auto" which is	// slightly different.	const char *z_attr = m_node->get_attribute("z-index");	common::zindex_t z = 0;	if (z_attr) z = strtol(z_attr, NULL, 10);	AM_DBG lib::logger::get_logger()->debug("region_node::reset: z-index=%d", z);	if (z != m_zindex) {		changed = true;	}	set_zindex(z);	// soundLevel.	// XXXX Note that the implementation of z-index isn't 100% correct SMIL 2.0:	// we interpret missing z-index as zero, but the standard says "auto" which is	// slightly different.	const char *soundlevel_attr = m_node->get_attribute("soundLevel");	double sl = m_soundlevel;	char *lastp;	if (soundlevel_attr) {		sl = strtod(soundlevel_attr, &lastp);		if (*lastp == '%') sl *= 0.01;	}	AM_DBG lib::logger::get_logger()->debug("region_node::reset: soundLevel=%g", sl);	if (sl != m_soundlevel) {		changed = true;	}	set_soundlevel(sl);		// soundAlign	const char *soundalign_attr = m_node->get_attribute("soundAlign");	common::sound_alignment sa = m_soundalign;		if (soundalign_attr == NULL)		/*do nothing*/;	else if (strcmp(soundalign_attr, "both") == 0)		sa = common::sa_both;	else if (strcmp(soundalign_attr, "left") == 0)		sa = common::sa_left;	else if (strcmp(soundalign_attr, "right") == 0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -