aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/SkGlyphCacheBench.cpp9
-rw-r--r--gm/all_bitmap_configs.cpp2
-rw-r--r--gm/coloremoji_blendmodes.cpp2
-rw-r--r--gm/colorwheel.cpp3
-rw-r--r--gm/downsamplebitmap.cpp6
-rw-r--r--gm/filterbitmap.cpp8
-rw-r--r--gm/fontcache.cpp6
-rw-r--r--gm/gammatext.cpp3
-rw-r--r--gm/lightingshader2.cpp3
-rw-r--r--gm/textblobrandomfont.cpp2
-rw-r--r--gm/typeface.cpp30
-rw-r--r--gm/variedtext.cpp6
-rw-r--r--gm/verttext.cpp20
-rw-r--r--include/core/SkFontStyle.h20
-rw-r--r--samplecode/ClockFaceView.cpp3
-rw-r--r--samplecode/SampleAll.cpp3
-rw-r--r--samplecode/SampleFontScalerTest.cpp40
-rw-r--r--samplecode/SampleSlides.cpp3
-rw-r--r--site/dev/testing/fonts.md4
-rw-r--r--src/core/SkFontStyle.cpp7
-rw-r--r--src/fonts/SkTestScalerContext.h2
-rw-r--r--src/svg/SkSVGDevice.cpp25
-rw-r--r--tests/PictureTest.cpp3
-rw-r--r--tools/create_test_font.cpp18
24 files changed, 120 insertions, 108 deletions
diff --git a/bench/SkGlyphCacheBench.cpp b/bench/SkGlyphCacheBench.cpp
index 4d43a611d4..1cc257fd3f 100644
--- a/bench/SkGlyphCacheBench.cpp
+++ b/bench/SkGlyphCacheBench.cpp
@@ -56,8 +56,7 @@ protected:
SkPaint paint;
paint.setAntiAlias(true);
paint.setSubpixelText(true);
- paint.setTypeface(sk_tool_utils::create_portable_typeface(
- "serif", SkFontStyle::FromOldStyle(SkTypeface::kItalic)));
+ paint.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()));
for (int work = 0; work < loops; work++) {
do_font_stuff(&paint);
@@ -89,10 +88,8 @@ protected:
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
SkGraphics::SetFontCacheLimit(fCacheSize);
sk_sp<SkTypeface> typefaces[] =
- {sk_tool_utils::create_portable_typeface("serif",
- SkFontStyle::FromOldStyle(SkTypeface::kItalic)),
- sk_tool_utils::create_portable_typeface("sans-serif",
- SkFontStyle::FromOldStyle(SkTypeface::kItalic))};
+ {sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()),
+ sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Italic())};
for (int work = 0; work < loops; work++) {
SkTaskGroup().batch(16, [&](int threadIndex) {
diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp
index d9735b2d3d..32fb86c9cd 100644
--- a/gm/all_bitmap_configs.cpp
+++ b/gm/all_bitmap_configs.cpp
@@ -81,7 +81,7 @@ static void color_wheel_native(SkCanvas* canvas) {
const SkScalar D = 0.3f * SkIntToScalar(SCALE);
const SkScalar X = SkDoubleToScalar(D * sqrt_3_over_2);
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);
draw_center_letter('K', &p, SK_ColorBLACK, Z, Z, canvas);
draw_center_letter('R', &p, SK_ColorRED, Z, D, canvas);
diff --git a/gm/coloremoji_blendmodes.cpp b/gm/coloremoji_blendmodes.cpp
index ee3db7671d..b93c6b4e45 100644
--- a/gm/coloremoji_blendmodes.cpp
+++ b/gm/coloremoji_blendmodes.cpp
@@ -35,7 +35,7 @@ protected:
0, &local));
sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif",
- SkFontStyle::FromOldStyle(SkTypeface::kBold)));
+ SkFontStyle::Bold()));
if (nullptr == orig) {
orig = SkTypeface::MakeDefault();
}
diff --git a/gm/colorwheel.cpp b/gm/colorwheel.cpp
index b938cd5088..b8a08951f5 100644
--- a/gm/colorwheel.cpp
+++ b/gm/colorwheel.cpp
@@ -40,8 +40,7 @@ DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) {
SkPaint paint;
- sk_tool_utils::set_portable_typeface(&paint, "sans-serif",
- SkFontStyle::FromOldStyle(SkTypeface::kBold));
+ sk_tool_utils::set_portable_typeface(&paint, "sans-serif", SkFontStyle::Bold());
paint.setTextSize(18.0f);
canvas->clear(sk_tool_utils::color_to_565(SK_ColorLTGRAY));
diff --git a/gm/downsamplebitmap.cpp b/gm/downsamplebitmap.cpp
index fefc94bd57..e142bde112 100644
--- a/gm/downsamplebitmap.cpp
+++ b/gm/downsamplebitmap.cpp
@@ -128,11 +128,11 @@ class DownsampleBitmapTextGM: public DownsampleBitmapGM {
setTypeface(&paint, "serif", SkFontStyle());
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);
- setTypeface(&paint, "serif", SkFontStyle::FromOldStyle(SkTypeface::kItalic));
+ setTypeface(&paint, "serif", SkFontStyle::Italic());
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);
}
private:
diff --git a/gm/filterbitmap.cpp b/gm/filterbitmap.cpp
index 92aeddc788..a630662976 100644
--- a/gm/filterbitmap.cpp
+++ b/gm/filterbitmap.cpp
@@ -124,13 +124,13 @@ class FilterBitmapTextGM: public FilterBitmapGM {
paint.setSubpixelText(true);
paint.setTextSize(fTextSize);
- setTypeface(&paint, "serif", SkFontStyle());
+ setTypeface(&paint, "serif", SkFontStyle::Normal());
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);
- setTypeface(&paint, "serif", SkFontStyle::FromOldStyle(SkTypeface::kItalic));
+ setTypeface(&paint, "serif", SkFontStyle::Italic());
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);
}
private:
diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp
index f3f891073c..a8c5b768c3 100644
--- a/gm/fontcache.cpp
+++ b/gm/fontcache.cpp
@@ -33,10 +33,8 @@ protected:
}
void onOnceBeforeDraw() override {
- fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif",
- SkFontStyle::FromOldStyle(SkTypeface::kItalic));
- fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",
- SkFontStyle::FromOldStyle(SkTypeface::kItalic));
+ fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic());
+ fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",SkFontStyle::Italic());
}
void onDraw(SkCanvas* canvas) override {
diff --git a/gm/gammatext.cpp b/gm/gammatext.cpp
index 43b07200ee..f8f2aa6004 100644
--- a/gm/gammatext.cpp
+++ b/gm/gammatext.cpp
@@ -105,8 +105,7 @@ static sk_sp<SkShader> make_gradient(SkColor c) {
}
static void set_face(SkPaint* paint) {
- paint->setTypeface(SkTypeface::MakeFromName("serif",
- SkFontStyle::FromOldStyle(SkTypeface::kItalic)));
+ paint->setTypeface(SkTypeface::MakeFromName("serif", SkFontStyle::Italic()));
}
static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& shader) {
diff --git a/gm/lightingshader2.cpp b/gm/lightingshader2.cpp
index edec063dd1..b0c7beec46 100644
--- a/gm/lightingshader2.cpp
+++ b/gm/lightingshader2.cpp
@@ -140,8 +140,7 @@ protected:
constexpr SkScalar LABEL_SIZE = 10.0f;
SkPaint labelPaint;
- labelPaint.setTypeface(sk_tool_utils::create_portable_typeface("sans-serif",
- SkFontStyle()));
+ labelPaint.setTypeface(sk_tool_utils::create_portable_typeface("sans-serif",SkFontStyle()));
labelPaint.setAntiAlias(true);
labelPaint.setTextSize(LABEL_SIZE);
diff --git a/gm/textblobrandomfont.cpp b/gm/textblobrandomfont.cpp
index e00b299403..8dd77c51f0 100644
--- a/gm/textblobrandomfont.cpp
+++ b/gm/textblobrandomfont.cpp
@@ -41,7 +41,7 @@ protected:
// Setup our random scaler context
sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface(
- "sans-serif", SkFontStyle::FromOldStyle(SkTypeface::kBold)));
+ "sans-serif", SkFontStyle::Bold()));
if (nullptr == orig) {
orig = SkTypeface::MakeDefault();
}
diff --git a/gm/typeface.cpp b/gm/typeface.cpp
index 807b49c883..b0db62b05a 100644
--- a/gm/typeface.cpp
+++ b/gm/typeface.cpp
@@ -9,6 +9,7 @@
#include "sk_tool_utils.h"
#include "Resources.h"
#include "SkCanvas.h"
+#include "SkFontStyle.h"
#include "SkString.h"
#include "SkSurfaceProps.h"
#include "SkTypeface.h"
@@ -74,20 +75,20 @@ static void drawKernText(SkCanvas* canvas, const void* text, size_t len,
constexpr struct {
const char* fName;
- SkTypeface::Style fStyle;
+ SkFontStyle fStyle;
} gFaceStyles[] = {
- { "sans-serif", SkTypeface::kNormal },
- { "sans-serif", SkTypeface::kBold },
- { "sans-serif", SkTypeface::kItalic },
- { "sans-serif", SkTypeface::kBoldItalic },
- { "serif", SkTypeface::kNormal },
- { "serif", SkTypeface::kBold },
- { "serif", SkTypeface::kItalic },
- { "serif", SkTypeface::kBoldItalic },
- { "monospace", SkTypeface::kNormal },
- { "monospace", SkTypeface::kBold },
- { "monospace", SkTypeface::kItalic },
- { "monospace", SkTypeface::kBoldItalic },
+ { "sans-serif", SkFontStyle::Normal() },
+ { "sans-serif", SkFontStyle::Bold() },
+ { "sans-serif", SkFontStyle::Italic() },
+ { "sans-serif", SkFontStyle::BoldItalic() },
+ { "serif", SkFontStyle::Normal() },
+ { "serif", SkFontStyle::Bold() },
+ { "serif", SkFontStyle::Italic() },
+ { "serif", SkFontStyle::BoldItalic() },
+ { "monospace", SkFontStyle::Normal() },
+ { "monospace", SkFontStyle::Bold() },
+ { "monospace", SkFontStyle::Italic() },
+ { "monospace", SkFontStyle::BoldItalic() },
};
constexpr int gFaceStylesCount = SK_ARRAY_COUNT(gFaceStyles);
@@ -106,8 +107,7 @@ protected:
void onOnceBeforeDraw() override {
for (int i = 0; i < gFaceStylesCount; i++) {
fFaces[i] = SkTypeface::MakeFromName(
- sk_tool_utils::platform_font_name(
- gFaceStyles[i].fName), SkFontStyle::FromOldStyle(gFaceStyles[i].fStyle));
+ sk_tool_utils::platform_font_name(gFaceStyles[i].fName), gFaceStyles[i].fStyle);
}
}
diff --git a/gm/variedtext.cpp b/gm/variedtext.cpp
index c0f6cbf8c7..e8e1c29632 100644
--- a/gm/variedtext.cpp
+++ b/gm/variedtext.cpp
@@ -54,11 +54,9 @@ protected:
static_assert(4 == SK_ARRAY_COUNT(fTypefaces), "typeface_cnt");
fTypefaces[0] = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle());
- fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",
- SkFontStyle::FromOldStyle(SkTypeface::kBold));
+ fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Bold());
fTypefaces[2] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle());
- fTypefaces[3] = sk_tool_utils::create_portable_typeface("serif",
- SkFontStyle::FromOldStyle(SkTypeface::kBold));
+ fTypefaces[3] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Bold());
SkRandom random;
for (int i = 0; i < kCnt; ++i) {
diff --git a/gm/verttext.cpp b/gm/verttext.cpp
index 9c9ddb0e11..c729271c05 100644
--- a/gm/verttext.cpp
+++ b/gm/verttext.cpp
@@ -28,20 +28,20 @@ constexpr size_t gLen = sizeof(gText) - sizeof(gText[0]);
class VertTextGM : public GM {
public:
VertTextGM()
- // : fFace(SkTypeface::CreateFromName("unifont", SkTypeface::kNormal))
- // : fFace(SkTypeface::CreateFromFile("MotoyaL04Mincho_3.ttf"))
+ // : fFace(SkTypeface::MakeFromName("unifont", SkFontStyle::Normal()))
+ // : fFace(SkTypeface::MakeFromFile("MotoyaL04Mincho_3.ttf"))
// Bitmap fonts on OS X.
- // : fFace(SkTypeface::CreateFromName("GB18030 Bitmap", SkTypeface::kNormal))
- // : fFace(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal))
+ // : fFace(SkTypeface::MakeFromName("GB18030 Bitmap", SkFontStyle::Normal()))
+ // : fFace(SkTypeface::MakeFromName("Apple Color Emoji", SkFontStyle::Normal()))
// OTF CFF fonts on OS X.
- // : fFace(SkTypeface::CreateFromName("Hiragino Mincho ProN", SkTypeface::kNormal))
- // : fFace(SkTypeface::CreateFromName("Hiragino Kaku Gothic Pro", SkTypeface::kNormal))
- // : fFace(SkTypeface::CreateFromName("Hiragino Sans GB", SkTypeface::kNormal))
- // : fFace(SkTypeface::CreateFromName("STIXGeneral", SkTypeface::kNormal))
- // : fFace(SkTypeface::CreateFromName("Yuppy SC", SkTypeface::kNormal))
- // : fFace(SkTypeface::CreateFromName("Yuppy TC", SkTypeface::kNormal))
+ // : fFace(SkTypeface::MakeFromName("Hiragino Mincho ProN", SkFontStyle::Normal()))
+ // : fFace(SkTypeface::MakeFromName("Hiragino Kaku Gothic Pro", SkFontStyle::Normal()))
+ // : fFace(SkTypeface::MakeFromName("Hiragino Sans GB", SkFontStyle::Normal()))
+ // : fFace(SkTypeface::MakeFromName("STIXGeneral", SkFontStyle::Normal()))
+ // : fFace(SkTypeface::MakeFromName("Yuppy SC", SkFontStyle::Normal()))
+ // : fFace(SkTypeface::MakeFromName("Yuppy TC", SkFontStyle::Normal()))
{
}
diff --git a/include/core/SkFontStyle.h b/include/core/SkFontStyle.h
index 7dd25910a2..306895d78f 100644
--- a/include/core/SkFontStyle.h
+++ b/include/core/SkFontStyle.h
@@ -45,7 +45,12 @@ public:
};
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);
@@ -57,6 +62,19 @@ public:
int width() const { return fUnion.fR.fWidth; }
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:
union {
struct {
diff --git a/samplecode/ClockFaceView.cpp b/samplecode/ClockFaceView.cpp
index f4d2324676..8de2f9339d 100644
--- a/samplecode/ClockFaceView.cpp
+++ b/samplecode/ClockFaceView.cpp
@@ -187,8 +187,7 @@ protected:
paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(240));
- paint.setTypeface(SkTypeface::MakeFromName("sans-serif",
- SkFontStyle::FromOldStyle(SkTypeface::kBold)));
+ paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkFontStyle::Bold()));
SkString str("9");
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp
index f7a5a3a7b1..f3d1083cb1 100644
--- a/samplecode/SampleAll.cpp
+++ b/samplecode/SampleAll.cpp
@@ -487,8 +487,7 @@ protected:
paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(48));
- paint.setTypeface(SkTypeface::MakeFromName("sans-serif",
- SkFontStyle::FromOldStyle(SkTypeface::kBold)));
+ paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkFontStyle::Bold()));
SkString str("GOOGLE");
diff --git a/samplecode/SampleFontScalerTest.cpp b/samplecode/SampleFontScalerTest.cpp
index 2b4a46d00c..b41166d38e 100644
--- a/samplecode/SampleFontScalerTest.cpp
+++ b/samplecode/SampleFontScalerTest.cpp
@@ -5,32 +5,33 @@
* found in the LICENSE file.
*/
#include "SampleCode.h"
-#include "SkView.h"
+#include "Sk1DPathEffect.h"
#include "SkCanvas.h"
-#include "SkTypeface.h"
+#include "SkColorFilter.h"
+#include "SkColorPriv.h"
+#include "SkCornerPathEffect.h"
+#include "SkDither.h"
+#include "SkFontStyle.h"
#include "SkPath.h"
+#include "SkPathMeasure.h"
+#include "SkRandom.h"
#include "SkRegion.h"
#include "SkShader.h"
+#include "SkTypeface.h"
#include "SkUtils.h"
-#include "Sk1DPathEffect.h"
-#include "SkCornerPathEffect.h"
-#include "SkPathMeasure.h"
-#include "SkRandom.h"
-#include "SkColorPriv.h"
-#include "SkColorFilter.h"
-#include "SkDither.h"
+#include "SkView.h"
-static const struct {
+static constexpr struct {
const char* fName;
- SkTypeface::Style fStyle;
+ SkFontStyle fStyle;
} gFaces[] = {
- { nullptr, SkTypeface::kNormal },
- { nullptr, SkTypeface::kBold },
- { "serif", SkTypeface::kNormal },
- { "serif", SkTypeface::kBold },
- { "serif", SkTypeface::kItalic },
- { "serif", SkTypeface::kBoldItalic },
- { "monospace", SkTypeface::kNormal }
+ { nullptr, SkFontStyle::Normal() },
+ { nullptr, SkFontStyle::Bold() },
+ { "serif", SkFontStyle::Normal() },
+ { "serif", SkFontStyle::Bold() },
+ { "serif", SkFontStyle::Italic() },
+ { "serif", SkFontStyle::BoldItalic() },
+ { "monospace", SkFontStyle::Normal() }
};
static const int gFaceCount = SK_ARRAY_COUNT(gFaces);
@@ -41,8 +42,7 @@ class FontScalerTestView : public SampleView {
public:
FontScalerTestView() {
for (int i = 0; i < gFaceCount; i++) {
- fFaces[i] = SkTypeface::MakeFromName(
- gFaces[i].fName, SkFontStyle::FromOldStyle(gFaces[i].fStyle));
+ fFaces[i] = SkTypeface::MakeFromName(gFaces[i].fName, gFaces[i].fStyle);
}
}
diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp
index b8cf3800e0..91daa2a567 100644
--- a/samplecode/SampleSlides.cpp
+++ b/samplecode/SampleSlides.cpp
@@ -624,8 +624,7 @@ static void texteffect_slide(SkCanvas* canvas) {
SkScalar x = 20;
SkScalar y = 80;
SkPaint paint;
- paint.setTypeface(SkTypeface::MakeFromName("Georgia",
- SkFontStyle::FromOldStyle(SkTypeface::kItalic)));
+ paint.setTypeface(SkTypeface::MakeFromName("Georgia", SkFontStyle::Italic()));
paint.setTextSize(75);
paint.setAntiAlias(true);
paint.setColor(SK_ColorBLUE);
diff --git a/site/dev/testing/fonts.md b/site/dev/testing/fonts.md
index cf1eec6d96..5772f28f3a 100644
--- a/site/dev/testing/fonts.md
+++ b/site/dev/testing/fonts.md
@@ -71,14 +71,14 @@ portable typeface on the paint, call:
~~~~
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:
~~~~
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
diff --git a/src/core/SkFontStyle.cpp b/src/core/SkFontStyle.cpp
index a24e7cde2e..24ee645a4f 100644
--- a/src/core/SkFontStyle.cpp
+++ b/src/core/SkFontStyle.cpp
@@ -16,13 +16,6 @@ SkFontStyle::SkFontStyle() {
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) {
return SkFontStyle((oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weight
: SkFontStyle::kNormal_Weight,
diff --git a/src/fonts/SkTestScalerContext.h b/src/fonts/SkTestScalerContext.h
index 746dcc1329..1d362901eb 100644
--- a/src/fonts/SkTestScalerContext.h
+++ b/src/fonts/SkTestScalerContext.h
@@ -106,6 +106,4 @@ private:
friend class SkTestScalerContext;
};
-SkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style);
-
#endif
diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp
index a1cb38ec29..904a9a6ea0 100644
--- a/src/svg/SkSVGDevice.cpp
+++ b/src/svg/SkSVGDevice.cpp
@@ -546,12 +546,27 @@ void SkSVGDevice::AutoElement::addTextAttributes(const SkPaint& paint) {
sk_sp<SkTypeface> tface(paint.getTypeface() ? paint.refTypeface() : SkTypeface::MakeDefault());
SkASSERT(tface);
- SkTypeface::Style style = tface->style();
- if (style & SkTypeface::kItalic) {
+ SkFontStyle style = tface->fontStyle();
+ if (style.slant() == SkFontStyle::kItalic_Slant) {
this->addAttribute("font-style", "italic");
- }
- if (style & SkTypeface::kBold) {
- this->addAttribute("font-weight", "bold");
+ } else if (style.slant() == SkFontStyle::kOblique_Slant) {
+ this->addAttribute("font-style", "oblique");
+ }
+ int weightIndex = (SkTPin(style.weight(), 100, 900) - 50) / 100;
+ 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());
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 0dc3bfe7b6..d407fc0848 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -848,8 +848,7 @@ static void test_typeface(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(10, 10);
SkPaint paint;
- paint.setTypeface(SkTypeface::MakeFromName("Arial",
- SkFontStyle::FromOldStyle(SkTypeface::kItalic)));
+ paint.setTypeface(SkTypeface::MakeFromName("Arial", SkFontStyle::Italic()));
canvas->drawString("Q", 0, 10, paint);
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream stream;
diff --git a/tools/create_test_font.cpp b/tools/create_test_font.cpp
index 721e16b567..4fd8dbbdbb 100644
--- a/tools/create_test_font.cpp
+++ b/tools/create_test_font.cpp
@@ -9,6 +9,7 @@
// and ./tools/test_font_<generic name>.inc which are read by ./tools/sk_tool_utils_font.cpp
#include "Resources.h"
+#include "SkFontStyle.h"
#include "SkOSFile.h"
#include "SkOSPath.h"
#include "SkPaint.h"
@@ -28,16 +29,17 @@ struct NamedFontStyle {
const char* fName;
SkFontStyle fStyle;
};
-NamedFontStyle normal = {"Normal", SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant)};
-NamedFontStyle bold = {"Bold", SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant)};
-NamedFontStyle italic = {"Italic", SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kItalic_Slant )};
-NamedFontStyle bolditalic = {"BoldItalic", SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kItalic_Slant )};
+constexpr NamedFontStyle normal = {"Normal", SkFontStyle::Normal() };
+constexpr NamedFontStyle bold = {"Bold", SkFontStyle::Bold() };
+constexpr NamedFontStyle italic = {"Italic", SkFontStyle::Italic() };
+constexpr NamedFontStyle bolditalic = {"BoldItalic", SkFontStyle::BoldItalic()};
struct FontDesc {
- const char* fGenericName;
- NamedFontStyle fNamedStyle;
- const char* fFontName;
- const char* fFile;
+ char const * const fGenericName;
+ NamedFontStyle const fNamedStyle;
+ char const * const fFontName;
+ char const * const fFile;
+ // fFontIndex is mutable and will be set later.
int fFontIndex;
} gFonts[] = {
{"monospace", normal, "Liberation Mono", "LiberationMono-Regular.ttf", -1},