Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkSVGDevice::AutoElement Class Reference
Inheritance diagram for SkSVGDevice::AutoElement:
SkNoncopyable

Public Member Functions

 AutoElement (const char name[], SkXMLWriter *writer)
 
 AutoElement (const char name[], const std::unique_ptr< SkXMLWriter > &writer)
 
 AutoElement (const char name[], SkSVGDevice *svgdev, ResourceBucket *bucket, const MxCp &mc, const SkPaint &paint)
 
 ~AutoElement ()
 
void addAttribute (const char name[], const char val[])
 
void addAttribute (const char name[], const SkString &val)
 
void addAttribute (const char name[], int32_t val)
 
void addAttribute (const char name[], SkScalar val)
 
void addText (const SkString &text)
 
void addRectAttributes (const SkRect &)
 
void addPathAttributes (const SkPath &, SkParsePath::PathEncoding)
 
void addTextAttributes (const SkFont &)
 

Detailed Description

Definition at line 280 of file SkSVGDevice.cpp.

Constructor & Destructor Documentation

◆ AutoElement() [1/3]

SkSVGDevice::AutoElement::AutoElement ( const char  name[],
SkXMLWriter writer 
)
inline

Definition at line 282 of file SkSVGDevice.cpp.

283 : fWriter(writer)
284 , fResourceBucket(nullptr) {
285 fWriter->startElement(name);
286 }
void startElement(const char elem[])
Definition: SkXMLWriter.cpp:84
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ AutoElement() [2/3]

SkSVGDevice::AutoElement::AutoElement ( const char  name[],
const std::unique_ptr< SkXMLWriter > &  writer 
)
inline

Definition at line 288 of file SkSVGDevice.cpp.

289 : AutoElement(name, writer.get()) {}
AutoElement(const char name[], SkXMLWriter *writer)

◆ AutoElement() [3/3]

SkSVGDevice::AutoElement::AutoElement ( const char  name[],
SkSVGDevice svgdev,
ResourceBucket bucket,
const MxCp mc,
const SkPaint paint 
)
inline

Definition at line 291 of file SkSVGDevice.cpp.

293 : fWriter(svgdev->fWriter.get())
294 , fResourceBucket(bucket) {
295
296 svgdev->syncClipStack(*mc.fClipStack);
297 Resources res = this->addResources(mc, paint);
298
299 fWriter->startElement(name);
300
301 this->addPaint(paint, res);
302
303 if (!mc.fMatrix->isIdentity()) {
304 this->addAttribute("transform", svg_transform(*mc.fMatrix));
305 }
306 }
void addAttribute(const char name[], const char val[])
const Paint & paint
Definition: color_source.cc:38

◆ ~AutoElement()

SkSVGDevice::AutoElement::~AutoElement ( )
inline

Definition at line 308 of file SkSVGDevice.cpp.

308 {
309 fWriter->endElement();
310 }
void endElement()
Definition: SkXMLWriter.h:29

Member Function Documentation

◆ addAttribute() [1/4]

void SkSVGDevice::AutoElement::addAttribute ( const char  name[],
const char  val[] 
)
inline

Definition at line 312 of file SkSVGDevice.cpp.

312 {
313 fWriter->addAttribute(name, val);
314 }
void addAttribute(const char name[], const char value[])
Definition: SkXMLWriter.cpp:26

◆ addAttribute() [2/4]

void SkSVGDevice::AutoElement::addAttribute ( const char  name[],
const SkString val 
)
inline

Definition at line 316 of file SkSVGDevice.cpp.

316 {
317 fWriter->addAttribute(name, val.c_str());
318 }
const char * c_str() const
Definition: SkString.h:133

◆ addAttribute() [3/4]

void SkSVGDevice::AutoElement::addAttribute ( const char  name[],
int32_t  val 
)
inline

Definition at line 320 of file SkSVGDevice.cpp.

320 {
321 fWriter->addS32Attribute(name, val);
322 }
void addS32Attribute(const char name[], int32_t value)
Definition: SkXMLWriter.cpp:30

◆ addAttribute() [4/4]

void SkSVGDevice::AutoElement::addAttribute ( const char  name[],
SkScalar  val 
)
inline

Definition at line 324 of file SkSVGDevice.cpp.

324 {
325 fWriter->addScalarAttribute(name, val);
326 }
void addScalarAttribute(const char name[], SkScalar value)
Definition: SkXMLWriter.cpp:42

◆ addPathAttributes()

void SkSVGDevice::AutoElement::addPathAttributes ( const SkPath path,
SkParsePath::PathEncoding  encoding 
)

Definition at line 677 of file SkSVGDevice.cpp.

678 {
679 this->addAttribute("d", SkParsePath::ToSVGString(path, encoding));
680}
static SkString ToSVGString(const SkPath &, PathEncoding=PathEncoding::Absolute)

◆ addRectAttributes()

void SkSVGDevice::AutoElement::addRectAttributes ( const SkRect rect)

Definition at line 664 of file SkSVGDevice.cpp.

664 {
665 // x, y default to 0
666 if (rect.x() != 0) {
667 this->addAttribute("x", rect.x());
668 }
669 if (rect.y() != 0) {
670 this->addAttribute("y", rect.y());
671 }
672
673 this->addAttribute("width", rect.width());
674 this->addAttribute("height", rect.height());
675}
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
constexpr float x() const
Definition: SkRect.h:720
constexpr float y() const
Definition: SkRect.h:727
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762

◆ addText()

void SkSVGDevice::AutoElement::addText ( const SkString text)
inline

Definition at line 328 of file SkSVGDevice.cpp.

328 {
329 fWriter->addText(text.c_str(), text.size());
330 }
void addText(const char text[], size_t length)
Definition: SkXMLWriter.cpp:48
std::u16string text

◆ addTextAttributes()

void SkSVGDevice::AutoElement::addTextAttributes ( const SkFont font)

Definition at line 682 of file SkSVGDevice.cpp.

682 {
683 this->addAttribute("font-size", font.getSize());
684
685 SkString familyName;
686 THashSet<SkString> familySet;
687 sk_sp<SkTypeface> tface = font.refTypeface();
688
689 SkASSERT(tface);
690 SkFontStyle style = tface->fontStyle();
691 if (style.slant() == SkFontStyle::kItalic_Slant) {
692 this->addAttribute("font-style", "italic");
693 } else if (style.slant() == SkFontStyle::kOblique_Slant) {
694 this->addAttribute("font-style", "oblique");
695 }
696 int weightIndex = (SkTPin(style.weight(), 100, 900) - 50) / 100;
697 if (weightIndex != 3) {
698 static constexpr const char* weights[] = {
699 "100", "200", "300", "normal", "400", "500", "600", "bold", "800", "900"
700 };
701 this->addAttribute("font-weight", weights[weightIndex]);
702 }
703 int stretchIndex = style.width() - 1;
704 if (stretchIndex != 4) {
705 static constexpr const char* stretches[] = {
706 "ultra-condensed", "extra-condensed", "condensed", "semi-condensed",
707 "normal",
708 "semi-expanded", "expanded", "extra-expanded", "ultra-expanded"
709 };
710 this->addAttribute("font-stretch", stretches[stretchIndex]);
711 }
712
714 SkTypeface::LocalizedString familyString;
715 if (familyNameIter) {
716 while (familyNameIter->next(&familyString)) {
717 if (familySet.contains(familyString.fString)) {
718 continue;
719 }
720 familySet.add(familyString.fString);
721 familyName.appendf((familyName.isEmpty() ? "%s" : ", %s"), familyString.fString.c_str());
722 }
723 }
724 if (!familyName.isEmpty()) {
725 this->addAttribute("font-family", familyName);
726 }
727}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
Slant slant() const
Definition: SkFontStyle.h:64
int width() const
Definition: SkFontStyle.h:63
int weight() const
Definition: SkFontStyle.h:62
SkScalar getSize() const
Definition: SkFont.h:217
bool isEmpty() const
Definition: SkString.h:130
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
LocalizedStrings * createFamilyNameIterator() const
Definition: SkTypeface.cpp:455
SkFontStyle fontStyle() const
Definition: SkTypeface.h:55
void add(T item)
Definition: SkTHash.h:592
bool contains(const T &item) const
Definition: SkTHash.h:595
font
Font Metadata and Metrics.

The documentation for this class was generated from the following file: