本文整理汇总了C++中SVGLength类的典型用法代码示例。如果您正苦于以下问题:C++ SVGLength类的具体用法?C++ SVGLength怎么用?C++ SVGLength使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SVGLength类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DCHECK_NE
FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context,
SVGUnitTypes::SVGUnitType type,
const FloatRect& viewport,
const SVGLength& x,
const SVGLength& y,
const SVGLength& width,
const SVGLength& height) {
DCHECK_NE(SVGUnitTypes::kSvgUnitTypeUnknown, type);
if (type != SVGUnitTypes::kSvgUnitTypeUserspaceonuse) {
const FloatSize& viewportSize = viewport.size();
return FloatRect(
convertValueFromPercentageToUserUnits(x, viewportSize) + viewport.x(),
convertValueFromPercentageToUserUnits(y, viewportSize) + viewport.y(),
convertValueFromPercentageToUserUnits(width, viewportSize),
convertValueFromPercentageToUserUnits(height, viewportSize));
}
SVGLengthContext lengthContext(context);
return FloatRect(x.value(lengthContext), y.value(lengthContext),
width.value(lengthContext), height.value(lengthContext));
}
示例2: IntSize
IntSize SVGImage::size() const
{
if (!m_page)
return IntSize();
Frame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
if (!rootElement)
return IntSize();
SVGLength width = rootElement->width();
SVGLength height = rootElement->height();
IntSize svgSize;
if (width.unitType() == LengthTypePercentage)
svgSize.setWidth(rootElement->relativeWidthValue());
else
svgSize.setWidth(static_cast<int>(width.value(rootElement)));
if (height.unitType() == LengthTypePercentage)
svgSize.setHeight(rootElement->relativeHeightValue());
else
svgSize.setHeight(static_cast<int>(height.value(rootElement)));
return svgSize;
}
示例3: create
PassRefPtr<CSSPrimitiveValue> SVGLength::toCSSPrimitiveValue(const SVGLength& length)
{
CSSPrimitiveValue::UnitTypes cssType = CSSPrimitiveValue::CSS_UNKNOWN;
switch (length.unitType()) {
case LengthTypeUnknown:
break;
case LengthTypeNumber:
cssType = CSSPrimitiveValue::CSS_NUMBER;
break;
case LengthTypePercentage:
cssType = CSSPrimitiveValue::CSS_PERCENTAGE;
break;
case LengthTypeEMS:
cssType = CSSPrimitiveValue::CSS_EMS;
break;
case LengthTypeEXS:
cssType = CSSPrimitiveValue::CSS_EXS;
break;
case LengthTypePX:
cssType = CSSPrimitiveValue::CSS_PX;
break;
case LengthTypeCM:
cssType = CSSPrimitiveValue::CSS_CM;
break;
case LengthTypeMM:
cssType = CSSPrimitiveValue::CSS_MM;
break;
case LengthTypeIN:
cssType = CSSPrimitiveValue::CSS_IN;
break;
case LengthTypePT:
cssType = CSSPrimitiveValue::CSS_PT;
break;
case LengthTypePC:
cssType = CSSPrimitiveValue::CSS_PC;
break;
};
return CSSPrimitiveValue::create(length.valueInSpecifiedUnits(), cssType);
}
示例4: calculateBaselineShift
float SVGTextLayoutEngineBaseline::calculateBaselineShift(const SVGRenderStyle* style, SVGElement* lengthContext) const
{
if (style->baselineShift() == BS_LENGTH) {
SVGLength baselineShiftValueLength = style->baselineShiftValue();
if (baselineShiftValueLength.unitType() == LengthTypePercentage)
return baselineShiftValueLength.valueAsPercentage() * m_font.pixelSize();
return baselineShiftValueLength.value(lengthContext);
}
switch (style->baselineShift()) {
case BS_BASELINE:
return 0;
case BS_SUB:
return -m_font.height() / 2;
case BS_SUPER:
return m_font.height() / 2;
default:
ASSERT_NOT_REACHED();
return 0;
}
}
示例5: calculateCSSKerningAndSpacing
float SVGTextLayoutEngineSpacing::calculateCSSKerningAndSpacing(const SVGRenderStyle* style, SVGElement* lengthContext, const UChar* currentCharacter)
{
float kerning = 0;
SVGLength kerningLength = style->kerning();
if (kerningLength.unitType() == LengthTypePercentage)
kerning = kerningLength.valueAsPercentage() * m_font.pixelSize();
else
kerning = kerningLength.value(lengthContext);
const UChar* lastCharacter = m_lastCharacter;
m_lastCharacter = currentCharacter;
if (!kerning && !m_font.letterSpacing() && !m_font.wordSpacing())
return 0;
float spacing = m_font.letterSpacing() + kerning;
if (currentCharacter && lastCharacter && m_font.wordSpacing()) {
if (Font::treatAsSpace(*currentCharacter) && !Font::treatAsSpace(*lastCharacter))
spacing += m_font.wordSpacing();
}
return spacing;
}
示例6: while
SVGParsingError SVGLengthList::parseInternal(const CharType*& ptr,
const CharType* end) {
const CharType* listStart = ptr;
while (ptr < end) {
const CharType* start = ptr;
// TODO(shanmuga.m): Enable calc for SVGLengthList
while (ptr < end && *ptr != ',' && !isHTMLSpace<CharType>(*ptr))
ptr++;
if (ptr == start)
break;
String valueString(start, ptr - start);
if (valueString.isEmpty())
break;
SVGLength* length = SVGLength::create(m_mode);
SVGParsingError lengthParseStatus = length->setValueAsString(valueString);
if (lengthParseStatus != SVGParseStatus::NoError)
return lengthParseStatus.offsetWith(start - listStart);
append(length);
skipOptionalSVGSpacesOrDelimiter(ptr, end);
}
return SVGParseStatus::NoError;
}
示例7: calculateBaselineShift
// Helper function
static float calculateBaselineShift(RenderObject* item)
{
ASSERT(item);
ASSERT(item->style());
ASSERT(item->node());
ASSERT(item->node()->isSVGElement());
const Font& font = item->style()->font();
const SVGRenderStyle* svgStyle = item->style()->svgStyle();
float baselineShift = 0.0f;
if (svgStyle->baselineShift() == BS_LENGTH) {
SVGLength baselineShiftValueLength = svgStyle->baselineShiftValue();
if (baselineShiftValueLength.unitType() == LengthTypePercentage)
baselineShift = baselineShiftValueLength.valueAsPercentage() * font.pixelSize();
else
baselineShift = baselineShiftValueLength.value(static_cast<SVGElement*>(item->node()));
} else {
float baselineAscent = font.ascent() + font.descent();
switch (svgStyle->baselineShift()) {
case BS_BASELINE:
break;
case BS_SUB:
baselineShift = -baselineAscent / 2.0f;
break;
case BS_SUPER:
baselineShift = baselineAscent / 2.0f;
break;
default:
ASSERT_NOT_REACHED();
}
}
return baselineShift;
}
示例8: tokenizer
nsresult
SVGLengthList::SetValueFromString(const nsAString& aValue)
{
SVGLengthList temp;
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
tokenizer(aValue, ',', nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
nsCAutoString str; // outside loop to minimize memory churn
while (tokenizer.hasMoreTokens()) {
SVGLength length;
if (!length.SetValueFromString(tokenizer.nextToken())) {
return NS_ERROR_DOM_SYNTAX_ERR;
}
if (!temp.AppendItem(length)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
if (tokenizer.lastTokenEndedWithSeparator()) {
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
}
return CopyFrom(temp);
}
示例9: ASSERT
FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context, SVGUnitTypes::SVGUnitType type, const FloatRect& viewport, const SVGLength& x, const SVGLength& y, const SVGLength& width, const SVGLength& height)
{
ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN);
if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) {
SVGLengthContext lengthContext(context);
return FloatRect(x.value(lengthContext), y.value(lengthContext), width.value(lengthContext), height.value(lengthContext));
}
SVGLengthContext lengthContext(context, viewport);
return FloatRect(x.value(lengthContext) + viewport.x(),
y.value(lengthContext) + viewport.y(),
width.value(lengthContext),
height.value(lengthContext));
}
示例10: set
void SPGenericEllipse::set(unsigned int key, gchar const *value)
{
// There are multiple ways to set internal cx, cy, rx, and ry (via SVG attributes or Sodipodi
// attributes) thus we don't want to unset them if a read fails (e.g., when we explicitly clear
// an attribute by setting it to NULL).
SVGLength t;
switch (key) {
case SP_ATTR_CX:
case SP_ATTR_SODIPODI_CX:
if( t.read(value) ) cx = t;
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_CY:
case SP_ATTR_SODIPODI_CY:
if( t.read(value) ) cy = t;
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_RX:
case SP_ATTR_SODIPODI_RX:
if( t.read(value) && t.value > 0.0 ) this->rx = t;
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_RY:
case SP_ATTR_SODIPODI_RY:
if( t.read(value) && t.value > 0.0 ) this->ry = t;
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_R:
if( t.read(value) && t.value > 0.0 ) {
this->ry = this->rx = t;
}
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_SODIPODI_START:
if (value) {
sp_svg_number_read_d(value, &this->start);
} else {
this->start = 0;
}
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_SODIPODI_END:
if (value) {
sp_svg_number_read_d(value, &this->end);
} else {
this->end = 2 * M_PI;
}
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_SODIPODI_OPEN:
this->_closed = (!value);
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
default:
SPShape::set(key, value);
break;
}
}
示例11: convertValueFromPercentageToUserUnits
static float convertValueFromPercentageToUserUnits(const SVGLength& value, const FloatSize& viewportSize)
{
return CSSPrimitiveValue::clampToCSSLengthRange(value.scaleByPercentage(dimensionForLengthMode(value.unitMode(), viewportSize)));
}
示例12: SVGTranslateTransform
void
SVGAnimateMotionElement::animationTraverse(svgl::AnimationInfo* animinfo)
{
_elementToAnimate = animinfo->element;
_translateToAnimate = 0;
SVGTransformable* toAnimate = dynamic_cast<SVGTransformable*>(_elementToAnimate);
if(!toAnimate) {
std::cerr << "element refered by 'animateMotion' is not a SVGTransformable" << __FL__;
return;
}
Attribute< SVGAnimatedTransformList >& transform = toAnimate->transform;
{
std::vector <float> v;
v.push_back(0);
v.push_back(0);
_translateToAnimate = new SVGTranslateTransform(v);
}
MYGET_ANIMATED_VAL(transform).insertItemBefore(_translateToAnimate, 0);
_doBezierAnim=false;
_doRotateAnim = rotate_no;
_rotateToAnimate=0;
const SVGNumberList& keytimes = GET_SIMPLE_VAL(KeyTimes);
const SVGPathSegList* pl=0;
dom::Node *n = getFirstChild();
if(n) {
SVGMPathElement* mpath = 0;
for(;n;n=n->getNextSibling()) {
mpath = dynamic_cast<SVGMPathElement*>(n);
if(mpath)
break;
}
if(mpath) {
unicode::String* href = mpath->GET_SIMPLE_VAL(Href);
if(href->getLength()) {
dom::Element* de = animinfo->externalEntityManager->get(href, getOwnerDocument());
//dom::Element* de = GET_SIMPLE_VAL(OwnerSVGElement)->getElementById(href->substring(1));
SVGPathElement* path = dynamic_cast<SVGPathElement*>(de);
if(de)
pl = &(path->GET_SIMPLE_VAL(PathSegList));
}
}
}
else
pl = &(GET_SIMPLE_VAL(Path));
if (pl && pl->numberOfItems()>=2) {
BezierPath bezier;
for(unsigned int i=0; i<pl->numberOfItems(); ++i) {
const SVGPathSeg* p = pl->getItem(i);
p->updateBezier(bezier);
}
_distanceIter = new svgl::BezierPathDistanceIterator(bezier,.1);
_bezierLength = svgl::length(bezier);
unicode::String* rotate_ptr = GET_SIMPLE_VAL(Rotate);
unicode::String& rotate = *rotate_ptr;
if (rotate_ptr && rotate.getLength()) {
static unicode::String
&auto_string = *unicode::String::internString("auto"),
&auto_reverse_string = *unicode::String::internString("auto-reverse");
float rot=0;
if(rotate==auto_string) {
_doRotateAnim=rotate_auto;
}
else if(rotate==auto_reverse_string) {
_doRotateAnim=rotate_auto_reverse;
}
else {
if (unicode::get_float(rotate, &rot)) {
_doRotateAnim=rotate_angle;
}
}
if(_doRotateAnim!=rotate_no) {
std::vector<float> v;
v.push_back(rot);
v.push_back(0);
v.push_back(0);
_rotateToAnimate = new SVGRotateTransform(v);
MYGET_ANIMATED_VAL(transform).insertItemBefore(_rotateToAnimate, 1);
}
}
_doBezierAnim = true;
}
else {
const SVGLengthList& values = GET_SIMPLE_VAL(Values);
unsigned int valuesSize = values.numberOfItems();
if(valuesSize) {
if(valuesSize % 2) {
std::cerr << "'values' for 'animateMotion' must be a list of pair of length" << __FL__;
return;
}
if(keytimes.numberOfItems()) {
if(keytimes.numberOfItems()!=values.numberOfItems()) {
std::cerr << "'keyTimes' and 'values' have different size" << __FL__;
//.........这里部分代码省略.........
示例13: ATLASSERT
STDMETHODIMP CESVGRectElement::Move(ISVGView* view, double dx, double dy)
{
ATLASSERT(0);
#if 0
CComQIPtr<ILSVGRectElement> rect = m_domElement;
CComPtr<ILHTMLWindow> window;
view->GetHTMLWindow(&window);
CComPtr<ILSVGElement> viewportElement;
rect->get_viewportElement(&viewportElement);
// TODO, this can't be correct
CComPtr<ILSVGRect> _rect;
window->svgGetRBBox(viewportElement, &_rect);
SVGRect viewBox = _rect;
// x
{
CComPtr<ILSVGAnimatedLength> alength;
rect->get_x(&alength);
SVGLength length;
alength->get_baseVal(&length);
if (length.GetUnitType() == SVG_LENGTHTYPE_PERCENTAGE)
{
double dx_pcnt = dx*100/viewBox.Width;
double value;
length->get_valueInSpecifiedUnits(&value);
length->put_valueInSpecifiedUnits(value+dx_pcnt);
}
else
{
double value;
length->get_value(&value);
length->put_value(value + dx);
}
}
// y
{
CComPtr<ILSVGAnimatedLength> alength;
rect->get_y(&alength);
SVGLength length;
alength->get_baseVal(&length);
if (length.GetUnitType() == SVG_LENGTHTYPE_PERCENTAGE)
{
double dy_pcnt = dy*100/viewBox.Height;
double value;
length->get_valueInSpecifiedUnits(&value);
length->put_valueInSpecifiedUnits(value+dy_pcnt);
}
else
{
double value;
length->get_value(&value);
length->put_value(value + dy);
}
}
#endif
return S_OK;
}
示例14: GET_SIMPLE_VAL
void
SVGAnimateElement::animationTraverse(svgl::AnimationInfo* animinfo)
{
unicode::String* attrName = GET_SIMPLE_VAL(AttributeName);
SVG_ANIMATION_ATTRIBUTE_TYPE attrType = GET_SIMPLE_VAL(AttributeType);
_elementToAnimate = animinfo->element;
_attributeToAnimate=0;
switch (attrType) {
case SVG_ANIMATION_ATTRIBUTE_TYPE_CSS:
std::cerr << "CSS animation not supported" << __FL__;
return;
break;
default:
attributeType.setValue(SVG_ANIMATION_ATTRIBUTE_TYPE_AUTO);
case SVG_ANIMATION_ATTRIBUTE_TYPE_AUTO:
case SVG_ANIMATION_ATTRIBUTE_TYPE_XML:
{
_attributeToAnimate = _elementToAnimate->getAttributeByName(attrName);
}
break;
#if 0
default:
std::cerr << "SVG_ANIMATION_ATTRIBUTE is set to UNKNOWN" << __FL__;
break;
#endif
}
if(_attributeToAnimate==0) {
if(css::CSSStyleDeclaration::isStyleAttribute(attrName)) {
std::cerr << "attribute '" << attrName << "' for element '" << _elementToAnimate->getDtdElement() << "' is a style attribute and is not yet supported yet '<animate>'" << __FL__;
}
else {
std::cerr << "attribute '" << attrName << "' does not exist for element " << _elementToAnimate->getDtdElement() << __FL__;
}
return;
}
if(!_attributeToAnimate->canBeSetAsDouble()) {
_attributeToAnimate=0;
std::cerr << "attribute '" << attrName << "' in element '" << _elementToAnimate->getDtdElement() << "' can not be set as double" << __FL__;
return;
}
const SVGLengthList& values = GET_SIMPLE_VAL(Values);
#if 0
std::cerr << "-- values" << __FL__;
for(unsigned int t=0; t<values.size(); ++t)
std::cerr << values[t] << " ";
std::cerr << std::endl;
#endif
if(values.numberOfItems()) {
const SVGNumberList& keytimes = GET_SIMPLE_VAL(KeyTimes);
#if 0
std::cerr << "** keytimes " << __FL__;
#endif
if(keytimes.numberOfItems()) {
if(keytimes.numberOfItems()!=values.numberOfItems()) {
std::cerr << "'keyTimes' and 'values' have different size" << __FL__;
return;
}
for(std::vector<float>::size_type i=0;
i<values.numberOfItems();
++i) {
SVGLength l = values.getItem(i);
float v = l.computeValue();
_keyFrames.push_back(KeyFrame(v, keytimes.getItem(i).GET_SIMPLE_VAL(Value)));
// std::cerr << values[i] << " " << keytimes[i];
}
// std::cerr << std::endl;
}
else {
for(std::vector<float>::size_type i=0;
i<values.numberOfItems();
++i) {
float t=i/((float)values.numberOfItems()-1);
SVGLength l = values.getItem(i);
float v = l.computeValue();
_keyFrames.push_back(KeyFrame(v, t));
}
}
}
else {
unicode::String* fromstr = GET_SIMPLE_VAL(From);
unicode::String* tostr = GET_SIMPLE_VAL(To);
unicode::String* bystr = GET_SIMPLE_VAL(By);
//std::cerr << DBGVAR(attrName) << DBGVAR(attrType) << DBGVAR(fromstr) << DBGVAR(tostr) << __FL__;
SVGLength froml, tol, byl;
bool fromb=false, tob=false, byb=false;
froml.dom_setValueAsString(fromstr);
tol.dom_setValueAsString(tostr);
byl.dom_setValueAsString(bystr);
//.........这里部分代码省略.........