blob: 675f34fa0f0187096346d48b7b8afa5cb2fd91db [file]
// Copyright 2026 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include <vector>
#include "core/fxge/cfx_font.h"
#include "core/fxge/skrifa/src/main.rs.h"
#include "core/fxge/skrifa/src/outlines.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/utils/file_util.h"
#include "testing/utils/path_service.h"
TEST(FxSkrifaTest, TestFoxitFixedCff) {
std::string font_path = PathService::GetTestFilePath("fonts/foxit_fixed.cff");
skrifa::run(rust::Str(font_path));
}
TEST(FxSkrifaTest, TestGetOs2CodePageRange) {
std::string font_path = PathService::GetTestFilePath("fonts/bug_2094.ttf");
std::vector<uint8_t> bytes = GetFileContents(font_path.c_str());
skrifa::CodePageRange range;
EXPECT_TRUE(skrifa::get_os2_code_page_range(rust::Slice<const uint8_t>(bytes),
range));
EXPECT_EQ(range.range1, 0u);
EXPECT_EQ(range.range2, 0u);
}
TEST(FxSkrifaTest, TestGetOs2Panose) {
std::string font_path = PathService::GetTestFilePath("fonts/bug_2094.ttf");
std::vector<uint8_t> bytes = GetFileContents(font_path.c_str());
skrifa::Os2Panose panose;
EXPECT_TRUE(
skrifa::get_os2_panose(rust::Slice<const uint8_t>(bytes), panose));
EXPECT_EQ(panose.b0, 2);
EXPECT_EQ(panose.b1, 0);
}
TEST(FxSkrifaTest, TestGetOs2FsType) {
std::string font_path = PathService::GetTestFilePath("fonts/bug_2094.ttf");
std::vector<uint8_t> bytes = GetFileContents(font_path.c_str());
uint16_t fs_type = 0x1234; // Show that is is updated.
EXPECT_TRUE(
skrifa::get_os2_fs_type(rust::Slice<const uint8_t>(bytes), fs_type));
EXPECT_EQ(fs_type, 0u);
}
TEST(FxSkrifaTest, TestGetCharCodesAndIndices) {
std::string font_path = PathService::GetTestFilePath("fonts/ahem/Ahem.ttf");
std::vector<uint8_t> bytes = GetFileContents(font_path.c_str());
auto results = skrifa::get_char_codes_and_indices(
rust::Slice<const uint8_t>(bytes), 0xFFFF);
ASSERT_EQ(278u, results.size());
EXPECT_EQ(skrifa::CharCodeAndIndex(32, 3), results[0]);
EXPECT_EQ(skrifa::CharCodeAndIndex(33, 4), results[1]);
EXPECT_EQ(skrifa::CharCodeAndIndex(65279, 245), results[277]);
}