1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
|
/*
* Copyright (C) 2004-2023 Apple Inc. All rights reserved.
* Copyright (C) 2016 Google Inc. All rights reserved.
* (C) 2005 Rob Buis <buis@kde.org>
* (C) 2006 Alexander Kellett <lypanov@kde.org>
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "SVGRenderTreeAsText.h"
#include "ColorSerialization.h"
#include "InlineIteratorBoxInlines.h"
#include "InlineIteratorInlineBox.h"
#include "InlineIteratorSVGTextBox.h"
#include "LegacyRenderSVGImage.h"
#include "LegacyRenderSVGResourceClipperInlines.h"
#include "LegacyRenderSVGResourceFilterInlines.h"
#include "LegacyRenderSVGResourceLinearGradientInlines.h"
#include "LegacyRenderSVGResourceMarkerInlines.h"
#include "LegacyRenderSVGResourceMaskerInlines.h"
#include "LegacyRenderSVGResourcePattern.h"
#include "LegacyRenderSVGResourceRadialGradientInlines.h"
#include "LegacyRenderSVGResourceSolidColor.h"
#include "LegacyRenderSVGRoot.h"
#include "LegacyRenderSVGShapeInlines.h"
#include "NodeRenderStyle.h"
#include "NullGraphicsContext.h"
#include "RenderImage.h"
#include "RenderIterator.h"
#include "RenderObjectInlines.h"
#include "RenderSVGContainer.h"
#include "RenderSVGGradientStopInlines.h"
#include "RenderSVGInlineText.h"
#include "RenderSVGRoot.h"
#include "RenderSVGShapeInlines.h"
#include "RenderSVGText.h"
#include "RenderStyleInlines.h"
#include "SVGCircleElement.h"
#include "SVGElementTypeHelpers.h"
#include "SVGEllipseElement.h"
#include "SVGInlineTextBoxInlines.h"
#include "SVGLineElement.h"
#include "SVGPathElement.h"
#include "SVGPathUtilities.h"
#include "SVGPolyElement.h"
#include "SVGRectElement.h"
#include "SVGRenderStyle.h"
#include "SVGRootInlineBox.h"
#include "SVGStopElement.h"
#include "StyleCachedImage.h"
#include <math.h>
namespace WebCore {
/** class + iomanip to help streaming list separators, i.e. ", " in string "a, b, c, d"
* Can be used in cases where you don't know which item in the list is the first
* one to be printed, but still want to avoid strings like ", b, c".
*/
class TextStreamSeparator {
public:
TextStreamSeparator(UChar s)
: m_separator(s)
, m_needToSeparate(false)
{
}
private:
friend TextStream& operator<<(TextStream&, TextStreamSeparator&);
UChar m_separator;
bool m_needToSeparate;
};
TextStream& operator<<(TextStream& ts, TextStreamSeparator& sep)
{
if (sep.m_needToSeparate)
ts << sep.m_separator;
else
sep.m_needToSeparate = true;
return ts;
}
static TextStream& operator<<(TextStream& ts, const DashArray& a)
{
ts << '{';
bool isFirst = true;
for (auto& value : a) {
if (isFirst)
isFirst = false;
else
ts << ", "_s;
ts << value;
}
ts << '}';
return ts;
}
template<typename ValueType>
static void writeNameValuePair(TextStream& ts, ASCIILiteral name, ValueType value)
{
ts << " ["_s << name << '=' << value << ']';
}
template<typename ValueType>
static void writeNameAndQuotedValue(TextStream& ts, ASCIILiteral name, ValueType value)
{
ts << " ["_s << name << "=\""_s << value << "\"]"_s;
}
static void writeIfNotEmpty(TextStream& ts, ASCIILiteral name, const String& value)
{
if (!value.isEmpty())
writeNameValuePair(ts, name, value);
}
template<typename ValueType>
static void writeIfNotDefault(TextStream& ts, ASCIILiteral name, ValueType value, ValueType defaultValue)
{
if (value != defaultValue)
writeNameValuePair(ts, name, value);
}
static TextStream& operator<<(TextStream& ts, const SVGUnitTypes::SVGUnitType& unitType)
{
ts << SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::toString(unitType);
return ts;
}
static TextStream& operator<<(TextStream& ts, const SVGMarkerUnitsType& markerUnit)
{
ts << SVGPropertyTraits<SVGMarkerUnitsType>::toString(markerUnit);
return ts;
}
static TextStream& operator<<(TextStream& ts, const SVGSpreadMethodType& type)
{
ts << SVGPropertyTraits<SVGSpreadMethodType>::toString(type).convertToASCIIUppercase();
return ts;
}
static void writeSVGPaintingResource(TextStream& ts, const LegacyRenderSVGResource& resource)
{
if (auto* solidColorResource = dynamicDowncast<LegacyRenderSVGResourceSolidColor>(resource)) {
ts << "[type=SOLID] [color="_s << solidColorResource->color() << ']';
return;
}
auto resourceType = resource.resourceType();
if (resourceType == PatternResourceType)
ts << "[type=PATTERN]"_s;
else if (resourceType == LinearGradientResourceType)
ts << "[type=LINEAR-GRADIENT]"_s;
else if (resourceType == RadialGradientResourceType)
ts << "[type=RADIAL-GRADIENT]"_s;
// All other resources derive from LegacyRenderSVGResourceContainer.
// FIXME: This should use a safe cast.
const auto& container = static_cast<const LegacyRenderSVGResourceContainer&>(resource);
ts << " [id=\""_s << container.element().getIdAttribute() << "\"]"_s;
}
static void writeSVGFillPaintingResource(TextStream& ts, const RenderElement& renderer, const LegacyRenderSVGResource& fillPaintingResource)
{
TextStreamSeparator s(' ');
ts << " [fill={"_s << s;
writeSVGPaintingResource(ts, fillPaintingResource);
const auto& svgStyle = renderer.style().svgStyle();
writeIfNotDefault(ts, "opacity"_s, svgStyle.fillOpacity(), 1.0f);
writeIfNotDefault(ts, "fill rule"_s, svgStyle.fillRule(), WindRule::NonZero);
ts << "}]"_s;
}
static void writeSVGStrokePaintingResource(TextStream& ts, const RenderElement& renderer, const LegacyRenderSVGResource& strokePaintingResource, const SVGGraphicsElement& shape)
{
TextStreamSeparator s(' ');
ts << " [stroke={"_s << s;
writeSVGPaintingResource(ts, strokePaintingResource);
const auto& style = renderer.style();
const auto& svgStyle = style.svgStyle();
SVGLengthContext lengthContext(&shape);
double dashOffset = lengthContext.valueForLength(svgStyle.strokeDashOffset());
double strokeWidth = lengthContext.valueForLength(style.strokeWidth());
auto dashArray = svgStyle.strokeDashArray().map([&](auto& length) -> DashArrayElement {
return length.value(lengthContext);
});
writeIfNotDefault(ts, "opacity"_s, svgStyle.strokeOpacity(), 1.0f);
writeIfNotDefault(ts, "stroke width"_s, strokeWidth, 1.0);
writeIfNotDefault(ts, "miter limit"_s, style.strokeMiterLimit(), 4.0f);
writeIfNotDefault(ts, "line cap"_s, style.capStyle(), LineCap::Butt);
writeIfNotDefault(ts, "line join"_s, style.joinStyle(), LineJoin::Miter);
writeIfNotDefault(ts, "dash offset"_s, dashOffset, 0.0);
if (!dashArray.isEmpty())
writeNameValuePair(ts, "dash array"_s, dashArray);
if (RefPtr element = dynamicDowncast<SVGGeometryElement>(shape)) {
double pathLength = element->pathLength();
writeIfNotDefault(ts, "path length"_s, pathLength, 0.0);
}
ts << "}]"_s;
}
void writeSVGPaintingFeatures(TextStream& ts, const RenderElement& renderer, OptionSet<RenderAsTextFlag>)
{
const RenderStyle& style = renderer.style();
Ref svgStyle = style.svgStyle();
if (!renderer.localTransform().isIdentity())
writeNameValuePair(ts, "transform"_s, renderer.localTransform());
writeIfNotDefault(ts, "image rendering"_s, style.imageRendering(), RenderStyle::initialImageRendering());
writeIfNotDefault(ts, "opacity"_s, style.opacity(), RenderStyle::initialOpacity());
if (auto* shape = dynamicDowncast<LegacyRenderSVGShape>(renderer)) {
Color fallbackColor;
if (auto* strokePaintingResource = LegacyRenderSVGResource::strokePaintingResource(const_cast<LegacyRenderSVGShape&>(*shape), shape->style(), fallbackColor))
writeSVGStrokePaintingResource(ts, renderer, *strokePaintingResource, shape->protectedGraphicsElement());
if (auto* fillPaintingResource = LegacyRenderSVGResource::fillPaintingResource(const_cast<LegacyRenderSVGShape&>(*shape), shape->style(), fallbackColor))
writeSVGFillPaintingResource(ts, renderer, *fillPaintingResource);
writeIfNotDefault(ts, "clip rule"_s, svgStyle->clipRule(), WindRule::NonZero);
} else if (auto* shape = dynamicDowncast<RenderSVGShape>(renderer)) {
Color fallbackColor;
if (auto* strokePaintingResource = LegacyRenderSVGResource::strokePaintingResource(const_cast<RenderSVGShape&>(*shape), shape->style(), fallbackColor))
writeSVGStrokePaintingResource(ts, renderer, *strokePaintingResource, shape->protectedGraphicsElement());
if (auto* fillPaintingResource = LegacyRenderSVGResource::fillPaintingResource(const_cast<RenderSVGShape&>(*shape), shape->style(), fallbackColor))
writeSVGFillPaintingResource(ts, renderer, *fillPaintingResource);
writeIfNotDefault(ts, "clip rule"_s, svgStyle->clipRule(), WindRule::NonZero);
}
auto writeMarker = [&](ASCIILiteral name, const String& value) {
auto* element = renderer.element();
if (!element)
return;
auto fragment = SVGURIReference::fragmentIdentifierFromIRIString(value, element->protectedDocument());
writeIfNotEmpty(ts, name, fragment);
};
writeMarker("start marker"_s, svgStyle->markerStartResource());
writeMarker("middle marker"_s, svgStyle->markerMidResource());
writeMarker("end marker"_s, svgStyle->markerEndResource());
}
static TextStream& writePositionAndStyle(TextStream& ts, const RenderElement& renderer, OptionSet<RenderAsTextFlag> behavior = { })
{
if (behavior.contains(RenderAsTextFlag::ShowSVGGeometry)) {
if (auto* box = dynamicDowncast<RenderBox>(renderer))
ts << ' ' << enclosingIntRect(box->frameRect());
ts << " clipped"_s;
}
ts << ' ' << enclosingIntRect(renderer.absoluteClippedOverflowRectForRenderTreeAsText());
writeSVGPaintingFeatures(ts, renderer, behavior);
return ts;
}
void writeSVGGraphicsElement(TextStream& ts, const SVGGraphicsElement& svgElement)
{
SVGLengthContext lengthContext(&svgElement);
if (auto* element = dynamicDowncast<SVGRectElement>(svgElement)) {
writeNameValuePair(ts, "x"_s, element->x().value(lengthContext));
writeNameValuePair(ts, "y"_s, element->y().value(lengthContext));
writeNameValuePair(ts, "width"_s, element->width().value(lengthContext));
writeNameValuePair(ts, "height"_s, element->height().value(lengthContext));
} else if (auto* element = dynamicDowncast<SVGLineElement>(svgElement)) {
writeNameValuePair(ts, "x1"_s, element->x1().value(lengthContext));
writeNameValuePair(ts, "y1"_s, element->y1().value(lengthContext));
writeNameValuePair(ts, "x2"_s, element->x2().value(lengthContext));
writeNameValuePair(ts, "y2"_s, element->y2().value(lengthContext));
} else if (auto* element = dynamicDowncast<SVGEllipseElement>(svgElement)) {
writeNameValuePair(ts, "cx"_s, element->cx().value(lengthContext));
writeNameValuePair(ts, "cy"_s, element->cy().value(lengthContext));
writeNameValuePair(ts, "rx"_s, element->rx().value(lengthContext));
writeNameValuePair(ts, "ry"_s, element->ry().value(lengthContext));
} else if (auto* element = dynamicDowncast<SVGCircleElement>(svgElement)) {
writeNameValuePair(ts, "cx"_s, element->cx().value(lengthContext));
writeNameValuePair(ts, "cy"_s, element->cy().value(lengthContext));
writeNameValuePair(ts, "r"_s, element->r().value(lengthContext));
} else if (auto* element = dynamicDowncast<SVGPolyElement>(svgElement))
writeNameAndQuotedValue(ts, "points"_s, element->points().valueAsString());
else if (auto* element = dynamicDowncast<SVGPathElement>(svgElement)) {
String pathString;
// FIXME: We should switch to UnalteredParsing here - this will affect the path dumping output of dozens of tests.
buildStringFromByteStream(element->pathByteStream(), pathString, NormalizedParsing);
writeNameAndQuotedValue(ts, "data"_s, pathString);
} else
ASSERT_NOT_REACHED();
}
static TextStream& operator<<(TextStream& ts, const LegacyRenderSVGShape& shape)
{
writePositionAndStyle(ts, shape);
writeSVGGraphicsElement(ts, shape.protectedGraphicsElement());
return ts;
}
static void writeRenderSVGTextBox(TextStream& ts, const RenderSVGText& text)
{
auto box = InlineIterator::firstRootInlineBoxFor(text);
if (!box)
return;
ts << ' ' << enclosingIntRect(FloatRect(text.location(), FloatSize(box->logicalWidth(), box->logicalHeight())));
// FIXME: Remove this hack, once the new text layout engine is completly landed. We want to preserve the old layout test results for now.
ts << " contains 1 chunk(s)"_s;
if (text.parent() && (text.parent()->style().visitedDependentColor(CSSPropertyColor) != text.style().visitedDependentColor(CSSPropertyColor)))
writeNameValuePair(ts, "color"_s, serializationForRenderTreeAsText(text.style().visitedDependentColor(CSSPropertyColor)));
}
static inline void writeSVGInlineTextBox(TextStream& ts, const InlineIterator::SVGTextBox& textBox)
{
auto& fragments = textBox.textFragments();
if (fragments.isEmpty())
return;
Ref svgStyle = textBox.renderer().style().svgStyle();
String text = textBox.renderer().text();
TextStream::IndentScope indentScope(ts);
unsigned fragmentsSize = fragments.size();
for (unsigned i = 0; i < fragmentsSize; ++i) {
auto& fragment = fragments.at(i);
ts << indent;
unsigned startOffset = fragment.characterOffset;
unsigned endOffset = fragment.characterOffset + fragment.length;
// FIXME: Remove this hack, once the new text layout engine is completly landed. We want to preserve the old layout test results for now.
ts << "chunk 1 "_s;
TextAnchor anchor = svgStyle->textAnchor();
bool isVerticalText = textBox.renderer().writingMode().isVertical();
if (anchor == TextAnchor::Middle) {
ts << "(middle anchor"_s;
if (isVerticalText)
ts << ", vertical"_s;
ts << ") "_s;
} else if (anchor == TextAnchor::End) {
ts << "(end anchor"_s;
if (isVerticalText)
ts << ", vertical"_s;
ts << ") "_s;
} else if (isVerticalText)
ts << "(vertical) "_s;
startOffset -= textBox.start();
endOffset -= textBox.start();
// </hack>
ts << "text run "_s << i + 1 << " at ("_s << fragment.x << ',' << fragment.y << ')';
ts << " startOffset "_s << startOffset << " endOffset "_s << endOffset;
if (isVerticalText)
ts << " height "_s << fragment.height;
else
ts << " width "_s << fragment.width;
if (!textBox.isLeftToRightDirection())
ts << " RTL"_s;
ts << ": "_s << quoteAndEscapeNonPrintables(text.substring(fragment.characterOffset, fragment.length)) << '\n';
}
}
static inline void writeSVGInlineTextBoxes(TextStream& ts, const RenderSVGInlineText& text)
{
for (auto& box : InlineIterator::svgTextBoxesFor(text))
writeSVGInlineTextBox(ts, box);
}
enum class WriteIndentOrNot : bool { No, Yes };
static void writeStandardPrefix(TextStream& ts, const RenderObject& object, OptionSet<RenderAsTextFlag> behavior, WriteIndentOrNot writeIndent = WriteIndentOrNot::Yes)
{
if (writeIndent == WriteIndentOrNot::Yes)
ts << indent;
ts << object.renderName().characters();
if (behavior.contains(RenderAsTextFlag::ShowAddresses))
ts << ' ' << &object;
if (object.node())
ts << " {"_s << object.node()->nodeName() << '}';
writeDebugInfo(ts, object, behavior);
}
static void writeChildren(TextStream& ts, const RenderElement& parent, OptionSet<RenderAsTextFlag> behavior)
{
TextStream::IndentScope indentScope(ts);
for (const auto& child : childrenOfType<RenderObject>(parent)) {
if (parent.document().settings().layerBasedSVGEngineEnabled() && child.hasLayer())
continue;
write(ts, child, behavior);
}
}
static inline void writeCommonGradientProperties(TextStream& ts, SVGSpreadMethodType spreadMethod, const AffineTransform& gradientTransform, SVGUnitTypes::SVGUnitType gradientUnits)
{
writeNameValuePair(ts, "gradientUnits"_s, gradientUnits);
if (spreadMethod != SVGSpreadMethodPad)
ts << " [spreadMethod="_s << spreadMethod << ']';
if (!gradientTransform.isIdentity())
ts << " [gradientTransform="_s << gradientTransform << ']';
}
void writeSVGResourceContainer(TextStream& ts, const LegacyRenderSVGResourceContainer& resource, OptionSet<RenderAsTextFlag> behavior)
{
writeStandardPrefix(ts, resource, behavior);
const AtomString& id = resource.element().getIdAttribute();
writeNameAndQuotedValue(ts, "id"_s, id);
if (auto* masker = dynamicDowncast<const LegacyRenderSVGResourceMasker>(resource)) {
writeNameValuePair(ts, "maskUnits"_s, masker->maskUnits());
writeNameValuePair(ts, "maskContentUnits"_s, masker->maskContentUnits());
ts << '\n';
} else if (resource.resourceType() == FilterResourceType) {
const auto& filter = static_cast<const LegacyRenderSVGResourceFilter&>(resource);
writeNameValuePair(ts, "filterUnits"_s, filter.filterUnits());
writeNameValuePair(ts, "primitiveUnits"_s, filter.primitiveUnits());
ts << '\n';
// Creating a placeholder filter which is passed to the builder.
FloatRect dummyRect;
FloatSize dummyScale(1, 1);
auto dummyFilter = SVGFilter::create(filter.protectedFilterElement(), FilterRenderingMode::Software, dummyScale, dummyRect, dummyRect, NullGraphicsContext());
if (dummyFilter) {
TextStream::IndentScope indentScope(ts);
dummyFilter->externalRepresentation(ts, FilterRepresentation::TestOutput);
}
} else if (resource.resourceType() == ClipperResourceType) {
const auto& clipper = static_cast<const LegacyRenderSVGResourceClipper&>(resource);
writeNameValuePair(ts, "clipPathUnits"_s, clipper.clipPathUnits());
ts << '\n';
} else if (resource.resourceType() == MarkerResourceType) {
const auto& marker = static_cast<const LegacyRenderSVGResourceMarker&>(resource);
writeNameValuePair(ts, "markerUnits"_s, marker.markerUnits());
ts << " [ref at "_s << marker.referencePoint() << ']';
ts << " [angle="_s;
if (auto angle = marker.angle())
ts << *angle << "]\n"_s;
else
ts << "auto"_s << "]\n"_s;
} else if (auto* pattern = dynamicDowncast<const LegacyRenderSVGResourcePattern>(resource)) {
// Dump final results that are used for rendering. No use in asking SVGPatternElement for its patternUnits(), as it may
// link to other patterns using xlink:href, we need to build the full inheritance chain, aka. collectPatternProperties()
PatternAttributes attributes;
pattern->collectPatternAttributes(attributes);
writeNameValuePair(ts, "patternUnits"_s, attributes.patternUnits());
writeNameValuePair(ts, "patternContentUnits"_s, attributes.patternContentUnits());
AffineTransform transform = attributes.patternTransform();
if (!transform.isIdentity())
ts << " [patternTransform="_s << transform << ']';
ts << '\n';
} else if (auto* gradient = dynamicDowncast<const LegacyRenderSVGResourceLinearGradient>(resource)) {
// Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may
// link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties()
LinearGradientAttributes attributes;
gradient->linearGradientElement().collectGradientAttributes(attributes);
writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.gradientUnits());
ts << " [start="_s << gradient->startPoint(attributes) << "] [end="_s << gradient->endPoint(attributes) << "]\n"_s;
} else if (auto* gradient = dynamicDowncast<const LegacyRenderSVGResourceRadialGradient>(resource)) {
// Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may
// link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties()
RadialGradientAttributes attributes;
gradient->radialGradientElement().collectGradientAttributes(attributes);
writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.gradientUnits());
FloatPoint focalPoint = gradient->focalPoint(attributes);
FloatPoint centerPoint = gradient->centerPoint(attributes);
float radius = gradient->radius(attributes);
float focalRadius = gradient->focalRadius(attributes);
ts << " [center="_s << centerPoint << "] [focal="_s << focalPoint << "] [radius="_s << radius << "] [focalRadius="_s << focalRadius << "]\n"_s;
} else
ts << '\n';
writeChildren(ts, resource, behavior);
}
void writeSVGContainer(TextStream& ts, const LegacyRenderSVGContainer& container, OptionSet<RenderAsTextFlag> behavior)
{
// Currently RenderSVGResourceFilterPrimitive has no meaningful output.
if (container.isRenderOrLegacyRenderSVGResourceFilterPrimitive())
return;
writeStandardPrefix(ts, container, behavior);
writePositionAndStyle(ts, container, behavior);
ts << '\n';
writeResources(ts, container, behavior);
writeChildren(ts, container, behavior);
}
void write(TextStream& ts, const LegacyRenderSVGRoot& root, OptionSet<RenderAsTextFlag> behavior)
{
writeStandardPrefix(ts, root, behavior);
writePositionAndStyle(ts, root, behavior);
ts << '\n';
writeChildren(ts, root, behavior);
}
void writeSVGText(TextStream& ts, const RenderSVGText& text, OptionSet<RenderAsTextFlag> behavior)
{
writeStandardPrefix(ts, text, behavior);
writeRenderSVGTextBox(ts, text);
ts << '\n';
writeResources(ts, text, behavior);
writeChildren(ts, text, behavior);
}
void writeSVGInlineText(TextStream& ts, const RenderSVGInlineText& text, OptionSet<RenderAsTextFlag> behavior)
{
writeStandardPrefix(ts, text, behavior);
ts << ' ' << enclosingIntRect(FloatRect(text.firstRunLocation(), text.floatLinesBoundingBox().size())) << '\n';
writeResources(ts, text, behavior);
writeSVGInlineTextBoxes(ts, text);
}
void writeSVGImage(TextStream& ts, const LegacyRenderSVGImage& image, OptionSet<RenderAsTextFlag> behavior)
{
writeStandardPrefix(ts, image, behavior);
writePositionAndStyle(ts, image, behavior);
ts << '\n';
writeResources(ts, image, behavior);
}
void write(TextStream& ts, const LegacyRenderSVGShape& shape, OptionSet<RenderAsTextFlag> behavior)
{
writeStandardPrefix(ts, shape, behavior);
ts << shape << '\n';
writeResources(ts, shape, behavior);
}
void writeSVGGradientStop(TextStream& ts, const RenderSVGGradientStop& stop, OptionSet<RenderAsTextFlag> behavior)
{
writeStandardPrefix(ts, stop, behavior);
ts << " [offset="_s << stop.element().offset() << "] [color="_s << stop.element().stopColorIncludingOpacity() << "]\n"_s;
}
void writeResources(TextStream& ts, const RenderObject& renderer, OptionSet<RenderAsTextFlag> behavior)
{
const RenderStyle& style = renderer.style();
// FIXME: We want to use SVGResourcesCache to determine which resources are present, instead of quering the resource <-> id cache.
// For now leave the DRT output as is, but later on we should change this so cycles are properly ignored in the DRT output.
if (style.hasPositionedMask()) {
RefPtr maskImage = style.maskImage();
Ref document = renderer.document();
auto reresolvedURL = maskImage ? maskImage->reresolvedURL(document) : URL();
if (!reresolvedURL.isEmpty()) {
auto resourceID = SVGURIReference::fragmentIdentifierFromIRIString(reresolvedURL.string(), document);
if (auto* masker = getRenderSVGResourceById<LegacyRenderSVGResourceMasker>(renderer.treeScopeForSVGReferences(), resourceID)) {
ts << indent << ' ';
writeNameAndQuotedValue(ts, "masker"_s, resourceID);
ts << ' ';
writeStandardPrefix(ts, *masker, behavior, WriteIndentOrNot::No);
ts << ' ' << masker->resourceBoundingBox(renderer, RepaintRectCalculation::Accurate) << '\n';
}
}
}
if (auto* resourceClipPath = dynamicDowncast<ReferencePathOperation>(style.clipPath())) {
AtomString id = resourceClipPath->fragment();
if (LegacyRenderSVGResourceClipper* clipper = getRenderSVGResourceById<LegacyRenderSVGResourceClipper>(renderer.treeScopeForSVGReferences(), id)) {
ts << indent << ' ';
writeNameAndQuotedValue(ts, "clipPath"_s, id);
ts << ' ';
writeStandardPrefix(ts, *clipper, behavior, WriteIndentOrNot::No);
ts << ' ' << clipper->resourceBoundingBox(renderer, RepaintRectCalculation::Accurate) << '\n';
}
}
if (style.hasFilter()) {
const FilterOperations& filterOperations = style.filter();
if (filterOperations.size() == 1) {
if (RefPtr referenceFilterOperation = dynamicDowncast<ReferenceFilterOperation>(*filterOperations.at(0))) {
AtomString id = SVGURIReference::fragmentIdentifierFromIRIString(referenceFilterOperation->url(), renderer.protectedDocument());
if (LegacyRenderSVGResourceFilter* filter = getRenderSVGResourceById<LegacyRenderSVGResourceFilter>(renderer.treeScopeForSVGReferences(), id)) {
ts << indent << ' ';
writeNameAndQuotedValue(ts, "filter"_s, id);
ts << ' ';
writeStandardPrefix(ts, *filter, behavior, WriteIndentOrNot::No);
ts << ' ' << filter->resourceBoundingBox(renderer, RepaintRectCalculation::Accurate) << '\n';
}
}
}
}
}
} // namespace WebCore
|