Skip to content

Commit

Permalink
Move funcs in wrfont.c to Rust crate font and turn it to lisp
Browse files Browse the repository at this point in the history
  • Loading branch information
declantsien committed Apr 13, 2024
1 parent 3da968b commit 0146550
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 62 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7293,9 +7293,6 @@ if test "${HAVE_HARFBUZZ}" = "yes" ; then
FONT_OBJ="$FONT_OBJ hbfont.o"
fi

if test "${with_webrender}" = "yes" ; then
FONT_OBJ="$FONT_OBJ wrfont.o"
fi
AC_SUBST([XMENU_OBJ])
AC_SUBST([XOBJ])
AC_SUBST([FONT_OBJ])
Expand Down Expand Up @@ -7959,7 +7956,7 @@ AC_SUBST(CARGO_FEATURES)

dnl Rust sources which has Lisp symbols definitions
AS_ECHO(["Collecting Rust sources..."])
RUST_CRATES_SOURCES=`(ABS_TOP_SRCDIR=$(pwd) cargo run -p codegen --bin print-source ${CARGO_FEATURES} 2>/dev/null)`
RUST_CRATES_SOURCES=`(ABS_TOP_SRCDIR=$(pwd) cargo run -p codegen --bin print-source ${CARGO_FEATURES})`
AS_ECHO(["Collecting Rust sources...done"])
AC_SUBST(RUST_CRATES_SOURCES)

Expand Down
3 changes: 3 additions & 0 deletions crates/font/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ build = "../codegen/etc/build.rs"
[dependencies]
webrender_api.workspace = true
emacs-sys.path = "../emacs-sys"
lisp-macros.path = "../lisp-macros"
lisp-util.path = "../lisp-util"
lazy_static = "1.4"
log.workspace = true
libc.workspace = true
parking_lot.workspace = true
Expand Down
53 changes: 53 additions & 0 deletions crates/font/src/fns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use emacs_sys::bindings::globals;
use emacs_sys::bindings::CHECK_SYMBOL;
use emacs_sys::bindings::CONSP;
use emacs_sys::bindings::XCAR;
use emacs_sys::bindings::XCDR;
use emacs_sys::globals::Qnil;
use emacs_sys::lisp::LispObject;
use lisp_macros::lisp_fn;

/// Convert emacs script name to OTF 4-letter script code.
/// See `otf-script-alist'.
#[lisp_fn(min = "1")]
pub fn script_to_otf(script: LispObject) -> LispObject {
use emacs_sys::bindings::Frassq;
unsafe { CHECK_SYMBOL(script) };
let otf = unsafe { Frassq(script, globals.Votf_script_alist) };
if otf.is_cons() {
let otf = otf.force_cons();
return otf.car();
}
Qnil
}

/// Convert a font registry.
/// See `registry-script-alist'.
#[lisp_fn(min = "1")]
pub fn registry_to_script(reg: LispObject) -> LispObject {
unsafe { CHECK_SYMBOL(reg) };

use emacs_sys::bindings::strncmp;
use emacs_sys::bindings::SBYTES;
use emacs_sys::bindings::SSDATA;
use emacs_sys::bindings::SYMBOL_NAME;

let mut rsa = unsafe { globals.Vregistry_script_alist };
let mut r;
while unsafe { CONSP(rsa) } {
r = unsafe { XCAR(XCAR(rsa)) };
if !unsafe {
strncmp(
SSDATA(r),
SSDATA(SYMBOL_NAME(reg)),
SBYTES(r).try_into().unwrap(),
) != 0
} {
return unsafe { XCDR(XCAR(rsa)) };
}
rsa = unsafe { XCDR(rsa) };
}
return Qnil;
}

include!(concat!(env!("OUT_DIR"), "/fns_exports.rs"));
15 changes: 10 additions & 5 deletions crates/font/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#![feature(concat_idents)]

#[macro_use]
extern crate emacs_sys;
extern crate lisp_macros;
#[macro_use]
extern crate lisp_util;

mod cache;
mod fns;

use emacs_sys::bindings::assq_no_quit;
use emacs_sys::bindings::font_put_extra;
use emacs_sys::bindings::globals;
use emacs_sys::bindings::make_fixnum;
use emacs_sys::bindings::registry_to_otf;
use emacs_sys::bindings::script_to_otf;
use emacs_sys::bindings::AREF;
use emacs_sys::bindings::CONSP;
use emacs_sys::bindings::SYMBOLP;
Expand Down Expand Up @@ -295,7 +300,7 @@ impl From<LispFontLike> for OptionalScript {
let key = XCAR(tmp);
let val = XCDR(tmp);
if key.eq(QCscript) && SYMBOLP(val) {
let otf_script = script_to_otf(val);
let otf_script = Fscript_to_otf(val);
if otf_script.is_not_nil() {
return Some(otf_script.into());
}
Expand All @@ -319,7 +324,8 @@ impl From<LispFontLike> for OptionalScript {

let reg = spec_or_entity.aref(font_property_index::FONT_REGISTRY_INDEX);
if reg.is_symbol() {
let otf_script = unsafe { registry_to_otf(reg) };
let script = Fregistry_to_script(reg);
let otf_script = Fscript_to_otf(script);
return Some(otf_script.into());
}

Expand Down Expand Up @@ -671,7 +677,6 @@ extern "C" fn otf_capability(_font: *mut font) -> LispObject {
pub extern "C" fn shape(lgstring: LispObject, direction: LispObject) -> LispObject {
use core::ops::Range;
use emacs_sys::bindings::font_metrics as FontMetrics;
use emacs_sys::bindings::globals;
use emacs_sys::bindings::CHECK_FONT_GET_OBJECT;
use emacs_sys::globals::QL2R;
use emacs_sys::globals::QR2L;
Expand Down
50 changes: 0 additions & 50 deletions src/wrfont.c

This file was deleted.

3 changes: 0 additions & 3 deletions src/wrgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,4 @@ struct wr_bitmap_record
int height, width, depth;
};

extern Lisp_Object script_to_otf (Lisp_Object otf);
extern Lisp_Object registry_to_otf (Lisp_Object reg);

#endif /* EMACS_WRGUI_H */

0 comments on commit 0146550

Please sign in to comment.