commit a0e3ba859eabbdd4d207b8c6018ad9bb9ce5cfce
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Tue Jun 10 10:26:09 2025 +0200

    Validate colors in PDF settings
    
    If a user enters a known non-base color,
    we load the respective model.
---
 lib/doc/UserGuide.lyx    | 31 -------------------------------
 lib/doc/de/UserGuide.lyx | 23 -----------------------
 src/BufferParams.cpp     |  1 +
 src/PDFOptions.cpp       | 25 +++++++++++++++++++++++++
 src/PDFOptions.h         |  3 +++
 5 files changed, 29 insertions(+), 54 deletions(-)

diff --git a/lib/doc/UserGuide.lyx b/lib/doc/UserGuide.lyx
index 709977c234..3a37e2aba4 100644
--- a/lib/doc/UserGuide.lyx
+++ b/lib/doc/UserGuide.lyx
@@ -33340,37 +33340,6 @@ to the field
 Additional options
 \family default
  in the PDF Properties dialog.
-\change_inserted -712698321 1749490548
-
-\end_layout
-
-\begin_layout Standard
-
-\change_inserted -712698321 1749490902
-Note that by default only the \SpecialChar LaTeX
- base colors are supported.
- If you want to use a color of a different color category from those listed in 
\SpecialChar LyX
-'s color combos (e.
-\begin_inset space \thinspace{}
-\end_inset
-
-g.,
- in 
-\family sans
-Text Properties
-\family default
-),
- e.
-\begin_inset space \thinspace{}
-\end_inset
-
-g.
- an SVG or X11 color,
- you need to ensure that the corresponding color model has been loaded.
- Otherwise you may get a \SpecialChar LaTeX
- error.
-\change_unchanged
-
 \end_layout
 
 \begin_layout Standard
diff --git a/lib/doc/de/UserGuide.lyx b/lib/doc/de/UserGuide.lyx
index 67696b1659..0a91645cce 100644
--- a/lib/doc/de/UserGuide.lyx
+++ b/lib/doc/de/UserGuide.lyx
@@ -32056,29 +32056,6 @@ blue
 .
 \end_layout
 
-\begin_layout Standard
-Beachten Sie,
- dass von Haus aus nur \SpecialChar LaTeX
--Grundfarben unterstützt werden.
- Falls Sie eine Farbe einer anderen Kategorie aus der Liste verwenden wollen,
- die in den \SpecialChar LyX
--Farbauswahlfeldern (z.
-\begin_inset space \thinspace{}
-\end_inset
-
-B.
- in den 
-\family sans
-Texteigenschaften
-\family default
-) angeboten wird,
- beispielweise eine SVG- or X11-Farbe),
- müssen Sie selbst dafür Sorge tragen,
- dass das entsprechende Farbmodell geladen wurde.
- Andernfalls bekommen Sie einen \SpecialChar LaTeX
--Fehler.
-\end_layout
-
 \begin_layout Standard
 Direkt aus \SpecialChar LyX
  können Sie einen Link über das Kontextmenü oder direkt mit 
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index aee67a0147..342193c061 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -2024,6 +2024,7 @@ void BufferParams::validate(LaTeXFeatures & features) 
const
                // option, see http://www.lyx.org/trac/ticket/5291
                if (pdfoptions().colorlinks)
                        features.require("color");
+               pdfoptions().validate(features);
        }
        if (!listings_params.empty()) {
                // do not test validity because listings_params is
diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp
index 6a7c80144a..a964551235 100644
--- a/src/PDFOptions.cpp
+++ b/src/PDFOptions.cpp
@@ -14,6 +14,7 @@
 #include "PDFOptions.h"
 
 #include "Encoding.h"
+#include "LaTeXColors.h"
 #include "LaTeXFeatures.h"
 #include "OutputParams.h"
 #include "texstream.h"
@@ -303,4 +304,28 @@ void PDFOptions::clear()
        pdfusetitle             = true;  //in contrast with hyperref
 }
 
+
+void PDFOptions::validate(LaTeXFeatures & features) const
+{
+       if (quoted_options.empty())
+               return;
+
+       vector<string> const opts = getVectorFromString(quoted_options);
+       for (auto const & opt : opts) {
+               if (!contains(opt, "color="))
+                       continue;
+               string const color = split(opt, '=');
+               if (theLaTeXColors().isRealLaTeXColor(color)) {
+                       string const lyxcolor = 
theLaTeXColors().getFromLaTeXColor(color);
+                       LaTeXColor const lc = 
theLaTeXColors().getLaTeXColor(lyxcolor);
+                       for (auto const & r : lc.req())
+                               features.require(r);
+                       features.require("xcolor");
+                       if (!lc.model().empty())
+                               features.require("xcolor:" + lc.model());
+               }
+       }
+       
+}
+
 } // namespace lyx
diff --git a/src/PDFOptions.h b/src/PDFOptions.h
index e013566c14..c0532ecded 100644
--- a/src/PDFOptions.h
+++ b/src/PDFOptions.h
@@ -16,6 +16,7 @@
 
 namespace lyx {
 
+class LaTeXFeatures;
 class OutputParams;
 class otexstream;
 
@@ -37,6 +38,8 @@ public:
        /// output to tex header
        void writeLaTeX(OutputParams &, otexstream &,
                        bool hyperref_already_provided) const;
+       /// validate colors
+       void validate(LaTeXFeatures &) const;
        /// read tokens from lyx header
        std::string readToken(support::Lexer &lex, std::string const & token);
        /// set implicit settings for hyperref
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to