本文整理汇总了C++中SPDocument::getObjectById方法的典型用法代码示例。如果您正苦于以下问题:C++ SPDocument::getObjectById方法的具体用法?C++ SPDocument::getObjectById怎么用?C++ SPDocument::getObjectById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPDocument
的用法示例。
在下文中一共展示了SPDocument::getObjectById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
SPObject *get_stock_item(gchar const *urn, gboolean stock)
{
g_assert(urn != NULL);
/* check its an inkscape URN */
if (!strncmp (urn, "urn:inkscape:", 13)) {
gchar const *e = urn + 13;
int a = 0;
gchar * name = g_strdup(e);
gchar *name_p = name;
while (*name_p != ':' && *name_p != '\0'){
name_p++;
a++;
}
if (*name_p ==':') {
name_p++;
}
gchar * base = g_strndup(e, a);
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
SPDocument *doc = desktop->getDocument();
SPDefs *defs = doc->getDefs();
if (!defs) {
g_free(base);
return NULL;
}
SPObject *object = NULL;
if (!strcmp(base, "marker") && !stock) {
for ( SPObject *child = defs->firstChild(); child; child = child->getNext() )
{
if (child->getRepr()->attribute("inkscape:stockid") &&
!strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) &&
SP_IS_MARKER(child))
{
object = child;
}
}
}
else if (!strcmp(base,"pattern") && !stock) {
for ( SPObject *child = defs->firstChild() ; child; child = child->getNext() )
{
if (child->getRepr()->attribute("inkscape:stockid") &&
!strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) &&
SP_IS_PATTERN(child))
{
object = child;
}
}
}
else if (!strcmp(base,"gradient") && !stock) {
for ( SPObject *child = defs->firstChild(); child; child = child->getNext() )
{
if (child->getRepr()->attribute("inkscape:stockid") &&
!strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) &&
SP_IS_GRADIENT(child))
{
object = child;
}
}
}
if (object == NULL) {
if (!strcmp(base, "marker")) {
object = sp_marker_load_from_svg(name_p, doc);
}
else if (!strcmp(base, "pattern")) {
object = sp_pattern_load_from_svg(name_p, doc);
}
else if (!strcmp(base, "gradient")) {
object = sp_gradient_load_from_svg(name_p, doc);
}
}
g_free(base);
g_free(name);
if (object) {
object->getRepr()->setAttribute("inkscape:isstock", "true");
}
return object;
}
else {
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
SPDocument *doc = desktop->getDocument();
SPObject *object = doc->getObjectById(urn);
return object;
}
}
示例2: attach
void URIReference::attach(const URI &uri) throw(BadURIException)
{
SPDocument *document = NULL;
// Attempt to get the document that contains the URI
if (_owner) {
document = _owner->document;
} else if (_owner_document) {
document = _owner_document;
}
// createChildDoc() assumes that the referenced file is an SVG.
// PNG and JPG files are allowed (in the case of feImage).
gchar *filename = uri.toString();
bool skip = false;
if( g_str_has_suffix( filename, ".jpg" ) ||
g_str_has_suffix( filename, ".JPG" ) ||
g_str_has_suffix( filename, ".png" ) ||
g_str_has_suffix( filename, ".PNG" ) ) {
skip = true;
}
// The path contains references to separate document files to load.
if(document && uri.getPath() && !skip ) {
std::string base = document->getBase() ? document->getBase() : "";
std::string path = uri.getFullPath(base);
if(!path.empty()) {
document = document->createChildDoc(path);
} else {
document = NULL;
}
}
if(!document) {
g_warning("Can't get document for referenced URI: %s", filename);
g_free( filename );
return;
}
g_free( filename );
gchar const *fragment = uri.getFragment();
if ( !uri.isRelative() || uri.getQuery() || !fragment ) {
throw UnsupportedURIException();
}
/* FIXME !!! real xpointer support should be delegated to document */
/* for now this handles the minimal xpointer form that SVG 1.0
* requires of us
*/
gchar *id = NULL;
if (!strncmp(fragment, "xpointer(", 9)) {
/* FIXME !!! this is wasteful */
/* FIXME: It looks as though this is including "))" in the id. I suggest moving
the strlen calculation and validity testing to before strdup, and copying just
the id without the "))". -- pjrm */
if (!strncmp(fragment, "xpointer(id(", 12)) {
id = g_strdup(fragment+12);
size_t const len = strlen(id);
if ( len < 3 || strcmp(id+len-2, "))") ) {
g_free(id);
throw MalformedURIException();
}
} else {
throw UnsupportedURIException();
}
} else {
id = g_strdup(fragment);
}
/* FIXME !!! validate id as an NCName somewhere */
_connection.disconnect();
delete _uri;
_uri = new URI(uri);
_setObject(document->getObjectById(id));
_connection = document->connectIdChanged(id, sigc::mem_fun(*this, &URIReference::_setObject));
g_free(id);
}