%%
%% This is file `ctex-fontset-mac.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ctex-fontset.dtx  (with options: `fontset,mac')
%% -----------------------------------------------------------------------
%%   Copyright (C) 2003--2026                                            *
%%   CTEX.ORG and any individual authors listed elsewhere in this file.  *
%% -----------------------------------------------------------------------
%%   This work may be distributed and/or modified under the conditions   *
%%   of the LaTeX Project Public License (LPPL), either version 1.3c of  *
%%   this license or (at your option) any later version.                 *
%%   The latest version of this license is in                            *
%%                                                                       *
%%       http://www.latex-project.org/lppl.txt                           *
%%                                                                       *
%%   and version 1.3c or later is part of all distributions of LaTeX     *
%%   version 2008 or later.                                              *
%%                                                                       *
%%   This work has the LPPL maintenance status `maintained'.             *
%% -----------------------------------------------------------------------
\GetIdInfo $Id: ctex-fontset.dtx 2.6.4 2026-07-22 17:12:58 +0800 392183cf Liam <liamhuang0205@gmail.com>$
  {macOS fonts definition (CTEX)}
\ProvidesExplFile{ctex-fontset-mac.def}
  {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
\tl_new:N \g__ctex_macos_ver_tl
\msg_new:nnn { ctex } { macos-version-detect-failed }
  { Cannot~detect~macOS~version.~Falling~back~to~macold~fontset. }
\sys_if_engine_luatex:F
  {
    \ior_new:N \g__ctex_macos_ver_ior
    \bool_new:N \g__ctex_macos_ver_found_bool
    \file_if_exist:nT { /System/Library/CoreServices/SystemVersion.plist }
      {
        \ior_open:Nn \g__ctex_macos_ver_ior
          { /System/Library/CoreServices/SystemVersion.plist }
        \ior_map_inline:Nn \g__ctex_macos_ver_ior
          {
            \bool_if:NTF \g__ctex_macos_ver_found_bool
              {
                \tl_set:Nn \l_tmpa_tl {#1}
                \regex_replace_once:nnN
                  { .*? <string> (\d+) .* } { \1 } \l_tmpa_tl
                \tl_gset:NV \g__ctex_macos_ver_tl \l_tmpa_tl
                \ior_map_break:
              }
              {
                \tl_if_in:nnT {#1} { ProductVersion }
                  { \bool_gset_true:N \g__ctex_macos_ver_found_bool }
              }
          }
        \ior_close:N \g__ctex_macos_ver_ior
      }
    \use_none_delimit_by_q_stop:w
  }
\char_set_catcode_space:n { 32 }
\lua_now:n
  {
    local f = io.open("/System/Library/CoreServices/SystemVersion.plist", "r");
    if f then
      local content = f:read("*a");
      f:close();
      local ver = content:match("ProductVersion.-<string>(.-)</string>");
      if ver then
        local dot = ver:find(".", 1, true);
        local major = dot and ver:sub(1, dot - 1) or ver;
        if major then
          token.set_macro("g__ctex_macos_ver_tl", major, "global");
        end;
      end;
    end
  }
\char_set_catcode_ignore:n { 32 }
\use_none_delimit_by_q_stop:w \q_stop
\file_if_exist:nTF { /System/Library/Fonts/PingFang.ttc }
  { \ctex_file_input:n { ctex-fontset-macnew.def } }
  {
    \tl_if_empty:NTF \g__ctex_macos_ver_tl
      {
        \msg_warning:nn { ctex } { macos-version-detect-failed }
        \ctex_file_input:n { ctex-fontset-macold.def }
      }
      {
        \int_compare:nNnTF { \g__ctex_macos_ver_tl } < { 15 }
          { \ctex_file_input:n { ctex-fontset-macold.def } }
          { \ctex_file_input:n { ctex-fontset-macnew.def } }
      }
  }
%% 
%%
%% End of file `ctex-fontset-mac.def'.
