chromium/third_party/blink/renderer/platform/fonts/shaping/han_kerning_test.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/fonts/shaping/han_kerning.h"

#include <testing/gmock/include/gmock/gmock.h>
#include <testing/gtest/include/gtest/gtest.h>

#include "third_party/blink/renderer/platform/fonts/font.h"
#include "third_party/blink/renderer/platform/fonts/shaping/font_features.h"
#include "third_party/blink/renderer/platform/testing/font_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"

namespace blink {

Font CreateNotoCjk() {}

class HanKerningTest : public testing::Test {};

TEST_F(HanKerningTest, MayApply) {}

TEST_F(HanKerningTest, FontDataHorizontal) {}

TEST_F(HanKerningTest, FontDataVertical) {}

#if BUILDFLAG(IS_WIN)
// A test case of CJK fullwidth punctuation has slightly different widths from
// the `IdeographicInlineSize` (the width of U+0x6C34). crbug.com/1519775
// https://collabo-cafe.com/events/collabo/shingeki-anime-completed-hajime-isayama-illust2023/
TEST_F(HanKerningTest, FontDataSizeError) {
  class EnableAntialiasedText {
   public:
    EnableAntialiasedText()
        : is_antialiased_text_enabled_(
              FontCache::Get().AntialiasedTextEnabled()) {
      FontCache::Get().SetAntialiasedTextEnabled(true);
    }
    ~EnableAntialiasedText() {
      FontCache::Get().SetAntialiasedTextEnabled(is_antialiased_text_enabled_);
    }

   private:
    bool is_antialiased_text_enabled_;
  } enable_antialias_text;

  FontDescription font_description;
  font_description.SetFamily(
      FontFamily(AtomicString("Yu Gothic"), FontFamily::Type::kFamilyName));
  const float specified_size = 16.f * 1.03f;
  font_description.SetSpecifiedSize(specified_size);
  const float computed_size = specified_size * 1.25f;
  font_description.SetComputedSize(computed_size);
  font_description.SetFontSmoothing(FontSmoothingMode::kAntialiased);
  Font font(font_description);
  const SimpleFontData* primary_font = font.PrimaryFont();

  SkString name;
  primary_font->PlatformData().Typeface()->getPostScriptName(&name);
  if (!name.equals("YuGothic-Regular")) {
    return;
  }

  scoped_refptr<LayoutLocale> locale =
      LayoutLocale::CreateForTesting(AtomicString("ja"));
  HanKerning::FontData data(*font.PrimaryFont(), *locale, true);
  EXPECT_TRUE(data.has_alternate_spacing);
  EXPECT_EQ(data.type_for_dot, HanKerning::CharType::kClose);
  EXPECT_EQ(data.type_for_colon, HanKerning::CharType::kMiddle);
  EXPECT_EQ(data.type_for_semicolon, HanKerning::CharType::kMiddle);
  EXPECT_FALSE(data.is_quote_fullwidth);
}
#endif  // BUILDFLAG(IS_WIN)

TEST_F(HanKerningTest, ResetFeatures) {}

}  // namespace blink