use super::cmap::RawCMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(dead_code)]
pub(crate) enum Scheme {
OneByte,
TwoBytes,
MixedTwoBytes,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Kind {
Single,
Range,
}
static GB1_BLOB: &[u8] = include_bytes!("cmap_data/gb1.bin");
static GB1: &[RawCMap] = &[
RawCMap {
name: "GB-EUC-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 254), (0, 0)],
kind: Kind::Range,
off: 0,
records: 90,
use_index: -1,
},
RawCMap {
name: "GB-EUC-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 254), (0, 0)],
kind: Kind::Range,
off: 270,
records: 20,
use_index: 0,
},
RawCMap {
name: "GBpc-EUC-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 252), (0, 0)],
kind: Kind::Range,
off: 330,
records: 91,
use_index: -1,
},
RawCMap {
name: "GBpc-EUC-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 252), (0, 0)],
kind: Kind::Range,
off: 603,
records: 20,
use_index: 2,
},
RawCMap {
name: "GBK-EUC-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 663,
records: 4071,
use_index: -1,
},
RawCMap {
name: "GBK-EUC-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 12876,
records: 20,
use_index: 4,
},
RawCMap {
name: "GBKp-EUC-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 12936,
records: 4070,
use_index: 4,
},
RawCMap {
name: "GBKp-EUC-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 25146,
records: 20,
use_index: 6,
},
RawCMap {
name: "GBK2K-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 25206,
records: 4071,
use_index: 4,
},
RawCMap {
name: "GBK2K-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 37419,
records: 41,
use_index: 8,
},
RawCMap {
name: "UniGB-UCS2-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 37542,
records: 13825,
use_index: -1,
},
RawCMap {
name: "UniGB-UCS2-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 79017,
records: 24,
use_index: 10,
},
RawCMap {
name: "UniGB-UTF16-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 37542,
records: 13825,
use_index: -1,
},
RawCMap {
name: "UniGB-UTF16-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 79017,
records: 24,
use_index: 12,
},
];
static CNS1_BLOB: &[u8] = include_bytes!("cmap_data/cns1.bin");
static CNS1: &[RawCMap] = &[
RawCMap {
name: "B5pc-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 252), (0, 0)],
kind: Kind::Range,
off: 0,
records: 247,
use_index: -1,
},
RawCMap {
name: "B5pc-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 252), (0, 0)],
kind: Kind::Range,
off: 741,
records: 12,
use_index: 0,
},
RawCMap {
name: "HKscs-B5-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(136, 254), (0, 0)],
kind: Kind::Range,
off: 777,
records: 1210,
use_index: -1,
},
RawCMap {
name: "HKscs-B5-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(136, 254), (0, 0)],
kind: Kind::Range,
off: 4407,
records: 13,
use_index: 2,
},
RawCMap {
name: "ETen-B5-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 254), (0, 0)],
kind: Kind::Range,
off: 4446,
records: 254,
use_index: -1,
},
RawCMap {
name: "ETen-B5-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 254), (0, 0)],
kind: Kind::Range,
off: 5208,
records: 13,
use_index: 4,
},
RawCMap {
name: "ETenms-B5-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 254), (0, 0)],
kind: Kind::Range,
off: 5247,
records: 1,
use_index: 4,
},
RawCMap {
name: "ETenms-B5-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 254), (0, 0)],
kind: Kind::Range,
off: 5250,
records: 18,
use_index: 6,
},
RawCMap {
name: "UniCNS-UCS2-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 5304,
records: 16418,
use_index: -1,
},
RawCMap {
name: "UniCNS-UCS2-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 54558,
records: 13,
use_index: 8,
},
RawCMap {
name: "UniCNS-UTF16-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Single,
off: 54597,
records: 14557,
use_index: -1,
},
RawCMap {
name: "UniCNS-UTF16-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 54558,
records: 13,
use_index: 10,
},
];
static JAPAN1_BLOB: &[u8] = include_bytes!("cmap_data/japan1.bin");
static JAPAN1: &[RawCMap] = &[
RawCMap {
name: "83pv-RKSJ-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 0,
records: 222,
use_index: -1,
},
RawCMap {
name: "90ms-RKSJ-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 666,
records: 171,
use_index: -1,
},
RawCMap {
name: "90ms-RKSJ-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 1179,
records: 78,
use_index: 1,
},
RawCMap {
name: "90msp-RKSJ-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 1413,
records: 170,
use_index: 1,
},
RawCMap {
name: "90msp-RKSJ-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 1923,
records: 78,
use_index: 3,
},
RawCMap {
name: "90pv-RKSJ-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 2157,
records: 263,
use_index: -1,
},
RawCMap {
name: "Add-RKSJ-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 2946,
records: 635,
use_index: -1,
},
RawCMap {
name: "Add-RKSJ-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 4851,
records: 57,
use_index: 6,
},
RawCMap {
name: "EUC-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(142, 142), (161, 254)],
kind: Kind::Range,
off: 5022,
records: 120,
use_index: -1,
},
RawCMap {
name: "EUC-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(142, 142), (161, 254)],
kind: Kind::Range,
off: 5382,
records: 27,
use_index: 8,
},
RawCMap {
name: "Ext-RKSJ-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 5463,
records: 665,
use_index: 6,
},
RawCMap {
name: "Ext-RKSJ-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 159), (224, 252)],
kind: Kind::Range,
off: 7458,
records: 39,
use_index: 10,
},
RawCMap {
name: "H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 7575,
records: 118,
use_index: -1,
},
RawCMap {
name: "V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 7929,
records: 27,
use_index: 12,
},
RawCMap {
name: "UniJIS-UCS2-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Single,
off: 8010,
records: 9772,
use_index: -1,
},
RawCMap {
name: "UniJIS-UCS2-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Single,
off: 27554,
records: 251,
use_index: 14,
},
RawCMap {
name: "UniJIS-UCS2-HW-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 28056,
records: 4,
use_index: 14,
},
RawCMap {
name: "UniJIS-UCS2-HW-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 28068,
records: 199,
use_index: 16,
},
RawCMap {
name: "UniJIS-UTF16-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Single,
off: 8010,
records: 9772,
use_index: -1,
},
RawCMap {
name: "UniJIS-UTF16-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Single,
off: 27554,
records: 251,
use_index: 18,
},
];
static KOREA1_BLOB: &[u8] = include_bytes!("cmap_data/korea1.bin");
static KOREA1: &[RawCMap] = &[
RawCMap {
name: "KSC-EUC-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 254), (0, 0)],
kind: Kind::Range,
off: 0,
records: 467,
use_index: -1,
},
RawCMap {
name: "KSC-EUC-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 254), (0, 0)],
kind: Kind::Range,
off: 1401,
records: 16,
use_index: 0,
},
RawCMap {
name: "KSCms-UHC-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 1449,
records: 675,
use_index: 0,
},
RawCMap {
name: "KSCms-UHC-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 3474,
records: 16,
use_index: 2,
},
RawCMap {
name: "KSCms-UHC-HW-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 3522,
records: 675,
use_index: -1,
},
RawCMap {
name: "KSCms-UHC-HW-V",
wmode: 1,
scheme: Scheme::MixedTwoBytes,
lead: [(129, 254), (0, 0)],
kind: Kind::Range,
off: 5547,
records: 16,
use_index: 4,
},
RawCMap {
name: "KSCpc-EUC-H",
wmode: 0,
scheme: Scheme::MixedTwoBytes,
lead: [(161, 253), (0, 0)],
kind: Kind::Range,
off: 5595,
records: 509,
use_index: 0,
},
RawCMap {
name: "UniKS-UCS2-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 7122,
records: 8394,
use_index: -1,
},
RawCMap {
name: "UniKS-UCS2-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 32304,
records: 18,
use_index: 7,
},
RawCMap {
name: "UniKS-UTF16-H",
wmode: 0,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Single,
off: 32358,
records: 158,
use_index: 7,
},
RawCMap {
name: "UniKS-UTF16-V",
wmode: 1,
scheme: Scheme::TwoBytes,
lead: [(0, 0), (0, 0)],
kind: Kind::Range,
off: 32304,
records: 18,
use_index: 9,
},
];
pub(crate) static CHARSETS: &[(&[RawCMap], &[u8])] = &[
(GB1, GB1_BLOB),
(CNS1, CNS1_BLOB),
(JAPAN1, JAPAN1_BLOB),
(KOREA1, KOREA1_BLOB),
];
static GB1_UNI: &[u8] = include_bytes!("cmap_data/gb1_uni.bin");
static CNS1_UNI: &[u8] = include_bytes!("cmap_data/cns1_uni.bin");
static JAPAN1_UNI: &[u8] = include_bytes!("cmap_data/japan1_uni.bin");
static KOREA1_UNI: &[u8] = include_bytes!("cmap_data/korea1_uni.bin");
pub(crate) fn cid2uni_table(charset: crate::font::system::Charset) -> Option<&'static [u8]> {
use crate::font::system::Charset;
match charset {
Charset::ChineseSimplified => Some(GB1_UNI),
Charset::ChineseTraditional => Some(CNS1_UNI),
Charset::ShiftJis => Some(JAPAN1_UNI),
Charset::Hangul => Some(KOREA1_UNI),
_ => None,
}
}
pub fn cid_to_unicode(charset: crate::font::system::Charset, cid: u32) -> Option<char> {
let table = cid2uni_table(charset)?;
let i = (cid as usize).checked_mul(2)?;
let pair = table.get(i..i + 2)?;
let u = u16::from_le_bytes([pair[0], pair[1]]);
if u == 0x0000 || u == 0xFFFD {
return None;
}
char::from_u32(u as u32)
}