Flutter Engine
The Flutter Engine
Functions
SkFontMetricsPrivTest.cpp File Reference
#include "src/core/SkFontMetricsPriv.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontMetrics.h"
#include "include/core/SkTypeface.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkScalerContext.h"
#include "src/core/SkStrikeSpec.h"
#include "src/core/SkWriteBuffer.h"
#include "tests/Test.h"
#include "tools/fonts/FontToolUtils.h"
#include <optional>

Go to the source code of this file.

Functions

 DEF_TEST (SkFontMetricsPriv_Basic, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( SkFontMetricsPriv_Basic  ,
reporter   
)

Definition at line 22 of file SkFontMetricsPrivTest.cpp.

22 {
23 auto typeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
24 SkFont font{typeface};
26 auto context = spec.createScalerContext();
27 SkFontMetrics srcMetrics;
28
29 // Check that font metrics round-trip.
30 context->getFontMetrics(&srcMetrics);
31
32 SkBinaryWriteBuffer writeBuffer({});
33 SkFontMetricsPriv::Flatten(writeBuffer, srcMetrics);
34
35 auto data = writeBuffer.snapshotAsData();
36
37 SkReadBuffer readBuffer{data->data(), data->size()};
38
39 std::optional<SkFontMetrics> dstMetrics = SkFontMetricsPriv::MakeFromBuffer(readBuffer);
40
41 REPORTER_ASSERT(reporter, dstMetrics.has_value());
42 REPORTER_ASSERT(reporter, srcMetrics == dstMetrics.value());
43
44 // Check that a broken buffer is detected.
45 // Must be multiple of 4 for a valid buffer.
46 std::uint8_t brokenData[] = {1, 2, 3, 4, 5, 6, 7, 8};
47 SkReadBuffer brokenBuffer{brokenData, std::size(brokenData)};
48
49 dstMetrics = SkFontMetricsPriv::MakeFromBuffer(brokenBuffer);
50 REPORTER_ASSERT(reporter, !dstMetrics.has_value());
51}
reporter
Definition: FontMgrTest.cpp:39
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static void Flatten(SkWriteBuffer &buffer, const SkFontMetrics &metrics)
static std::optional< SkFontMetrics > MakeFromBuffer(SkReadBuffer &buffer)
Definition: SkFont.h:35
static SkStrikeSpec MakeWithNoDevice(const SkFont &font, const SkPaint *paint=nullptr)
std::unique_ptr< SkScalerContext > createScalerContext() const
Definition: SkStrikeSpec.h:91
sk_sp< SkTypeface > CreateTestTypeface(const char *name, SkFontStyle style)
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.
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63