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>
This commit is contained in:
Ben Wagner 2017-08-07 09:56:21 -04:00 committed by Skia Commit-Bot
parent 0ac06e4726
commit c6c10b4518
5 changed files with 83 additions and 21 deletions

View File

@ -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() {

View File

@ -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

View File

@ -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();

View File

@ -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() {

View File

@ -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);