Skip to content

Commit

Permalink
Introduce Language::Default
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed May 20, 2024
1 parent 60f9989 commit 1b906a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opentype"
version = "0.36.0"
version = "0.36.1"
edition = "2021"
license = "Apache-2.0/MIT"
authors = [
Expand All @@ -17,6 +17,7 @@ keywords = ["font", "opentype", "typeface", "typography"]
exclude = ["tests/fixtures/*"]

[features]
default-language = []
# https://github.com/google/fonts/issues/6888
ignore-incomplete-directories = []
# https://github.com/google/fonts/issues/6894
Expand Down
17 changes: 11 additions & 6 deletions src/layout/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@ table! {
}

macro_rules! implement {
($($tag:literal => $name:literal => $variant:ident => $codes:literal,)*) => (
($(
$(#[$attribute:meta])*
$tag:literal => $name:literal => $variant:ident => $codes:literal,
)*) => (
/// A language system.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum Language {
$(#[doc = $name] $variant,)*
$($(#[$attribute])* #[doc = $name] $variant,)*
Other(Tag),
}

impl Language {
/// Create an instance from a tag.
pub fn from_tag(tag: &Tag) -> Self {
match &**tag {
$($tag => Self::$variant,)*
$($(#[$attribute])* $tag => Self::$variant,)*
_ => Self::Other(tag.clone()),
}
}
Expand All @@ -45,7 +48,7 @@ macro_rules! implement {
pub fn codes(&self) -> impl Iterator<Item = &'static str> {
let filter = |code: &&str| !code.is_empty();
let value = match self {
$(Language::$variant => $codes,)*
$($(#[$attribute])* Language::$variant => $codes,)*
_ => "",
};
value.split(", ").filter(filter)
Expand All @@ -54,7 +57,7 @@ macro_rules! implement {
/// Return the name.
pub fn name(&self) -> Option<&'static str> {
match self {
$(Self::$variant => Some($name),)*
$($(#[$attribute])* Self::$variant => Some($name),)*
_ => None,
}
}
Expand All @@ -63,7 +66,7 @@ macro_rules! implement {
impl From<Language> for Tag {
fn from(language: Language) -> Self {
match language {
$(Language::$variant => Tag(*$tag),)*
$($(#[$attribute])* Language::$variant => Tag(*$tag),)*
Language::Other(tag) => tag,
}
}
Expand Down Expand Up @@ -181,6 +184,8 @@ implement! {
b"DAR " => "Dargwa" => Dargwa => "dar",
b"DAX " => "Dayi" => Dayi => "dax",
b"DCR " => "Woods Cree" => WoodsCree => "cwd",
#[cfg(feature = "default-language")]
b"DFLT" => "Default" => Default => "",
b"DEU " => "German" => German => "deu",
b"DGO " => "Dogri" => Dogri => "dgo",
b"DGR " => "Dogri" => DogriMacrolanguage => "doi",
Expand Down

0 comments on commit 1b906a6

Please sign in to comment.