JFLib

cidmap#

a JFLib library crate -- crate root lib/cidmap/src/lib.rs

cidmap -- the predefined CMaps of Adobe's Chinese, Japanese and Korean character collections
(character code -> CID) and their CID -> Unicode tables

  predefined(name) -> Option<CMap>      a CMap of ISO 32000-1 Table 118 by its name
                                        (90ms-RKSJ-H, GBK-EUC-H, UniJIS-UTF16-V, ...)
  names() -> Vec<&'static str>          the CMaps this crate has (59)
  CMap { name, collection, vertical, codespace }
    code_len(bytes) -> usize            the length of the code at the start (1 to 4 bytes)
    cid(code, len) -> Option<u32>       a code's CID (its CID range, else its notdef range)
    ranges() -> &[CidRange]             every code -> CID range, with what usecmap brings in
  Collection { Gb1, Cns1, Japan1, Korea1 }
    from_ordering(b"Japan1"), ordering(), lang() (zh-Hans, zh-Hant, ja, ko)
  to_unicode(collection) -> ToUnicode   CID -> text (Adobe's Adobe-Japan1-UCS2 and the like)
    get(cid) -> Option<&str>, len()

The data (data/cidmap.bin, made by tools/cidmap_gen.py from Adobe's files, BSD-3-Clause:
licenses/adobe-cmap-resources-LICENSE.md) is one zstd frame per collection, unpacked when a
CMap or table of it is asked for; callers keep what they use.  Identity-H and -V are not here:
their CID is the two-byte code, with no collection.

cidmap crate root#

  • enum Collection one of Adobe's four CJK character collections (Registry "Adobe")
    • Gb1 -- Adobe-GB1: simplified Chinese
    • Cns1 -- Adobe-CNS1: traditional Chinese
    • Japan1 -- Adobe-Japan1: Japanese
    • Korea1 -- Adobe-Korea1: Korean

impl Collection

  • const ALL: [Collection; 4] = [Collection::Gb1, Collection::Cns1, Collection::Japan1, C ...

  • fn from_ordering(o: &[u8]) -> Option<Collection> a CIDSystemInfo's Ordering (with Registry "Adobe")

  • fn ordering(self) -> &'static str

  • fn lang(self) -> &'static str the language tag of its text, for choosing a font (Han characters take its forms)

  • struct CodeSpace a range of the code space: codes of len bytes whose every byte lies between that of lo and hi

    • len: u8
    • lo: [u8; 4]
    • hi: [u8; 4]
  • struct CidRange the codes lo..=hi of len bytes (big-endian, as u32) -> the CIDs from cid on

    • len: u8
    • lo: u32
    • hi: u32
    • cid: u32
  • struct CMap a predefined CMap, with what it takes in by usecmap

    • name: &'static str
    • collection: Collection
    • vertical: bool -- WMode 1: vertical writing
    • codespace: Vec<CodeSpace>

impl CMap

  • fn code_len(&self, b: &[u8]) -> usize the length of the code at the start of b (1 to 4 bytes): the shortest the code space has for it, else the code space's shortest length

  • fn cid(&self, code: u32, len: u8) -> Option<u32> the CID of a code of len bytes: its CID range's, else its notdef range's

  • fn ranges(&self) -> &[CidRange] every code -> CID range, sorted by (len, lo)

  • struct ToUnicode CID -> Unicode text of a collection

impl ToUnicode

  • fn get(&self, cid: u32) -> Option<&str> a CID's text (a character, or a few of them)

  • fn len(&self) -> usize the number of CIDs (with text or not)

  • fn is_empty(&self) -> bool

  • fn predefined(name: &[u8]) -> Option<CMap> a predefined CMap by its name (ISO 32000-1 Table 118: GB-EUC-H to UniKS-UTF16-V)

  • fn names() -> Vec<&'static str> the names of the CMaps this crate has, in the order of the data file

  • fn to_unicode(c: Collection) -> ToUnicode a collection's CID -> Unicode table (empty if the data is damaged, which the tests rule out)

Source: docs/API.md in the JFLib repository.