[Libreoffice-commits] core.git: include/tools tools/source
dante (via logerrit)
logerrit at kemper.freedesktop.org
Sat Nov 21 06:18:07 UTC 2020
include/tools/color.hxx | 21 ++++++++++++++++++++-
tools/source/generic/color.cxx | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
New commits:
commit fcc9128aabb56d521e71e3e537d895e640c86004
Author: dante <dante19031999 at gmail.com>
AuthorDate: Fri Nov 20 12:33:57 2020 +0100
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Nov 21 07:17:26 2020 +0100
Changes to the color class
Before colors could be only converted to string rrggbb. Now also supports RRGGBB. It can also be converted back into a color.
Change-Id: Ifb89d554b434c243c4f0956ee680ec23de823339
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106224
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/tools/color.hxx b/include/tools/color.hxx
index dfa84d255dbc..99966c65d779 100644
--- a/include/tools/color.hxx
+++ b/include/tools/color.hxx
@@ -333,6 +333,19 @@ public:
*/
static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness);
+ /** Converts a string into a color. Supports:
+ * #RRGGBB
+ * #rrggbb
+ * #RGB
+ * #rgb
+ * RRGGBB
+ * rrggbb
+ * RGB
+ * rgb
+ * If fails returns Color().
+ */
+ static Color STRtoRGB(const OUString& colorname);
+
/** Color space conversion tools
* @param nHue
* @param nSaturation
@@ -340,12 +353,18 @@ public:
*/
void RGBtoHSB(sal_uInt16& nHue, sal_uInt16& nSaturation, sal_uInt16& nBrightness) const;
- /* Return color as RGB hex string
+ /* Return color as RGB hex string: rrggbb
* for example "00ff00" for green color
* @return hex string
*/
OUString AsRGBHexString() const;
+ /* Return color as RGB hex string: RRGGBB
+ * for example "00FF00" for green color
+ * @return hex string
+ */
+ OUString AsRGBHEXString() const;
+
/* get ::basegfx::BColor from this color
* @return basegfx color
*/
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx
index 2b7c5cc35102..cf4e084b722f 100644
--- a/tools/source/generic/color.cxx
+++ b/tools/source/generic/color.cxx
@@ -158,6 +158,38 @@ Color Color::HSBtoRGB( sal_uInt16 nHue, sal_uInt16 nSat, sal_uInt16 nBri )
return Color( cR, cG, cB );
}
+Color Color::STRtoRGB(const OUString& colorname)
+{
+ Color col;
+ if(colorname.isEmpty()) return col;
+
+ switch(colorname.getLength()){
+ case 7:
+ col.mValue = colorname.copy(1,6).toUInt32(16);
+ break;
+ case 6:
+ col.mValue = colorname.toUInt32(16);
+ break;
+ case 4:
+ {
+ sal_Unicode data[6] = { colorname[1], colorname[1], colorname[2],
+ colorname[2], colorname[3], colorname[3] };
+ col.mValue = OUString(data,6).toUInt32(16);
+ break;
+ }
+ case 3:
+ {
+ sal_Unicode data[6] = { colorname[0], colorname[0], colorname[1],
+ colorname[1], colorname[2], colorname[2] };
+ col.mValue = OUString(data,6).toUInt32(16);
+ break;
+ }
+ default:
+ break;
+ }
+ return col;
+}
+
OUString Color::AsRGBHexString() const
{
std::stringstream ss;
@@ -165,6 +197,13 @@ OUString Color::AsRGBHexString() const
return OUString::createFromAscii(ss.str().c_str());
}
+OUString Color::AsRGBHEXString() const
+{
+ std::stringstream ss;
+ ss << std::hex << std::uppercase << std::setfill ('0') << std::setw(6) << sal_uInt32(GetRGBColor());
+ return OUString::createFromAscii(ss.str().c_str());
+}
+
void Color::ApplyTintOrShade(sal_Int16 n100thPercent)
{
if (n100thPercent == 0)
More information about the Libreoffice-commits
mailing list