Commit 21a590ea authored by Mike Reed's avatar Mike Reed

export SkFont from PaintFlags

Bug: skia:2664
Change-Id: Icf69c8361ae1ff939d95ba3ac74d080ea9027525
Reviewed-on: https://chromium-review.googlesource.com/c/1343658Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarFlorin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610110}
parent 09c8db6e
...@@ -151,6 +151,23 @@ SkPaint PaintFlags::ToSkPaint() const { ...@@ -151,6 +151,23 @@ SkPaint PaintFlags::ToSkPaint() const {
return paint; return paint;
} }
SkFont PaintFlags::ToSkFont() const {
SkFont font;
font.setTypeface(typeface_);
font.setSize(text_size_);
font.setHinting(static_cast<SkFontHinting>(getHinting()));
font.setForceAutoHinting(isAutohinted());
font.setSubpixel(isSubpixelText());
if (isAntiAlias()) {
if (isLCDRenderText()) {
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
} else {
font.setEdging(SkFont::Edging::kAntiAlias);
}
}
return font;
}
bool PaintFlags::IsValid() const { bool PaintFlags::IsValid() const {
return PaintOp::IsValidPaintFlagsSkBlendMode(getBlendMode()); return PaintOp::IsValidPaintFlagsSkBlendMode(getBlendMode());
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColorFilter.h" #include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkDrawLooper.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkFontTypes.h" #include "third_party/skia/include/core/SkFontTypes.h"
#include "third_party/skia/include/core/SkImageFilter.h" #include "third_party/skia/include/core/SkImageFilter.h"
#include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/core/SkMaskFilter.h"
...@@ -19,8 +20,6 @@ ...@@ -19,8 +20,6 @@
#include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/core/SkTypeface.h"
class SkPaint;
namespace cc { namespace cc {
class PaintFilter; class PaintFilter;
...@@ -210,6 +209,7 @@ class CC_PAINT_EXPORT PaintFlags { ...@@ -210,6 +209,7 @@ class CC_PAINT_EXPORT PaintFlags {
bool SupportsFoldingAlpha() const; bool SupportsFoldingAlpha() const;
SkPaint ToSkPaint() const; SkPaint ToSkPaint() const;
SkFont ToSkFont() const;
bool IsValid() const; bool IsValid() const;
bool operator==(const PaintFlags& other) const; bool operator==(const PaintFlags& other) const;
......
...@@ -65,16 +65,15 @@ void GetGlyphWidthAndExtents(cc::PaintFlags* flags, ...@@ -65,16 +65,15 @@ void GetGlyphWidthAndExtents(cc::PaintFlags* flags,
hb_codepoint_t codepoint, hb_codepoint_t codepoint,
hb_position_t* width, hb_position_t* width,
hb_glyph_extents_t* extents) { hb_glyph_extents_t* extents) {
SkPaint paint = flags->ToSkPaint(); SkFont font = flags->ToSkFont();
DCHECK_LE(codepoint, std::numeric_limits<uint16_t>::max()); DCHECK_LE(codepoint, std::numeric_limits<uint16_t>::max());
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
SkScalar sk_width; SkScalar sk_width;
SkRect sk_bounds; SkRect sk_bounds;
uint16_t glyph = static_cast<uint16_t>(codepoint); uint16_t glyph = static_cast<uint16_t>(codepoint);
paint.getTextWidths(&glyph, sizeof(glyph), &sk_width, &sk_bounds); font.getWidths(&glyph, 1, &sk_width, &sk_bounds);
if (width) if (width)
*width = SkiaScalarToHarfBuzzUnits(sk_width); *width = SkiaScalarToHarfBuzzUnits(sk_width);
if (extents) { if (extents) {
...@@ -100,9 +99,8 @@ hb_bool_t GetGlyph(hb_font_t* font, ...@@ -100,9 +99,8 @@ hb_bool_t GetGlyph(hb_font_t* font,
bool exists = cache->count(unicode) != 0; bool exists = cache->count(unicode) != 0;
if (!exists) { if (!exists) {
font_data->flags_.setTextEncoding(cc::PaintFlags::kUTF32_TextEncoding); (*cache)[unicode] =
SkPaint paint = font_data->flags_.ToSkPaint(); font_data->flags_.getTypeface()->unicharToGlyph(unicode);
paint.textToGlyphs(&unicode, sizeof(hb_codepoint_t), &(*cache)[unicode]);
} }
*glyph = (*cache)[unicode]; *glyph = (*cache)[unicode];
return !!*glyph; return !!*glyph;
......
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