Skip to content

Commit

Permalink
feat: upgrade to usvg/resvg 0.34
Browse files Browse the repository at this point in the history
  • Loading branch information
zimond committed Sep 18, 2023
1 parent 093b839 commit f4138e4
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 120 deletions.
13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,22 @@ 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" }

[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]
mimalloc-rust = { version = "0.2" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.84"
js-sys = "0.3.61"
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.12.1", features = ["serde-json", "async"] }
napi-derive = "2.10.1"
resvg = { version = "0.29.0", default-features = false, features = [
"filter",
napi = { version = "2.13.3", features = ["serde-json", "async"] }
napi-derive = "2.13.0"
resvg = { version = "0.34.0", default-features = false, features = [
"raster-images",
"text",
"system-fonts",
Expand All @@ -56,4 +53,4 @@ 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 = "9a44a3c" }
6 changes: 3 additions & 3 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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 @@ -265,7 +265,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 @@ -521,7 +521,7 @@ 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.height, 100)
t.is(bbox.x, 50.4)
t.is(bbox.y, 60.8)

Expand Down
6 changes: 3 additions & 3 deletions __test__/wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,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 @@ -262,7 +262,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 Down Expand Up @@ -393,7 +393,7 @@ 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.height, 100)
t.is(bbox.x, 50.4)
t.is(bbox.y, 60.8)
// Must not have Alpha
Expand Down
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 @@ -86,7 +86,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 @@ -126,7 +125,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 @@ -194,7 +192,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

0 comments on commit f4138e4

Please sign in to comment.