sp-string.cpp revision ff4ea886f996cc57a3e9d6fde8ca2c03dbb25907
/*
* SVG <text> and <tspan> implementation
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/*
* fixme:
*
* These subcomponents should not be items, or alternately
* we have to invent set of flags to mark, whether standard
* attributes are applicable to given item (I even like this
* idea somewhat - Lauris)
*
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "sp-string.h"
#include "style.h"
#include "sp-factory.h"
#include <iostream>
namespace {
SPObject* createString() {
return new SPString();
}
}
/*#####################################################
# SPSTRING
#####################################################*/
}
}
object->read_content();
}
}
void SPString::read_content() {
//XML Tree being used directly here while it shouldn't be.
// std::cout << ">" << (xml_string?xml_string:"Null") << "<" << std::endl;
// See: http://dev.w3.org/csswg/css-text/#white-space
// ---------|------------|--------------|--------------
// normal | Collapes | Collapse | Wrap
// pre | Preserve | Preserve | No Wrap
// nowrap | Collapse | Collapse | No Wrap
// pre-wrap | Preserve | Preserve | Wrap
// pre-line | Preserve | Collapse | Wrap
// 'xml:space' has two values:
// 'default' which corresponds to 'normal' (without wrapping).
// 'preserve' which corresponds to 'pre' except new lines are converted to spaces.
// See algorithms described in svg 1.1 section 10.15
bool collapse_space = true;
bool collapse_line = true;
bool is_css = false;
// Strings don't have style, check parent for style
collapse_line = false;
}
collapse_space = false;
}
is_css = true; // If white-space not normal, we assume white-space is set.
}
}
if( !is_css ) {
// SVG 2: Use 'xml:space' only if 'white-space' not 'normal'.
collapse_space = false;
}
}
bool white_space = false;
switch (c) {
case 0xd: // Carriage return
// XML Parsers convert 0xa, 0xd, 0xD 0xA to 0xA. CSS also follows this rule so we
// should never see 0xd.
continue;
break;
case 0xa: // Line feed
if( collapse_line ) {
white_space = true; // Convert to space and collapse
} else {
continue;
}
break;
case '\t': // Tab
if( collapse_space ) {
white_space = true; // Convert to space and collapse
} else {
continue;
}
break;
case ' ': // Space
if( collapse_space ) {
white_space = true; // Collapse white space
} else {
continue;
}
break;
default:
}
white_space = false;
} // End switch
} // End loop
// Insert white space at end if more text follows
if (white_space && object->getRepr()->next() != NULL) { // can't use SPObject::getNext() when the SPObject tree is still being built
}
// std::cout << ">" << string->string << "<" << std::endl;
}
// SPObject::onUpdate(ctx, flags);
// if (flags & (SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_MODIFIED_FLAG)) {
// /* Parent style or we ourselves changed, so recalculate */
// flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // won't be "just a transformation" anymore, we're going to recompute "x" and "y" attributes
// }
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :