add arabic test
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
4922d63c8c
commit
e4cf2563be
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
**/*.rs.bk
|
99
Cargo.lock
generated
Normal file
99
Cargo.lock
generated
Normal file
@ -0,0 +1,99 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "approx"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "fontdue"
|
||||
version = "0.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ordered-float"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-font-test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"fontdue 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rusttype 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"stats_alloc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusttype"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"stb_truetype 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stats_alloc"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "stb_truetype"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3"
|
||||
"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
|
||||
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
|
||||
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
|
||||
"checksum fontdue 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3ce5d972ee28d2830f868d3e1398721e0966a32113b888d8553712b50b1d03"
|
||||
"checksum hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1de41fb8dba9714efd92241565cdff73f78508c95697dd56787d3cba27e2353"
|
||||
"checksum num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "443c53b3c3531dfcbfa499d8893944db78474ad7a1d87fa2d94d1a2231693ac6"
|
||||
"checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518"
|
||||
"checksum rusttype 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6fa38506b5cbf2fb67f915e2725cb5012f1b9a785b0ab55c4733acda5f6554ef"
|
||||
"checksum stats_alloc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "a260c96bf26273969f360c2fc2e2c7732acc2ce49d939c7243c7230c2ad179d0"
|
||||
"checksum stb_truetype 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "824210d6fb52cbc3ad2545270ead6860c7311aa5450642b078da4515937b6f7a"
|
BIN
resources/LateefRegOT.ttf
Normal file
BIN
resources/LateefRegOT.ttf
Normal file
Binary file not shown.
28
src/main.rs
28
src/main.rs
@ -9,12 +9,22 @@ use std::alloc::System;
|
||||
static GLOBAL: &StatsAlloc<System> = &INSTRUMENTED_SYSTEM;
|
||||
|
||||
fn main() {
|
||||
// Chinese test
|
||||
let font = include_bytes!("../resources/WenQuanYiMicroHei-01.ttf");
|
||||
test_rusttype(font);
|
||||
test_fontdue(font);
|
||||
let message = " 發啊你好";
|
||||
let rtl = false;
|
||||
test_rusttype(font, message, rtl);
|
||||
test_fontdue(font, message, rtl);
|
||||
|
||||
// Arabic test
|
||||
let font = include_bytes!("../resources/LateefRegOT.ttf");
|
||||
let message = "مرحبا بالعالم";
|
||||
let rtl = true;
|
||||
test_rusttype(font, message, rtl);
|
||||
test_fontdue(font, message, rtl);
|
||||
}
|
||||
|
||||
fn test_fontdue(font: &[u8]) {
|
||||
fn test_fontdue(font: &[u8], message: &str, _rtl: bool) {
|
||||
let reg = Region::new(&GLOBAL);
|
||||
println!("start: {:#?}", reg.change());
|
||||
|
||||
@ -23,7 +33,7 @@ fn test_fontdue(font: &[u8]) {
|
||||
println!("from_bytes: {:#?}", reg.change());
|
||||
|
||||
// Rasterize and get the layout metrics for the letter 'g' at 17px.
|
||||
let (metrics, bitmap) = font.rasterize('欢', 17.0);
|
||||
let (metrics, bitmap) = font.rasterize(message.chars().nth(0).unwrap(), 17.0);
|
||||
println!("font.rasterize: {:#?}", reg.change());
|
||||
|
||||
// Used here to ensure that the value is not
|
||||
@ -33,7 +43,7 @@ fn test_fontdue(font: &[u8]) {
|
||||
::std::mem::size_of_val(&font);
|
||||
}
|
||||
|
||||
fn test_rusttype(font: &[u8]) {
|
||||
fn test_rusttype(font: &[u8], message: &str, rtl: bool) {
|
||||
let reg = Region::new(&GLOBAL);
|
||||
let collection = FontCollection::from_bytes(font).unwrap_or_else(|e| {
|
||||
panic!("error constructing a FontCollection from bytes: {}", e);
|
||||
@ -65,7 +75,7 @@ fn test_rusttype(font: &[u8]) {
|
||||
println!("metrics: {:#?}", reg.change());
|
||||
|
||||
// Glyphs to draw for "RustType". Feel free to try other strings.
|
||||
let glyphs: Vec<PositionedGlyph<'_>> = font.layout("Xous:發啊你好", scale, offset).collect();
|
||||
let glyphs: Vec<PositionedGlyph<'_>> = font.layout(message, scale, offset).collect();
|
||||
println!("glyphs: {:#?}", reg.change());
|
||||
|
||||
// Find the most visually pleasing width to display
|
||||
@ -94,7 +104,11 @@ fn test_rusttype(font: &[u8]) {
|
||||
let y = y as i32 + bb.min.y;
|
||||
// There's still a possibility that the glyph clips the boundaries of the bitmap
|
||||
if x >= 0 && x < width as i32 && y >= 0 && y < pixel_height as i32 {
|
||||
let x = x as usize;
|
||||
let x = if rtl {
|
||||
width - (x as usize) - 1
|
||||
} else {
|
||||
x as usize
|
||||
};
|
||||
let y = y as usize;
|
||||
pixel_data[(x + y * width)] = c;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user