subpixel-anti-aliasing-in-FreeType-2.8.1.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. From f25787b72c20e97cdeb74e037dc1ff56a88b45c6 Mon Sep 17 00:00:00 2001
  2. From: Ben Wagner <bungeman@google.com>
  3. Date: Tue, 1 Dec 2020 20:22:00 -0500
  4. Subject: [PATCH] Subpixel anti-aliasing in FreeType 2.8.1+
  5. FreeType 2.8.1 and later always provide some form of subpixel
  6. anti-aliasing.
  7. Bug: skia:10950,skia:6663
  8. Change-Id: I666cc942e73b73073cdabf900c25faa10d9aaf0f
  9. Reviewed-on: https://skia-review.googlesource.com/c/skia/+/339861
  10. Reviewed-by: Herb Derby <herb@google.com>
  11. Commit-Queue: Ben Wagner <bungeman@google.com>
  12. ---
  13. src/ports/SkFontHost_FreeType.cpp | 33 ++++++++++++++++++++-----------
  14. 1 file changed, 22 insertions(+), 11 deletions(-)
  15. diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
  16. index 990eff4f5e..c0aeb792da 100644
  17. --- a/src/ports/SkFontHost_FreeType.cpp
  18. +++ b/src/ports/SkFontHost_FreeType.cpp
  19. @@ -32,6 +32,7 @@
  20. #include "src/utils/SkMatrix22.h"
  21. #include <memory>
  22. +#include <tuple>
  23. #include <ft2build.h>
  24. #include FT_ADVANCES_H
  25. @@ -147,13 +148,16 @@ public:
  26. // *reinterpret_cast<void**>(&procPtr) = dlsym(self, "proc");
  27. // because clang has not implemented DR573. See http://clang.llvm.org/cxx_dr_status.html .
  28. - FT_Int major, minor, patch;
  29. - FT_Library_Version(fLibrary, &major, &minor, &patch);
  30. + using Version = std::tuple<FT_Int, FT_Int, FT_Int>;
  31. + Version version;
  32. + FT_Library_Version(fLibrary, &std::get<0>(version),
  33. + &std::get<1>(version),
  34. + &std::get<2>(version));
  35. #if SK_FREETYPE_MINIMUM_RUNTIME_VERSION >= 0x02070100
  36. fGetVarDesignCoordinates = FT_Get_Var_Design_Coordinates;
  37. #elif SK_FREETYPE_MINIMUM_RUNTIME_VERSION & SK_FREETYPE_DLOPEN
  38. - if (major > 2 || ((major == 2 && minor > 7) || (major == 2 && minor == 7 && patch >= 0))) {
  39. + if (Version(2,7,0) <= version) {
  40. //The FreeType library is already loaded, so symbols are available in process.
  41. void* self = dlopen(nullptr, RTLD_LAZY);
  42. if (self) {
  43. @@ -166,7 +170,7 @@ public:
  44. #if SK_FREETYPE_MINIMUM_RUNTIME_VERSION >= 0x02070200
  45. FT_Set_Default_Properties(fLibrary);
  46. #elif SK_FREETYPE_MINIMUM_RUNTIME_VERSION & SK_FREETYPE_DLOPEN
  47. - if (major > 2 || ((major == 2 && minor > 7) || (major == 2 && minor == 7 && patch >= 1))) {
  48. + if (Version(2,7,1) <= version) {
  49. //The FreeType library is already loaded, so symbols are available in process.
  50. void* self = dlopen(nullptr, RTLD_LAZY);
  51. if (self) {
  52. @@ -185,7 +189,7 @@ public:
  53. #if SK_FREETYPE_MINIMUM_RUNTIME_VERSION >= 0x02080000
  54. fLightHintingIsYOnly = true;
  55. #else
  56. - if (major > 2 || ((major == 2 && minor > 8) || (major == 2 && minor == 8 && patch >= 0))) {
  57. + if (Version(2,8,0) <= version) {
  58. fLightHintingIsYOnly = true;
  59. }
  60. #endif
  61. @@ -194,7 +198,7 @@ public:
  62. #if SK_FREETYPE_MINIMUM_RUNTIME_VERSION >= 0x02080100
  63. fGetVarAxisFlags = FT_Get_Var_Axis_Flags;
  64. #elif SK_FREETYPE_MINIMUM_RUNTIME_VERSION & SK_FREETYPE_DLOPEN
  65. - if (major > 2 || ((major == 2 && minor > 7) || (major == 2 && minor == 7 && patch >= 0))) {
  66. + if (Version(2,7,0) <= version) {
  67. //The FreeType library is already loaded, so symbols are available in process.
  68. void* self = dlopen(nullptr, RTLD_LAZY);
  69. if (self) {
  70. @@ -204,11 +208,18 @@ public:
  71. }
  72. #endif
  73. - // Setup LCD filtering. This reduces color fringes for LCD smoothed glyphs.
  74. - // The default has changed over time, so this doesn't mean the same thing to all users.
  75. - if (FT_Library_SetLcdFilter(fLibrary, FT_LCD_FILTER_DEFAULT) == 0) {
  76. - fIsLCDSupported = true;
  77. - fLCDExtra = 2; //Using a filter adds one full pixel to each side.
  78. + fIsLCDSupported =
  79. + // Subpixel anti-aliasing may be unfiltered until the LCD filter is set.
  80. + // Newer versions may still need this, so this test with side effects must come first.
  81. + // The default has changed over time, so this doesn't mean the same thing to all users.
  82. + (FT_Library_SetLcdFilter(fLibrary, FT_LCD_FILTER_DEFAULT) == 0) ||
  83. +
  84. + // In 2.8.1 and later FreeType always provides some form of subpixel anti-aliasing.
  85. + ((SK_FREETYPE_MINIMUM_RUNTIME_VERSION) >= 0x02080100) ||
  86. + (Version(2,8,1) <= version);
  87. +
  88. + if (fIsLCDSupported) {
  89. + fLCDExtra = 2; // Using a filter may require up to one full pixel to each side.
  90. }
  91. }
  92. ~FreeTypeLibrary() {