Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skia/m112 #648

Merged
merged 4 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `skr canvas`

![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm110-hotpink)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm112-hotpink)
[![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas)
[![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `skr canvas`

![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm110-hotpink)
![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm112-hotpink)
[![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas)
[![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)

Expand Down
3 changes: 3 additions & 0 deletions __test__/echarts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ test('echarts-start', async (t) => {
// @ts-expect-error
const chart = init(canvas)
chart.setOption({
textStyle: {
fontFamily: 'Iosevka Slab, PingFang HK',
},
title: {
text: 'ECharts 入门示例',
},
Expand Down
Binary file modified __test__/snapshots/draw-image-svg-noto-emoji.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/echarts-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-blur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-contrast-ff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-grayscale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/filter-hue-rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __test__/snapshots/text-align-with-space.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __test__/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test('text-align-with-space', async (t) => {
ctx.moveTo(100, 0)
ctx.lineTo(100, 512)
ctx.stroke()
ctx.font = '48px sans-serif'
ctx.font = '48px sans-serif, PingFang HK'
ctx.textAlign = 'center'
ctx.fillText('蒙娜丽莎', 100, 50)
ctx.fillText('兔 宝 宝', 100, 200)
Expand Down
8 changes: 5 additions & 3 deletions example/draw-emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ const { join } = require('path')

const { createCanvas, GlobalFonts } = require('../index.js')

GlobalFonts.registerFromPath(join(__dirname, '..', '__test__', 'fonts', 'AppleColorEmoji@2x.ttf'), 'Apple Emoji')
GlobalFonts.registerFromPath(join(__dirname, '..', '__test__', 'fonts', 'AppleColorEmoji@2x.ttf'), 'Apple Color Emoji')
GlobalFonts.registerFromPath(join(__dirname, '..', '__test__', 'fonts', 'COLRv1.ttf'), 'COLRv1')

console.info(GlobalFonts.families)
GlobalFonts.families.forEach(({ family }) => {
console.info(family)
})

const canvas = createCanvas(760, 360)
const ctx = canvas.getContext('2d')

ctx.font = '50px Apple Emoji'
ctx.font = '50px Apple Color Emoji'
ctx.strokeText('😀😃😄😁😆😅😂🤣☺️😊😊😇', 50, 150)

ctx.font = '100px COLRv1'
Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,41 +62,41 @@
"version": "napi version && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
},
"devDependencies": {
"@jimp/core": "^0.22.0",
"@jimp/custom": "^0.22.0",
"@jimp/jpeg": "^0.22.0",
"@jimp/png": "^0.22.0",
"@napi-rs/cli": "^2.14.5",
"@octokit/rest": "^19.0.5",
"@swc-node/register": "^1.5.4",
"@swc/core": "^1.3.24",
"@jimp/core": "^0.22.7",
"@jimp/custom": "^0.22.7",
"@jimp/jpeg": "^0.22.7",
"@jimp/png": "^0.22.7",
"@napi-rs/cli": "^2.14.8",
"@octokit/rest": "^19.0.7",
"@swc-node/register": "^1.6.2",
"@swc/core": "^1.3.39",
"@types/lodash": "^4.14.191",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"ava": "^5.1.0",
"@types/node": "^18.15.0",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"ava": "^5.2.0",
"benny": "^3.7.1",
"canvas": "^2.11.0",
"canvaskit-wasm": "^0.38.0",
"colorette": "^2.0.19",
"conventional-changelog-cli": "^2.2.2",
"echarts": "^5.4.1",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-sonarjs": "^0.18.0",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
"husky": "^8.0.3",
"lint-staged": "^13.2.0",
"lodash": "^4.17.21",
"npm-run-all": "^4.1.5",
"pinst": "^3.0.0",
"png.js": "^0.2.1",
"prettier": "^2.8.1",
"pretty-bytes": "^6.0.0",
"prettier": "^2.8.4",
"pretty-bytes": "^6.1.0",
"skia-canvas": "^1.0.1",
"table": "^6.8.1",
"typescript": "^4.9.4"
"typescript": "^4.9.5"
},
"lint-staged": {
"*.@(js|ts|tsx|yml|yaml|md|json|html)": [
Expand Down
11 changes: 9 additions & 2 deletions scripts/build-skia.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let ExtraLdFlags
let ExtraAsmFlags

const GN_ARGS = [
`is_official_build=false`,
`is_official_build=true`,
`is_component_build=false`,
`is_debug=false`,
`werror=false`,
Expand All @@ -45,7 +45,6 @@ const GN_ARGS = [
`skia_enable_android_utils=false`,
`skia_enable_discrete_gpu=false`,
`skia_enable_gpu=false`,
`skia_enable_particles=true`,
`skia_enable_pdf=true`,
`skia_enable_skottie=false`,
`skia_enable_skshaper=true`,
Expand All @@ -55,6 +54,7 @@ const GN_ARGS = [
`skia_enable_sktext=true`,
`skia_pdf_subset_harfbuzz=true`,
`skia_use_expat=true`,
`skia_use_system_expat=false`,
`skia_use_gl=false`,
`skia_use_harfbuzz=true`,
`skia_use_icu=true`,
Expand All @@ -78,6 +78,10 @@ const GN_ARGS = [
`skia_use_system_harfbuzz=false`,
`skia_use_lua=false`,
`skia_use_piex=false`,
`skia_enable_fontmgr_custom_directory=true`,
`skia_enable_fontmgr_custom_embedded=false`,
`skia_enable_fontmgr_custom_empty=true`,
`skia_enable_fontmgr_android=false`,
]

switch (PLATFORM_NAME) {
Expand All @@ -98,6 +102,8 @@ switch (PLATFORM_NAME) {
'\\"-DSK_HAS_HEIF_LIBRARY\\",' +
'\\"-DSK_SHAPER_HARFBUZZ_AVAILABLE\\"'
ExtraSkiaBuildFlag = 'clang_win=\\"C:\\\\Program Files\\\\LLVM\\"'
GN_ARGS.push(`skia_enable_fontmgr_win=false`)
GN_ARGS.push(`skia_fontmgr_factory=\\":fontmgr_custom_directory_factory\\"`)
break
case 'linux':
case 'darwin':
Expand All @@ -124,6 +130,7 @@ switch (PLATFORM_NAME) {
) {
ExtraCflagsCC += ',"-stdlib=libc++", "-static", "-I/usr/lib/llvm-15/include/c++/v1"'
}
GN_ARGS.push(`skia_fontmgr_factory=":fontmgr_custom_directory_factory"`)
break
default:
throw new TypeError(`Don't support ${PLATFORM_NAME} for now`)
Expand Down
8 changes: 4 additions & 4 deletions scripts/release-skia-binary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { execSync } = require('child_process')
const { promises: fs, copyFileSync, createReadStream, statSync } = require('fs')
const { promises: fs, copyFileSync, statSync } = require('fs')
const { platform } = require('os')
const { parse, join } = require('path')

Expand Down Expand Up @@ -78,7 +78,7 @@ async function upload() {
'content-length': dstFileStats.size,
'content-type': 'application/octet-stream',
},
data: createReadStream(copy),
data: await fs.readFile(copy),
})
.catch((e) => {
execSync(`ls -la ./skia/out/Static`, { stdio: 'inherit' })
Expand All @@ -98,7 +98,7 @@ async function upload() {
}
console.info(green(`Uploading [${ICU_DAT}] to github release: [${TAG}]`))
const icuDataPath = join(__dirname, '..', 'skia', 'out', 'Static', ICU_DAT)
await await CLIENT.repos.uploadReleaseAsset({
await CLIENT.repos.uploadReleaseAsset({
owner: OWNER,
repo: REPO,
name: ICU_DAT,
Expand All @@ -108,7 +108,7 @@ async function upload() {
'content-length': statSync(icuDataPath).size,
'content-type': 'application/octet-stream',
},
data: createReadStream(icuDataPath),
data: await fs.readFile(icuDataPath),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion skia
Submodule skia updated 3055 files
4 changes: 2 additions & 2 deletions skia-c/skia_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ extern "C"
p.setStrokeMiter(miter_limit);
const SkPath *const_path = path;
const SkPaint const_paint = p;
return FillPathWithPaint(*const_path, const_paint, path);
return skpathutils::FillPathWithPaint(*const_path, const_paint, path);
}

void skiac_path_compute_tight_bounds(skiac_path *c_path, skiac_rect *c_rect)
Expand Down Expand Up @@ -962,7 +962,7 @@ extern "C"
auto precision = 0.3; // Based on config in Chromium
const SkPath *const_path = path;
const SkPaint const_paint = paint;
if (FillPathWithPaint(*const_path, const_paint, &traced_path, nullptr, precision))
if (skpathutils::FillPathWithPaint(*const_path, const_paint, &traced_path, nullptr, precision))
{
result = traced_path.contains(x, y);
}
Expand Down
3 changes: 2 additions & 1 deletion skia-c/skia_c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <include/core/SkColorFilter.h>
#include <include/core/SkData.h>
#include <include/core/SkDrawable.h>
#include <include/core/SkEncodedImageFormat.h>
#include <include/core/SkGraphics.h>
#include <include/core/SkFontMgr.h>
#include <include/core/SkPaint.h>
Expand Down Expand Up @@ -129,7 +130,7 @@ struct skiac_font_collection
sk_sp<FontCollection> collection;
sk_sp<SkFontMgr> font_mgr;
sk_sp<TypefaceFontProviderCustom> assets;
skiac_font_collection() : collection(sk_make_sp<FontCollection>()), font_mgr(SkFontMgr_New_Custom_Directory(SK_FONT_FILE_PREFIX)), assets(sk_make_sp<TypefaceFontProviderCustom>(font_mgr))
skiac_font_collection() : collection(sk_make_sp<FontCollection>()), font_mgr(SkFontMgr::RefDefault()), assets(sk_make_sp<TypefaceFontProviderCustom>(font_mgr))
{
collection->setDefaultFontManager(SkFontMgr::RefDefault());
collection->setAssetFontManager(font_mgr);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"allowSyntheticDefaultImports": true,
"allowJs": true,
"outDir": "dist",
"sourceMap": true,
"lib": ["ESNext", "DOM"]
},
"exclude": ["node_modules", "depot_tools", "skia", "skia-c", "example", "target", "npm"]
Expand Down
Loading