Example #1
0
/* readonly attribute int32_t width; */
NS_IMETHODIMP
VectorImage::GetWidth(int32_t* aWidth)
{
  if (mError || !mIsFullyLoaded) {
    *aWidth = -1;
  } else {
    SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
    MOZ_ASSERT(rootElem, "Should have a root SVG elem, since we finished "
                         "loading without errors");
    *aWidth = rootElem->GetIntrinsicWidth();
  }
  return *aWidth >= 0 ? NS_OK : NS_ERROR_FAILURE;
}
Example #2
0
VectorImage::GetFrame(uint32_t aWhichFrame,
                      uint32_t aFlags)
{
  MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);

  if (aWhichFrame > FRAME_MAX_VALUE) {
    return nullptr;
  }

  if (mError || !mIsFullyLoaded) {
    return nullptr;
  }

  // Look up height & width
  // ----------------------
  SVGSVGElement* svgElem = mSVGDocumentWrapper->GetRootSVGElem();
  MOZ_ASSERT(svgElem, "Should have a root SVG elem, since we finished "
                      "loading without errors");
  nsIntSize imageIntSize(svgElem->GetIntrinsicWidth(),
                         svgElem->GetIntrinsicHeight());

  if (imageIntSize.IsEmpty()) {
    // We'll get here if our SVG doc has a percent-valued or negative width or
    // height.
    return nullptr;
  }

  // Make our surface the size of what will ultimately be drawn to it.
  // (either the full image size, or the restricted region)
  RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->
    CreateOffscreenContentDrawTarget(IntSize(imageIntSize.width,
                                             imageIntSize.height),
                                     SurfaceFormat::B8G8R8A8);
  if (!dt) {
    NS_ERROR("Could not create a DrawTarget");
    return nullptr;
  }

  nsRefPtr<gfxContext> context = new gfxContext(dt);

  auto result = Draw(context, imageIntSize,
                     ImageRegion::Create(imageIntSize),
                     aWhichFrame, GraphicsFilter::FILTER_NEAREST,
                     Nothing(), aFlags);

  return result == DrawResult::SUCCESS ? dt->Snapshot() : nullptr;
}
Example #3
0
VectorImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags)
{
  // Look up height & width
  // ----------------------
  SVGSVGElement* svgElem = mSVGDocumentWrapper->GetRootSVGElem();
  MOZ_ASSERT(svgElem, "Should have a root SVG elem, since we finished "
                      "loading without errors");
  nsIntSize imageIntSize(svgElem->GetIntrinsicWidth(),
                         svgElem->GetIntrinsicHeight());

  if (imageIntSize.IsEmpty()) {
    // We'll get here if our SVG doc has a percent-valued or negative width or
    // height.
    return nullptr;
  }

  return GetFrameAtSize(imageIntSize, aWhichFrame, aFlags);
}
Example #4
0
//******************************************************************************
NS_IMETHODIMP
VectorImage::GetWidth(int32_t* aWidth)
{
  if (mError || !mIsFullyLoaded) {
    // XXXdholbert Technically we should leave outparam untouched when we
    // fail. But since many callers don't check for failure, we set it to 0 on
    // failure, for sane/predictable results.
    *aWidth = 0;
    return NS_ERROR_FAILURE;
  }

  SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
  MOZ_ASSERT(rootElem, "Should have a root SVG elem, since we finished "
             "loading without errors");
  int32_t rootElemWidth = rootElem->GetIntrinsicWidth();
  if (rootElemWidth < 0) {
    *aWidth = 0;
    return NS_ERROR_FAILURE;
  }
  *aWidth = rootElemWidth;
  return NS_OK;
}