コード例 #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
static void writeImageToDataObject(DataObject* dataObject,
                                   Element* element,
                                   const KURL& url) {
  // Shove image data into a DataObject for use as a file
  ImageResourceContent* cachedImage = getImageResourceContent(element);
  if (!cachedImage || !cachedImage->getImage() || !cachedImage->isLoaded())
    return;

  RefPtr<SharedBuffer> imageBuffer = cachedImage->getImage()->data();
  if (!imageBuffer || !imageBuffer->size())
    return;

  String imageExtension = cachedImage->getImage()->filenameExtension();
  ASSERT(!imageExtension.isEmpty());

  // Determine the filename for the file contents of the image.
  String filename = cachedImage->response().suggestedFilename();
  if (filename.isEmpty())
    filename = url.lastPathComponent();

  String fileExtension;
  if (filename.isEmpty()) {
    filename = element->getAttribute(HTMLNames::altAttr);
  } else {
    // Strip any existing extension. Assume that alt text is usually not a
    // filename.
    int extensionIndex = filename.reverseFind('.');
    if (extensionIndex != -1) {
      fileExtension = filename.substring(extensionIndex + 1);
      filename.truncate(extensionIndex);
    }
  }

  if (!fileExtension.isEmpty() && fileExtension != imageExtension) {
    String imageMimeType =
        MIMETypeRegistry::getMIMETypeForExtension(imageExtension);
    ASSERT(imageMimeType.startsWith("image/"));
    // Use the file extension only if it has imageMimeType: it's untrustworthy
    // otherwise.
    if (imageMimeType ==
        MIMETypeRegistry::getMIMETypeForExtension(fileExtension))
      imageExtension = fileExtension;
  }

  imageExtension = "." + imageExtension;
  validateFilename(filename, imageExtension);

  dataObject->addSharedBuffer(filename + imageExtension, imageBuffer);
}
コード例 #4
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());
}