font_fallback_skia.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/gfx/font_fallback.h"
  5. #include <string>
  6. #include <vector>
  7. #include "base/strings/string_piece.h"
  8. #include "base/strings/utf_string_conversions.h"
  9. #include "base/trace_event/trace_event.h"
  10. #include "build/build_config.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. #include "ui/gfx/font.h"
  13. #include "ui/gfx/font_fallback_skia_impl.h"
  14. #include "ui/gfx/font_render_params.h"
  15. #include "ui/gfx/platform_font.h"
  16. namespace gfx {
  17. std::vector<Font> GetFallbackFonts(const Font& font) {
  18. return std::vector<Font>();
  19. }
  20. bool GetFallbackFont(const Font& font,
  21. const std::string& locale,
  22. base::StringPiece16 text,
  23. Font* result) {
  24. TRACE_EVENT0("fonts", "gfx::GetFallbackFont");
  25. if (text.empty())
  26. return false;
  27. sk_sp<SkTypeface> fallback_typeface =
  28. GetSkiaFallbackTypeface(font, locale, text);
  29. if (!fallback_typeface)
  30. return false;
  31. // Fallback needs to keep the exact SkTypeface, as re-matching the font using
  32. // family name and styling information loses access to the underlying platform
  33. // font handles and is not guaranteed to result in the correct typeface, see
  34. // https://crbug.com/1003829
  35. *result = Font(PlatformFont::CreateFromSkTypeface(
  36. std::move(fallback_typeface), font.GetFontSize(), absl::nullopt));
  37. return true;
  38. }
  39. } // namespace gfx