From 8cb9a6d3f6463321cdaf49a3cedb854b09c51275 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Thu, 9 Jul 2020 11:46:07 +0200 Subject: [PATCH] Add support for the libertinus family of fonts (#11899) File format change. --- lib/chkconfig.ltx | 1 + lib/doc/LaTeXConfig.lyx | 77 ++++++++++++++++++++++++++++++++++++++++- lib/latexfonts | 45 ++++++++++++++++++++++++ lib/lyx2lyx/lyx_2_4.py | 77 +++++++++++++++++++++++++++++++++++++++-- src/version.h | 4 +-- 5 files changed, 199 insertions(+), 5 deletions(-) diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index 1ab93b4f65..8fb6800728 100644 --- a/lib/chkconfig.ltx +++ b/lib/chkconfig.ltx @@ -519,6 +519,7 @@ \TestPackage{libertineMono-type1} \TestPackage{libertineMono} \TestPackage{libertineRoman} +\TestPackage{libertinus} \TestPackage{lmodern} \TestPackage{luximono} \TestPackage{mathdesign}% for Roman fonts diff --git a/lib/doc/LaTeXConfig.lyx b/lib/doc/LaTeXConfig.lyx index bfaad603d7..9532d33091 100644 --- a/lib/doc/LaTeXConfig.lyx +++ b/lib/doc/LaTeXConfig.lyx @@ -1,5 +1,5 @@ #LyX 2.4 created this file. For more info see https://www.lyx.org/ -\lyxformat 595 +\lyxformat 597 \begin_document \begin_header \save_transient_properties true @@ -1181,6 +1181,81 @@ Libertine Mono \emph default typewriter font. This font is shipped with libertine font package as of February 2013. +\change_inserted -712698321 1594287772 + +\end_layout + +\begin_layout Subsection +Libertin +\change_deleted -712698321 1594287776 +e Mono +\change_inserted -712698321 1594287776 +us +\change_unchanged + +\end_layout + +\begin_layout Description +Found: +\begin_inset Info +type "package" +arg "libertinus" +\end_inset + + +\end_layout + +\begin_layout Description +CTAN: +\family typewriter +fonts/libertin +\change_inserted -712698321 1594287840 +us +\change_deleted -712698321 1594287840 +e +\change_unchanged +/ +\end_layout + +\begin_layout Description +Notes: The +\family sans +libertin +\change_deleted -712698321 1594287845 +eMono-type1 +\change_inserted -712698321 1594287845 +us +\change_unchanged + +\family default + package provides support for the +\emph on +Libertin +\change_deleted -712698321 1594287851 +e Mono +\emph default + typewriter font +\change_inserted -712698321 1594287856 + +\emph on +us +\emph default + family of fonts +\change_deleted -712698321 1594287920 +. + This font is shipped with libertine font package as of February 2013 +\change_inserted -712698321 1594287938 +, a derivate of the +\emph on +Libertine +\emph default + and +\emph on +Biolinum +\emph default + family of fonts with dome extra features +\change_unchanged +. \end_layout \begin_layout Subsection diff --git a/lib/latexfonts b/lib/latexfonts index e3b134f10f..6553f4e187 100644 --- a/lib/latexfonts +++ b/lib/latexfonts @@ -318,6 +318,25 @@ AltFont libertine-legacy Package libertine EndFont +Font libertinus + GuiName "Libertinus" + Family rm + OsfOption osf + Package libertinus + PackageOptions serif + CompleteFont libertinus-full + MoreOptions 1 + +EndFont + +AltFont libertinus-full + GuiName "Libertine" + Family rm + OsfOption osf + Package libertinus + MoreOptions 1 +EndFont + Font lmodern GuiName "Latin Modern Roman" Family rm @@ -941,6 +960,24 @@ Font kurierlc SwitchDefault 1 EndFont +Font LibertinusSans-LF + GuiName "Libertinus Sans" + Family sf + Requires libertinus + SwitchDefault 1 + OsfFont LibertinusSans-OsF + OsfFontOnly 1 + ScaleCommand \renewcommand*{\LibertinusSans@scale}{$$val} +EndFont + +AltFont LibertinusSans-OsF + GuiName "Libertinus Sans" + Family sf + Requires libertinus + SwitchDefault 1 + ScaleCommand \renewcommand*{\LibertinusSans@scale}{$$val} +EndFont + Font lmss GuiName "Latin Modern Sans" Family sf @@ -1139,6 +1176,14 @@ AltFont libertine-mono-type1 Package libertineMono-type1 EndFont +Font LibertinusMono-TLF + GuiName "Libertinus Mono" + Family tt + Requires libertinus + SwitchDefault 1 + ScaleCommand \renewcommand*{\LibertinusMono@scale}{$$val} +EndFont + Font lmtt GuiName "Latin Modern Typewriter" Family tt diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index d4e8b0a7b5..ea6d0bcbf9 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -194,6 +194,8 @@ def createFontMapping(fontlist): 'FiraSansUltralight,ultralight'], "sans", "sf", "FiraSans", "scaled", "lf", "true") fm.expandFontMapping(['FiraMono'], "typewriter", "tt", "FiraMono", "scaled", "lf", "true") + elif font == 'libertinus': + fm.expandFontMapping(['libertinus,serif'], "roman", None, "libertinus", None, "osf") return fm def convert_fonts(document, fm, osfoption = "osf"): @@ -3849,6 +3851,75 @@ def revert_line_vspaces(document): subst = put_cmd_in_ert(insets[inset]) document.body[i : end + 1] = subst +def convert_libertinus_rm_fonts(document): + """Handle Libertinus serif fonts definition to LaTeX""" + + if not get_bool_value(document.header, "\\use_non_tex_fonts"): + fm = createFontMapping(['Libertinus']) + convert_fonts(document, fm) + +def revert_libertinus_rm_fonts(document): + """Revert Libertinus serif font definition to LaTeX""" + + if not get_bool_value(document.header, "\\use_non_tex_fonts"): + fontmap = dict() + fm = createFontMapping(['libertinus']) + if revert_fonts(document, fm, fontmap): + add_preamble_fonts(document, fontmap) + +def revert_libertinus_sftt_fonts(document): + " Revert Libertinus sans and tt font definitions to LaTeX " + + if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1: + preamble = "" + # first sf font + i = find_token(document.header, "\\font_sans \"LibertinusSans-LF\"", 0) + if i != -1: + j = find_token(document.header, "\\font_sans_osf true", 0) + if j != -1: + add_to_preamble(document, ["\\renewcommand{\\sfdefault}{LibertinusSans-OsF}"]) + document.header[j] = "\\font_sans_osf false" + else: + add_to_preamble(document, ["\\renewcommand{\\sfdefault}{LibertinusSans-LF}"]) + document.header[i] = document.header[i].replace("LibertinusSans-LF", "default") + sf_scale = 100.0 + sfval = find_token(document.header, "\\font_sf_scale", 0) + if sfval == -1: + document.warning("Malformed LyX document: Missing \\font_sf_scale.") + else: + sfscale = document.header[sfval].split() + val = sfscale[1] + sfscale[1] = "100" + document.header[sfval] = " ".join(sfscale) + try: + # float() can throw + sf_scale = float(val) + except: + document.warning("Invalid font_sf_scale value: " + val) + if sf_scale != "100.0": + add_to_preamble(document, ["\\renewcommand*{\\LibertinusSans@scale}{" + str(sf_scale / 100.0) + "}"]) + # now tt font + i = find_token(document.header, "\\font_typewriter \"LibertinusMono-TLF\"", 0) + if i != -1: + add_to_preamble(document, ["\\renewcommand{\\ttdefault}{LibertinusMono-TLF}"]) + document.header[i] = document.header[i].replace("LibertinusMono-TLF", "default") + tt_scale = 100.0 + ttval = find_token(document.header, "\\font_tt_scale", 0) + if ttval == -1: + document.warning("Malformed LyX document: Missing \\font_tt_scale.") + else: + ttscale = document.header[ttval].split() + val = ttscale[1] + ttscale[1] = "100" + document.header[ttval] = " ".join(ttscale) + try: + # float() can throw + tt_scale = float(val) + except: + document.warning("Invalid font_tt_scale value: " + val) + if tt_scale != "100.0": + add_to_preamble(document, ["\\renewcommand*{\\LibertinusMono@scale}{" + str(tt_scale / 100.0) + "}"]) + ## # Conversion hub @@ -3907,10 +3978,12 @@ convert = [ [593, [convert_counter_maintenance]], [594, []], [595, []], - [596, [convert_parskip]] + [596, [convert_parskip]], + [597, [convert_libertinus_rm_fonts]] ] -revert = [[595, [revert_parskip,revert_line_vspaces]], +revert = [[595, [revert_libertinus_rm_fonts,revert_libertinus_sftt_fonts]], + [595, [revert_parskip,revert_line_vspaces]], [594, [revert_ams_spaces]], [593, [revert_counter_inset]], [592, [revert_counter_maintenance]], diff --git a/src/version.h b/src/version.h index b8d30fd6f5..b6e5600cf5 100644 --- a/src/version.h +++ b/src/version.h @@ -32,8 +32,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 596 // spitz: parskip -#define LYX_FORMAT_TEX2LYX 596 +#define LYX_FORMAT_LYX 597 // spitz: libertinus fonts +#define LYX_FORMAT_TEX2LYX 597 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER -- 2.39.5