tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SVGTransformList.cpp (2001B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "SVGTransformList.h"
      8 
      9 #include "SVGTransformListParser.h"
     10 #include "nsError.h"
     11 #include "nsString.h"
     12 
     13 namespace mozilla {
     14 
     15 gfxMatrix SVGTransformList::GetConsolidationMatrix() const {
     16  // To benefit from Return Value Optimization and avoid copy constructor calls
     17  // due to our use of return-by-value, we must return the exact same object
     18  // from ALL return points. This function must only return THIS variable:
     19  gfxMatrix result;
     20 
     21  if (mItems.IsEmpty()) return result;
     22 
     23  result = mItems[0].GetMatrix();
     24 
     25  if (mItems.Length() == 1) return result;
     26 
     27  for (uint32_t i = 1; i < mItems.Length(); ++i) {
     28    result.PreMultiply(mItems[i].GetMatrix());
     29  }
     30 
     31  return result;
     32 }
     33 
     34 nsresult SVGTransformList::CopyFrom(const SVGTransformList& rhs) {
     35  return CopyFrom(rhs.mItems);
     36 }
     37 
     38 nsresult SVGTransformList::CopyFrom(
     39    const nsTArray<SVGTransform>& aTransformArray) {
     40  if (!mItems.Assign(aTransformArray, fallible)) {
     41    return NS_ERROR_OUT_OF_MEMORY;
     42  }
     43  return NS_OK;
     44 }
     45 
     46 void SVGTransformList::GetValueAsString(nsAString& aValue) const {
     47  aValue.Truncate();
     48  uint32_t last = mItems.Length() - 1;
     49  for (uint32_t i = 0; i < mItems.Length(); ++i) {
     50    nsAutoString length;
     51    mItems[i].GetValueAsString(length);
     52    // We ignore OOM, since it's not useful for us to return an error.
     53    aValue.Append(length);
     54    if (i != last) {
     55      aValue.Append(' ');
     56    }
     57  }
     58 }
     59 
     60 nsresult SVGTransformList::SetValueFromString(const nsAString& aValue) {
     61  SVGTransformListParser parser(aValue);
     62  if (!parser.Parse()) {
     63    // there was a parse error.
     64    return NS_ERROR_DOM_SYNTAX_ERR;
     65  }
     66 
     67  return CopyFrom(parser.GetTransformList());
     68 }
     69 
     70 }  // namespace mozilla