change MakeRecAndEffects to take SkFont

Bug: skia:
Change-Id: I35be940a27e917b18f698addeb8827cb0216f067
Reviewed-on: https://skia-review.googlesource.com/c/168277
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2018-11-06 08:03:42 -05:00 committed by Skia Commit-Bot
parent 7a305a2ef7
commit 4529cb56e0
6 changed files with 54 additions and 31 deletions

View File

@ -434,6 +434,7 @@ private:
};
static SkFontStyle FromOldStyle(Style oldStyle);
static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal);
friend class SkFontPriv; // GetDefaultTypeface
friend class SkPaintPriv; // GetDefaultTypeface
private:

View File

@ -60,10 +60,11 @@ static const SkDescriptor* create_descriptor(
DescriptorType type, const SkPaint& paint, const SkMatrix& m,
const SkSurfaceProps& props, SkScalerContextFlags flags,
SkAutoDescriptor* ad, SkScalerContextEffects* effects) {
SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
SkScalerContextRec deviceRec;
bool enableTypefaceFiltering = (type == kDevice);
SkScalerContext::MakeRecAndEffects(
paint, &props, &m, flags, &deviceRec, effects, enableTypefaceFiltering);
font, paint, &props, &m, flags, &deviceRec, effects, enableTypefaceFiltering);
return SkScalerContext::AutoDescriptorGivenRecAndEffects(deviceRec, *effects, ad);
}

View File

@ -14,6 +14,7 @@
#include "SkColorData.h"
#include "SkDescriptor.h"
#include "SkDraw.h"
#include "SkFontPriv.h"
#include "SkGlyph.h"
#include "SkMakeUnique.h"
#include "SkMaskFilter.h"
@ -889,9 +890,9 @@ static bool too_big_for_lcd(const SkScalerContextRec& rec, bool checkPost2x2) {
// if linear-text is on, then we force hinting to be off (since that's sort of
// the point of linear-text.
static SkFontHinting computeHinting(const SkPaint& paint) {
SkFontHinting h = (SkFontHinting)paint.getHinting();
if (paint.isLinearText()) {
static SkFontHinting computeHinting(const SkFont& font) {
SkFontHinting h = (SkFontHinting)font.getHinting();
if (font.isLinearMetrics()) {
h = kNo_SkFontHinting;
}
return h;
@ -899,7 +900,8 @@ static SkFontHinting computeHinting(const SkPaint& paint) {
// The only reason this is not file static is because it needs the context of SkScalerContext to
// access SkPaint::computeLuminanceColor.
void SkScalerContext::MakeRecAndEffects(const SkPaint& paint,
void SkScalerContext::MakeRecAndEffects(const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps* surfaceProps,
const SkMatrix* deviceMatrix,
SkScalerContextFlags scalerContextFlags,
@ -910,12 +912,12 @@ void SkScalerContext::MakeRecAndEffects(const SkPaint& paint,
sk_bzero(rec, sizeof(SkScalerContextRec));
SkTypeface* typeface = SkPaintPriv::GetTypefaceOrDefault(paint);
SkTypeface* typeface = SkFontPriv::GetTypefaceOrDefault(font);
rec->fFontID = typeface->uniqueID();
rec->fTextSize = paint.getTextSize();
rec->fPreScaleX = paint.getTextScaleX();
rec->fPreSkewX = paint.getTextSkewX();
rec->fTextSize = font.getSize();
rec->fPreScaleX = font.getScaleX();
rec->fPreSkewX = font.getSkewX();
bool checkPost2x2 = false;
@ -945,15 +947,15 @@ void SkScalerContext::MakeRecAndEffects(const SkPaint& paint,
unsigned flags = 0;
if (paint.isFakeBoldText()) {
if (font.isEmbolden()) {
#ifdef SK_USE_FREETYPE_EMBOLDEN
flags |= SkScalerContext::kEmbolden_Flag;
#else
SkScalar fakeBoldScale = SkScalarInterpFunc(paint.getTextSize(),
SkScalar fakeBoldScale = SkScalarInterpFunc(font.getSize(),
kStdFakeBoldInterpKeys,
kStdFakeBoldInterpValues,
kStdFakeBoldInterpLength);
SkScalar extra = paint.getTextSize() * fakeBoldScale;
SkScalar extra = font.getSize() * fakeBoldScale;
if (style == SkPaint::kFill_Style) {
style = SkPaint::kStrokeAndFill_Style;
@ -1013,19 +1015,19 @@ void SkScalerContext::MakeRecAndEffects(const SkPaint& paint,
}
}
if (paint.isEmbeddedBitmapText()) {
if (font.isEmbeddedBitmaps()) {
flags |= SkScalerContext::kEmbeddedBitmapText_Flag;
}
if (paint.isSubpixelText()) {
if (font.isSubpixel()) {
flags |= SkScalerContext::kSubpixelPositioning_Flag;
}
if (paint.isAutohinted()) {
if (font.isForceAutoHinting()) {
flags |= SkScalerContext::kForceAutohinting_Flag;
}
rec->fFlags = SkToU16(flags);
// these modify fFlags, so do them after assigning fFlags
rec->setHinting(computeHinting(paint));
rec->setHinting(computeHinting(font));
rec->setLuminanceColor(paint.computeLuminanceColor());
@ -1116,8 +1118,9 @@ SkDescriptor* SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
const SkMatrix* deviceMatrix, SkAutoDescriptor* ad,
SkScalerContextEffects* effects) {
SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
SkScalerContextRec rec;
MakeRecAndEffects(paint, surfaceProps, deviceMatrix, scalerContextFlags, &rec, effects);
MakeRecAndEffects(font, paint, surfaceProps, deviceMatrix, scalerContextFlags, &rec, effects);
return AutoDescriptorGivenRecAndEffects(rec, *effects, ad);
}

View File

@ -10,6 +10,7 @@
#include <memory>
#include "SkFont.h"
#include "SkFontTypes.h"
#include "SkGlyph.h"
#include "SkMacros.h"
@ -310,7 +311,8 @@ public:
static bool GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma,
uint8_t* data);
static void MakeRecAndEffects(const SkPaint& paint,
static void MakeRecAndEffects(const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps* surfaceProps,
const SkMatrix* deviceMatrix,
SkScalerContextFlags scalerContextFlags,
@ -318,6 +320,18 @@ public:
SkScalerContextEffects* effects,
bool enableTypefaceFiltering = true);
static void MakeRecAndEffectsUsingDefaultPaint(const SkFont& font,
const SkSurfaceProps* surfaceProps,
const SkMatrix* deviceMatrix,
SkScalerContextFlags scalerContextFlags,
SkScalerContextRec* rec,
SkScalerContextEffects* effects,
bool enableTypefaceFiltering = true) {
SkPaint paint;
return MakeRecAndEffects(font, paint, surfaceProps, deviceMatrix, scalerContextFlags,
rec, effects, enableTypefaceFiltering);
}
static SkDescriptor* MakeDescriptorForPaths(SkFontID fontID,
SkAutoDescriptor* ad);

View File

@ -393,16 +393,18 @@ bool SkTypeface::onComputeBounds(SkRect* bounds) const {
const SkScalar textSize = 2048;
const SkScalar invTextSize = 1 / textSize;
SkPaint paint;
paint.setTypeface(sk_ref_sp(const_cast<SkTypeface*>(this)));
paint.setTextSize(textSize);
paint.setLinearText(true);
SkFont font;
font.setTypeface(sk_ref_sp(const_cast<SkTypeface*>(this)));
font.setSize(textSize);
font.setLinearMetrics(true);
SkScalerContextRec rec;
SkScalerContextEffects effects;
SkScalerContext::MakeRecAndEffects(
paint, nullptr, nullptr, SkScalerContextFlags::kNone, &rec, &effects);
const SkSurfaceProps* defaultProps = nullptr;
const SkMatrix* noDeviceMatrix = nullptr;
SkScalerContext::MakeRecAndEffectsUsingDefaultPaint(
font, defaultProps, noDeviceMatrix, SkScalerContextFlags::kNone, &rec, &effects);
SkAutoDescriptor ad;
SkScalerContextEffects noeffects;

View File

@ -630,9 +630,10 @@ DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) {
auto clientTf = client.deserializeTypeface(tfData->data(), tfData->size());
REPORTER_ASSERT(reporter, clientTf);
SkFont font;
font.setTypeface(clientTf);
SkPaint paint;
paint.setAntiAlias(true);
paint.setTypeface(clientTf);
paint.setColor(SK_ColorRED);
auto lostGlyphID = SkPackedGlyphID(1, SK_FixedHalf, SK_FixedHalf);
@ -646,7 +647,7 @@ DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) {
SkScalerContextRec rec;
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
@ -664,7 +665,7 @@ DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) {
SkScalerContextRec rec;
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto testCache = strikeCache.findStrikeExclusive(*desc);
REPORTER_ASSERT(reporter, !(testCache == nullptr));
@ -676,7 +677,7 @@ DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) {
SkScalerContextRec rec;
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kNone;
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
testCache = strikeCache.findStrikeExclusive(*desc);
REPORTER_ASSERT(reporter, testCache == nullptr);
@ -734,6 +735,7 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
auto clientTf = client.deserializeTypeface(tfData->data(), tfData->size());
REPORTER_ASSERT(reporter, clientTf);
SkFont font;
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorRED);
@ -751,7 +753,7 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
paint.setTypeface(serverTf);
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto context = serverTf->createScalerContext(effects, desc, false);
@ -769,7 +771,7 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
paint.setTypeface(clientTf);
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
@ -806,7 +808,7 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
paint.setTypeface(clientTf);
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto fallbackCache = strikeCache.findStrikeExclusive(*desc);