📄 time_attrs.cpp
字号:
event = "marker"; bool succeeded = false; size_type open_par_ix = s1.find('('); size_type close_par_ix = s1.find(')'); if(open_par_ix != std::string::npos && close_par_ix != std::string::npos) { svs.sparam = trim(s1.substr(open_par_ix+1, close_par_ix - open_par_ix - 1)); succeeded = true; } if(!succeeded) { m_logger->trace("%s[%s].%s invalid marker [%s]", m_tag.c_str(), m_id.c_str(), time_spec_id(sl), s.c_str()); m_logger->warn(gettext("Error in SMIL timing info in document")); return; } } else if(ends_with(nmtoken, ".repeat")) { // repeat event-value svs.type = sv_repeat; svs.base = nmtoken.substr(0, last_dot_ix); event = "repeat"; bool succeeded = false; size_type open_par_ix = s1.find('('); if(open_par_ix != std::string::npos) { std::string sn = s1.substr(open_par_ix+1); int_p iparser; b = sn.begin(); e = sn.end(); if(iparser.parse(b, e) != -1) { svs.iparam = iparser.m_result; succeeded = true; } } if(!succeeded) { m_logger->trace("%s[%s].%s invalid repeat [%s]", m_tag.c_str(), m_id.c_str(), time_spec_id(sl), s.c_str()); m_logger->warn(gettext("Error in SMIL timing info in document")); return; } } else { // event-value other than repeat svs.type = sv_event; svs.base = nmtoken.substr(0, last_dot_ix); event = nmtoken.substr(last_dot_ix+1); }#ifdef CHECK_EVENT_NAMES if(events.find(event) == events.end()) { m_logger->trace("%s[%s].%s invalid event [%s]", m_tag.c_str(), m_id.c_str(), time_spec_id(sl), s.c_str()); m_logger->warn(gettext("Error in SMIL timing info in document")); } else {#else {#endif // CHECK_EVENT_NAMES svs.event = event; AM_DBG m_logger->debug("%s[%s].%s += [%s]", m_tag.c_str(), m_id.c_str(), time_spec_id(sl), repr(svs).c_str()); } // if base is not empty, locate node // else base is the default if(!svs.event.empty()) sl.push_back(svs); }// endsync ::= first | last | all | media | Id-value | smil1.0-Id-valuevoid time_attrs::parse_endsync() { m_endsync.rule = esr_last; const char *p = m_node->get_attribute("endsync"); if(!p) return; set_specified(SP_ENDSYNC); std::string endsync_str = trim(p); if(endsync_str == "first") m_endsync.rule = esr_first; else if(endsync_str == "last") m_endsync.rule = esr_last; else if(endsync_str == "all") m_endsync.rule = esr_all; else if(endsync_str == "media") m_endsync.rule = esr_media; else { m_endsync.rule = esr_id; xml_nmtoken_p parser; if(!parser.matches(endsync_str)) { m_logger->trace("invalid endsync attr [%s] for %s[%s]", endsync_str.c_str(), m_tag.c_str(), m_id.c_str()); m_logger->warn(gettext("Error in SMIL timing info in document")); } else { m_endsync.ident = endsync_str; } } AM_DBG m_logger->debug("%s[%s].endsync = [%s]", m_tag.c_str(), m_id.c_str(), endsync_str.c_str()); }// fill ::= remove | freeze | hold | transition | auto | defaultvoid time_attrs::parse_fill() { m_fill = modulated_fill(get_default_fill()); const char *p = m_node->get_attribute("fill"); if(!p) { AM_DBG m_logger->debug("%s[%s].fill = [%s]", m_tag.c_str(), m_id.c_str(), repr(m_fill).c_str()); return; } set_specified(SP_FILL); std::string fill = trim(p); if(fill == "remove") m_fill = fill_remove; else if(fill == "freeze") m_fill = fill_freeze; else if(fill == "hold") m_fill = fill_hold; else if(fill == "transition") m_fill = fill_transition; else if(fill == "auto") m_fill = fill_auto; // else default or invalid if(m_fill == fill_auto) m_fill = modulated_fill(m_fill); AM_DBG m_logger->debug("%s[%s].fill = [%s]", m_tag.c_str(), m_id.c_str(), repr(m_fill).c_str()); }fill_behavior time_attrs::modulated_fill(fill_behavior fb) { if(fb != fill_auto) return fb; bool dv = (specified_dur() || specified_rdur() || specified_rcount() || specified_end()); return dv?fill_remove:fill_freeze;}// Returns the fillDefault attribute active for this. // fillDefault ::= remove | freeze | hold | transition | auto | inherit// Applicable for an element and all descendentsfill_behavior time_attrs::get_default_fill() { fill_behavior retfb = fill_auto; const node *curr = m_node; while(curr) { const char *p = curr->get_attribute("fillDefault"); if(p) { //if(p && valid_fill_default(p) && not_inherit(p)) break; std::string fill = trim(p); if(fill == "remove") {retfb = fill_remove; break;} else if(fill == "freeze") {retfb = fill_freeze; break;} else if(fill == "hold") {retfb = fill_hold; break;} else if(fill == "transition") {retfb = fill_transition; break;} else if(fill == "auto") {retfb = fill_auto; break;} // else inherit or invalid e.g. continue } curr = curr->up(); } return retfb;}// restart ::= always | whenNotActive | never | defaultvoid time_attrs::parse_restart() { m_restart = get_default_restart(); const char *p = m_node->get_attribute("restart"); if(!p) return; set_specified(SP_RESTART); std::string restart = trim(p); if(restart == "always") m_restart = restart_always; else if(restart == "whenNotActive") m_restart = restart_when_not_active; else if(restart == "never") m_restart = restart_never; // else restart == "default" AM_DBG m_logger->debug("%s[%s].restart = [%s]", m_tag.c_str(), m_id.c_str(), repr(m_restart).c_str());}// actuate ::= onLoad | onRequestvoid time_attrs::parse_actuate() { m_actuate = actuate_onrequest; const char *p = m_node->get_attribute("actuate"); if(!p) return; std::string actuate = trim(p); if(actuate == "onLoad") m_actuate = actuate_onload; else if(actuate == "onRequest") m_actuate = actuate_onrequest; AM_DBG m_logger->debug("%s[%s].actuate = [%s]", m_tag.c_str(), m_id.c_str(), repr(m_actuate).c_str());}// Returns the restartDefault attribute active for this. // restartDefault := always | whenNotActive | never | inherit // Applicable for an element and all descendents// Returns one of : always | whenNotActive | neverrestart_behavior time_attrs::get_default_restart() { restart_behavior rb = restart_always; const node *curr = m_node; while(curr) { const char *p = curr->get_attribute("restartDefault"); if(p) { std::string restart = trim(p); if(restart == "always") { rb = restart_always; break;} else if(restart == "whenNotActive") { rb = restart_when_not_active; break;} else if(restart == "never") { rb = restart_never; break;} } curr = curr->up(); } return rb;}void time_attrs::parse_transitions() { const node_context *nctx = m_node->get_context(); const char *p = m_node->get_attribute("transIn"); m_trans_in = 0; if(p) { m_trans_in = transition_info::from_node(nctx->get_node(p)); if(!m_trans_in) { m_logger->trace("%s[%s] failed to locate transIn element: [%s]", m_tag.c_str(), m_id.c_str(), p); m_logger->warn(gettext("Error in SMIL transition info in document")); } else { if(get_trans_in_dur()() == 0) { m_logger->trace("%s[%s] the specified transIn element has invalid dur", m_tag.c_str(), m_id.c_str()); m_trans_in = 0; m_logger->warn(gettext("Error in SMIL transition info in document")); } } } p = m_node->get_attribute("transOut"); m_trans_out = 0; if(p) { m_trans_out = transition_info::from_node(nctx->get_node(p)); if(!m_trans_out) { m_logger->trace("%s[%s] failed to locate transOut element: [%s]", m_tag.c_str(), m_id.c_str(), p); m_logger->warn(gettext("Error in SMIL transition info in document")); } else { if(get_trans_out_dur()() == 0) { m_logger->trace("%s[%s] the specified transOut element has invalid dur", m_tag.c_str(), m_id.c_str()); m_logger->warn(gettext("Error in SMIL transition info in document")); m_trans_out = 0; } } }}void time_attrs::parse_time_manipulations() { const char *p = m_node->get_attribute("speed"); if(p) m_speed = atof(p); else m_speed = 1.0; if(m_speed == 0.0) m_speed = 1.0; // limit speed to 0.01 resolution double abs_speed = m_speed>0.0?m_speed:-m_speed; unsigned long speed100 = (unsigned long)(::floor(0.5 + abs_speed * 100)); if(speed100 == 0) speed100 = 1; m_speed = m_speed>0.0?0.01*speed100:-0.01*speed100; p = m_node->get_attribute("accelerate"); if(p) m_accelerate = atof(p); else m_accelerate = 0; m_accelerate = (m_accelerate<0.0)?0.0:((m_accelerate>1.0)?1.0:m_accelerate); p = m_node->get_attribute("decelerate"); if(p) m_decelerate = std::max(0.0, atof(p)); else m_decelerate = 0; m_decelerate = (m_decelerate<0.0)?0.0:((m_decelerate>1.0)?1.0:m_decelerate); if(m_accelerate + m_decelerate > 1.0) { m_accelerate = m_decelerate = 0; } p = m_node->get_attribute("autoReverse"); if(p) m_auto_reverse = (strcmp(p, "true") == 0); else m_auto_reverse = false;}bool time_attrs::has_time_manipulations() const { return m_speed != 1.0 || m_accelerate != 0.0 || m_decelerate != 0.0 || m_auto_reverse;}////////////////// helpers///////////////////////// Tracingstd::string smil2::repr(sync_value_type sv) { switch(sv) { case sv_offset: return "offset"; case sv_syncbase: return "syncbase"; case sv_event: return "event"; case sv_repeat: return "repeat"; case sv_accesskey: return "accesskey"; case sv_media_marker: return "marker"; case sv_wallclock: return "wallclock"; case sv_indefinite: return "indefinite"; } assert(false); return "";}std::string smil2::repr(const sync_value_struct& svs) { std::string os; char sz[64]; if(svs.type == sv_offset) { sprintf(sz, "%ld", svs.offset); os += sz; } else if(svs.type == sv_accesskey) { sprintf(sz, "accesskey(%c)", char(svs.iparam)); os += sz; if(svs.offset>0) {sprintf(sz, " + %ld", svs.offset); os += sz;} else if(svs.offset<0) {sprintf(sz, " - %ld", -svs.offset); os += sz;} } else { if(svs.base.empty()) { os += svs.event; } else { os += svs.base + "." + svs.event; } if(svs.iparam != -1) { sprintf(sz, "(%d)", svs.iparam); os += sz; } else if(!svs.sparam.empty()) os += "(" + svs.sparam + ")"; if(svs.offset>0) {sprintf(sz, " + %ld", svs.offset);os += sz;} else if(svs.offset<0) {sprintf(sz, " - %ld", -svs.offset);os += sz;} } return os;}std::string smil2::repr(fill_behavior f) { switch(f) { case fill_remove: return "remove"; case fill_freeze: return "freeze"; case fill_hold: return "hold"; case fill_transition: return "transition"; case fill_auto: return "auto"; case fill_default: return "default"; case fill_inherit: return "inherit"; } assert(false); return "";}std::string smil2::repr(restart_behavior f) { switch(f) { case restart_always: return "always"; case restart_when_not_active: return "whenNotActive"; case restart_never: return "never"; case restart_default: return "default"; case restart_inherit: return "inherit"; } assert(false); return "";}std::string smil2::repr(actuate f) { switch(f) { case actuate_onload: return "onLoad"; case actuate_onrequest: return "onRequest"; } assert(false); return "";}/////////////////////////////// priority_attrs implementation// staticpriority_attrs* priority_attrs::create_instance(const lib::node *n) { assert(n->get_local_name() == "priorityClass"); priority_attrs *pa = new priority_attrs(); const char *p; std::string spec; p = n->get_attribute("peers"); spec = p?p:"stop"; if(spec == "stop" || spec == "pause" || spec == "defer" || spec == "never") pa->peers = interrupt_from_str(spec); p = n->get_attribute("higher"); spec = p?p:"pause"; if(spec == "stop" || spec == "pause") pa->higher = interrupt_from_str(spec); p = n->get_attribute("lower"); spec = p?p:"defer"; if(spec == "defer" || spec == "never") pa->lower = interrupt_from_str(spec); p = n->get_attribute("pauseDisplay"); spec = p?p:"show"; if(spec == "disable" || spec == "hide" || spec == "show") pa->display = display_from_str(spec); return pa;}// static interrupt_type priority_attrs::interrupt_from_str(const std::string& spec) { if(spec == "stop") return int_stop; else if(spec == "pause") return int_pause; else if(spec == "defer") return int_defer; else if(spec == "never") return int_never; return int_stop;}//static pause_display priority_attrs::display_from_str(const std::string& spec) { if(spec == "disable") return display_disable; else if(spec == "hide") return display_hide; else if(spec == "show") return display_show; return display_show;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -