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: upgrade to usvg/resvg 0.34.0 #268

Merged
merged 4 commits into from
Oct 16, 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
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pathfinder_geometry = "0.5.1"
pathfinder_content = { version = "0.5.0", default-features = false }
pathfinder_simd = { version = "0.5.1", features = ["pf-no-simd"] }
futures = "0.3.21"
usvg-writer = { git = "https://github.com/zimond/resvg", rev = "6201182c" }
woff2 = "0.3.0"

[target.'cfg(all(not(all(target_os = "linux", target_arch = "aarch64", target_env = "musl")), not(all(target_os = "windows", target_arch = "aarch64")), not(target_arch = "wasm32")))'.dependencies]
Expand All @@ -30,17 +29,15 @@ mimalloc-rust = { version = "0.2" }
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.87"
js-sys = "0.3.64"
resvg = { version = "0.29.0", default-features = false, features = [
"filter",
resvg = { version = "0.34.0", default-features = false, features = [
"raster-images",
"text",
] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
napi = { version = "2.13.3", features = ["serde-json", "async"] }
napi-derive = "2.13.0"
resvg = { version = "0.29.0", default-features = false, features = [
"filter",
resvg = { version = "0.34.0", default-features = false, features = [
"raster-images",
"text",
"system-fonts",
Expand All @@ -57,5 +54,5 @@ opt-level = 3
codegen-units = 1

[patch.crates-io]
resvg = { git = "https://github.com/zimond/resvg", rev = "6201182c" }
resvg = { git = "https://github.com/zimond/resvg", rev = "3495d870" }
woff2 = { git="https://github.com/yisibl/woff2-rs", branch="fix-total-compressed-size" }
10 changes: 5 additions & 5 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ test('should be load custom fontFiles(no defaultFontFamily option)', (t) => {
const originPixels = pngData.pixels.toJSON().data

// Find the number of blue `rgb(0,255,255)`pixels
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1726)
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1727)
})

test('should be load custom fontDirs(no defaultFontFamily option)', (t) => {
Expand All @@ -283,7 +283,7 @@ test('should be load custom fontDirs(no defaultFontFamily option)', (t) => {
const originPixels = pngData.pixels.toJSON().data

// Find the number of blue `rgb(0,255,255)`pixels
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1726)
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1727)
})

test('The defaultFontFamily is not found in the OS and needs to be fallback', (t) => {
Expand Down Expand Up @@ -539,9 +539,9 @@ test('should get svg bbox(rect)', async (t) => {
const result = await jimp.read(pngBuffer)

t.is(bbox.width, 200)
t.is(bbox.height, 100.00000000000001)
t.is(bbox.x, 50.4)
t.is(bbox.y, 60.8)
t.is(bbox.height, 100)
t.is(bbox.x, 50.400001525878906)
t.is(bbox.y, 60.79999923706055)

// Must not have Alpha
t.is(result.hasAlpha(), false)
Expand Down
14 changes: 7 additions & 7 deletions __test__/wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ test('should be load custom font(no defaultFontFamily option)', async (t) => {
const originPixels = Array.from(pngData.pixels)

// Find the number of blue `rgb(0,255,255)`pixels
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1726)
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1727)
})

test('should be load custom fontBuffers(no defaultFontFamily option)', async (t) => {
Expand All @@ -282,7 +282,7 @@ test('should be load custom fontBuffers(no defaultFontFamily option)', async (t)
const originPixels = Array.from(pngData.pixels)

// Find the number of blue `rgb(0,255,255)`pixels
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1726)
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 1727)
})

test('should be load custom multiple fontBuffers', async (t) => {
Expand All @@ -306,7 +306,7 @@ test('should be load custom multiple fontBuffers', async (t) => {
const originPixels = Array.from(pngData.pixels)

// Find the number of blue `rgb(0,255,255)`pixels
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 8938)
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 8911)
})

test('should be load custom WOFF2 font', async (t) => {
Expand All @@ -327,7 +327,7 @@ test('should be load custom WOFF2 font', async (t) => {
const originPixels = Array.from(pngData.pixels)

// Find the number of blue `rgb(0,255,255)`pixels
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 6067)
t.is(originPixels.join(',').match(/0,0,255/g)?.length, 6039)
})

test('should generate a 80x80 png and opaque', async (t) => {
Expand Down Expand Up @@ -434,9 +434,9 @@ test('should get svg bbox(rect)', async (t) => {
const result = await jimp.read(Buffer.from(pngBuffer))

t.is(bbox.width, 200)
t.is(bbox.height, 100.00000000000001)
t.is(bbox.x, 50.4)
t.is(bbox.y, 60.8)
t.is(bbox.height, 100)
t.is(bbox.x, 50.400001525878906)
t.is(bbox.y, 60.79999923706055)
// Must not have Alpha
t.is(result.hasAlpha(), false)
// Here the expected value is actually 200*100, and the calculation of the bbox needs to be fixed.
Expand Down
Binary file modified example/bbox-out.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 example/out-resvg-js.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 example/out-sharp.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 example/out-skr-canvas.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 example/text-out-async.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 example/text-out.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 example/text2-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions src/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use crate::options::*;
use resvg::usvg_text_layout::fontdb::{Database, Language};
use resvg::usvg::fontdb::{Database, Language};

#[cfg(not(target_arch = "wasm32"))]
use log::{debug, warn};

#[cfg(not(target_arch = "wasm32"))]
use resvg::usvg_text_layout::fontdb::{Family, Query, Source};
use resvg::usvg::fontdb::{Family, Query, Source};

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::JsCast;
Expand Down Expand Up @@ -95,7 +95,6 @@ fn set_font_families(font_options: &JsFontOptions, fontdb: &mut Database) {

let fontdb_found_default_font_family = fontdb
.faces()
.iter()
.find_map(|it| {
it.families
.iter()
Expand Down Expand Up @@ -135,7 +134,6 @@ fn set_wasm_font_families(

let fontdb_found_default_font_family = fontdb
.faces()
.iter()
.find_map(|it| {
it.families
.iter()
Expand Down Expand Up @@ -203,7 +201,7 @@ fn find_and_debug_font_path(fontdb: &mut Database, font_family: &str) {
fn get_first_font_family_or_fallback(fontdb: &mut Database) -> String {
let mut default_font_family = "Arial".to_string(); // 其他情况都 fallback 到指定的这个字体。

match fontdb.faces().iter().next() {
match fontdb.faces().next() {
Some(face) => {
let base_family = face
.families
Expand Down
Loading
Loading