From: André Pönitz Date: Thu, 26 Apr 2007 19:21:38 +0000 (+0000) Subject: I guess Windows folks are not too happy with files named color.h and Color.h X-Git-Tag: 1.6.10~10030 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=02703f47bfdb01dbe229d13ec02c9f567995f6ee;p=features.git I guess Windows folks are not too happy with files named color.h and Color.h git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18048 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BranchList.h b/src/BranchList.h index 550887a85a..0da9fe261f 100644 --- a/src/BranchList.h +++ b/src/BranchList.h @@ -30,9 +30,7 @@ #ifndef BRANCHES_H #define BRANCHES_H -#include "color.h" - -#include "support/docstring.h" +#include "Color.h" #include diff --git a/src/Color.cpp b/src/Color.cpp index 125321c1de..3474850fbc 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -22,29 +22,202 @@ #include "support/lstrings.h" #include +#include +#include +#include -namespace lyx { +#ifndef CXX_GLOBAL_CSTD +using std::floor; +#endif -using support::compare_ascii_no_case; -using support::ascii_lowercase; +using std::max; +using std::min; +using std::setw; -using std::endl; +using std::istringstream; +using std::ostringstream; using std::string; +using std::endl; + +using lyx::support::compare_ascii_no_case; +using lyx::support::ascii_lowercase; namespace { struct ColorEntry { - Color::color lcolor; + lyx::Color::color lcolor; char const * guiname; char const * latexname; char const * x11name; char const * lyxname; }; +int const nohue = -1; + +int hexstrToInt(string const & str) +{ + int val = 0; + istringstream is(str); + is >> std::setbase(16) >> val; + return val; +} + +} // namespace anon + + + +namespace lyx { + + +///////////////////////////////////////////////////////////////////// +// +// RGBColor +// +///////////////////////////////////////////////////////////////////// + + +string const X11hexname(RGBColor const & col) +{ + ostringstream ostr; + + ostr << '#' << std::setbase(16) << std::setfill('0') + << setw(2) << col.r + << setw(2) << col.g + << setw(2) << col.b; + + return ostr.str(); } + +RGBColor::RGBColor(string const & x11hexname) + : r(0), g(0), b(0) +{ + BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#'); + r = hexstrToInt(x11hexname.substr(1,2)); + g = hexstrToInt(x11hexname.substr(3,2)); + b = hexstrToInt(x11hexname.substr(5,2)); +} + + +RGBColor::RGBColor(HSVColor const & hsv) +{ + double h = hsv.h; + double const s = hsv.s; + double const v = hsv.v; + + double rd, gd, bd; + + if (h == nohue || s == 0.0) { + rd = gd = bd = v; + } else { + if (h == 360.0) h = 0.0; + h /= 60.0; + + int const j = max(0, static_cast(::floor(h))); + //if (j < 0) j = 0; + + double const f = h - j; + double const p = v * (1.0 - s); + double const q = v * (1.0 - (s * f)); + double const t = v * (1.0 - (s * (1.0 - f))); + + switch (j) { + case 0: + rd = v; + gd = t; + bd = p; + break; + case 1: + rd = q; + gd = v; + bd = p; + break; + case 2: + rd = p; + gd = v; + bd = t; + break; + case 3: + rd = p; + gd = q; + bd = v; + break; + case 4: + rd = t; + gd = p; + bd = v; + break; + case 5: + rd = v; + gd = p; + bd = q; + break; + default: + rd = v; + gd = t; + bd = p; + break; // should never happen. + } + } + + r = static_cast(::floor((rd * 255.0) + 0.5)); + g = static_cast(::floor((gd * 255.0) + 0.5)); + b = static_cast(::floor((bd * 255.0) + 0.5)); +} + + +///////////////////////////////////////////////////////////////////// +// +// HSVColor +// +///////////////////////////////////////////////////////////////////// + +HSVColor::HSVColor(RGBColor const & rgb) +{ + double const r = rgb.r / 255.0; + double const g = rgb.g / 255.0; + double const b = rgb.b / 255.0; + + double const maxval = max(max(r, g), b); + double const minval = min(min(r, g), b); + + v = maxval; + + double const diff = maxval - minval; + if (maxval != 0.0) + s = diff / maxval; + else + s = 0.0; + + h = nohue; + if (s != 0.0) { + double const rc = (maxval - r) / diff; + double const gc = (maxval - g) / diff; + double const bc = (maxval - b) / diff; + + if (r == maxval) + h = bc - gc; + else if (g == maxval) + h = 2.0 + rc - bc; + else if (b == maxval) + h = 4.0 + gc - rc; + + h *= 60.0; + if (h < 0) + h += 360; + } +} + + + +///////////////////////////////////////////////////////////////////// +// +// Color::Pimpl +// +///////////////////////////////////////////////////////////////////// + class Color::Pimpl { public: /// diff --git a/src/Color.h b/src/Color.h index c64ba16566..b2a43b7784 100644 --- a/src/Color.h +++ b/src/Color.h @@ -251,6 +251,55 @@ extern Color lcolor; extern Color system_lcolor; +struct RGBColor; +/// returns a string of form #rrggbb, given an RGBColor struct +std::string const X11hexname(RGBColor const & col); + +struct HSVColor { + double h; + double s; + double v; + HSVColor() : h(0.0), s(0.0), v(0.0) {} + HSVColor(double hue, double sat, double val) + : h(hue), s(sat), v(val) {} + HSVColor(RGBColor const &); +}; + +struct RGBColor { + unsigned int r; + unsigned int g; + unsigned int b; + RGBColor() : r(0), g(0), b(0) {} + RGBColor(unsigned int red, unsigned int green, unsigned int blue) + : r(red), g(green), b(blue) {} + RGBColor(HSVColor const &); + /// \param x11hexname is of the form "#ffa071" + RGBColor(std::string const & x11hexname); +}; + +struct NamedColor : public RGBColor { + std::string lyxname; + std::string guiname; + NamedColor() : RGBColor() {} + NamedColor(std::string const & lyx, std::string const & gui, + RGBColor const & c) + : RGBColor(c), lyxname(lyx), guiname(gui) {} + RGBColor const & color() const { return *this; } +}; + +inline +bool operator==(RGBColor const & c1, RGBColor const & c2) +{ + return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b); +} + + +inline +bool operator!=(RGBColor const & c1, RGBColor const & c2) +{ + return !(c1 == c2); +} + } // namespace lyx #endif diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 5dc426eecc..7b46065b8b 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -17,12 +17,11 @@ #include "LaTeXFeatures.h" #include "BufferParams.h" -#include "color.h" +#include "Color.h" #include "debug.h" #include "Encoding.h" #include "Floating.h" #include "FloatList.h" -#include "Color.h" #include "Language.h" #include "Lexer.h" #include "lyx_sty.h" diff --git a/src/Makefile.am b/src/Makefile.am index 9751daab06..088efd0539 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,144 +60,123 @@ endif lyx_SOURCES = \ - Bidi.cpp \ - Bidi.h \ - BufferView.cpp \ - BufferView.h \ - Bullet.cpp \ - Bullet.h \ - BranchList.cpp \ - BranchList.h \ - Chktex.cpp \ - Chktex.h \ - color.cpp \ - color.h \ - ConverterCache.cpp \ - ConverterCache.h \ - CutAndPaste.cpp \ - CutAndPaste.h \ - DepTable.cpp \ - DepTable.h \ - FloatList.cpp \ - FloatList.h \ - Floating.cpp \ - Floating.h \ - FontIterator.cpp \ - FontIterator.h \ - FuncStatus.cpp \ - FuncStatus.h \ - InsetList.cpp \ - InsetList.h \ - Color.cpp \ - Color.h \ - LaTeX.cpp \ - LaTeX.h \ - LaTeXFeatures.cpp \ - LaTeXFeatures.h \ - LyXAction.cpp \ - LyXAction.h \ - MenuBackend.cpp \ - MenuBackend.h \ - ParagraphList.h \ - ParagraphList_fwd.h \ - ParagraphParameters.cpp \ - ParagraphParameters.h \ - PrinterParams.cpp \ - PrinterParams.h \ - RowList_fwd.h \ - Spacing.cpp \ - Spacing.h \ - Thesaurus.cpp \ - Thesaurus.h \ - ToolbarBackend.cpp \ - ToolbarBackend.h \ - UpdateFlags.h \ - WordLangTuple.h \ + $(ASPELL) $(PSPELL) $(ISPELL) SpellBase.cpp \ Author.cpp \ Author.h \ + Bidi.cpp \ + Bidi.h \ boost.cpp \ - Box.h \ Box.cpp \ + Box.h \ + BranchList.cpp \ + BranchList.h \ Buffer.cpp \ - Buffer.h \ buffer_funcs.cpp \ buffer_funcs.h \ + Buffer.h \ BufferList.cpp \ BufferList.h \ BufferParams.cpp \ BufferParams.h \ + BufferView.cpp \ bufferview_funcs.cpp \ bufferview_funcs.h \ + BufferView.h \ + Bullet.cpp \ + Bullet.h \ Changes.cpp \ Changes.h \ + Chktex.cpp \ + Chktex.h \ + Color.cpp \ + Color.h \ config.h.in \ + ConverterCache.cpp \ + ConverterCache.h \ Converter.cpp \ Converter.h \ - Counters.cpp \ - Counters.h \ CoordCache.cpp \ CoordCache.h \ + Counters.cpp \ + Counters.h \ Cursor.cpp \ Cursor.h \ CursorSlice.cpp \ CursorSlice.h \ + CutAndPaste.cpp \ + CutAndPaste.h \ debug.cpp \ debug.h \ + DepTable.cpp \ + DepTable.h \ Dimension.cpp \ Dimension.h \ + DispatchResult.h \ DocIterator.cpp \ DocIterator.h \ - DispatchResult.h \ Encoding.cpp \ Encoding.h \ ErrorList.cpp \ ErrorList.h \ Exporter.cpp \ Exporter.h \ - gettext.cpp \ - gettext.h \ - factory.h \ factory.cpp \ + factory.h \ + Floating.cpp \ + Floating.h \ + FloatList.cpp \ + FloatList.h \ + FontIterator.cpp \ + FontIterator.h \ Format.cpp \ Format.h \ - FuncRequest.h \ FuncRequest.cpp \ + FuncRequest.h \ + FuncStatus.cpp \ + FuncStatus.h \ + gettext.cpp \ + gettext.h \ Graph.cpp \ Graph.h \ Importer.cpp \ Importer.h \ - Intl.cpp \ - Intl.h \ InsetIterator.cpp \ InsetIterator.h \ + InsetList.cpp \ + InsetList.h \ + Intl.cpp \ + Intl.h \ kb_keymap.cpp \ kb_keymap.h \ kb_sequence.cpp \ kb_sequence.h \ + KmodInfo.h \ Language.cpp \ Language.h \ - Session.cpp \ - Session.h \ + LaTeX.cpp \ + LaTeXFeatures.cpp \ + LaTeXFeatures.h \ + LaTeX.h \ layout.h \ lengthcommon.cpp \ lengthcommon.h \ Lexer.cpp \ Lexer.h \ lfuns.h \ + LyXAction.cpp \ + LyXAction.h \ lyx_cb.cpp \ lyx_cb.h \ LyX.cpp \ - LyX.h \ - lyx_sty.cpp \ - lyx_sty.h \ - LyXFont.cpp \ - LyXFont.h \ lyxfind.cpp \ lyxfind.h \ + LyXFont.cpp \ + LyXFont.h \ LyXFunc.cpp \ LyXFunc.h \ LyXGlueLength.cpp \ LyXGlueLength.h \ + LyX.h \ LyXLayout.cpp \ LyXLayout.h \ lyxlayout_ptr_fwd.h \ @@ -205,19 +184,21 @@ lyx_SOURCES = \ LyXLength.h \ LyXRC.cpp \ LyXRC.h \ - Row.cpp \ - Row.h \ LyXServer.cpp \ LyXServer.h \ LyXServerSocket.cpp \ LyXServerSocket.h \ - LyXText.h \ + lyx_sty.cpp \ + lyx_sty.h \ LyXTextClass.cpp \ LyXTextClass.h \ LyXTextClassList.cpp \ LyXTextClassList.h \ + LyXText.h \ LyXVC.cpp \ LyXVC.h \ + MenuBackend.cpp \ + MenuBackend.h \ Messages.cpp \ Messages.h \ MetricsInfo.cpp \ @@ -225,56 +206,73 @@ lyx_SOURCES = \ Mover.cpp \ Mover.h \ output.cpp \ - output.h \ - OutputParams.cpp \ - OutputParams.h \ output_docbook.cpp \ output_docbook.h \ + output.h \ output_latex.cpp \ output_latex.h \ + OutputParams.cpp \ + OutputParams.h \ output_plaintext.cpp \ output_plaintext.h \ paper.h \ Paragraph.cpp \ + paragraph_funcs.cpp \ + paragraph_funcs.h \ Paragraph.h \ + ParagraphList_fwd.h \ + ParagraphList.h \ ParagraphMetrics.cpp \ ParagraphMetrics.h \ - paragraph_funcs.cpp \ - paragraph_funcs.h \ + ParagraphParameters.cpp \ + ParagraphParameters.h \ ParIterator.cpp \ ParIterator.h \ - $(ASPELL) $(PSPELL) $(ISPELL) SpellBase.cpp \ - SpellBase.h \ + PrinterParams.cpp \ + PrinterParams.h \ + Row.cpp \ + Row.h \ + RowList_fwd.h \ rowpainter.cpp \ rowpainter.h \ + Session.cpp \ + Session.h \ sgml.cpp \ sgml.h \ + Spacing.cpp \ + Spacing.h \ + SpellBase.h \ tex-accent.cpp \ tex-accent.h \ - tex-strings.cpp \ - tex-strings.h \ TexRow.cpp \ TexRow.h \ - text.cpp \ + tex-strings.cpp \ + tex-strings.h \ text2.cpp \ text3.cpp \ + text.cpp \ TextMetrics.cpp \ TextMetrics.h \ + Thesaurus.cpp \ + Thesaurus.h \ TocBackend.cpp \ TocBackend.h \ toc.cpp \ toc.h \ + ToolbarBackend.cpp \ + ToolbarBackend.h \ Trans.cpp \ Trans.h \ - KmodInfo.h \ TransState.cpp \ TransState.h \ Undo.cpp \ Undo.h \ + UpdateFlags.h \ VCBackend.cpp \ VCBackend.h \ version.C \ version.h \ + WordLangTuple.h \ VSpace.cpp \ VSpace.h diff --git a/src/color.cpp b/src/color.cpp deleted file mode 100644 index 1722b8b5b1..0000000000 --- a/src/color.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/** - * \file color.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "color.h" - -#include "Color.h" - -#include -#include -#include - -#ifndef CXX_GLOBAL_CSTD -using std::floor; -#endif - -using std::max; -using std::min; -using std::setw; - -using std::istringstream; -using std::ostringstream; -using std::string; - -namespace lyx { - -namespace { - -int const nohue = -1; - -int hexstrToInt(string const & str) -{ - int val = 0; - istringstream is(str); - is >> std::setbase(16) >> val; - return val; -} - -} // namespace anon - - - -string const X11hexname(RGBColor const & col) -{ - ostringstream ostr; - - ostr << '#' << std::setbase(16) << std::setfill('0') - << setw(2) << col.r - << setw(2) << col.g - << setw(2) << col.b; - - return ostr.str(); -} - - -RGBColor::RGBColor(string const & x11hexname) - : r(0), g(0), b(0) -{ - BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#'); - r = hexstrToInt(x11hexname.substr(1,2)); - g = hexstrToInt(x11hexname.substr(3,2)); - b = hexstrToInt(x11hexname.substr(5,2)); -} - - -RGBColor::RGBColor(HSVColor const & hsv) -{ - double h = hsv.h; - double const s = hsv.s; - double const v = hsv.v; - - double rd, gd, bd; - - if (h == nohue || s == 0.0) { - rd = gd = bd = v; - } else { - if (h == 360.0) h = 0.0; - h /= 60.0; - - int const j = max(0, static_cast(::floor(h))); - //if (j < 0) j = 0; - - double const f = h - j; - double const p = v * (1.0 - s); - double const q = v * (1.0 - (s * f)); - double const t = v * (1.0 - (s * (1.0 - f))); - - switch (j) { - case 0: - rd = v; - gd = t; - bd = p; - break; - case 1: - rd = q; - gd = v; - bd = p; - break; - case 2: - rd = p; - gd = v; - bd = t; - break; - case 3: - rd = p; - gd = q; - bd = v; - break; - case 4: - rd = t; - gd = p; - bd = v; - break; - case 5: - rd = v; - gd = p; - bd = q; - break; - default: - rd = v; - gd = t; - bd = p; - break; // should never happen. - } - } - - r = static_cast(::floor((rd * 255.0) + 0.5)); - g = static_cast(::floor((gd * 255.0) + 0.5)); - b = static_cast(::floor((bd * 255.0) + 0.5)); -} - - -HSVColor::HSVColor(RGBColor const & rgb) -{ - double const r = rgb.r / 255.0; - double const g = rgb.g / 255.0; - double const b = rgb.b / 255.0; - - double const maxval = max(max(r, g), b); - double const minval = min(min(r, g), b); - - v = maxval; - - double const diff = maxval - minval; - if (maxval != 0.0) - s = diff / maxval; - else - s = 0.0; - - h = nohue; - if (s != 0.0) { - double const rc = (maxval - r) / diff; - double const gc = (maxval - g) / diff; - double const bc = (maxval - b) / diff; - - if (r == maxval) - h = bc - gc; - else if (g == maxval) - h = 2.0 + rc - bc; - else if (b == maxval) - h = 4.0 + gc - rc; - - h *= 60.0; - if (h < 0) - h += 360; - } -} - -} // namespace lyx diff --git a/src/color.h b/src/color.h deleted file mode 100644 index 7270991f09..0000000000 --- a/src/color.h +++ /dev/null @@ -1,74 +0,0 @@ -// -*- C++ -*- -/** - * \file color.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -/* structs RGBColor and HSVColor to enable simple conversion between - * color spaces. - */ - -#ifndef COLOR_H -#define COLOR_H - -#include - -namespace lyx { - -struct RGBColor; -/// returns a string of form #rrggbb, given an RGBColor struct -std::string const X11hexname(RGBColor const & col); - -struct HSVColor { - double h; - double s; - double v; - HSVColor() : h(0.0), s(0.0), v(0.0) {} - HSVColor(double hue, double sat, double val) - : h(hue), s(sat), v(val) {} - HSVColor(RGBColor const &); -}; - -struct RGBColor { - unsigned int r; - unsigned int g; - unsigned int b; - RGBColor() : r(0), g(0), b(0) {} - RGBColor(unsigned int red, unsigned int green, unsigned int blue) - : r(red), g(green), b(blue) {} - RGBColor(HSVColor const &); - /// \param x11hexname is of the form "#ffa071" - RGBColor(std::string const & x11hexname); -}; - -struct NamedColor : public RGBColor { - std::string lyxname; - std::string guiname; - NamedColor() : RGBColor() {} - NamedColor(std::string const & lyx, std::string const & gui, - RGBColor const & c) - : RGBColor(c), lyxname(lyx), guiname(gui) {} - RGBColor const & color() const { return *this; } -}; - -inline -bool operator==(RGBColor const & c1, RGBColor const & c2) -{ - return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b); -} - - -inline -bool operator!=(RGBColor const & c1, RGBColor const & c2) -{ - return !(c1 == c2); -} - -} // namespace lyx - -#endif diff --git a/src/frontends/qt4/ColorCache.cpp b/src/frontends/qt4/ColorCache.cpp index 7c5127d9f2..4a77f0ff63 100644 --- a/src/frontends/qt4/ColorCache.cpp +++ b/src/frontends/qt4/ColorCache.cpp @@ -10,9 +10,7 @@ #include -#include "color.h" #include "ColorCache.h" - #include "Color.h" diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 971cf53e9e..86dd43e9b3 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -27,7 +27,7 @@ #include "support/Package.h" #include "BufferView.h" -#include "color.h" +#include "Color.h" #include "debug.h" #include "FuncRequest.h" #include "LyX.h"