Пример #1
0
PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& description, ShouldRetain shouldRetain)
{
    const AtomicString fallbackFontFamily = getFallbackFontFamily(description);
    const FontPlatformData* fontPlatformData = getFontPlatformData(description, fallbackFontFamily);

    // We should at least have Sans or Arial which is the last resort fallback of SkFontHost ports.
    if (!fontPlatformData) {
        DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("Sans", AtomicString::ConstructFromLiteral));
        fontPlatformData = getFontPlatformData(description, sansStr);
    }
Пример #2
0
PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& description, ShouldRetain shouldRetain)
{
    const AtomicString fallbackFontFamily = getFallbackFontFamily(description);
    const FontPlatformData* fontPlatformData = 0;
    if (!fallbackFontFamily.isEmpty())
        fontPlatformData = getFontPlatformData(description, fallbackFontFamily);

    if (!fontPlatformData) {
        // we should at least have Arial; this is the SkFontHost_fontconfig last resort fallback
        DEFINE_STATIC_LOCAL(const AtomicString, arialStr, ("Arial", AtomicString::ConstructFromLiteral));
        fontPlatformData = getFontPlatformData(description, arialStr);
    }
Пример #3
0
sk_sp<SkTypeface> FontCache::createTypeface(
    const FontDescription& fontDescription,
    const FontFaceCreationParams& creationParams,
    CString& name) {
  AtomicString family = creationParams.family();

  if (family.isEmpty()) {
    name = getFallbackFontFamily(fontDescription).string().utf8();
  } else {
    name = family.utf8();
  }

  fonts::FontRequest request;
  request.family = name.data();
  request.weight = ToIntegerWeight(fontDescription.weight());
  request.width = static_cast<uint32_t>(fontDescription.stretch());
  request.slant = ToFontSlant(fontDescription.style());

  fonts::FontResponsePtr response;
  auto& font_provider = GetFontProvider();
  font_provider->GetFont(
      std::move(request),
      [&response](fonts::FontResponsePtr r) { response = std::move(r); });
  font_provider.WaitForResponse();

  FXL_DCHECK(response)
      << "Unable to contact the font provider. Did you run "
         "Flutter in an environment that has a font manager?\n"
         "See <https://fuchsia.googlesource.com/modular/+/master/README.md>.";

  if (!response)
    return nullptr;

  sk_sp<SkData> data = MakeSkDataFromBuffer(response->data.buffer);
  if (!data)
    return nullptr;

  return SkFontMgr::RefDefault()->makeFromData(std::move(data));
}