Explorar o código

wallet: switch from harfbuzz_rs to harfbuzz_sys

darkfi %!s(int64=2) %!d(string=hai) anos
pai
achega
6ac471f999

+ 4 - 3
bin/darkwallet/Cargo.toml

@@ -11,9 +11,10 @@ edition = "2021"
 miniquad = { git = "https://github.com/not-fl3/miniquad" }
 # Currently latest version links to freetype-sys 0.19 but we use 0.21
 #harfbuzz-sys = "0.6"
-#harfbuzz-sys = { git = "https://github.com/servo/rust-harfbuzz" }
-# Until we get cargo-quad ported, we are stuck with my shitty hack of unmaintained harfbuzz wrapper rather than the servo FFI
-harfbuzz_rs = { git = "https://github.com/narodnik/hbrs2.git", features = ["freetype"] }
+#harfbuzz-sys = { git = "https://github.com/servo/rust-harfbuzz", features = ["bundled"] }
+harfbuzz-sys = { git = "https://github.com/narodnik/rust-harfbuzz", features = ["bundled"] }
+# Old and crap
+#harfbuzz_rs = { git = "https://github.com/narodnik/hbrs2.git", features = ["freetype"] }
 freetype-rs = { version = "0.37", features = ["bundled"] }
 image = "0.25.1"
 log = "0.4.21"

+ 2 - 2
bin/darkwallet/Dockerfile

@@ -45,8 +45,8 @@ ENV NDK_HOME /usr/local/android-ndk-r25
 
 # Copy contents to container. Should only use this on a clean directory
 WORKDIR /root/
-RUN git clone https://github.com/not-fl3/cargo-quad-apk cargo-apk
-#RUN git clone https://github.com/narodnik/cargo-quad-apk cargo-apk
+#RUN git clone https://github.com/not-fl3/cargo-quad-apk cargo-apk
+RUN git clone https://github.com/narodnik/cargo-quad-apk cargo-apk
 
 # ArmV7a
 #ENV CC ${NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi31-clang

+ 1 - 1
bin/darkwallet/Makefile

@@ -2,7 +2,7 @@ default:
 	cargo lrun
 
 android:
-	docker run -v $(shell pwd):/root/dw -v /tmp/cargo-quad-apk:/root/cargo-quad-apk -w /root/dw -t apk cargo quad-apk build
+	docker run -v $(shell pwd):/root/dw -w /root/dw -t apk cargo quad-apk build
 	adb uninstall darkfi.darkwallet
 	adb install target/android-artifacts/debug/apk/darkwallet.apk
 	reset

+ 5 - 9
bin/darkwallet/src/text2.rs

@@ -1,6 +1,5 @@
 use async_lock::Mutex;
 use freetype as ft;
-/*
 use harfbuzz_sys::{
     freetype::hb_ft_font_create_referenced, hb_buffer_add_utf8, hb_buffer_create,
     hb_buffer_destroy, hb_buffer_get_glyph_infos, hb_buffer_get_glyph_positions,
@@ -8,7 +7,6 @@ use harfbuzz_sys::{
     hb_feature_t, hb_font_destroy, hb_glyph_info_t, hb_glyph_position_t, hb_shape,
     HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS, HB_BUFFER_CONTENT_TYPE_UNICODE,
 };
-*/
 use miniquad::TextureId;
 use std::{
     collections::HashMap,
@@ -286,7 +284,7 @@ impl TextShaper {
 
         for (face_idx, text) in substrs {
             //debug!("substr {}", text);
-            let face = &faces.0[face_idx];
+            let face = &mut faces.0[face_idx];
             if face.has_fixed_sizes() {
                 // emojis required a fixed size
                 //face.set_char_size(109 * 64, 0, 72, 72).unwrap();
@@ -295,6 +293,7 @@ impl TextShaper {
                 face.set_char_size(font_size as isize * 64, 0, 96, 96).unwrap();
             }
 
+            /*
             let hb_font = harfbuzz_rs::Font::from_freetype_face(face.clone());
             let buffer = harfbuzz_rs::UnicodeBuffer::new()
                 .set_cluster_level(harfbuzz_rs::ClusterLevel::MonotoneCharacters)
@@ -303,8 +302,8 @@ impl TextShaper {
 
             let positions = output.get_glyph_positions();
             let infos = output.get_glyph_infos();
+            */
 
-            /*
             let utf8_ptr = text.as_ptr() as *const _;
             // https://harfbuzz.github.io/a-simple-shaping-example.html
             let (hb_font, buf, glyph_infos, glyph_pos, glyph_infos_iter, glyph_pos_iter) = unsafe {
@@ -334,12 +333,11 @@ impl TextShaper {
 
                 (hb_font, buf, glyph_infos, glyph_pos, glyph_infos_iter, glyph_pos_iter)
             };
-            */
 
             let mut prev_cluster = 0;
 
-            for (i, (position, info)) in positions.iter().zip(infos).enumerate() {
-                //for (i, (position, info)) in glyph_pos_iter.iter().zip(glyph_infos_iter.iter()).enumerate() {
+            //for (i, (position, info)) in positions.iter().zip(infos).enumerate() {
+            for (i, (position, info)) in glyph_pos_iter.iter().zip(glyph_infos_iter.iter()).enumerate() {
                 let glyph_id = info.codepoint as u32;
                 // Index within this substr
                 let curr_cluster = info.cluster as usize;
@@ -472,12 +470,10 @@ impl TextShaper {
             let substr = text[prev_cluster..].to_string();
             glyphs.last_mut().unwrap().substr = substr;
 
-            /*
             unsafe {
                 hb_buffer_destroy(buf);
                 hb_font_destroy(hb_font);
             }
-            */
         }
 
         glyphs