Skip to content

Commit

Permalink
Implement GlyphNameVec (fixes last commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlcctrlv committed Dec 25, 2022
1 parent 60804fb commit dfaf4d1
Show file tree
Hide file tree
Showing 23 changed files with 5,058 additions and 77 deletions.
2 changes: 2 additions & 0 deletions gendata/aglfn_fn1def.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fn glyph_name_strict<'a>(c: char) -> Option<Cow<'a, str>> {
match c as u32 {
3 changes: 3 additions & 0 deletions gendata/aglfn_fn1foot.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ => None,
}
}
16 changes: 16 additions & 0 deletions gendata/aglfn_fn2.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@include "../gendata/join.awk"
@include "../gendata/rust_arr_join.awk"
# NOTE: This script must remain compatible with BSD awk and GNU awk

BEGIN {
FS=";"
}

# /^[0-9A-F]{4};/ should work but FreeBSD awk as of 12.1 doesn't support {}
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=54410
/^[0-9A-F ]+;/ {
rust_arr_split_chars($1, hex);
joined=rust_arr_join(hex);

printf("%12c%s => Some(Cow::from(\"%s\")),\n", " ", arr, $2, "")
}
2 changes: 2 additions & 0 deletions gendata/aglfn_fn2def.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fn glyph_name_vec<'a, S: AsRef<[char]>>(s: S) -> Option<Cow<'a, str>> {
match s.as_ref().into_iter().map(|c|*c as u32).collect::<Vec<u32>>().as_slice() {
3 changes: 3 additions & 0 deletions gendata/aglfn_fn2foot.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ => None,
}
}
11 changes: 7 additions & 4 deletions gendata/aglfn_footer.rs.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
_ => None,

impl<'a> GlyphNameStrict<'a> for AdobeGlyphListForNewFonts {
fn glyph_name_strict(c: char) -> Option<Cow<'a, str>> {
self::glyph_name_strict(c)
}
}

impl<'a> GlyphNameOpt<'a> for AdobeGlyphListForNewFonts {
fn glyph_name_opt(c: char) -> Option<Cow<'a, str>> {
self::glyph_name_opt(c)
impl<'a> GlyphNameVec<'a> for AdobeGlyphListForNewFonts {
fn glyph_name_vec<'b, S: AsRef<[char]>>(s: S) -> Option<Cow<'a, str>> {
self::glyph_name_vec(s)
}
}
4 changes: 1 addition & 3 deletions gendata/aglfn_header.rs.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub struct AdobeGlyphListForNewFonts;

use std::borrow::Cow;
use super::GlyphNameOpt;
use crate::traits::{GlyphNameStrict, GlyphNameVec};

fn glyph_name_opt<'a>(c: char) -> Option<Cow<'a, str>> {
match c as u32 {
2 changes: 1 addition & 1 deletion gendata/glyphlist.awk
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ BEGIN {

# /^[0-9A-F]{4};/ should work but FreeBSD awk as of 12.1 doesn't support {}
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=54410
/^[0-9A-Za-z._-]+;[0-9A-F]+/ { printf("%12c0x%s => Some(Cow::from(\"%s\")), %"(12+maxglyphname-length($1)-(length(substr($2, 4, -1))))"s%s\n", " ", substr($2, 0, 4), $1, "", "// "$3) }
/^[0-9A-Za-z._-]+;[0-9A-F ]+/ { printf("%12c0x%s => Some(Cow::from(\"%s\")), %"(12+maxglyphname-length($1)-(length(substr($2, 4, -1))))"s%s\n", " ", substr($2, 0, 4), $1, "", "// "$3) }
2 changes: 2 additions & 0 deletions gendata/glyphlist_fn1def.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fn glyph_name_strict<'a>(c: char) -> Option<Cow<'a, str>> {
match c as u32 {
3 changes: 3 additions & 0 deletions gendata/glyphlist_fn1foot.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ => None,
}
}
16 changes: 16 additions & 0 deletions gendata/glyphlist_fn2.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@include "../gendata/join.awk"
@include "../gendata/rust_arr_join.awk"
# NOTE: This script must remain compatible with BSD awk and GNU awk

BEGIN {
FS=";"
}

# /^[0-9A-F]{4};/ should work but FreeBSD awk as of 12.1 doesn't support {}
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=54410
/^[0-9A-Za-z._-]+;[0-9A-F ]+/ {
rust_arr_split_chars($2, hex);
joined=rust_arr_join(hex);

printf("%12c%s => Some(Cow::from(\"%s\")),\n", " ", arr, $1, "")
}
2 changes: 2 additions & 0 deletions gendata/glyphlist_fn2def.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fn glyph_name_vec<'a, S: AsRef<[char]>>(s: S) -> Option<Cow<'a, str>> {
match s.as_ref().into_iter().map(|c|*c as u32).collect::<Vec<u32>>().as_slice() {
3 changes: 3 additions & 0 deletions gendata/glyphlist_fn2foot.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ => None,
}
}
11 changes: 7 additions & 4 deletions gendata/glyphlist_footer.rs.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
_ => None,

impl<'a> GlyphNameStrict<'a> for LegacyAdobeGlyphList {
fn glyph_name_strict(c: char) -> Option<Cow<'a, str>> {
self::glyph_name_strict(c)
}
}

impl<'a> GlyphNameOpt<'a> for LegacyAdobeGlyphList {
fn glyph_name_opt(c: char) -> Option<Cow<'a, str>> {
self::glyph_name_opt(c)
impl<'a> GlyphNameVec<'a> for LegacyAdobeGlyphList {
fn glyph_name_vec<'b, S: AsRef<[char]>>(s: S) -> Option<Cow<'a, str>> {
self::glyph_name_vec(s)
}
}
5 changes: 1 addition & 4 deletions gendata/glyphlist_header.rs.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
pub struct LegacyAdobeGlyphList;

use std::borrow::Cow;
use super::GlyphNameOpt;

fn glyph_name_opt<'a>(c: char) -> Option<Cow<'a, str>> {
match c as u32 {
use crate::traits::{GlyphNameStrict, GlyphNameVec};
2 changes: 2 additions & 0 deletions gendata/header_common.rs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#![allow(dead_code)]
#![allow(unreachable_patterns)]
14 changes: 14 additions & 0 deletions gendata/join.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# join.awk --- join an array into a string
# https://www.gnu.org/software/gawk/manual/html_node/Join-Function.html

function join(array, start, end, sep, result, i)
{
if (sep == "")
sep = " "
else if (sep == SUBSEP) # magic value
sep = ""
result = array[start]
for (i = start + 1; i <= end; i++)
result = result sep array[i]
return result
}
12 changes: 12 additions & 0 deletions gendata/rust_arr_join.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function rust_arr_split_chars(s, hex) {
split(s, hex, " ");
for (i = 1; i <= length(hex); i++) {
hex[i] = ("0x"hex[i]"u32");
}
}

function rust_arr_join(a) {
joined=join(a, 1, length(a), ", ");
arr="&["joined"]";
return arr;
}
8 changes: 7 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ aglfn.rs glyphlist.rs:
input=$$(echo $@ | sed -e 's@^@agl-aglfn/@; s/\.rs$$/.txt/;') &&\
filename=$$(echo $$input | sed -e 's@agl-aglfn/@@; s@\.txt@@;') &&\
echo $$filename &&\
cat ../gendata/$${filename}_abovecomment.rs.template > ${.TARGET} &&\
cat ../gendata/header_common.rs.template > ${.TARGET} &&\
cat ../gendata/$${filename}_abovecomment.rs.template >> ${.TARGET} &&\
awk -f ../gendata/comments.awk -v midcomment=../gendata/$${filename}_midcomment.rs.template < ../$$input >> ${.TARGET} &&\
cat ../gendata/$${filename}_header.rs.template >> ${.TARGET} &&\
([ -f ../gendata/$${filename}_fn1def.rs.template ] && cat ../gendata/$${filename}_fn1def.rs.template >> ${.TARGET} || true) &&\
LONGEST=$$(sort ../$$input | $$AWK -f ../gendata/longest_$${filename}.awk) &&\
sort ../$$input | $$AWK -f ../gendata/$${filename}.awk -v maxglyphname=$$LONGEST >> $${filename}.rs &&\
([ -f ../gendata/$${filename}_fn1foot.rs.template ] && cat ../gendata/$${filename}_fn1foot.rs.template >> ${.TARGET} || true) &&\
([ -f ../gendata/$${filename}_fn2def.rs.template ] && cat ../gendata/$${filename}_fn2def.rs.template >> ${.TARGET} || true) &&\
([ -f ../gendata/$${filename}_fn2.awk ] && sort ../$$input | gawk -f ../gendata/$${filename}_fn2.awk -v maxglyphname=$$LONGEST >> $${filename}.rs || true) &&\
([ -f ../gendata/$${filename}_fn2foot.rs.template ] && cat ../gendata/$${filename}_fn2foot.rs.template >> ${.TARGET} || true) &&\
cat ../gendata/$${filename}_footer.rs.template >> $${filename}.rs\
)

Expand Down
Loading

0 comments on commit dfaf4d1

Please sign in to comment.