Flutter Engine
The Flutter Engine
Classes | Functions
pictureimagegenerator.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageGenerator.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/pathops/SkPathOps.h"
#include "include/utils/SkTextUtils.h"
#include "src/image/SkImageGeneratorPriv.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <string.h>
#include <memory>

Go to the source code of this file.

Classes

class  PictureGeneratorGM
 

Functions

static void draw_vector_logo (SkCanvas *canvas, const SkRect &viewBox)
 

Function Documentation

◆ draw_vector_logo()

static void draw_vector_logo ( SkCanvas canvas,
const SkRect viewBox 
)
static

Definition at line 43 of file pictureimagegenerator.cpp.

43 {
44 constexpr char kSkiaStr[] = "SKIA";
45 constexpr SkScalar kGradientPad = .1f;
46 constexpr SkScalar kVerticalSpacing = 0.25f;
47 constexpr SkScalar kAccentScale = 1.20f;
48
50 paint.setAntiAlias(true);
51
53 font.setSubpixel(true);
54 font.setEmbolden(true);
55
57 SkRect iBox, skiBox, skiaBox;
59 TightBounds(path, &skiBox);
61 TightBounds(path, &iBox);
62 iBox.offsetTo(skiBox.fRight - iBox.width(), iBox.fTop);
63
64 const size_t textLen = strlen(kSkiaStr);
65 SkTextUtils::GetPath(kSkiaStr, textLen, SkTextEncoding::kUTF8, 0, 0, font, &path);
66 TightBounds(path, &skiaBox);
67 skiaBox.outset(0, 2 * iBox.width() * (kVerticalSpacing + 1));
68
69 const SkScalar accentSize = iBox.width() * kAccentScale;
70 const SkScalar underlineY = iBox.bottom() +
71 (kVerticalSpacing + SkScalarSqrt(3) / 2) * accentSize;
72 SkAutoCanvasRestore acr(canvas, true);
73 canvas->concat(SkMatrix::RectToRect(skiaBox, viewBox));
74
75 canvas->drawCircle(iBox.centerX(),
76 iBox.y() - (0.5f + kVerticalSpacing) * accentSize,
77 accentSize / 2,
78 paint);
79
80 path.reset();
81 path.moveTo(iBox.centerX() - accentSize / 2, iBox.bottom() + kVerticalSpacing * accentSize);
82 path.rLineTo(accentSize, 0);
83 path.lineTo(iBox.centerX(), underlineY);
84 canvas->drawPath(path, paint);
85
86 SkRect underlineRect = SkRect::MakeLTRB(iBox.centerX() - iBox.width() * accentSize * 3,
87 underlineY,
88 iBox.centerX(),
89 underlineY + accentSize / 10);
90 const SkPoint pts1[] = { SkPoint::Make(underlineRect.x(), 0),
91 SkPoint::Make(iBox.centerX(), 0) };
92 const SkScalar pos1[] = { 0, 0.75f };
93 const SkColor colors1[] = { SK_ColorTRANSPARENT, SK_ColorBLACK };
94 SkASSERT(std::size(pos1) == std::size(colors1));
95 paint.setShader(SkGradientShader::MakeLinear(pts1, colors1, pos1, std::size(pos1),
97 canvas->drawRect(underlineRect, paint);
98
99 const SkPoint pts2[] = { SkPoint::Make(iBox.x() - iBox.width() * kGradientPad, 0),
100 SkPoint::Make(iBox.right() + iBox.width() * kGradientPad, 0) };
101 const SkScalar pos2[] = { 0, .01f, 1.0f/3, 1.0f/3, 2.0f/3, 2.0f/3, .99f, 1 };
102 const SkColor colors2[] = {
104 0xffca5139,
105 0xffca5139,
106 0xff8dbd53,
107 0xff8dbd53,
108 0xff5460a5,
109 0xff5460a5,
111 };
112 SkASSERT(std::size(pos2) == std::size(colors2));
113 paint.setShader(SkGradientShader::MakeLinear(pts2, colors2, pos2, std::size(pos2),
115 canvas->drawSimpleText(kSkiaStr, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint);
116}
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
@ kUTF8
uses bytes to represent UTF-8 or ASCII
bool SK_API TightBounds(const SkPath &path, SkRect *result)
#define SkScalarSqrt(x)
Definition: SkScalar.h:42
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
Definition: SkFont.h:35
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
Definition: SkPath.h:59
static void GetPath(const void *text, size_t length, SkTextEncoding, SkScalar x, SkScalar y, const SkFont &, SkPath *)
Definition: SkTextUtils.cpp:38
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
SkFont DefaultPortableFont()
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
void offsetTo(float newX, float newY)
Definition: SkRect.h:1043
constexpr float x() const
Definition: SkRect.h:720
void outset(float dx, float dy)
Definition: SkRect.h:1077
constexpr float y() const
Definition: SkRect.h:727
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float right() const
Definition: SkRect.h:748
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
constexpr float bottom() const
Definition: SkRect.h:755
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15