Flutter Engine
The Flutter Engine
Functions
FontMgrFontConfigTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontArguments.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/ports/SkFontMgr_fontconfig.h"
#include "tests/Test.h"
#include "tools/Resources.h"
#include <fontconfig/fontconfig.h>
#include <array>
#include <memory>

Go to the source code of this file.

Functions

 DEF_TEST (FontMgrFontConfig, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( FontMgrFontConfig  ,
reporter   
)

Definition at line 63 of file FontMgrFontConfigTest.cpp.

63 {
64 FcConfig* config = build_fontconfig_with_fontfile("/fonts/Distortable.ttf");
65
67 sk_sp<SkTypeface> typeface(fontMgr->legacyMakeTypeface("Distortable", SkFontStyle()));
68 if (!typeface) {
69 ERRORF(reporter, "Could not find typeface. FcVersion: %d", FcGetVersion());
70 return;
71 }
72
73 SkBitmap bitmapStream;
74 bitmapStream.allocN32Pixels(64, 64);
75 SkCanvas canvasStream(bitmapStream);
76 canvasStream.drawColor(SK_ColorWHITE);
77
78 SkBitmap bitmapClone;
79 bitmapClone.allocN32Pixels(64, 64);
80 SkCanvas canvasClone(bitmapClone);
81 canvasStream.drawColor(SK_ColorWHITE);
82
84 paint.setColor(SK_ColorGRAY);
85
86 constexpr float kTextSize = 20;
87
88 std::unique_ptr<SkStreamAsset> distortableStream(
89 GetResourceAsStream("fonts/Distortable.ttf"));
90 if (!distortableStream) {
91 return;
92 }
93
94 SkPoint point = SkPoint::Make(20.0f, 20.0f);
95 SkFourByteTag tag = SkSetFourByteTag('w', 'g', 'h', 't');
96
97 for (int i = 0; i < 10; ++i) {
98 SkScalar styleValue =
99 SkDoubleToScalar(0.5 + i * ((2.0 - 0.5) / 10));
101 coordinates[] = {{tag, styleValue}};
103 position = {coordinates, std::size(coordinates)};
104
105 SkFont fontStream(
106 fontMgr->makeFromStream(distortableStream->duplicate(),
107 SkFontArguments().setVariationDesignPosition(position)),
108 kTextSize);
109 fontStream.setEdging(SkFont::Edging::kSubpixelAntiAlias);
110
111 SkFont fontClone(
112 typeface->makeClone(SkFontArguments().setVariationDesignPosition(position)), kTextSize);
113 fontClone.setEdging(SkFont::Edging::kSubpixelAntiAlias);
114
115 constexpr char text[] = "abc";
116
117 canvasStream.drawColor(SK_ColorWHITE);
118 canvasStream.drawString(text, point.fX, point.fY, fontStream, paint);
119
120 canvasClone.drawColor(SK_ColorWHITE);
121 canvasClone.drawString(text, point.fX, point.fY, fontClone, paint);
122
123 bool success = bitmap_compare(bitmapStream, bitmapClone);
124 REPORTER_ASSERT(reporter, success);
125 }
126}
static bool bitmap_compare(const SkBitmap &ref, const SkBitmap &test)
reporter
Definition: FontMgrTest.cpp:39
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition: Resources.cpp:31
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
SK_API sk_sp< SkFontMgr > SkFontMgr_New_FontConfig(FcConfig *fc)
#define SkDoubleToScalar(x)
Definition: SkScalar.h:64
uint32_t SkFourByteTag
Definition: SkTypes.h:166
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
Definition: SkFontMgr.cpp:127
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
Definition: SkFontMgr.cpp:150
Definition: SkFont.h:35
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
float SkScalar
Definition: extension.cpp:12
std::u16string text
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
float fX
x-axis value
Definition: SkPoint_impl.h:164
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
float fY
y-axis value
Definition: SkPoint_impl.h:165