]> git.lyx.org Git - features.git/commitdiff
Prevent more local colors from leaking (#6626)
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 22 Jan 2021 09:34:41 +0000 (10:34 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 22 Jan 2021 09:34:41 +0000 (10:34 +0100)
src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/insets/InsetBox.cpp
src/insets/InsetIndex.cpp
src/insets/InsetNote.cpp

index 7443931dd6f248e5b1aa282e88cac561d0582db0..6454ba3c9213ec333988671642768116a84f20af 100644 (file)
@@ -988,7 +988,7 @@ int Buffer::readHeader(Lexer & lex)
                                      << token << '\'');
 
                string const result =
-                       params().readToken(lex, token, d->filename.onlyPath());
+                       params().readToken(lex, token, d->filename);
                if (!result.empty()) {
                        if (token == "\\textclass") {
                                d->layout_position = result;
index 46d56581ca13eb3acbbb5d4bf8da4bb6f93f8bc6..a4756ec24eaf7cadb7e610eb872c07910a1dea46 100644 (file)
@@ -704,9 +704,10 @@ BufferParams::MathNumber BufferParams::getMathNumber() const
 
 
 string BufferParams::readToken(Lexer & lex, string const & token,
-       FileName const & filepath)
+       FileName const & filename)
 {
        string result;
+       FileName const & filepath = filename.onlyPath();
 
        if (token == "\\textclass") {
                lex.next();
@@ -1028,7 +1029,7 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                                        color = lcolor.getX11HexName(Color_background);
                                // FIXME UNICODE
                                if (!shortcut.empty())
-                                       lcolor.setColor(to_utf8(shortcut), color);
+                                       lcolor.setColor(to_utf8(shortcut)+ "@" + filename.absFileName(), color);
                        }
                }
        } else if (token == "\\author") {
@@ -1055,12 +1056,14 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                notefontcolor = lyx::rgbFromHexName(color);
                lcolor.setColor("notefontcolor", color);
                lcolor.setLaTeXName("notefontcolor", "note_fontcolor");
+               // set a local name for the painter
+               lcolor.setColor("notefontcolor@" + filename.absFileName(), color);
                isnotefontcolor = true;
        } else if (token == "\\boxbgcolor") {
                lex.eatLine();
                string color = lex.getString();
                boxbgcolor = lyx::rgbFromHexName(color);
-               lcolor.setColor("boxbgcolor", color);
+               lcolor.setColor("boxbgcolor@" + filename.absFileName(), color);
                isboxbgcolor = true;
        } else if (token == "\\paperwidth") {
                lex >> paperwidth;
index 73bb9f6ff55eda89014c2a56f9c661afe352a388..ff5604eb528db316b1ceba1eece6abb997218173 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "Citation.h"
 #include "ColorCode.h"
+#include "ColorSet.h"
 #include "DocumentClassPtr.h"
 #include "LayoutModuleList.h"
 #include "paper.h"
@@ -78,7 +79,7 @@ public:
        /// read a header token, if unrecognised, return it or an unknown class name
        std::string readToken(Lexer & lex,
                std::string const & token, ///< token to read.
-               support::FileName const & filepath);
+               support::FileName const & filename);
 
        ///
        void writeFile(std::ostream &, Buffer const *) const;
index 34e33a561ad8758bcb3c765a79824db953534665..c04bd1e927e6bf9721ba0b13b6793766bb854699 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "support/debug.h"
 #include "support/docstream.h"
+#include "support/FileName.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/Translator.h"
@@ -220,10 +221,10 @@ ColorCode InsetBox::backgroundColor(PainterInfo const &) const
                return getLayout().bgcolor();
 
        if (params_.type == "Shaded") {
-               if (buffer().params().isboxbgcolor)
+               if (!buffer().params().isboxbgcolor)
                        return getLayout().bgcolor();
 
-               ColorCode c = lcolor.getFromLyXName("boxbgcolor");
+               ColorCode c = lcolor.getFromLyXName("boxbgcolor@" + buffer().fileName().absFileName());
                if (c == Color_none)
                        return getLayout().bgcolor();
                return c;
index 149ef6506a32ef703741b28089d122f48df57ccd..7790ad91fb865ca79c91445185edcc90dd699084 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "support/debug.h"
 #include "support/docstream.h"
+#include "support/FileName.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
@@ -456,7 +457,8 @@ ColorCode InsetIndex::labelColor() const
        if (params_.index.empty() || params_.index == from_ascii("idx"))
                return InsetCollapsible::labelColor();
        // FIXME UNICODE
-       ColorCode c = lcolor.getFromLyXName(to_utf8(params_.index));
+       ColorCode c = lcolor.getFromLyXName(to_utf8(params_.index)
+                                           + "@" + buffer().fileName().absFileName());
        if (c == Color_none)
                c = InsetCollapsible::labelColor();
        return c;
index c9b0b8823a7f85d1209f59a95c7fac3551ac4e28..adacef3bae267066beec930dacb5f5b707ca6f65 100644 (file)
@@ -332,6 +332,10 @@ FontInfo InsetNote::getFont() const
                ColorCode c = lcolor.getFromLyXName("notefontcolor");
                if (c != Color_none)
                        font.setColor(c);
+               // This is the local color (not overridden by other documents)
+               ColorCode lc = lcolor.getFromLyXName("notefontcolor@" + buffer().fileName().absFileName());
+               if (lc != Color_none)
+                       font.setPaintColor(lc);
        }
        return font;
 }