ttf_name_decoder/
platform.rs

1use std::convert::{Into, TryFrom};
2
3/// ref. <https://docs.microsoft.com/en-us/typography/opentype/spec/name#platform-ids>
4#[derive(Debug, PartialEq, Clone, Copy)]
5pub enum PlatformId {
6    Unicode,
7    Macintosh,
8    ISO,
9    Windows,
10    Custom,
11}
12
13impl TryFrom<u16> for PlatformId {
14    type Error = crate::Error;
15    fn try_from(id: u16) -> crate::Result<Self> {
16        match id {
17            0 => Ok(PlatformId::Unicode),
18            1 => Ok(PlatformId::Macintosh),
19            2 => Ok(PlatformId::ISO),
20            3 => Ok(PlatformId::Windows),
21            4 => Ok(PlatformId::Custom),
22            _ => Err(crate::Error::UnsupportedPlatform),
23        }
24    }
25}
26
27impl Into<u16> for PlatformId {
28    fn into(self) -> u16 {
29        match self {
30            PlatformId::Unicode => 0,
31            PlatformId::Macintosh => 1,
32            PlatformId::ISO => 2,
33            PlatformId::Windows => 3,
34            PlatformId::Custom => 4,
35        }
36    }
37}