Commit c101dcd6 authored by Mike Reed's avatar Mike Reed Committed by Commit Bot

simple_font_data and harfbuzz_font to use SkFont instead of SkPaint

Change-Id: I0243c3853632ec44a2e1e4ec4220ce4425e05e64
Bug: skia:2664
Reviewed-on: https://chromium-review.googlesource.com/c/1341217
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: default avatarFlorin Malita <fmalita@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609307}
parent ed72893b
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "third_party/blink/renderer/platform/fonts/font_platform_data.h" #include "third_party/blink/renderer/platform/fonts/font_platform_data.h"
#include "third_party/blink/renderer/platform/fonts/vdmx_parser.h" #include "third_party/blink/renderer/platform/fonts/vdmx_parser.h"
#include <SkPaint.h> #include <SkFont.h>
#include <SkTypeface.h> #include <SkTypeface.h>
namespace blink { namespace blink {
...@@ -49,13 +49,13 @@ void FontMetrics::AscentDescentWithHacks( ...@@ -49,13 +49,13 @@ void FontMetrics::AscentDescentWithHacks(
unsigned& visual_overflow_inflation_for_ascent, unsigned& visual_overflow_inflation_for_ascent,
unsigned& visual_overflow_inflation_for_descent, unsigned& visual_overflow_inflation_for_descent,
const FontPlatformData& platform_data, const FontPlatformData& platform_data,
const SkPaint& paint, const SkFont& font,
bool subpixel_ascent_descent) { bool subpixel_ascent_descent) {
SkTypeface* face = paint.getTypeface(); SkTypeface* face = font.getTypeface();
DCHECK(face); DCHECK(face);
SkFontMetrics metrics; SkFontMetrics metrics;
paint.getFontMetrics(&metrics); font.getMetrics(&metrics);
int vdmx_ascent = 0, vdmx_descent = 0; int vdmx_ascent = 0, vdmx_descent = 0;
bool is_vdmx_valid = false; bool is_vdmx_valid = false;
...@@ -66,8 +66,9 @@ void FontMetrics::AscentDescentWithHacks( ...@@ -66,8 +66,9 @@ void FontMetrics::AscentDescentWithHacks(
// done. This code should be pushed into FreeType (hinted font metrics). // done. This code should be pushed into FreeType (hinted font metrics).
static const uint32_t kVdmxTag = SkSetFourByteTag('V', 'D', 'M', 'X'); static const uint32_t kVdmxTag = SkSetFourByteTag('V', 'D', 'M', 'X');
int pixel_size = platform_data.size() + 0.5; int pixel_size = platform_data.size() + 0.5;
if (!paint.isAutohinted() && (paint.getHinting() == SkFontHinting::kFull || if (!font.isForceAutoHinting() &&
paint.getHinting() == SkFontHinting::kNormal)) { (font.getHinting() == SkFontHinting::kFull ||
font.getHinting() == SkFontHinting::kNormal)) {
size_t vdmx_size = face->getTableSize(kVdmxTag); size_t vdmx_size = face->getTableSize(kVdmxTag);
if (vdmx_size && vdmx_size < kMaxVDMXTableSize) { if (vdmx_size && vdmx_size < kMaxVDMXTableSize) {
uint8_t* vdmx_table = (uint8_t*)WTF::Partitions::FastMalloc( uint8_t* vdmx_table = (uint8_t*)WTF::Partitions::FastMalloc(
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h" #include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include <SkPaint.h> class SkFont;
namespace blink { namespace blink {
...@@ -168,7 +168,7 @@ class FontMetrics { ...@@ -168,7 +168,7 @@ class FontMetrics {
unsigned& visual_overflow_inflation_for_ascent, unsigned& visual_overflow_inflation_for_ascent,
unsigned& visual_overflow_inflation_for_descent, unsigned& visual_overflow_inflation_for_descent,
const FontPlatformData&, const FontPlatformData&,
const SkPaint&, const SkFont&,
bool subpixel_ascent_descent = false); bool subpixel_ascent_descent = false);
private: private:
......
...@@ -263,7 +263,7 @@ float OpenTypeVerticalData::AdvanceHeight(Glyph glyph) const { ...@@ -263,7 +263,7 @@ float OpenTypeVerticalData::AdvanceHeight(Glyph glyph) const {
} }
void OpenTypeVerticalData::GetVerticalTranslationsForGlyphs( void OpenTypeVerticalData::GetVerticalTranslationsForGlyphs(
const SkPaint& paint, const SkFont& font,
const Glyph* glyphs, const Glyph* glyphs,
size_t count, size_t count,
float* out_xy_array) const { float* out_xy_array) const {
...@@ -304,7 +304,7 @@ void OpenTypeVerticalData::GetVerticalTranslationsForGlyphs( ...@@ -304,7 +304,7 @@ void OpenTypeVerticalData::GetVerticalTranslationsForGlyphs(
float top_side_bearing = top_side_bearing_f_unit * size_per_unit_; float top_side_bearing = top_side_bearing_f_unit * size_per_unit_;
SkRect skiaBounds; SkRect skiaBounds;
SkiaTextMetrics(&paint).GetSkiaBoundsForGlyph(glyph, &skiaBounds); SkiaTextMetrics(font).GetSkiaBoundsForGlyph(glyph, &skiaBounds);
FloatRect bounds(skiaBounds); FloatRect bounds(skiaBounds);
out_xy_array[1] = bounds.Y() - top_side_bearing; out_xy_array[1] = bounds.Y() - top_side_bearing;
continue; continue;
......
...@@ -33,10 +33,11 @@ ...@@ -33,10 +33,11 @@
#include "third_party/blink/renderer/platform/wtf/ref_counted.h" #include "third_party/blink/renderer/platform/wtf/ref_counted.h"
#include "third_party/blink/renderer/platform/wtf/vector.h" #include "third_party/blink/renderer/platform/wtf/vector.h"
#include <SkPaint.h>
#include <SkRefCnt.h> #include <SkRefCnt.h>
#include <SkTypeface.h> #include <SkTypeface.h>
class SkFont;
namespace blink { namespace blink {
class PLATFORM_EXPORT OpenTypeVerticalData class PLATFORM_EXPORT OpenTypeVerticalData
...@@ -55,7 +56,7 @@ class PLATFORM_EXPORT OpenTypeVerticalData ...@@ -55,7 +56,7 @@ class PLATFORM_EXPORT OpenTypeVerticalData
bool HasVerticalMetrics() const { return !advance_heights_.IsEmpty(); } bool HasVerticalMetrics() const { return !advance_heights_.IsEmpty(); }
float AdvanceHeight(Glyph) const; float AdvanceHeight(Glyph) const;
void GetVerticalTranslationsForGlyphs(const SkPaint&, void GetVerticalTranslationsForGlyphs(const SkFont&,
const Glyph*, const Glyph*,
size_t, size_t,
float* out_xy_array) const; float* out_xy_array) const;
......
...@@ -131,7 +131,7 @@ static hb_position_t HarfBuzzGetGlyphHorizontalAdvance(hb_font_t* hb_font, ...@@ -131,7 +131,7 @@ static hb_position_t HarfBuzzGetGlyphHorizontalAdvance(hb_font_t* hb_font,
reinterpret_cast<HarfBuzzFontData*>(font_data); reinterpret_cast<HarfBuzzFontData*>(font_data);
hb_position_t advance = 0; hb_position_t advance = 0;
SkiaTextMetrics(&hb_font_data->paint_) SkiaTextMetrics(hb_font_data->font_)
.GetGlyphWidthForHarfBuzz(glyph, &advance); .GetGlyphWidthForHarfBuzz(glyph, &advance);
return advance; return advance;
} }
...@@ -146,7 +146,7 @@ static void HarfBuzzGetGlyphHorizontalAdvances(hb_font_t* font, ...@@ -146,7 +146,7 @@ static void HarfBuzzGetGlyphHorizontalAdvances(hb_font_t* font,
void* user_data) { void* user_data) {
HarfBuzzFontData* hb_font_data = HarfBuzzFontData* hb_font_data =
reinterpret_cast<HarfBuzzFontData*>(font_data); reinterpret_cast<HarfBuzzFontData*>(font_data);
SkiaTextMetrics(&hb_font_data->paint_) SkiaTextMetrics(hb_font_data->font_)
.GetGlyphWidthForHarfBuzz(count, first_glyph, glyph_stride, first_advance, .GetGlyphWidthForHarfBuzz(count, first_glyph, glyph_stride, first_advance,
advance_stride); advance_stride);
} }
...@@ -166,7 +166,7 @@ static hb_bool_t HarfBuzzGetGlyphVerticalOrigin(hb_font_t* hb_font, ...@@ -166,7 +166,7 @@ static hb_bool_t HarfBuzzGetGlyphVerticalOrigin(hb_font_t* hb_font,
float result[] = {0, 0}; float result[] = {0, 0};
Glyph the_glyph = glyph; Glyph the_glyph = glyph;
vertical_data->GetVerticalTranslationsForGlyphs(hb_font_data->paint_, vertical_data->GetVerticalTranslationsForGlyphs(hb_font_data->font_,
&the_glyph, 1, result); &the_glyph, 1, result);
*x = SkiaTextMetrics::SkiaScalarToHarfBuzzPosition(-result[0]); *x = SkiaTextMetrics::SkiaScalarToHarfBuzzPosition(-result[0]);
*y = SkiaTextMetrics::SkiaScalarToHarfBuzzPosition(-result[1]); *y = SkiaTextMetrics::SkiaScalarToHarfBuzzPosition(-result[1]);
...@@ -201,7 +201,7 @@ static hb_position_t HarfBuzzGetGlyphHorizontalKerning( ...@@ -201,7 +201,7 @@ static hb_position_t HarfBuzzGetGlyphHorizontalKerning(
HarfBuzzFontData* hb_font_data = HarfBuzzFontData* hb_font_data =
reinterpret_cast<HarfBuzzFontData*>(font_data); reinterpret_cast<HarfBuzzFontData*>(font_data);
SkTypeface* typeface = hb_font_data->paint_.getTypeface(); SkTypeface* typeface = hb_font_data->font_.getTypeface();
const uint16_t glyphs[2] = {static_cast<uint16_t>(left_glyph), const uint16_t glyphs[2] = {static_cast<uint16_t>(left_glyph),
static_cast<uint16_t>(right_glyph)}; static_cast<uint16_t>(right_glyph)};
...@@ -224,7 +224,7 @@ static hb_bool_t HarfBuzzGetGlyphExtents(hb_font_t* hb_font, ...@@ -224,7 +224,7 @@ static hb_bool_t HarfBuzzGetGlyphExtents(hb_font_t* hb_font,
HarfBuzzFontData* hb_font_data = HarfBuzzFontData* hb_font_data =
reinterpret_cast<HarfBuzzFontData*>(font_data); reinterpret_cast<HarfBuzzFontData*>(font_data);
SkiaTextMetrics(&hb_font_data->paint_) SkiaTextMetrics(hb_font_data->font_)
.GetGlyphExtentsForHarfBuzz(glyph, extents); .GetGlyphExtentsForHarfBuzz(glyph, extents);
return true; return true;
} }
...@@ -300,7 +300,7 @@ unsigned HarfBuzzFace::UnitsPerEmFromHeadTable() { ...@@ -300,7 +300,7 @@ unsigned HarfBuzzFace::UnitsPerEmFromHeadTable() {
} }
bool HarfBuzzFace::ShouldSubpixelPosition() { bool HarfBuzzFace::ShouldSubpixelPosition() {
return harfbuzz_font_data_->paint_.isSubpixelText(); return harfbuzz_font_data_->font_.isSubpixel();
} }
static hb_font_funcs_t* HarfBuzzSkiaGetFontFuncs() { static hb_font_funcs_t* HarfBuzzSkiaGetFontFuncs() {
...@@ -431,11 +431,8 @@ static_assert( ...@@ -431,11 +431,8 @@ static_assert(
hb_font_t* HarfBuzzFace::GetScaledFont( hb_font_t* HarfBuzzFace::GetScaledFont(
scoped_refptr<UnicodeRangeSet> range_set, scoped_refptr<UnicodeRangeSet> range_set,
VerticalLayoutCallbacks vertical_layout) const { VerticalLayoutCallbacks vertical_layout) const {
SkPaint paint;
platform_data_->SetupSkPaint(&paint);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
harfbuzz_font_data_->range_set_ = std::move(range_set); harfbuzz_font_data_->range_set_ = std::move(range_set);
harfbuzz_font_data_->UpdateFallbackMetricsAndScale(*platform_data_, paint, harfbuzz_font_data_->UpdateFallbackMetricsAndScale(*platform_data_,
vertical_layout); vertical_layout);
int scale = int scale =
...@@ -443,7 +440,7 @@ hb_font_t* HarfBuzzFace::GetScaledFont( ...@@ -443,7 +440,7 @@ hb_font_t* HarfBuzzFace::GetScaledFont(
hb_font_set_scale(unscaled_font_, scale, scale); hb_font_set_scale(unscaled_font_, scale, scale);
hb_font_set_ptem(unscaled_font_, platform_data_->size() / kCssPixelsPerPoint); hb_font_set_ptem(unscaled_font_, platform_data_->size() / kCssPixelsPerPoint);
SkTypeface* typeface = harfbuzz_font_data_->paint_.getTypeface(); SkTypeface* typeface = harfbuzz_font_data_->font_.getTypeface();
int axis_count = typeface->getVariationDesignPosition(nullptr, 0); int axis_count = typeface->getVariationDesignPosition(nullptr, 0);
if (axis_count > 0) { if (axis_count > 0) {
Vector<SkFontArguments::VariationPosition::Coordinate> axis_values; Vector<SkFontArguments::VariationPosition::Coordinate> axis_values;
......
...@@ -40,7 +40,7 @@ struct HarfBuzzFontData { ...@@ -40,7 +40,7 @@ struct HarfBuzzFontData {
public: public:
HarfBuzzFontData() HarfBuzzFontData()
: paint_(), : font_(),
space_in_gpos_(SpaceGlyphInOpenTypeTables::Unknown), space_in_gpos_(SpaceGlyphInOpenTypeTables::Unknown),
space_in_gsub_(SpaceGlyphInOpenTypeTables::Unknown), space_in_gsub_(SpaceGlyphInOpenTypeTables::Unknown),
vertical_data_(nullptr), vertical_data_(nullptr),
...@@ -51,19 +51,19 @@ struct HarfBuzzFontData { ...@@ -51,19 +51,19 @@ struct HarfBuzzFontData {
// layout information is found from the font. // layout information is found from the font.
void UpdateFallbackMetricsAndScale( void UpdateFallbackMetricsAndScale(
const FontPlatformData& platform_data, const FontPlatformData& platform_data,
const SkPaint& paint,
HarfBuzzFace::VerticalLayoutCallbacks vertical_layout) { HarfBuzzFace::VerticalLayoutCallbacks vertical_layout) {
float ascent = 0; float ascent = 0;
float descent = 0; float descent = 0;
unsigned dummy_ascent_inflation = 0; unsigned dummy_ascent_inflation = 0;
unsigned dummy_descent_inflation = 0; unsigned dummy_descent_inflation = 0;
paint_ = paint; font_ = SkFont();
platform_data.SetupSkFont(&font_);
if (UNLIKELY(vertical_layout == HarfBuzzFace::PrepareForVerticalLayout)) { if (UNLIKELY(vertical_layout == HarfBuzzFace::PrepareForVerticalLayout)) {
FontMetrics::AscentDescentWithHacks( FontMetrics::AscentDescentWithHacks(
ascent, descent, dummy_ascent_inflation, dummy_descent_inflation, ascent, descent, dummy_ascent_inflation, dummy_descent_inflation,
platform_data, paint); platform_data, font_);
ascent_fallback_ = ascent; ascent_fallback_ = ascent;
// Simulate the rounding that FontMetrics does so far for returning the // Simulate the rounding that FontMetrics does so far for returning the
// integer Height() // integer Height()
...@@ -87,7 +87,7 @@ struct HarfBuzzFontData { ...@@ -87,7 +87,7 @@ struct HarfBuzzFontData {
if (size_per_unit_ != kInvalidFallbackMetricsValue) if (size_per_unit_ != kInvalidFallbackMetricsValue)
return size_per_unit_; return size_per_unit_;
int units_per_em = typeface.getUnitsPerEm(); int units_per_em = typeface.getUnitsPerEm();
size_per_unit_ = paint_.getTextSize() / units_per_em; size_per_unit_ = font_.getSize() / units_per_em;
return size_per_unit_; return size_per_unit_;
} }
...@@ -98,14 +98,14 @@ struct HarfBuzzFontData { ...@@ -98,14 +98,14 @@ struct HarfBuzzFontData {
DCHECK_NE(size_per_unit_, kInvalidFallbackMetricsValue); DCHECK_NE(size_per_unit_, kInvalidFallbackMetricsValue);
vertical_data_ = vertical_data_ =
OpenTypeVerticalData::CreateUnscaled(paint_.refTypeface()); OpenTypeVerticalData::CreateUnscaled(font_.refTypeface());
} }
vertical_data_->SetScaleAndFallbackMetrics(size_per_unit_, ascent_fallback_, vertical_data_->SetScaleAndFallbackMetrics(size_per_unit_, ascent_fallback_,
height_fallback_); height_fallback_);
return vertical_data_; return vertical_data_;
} }
SkPaint paint_; SkFont font_;
// Capture these scaled fallback metrics from FontPlatformData so that a // Capture these scaled fallback metrics from FontPlatformData so that a
// OpenTypeVerticalData object can be constructed from them when needed. // OpenTypeVerticalData object can be constructed from them when needed.
......
...@@ -79,17 +79,16 @@ void SimpleFontData::PlatformInit(bool subpixel_ascent_descent) { ...@@ -79,17 +79,16 @@ void SimpleFontData::PlatformInit(bool subpixel_ascent_descent) {
SkFontMetrics metrics; SkFontMetrics metrics;
paint_ = SkPaint(); font_ = SkFont();
platform_data_.SetupSkPaint(&paint_); platform_data_.SetupSkFont(&font_);
paint_.setTextEncoding(SkPaint::kGlyphID_TextEncoding); font_.getMetrics(&metrics);
paint_.getFontMetrics(&metrics);
float ascent; float ascent;
float descent; float descent;
FontMetrics::AscentDescentWithHacks( FontMetrics::AscentDescentWithHacks(
ascent, descent, visual_overflow_inflation_for_ascent_, ascent, descent, visual_overflow_inflation_for_ascent_,
visual_overflow_inflation_for_descent_, platform_data_, paint_, visual_overflow_inflation_for_descent_, platform_data_, font_,
subpixel_ascent_descent); subpixel_ascent_descent);
font_metrics_.SetAscent(ascent); font_metrics_.SetAscent(ascent);
...@@ -161,7 +160,7 @@ void SimpleFontData::PlatformInit(bool subpixel_ascent_descent) { ...@@ -161,7 +160,7 @@ void SimpleFontData::PlatformInit(bool subpixel_ascent_descent) {
} }
#endif #endif
SkTypeface* face = paint_.getTypeface(); SkTypeface* face = font_.getTypeface();
DCHECK(face); DCHECK(face);
if (int units_per_em = face->getUnitsPerEm()) if (int units_per_em = face->getUnitsPerEm())
font_metrics_.SetUnitsPerEm(units_per_em); font_metrics_.SetUnitsPerEm(units_per_em);
...@@ -349,7 +348,7 @@ FloatRect SimpleFontData::PlatformBoundsForGlyph(Glyph glyph) const { ...@@ -349,7 +348,7 @@ FloatRect SimpleFontData::PlatformBoundsForGlyph(Glyph glyph) const {
static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated.");
SkRect bounds; SkRect bounds;
SkiaTextMetrics(&paint_).GetSkiaBoundsForGlyph(glyph, &bounds); SkiaTextMetrics(font_).GetSkiaBoundsForGlyph(glyph, &bounds);
return FloatRect(bounds); return FloatRect(bounds);
} }
...@@ -361,7 +360,7 @@ void SimpleFontData::BoundsForGlyphs(const Vector<Glyph, 256>& glyphs, ...@@ -361,7 +360,7 @@ void SimpleFontData::BoundsForGlyphs(const Vector<Glyph, 256>& glyphs,
return; return;
DCHECK_EQ(bounds->size(), glyphs.size()); DCHECK_EQ(bounds->size(), glyphs.size());
SkiaTextMetrics(&paint_).GetSkiaBoundsForGlyphs(glyphs, bounds->data()); SkiaTextMetrics(font_).GetSkiaBoundsForGlyphs(glyphs, bounds->data());
} }
float SimpleFontData::PlatformWidthForGlyph(Glyph glyph) const { float SimpleFontData::PlatformWidthForGlyph(Glyph glyph) const {
...@@ -370,7 +369,7 @@ float SimpleFontData::PlatformWidthForGlyph(Glyph glyph) const { ...@@ -370,7 +369,7 @@ float SimpleFontData::PlatformWidthForGlyph(Glyph glyph) const {
static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated.");
return SkiaTextMetrics(&paint_).GetSkiaWidthForGlyph(glyph); return SkiaTextMetrics(font_).GetSkiaWidthForGlyph(glyph);
} }
} // namespace blink } // namespace blink
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_SIMPLE_FONT_DATA_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_SIMPLE_FONT_DATA_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_SIMPLE_FONT_DATA_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_SIMPLE_FONT_DATA_H_
#include <SkPaint.h> #include <SkFont.h>
#include <memory> #include <memory>
#include <utility> #include <utility>
...@@ -170,7 +170,7 @@ class PLATFORM_EXPORT SimpleFontData : public FontData { ...@@ -170,7 +170,7 @@ class PLATFORM_EXPORT SimpleFontData : public FontData {
float avg_char_width_; float avg_char_width_;
FontPlatformData platform_data_; FontPlatformData platform_data_;
SkPaint paint_; SkFont font_;
Glyph space_glyph_; Glyph space_glyph_;
float space_width_; float space_width_;
......
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