[LyX/master] Prevent more local colors from leaking (#6626)

Juergen Spitzmueller spitz at lyx.org
Fri Jan 22 09:33:41 UTC 2021


commit 6775d7c3a2bccdc064dc0fb37564b8941d956541
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Fri Jan 22 10:34:41 2021 +0100

    Prevent more local colors from leaking (#6626)
---
 src/Buffer.cpp            |    2 +-
 src/BufferParams.cpp      |    9 ++++++---
 src/BufferParams.h        |    3 ++-
 src/insets/InsetBox.cpp   |    5 +++--
 src/insets/InsetIndex.cpp |    4 +++-
 src/insets/InsetNote.cpp  |    4 ++++
 6 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 7443931..6454ba3 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -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;
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 46d5658..a4756ec 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -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;
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 73bb9f6..ff5604e 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -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;
diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp
index 34e33a5..c04bd1e 100644
--- a/src/insets/InsetBox.cpp
+++ b/src/insets/InsetBox.cpp
@@ -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;
diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp
index 149ef65..7790ad9 100644
--- a/src/insets/InsetIndex.cpp
+++ b/src/insets/InsetIndex.cpp
@@ -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;
diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp
index c9b0b88..adacef3 100644
--- a/src/insets/InsetNote.cpp
+++ b/src/insets/InsetNote.cpp
@@ -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;
 }


More information about the lyx-cvs mailing list