diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2025-01-17 16:07:37 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2025-01-20 01:40:10 +0100 |
commit | b9477183bb383c7a00d5ad2c27985fbd9d22173b (patch) | |
tree | e657b9fec4696f684fd5565fe93d83c38ad6dbc7 /tools/source/generic | |
parent | 2990620e202eb59edce160264e25ca63ba4a93ba (diff) |
tools: moved function to create the color from string to tools
Will be needed again in a follow up commit.
Change-Id: Idbe2f540f9c3fb974f7dadf62dc099a0791bb0c6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180378
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Jenkins
Diffstat (limited to 'tools/source/generic')
-rw-r--r-- | tools/source/generic/color.cxx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx index 0834b0946722..3a43c95d948b 100644 --- a/tools/source/generic/color.cxx +++ b/tools/source/generic/color.cxx @@ -28,6 +28,7 @@ #include <tools/helpers.hxx> #include <tools/long.hxx> #include <o3tl/string_view.hxx> +#include <o3tl/numeric.hxx> #include <basegfx/color/bcolortools.hxx> #include <basegfx/numeric/ftools.hxx> @@ -295,4 +296,24 @@ void Color::ApplyLumModOff(sal_Int16 nMod, sal_Int16 nOff) B = sal_uInt8(std::lround(aBColor.getBlue() * 255.0)); } +namespace color +{ +bool createFromString(OString const& rString, Color& rColor) +{ + if (rString.getLength() != 7) + return false; + + const char aChar(rString[0]); + + if (aChar != '#') + return false; + + rColor.SetRed(o3tl::convertToHex<sal_Int32>(rString[1], rString[2])); + rColor.SetGreen(o3tl::convertToHex<sal_Int32>(rString[3], rString[4])); + rColor.SetBlue(o3tl::convertToHex<sal_Int32>(rString[5], rString[6])); + + return true; +} +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |