Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
tests
SkFontMetricsPrivTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2023 Google LLC
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
src/core/SkFontMetricsPriv.h
"
9
10
#include "
include/core/SkFont.h
"
11
#include "
include/core/SkFontMetrics.h
"
12
#include "
include/core/SkTypeface.h
"
13
#include "
src/core/SkReadBuffer.h
"
14
#include "
src/core/SkScalerContext.h
"
15
#include "
src/core/SkStrikeSpec.h
"
16
#include "
src/core/SkWriteBuffer.h
"
17
#include "
tests/Test.h
"
18
#include "
tools/fonts/FontToolUtils.h
"
19
20
#include <optional>
21
22
DEF_TEST
(SkFontMetricsPriv_Basic,
reporter
) {
23
auto
typeface =
ToolUtils::CreateTestTypeface
(
"monospace"
,
SkFontStyle
());
24
SkFont
font{typeface};
25
SkStrikeSpec
spec =
SkStrikeSpec::MakeWithNoDevice
(font);
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
}
52
53
reporter
reporter
Definition
FontMgrTest.cpp:39
FontToolUtils.h
SkFontMetricsPriv.h
SkFontMetrics.h
SkFont.h
SkReadBuffer.h
SkScalerContext.h
SkStrikeSpec.h
SkTypeface.h
SkWriteBuffer.h
Test.h
DEF_TEST
#define DEF_TEST(name, reporter)
Definition
Test.h:312
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition
Test.h:286
SkBinaryWriteBuffer
Definition
SkWriteBuffer.h:97
SkFontMetricsPriv::Flatten
static void Flatten(SkWriteBuffer &buffer, const SkFontMetrics &metrics)
Definition
SkFontMetricsPriv.cpp:15
SkFontMetricsPriv::MakeFromBuffer
static std::optional< SkFontMetrics > MakeFromBuffer(SkReadBuffer &buffer)
Definition
SkFontMetricsPriv.cpp:34
SkFontStyle
Definition
SkFontStyle.h:16
SkFont
Definition
SkFont.h:35
SkReadBuffer
Definition
SkReadBuffer.h:52
SkStrikeSpec
Definition
SkStrikeSpec.h:39
SkStrikeSpec::MakeWithNoDevice
static SkStrikeSpec MakeWithNoDevice(const SkFont &font, const SkPaint *paint=nullptr)
Definition
SkStrikeSpec.cpp:92
SkStrikeSpec::createScalerContext
std::unique_ptr< SkScalerContext > createScalerContext() const
Definition
SkStrikeSpec.h:91
ToolUtils::CreateTestTypeface
sk_sp< SkTypeface > CreateTestTypeface(const char *name, SkFontStyle style)
Definition
FontToolUtils.cpp:307
SkFontMetrics
Definition
SkFontMetrics.h:18
Generated on Fri Apr 26 2024 06:18:02 for Flutter Engine by
1.9.8