Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static void Flatten(SkWriteBuffer &buffer, const SkFontMetrics &metrics)
static std::optional< SkFontMetrics > MakeFromBuffer(SkReadBuffer &buffer)
static SkStrikeSpec MakeWithNoDevice(const SkFont &font, const SkPaint *paint=nullptr)
std::unique_ptr< SkScalerContext > createScalerContext() const
sk_sp< SkTypeface > CreateTestTypeface(const char *name, SkFontStyle style)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
font
Font Metadata and Metrics.