Bump version to 21.06.18.1
[LibreOffice.git] / tools / source / stream / GenericTypeSerializer.cxx
blobc099713d24ac91bc782741c45c2e8fcd1c989e7d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <tools/GenericTypeSerializer.hxx>
23 #include <vector>
25 namespace tools
27 constexpr sal_uInt16 COL_NAME_USER = 0x8000;
29 constexpr sal_Int32 RECT_EMPTY_VALUE_RIGHT_BOTTOM = -32767;
31 void GenericTypeSerializer::readColor(Color& rColor)
33 sal_uInt16 nColorNameID(0);
35 mrStream.ReadUInt16(nColorNameID);
37 if (nColorNameID & COL_NAME_USER)
39 sal_uInt16 nRed;
40 sal_uInt16 nGreen;
41 sal_uInt16 nBlue;
43 mrStream.ReadUInt16(nRed);
44 mrStream.ReadUInt16(nGreen);
45 mrStream.ReadUInt16(nBlue);
47 rColor = Color(nRed >> 8, nGreen >> 8, nBlue >> 8);
49 else
51 static const std::vector<Color> staticColorArray = {
52 COL_BLACK, // COL_BLACK
53 COL_BLUE, // COL_BLUE
54 COL_GREEN, // COL_GREEN
55 COL_CYAN, // COL_CYAN
56 COL_RED, // COL_RED
57 COL_MAGENTA, // COL_MAGENTA
58 COL_BROWN, // COL_BROWN
59 COL_GRAY, // COL_GRAY
60 COL_LIGHTGRAY, // COL_LIGHTGRAY
61 COL_LIGHTBLUE, // COL_LIGHTBLUE
62 COL_LIGHTGREEN, // COL_LIGHTGREEN
63 COL_LIGHTCYAN, // COL_LIGHTCYAN
64 COL_LIGHTRED, // COL_LIGHTRED
65 COL_LIGHTMAGENTA, // COL_LIGHTMAGENTA
66 COL_YELLOW, // COL_YELLOW
67 COL_WHITE, // COL_WHITE
68 COL_WHITE, // COL_MENUBAR
69 COL_BLACK, // COL_MENUBARTEXT
70 COL_WHITE, // COL_POPUPMENU
71 COL_BLACK, // COL_POPUPMENUTEXT
72 COL_BLACK, // COL_WINDOWTEXT
73 COL_WHITE, // COL_WINDOWWORKSPACE
74 COL_BLACK, // COL_HIGHLIGHT
75 COL_WHITE, // COL_HIGHLIGHTTEXT
76 COL_BLACK, // COL_3DTEXT
77 COL_LIGHTGRAY, // COL_3DFACE
78 COL_WHITE, // COL_3DLIGHT
79 COL_GRAY, // COL_3DSHADOW
80 COL_LIGHTGRAY, // COL_SCROLLBAR
81 COL_WHITE, // COL_FIELD
82 COL_BLACK // COL_FIELDTEXT
85 if (nColorNameID < staticColorArray.size())
86 rColor = staticColorArray[nColorNameID];
87 else
88 rColor = COL_BLACK;
92 void GenericTypeSerializer::writeColor(const Color& rColor)
94 mrStream.WriteUInt16(COL_NAME_USER);
96 sal_uInt16 nR = rColor.GetRed();
97 sal_uInt16 nG = rColor.GetGreen();
98 sal_uInt16 nB = rColor.GetBlue();
100 mrStream.WriteUInt16((nR << 8) + nR);
101 mrStream.WriteUInt16((nG << 8) + nG);
102 mrStream.WriteUInt16((nB << 8) + nB);
105 void GenericTypeSerializer::readPoint(Point& rPoint)
107 sal_Int32 nX(0);
108 sal_Int32 nY(0);
110 mrStream.ReadInt32(nX);
111 mrStream.ReadInt32(nY);
113 rPoint.setX(nX);
114 rPoint.setY(nY);
117 void GenericTypeSerializer::writePoint(const Point& rPoint)
119 mrStream.WriteInt32(rPoint.getX());
120 mrStream.WriteInt32(rPoint.getY());
123 void GenericTypeSerializer::readSize(Size& rSize)
125 sal_Int32 nWidth(0);
126 sal_Int32 nHeight(0);
128 mrStream.ReadInt32(nWidth);
129 mrStream.ReadInt32(nHeight);
131 rSize.setWidth(nWidth);
132 rSize.setHeight(nHeight);
135 void GenericTypeSerializer::writeSize(const Size& rSize)
137 mrStream.WriteInt32(rSize.getWidth());
138 mrStream.WriteInt32(rSize.getHeight());
141 void GenericTypeSerializer::readRectangle(Rectangle& rRectangle)
143 sal_Int32 nLeft(0);
144 sal_Int32 nTop(0);
145 sal_Int32 nRight(0);
146 sal_Int32 nBottom(0);
148 mrStream.ReadInt32(nLeft);
149 mrStream.ReadInt32(nTop);
150 mrStream.ReadInt32(nRight);
151 mrStream.ReadInt32(nBottom);
153 if (nRight == RECT_EMPTY_VALUE_RIGHT_BOTTOM || nBottom == RECT_EMPTY_VALUE_RIGHT_BOTTOM)
155 rRectangle.SetEmpty();
157 else
159 rRectangle.SetLeft(nLeft);
160 rRectangle.SetTop(nTop);
161 rRectangle.SetRight(nRight);
162 rRectangle.SetBottom(nBottom);
166 void GenericTypeSerializer::writeRectangle(const Rectangle& rRectangle)
168 if (rRectangle.IsEmpty())
170 mrStream.WriteInt32(0);
171 mrStream.WriteInt32(0);
172 mrStream.WriteInt32(RECT_EMPTY_VALUE_RIGHT_BOTTOM);
173 mrStream.WriteInt32(RECT_EMPTY_VALUE_RIGHT_BOTTOM);
175 else
177 mrStream.WriteInt32(rRectangle.Left());
178 mrStream.WriteInt32(rRectangle.Top());
179 mrStream.WriteInt32(rRectangle.Right());
180 mrStream.WriteInt32(rRectangle.Bottom());
184 } // end namespace tools
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */