예제 #1
0
FloatSize SVGImagePainter::computeImageViewportSize() const {
  DCHECK(m_layoutSVGImage.imageResource()->hasImage());

  if (toSVGImageElement(m_layoutSVGImage.element())
          ->preserveAspectRatio()
          ->currentValue()
          ->align() != SVGPreserveAspectRatio::kSvgPreserveaspectratioNone)
    return m_layoutSVGImage.objectBoundingBox().size();

  ImageResourceContent* cachedImage =
      m_layoutSVGImage.imageResource()->cachedImage();

  // Images with preserveAspectRatio=none should force non-uniform scaling. This
  // can be achieved by setting the image's container size to its viewport size
  // (i.e. concrete object size returned by the default sizing algorithm.)  See
  // https://www.w3.org/TR/SVG/single-page.html#coords-PreserveAspectRatioAttribute
  // and https://drafts.csswg.org/css-images-3/#default-sizing.

  // Avoid returning the size of the broken image.
  if (cachedImage->errorOccurred())
    return FloatSize();

  if (cachedImage->getImage()->isSVGImage())
    return toSVGImage(cachedImage->getImage())
        ->concreteObjectSize(m_layoutSVGImage.objectBoundingBox().size());

  return FloatSize(cachedImage->getImage()->size());
}
예제 #2
0
static Image* renderableImageForCSSValue(CSSValue* value,
                                         const LayoutObject& layoutObject) {
  ImageResourceContent* cachedImage =
      cachedImageForCSSValue(value, layoutObject.document());

  if (!cachedImage || cachedImage->errorOccurred() ||
      cachedImage->getImage()->isNull())
    return nullptr;

  return cachedImage->getImage();
}
예제 #3
0
FloatSize LayoutSVGImage::calculateObjectSize() const {
  ImageResourceContent* cachedImage = m_imageResource->cachedImage();
  if (!cachedImage || cachedImage->errorOccurred())
    return m_objectBoundingBox.size();

  FloatSize intrinsicSize = FloatSize(cachedImage->getImage()->size());
  if (styleRef().width().isAuto() && styleRef().height().isAuto())
    return intrinsicSize;

  if (styleRef().height().isAuto())
    return FloatSize(
        m_objectBoundingBox.width(),
        resolveHeightForRatio(m_objectBoundingBox.width(), intrinsicSize));

  DCHECK(styleRef().width().isAuto());
  return FloatSize(
      resolveWidthForRatio(m_objectBoundingBox.height(), intrinsicSize),
      m_objectBoundingBox.height());
}