aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2017-08-07 09:56:21 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-08-08 15:27:19 +0000
commitc6c10b45188f0921c9451644b61b072e3a36ee12 (patch)
tree34c7ae0b90be040daa5523657fec04d6771f9472
parent0ac06e47269a40c177747310a613d213c95d1d6d (diff)
Remove SkTypeface::Style from fuzzers and lua.
Change-Id: I53be039e21a4c11ec3a4bc54c1424cd3e15afc6a Reviewed-on: https://skia-review.googlesource.com/31643 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
-rw-r--r--fuzz/FilterFuzz.cpp11
-rw-r--r--resources/slides.lua22
-rw-r--r--resources/test.lua2
-rw-r--r--samplecode/SampleFilterFuzz.cpp2
-rw-r--r--src/utils/SkLua.cpp67
5 files changed, 83 insertions, 21 deletions
diff --git a/fuzz/FilterFuzz.cpp b/fuzz/FilterFuzz.cpp
index 015a0a06aa..41e2c7276f 100644
--- a/fuzz/FilterFuzz.cpp
+++ b/fuzz/FilterFuzz.cpp
@@ -23,6 +23,7 @@
#include "SkDropShadowImageFilter.h"
#include "SkEmbossMaskFilter.h"
#include "SkFlattenableSerialization.h"
+#include "SkFontStyle.h"
#include "SkImageSource.h"
#include "SkLayerRasterizer.h"
#include "SkLightingImageFilter.h"
@@ -182,9 +183,13 @@ static SkFilterQuality make_filter_quality() {
}
static SkFontStyle make_typeface_style() {
- uint8_t i;
- fuzz->nextRange(&i, 0, (uint8_t)SkTypeface::kBoldItalic);
- return SkFontStyle::FromOldStyle(i);
+ uint16_t weight;
+ fuzz->nextRange(&weight, SkFontStyle::kInvisible_Weight, SkFontStyle::kExtraBlack_Weight);
+ uint8_t width;
+ fuzz->nextRange(&width, SkFontStyle::kUltraCondensed_Width, SkFontStyle::kUltraExpanded_Width);
+ uint8_t slant;
+ fuzz->nextRange(&slant, SkFontStyle::kUpright_Slant, SkFontStyle::kOblique_Slant);
+ return SkFontStyle(weight, width, static_cast<SkFontStyle::Slant>(slant));
}
static SkPath1DPathEffect::Style make_path_1d_path_effect_style() {
diff --git a/resources/slides.lua b/resources/slides.lua
index 43c9b3b32f..9d61a87273 100644
--- a/resources/slides.lua
+++ b/resources/slides.lua
@@ -1,7 +1,7 @@
gShowBounds = false
gUseBlurInTransitions = false
-gPath = "/skia/trunk/resources/"
+gPath = "resources/"
function load_file(file)
local prev_path = package.path
@@ -12,17 +12,17 @@ end
load_file("slides_utils")
-gSlides = parse_file(io.open("/skia/trunk/resources/slides_content2.lua", "r"))
+gSlides = parse_file(io.open("resources/slides_content2.lua", "r"))
function make_rect(l, t, r, b)
return { left = l, top = t, right = r, bottom = b }
end
-function make_paint(typefacename, stylebits, size, color)
+function make_paint(typefacename, style, size, color)
local paint = Sk.newPaint();
paint:setAntiAlias(true)
paint:setSubpixelText(true)
- paint:setTypeface(Sk.newTypeface(typefacename, stylebits))
+ paint:setTypeface(Sk.newTypeface(typefacename, style))
paint:setTextSize(size)
paint:setColor(color)
return paint
@@ -102,27 +102,29 @@ function make_tmpl(paint, extra_dy)
end
function SkiaPoint_make_template()
+ normal = Sk.newFontStyle()
+ bold = Sk.newFontStyle(700)
local title = {
margin_x = 30,
margin_y = 100,
}
- title[1] = make_paint("Arial", 1, 45, { a=1, r=1, g=1, b=1 })
+ title[1] = make_paint("Arial", bold, 45, { a=1, r=1, g=1, b=1 })
title[1]:setTextAlign("center")
- title[2] = make_paint("Arial", 1, 25, { a=1, r=.75, g=.75, b=.75 })
+ title[2] = make_paint("Arial", bold, 25, { a=1, r=.75, g=.75, b=.75 })
title[2]:setTextAlign("center")
local slide = {
margin_x = 20,
margin_y = 25,
}
- slide[1] = make_tmpl(make_paint("Arial", 1, 35, { a=1, r=1, g=1, b=1 }), 18)
- slide[2] = make_tmpl(make_paint("Arial", 0, 25, { a=1, r=1, g=1, b=1 }), 10)
- slide[3] = make_tmpl(make_paint("Arial", 0, 20, { a=1, r=.9, g=.9, b=.9 }), 5)
+ slide[1] = make_tmpl(make_paint("Arial", bold, 35, { a=1, r=1, g=1, b=1 }), 18)
+ slide[2] = make_tmpl(make_paint("Arial", normal, 25, { a=1, r=1, g=1, b=1 }), 10)
+ slide[3] = make_tmpl(make_paint("Arial", normal, 20, { a=1, r=.9, g=.9, b=.9 }), 5)
return {
title = title,
slide = slide,
- codePaint = make_paint("Courier", 0, 20, { a=1, r=.9, g=.9, b=.9 }),
+ codePaint = make_paint("Courier", normal, 20, { a=1, r=.9, g=.9, b=.9 }),
}
end
diff --git a/resources/test.lua b/resources/test.lua
index 1029db41ed..03201baeda 100644
--- a/resources/test.lua
+++ b/resources/test.lua
@@ -47,7 +47,7 @@ function onStartup()
local paint = Sk.newPaint();
paint:setColor{a=1, r=1, g=0, b=0};
if false then
- local doc = Sk.newDocumentPDF('/skia/trunk/test.pdf');
+ local doc = Sk.newDocumentPDF('out/test.pdf');
local canvas = doc:beginPage(72*8.5, 72*11);
canvas:drawText('Hello Lua', 300, 300, paint);
doc:close();
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index ec9476fcfe..97fe6fc760 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -197,7 +197,7 @@ static SkFilterQuality make_filter_quality() {
}
static SkFontStyle make_typeface_style() {
- return SkFontStyle::FromOldStyle(SkTypeface::kBoldItalic+1);
+ return SkFontStyle::Normal();
}
static SkPath1DPathEffect::Style make_path_1d_path_effect_style() {
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index fa474b3b13..413a207114 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -16,6 +16,7 @@
#include "SkColorFilter.h"
#include "SkData.h"
#include "SkDocument.h"
+#include "SkFontStyle.h"
#include "SkGradientShader.h"
#include "SkImage.h"
#include "SkMatrix.h"
@@ -58,10 +59,11 @@ DEF_MTNAME(SkShader)
DEF_MTNAME(SkSurface)
DEF_MTNAME(SkTextBlob)
DEF_MTNAME(SkTypeface)
+DEF_MTNAME(SkFontStyle)
-template <typename T> T* push_new(lua_State* L) {
+template <typename T, typename... Args> T* push_new(lua_State* L, Args&&... args) {
T* addr = (T*)lua_newuserdata(L, sizeof(T));
- new (addr) T;
+ new (addr) T(std::forward<Args>(args)...);
luaL_getmetatable(L, get_mtname<T>());
lua_setmetatable(L, -2);
return addr;
@@ -1818,6 +1820,36 @@ static const struct luaL_Reg gSkTypeface_Methods[] = {
///////////////////////////////////////////////////////////////////////////////
+static int lfontstyle_weight(lua_State* L) {
+ lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->weight());
+ return 1;
+}
+
+static int lfontstyle_width(lua_State* L) {
+ lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->width());
+ return 1;
+}
+
+static int lfontstyle_slant(lua_State* L) {
+ lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->slant());
+ return 1;
+}
+
+static int lfontstyle_gc(lua_State* L) {
+ get_obj<SkFontStyle>(L, 1)->~SkFontStyle();
+ return 0;
+}
+
+static const struct luaL_Reg gSkFontStyle_Methods[] = {
+ { "weight", lfontstyle_weight },
+ { "width", lfontstyle_width },
+ { "slant", lfontstyle_slant },
+ { "__gc", lfontstyle_gc },
+ { nullptr, nullptr }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
class AutoCallLua {
public:
AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) {
@@ -1940,17 +1972,20 @@ static int lsk_newTextBlob(lua_State* L) {
static int lsk_newTypeface(lua_State* L) {
const char* name = nullptr;
- int style = SkTypeface::kNormal;
+ SkFontStyle style;
int count = lua_gettop(L);
if (count > 0 && lua_isstring(L, 1)) {
name = lua_tolstring(L, 1, nullptr);
- if (count > 1 && lua_isnumber(L, 2)) {
- style = lua_tointegerx(L, 2, nullptr) & SkTypeface::kBoldItalic;
+ if (count > 1) {
+ SkFontStyle* passedStyle = get_obj<SkFontStyle>(L, 2);
+ if (passedStyle) {
+ style = *passedStyle;
+ }
}
}
- sk_sp<SkTypeface> face(SkTypeface::MakeFromName(name, SkFontStyle::FromOldStyle(style)));
+ sk_sp<SkTypeface> face(SkTypeface::MakeFromName(name, style));
// SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, face->getRefCnt());
if (nullptr == face) {
face = SkTypeface::MakeDefault();
@@ -1959,6 +1994,24 @@ static int lsk_newTypeface(lua_State* L) {
return 1;
}
+static int lsk_newFontStyle(lua_State* L) {
+ int count = lua_gettop(L);
+ int weight = SkFontStyle::kNormal_Weight;
+ int width = SkFontStyle::kNormal_Width;
+ SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
+ if (count >= 1 && lua_isnumber(L, 1)) {
+ weight = lua_tointegerx(L, 1, nullptr);
+ }
+ if (count >= 2 && lua_isnumber(L, 2)) {
+ width = lua_tointegerx(L, 2, nullptr);
+ }
+ if (count >= 3 && lua_isnumber(L, 3)) {
+ slant = static_cast<SkFontStyle::Slant>(lua_tointegerx(L, 3, nullptr));
+ }
+ push_new<SkFontStyle>(L, weight, width, slant);
+ return 1;
+}
+
static int lsk_newRasterSurface(lua_State* L) {
int width = lua2int_def(L, 1, 0);
int height = lua2int_def(L, 2, 0);
@@ -2006,6 +2059,7 @@ static void register_Sk(lua_State* L) {
setfield_function(L, "newRasterSurface", lsk_newRasterSurface);
setfield_function(L, "newTextBlob", lsk_newTextBlob);
setfield_function(L, "newTypeface", lsk_newTypeface);
+ setfield_function(L, "newFontStyle", lsk_newFontStyle);
lua_pop(L, 1); // pop off the Sk table
}
@@ -2036,6 +2090,7 @@ void SkLua::Load(lua_State* L) {
REG_CLASS(L, SkSurface);
REG_CLASS(L, SkTextBlob);
REG_CLASS(L, SkTypeface);
+ REG_CLASS(L, SkFontStyle);
}
extern "C" int luaopen_skia(lua_State* L);