]> git.lyx.org Git - lyx.git/commitdiff
DocBook: add the DocBookNoFontInside layout configuration.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Sat, 13 Feb 2021 03:34:03 +0000 (04:34 +0100)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Sat, 13 Feb 2021 04:09:59 +0000 (05:09 +0100)
autotests/export/docbook/author_plus_font.lyx [new file with mode: 0644]
autotests/export/docbook/author_plus_font.xml [new file with mode: 0644]
lib/layouts/stdtitle.inc
lib/scripts/layout2layout.py
src/Layout.cpp
src/Layout.h
src/Paragraph.cpp
src/TextClass.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h

diff --git a/autotests/export/docbook/author_plus_font.lyx b/autotests/export/docbook/author_plus_font.lyx
new file mode 100644 (file)
index 0000000..3f3693d
--- /dev/null
@@ -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 (file)
index 0000000..860fc5a
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This DocBook file was created by LyX 2.4.0dev
+  See https://www.lyx.org/ for more information -->
+<book xml:lang="fr_FR" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
+<info>
+<title><personname><emphasis role='bold'>Think Julia</emphasis></personname></title>
+<author>
+<personname>Auteurs: Ben Lauwens et Allen B. DowneyTraduction française et aménagements: Thierry Lepoint</personname>
+</author>
+</info>
+<chapter>
+<title>Droits associés à la version française</title>
+<para>En vertu de la licence Creative Commons (<link xlink:href="https://creativecommons.org/licenses/by-nc-sa/3.0/fr/">CC BY-NC-SA 3.0 FR</link>; <emphasis>Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 3.0 FR</emphasis>), 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:</para>
+<itemizedlist>
+<listitem>
+<para><emphasis>Attribution</emphasis> — Vous devez créditer le document, intégrer un lien vers la licence (en l'occurrence: <link xlink:href="https://creativecommons.org/licenses/by-nc-sa/3.0/fr/legalcode">CC BY-NC-SA 3.0 FR</link>) 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. </para>
+</listitem>
+<listitem>
+<para><emphasis>Pas d’utilisation commerciale</emphasis> — Vous n'êtes pas autorisé à faire un usage commercial du présent document, tout ou partie du matériel le composant. </para>
+</listitem>
+<listitem>
+<para><emphasis>Partage dans les mêmes conditions —</emphasis> 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é. </para>
+</listitem>
+</itemizedlist>
+<para>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 <link xlink:href="https://creativecommons.org/licenses/by-nc-sa/3.0/fr/legalcode">licence</link>.</para>
+</chapter>
+</book>
\ No newline at end of file
index d48cc6a47518e12647fc4e991f5b721f9ad1f074..a7e93c380d195fb2135bdd7a2f24fc5d2014659c 100644 (file)
@@ -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
 
 
index 7d377d01a32810e8aa9e9477cff277e0de3dd51e..eb04f45a482cb53055b9a0d3289770e3f87245c3 100644 (file)
@@ -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
index b98dd3b1b5419817322a15cbcd3b5adc4916b931..e037ad1c5e69d6840a0e4e9679d477aa46a77c86 100644 (file)
@@ -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";
 }
index dfb5afebda3f2d3ad5abacfccbcba3fe0e9db062..4eb8412723b9263d75427e4b71afcef11b4801d0 100644 (file)
@@ -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
index 77611c2e264dfa72d35801fd2673440eac6c8413..7b0120ab87bbe44e051690e31a97dd45b93a1a21 100644 (file)
@@ -3448,6 +3448,10 @@ std::vector<docstring> 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<docstring> 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<docstring> 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<docstring> 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<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
-                       vector<xml::EndFontTag>::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<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
+            vector<xml::EndFontTag>::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<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
                        vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
                        for (; sit != sen; ++sit)
@@ -3503,6 +3506,7 @@ std::vector<docstring> 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;
index 4054b98fd4d0b49e2038c0eb27792a80793796bf..57a9f749626c788b7bd4f664e2622d9b2ee0052d 100644 (file)
@@ -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
index c45a0176d6f97401992b609e4a38facf2c0e9c25..391f9c932f9c172e6843b4736c895e05b185c039 100644 (file)
@@ -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<string> const req
index 4958d364aade73b5a38087df4e2118b2a1f5b3fd..47fa633e6930f749a9ebcd0e4ef7e80bd0400b6a 100644 (file)
@@ -182,6 +182,8 @@ public:
        ///
        std::string docbookitemattr() const { return docbookitemattr_; }
        ///
+       bool docbooknofontinside() const { return docbooknofontinside_; }
+       ///
        std::set<std::string> required() const { return required_; }
        ///
        bool isMultiPar() const { return multipar_; }
@@ -341,6 +343,8 @@ private:
        ///
        std::string docbookitemwrapperattr_;
        ///
+       bool docbooknofontinside_ = false;
+       ///
        std::set<std::string> required_;
        ///
        bool multipar_ = true;