Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
ToolUtils::VariationSliders Class Reference

#include <ToolUtils.h>

Public Member Functions

 VariationSliders ()
 
 VariationSliders (SkTypeface *, SkFontArguments::VariationPosition variationPosition={nullptr, 0})
 
bool writeControls (SkMetaData *controls)
 
void readControls (const SkMetaData &controls, bool *changed=nullptr)
 
SkSpan< const SkFontArguments::VariationPosition::CoordinategetCoordinates ()
 

Static Public Member Functions

static SkString tagToString (SkFourByteTag tag)
 

Detailed Description

Definition at line 320 of file ToolUtils.h.

Constructor & Destructor Documentation

◆ VariationSliders() [1/2]

ToolUtils::VariationSliders::VariationSliders ( )
inline

Definition at line 322 of file ToolUtils.h.

322{}

◆ VariationSliders() [2/2]

ToolUtils::VariationSliders::VariationSliders ( SkTypeface typeface,
SkFontArguments::VariationPosition  variationPosition = {nullptr, 0} 
)

Definition at line 522 of file ToolUtils.cpp.

523 {
524 if (!typeface) {
525 return;
526 }
527
528 int numAxes = typeface->getVariationDesignParameters(nullptr, 0);
529 if (numAxes < 0) {
530 return;
531 }
532
533 std::unique_ptr<SkFontParameters::Variation::Axis[]> copiedAxes =
534 std::make_unique<SkFontParameters::Variation::Axis[]>(numAxes);
535
536 numAxes = typeface->getVariationDesignParameters(copiedAxes.get(), numAxes);
537 if (numAxes < 0) {
538 return;
539 }
540
541 auto argVariationPositionOrDefault = [&variationPosition](SkFourByteTag tag,
542 SkScalar defaultValue) -> SkScalar {
543 for (int i = 0; i < variationPosition.coordinateCount; ++i) {
544 if (variationPosition.coordinates[i].axis == tag) {
545 return variationPosition.coordinates[i].value;
546 }
547 }
548 return defaultValue;
549 };
550
551 fAxisSliders.resize(numAxes);
552 fCoords = std::make_unique<SkFontArguments::VariationPosition::Coordinate[]>(numAxes);
553 for (int i = 0; i < numAxes; ++i) {
554 fAxisSliders[i].axis = copiedAxes[i];
555 fAxisSliders[i].current =
556 argVariationPositionOrDefault(copiedAxes[i].tag, copiedAxes[i].def);
557 fAxisSliders[i].name = tagToString(fAxisSliders[i].axis.tag);
558 fCoords[i] = { fAxisSliders[i].axis.tag, fAxisSliders[i].current };
559 }
560}
uint32_t SkFourByteTag
Definition: SkTypes.h:166
int getVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], int parameterCount) const
Definition: SkTypeface.cpp:295
static SkString tagToString(SkFourByteTag tag)
Definition: ToolUtils.cpp:563
float SkScalar
Definition: extension.cpp:12

Member Function Documentation

◆ getCoordinates()

SkSpan< const SkFontArguments::VariationPosition::Coordinate > ToolUtils::VariationSliders::getCoordinates ( )

Definition at line 600 of file ToolUtils.cpp.

600 {
602 fAxisSliders.size()};
603}

◆ readControls()

void ToolUtils::VariationSliders::readControls ( const SkMetaData controls,
bool *  changed = nullptr 
)

Definition at line 585 of file ToolUtils.cpp.

585 {
586 for (size_t i = 0; i < fAxisSliders.size(); ++i) {
587 SkScalar axisVars[kAxisVarsSize] = {0};
588 int resultAxisVarsSize = 0;
590 tagToString(fAxisSliders[i].axis.tag).c_str(), &resultAxisVarsSize, axisVars));
591 SkASSERT_RELEASE(resultAxisVarsSize == kAxisVarsSize);
592 if (changed) {
593 *changed |= fAxisSliders[i].current != axisVars[0];
594 }
595 fAxisSliders[i].current = axisVars[0];
596 fCoords[i] = { fAxisSliders[i].axis.tag, fAxisSliders[i].current };
597 }
598}
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
const SkScalar * findScalars(const char name[], int *count, SkScalar values[]=nullptr) const
Definition: SkMetaData.cpp:122
const char * c_str() const
Definition: SkString.h:133

◆ tagToString()

SkString ToolUtils::VariationSliders::tagToString ( SkFourByteTag  tag)
static

Definition at line 563 of file ToolUtils.cpp.

563 {
564 char tagAsString[5];
565 tagAsString[4] = 0;
566 tagAsString[0] = (char)(uint8_t)(tag >> 24);
567 tagAsString[1] = (char)(uint8_t)(tag >> 16);
568 tagAsString[2] = (char)(uint8_t)(tag >> 8);
569 tagAsString[3] = (char)(uint8_t)(tag >> 0);
570 return SkString(tagAsString);
571}

◆ writeControls()

bool ToolUtils::VariationSliders::writeControls ( SkMetaData controls)

Definition at line 573 of file ToolUtils.cpp.

573 {
574 for (size_t i = 0; i < fAxisSliders.size(); ++i) {
575 SkScalar axisVars[kAxisVarsSize];
576
577 axisVars[0] = fAxisSliders[i].current;
578 axisVars[1] = fAxisSliders[i].axis.min;
579 axisVars[2] = fAxisSliders[i].axis.max;
580 controls->setScalars(fAxisSliders[i].name.c_str(), kAxisVarsSize, axisVars);
581 }
582 return true;
583}
SkScalar * setScalars(const char name[], int count, const SkScalar values[]=nullptr)
Definition: SkMetaData.cpp:34
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

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