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