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:
parent
23890a9ac8
commit
713195071d
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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()))
|
||||
|
||||
{
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -5,32 +5,33 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
#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 "SkCanvas.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 "SkColorPriv.h"
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkDither.h"
|
||||
#include "SkRegion.h"
|
||||
#include "SkShader.h"
|
||||
#include "SkTypeface.h"
|
||||
#include "SkUtils.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -106,6 +106,4 @@ private:
|
||||
friend class SkTestScalerContext;
|
||||
};
|
||||
|
||||
SkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style);
|
||||
|
||||
#endif
|
||||
|
@ -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");
|
||||
} else if (style.slant() == SkFontStyle::kOblique_Slant) {
|
||||
this->addAttribute("font-style", "oblique");
|
||||
}
|
||||
if (style & SkTypeface::kBold) {
|
||||
this->addAttribute("font-weight", "bold");
|
||||
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());
|
||||
|
@ -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;
|
||||
|
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user