%%
%% jlreq-deluxe.sty
%%
%% Copyright 2019-2021 Yukimasa Morimi (h20y6m)
%%   GitHub:   https://github.com/h20y6m
%%
%% This package is distributed under the MIT License.
%%

% --------------------------------------------------

\NeedsTeXFormat{pLaTeX2e}
\RequirePackage{expl3}[2019-05-03]
\ProvidesExplPackage {jlreq-deluxe} {2021-03-13} {0.4.0}
  {Multi-weight Japanese font for jlreq class}

% --------------------------------------------------
% load packeges

\RequirePackage{l3keys2e}

% --------------------------------------------------
% Variables

\tl_new:N \l__jldx_prefix_tl
\tl_new:N \l__jldx_scale_tl
\bool_new:N \l__jldx_deluxe_bool
\bool_new:N \l__jldx_jismmiv_bool
\bool_new:N \l__jldx_uplatex_bool
\bool_new:N \l__jldx_hanging_punctuation_bool
\bool_new:N \l__jldx_zenkakunibu_nibu_bool

% --------------------------------------------------
% Messages

\msg_new:nnn { jlreq-deluxe } { option-not-available }
  { The~`#1'~option~is~not~available. }

% --------------------------------------------------
% Helpers

\prg_new_conditional:Npnn \__jldx_if_class_loaded:n #1 { p , T , F , TF }
  {
    \@ifclassloaded {#1}
      { \prg_return_true: }
      { \prg_return_false: }
  }

% --------------------------------------------------
%% Options

% options for japanese-otf package
\keys_define:nn { jlreq-deluxe }
  {
    deluxe .bool_set:N = \l__jldx_deluxe_bool,
    burasage .code:n =
      {
        \msg_error:nnn { jlreq-deluxe } { option-not-available }
          { burasage }
      },
    jis2004 .bool_set:N = \l__jldx_jismmiv_bool,
    uplatex .bool_set:N = \l__jldx_uplatex_bool,
    scale .tl_set:N = \l__jldx_scale_tl,
  }

% options for this package
\keys_define:nn { jlreq-deluxe }
  {
    hanging_punctuation .bool_set:N = \l__jldx_hanging_punctuation_bool,
    zenkakunibu_nibu .bool_set:N = \l__jldx_zenkakunibu_nibu_bool,
  }

% unknown option
\keys_define:nn { jlreq-deluxe }
  {
    unknown .code:n =
      {
        \PassOptionsToPackage { \CurrentOption } { pxjodel }
      }
  }

% set default options
\keys_set:nn { jlreq-deluxe }
  {
    deluxe = true,
    jis2004 = true,
  }

% process options
\ProcessKeysOptions { jlreq-deluxe }

% --------------------------------------------------
%% jlreq parameters

\__jldx_if_class_loaded:nT { jlreq }
  {
    % uplatex
    \sys_if_engine_uptex:T
      {
        \bool_set_true:N \l__jldx_uplatex_bool
      }
    % scale
    \jlreq@divide { \jlreq@jafontsize } { \jlreq@fontsize }
    \tl_set:Nx \l__jldx_scale_tl
      {
        \strip@pt \jlreq@resultdimen
      }
    % hanging_punctuation
    \bool_set:Nn \l__jldx_zenkakunibu_nibu_bool
      {
        \str_if_eq_p:no { zenkakunibu_nibu } { \jlreq@open@bracket@pos }
      }
    % zenkakunibu_nibu
    \bool_set:Nn \l__jldx_hanging_punctuation_bool
      {
        \legacy_if_p:n { jlreq@burasage }
      }
  }

% --------------------------------------------------
%% prefix

\tl_set:Nn \l__jldx_prefix_tl { jlreq }

% zenkakunibu_nibu
\bool_if:NT \l__jldx_zenkakunibu_nibu_bool
  {
    \tl_put_left:Nn \l__jldx_prefix_tl { z }
  }
% hanging_punctuation
\bool_if:NT \l__jldx_hanging_punctuation_bool
  {
    \tl_put_left:Nn \l__jldx_prefix_tl { b }
  }

% --------------------------------------------------
% pxjodel

% prefix
\PassOptionsToPackage { prefix = \l__jldx_prefix_tl } { pxjodel }

% deluxe
\bool_if:NT \l__jldx_deluxe_bool
  {
    \PassOptionsToPackage { deluxe } { pxjodel }
  }

% jis2004
\bool_if:NT \l__jldx_jismmiv_bool
  {
    \PassOptionsToPackage { jis2004 } { pxjodel }
  }

% uplatex
\bool_if:NT \l__jldx_uplatex_bool
  {
    \PassOptionsToPackage { uplatex } { pxjodel }
  }

% scale
\tl_if_empty:NF \l__jldx_scale_tl
  {
    \PassOptionsToPackage { scale = \l__jldx_scale_tl } { pxjodel }
  }

% load pxjodel package
\RequirePackage{pxjodel}
