commit e35bb3126a70384544b315771288db116f894926
Author: Uwe Stöhr <[email protected]>
Date: Thu May 14 22:23:44 2015 +0200
support for all default colors of the package xcolor
fileformat change
diff --git a/development/FORMAT b/development/FORMAT
index 68e1d33..ae75380 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,12 @@ adjustments are made to tex2lyx and bugs are fixed in
lyx2lyx.
-----------------------
+2015-05-14 Uwe Stöhr <[email protected]>
+ * Format incremented to 491: support for xcolor's default colors
+ No new parameter, the \\color parameter can nowhave these values:
+ "brown", "darkgray", "gray", "lightgray", "lime", "olive", "orange",
+ "pink", "purple", "teal", "violet"
+
2015-05-13 Enrico Forestieri <[email protected]>
* Format incremented to 490: new \origin tag, extended \textclass tag.
The \origin tag keeps track of the document directory and is useful
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index 15bbf08..246ab33 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -85,7 +85,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" ,
4)),
("1_6", list(range(277,346)), minor_versions("1.6" , 10)),
("2_0", list(range(346,414)), minor_versions("2.0" , 8)),
("2_1", list(range(414,475)), minor_versions("2.1" , 0)),
- ("2_2", list(range(475,491)), minor_versions("2.2" , 0))
+ ("2_2", list(range(475,492)), minor_versions("2.2" , 0))
]
####################################################################
diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py
index 10e78ac..f53b3a8 100644
--- a/lib/lyx2lyx/lyx_2_2.py
+++ b/lib/lyx2lyx/lyx_2_2.py
@@ -992,7 +992,7 @@ def revert_BoxFeatures(document):
# delete the specification
del document.body[i+1:i+4]
# output ERT
- # first output the closing braces
+ # first output the closing brace
if shadowsize != defaultShadow or separation != defaultSep or
thickness != defaultThick:
document.body[i + 10 : i + 10] = put_cmd_in_ert("}")
# now output the lengths
@@ -1039,6 +1039,44 @@ def revert_origin(document):
del document.header[i]
+color_names = ["brown", "darkgray", "gray", \
+ "lightgray", "lime", "olive", "orange", \
+ "pink", "purple", "teal", "violet"]
+
+def revert_textcolor(document):
+ " revert new \texcolor colors to TeX code "
+
+ i = 0
+ j = 0
+ xcolor = False
+ add_to_preamble(document,
["\\@ifundefined{rangeHsb}{\\usepackage{xcolor}}"])
+ while True:
+ i = find_token(document.body, "\\color ", i)
+ if i == -1:
+ return
+ else:
+ for color in list(color_names):
+ if document.body[i] == "\\color " + color:
+ # register that xcolor must be loaded in the preamble
+ if xcolor == False:
+ xcolor = True
+ add_to_preamble(document,
["\\@ifundefined{rangeHsb}{\usepackage{xcolor}}"])
+ # find the next \\color and/or the next \\end_layout
+ j = find_token(document.body, "\\color", i + 1)
+ k = find_token(document.body, "\\end_layout", i + 1)
+ if j == -1 and k != -1:
+ j = k +1
+ # output TeX code
+ # first output the closing brace
+ if k < j:
+ document.body[k: k] = put_cmd_in_ert("}")
+ else:
+ document.body[j: j] = put_cmd_in_ert("}")
+ # now output the \textcolor command
+ document.body[i : i + 1] = put_cmd_in_ert("\\textcolor{" +
color + "}{")
+ i = i + 1
+
+
##
# Conversion hub
#
@@ -1063,10 +1101,12 @@ convert = [
[487, []],
[488, [convert_newgloss]],
[489, [convert_BoxFeatures]],
- [490, [convert_origin]]
+ [490, [convert_origin]],
+ [491, []]
]
revert = [
+ [490, [revert_textcolor]],
[489, [revert_origin]],
[488, [revert_BoxFeatures]],
[487, [revert_newgloss, revert_glossgroup]],
diff --git a/src/Color.cpp b/src/Color.cpp
index 161ebba..f08c9fb 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -203,11 +203,22 @@ ColorSet::ColorSet()
{ Color_none, N_("none"), "none", "black", "none" },
{ Color_black, N_("black"), "black", "black", "black" },
{ Color_white, N_("white"), "white", "white", "white" },
- { Color_red, N_("red"), "red", "red", "red" },
- { Color_green, N_("green"), "green", "green", "green" },
{ Color_blue, N_("blue"), "blue", "blue", "blue" },
+ { Color_brown, N_("brown"), "brown", "brown", "brown" },
{ Color_cyan, N_("cyan"), "cyan", "cyan", "cyan" },
+ { Color_darkgray, N_("darkgray"), "darkgray", "darkgray", "darkgray" },
+ { Color_gray, N_("gray"), "gray", "gray", "gray" },
+ { Color_green, N_("green"), "green", "green", "green" },
+ { Color_lightgray, N_("lightgray"), "lightgray", "lightgray",
"lightgray" },
+ { Color_lime, N_("lime"), "lime", "lime", "lime" },
{ Color_magenta, N_("magenta"), "magenta", "magenta", "magenta" },
+ { Color_olive, N_("olive"), "olive", "olive", "olive" },
+ { Color_orange, N_("orange"), "orange", "orange", "orange" },
+ { Color_pink, N_("pink"), "pink", "pink", "pink" },
+ { Color_purple, N_("purple"), "purple", "purple", "purple" },
+ { Color_red, N_("red"), "red", "red", "red" },
+ { Color_teal, N_("teal"), "teal", "teal", "teal" },
+ { Color_violet, N_("violet"), "violet", "violet", "violet" },
{ Color_yellow, N_("yellow"), "yellow", "yellow", "yellow" },
{ Color_cursor, N_("cursor"), "cursor", "black", "cursor" },
{ Color_background, N_("background"), "background", "linen",
"background" },
diff --git a/src/ColorCode.h b/src/ColorCode.h
index 4d391c0..180e544 100644
--- a/src/ColorCode.h
+++ b/src/ColorCode.h
@@ -21,16 +21,38 @@ enum ColorCode {
///
Color_white,
///
- Color_red,
+ Color_blue,
+ ///
+ Color_brown,
+ ///
+ Color_cyan,
+ ///
+ Color_darkgray,
+ ///
+ Color_gray,
///
Color_green,
///
- Color_blue,
+ Color_lightgray,
///
- Color_cyan,
+ Color_lime,
///
Color_magenta,
///
+ Color_olive,
+ ///
+ Color_orange,
+ ///
+ Color_pink,
+ ///
+ Color_purple,
+ ///
+ Color_red,
+ ///
+ Color_teal,
+ ///
+ Color_violet,
+ ///
Color_yellow,
// Needed interface colors
diff --git a/src/Font.cpp b/src/Font.cpp
index 7e8b3f4..34c5c0b 100644
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -695,6 +695,18 @@ void Font::validate(LaTeXFeatures & features) const
case Color_latex:
case Color_notelabel:
break;
+ case Color_brown:
+ case Color_darkgray:
+ case Color_gray:
+ case Color_lightgray:
+ case Color_lime:
+ case Color_olive:
+ case Color_orange:
+ case Color_pink:
+ case Color_purple:
+ case Color_teal:
+ case Color_violet:
+ features.require("xcolor");
default:
features.require("color");
LYXERR(Debug::LATEX, "Color enabled. Font: " <<
to_utf8(stateText(0)));
diff --git a/src/frontends/qt4/GuiCharacter.cpp
b/src/frontends/qt4/GuiCharacter.cpp
index 0e47576..a947143 100644
--- a/src/frontends/qt4/GuiCharacter.cpp
+++ b/src/frontends/qt4/GuiCharacter.cpp
@@ -21,12 +21,15 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
+#include "Color.h"
+#include "ColorCache.h"
#include "Cursor.h"
#include "FuncRequest.h"
#include "Language.h"
#include "Paragraph.h"
#include <QAbstractItemModel>
+#include <QComboBox>
#include <QModelIndex>
#include <QSettings>
#include <QVariant>
@@ -92,11 +95,22 @@ static QList<ColorPair> colorData()
colors << ColorPair(qt_("No color"), Color_none);
colors << ColorPair(qt_("Black"), Color_black);
colors << ColorPair(qt_("White"), Color_white);
- colors << ColorPair(qt_("Red"), Color_red);
- colors << ColorPair(qt_("Green"), Color_green);
colors << ColorPair(qt_("Blue"), Color_blue);
+ colors << ColorPair(qt_("Brown"), Color_brown);
colors << ColorPair(qt_("Cyan"), Color_cyan);
+ colors << ColorPair(qt_("Darkgray"), Color_darkgray);
+ colors << ColorPair(qt_("Gray"), Color_gray);
+ colors << ColorPair(qt_("Green"), Color_green);
+ colors << ColorPair(qt_("Lightgray"), Color_lightgray);
+ colors << ColorPair(qt_("Lime"), Color_lime);
colors << ColorPair(qt_("Magenta"), Color_magenta);
+ colors << ColorPair(qt_("Olive"), Color_olive);
+ colors << ColorPair(qt_("Orange"), Color_orange);
+ colors << ColorPair(qt_("Pink"), Color_pink);
+ colors << ColorPair(qt_("Purple"), Color_purple);
+ colors << ColorPair(qt_("Red"), Color_red);
+ colors << ColorPair(qt_("Teal"), Color_teal);
+ colors << ColorPair(qt_("Violet"), Color_violet);
colors << ColorPair(qt_("Yellow"), Color_yellow);
colors << ColorPair(qt_("Reset"), Color_inherit);
return colors;
@@ -156,6 +170,25 @@ void fillCombo(QComboBox * combo, QList<T> const & list)
combo->addItem(cit->first);
}
+template<typename T>
+void fillComboColor(QComboBox * combo, QList<T> const & list)
+{
+ // at first add the 2 colors "No change" and "No color"
+ combo->addItem(list.begin()->first);
+ combo->addItem((list.begin() + 1)->first);
+ // now add the real colors
+ QPixmap coloritem(32, 32);
+ QColor color;
+ typename QList<T>::const_iterator cit = list.begin() + 2;
+ for (; cit != list.end() - 1; ++cit) {
+ color = QColor(guiApp->colorCache().get(cit->second, false));
+ coloritem.fill(color);
+ combo->addItem(QIcon(coloritem), cit->first);
+ }
+ //the last color is "Reset"
+ combo->addItem((list.end() - 1)->first);
+}
+
}
GuiCharacter::GuiCharacter(GuiView & lv)
@@ -195,7 +228,7 @@ GuiCharacter::GuiCharacter(GuiView & lv)
fillCombo(sizeCO, size);
fillCombo(shapeCO, shape);
fillCombo(miscCO, bar);
- fillCombo(colorCO, color);
+ fillComboColor(colorCO, color);
fillCombo(langCO, language);
bc().setPolicy(ButtonPolicy::OkApplyCancelAutoReadOnlyPolicy);
diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp
index 995f8fa..a9917e4 100644
--- a/src/frontends/qt4/GuiPrefs.cpp
+++ b/src/frontends/qt4/GuiPrefs.cpp
@@ -1121,11 +1121,22 @@ PrefColors::PrefColors(GuiPreferences * form)
if (lc == Color_none
|| lc == Color_black
|| lc == Color_white
- || lc == Color_red
- || lc == Color_green
|| lc == Color_blue
+ || lc == Color_brown
|| lc == Color_cyan
+ || lc == Color_darkgray
+ || lc == Color_gray
+ || lc == Color_green
+ || lc == Color_lightgray
+ || lc == Color_lime
|| lc == Color_magenta
+ || lc == Color_olive
+ || lc == Color_orange
+ || lc == Color_pink
+ || lc == Color_purple
+ || lc == Color_red
+ || lc == Color_teal
+ || lc == Color_violet
|| lc == Color_yellow
|| lc == Color_inherit
|| lc == Color_ignore)
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 0ae9a27..d988e1d 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -159,11 +159,13 @@ const char * const known_if_commands[] = {"if",
"ifarydshln", "ifbraket",
"ifcancel", "ifcolortbl", "ifeurosym", "ifmarginnote", "ifmmode", "ifpdf",
"ifsidecap", "ifupgreek", 0};
-const char * const known_basic_colors[] = {"blue", "black", "cyan", "green",
-"magenta", "red", "white", "yellow", 0};
+const char * const known_basic_colors[] = {"black", "blue", "brown", "cyan",
+ "darkgray", "gray", "green", "lightgray", "lime", "magenta", "orange",
"olive",
+ "pink", "purple", "red", "teal", "violet", "white", "yellow", 0};
-const char * const known_basic_color_codes[] = {"#0000ff", "#000000",
"#00ffff",
-"#00ff00", "#ff00ff", "#ff0000", "#ffffff", "#ffff00", 0};
+const char * const known_basic_color_codes[] = {"#000000", "#0000ff",
"#964B00", "#00ffff",
+ "#a9a9a9", "#808080", "#00ff00", "#d3d3d3", "#bfff00", "#ff00ff",
"#ff7f00", "#808000",
+ "#ffc0cb", "#800080", "#ff0000", "#008080", "#8F00FF", "#ffffff",
"#ffff00", 0};
/// conditional commands with three arguments like \@ifundefined{}{}{}
const char * const known_if_3arg_commands[] = {"@ifundefined", "IfFileExists",
diff --git a/src/tex2lyx/test/box-color-size-space-align.tex
b/src/tex2lyx/test/box-color-size-space-align.tex
index feee588..338a269 100644
--- a/src/tex2lyx/test/box-color-size-space-align.tex
+++ b/src/tex2lyx/test/box-color-size-space-align.tex
@@ -37,6 +37,7 @@
\usepackage{pifont}
\usepackage{tipa}
\usepackage{tipx}
+\usepackage{xcolor}
\setlength{\parskip}{3mm}
\setlength{\parindent}{0sp}
@@ -175,6 +176,9 @@ Shaded background box, with inner minipage\end{shaded}%
\subsection{Predefined Colors}
test \textcolor{blue}{blue} test \textcolor{red}{red red red} test
\textcolor{green}{bla}\textcolor{magenta}{blub}
+test \textcolor{brown}{brown} test \textcolor{darkgray}{darkgray} test
\textcolor{gray}{gray}\textcolor{lightgray}{lightgray}
+test \textcolor{lime}{lime} test \textcolor{olive}{olive} test
\textcolor{orange}{orange}\textcolor{pink}{pink}
+test \textcolor{purple}{purple} test \textcolor{teal}{teal} test
\textcolor{violet}{violet}
test
\textcolor{green}{c}%
\textcolor{red}{o}%
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 88ec91d..c0845c1 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -3145,7 +3145,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags,
bool outer,
else if (t.cs() == "textcolor") {
// scheme is \textcolor{color name}{text}
string const color = p.verbatim_item();
- // we only support the predefined colors of the color
package
+ // we support the predefined colors of the color and
the xcolor package
if (color == "black" || color == "blue" || color ==
"cyan"
|| color == "green" || color == "magenta" ||
color == "red"
|| color == "white" || color == "yellow") {
@@ -3155,6 +3155,16 @@ void parse_text(Parser & p, ostream & os, unsigned
flags, bool outer,
context.check_layout(os);
os << "\n\\color inherit\n";
preamble.registerAutomaticallyLoadedPackage("color");
+ } else if (color == "brown" || color == "darkgray" ||
color == "gray"
+ || color == "lightgray" || color == "lime" ||
color == "olive"
+ || color == "orange" || color == "pink" ||
color == "purple"
+ || color == "teal" || color == "violet") {
+ context.check_layout(os);
+ os << "\n\\color " << color << "\n";
+ parse_text_snippet(p, os, FLAG_ITEM,
outer, context);
+ context.check_layout(os);
+ os << "\n\\color inherit\n";
+
preamble.registerAutomaticallyLoadedPackage("xcolor");
} else
// for custom defined colors
output_ert_inset(os, t.asInput() + "{" + color
+ "}", context);
diff --git a/src/version.h b/src/version.h
index 35de8f0..64ecd8f 100644
--- a/src/version.h
+++ b/src/version.h
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 490 // forenr: new origin tag
-#define LYX_FORMAT_TEX2LYX 490
+#define LYX_FORMAT_LYX 491 // uwestoehr: support more text colors
+#define LYX_FORMAT_TEX2LYX 491
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER