Commit d1955fbf authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Fix FontPlatformDataMacTest.VariableOpticalSizingThreshold for Big Sur

On Big Sur, the system font has a full, real, 'opsz' axis rather than
the 10.15 trick of gluing together two optical sizes. Adjust
the test to match.

Do some cleanup in the main .mm file. Switch from VLAs in
VariableAxisChangeEffective() to WTF::Vector (as is used in the
rest of the file) as VLAs are not allowed in Chromium nor Blink,
and use #include as the style is to use #import for Objective-C
headers.

Bug: 1101448
Change-Id: I6043b53b9ac07cdddd082a19abf7bc8cbe3af58b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351299
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797228}
parent 5c03167f
...@@ -46,6 +46,9 @@ enum class FontOrientation; ...@@ -46,6 +46,9 @@ enum class FontOrientation;
class FontPlatformData; class FontPlatformData;
class FontVariationSettings; class FontVariationSettings;
// Given a typeface and a variable axis, returns whether a new value for that
// axis isn't clamped and therefore will effect a change to the typeface if
// applied.
bool PLATFORM_EXPORT VariableAxisChangeEffective(SkTypeface* typeface, bool PLATFORM_EXPORT VariableAxisChangeEffective(SkTypeface* typeface,
SkFourByteTag axis, SkFourByteTag axis,
float new_value); float new_value);
......
...@@ -26,22 +26,23 @@ ...@@ -26,22 +26,23 @@
#import <AppKit/NSFont.h> #import <AppKit/NSFont.h>
#import <AvailabilityMacros.h> #import <AvailabilityMacros.h>
#include "base/mac/foundation_util.h" #import "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h" #import "base/mac/scoped_nsobject.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#import "third_party/blink/public/platform/mac/web_sandbox_support.h" #include "third_party/blink/public/platform/mac/web_sandbox_support.h"
#import "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#import "third_party/blink/renderer/platform/fonts/font.h" #include "third_party/blink/renderer/platform/fonts/font.h"
#import "third_party/blink/renderer/platform/fonts/font_platform_data.h" #include "third_party/blink/renderer/platform/fonts/font_platform_data.h"
#import "third_party/blink/renderer/platform/fonts/mac/core_text_font_format_support.h" #include "third_party/blink/renderer/platform/fonts/mac/core_text_font_format_support.h"
#import "third_party/blink/renderer/platform/fonts/opentype/font_settings.h" #include "third_party/blink/renderer/platform/fonts/opentype/font_settings.h"
#import "third_party/blink/renderer/platform/fonts/shaping/harfbuzz_face.h" #include "third_party/blink/renderer/platform/fonts/shaping/harfbuzz_face.h"
#import "third_party/blink/renderer/platform/web_test_support.h" #include "third_party/blink/renderer/platform/web_test_support.h"
#import "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#import "third_party/skia/include/core/SkFont.h" #include "third_party/blink/renderer/platform/wtf/vector.h"
#import "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkFont.h"
#import "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/core/SkStream.h"
#import "third_party/skia/include/core/SkTypes.h" #include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/core/SkTypes.h"
#import "third_party/skia/include/ports/SkTypeface_mac.h" #import "third_party/skia/include/ports/SkTypeface_mac.h"
namespace { namespace {
...@@ -58,9 +59,9 @@ bool VariableAxisChangeEffective(SkTypeface* typeface, ...@@ -58,9 +59,9 @@ bool VariableAxisChangeEffective(SkTypeface* typeface,
if (num_axes <= 0) if (num_axes <= 0)
return false; return false;
SkFontParameters::Variation::Axis axes_parameters[num_axes]; Vector<SkFontParameters::Variation::Axis> axes_parameters(num_axes);
int returned_axes = int returned_axes =
typeface->getVariationDesignParameters(axes_parameters, num_axes); typeface->getVariationDesignParameters(axes_parameters.data(), num_axes);
DCHECK_EQ(num_axes, returned_axes); DCHECK_EQ(num_axes, returned_axes);
DCHECK_GE(num_axes, 0); DCHECK_GE(num_axes, 0);
...@@ -78,9 +79,10 @@ bool VariableAxisChangeEffective(SkTypeface* typeface, ...@@ -78,9 +79,10 @@ bool VariableAxisChangeEffective(SkTypeface* typeface,
// effect. // effect.
// Then compare if clamped value differs from what is set on the font. // Then compare if clamped value differs from what is set on the font.
SkFontArguments::VariationPosition::Coordinate coordinates[num_coordinates]; Vector<SkFontArguments::VariationPosition::Coordinate> coordinates(
num_coordinates);
int returned_coordinates = int returned_coordinates =
typeface->getVariationDesignPosition(coordinates, num_coordinates); typeface->getVariationDesignPosition(coordinates.data(), num_coordinates);
if (returned_coordinates != num_coordinates) if (returned_coordinates != num_coordinates)
return false; // Something went wrong in retrieving actual axis positions, return false; // Something went wrong in retrieving actual axis positions,
...@@ -213,10 +215,10 @@ std::unique_ptr<FontPlatformData> FontPlatformDataFromNSFont( ...@@ -213,10 +215,10 @@ std::unique_ptr<FontPlatformData> FontPlatformDataFromNSFont(
} }
// Iterate over the font's axes and find a missing tag from variation // Iterate over the font's axes and find a missing tag from variation
// settings, special case opsz, track the number of axes reconfigured. // settings, special case 'opsz', track the number of axes reconfigured.
bool axes_reconfigured = false; bool axes_reconfigured = false;
for (auto& coordinate : coordinates_to_set) { for (auto& coordinate : coordinates_to_set) {
// Set opsz to font size but allow having it overriden by // Set 'opsz' to font size but allow having it overridden by
// font-variation-settings in case it has 'opsz'. // font-variation-settings in case it has 'opsz'.
if (coordinate.axis == kOpszTag && optical_sizing == kAutoOpticalSizing) { if (coordinate.axis == kOpszTag && optical_sizing == kAutoOpticalSizing) {
if (VariableAxisChangeEffective(typeface.get(), coordinate.axis, size)) { if (VariableAxisChangeEffective(typeface.get(), coordinate.axis, size)) {
...@@ -247,7 +249,7 @@ std::unique_ptr<FontPlatformData> FontPlatformDataFromNSFont( ...@@ -247,7 +249,7 @@ std::unique_ptr<FontPlatformData> FontPlatformDataFromNSFont(
SkFontArguments().setVariationDesignPosition(variation_design_position))); SkFontArguments().setVariationDesignPosition(variation_design_position)));
if (!cloned_typeface) { if (!cloned_typeface) {
// Applying varition parameters failed, return original typeface. // Applying variation parameters failed, return original typeface.
return make_typeface_fontplatformdata(); return make_typeface_fontplatformdata();
} }
typeface = cloned_typeface; typeface = cloned_typeface;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment