chromium/third_party/blink/renderer/platform/fonts/font_platform_data.cc

/*
 * Copyright (C) 2011 Brent Fulgham
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/platform/fonts/font_platform_data.h"

#include "base/feature_list.h"
#include "build/build_config.h"
#include "hb-ot.h"
#include "hb.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_token_builder.h"
#include "third_party/blink/public/platform/linux/web_sandbox_support.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/fonts/font_cache.h"
#include "third_party/blink/renderer/platform/fonts/shaping/harfbuzz_face.h"
#include "third_party/blink/renderer/platform/fonts/shaping/harfbuzz_font_cache.h"
#include "third_party/blink/renderer/platform/fonts/shaping/harfbuzz_font_data.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/text/character.h"
#include "third_party/blink/renderer/platform/web_test_support.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkTypeface.h"

#if BUILDFLAG(IS_MAC)
#include "third_party/skia/include/ports/SkTypeface_mac.h"
#endif

namespace blink {
namespace {

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// Getting the system font render style takes a significant amount of time on
// Linux because looking up fonts using fontconfig can be very slow. We fetch
// the render style for each font family and text size, while it's very
// unlikely that different text sizes for the same font family will have
// different render styles. In addition, sometimes the font family name is not
// normalized, so we may look up both "Arial" and "arial" which causes an
// additional fontconfig lookup. This feature enables normalizing the font
// family name and not using the text size for looking up the system render
// style, which will hopefully result in a large decrease in the number of slow
// fontconfig lookups.
BASE_FEATURE();
#endif  //  BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

}  // namespace

FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
    :{}

FontPlatformData::FontPlatformData() = default;

FontPlatformData::FontPlatformData(const FontPlatformData& source)
    :{}

FontPlatformData::FontPlatformData(const FontPlatformData& src, float text_size)
    :{}

FontPlatformData::FontPlatformData(sk_sp<SkTypeface> typeface,
                                   const std::string& family,
                                   float text_size,
                                   bool synthetic_bold,
                                   bool synthetic_italic,
                                   TextRenderingMode text_rendering,
                                   ResolvedFontFeatures resolved_font_features,
                                   FontOrientation orientation)
    :{}

FontPlatformData::~FontPlatformData() = default;

void FontPlatformData::Trace(Visitor* visitor) const {}

#if BUILDFLAG(IS_MAC)
CTFontRef FontPlatformData::CtFont() const {
  return SkTypeface_GetCTFontRef(typeface_.get());
}
#endif

bool FontPlatformData::operator==(const FontPlatformData& a) const {}

SkTypefaceID FontPlatformData::UniqueID() const {}

String FontPlatformData::FontFamilyName() const {}

bool FontPlatformData::IsAhem() const {}

SkTypeface* FontPlatformData::Typeface() const {}

HarfBuzzFace* FontPlatformData::GetHarfBuzzFace() const {}

bool FontPlatformData::HasSpaceInLigaturesOrKerning(
    TypesettingFeatures features) const {}

unsigned FontPlatformData::GetHash() const {}

#if !BUILDFLAG(IS_MAC)
bool FontPlatformData::FontContainsCharacter(UChar32 character) const {}
#endif

#if !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_WIN)
// static
WebFontRenderStyle FontPlatformData::QuerySystemRenderStyle(
    const std::string& family,
    float text_size,
    SkFontStyle font_style,
    TextRenderingMode text_rendering) {}
#endif  // !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_WIN)

#if !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_IOS)
SkFont FontPlatformData::CreateSkFont(const FontDescription*) const {}
#endif  // !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_IOS)

IdentifiableToken FontPlatformData::ComputeTypefaceDigest() const {}

String FontPlatformData::GetPostScriptName() const {}

}  // namespace blink