From d18dff22b5583a126d37f770616d3076a72f99c4 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sat, 13 Feb 2021 04:34:03 +0100 Subject: [PATCH] DocBook: add the DocBookNoFontInside layout configuration. --- autotests/export/docbook/author_plus_font.lyx | 277 ++++++++++++++++++ autotests/export/docbook/author_plus_font.xml | 27 ++ lib/layouts/stdtitle.inc | 3 +- lib/scripts/layout2layout.py | 9 +- src/Layout.cpp | 9 +- src/Layout.h | 4 + src/Paragraph.cpp | 44 +-- src/TextClass.cpp | 2 +- src/insets/InsetLayout.cpp | 5 + src/insets/InsetLayout.h | 4 + 10 files changed, 358 insertions(+), 26 deletions(-) create mode 100644 autotests/export/docbook/author_plus_font.lyx create mode 100644 autotests/export/docbook/author_plus_font.xml diff --git a/autotests/export/docbook/author_plus_font.lyx b/autotests/export/docbook/author_plus_font.lyx new file mode 100644 index 0000000000..3f3693ddd4 --- /dev/null +++ b/autotests/export/docbook/author_plus_font.lyx @@ -0,0 +1,277 @@ +#LyX 2.4 created this file. For more info see https://www.lyx.org/ +\lyxformat 606 +\begin_document +\begin_header +\save_transient_properties true +\origin unavailable +\textclass book +\begin_preamble +\date{Janvier 2021} + + +%espacement horizontal contrôlé TDM/TOC empêche chevauchement +\usepackage{tocloft} +\setlength{\cftfignumwidth}{3.5em} +\cftsetindents{section}{0em}{2.8em} +\cftsetindents{subsection}{2.4em}{3.7em} + +% +\usepackage{xcolor} +\colorlet{BLUE}{blue} + +%liens en gris TDM/TDF/TDT + hyperlien + citations biblio +\hypersetup{urlcolor=gray} +\hypersetup{linkcolor=gray} +\hypersetup{citecolor=gray} + +% ??? +\usepackage{alltt} +\usepackage{upquote} +\newcommand{\nospace}[1]{\texttt{#1}} + +% faire apparaître les chapitres* +\let\newchapter\chapter +\long\def\chapter{\addtocontents{toc}{\penalty-3000}\newchapter} + +\usepackage{newtxmath} + +% tableau dans encadré TeX +\usepackage{tabularx} + + + +% évite la numérotation des pages vides et met le numérotation i, ii, iii, iv, etc +% pour les pages avant les chapitres (numérotés arabian) +\usepackage{emptypage} +\usepackage{etoolbox} +% Fixing the appearance of the footer in the empty pages in between chapters. +\let\origdoublepage\cleardoublepage +\renewcommand{\cleardoublepage}{% + \clearpage + {\pagestyle{empty}\origdoublepage}% +} +% Finished fixing appearance + +% empêche que les pages incomplètes incorporent des espaces verticaux +\raggedbottom + +% citations comme [1-4] au lieu de [1,2,3,4] +\usepackage{cite} + +% pour l'index +\usepackage{latexsym} +\usepackage{textgreek} + +% séparation texte / notes de bas de page si page pas pleine +%\addtolength{\skip\footins}{5pt} +\usepackage[bottom]{footmisc} +\end_preamble +\use_default_options true +\begin_modules +theorems-ams +eqs-within-sections +figs-within-sections +\end_modules +\maintain_unincluded_children no +\language french +\language_package default +\inputencoding auto-legacy +\fontencoding auto +\font_roman "times" "default" +\font_sans "default" "default" +\font_typewriter "default" "default" +\font_math "auto" "auto" +\font_default_family default +\use_non_tex_fonts false +\font_sc false +\font_roman_osf false +\font_sans_osf false +\font_typewriter_osf false +\font_sf_scale 100 100 +\font_tt_scale 100 100 +\use_microtype false +\use_dash_ligatures true +\graphics default +\default_output_format default +\output_sync 0 +\bibtex_command default +\index_command default +\paperfontsize default +\spacing single +\use_hyperref true +\pdf_bookmarks true +\pdf_bookmarksnumbered true +\pdf_bookmarksopen false +\pdf_bookmarksopenlevel 1 +\pdf_breaklinks true +\pdf_pdfborder true +\pdf_colorlinks true +\pdf_backref false +\pdf_pdfusetitle true +\papersize b5 +\use_geometry false +\use_package amsmath 1 +\use_package amssymb 1 +\use_package cancel 1 +\use_package esint 1 +\use_package mathdots 1 +\use_package mathtools 1 +\use_package mhchem 1 +\use_package stackrel 1 +\use_package stmaryrd 1 +\use_package undertilde 1 +\cite_engine basic +\cite_engine_type default +\biblio_style plain +\use_bibtopic false +\use_indices true +\paperorientation portrait +\suppress_date false +\justification true +\use_refstyle 1 +\use_minted 0 +\use_lineno 0 +\backgroundcolor #ffffff +\fontcolor #000000 +\index Index +\shortcut idx +\color #008000 +\end_index +\index Index des fonctions extrinsèques +\shortcut ind +\color #008000 +\end_index +\paperwidth 175cm +\paperheight 240mm +\secnumdepth 2 +\tocdepth 2 +\paragraph_separation indent +\paragraph_indentation default +\is_math_indent 0 +\math_numbering_side default +\quotes_style swiss +\dynamic_quotes 0 +\papercolumns 1 +\papersides 2 +\paperpagestyle headings +\tablestyle default +\tracking_changes false +\output_changes false +\change_bars false +\postpone_fragile_content false +\html_math_output 0 +\html_css_as_file 0 +\html_be_strict false +\docbook_table_output 0 +\end_header + +\begin_body + +\begin_layout Title + +\series bold +\noun on +Think Julia +\end_layout + +\begin_layout Author + +\size normal +\noun on +Auteurs: Ben Lauwens et Allen B. + Downey +\size default + +\begin_inset Newline newline +\end_inset + + +\size normal +Traduction française et aménagements: Thierry Lepoint +\end_layout + +\begin_layout Chapter +Droits associés à la version française +\end_layout + +\begin_layout Standard +En vertu de la licence Creative Commons ( +\begin_inset CommandInset href +LatexCommand href +name "CC BY-NC-SA 3.0 FR" +target "https://creativecommons.org/licenses/by-nc-sa/3.0/fr/" +literal "false" + +\end_inset + +; +\emph on +Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions + 3.0 FR +\emph default +), vous êtes autorisé à partager (copier, distribuer et communiquer le matériel + par tous moyens et sous tous formats) et adapter (remixer, transformer + et créer à partir du matériel) selon les conditions suivantes: +\end_layout + +\begin_layout Itemize + +\emph on +Attribution +\emph default + — Vous devez créditer le document, intégrer un lien vers la licence (en + l'occurrence: +\begin_inset CommandInset href +LatexCommand href +name "CC BY-NC-SA 3.0 FR" +target "https://creativecommons.org/licenses/by-nc-sa/3.0/fr/legalcode" +literal "false" + +\end_inset + +) et indiquer si des modifications ont été effectuées au document. + Vous devez indiquer ces informations par tous les moyens raisonnables, + sans toutefois suggérer que le présent auteur vous soutient ou soutient + la façon dont vous avez utilisé son travail. + +\end_layout + +\begin_layout Itemize + +\emph on +Pas d’utilisation commerciale +\emph default + — Vous n'êtes pas autorisé à faire un usage commercial du présent document, + tout ou partie du matériel le composant. + +\end_layout + +\begin_layout Itemize + +\emph on +Partage dans les mêmes conditions — +\emph default +Dans le cas où vous effectuez un remix, que vous transformez, ou créez à + partir du matériel composant le document original, vous devez diffuser + le document modifié dans les mêmes conditions, c'est-à-dire avec la même + licence avec laquelle le document original a été diffusé. + +\end_layout + +\begin_layout Standard +Vous n'êtes pas autorisé à appliquer des conditions légales ou des mesures + techniques qui restreindraient légalement autrui à utiliser le document + dans les conditions décrites par la +\begin_inset CommandInset href +LatexCommand href +name "licence" +target "https://creativecommons.org/licenses/by-nc-sa/3.0/fr/legalcode" +literal "false" + +\end_inset + +. +\end_layout + +\end_body +\end_document diff --git a/autotests/export/docbook/author_plus_font.xml b/autotests/export/docbook/author_plus_font.xml new file mode 100644 index 0000000000..860fc5a336 --- /dev/null +++ b/autotests/export/docbook/author_plus_font.xml @@ -0,0 +1,27 @@ + + + + +<personname><emphasis role='bold'>Think Julia</emphasis></personname> + +Auteurs: Ben Lauwens et Allen B. DowneyTraduction française et aménagements: Thierry Lepoint + + + +Droits associés à la version française +En vertu de la licence Creative Commons (CC BY-NC-SA 3.0 FR; Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 3.0 FR), vous êtes autorisé à partager (copier, distribuer et communiquer le matériel par tous moyens et sous tous formats) et adapter (remixer, transformer et créer à partir du matériel) selon les conditions suivantes: + + +Attribution — Vous devez créditer le document, intégrer un lien vers la licence (en l'occurrence: CC BY-NC-SA 3.0 FR) et indiquer si des modifications ont été effectuées au document. Vous devez indiquer ces informations par tous les moyens raisonnables, sans toutefois suggérer que le présent auteur vous soutient ou soutient la façon dont vous avez utilisé son travail. + + +Pas d’utilisation commerciale — Vous n'êtes pas autorisé à faire un usage commercial du présent document, tout ou partie du matériel le composant. + + +Partage dans les mêmes conditions — Dans le cas où vous effectuez un remix, que vous transformez, ou créez à partir du matériel composant le document original, vous devez diffuser le document modifié dans les mêmes conditions, c'est-à-dire avec la même licence avec laquelle le document original a été diffusé. + + +Vous n'êtes pas autorisé à appliquer des conditions légales ou des mesures techniques qui restreindraient légalement autrui à utiliser le document dans les conditions décrites par la licence. + + \ No newline at end of file diff --git a/lib/layouts/stdtitle.inc b/lib/layouts/stdtitle.inc index d48cc6a475..a7e93c380d 100644 --- a/lib/layouts/stdtitle.inc +++ b/lib/layouts/stdtitle.inc @@ -8,7 +8,7 @@ # a document, like title, author and such. -Format 92 +Format 93 Style Title Margin Static @@ -55,6 +55,7 @@ Style Author DocBookWrapperTag author DocBookWrapperTagType block DocBookInInfo always + DocBookNoFontInside true End diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 7d377d01a3..eb04f45a48 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -11,7 +11,7 @@ # This script will update a .layout file to current format # The latest layout format is also defined in src/TextClass.cpp -currentFormat = 92 +currentFormat = 93 # Incremented to format 4, 6 April 2007, lasgouttes @@ -311,7 +311,10 @@ currentFormat = 92 # InputGlobal tag # Incremented to format 92, 30 January 2021 by spitz -# Add ProvideInsetLayout and ModifyIndetLayout +# Add ProvideInsetLayout and ModifyInsetLayout + +# Incremented to format 93, 13 February 2021 by spitz +# Add DocBookNoFontInside # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). @@ -563,7 +566,7 @@ def convert(lines, end_format): i += 1 continue - if 87 <= format <= 92: + if 87 <= format <= 93: # nothing to do. i += 1 continue diff --git a/src/Layout.cpp b/src/Layout.cpp index b98dd3b1b5..e037ad1c5e 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -129,6 +129,7 @@ enum LayoutTags { LT_DOCBOOKITEMINNERATTR, LT_DOCBOOKITEMINNERTAGTYPE, LT_DOCBOOKFORCEABSTRACTTAG, + LT_DOCBOOKNOFONTINSIDE, LT_INPREAMBLE, LT_HTMLTITLE, LT_SPELLCHECK, @@ -252,6 +253,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass, { "docbookitemwrapperattr", LT_DOCBOOKITEMWRAPPERATTR }, { "docbookitemwrappertag", LT_DOCBOOKITEMWRAPPERTAG }, { "docbookitemwrappertagtype", LT_DOCBOOKITEMWRAPPERTAGTYPE }, + { "docbooknofontinside", LT_DOCBOOKNOFONTINSIDE, }, { "docbooksection", LT_DOCBOOKSECTION }, { "docbooksectiontag", LT_DOCBOOKSECTIONTAG }, { "docbooktag", LT_DOCBOOKTAG }, @@ -853,6 +855,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass, lex >> docbookiteminnertagtype_; break; + case LT_DOCBOOKNOFONTINSIDE: + lex >> docbooknofontinside_; + break; + case LT_SPELLCHECK: lex >> spellcheck; break; @@ -1719,7 +1725,8 @@ void Layout::write(ostream & os) const os << "\tDocBookItemInnerTagType " << docbookiteminnertagtype_ << '\n'; if(!docbookforceabstracttag_.empty()) os << "\tDocBookForceAbstractTag " << docbookforceabstracttag_ << '\n'; - os << "\tSpellcheck " << spellcheck << "\n" + os << "\tDocBookNoFontInside " << docbooknofontinside_ << "\n" + "\tSpellcheck " << spellcheck << "\n" "\tForceLocal " << forcelocal << "\n" "End\n"; } diff --git a/src/Layout.h b/src/Layout.h index dfb5afebda..4eb8412723 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -251,6 +251,8 @@ public: /// std::string const & docbookforceabstracttag() const; /// + bool docbooknofontinside() const { return docbooknofontinside_; } + /// bool isParagraph() const { return latextype == LATEX_PARAGRAPH; } /// bool isCommand() const { return latextype == LATEX_COMMAND; } @@ -573,6 +575,8 @@ private: /// in LyX must be considered as the abstract if this is true); this text must be output with the specific tag /// held by this attribute mutable std::string docbookforceabstracttag_; + /// Whether font tags are allowed inside this tag. + bool docbooknofontinside_ = false; /// Should we generate the default CSS for this layout, even if HTMLStyle /// has been given? Default is false. /// Note that the default CSS is output first, then the user CSS, so it is diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 77611c2e26..7b0120ab87 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -3448,6 +3448,10 @@ std::vector Paragraph::simpleDocBookOnePar(Buffer const & buf, // Parsing main loop. for (pos_type i = initial; i < size(); ++i) { + bool ignore_fonts_i = ignore_fonts + || style.docbooknofontinside() + || (getInset(i) && getInset(i)->getLayout().docbooknofontinside()); + // Don't show deleted material in the output. if (isDeleted(i)) continue; @@ -3455,7 +3459,7 @@ std::vector Paragraph::simpleDocBookOnePar(Buffer const & buf, // If this is an InsetNewline, generate a new paragraph. Also reset the fonts, so that tags are closed in // this paragraph. if (getInset(i) && getInset(i)->lyxCode() == NEWLINE_CODE) { - if (!ignore_fonts) + if (!ignore_fonts_i) xs->closeFontTags(); // Output one paragraph (i.e. one string entry in generatedParagraphs). @@ -3468,7 +3472,7 @@ std::vector Paragraph::simpleDocBookOnePar(Buffer const & buf, xs = new XMLStream(os); // Restore the fonts for the new paragraph, so that the right tags are opened for the new entry. - if (!ignore_fonts) { + if (!ignore_fonts_i) { font_old = outerfont.fontInfo(); fs = old_fs; } @@ -3476,24 +3480,23 @@ std::vector Paragraph::simpleDocBookOnePar(Buffer const & buf, // Determine which tags should be opened or closed regarding fonts. Font const font = getFont(buf.masterBuffer()->params(), i, outerfont); - if (!ignore_fonts) { - tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs); - - // FIXME XHTML - // Other such tags? What about the other text ranges? - - vector::const_iterator cit = tagsToClose.begin(); - vector::const_iterator cen = tagsToClose.end(); - for (; cit != cen; ++cit) - *xs << *cit; - - // Deal with the delayed characters *after* closing font tags. - if (!delayedChars.empty()) { - for (char_type c: delayedChars) - *xs << c; - delayedChars.clear(); - } - + tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs); + + if (!ignore_fonts_i) { + vector::const_iterator cit = tagsToClose.begin(); + vector::const_iterator cen = tagsToClose.end(); + for (; cit != cen; ++cit) + *xs << *cit; + } + + // Deal with the delayed characters *after* closing font tags. + if (!delayedChars.empty()) { + for (char_type c: delayedChars) + *xs << c; + delayedChars.clear(); + } + + if (!ignore_fonts_i) { vector::const_iterator sit = tagsToOpen.begin(); vector::const_iterator sen = tagsToOpen.end(); for (; sit != sen; ++sit) @@ -3503,6 +3506,7 @@ std::vector Paragraph::simpleDocBookOnePar(Buffer const & buf, tagsToOpen.clear(); } + // Finally, write the next character or inset. if (Inset const * inset = getInset(i)) { if (!runparams.for_toc || inset->isInToc()) { OutputParams np = runparams; diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 4054b98fd4..57a9f74962 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -59,7 +59,7 @@ namespace lyx { // You should also run the development/tools/updatelayouts.py script, // to update the format of all of our layout files. // -int const LAYOUT_FORMAT = 92; // spitz: ProvideInsetLayout and ModifyInsetLayout +int const LAYOUT_FORMAT = 93; // tcuvelier: DocBookNoFontInside // Layout format for the current lyx file format. Controls which format is diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index c45a0176d6..391f9c932f 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -106,6 +106,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass, IL_DOCBOOKITEMWRAPPERTAG, IL_DOCBOOKITEMWRAPPERTAGTYPE, IL_DOCBOOKITEMWRAPPERATTR, + IL_DOCBOOKNOFONTINSIDE, IL_INTOC, IL_ISTOCCAPTION, IL_LABELFONT, @@ -159,6 +160,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass, { "docbookitemwrapperattr", IL_DOCBOOKITEMWRAPPERATTR }, { "docbookitemwrappertag", IL_DOCBOOKITEMWRAPPERTAG }, { "docbookitemwrappertagtype", IL_DOCBOOKITEMWRAPPERTAGTYPE }, + { "docbooknofontinside", IL_DOCBOOKNOFONTINSIDE }, { "docbooknotinpara", IL_DOCBOOKNOTINPARA }, { "docbooksection", IL_DOCBOOKSECTION }, { "docbooktag", IL_DOCBOOKTAG }, @@ -556,6 +558,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass, case IL_DOCBOOKWRAPPERATTR: lex >> docbookwrapperattr_; break; + case IL_DOCBOOKNOFONTINSIDE: + lex >> docbooknofontinside_; + break; case IL_REQUIRES: { lex.eatLine(); vector const req diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 4958d364aa..47fa633e69 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -182,6 +182,8 @@ public: /// std::string docbookitemattr() const { return docbookitemattr_; } /// + bool docbooknofontinside() const { return docbooknofontinside_; } + /// std::set required() const { return required_; } /// bool isMultiPar() const { return multipar_; } @@ -341,6 +343,8 @@ private: /// std::string docbookitemwrapperattr_; /// + bool docbooknofontinside_ = false; + /// std::set required_; /// bool multipar_ = true; -- 2.39.2