2011-09-25 14:04:31 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-09-25 14:04:31 -07:00
|
|
|
|
|
|
|
#include "SVGTransformList.h"
|
2011-09-25 14:04:32 -07:00
|
|
|
#include "SVGTransformListParser.h"
|
2012-01-26 01:57:21 -08:00
|
|
|
#include "nsString.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2011-09-25 14:04:31 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
gfxMatrix
|
|
|
|
SVGTransformList::GetConsolidationMatrix() const
|
|
|
|
{
|
|
|
|
// To benefit from Return Value Optimization and avoid copy constructor calls
|
|
|
|
// due to our use of return-by-value, we must return the exact same object
|
|
|
|
// from ALL return points. This function must only return THIS variable:
|
|
|
|
gfxMatrix result;
|
|
|
|
|
|
|
|
if (mItems.IsEmpty())
|
|
|
|
return result;
|
|
|
|
|
2014-03-17 19:41:35 -07:00
|
|
|
result = mItems[0].GetMatrix();
|
2011-09-25 14:04:31 -07:00
|
|
|
|
|
|
|
if (mItems.Length() == 1)
|
|
|
|
return result;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 1; i < mItems.Length(); ++i) {
|
2014-03-17 19:41:35 -07:00
|
|
|
result.PreMultiply(mItems[i].GetMatrix());
|
2011-09-25 14:04:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGTransformList::CopyFrom(const SVGTransformList& rhs)
|
|
|
|
{
|
|
|
|
return CopyFrom(rhs.mItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-04-02 12:17:41 -07:00
|
|
|
SVGTransformList::CopyFrom(const nsTArray<nsSVGTransform>& aTransformArray)
|
2011-09-25 14:04:31 -07:00
|
|
|
{
|
|
|
|
if (!mItems.SetCapacity(aTransformArray.Length())) {
|
|
|
|
// Yes, we do want fallible alloc here
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mItems = aTransformArray;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGTransformList::GetValueAsString(nsAString& aValue) const
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t last = mItems.Length() - 1;
|
|
|
|
for (uint32_t i = 0; i < mItems.Length(); ++i) {
|
2011-09-25 14:04:31 -07:00
|
|
|
nsAutoString length;
|
|
|
|
mItems[i].GetValueAsString(length);
|
|
|
|
// We ignore OOM, since it's not useful for us to return an error.
|
|
|
|
aValue.Append(length);
|
|
|
|
if (i != last) {
|
|
|
|
aValue.Append(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGTransformList::SetValueFromString(const nsAString& aValue)
|
|
|
|
{
|
2013-10-29 10:15:39 -07:00
|
|
|
SVGTransformListParser parser(aValue);
|
|
|
|
if (!parser.Parse()) {
|
2011-09-25 14:04:31 -07:00
|
|
|
// there was a parse error.
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CopyFrom(parser.GetTransformList());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|