Remove internal use of SkTypeface::Style.

Change-Id: I71cf04b12be95a54b7fb47d048ba1f8672ed9a8f
Reviewed-on: https://skia-review.googlesource.com/27760
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Ben Wagner 2017-07-27 10:45:29 -04:00 committed by Skia Commit-Bot
parent 23890a9ac8
commit 713195071d
24 changed files with 120 additions and 108 deletions

View File

@ -56,8 +56,7 @@ protected:
SkPaint paint; SkPaint paint;
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setSubpixelText(true); paint.setSubpixelText(true);
paint.setTypeface(sk_tool_utils::create_portable_typeface( paint.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()));
"serif", SkFontStyle::FromOldStyle(SkTypeface::kItalic)));
for (int work = 0; work < loops; work++) { for (int work = 0; work < loops; work++) {
do_font_stuff(&paint); do_font_stuff(&paint);
@ -89,10 +88,8 @@ protected:
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit(); size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
SkGraphics::SetFontCacheLimit(fCacheSize); SkGraphics::SetFontCacheLimit(fCacheSize);
sk_sp<SkTypeface> typefaces[] = sk_sp<SkTypeface> typefaces[] =
{sk_tool_utils::create_portable_typeface("serif", {sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()),
SkFontStyle::FromOldStyle(SkTypeface::kItalic)), sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Italic())};
sk_tool_utils::create_portable_typeface("sans-serif",
SkFontStyle::FromOldStyle(SkTypeface::kItalic))};
for (int work = 0; work < loops; work++) { for (int work = 0; work < loops; work++) {
SkTaskGroup().batch(16, [&](int threadIndex) { SkTaskGroup().batch(16, [&](int threadIndex) {

View File

@ -81,7 +81,7 @@ static void color_wheel_native(SkCanvas* canvas) {
const SkScalar D = 0.3f * SkIntToScalar(SCALE); const SkScalar D = 0.3f * SkIntToScalar(SCALE);
const SkScalar X = SkDoubleToScalar(D * sqrt_3_over_2); const SkScalar X = SkDoubleToScalar(D * sqrt_3_over_2);
const SkScalar Y = D * SK_ScalarHalf; const SkScalar Y = D * SK_ScalarHalf;
sk_tool_utils::set_portable_typeface(&p, nullptr, SkFontStyle::FromOldStyle(SkTypeface::kBold)); sk_tool_utils::set_portable_typeface(&p, nullptr, SkFontStyle::Bold());
p.setTextSize(0.28125f * SCALE); p.setTextSize(0.28125f * SCALE);
draw_center_letter('K', &p, SK_ColorBLACK, Z, Z, canvas); draw_center_letter('K', &p, SK_ColorBLACK, Z, Z, canvas);
draw_center_letter('R', &p, SK_ColorRED, Z, D, canvas); draw_center_letter('R', &p, SK_ColorRED, Z, D, canvas);

View File

@ -35,7 +35,7 @@ protected:
0, &local)); 0, &local));
sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif", sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif",
SkFontStyle::FromOldStyle(SkTypeface::kBold))); SkFontStyle::Bold()));
if (nullptr == orig) { if (nullptr == orig) {
orig = SkTypeface::MakeDefault(); orig = SkTypeface::MakeDefault();
} }

View File

@ -40,8 +40,7 @@ DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) { DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) {
SkPaint paint; SkPaint paint;
sk_tool_utils::set_portable_typeface(&paint, "sans-serif", sk_tool_utils::set_portable_typeface(&paint, "sans-serif", SkFontStyle::Bold());
SkFontStyle::FromOldStyle(SkTypeface::kBold));
paint.setTextSize(18.0f); paint.setTextSize(18.0f);
canvas->clear(sk_tool_utils::color_to_565(SK_ColorLTGRAY)); canvas->clear(sk_tool_utils::color_to_565(SK_ColorLTGRAY));

View File

@ -128,11 +128,11 @@ class DownsampleBitmapTextGM: public DownsampleBitmapGM {
setTypeface(&paint, "serif", SkFontStyle()); setTypeface(&paint, "serif", SkFontStyle());
canvas.drawString("Hamburgefons", fTextSize/2, 1.2f*fTextSize, paint); canvas.drawString("Hamburgefons", fTextSize/2, 1.2f*fTextSize, paint);
setTypeface(&paint, "serif", SkFontStyle::FromOldStyle(SkTypeface::kBold)); setTypeface(&paint, "serif", SkFontStyle::Bold());
canvas.drawString("Hamburgefons", fTextSize/2, 2.4f*fTextSize, paint); canvas.drawString("Hamburgefons", fTextSize/2, 2.4f*fTextSize, paint);
setTypeface(&paint, "serif", SkFontStyle::FromOldStyle(SkTypeface::kItalic)); setTypeface(&paint, "serif", SkFontStyle::Italic());
canvas.drawString("Hamburgefons", fTextSize/2, 3.6f*fTextSize, paint); canvas.drawString("Hamburgefons", fTextSize/2, 3.6f*fTextSize, paint);
setTypeface(&paint, "serif", SkFontStyle::FromOldStyle(SkTypeface::kBoldItalic)); setTypeface(&paint, "serif", SkFontStyle::BoldItalic());
canvas.drawString("Hamburgefons", fTextSize/2, 4.8f*fTextSize, paint); canvas.drawString("Hamburgefons", fTextSize/2, 4.8f*fTextSize, paint);
} }
private: private:

View File

@ -124,13 +124,13 @@ class FilterBitmapTextGM: public FilterBitmapGM {
paint.setSubpixelText(true); paint.setSubpixelText(true);
paint.setTextSize(fTextSize); paint.setTextSize(fTextSize);
setTypeface(&paint, "serif", SkFontStyle()); setTypeface(&paint, "serif", SkFontStyle::Normal());
canvas.drawString("Hamburgefons", fTextSize/2, 1.2f*fTextSize, paint); canvas.drawString("Hamburgefons", fTextSize/2, 1.2f*fTextSize, paint);
setTypeface(&paint, "serif", SkFontStyle::FromOldStyle(SkTypeface::kBold)); setTypeface(&paint, "serif", SkFontStyle::Bold());
canvas.drawString("Hamburgefons", fTextSize/2, 2.4f*fTextSize, paint); canvas.drawString("Hamburgefons", fTextSize/2, 2.4f*fTextSize, paint);
setTypeface(&paint, "serif", SkFontStyle::FromOldStyle(SkTypeface::kItalic)); setTypeface(&paint, "serif", SkFontStyle::Italic());
canvas.drawString("Hamburgefons", fTextSize/2, 3.6f*fTextSize, paint); canvas.drawString("Hamburgefons", fTextSize/2, 3.6f*fTextSize, paint);
setTypeface(&paint, "serif", SkFontStyle::FromOldStyle(SkTypeface::kBoldItalic)); setTypeface(&paint, "serif", SkFontStyle::BoldItalic());
canvas.drawString("Hamburgefons", fTextSize/2, 4.8f*fTextSize, paint); canvas.drawString("Hamburgefons", fTextSize/2, 4.8f*fTextSize, paint);
} }
private: private:

View File

@ -33,10 +33,8 @@ protected:
} }
void onOnceBeforeDraw() override { void onOnceBeforeDraw() override {
fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif", fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic());
SkFontStyle::FromOldStyle(SkTypeface::kItalic)); fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",SkFontStyle::Italic());
fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",
SkFontStyle::FromOldStyle(SkTypeface::kItalic));
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {

View File

@ -105,8 +105,7 @@ static sk_sp<SkShader> make_gradient(SkColor c) {
} }
static void set_face(SkPaint* paint) { static void set_face(SkPaint* paint) {
paint->setTypeface(SkTypeface::MakeFromName("serif", paint->setTypeface(SkTypeface::MakeFromName("serif", SkFontStyle::Italic()));
SkFontStyle::FromOldStyle(SkTypeface::kItalic)));
} }
static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& shader) { static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& shader) {

View File

@ -140,8 +140,7 @@ protected:
constexpr SkScalar LABEL_SIZE = 10.0f; constexpr SkScalar LABEL_SIZE = 10.0f;
SkPaint labelPaint; SkPaint labelPaint;
labelPaint.setTypeface(sk_tool_utils::create_portable_typeface("sans-serif", labelPaint.setTypeface(sk_tool_utils::create_portable_typeface("sans-serif",SkFontStyle()));
SkFontStyle()));
labelPaint.setAntiAlias(true); labelPaint.setAntiAlias(true);
labelPaint.setTextSize(LABEL_SIZE); labelPaint.setTextSize(LABEL_SIZE);

View File

@ -41,7 +41,7 @@ protected:
// Setup our random scaler context // Setup our random scaler context
sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface( sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface(
"sans-serif", SkFontStyle::FromOldStyle(SkTypeface::kBold))); "sans-serif", SkFontStyle::Bold()));
if (nullptr == orig) { if (nullptr == orig) {
orig = SkTypeface::MakeDefault(); orig = SkTypeface::MakeDefault();
} }

View File

@ -9,6 +9,7 @@
#include "sk_tool_utils.h" #include "sk_tool_utils.h"
#include "Resources.h" #include "Resources.h"
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkFontStyle.h"
#include "SkString.h" #include "SkString.h"
#include "SkSurfaceProps.h" #include "SkSurfaceProps.h"
#include "SkTypeface.h" #include "SkTypeface.h"
@ -74,20 +75,20 @@ static void drawKernText(SkCanvas* canvas, const void* text, size_t len,
constexpr struct { constexpr struct {
const char* fName; const char* fName;
SkTypeface::Style fStyle; SkFontStyle fStyle;
} gFaceStyles[] = { } gFaceStyles[] = {
{ "sans-serif", SkTypeface::kNormal }, { "sans-serif", SkFontStyle::Normal() },
{ "sans-serif", SkTypeface::kBold }, { "sans-serif", SkFontStyle::Bold() },
{ "sans-serif", SkTypeface::kItalic }, { "sans-serif", SkFontStyle::Italic() },
{ "sans-serif", SkTypeface::kBoldItalic }, { "sans-serif", SkFontStyle::BoldItalic() },
{ "serif", SkTypeface::kNormal }, { "serif", SkFontStyle::Normal() },
{ "serif", SkTypeface::kBold }, { "serif", SkFontStyle::Bold() },
{ "serif", SkTypeface::kItalic }, { "serif", SkFontStyle::Italic() },
{ "serif", SkTypeface::kBoldItalic }, { "serif", SkFontStyle::BoldItalic() },
{ "monospace", SkTypeface::kNormal }, { "monospace", SkFontStyle::Normal() },
{ "monospace", SkTypeface::kBold }, { "monospace", SkFontStyle::Bold() },
{ "monospace", SkTypeface::kItalic }, { "monospace", SkFontStyle::Italic() },
{ "monospace", SkTypeface::kBoldItalic }, { "monospace", SkFontStyle::BoldItalic() },
}; };
constexpr int gFaceStylesCount = SK_ARRAY_COUNT(gFaceStyles); constexpr int gFaceStylesCount = SK_ARRAY_COUNT(gFaceStyles);
@ -106,8 +107,7 @@ protected:
void onOnceBeforeDraw() override { void onOnceBeforeDraw() override {
for (int i = 0; i < gFaceStylesCount; i++) { for (int i = 0; i < gFaceStylesCount; i++) {
fFaces[i] = SkTypeface::MakeFromName( fFaces[i] = SkTypeface::MakeFromName(
sk_tool_utils::platform_font_name( sk_tool_utils::platform_font_name(gFaceStyles[i].fName), gFaceStyles[i].fStyle);
gFaceStyles[i].fName), SkFontStyle::FromOldStyle(gFaceStyles[i].fStyle));
} }
} }

View File

@ -54,11 +54,9 @@ protected:
static_assert(4 == SK_ARRAY_COUNT(fTypefaces), "typeface_cnt"); static_assert(4 == SK_ARRAY_COUNT(fTypefaces), "typeface_cnt");
fTypefaces[0] = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle()); fTypefaces[0] = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle());
fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif", fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Bold());
SkFontStyle::FromOldStyle(SkTypeface::kBold));
fTypefaces[2] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle()); fTypefaces[2] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle());
fTypefaces[3] = sk_tool_utils::create_portable_typeface("serif", fTypefaces[3] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Bold());
SkFontStyle::FromOldStyle(SkTypeface::kBold));
SkRandom random; SkRandom random;
for (int i = 0; i < kCnt; ++i) { for (int i = 0; i < kCnt; ++i) {

View File

@ -28,20 +28,20 @@ constexpr size_t gLen = sizeof(gText) - sizeof(gText[0]);
class VertTextGM : public GM { class VertTextGM : public GM {
public: public:
VertTextGM() VertTextGM()
// : fFace(SkTypeface::CreateFromName("unifont", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("unifont", SkFontStyle::Normal()))
// : fFace(SkTypeface::CreateFromFile("MotoyaL04Mincho_3.ttf")) // : fFace(SkTypeface::MakeFromFile("MotoyaL04Mincho_3.ttf"))
// Bitmap fonts on OS X. // Bitmap fonts on OS X.
// : fFace(SkTypeface::CreateFromName("GB18030 Bitmap", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("GB18030 Bitmap", SkFontStyle::Normal()))
// : fFace(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("Apple Color Emoji", SkFontStyle::Normal()))
// OTF CFF fonts on OS X. // OTF CFF fonts on OS X.
// : fFace(SkTypeface::CreateFromName("Hiragino Mincho ProN", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("Hiragino Mincho ProN", SkFontStyle::Normal()))
// : fFace(SkTypeface::CreateFromName("Hiragino Kaku Gothic Pro", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("Hiragino Kaku Gothic Pro", SkFontStyle::Normal()))
// : fFace(SkTypeface::CreateFromName("Hiragino Sans GB", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("Hiragino Sans GB", SkFontStyle::Normal()))
// : fFace(SkTypeface::CreateFromName("STIXGeneral", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("STIXGeneral", SkFontStyle::Normal()))
// : fFace(SkTypeface::CreateFromName("Yuppy SC", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("Yuppy SC", SkFontStyle::Normal()))
// : fFace(SkTypeface::CreateFromName("Yuppy TC", SkTypeface::kNormal)) // : fFace(SkTypeface::MakeFromName("Yuppy TC", SkFontStyle::Normal()))
{ {
} }

View File

@ -45,7 +45,12 @@ public:
}; };
SkFontStyle(); SkFontStyle();
SkFontStyle(int weight, int width, Slant);
constexpr SkFontStyle(int weight, int width, Slant slant) : fUnion {{
static_cast<uint16_t>(SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)),
static_cast<uint8_t >(SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width)),
static_cast<uint8_t >(SkTPin<int>(slant, kUpright_Slant, kOblique_Slant))
}} { }
static SkFontStyle FromOldStyle(unsigned oldStyle); static SkFontStyle FromOldStyle(unsigned oldStyle);
@ -57,6 +62,19 @@ public:
int width() const { return fUnion.fR.fWidth; } int width() const { return fUnion.fR.fWidth; }
Slant slant() const { return (Slant)fUnion.fR.fSlant; } Slant slant() const { return (Slant)fUnion.fR.fSlant; }
static constexpr SkFontStyle Normal() {
return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
}
static constexpr SkFontStyle Bold() {
return SkFontStyle(kBold_Weight, kNormal_Width, kUpright_Slant);
}
static constexpr SkFontStyle Italic() {
return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
}
static constexpr SkFontStyle BoldItalic() {
return SkFontStyle(kBold_Weight, kNormal_Width, kItalic_Slant );
}
private: private:
union { union {
struct { struct {

View File

@ -187,8 +187,7 @@ protected:
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(240)); paint.setTextSize(SkIntToScalar(240));
paint.setTypeface(SkTypeface::MakeFromName("sans-serif", paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkFontStyle::Bold()));
SkFontStyle::FromOldStyle(SkTypeface::kBold)));
SkString str("9"); SkString str("9");

View File

@ -487,8 +487,7 @@ protected:
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(48)); paint.setTextSize(SkIntToScalar(48));
paint.setTypeface(SkTypeface::MakeFromName("sans-serif", paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkFontStyle::Bold()));
SkFontStyle::FromOldStyle(SkTypeface::kBold)));
SkString str("GOOGLE"); SkString str("GOOGLE");

View File

@ -5,32 +5,33 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "SampleCode.h" #include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "SkTypeface.h"
#include "SkPath.h"
#include "SkRegion.h"
#include "SkShader.h"
#include "SkUtils.h"
#include "Sk1DPathEffect.h" #include "Sk1DPathEffect.h"
#include "SkCanvas.h"
#include "SkColorFilter.h"
#include "SkColorPriv.h"
#include "SkCornerPathEffect.h" #include "SkCornerPathEffect.h"
#include "SkDither.h"
#include "SkFontStyle.h"
#include "SkPath.h"
#include "SkPathMeasure.h" #include "SkPathMeasure.h"
#include "SkRandom.h" #include "SkRandom.h"
#include "SkColorPriv.h" #include "SkRegion.h"
#include "SkColorFilter.h" #include "SkShader.h"
#include "SkDither.h" #include "SkTypeface.h"
#include "SkUtils.h"
#include "SkView.h"
static const struct { static constexpr struct {
const char* fName; const char* fName;
SkTypeface::Style fStyle; SkFontStyle fStyle;
} gFaces[] = { } gFaces[] = {
{ nullptr, SkTypeface::kNormal }, { nullptr, SkFontStyle::Normal() },
{ nullptr, SkTypeface::kBold }, { nullptr, SkFontStyle::Bold() },
{ "serif", SkTypeface::kNormal }, { "serif", SkFontStyle::Normal() },
{ "serif", SkTypeface::kBold }, { "serif", SkFontStyle::Bold() },
{ "serif", SkTypeface::kItalic }, { "serif", SkFontStyle::Italic() },
{ "serif", SkTypeface::kBoldItalic }, { "serif", SkFontStyle::BoldItalic() },
{ "monospace", SkTypeface::kNormal } { "monospace", SkFontStyle::Normal() }
}; };
static const int gFaceCount = SK_ARRAY_COUNT(gFaces); static const int gFaceCount = SK_ARRAY_COUNT(gFaces);
@ -41,8 +42,7 @@ class FontScalerTestView : public SampleView {
public: public:
FontScalerTestView() { FontScalerTestView() {
for (int i = 0; i < gFaceCount; i++) { for (int i = 0; i < gFaceCount; i++) {
fFaces[i] = SkTypeface::MakeFromName( fFaces[i] = SkTypeface::MakeFromName(gFaces[i].fName, gFaces[i].fStyle);
gFaces[i].fName, SkFontStyle::FromOldStyle(gFaces[i].fStyle));
} }
} }

View File

@ -624,8 +624,7 @@ static void texteffect_slide(SkCanvas* canvas) {
SkScalar x = 20; SkScalar x = 20;
SkScalar y = 80; SkScalar y = 80;
SkPaint paint; SkPaint paint;
paint.setTypeface(SkTypeface::MakeFromName("Georgia", paint.setTypeface(SkTypeface::MakeFromName("Georgia", SkFontStyle::Italic()));
SkFontStyle::FromOldStyle(SkTypeface::kItalic)));
paint.setTextSize(75); paint.setTextSize(75);
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setColor(SK_ColorBLUE); paint.setColor(SK_ColorBLUE);

View File

@ -71,14 +71,14 @@ portable typeface on the paint, call:
~~~~ ~~~~
sk_tool_utils::set_portable_typeface(SkPaint* , const char* name = nullptr, sk_tool_utils::set_portable_typeface(SkPaint* , const char* name = nullptr,
SkTypeface::Style style = SkTypeface::kNormal ); SkFontStyle style = SkFontStyle());
~~~~ ~~~~
To create a portable typeface, use: To create a portable typeface, use:
~~~~ ~~~~
SkTypeface* typeface = sk_tool_utils::create_portable_typeface(const char* name, SkTypeface* typeface = sk_tool_utils::create_portable_typeface(const char* name,
SkTypeface::Style style); SkFontStyle style);
~~~~ ~~~~
Eventually, both 'set_portable_typeface()' and 'create_portable_typeface()' will be Eventually, both 'set_portable_typeface()' and 'create_portable_typeface()' will be

View File

@ -16,13 +16,6 @@ SkFontStyle::SkFontStyle() {
fUnion.fR.fSlant = kUpright_Slant; fUnion.fR.fSlant = kUpright_Slant;
} }
SkFontStyle::SkFontStyle(int weight, int width, Slant slant) {
fUnion.fU32 = 0;
fUnion.fR.fWeight = SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight);
fUnion.fR.fWidth = SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width);
fUnion.fR.fSlant = SkTPin<int>(slant, kUpright_Slant, kOblique_Slant);
}
/*static*/SkFontStyle SkFontStyle::FromOldStyle(unsigned oldStyle) { /*static*/SkFontStyle SkFontStyle::FromOldStyle(unsigned oldStyle) {
return SkFontStyle((oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weight return SkFontStyle((oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weight
: SkFontStyle::kNormal_Weight, : SkFontStyle::kNormal_Weight,

View File

@ -106,6 +106,4 @@ private:
friend class SkTestScalerContext; friend class SkTestScalerContext;
}; };
SkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style);
#endif #endif

View File

@ -546,12 +546,27 @@ void SkSVGDevice::AutoElement::addTextAttributes(const SkPaint& paint) {
sk_sp<SkTypeface> tface(paint.getTypeface() ? paint.refTypeface() : SkTypeface::MakeDefault()); sk_sp<SkTypeface> tface(paint.getTypeface() ? paint.refTypeface() : SkTypeface::MakeDefault());
SkASSERT(tface); SkASSERT(tface);
SkTypeface::Style style = tface->style(); SkFontStyle style = tface->fontStyle();
if (style & SkTypeface::kItalic) { if (style.slant() == SkFontStyle::kItalic_Slant) {
this->addAttribute("font-style", "italic"); this->addAttribute("font-style", "italic");
} else if (style.slant() == SkFontStyle::kOblique_Slant) {
this->addAttribute("font-style", "oblique");
} }
if (style & SkTypeface::kBold) { int weightIndex = (SkTPin(style.weight(), 100, 900) - 50) / 100;
this->addAttribute("font-weight", "bold"); if (weightIndex != 3) {
static constexpr const char* weights[] = {
"100", "200", "300", "normal", "400", "500", "600", "bold", "800", "900"
};
this->addAttribute("font-weight", weights[weightIndex]);
}
int stretchIndex = style.width() - 1;
if (stretchIndex != 4) {
static constexpr const char* stretches[] = {
"ultra-condensed", "extra-condensed", "condensed", "semi-condensed",
"normal",
"semi-expanded", "expanded", "extra-expanded", "ultra-expanded"
};
this->addAttribute("font-stretch", stretches[stretchIndex]);
} }
sk_sp<SkTypeface::LocalizedStrings> familyNameIter(tface->createFamilyNameIterator()); sk_sp<SkTypeface::LocalizedStrings> familyNameIter(tface->createFamilyNameIterator());

View File

@ -848,8 +848,7 @@ static void test_typeface(skiatest::Reporter* reporter) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(10, 10); SkCanvas* canvas = recorder.beginRecording(10, 10);
SkPaint paint; SkPaint paint;
paint.setTypeface(SkTypeface::MakeFromName("Arial", paint.setTypeface(SkTypeface::MakeFromName("Arial", SkFontStyle::Italic()));
SkFontStyle::FromOldStyle(SkTypeface::kItalic)));
canvas->drawString("Q", 0, 10, paint); canvas->drawString("Q", 0, 10, paint);
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream stream; SkDynamicMemoryWStream stream;

View File

@ -9,6 +9,7 @@
// and ./tools/test_font_<generic name>.inc which are read by ./tools/sk_tool_utils_font.cpp // and ./tools/test_font_<generic name>.inc which are read by ./tools/sk_tool_utils_font.cpp
#include "Resources.h" #include "Resources.h"
#include "SkFontStyle.h"
#include "SkOSFile.h" #include "SkOSFile.h"
#include "SkOSPath.h" #include "SkOSPath.h"
#include "SkPaint.h" #include "SkPaint.h"
@ -28,16 +29,17 @@ struct NamedFontStyle {
const char* fName; const char* fName;
SkFontStyle fStyle; SkFontStyle fStyle;
}; };
NamedFontStyle normal = {"Normal", SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant)}; constexpr NamedFontStyle normal = {"Normal", SkFontStyle::Normal() };
NamedFontStyle bold = {"Bold", SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant)}; constexpr NamedFontStyle bold = {"Bold", SkFontStyle::Bold() };
NamedFontStyle italic = {"Italic", SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kItalic_Slant )}; constexpr NamedFontStyle italic = {"Italic", SkFontStyle::Italic() };
NamedFontStyle bolditalic = {"BoldItalic", SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kItalic_Slant )}; constexpr NamedFontStyle bolditalic = {"BoldItalic", SkFontStyle::BoldItalic()};
struct FontDesc { struct FontDesc {
const char* fGenericName; char const * const fGenericName;
NamedFontStyle fNamedStyle; NamedFontStyle const fNamedStyle;
const char* fFontName; char const * const fFontName;
const char* fFile; char const * const fFile;
// fFontIndex is mutable and will be set later.
int fFontIndex; int fFontIndex;
} gFonts[] = { } gFonts[] = {
{"monospace", normal, "Liberation Mono", "LiberationMono-Regular.ttf", -1}, {"monospace", normal, "Liberation Mono", "LiberationMono-Regular.ttf", -1},