diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-04-27 11:18:42 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-04-27 06:48:18 +0200 |
commit | cae53cf14d59bc2fa6317c9493197804928d6e5e (patch) | |
tree | 4420d17bf2c9f1aa001c98c5c140ebd7ed04c30e /tools/source | |
parent | 55e28737e973b40f72d398c9bb7a4a41307eb562 (diff) |
Decouple reading/writing of Color into GenericTypeSerializer
This adds GenericTypeSerializer, which is now responsible of
serializing the Color into a stream (other types will follow), but
only for the older version of the binary format. The new version
we just write the sal_UInt32 mValue directly.
This is a start of decoupling the serialization of generic types
in tools and vcl module from the actual type, so we can in the
future replace those with basegfx variant.
Change-Id: I92738e7c178cac5cbca882dcbe45c80cc8269466
Reviewed-on: https://gerrit.libreoffice.org/71404
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'tools/source')
-rw-r--r-- | tools/source/generic/color.cxx | 96 | ||||
-rw-r--r-- | tools/source/stream/GenericTypeSerializer.cxx | 105 |
2 files changed, 105 insertions, 96 deletions
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx index f79342d37862..a06c6e84a964 100644 --- a/tools/source/generic/color.cxx +++ b/tools/source/generic/color.cxx @@ -25,7 +25,6 @@ #include <stdlib.h> #include <tools/color.hxx> -#include <tools/stream.hxx> #include <tools/helpers.hxx> #include <basegfx/color/bcolortools.hxx> @@ -184,18 +183,6 @@ Color Color::HSBtoRGB( sal_uInt16 nHue, sal_uInt16 nSat, sal_uInt16 nBri ) return Color( cR, cG, cB ); } -SvStream& Color::Read( SvStream& rIStm ) -{ - rIStm.ReadUInt32(mValue); - return rIStm; -} - -SvStream& Color::Write( SvStream& rOStm ) const -{ - rOStm.WriteUInt32(mValue); - return rOStm; -} - OUString Color::AsRGBHexString() const { std::stringstream ss; @@ -203,72 +190,6 @@ OUString Color::AsRGBHexString() const return OUString::createFromAscii(ss.str().c_str()); } -#define COL_NAME_USER (sal_uInt16(0x8000)) - -SvStream& ReadColor( SvStream& rIStream, Color& rColor ) -{ - sal_uInt16 nColorName(0); - - rIStream.ReadUInt16( nColorName ); - - if ( nColorName & COL_NAME_USER ) - { - sal_uInt16 nRed; - sal_uInt16 nGreen; - sal_uInt16 nBlue; - - rIStream.ReadUInt16( nRed ); - rIStream.ReadUInt16( nGreen ); - rIStream.ReadUInt16( nBlue ); - - rColor = Color( nRed>>8, nGreen>>8, nBlue>>8 ); - } - else - { - static const Color aColAry[] = - { - COL_BLACK, // COL_BLACK - COL_BLUE, // COL_BLUE - COL_GREEN, // COL_GREEN - COL_CYAN, // COL_CYAN - COL_RED, // COL_RED - COL_MAGENTA, // COL_MAGENTA - COL_BROWN, // COL_BROWN - COL_GRAY, // COL_GRAY - COL_LIGHTGRAY, // COL_LIGHTGRAY - COL_LIGHTBLUE, // COL_LIGHTBLUE - COL_LIGHTGREEN, // COL_LIGHTGREEN - COL_LIGHTCYAN, // COL_LIGHTCYAN - COL_LIGHTRED, // COL_LIGHTRED - COL_LIGHTMAGENTA, // COL_LIGHTMAGENTA - COL_YELLOW, // COL_YELLOW - COL_WHITE, // COL_WHITE - COL_WHITE, // COL_MENUBAR - COL_BLACK, // COL_MENUBARTEXT - COL_WHITE, // COL_POPUPMENU - COL_BLACK, // COL_POPUPMENUTEXT - COL_BLACK, // COL_WINDOWTEXT - COL_WHITE, // COL_WINDOWWORKSPACE - COL_BLACK, // COL_HIGHLIGHT - COL_WHITE, // COL_HIGHLIGHTTEXT - COL_BLACK, // COL_3DTEXT - COL_LIGHTGRAY, // COL_3DFACE - COL_WHITE, // COL_3DLIGHT - COL_GRAY, // COL_3DSHADOW - COL_LIGHTGRAY, // COL_SCROLLBAR - COL_WHITE, // COL_FIELD - COL_BLACK // COL_FIELDTEXT - }; - - if ( nColorName < SAL_N_ELEMENTS( aColAry ) ) - rColor = aColAry[nColorName]; - else - rColor = COL_BLACK; - } - - return rIStream; -} - void Color::ApplyTintOrShade(sal_Int16 n100thPercent) { if (n100thPercent == 0) @@ -295,21 +216,4 @@ void Color::ApplyTintOrShade(sal_Int16 n100thPercent) B = sal_uInt8(std::lround(aBColor.getBlue() * 255.0)); } -SvStream& WriteColor( SvStream& rOStream, const Color& rColor ) -{ - sal_uInt16 nRed = rColor.GetRed(); - sal_uInt16 nGreen = rColor.GetGreen(); - sal_uInt16 nBlue = rColor.GetBlue(); - nRed = (nRed<<8) + nRed; - nGreen = (nGreen<<8) + nGreen; - nBlue = (nBlue<<8) + nBlue; - - rOStream.WriteUInt16( COL_NAME_USER ); - rOStream.WriteUInt16( nRed ); - rOStream.WriteUInt16( nGreen ); - rOStream.WriteUInt16( nBlue ); - - return rOStream; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/stream/GenericTypeSerializer.cxx b/tools/source/stream/GenericTypeSerializer.cxx new file mode 100644 index 000000000000..7e261350ad50 --- /dev/null +++ b/tools/source/stream/GenericTypeSerializer.cxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <tools/GenericTypeSerializer.hxx> +#include <vector> + +namespace tools +{ +constexpr sal_uInt16 COL_NAME_USER = 0x8000; + +void GenericTypeSerializer::readColor(Color& rColor) +{ + sal_uInt16 nColorNameID(0); + + mrStream.ReadUInt16(nColorNameID); + + if (nColorNameID & COL_NAME_USER) + { + sal_uInt16 nRed; + sal_uInt16 nGreen; + sal_uInt16 nBlue; + + mrStream.ReadUInt16(nRed); + mrStream.ReadUInt16(nGreen); + mrStream.ReadUInt16(nBlue); + + rColor = Color(nRed >> 8, nGreen >> 8, nBlue >> 8); + } + else + { + static const std::vector<Color> staticColorArray = { + COL_BLACK, // COL_BLACK + COL_BLUE, // COL_BLUE + COL_GREEN, // COL_GREEN + COL_CYAN, // COL_CYAN + COL_RED, // COL_RED + COL_MAGENTA, // COL_MAGENTA + COL_BROWN, // COL_BROWN + COL_GRAY, // COL_GRAY + COL_LIGHTGRAY, // COL_LIGHTGRAY + COL_LIGHTBLUE, // COL_LIGHTBLUE + COL_LIGHTGREEN, // COL_LIGHTGREEN + COL_LIGHTCYAN, // COL_LIGHTCYAN + COL_LIGHTRED, // COL_LIGHTRED + COL_LIGHTMAGENTA, // COL_LIGHTMAGENTA + COL_YELLOW, // COL_YELLOW + COL_WHITE, // COL_WHITE + COL_WHITE, // COL_MENUBAR + COL_BLACK, // COL_MENUBARTEXT + COL_WHITE, // COL_POPUPMENU + COL_BLACK, // COL_POPUPMENUTEXT + COL_BLACK, // COL_WINDOWTEXT + COL_WHITE, // COL_WINDOWWORKSPACE + COL_BLACK, // COL_HIGHLIGHT + COL_WHITE, // COL_HIGHLIGHTTEXT + COL_BLACK, // COL_3DTEXT + COL_LIGHTGRAY, // COL_3DFACE + COL_WHITE, // COL_3DLIGHT + COL_GRAY, // COL_3DSHADOW + COL_LIGHTGRAY, // COL_SCROLLBAR + COL_WHITE, // COL_FIELD + COL_BLACK // COL_FIELDTEXT + }; + + if (nColorNameID < staticColorArray.size()) + rColor = staticColorArray[nColorNameID]; + else + rColor = COL_BLACK; + } +} + +void GenericTypeSerializer::writeColor(const Color& rColor) +{ + mrStream.WriteUInt16(COL_NAME_USER); + + sal_uInt16 nR = rColor.GetRed(); + sal_uInt16 nG = rColor.GetGreen(); + sal_uInt16 nB = rColor.GetBlue(); + + mrStream.WriteUInt16((nR << 8) + nR); + mrStream.WriteUInt16((nG << 8) + nG); + mrStream.WriteUInt16((nB << 8) + nB); +} + +} // end namespace tools + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |