LibreOffice Module tools (master) 1
GenericTypeSerializer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <sal/config.h>
22#include <sal/log.hxx>
23#include <vector>
24
25namespace tools
26{
27constexpr sal_uInt16 COL_NAME_USER = 0x8000;
28
29constexpr sal_Int32 RECT_EMPTY_VALUE_RIGHT_BOTTOM = -32767;
30
32{
33 sal_uInt16 nColorNameID(0);
34
35 mrStream.ReadUInt16(nColorNameID);
36
37 if (nColorNameID & COL_NAME_USER)
38 {
39 sal_uInt16 nRed(0);
40 sal_uInt16 nGreen(0);
41 sal_uInt16 nBlue(0);
42
43 mrStream.ReadUInt16(nRed);
44 mrStream.ReadUInt16(nGreen);
45 mrStream.ReadUInt16(nBlue);
46
47 rColor = Color(nRed >> 8, nGreen >> 8, nBlue >> 8);
48 }
49 else
50 {
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
83 };
84
85 if (nColorNameID < staticColorArray.size())
86 rColor = staticColorArray[nColorNameID];
87 else
88 rColor = COL_BLACK;
89 }
90}
91
93{
95
96 sal_uInt16 nR = rColor.GetRed();
97 sal_uInt16 nG = rColor.GetGreen();
98 sal_uInt16 nB = rColor.GetBlue();
99
100 mrStream.WriteUInt16((nR << 8) + nR);
101 mrStream.WriteUInt16((nG << 8) + nG);
102 mrStream.WriteUInt16((nB << 8) + nB);
103}
104
106{
107 sal_Int32 nX(0);
108 sal_Int32 nY(0);
109
112
113 rPoint.setX(nX);
114 rPoint.setY(nY);
115}
116
118{
119 mrStream.WriteInt32(rPoint.getX());
120 mrStream.WriteInt32(rPoint.getY());
121}
122
124{
125 sal_Int32 nWidth(0);
126 sal_Int32 nHeight(0);
127
128 mrStream.ReadInt32(nWidth);
129 mrStream.ReadInt32(nHeight);
130
131 rSize.setWidth(nWidth);
132 rSize.setHeight(nHeight);
133
134 // sanitize negative size dimensions
135 if (rSize.Width() < 0)
136 {
137 SAL_WARN("tools", "negative width");
138 rSize.setWidth(0);
139 }
140 if (rSize.Height() < 0)
141 {
142 SAL_WARN("tools", "negative height");
143 rSize.setHeight(0);
144 }
145}
146
148{
151}
152
154{
155 sal_Int32 nLeft(0);
156 sal_Int32 nTop(0);
157 sal_Int32 nRight(0);
158 sal_Int32 nBottom(0);
159
160 mrStream.ReadInt32(nLeft);
161 mrStream.ReadInt32(nTop);
162 mrStream.ReadInt32(nRight);
163 mrStream.ReadInt32(nBottom);
164
166 {
167 rRectangle.SetEmpty();
168 }
169 else
170 {
171 rRectangle.SetLeft(nLeft);
172 rRectangle.SetTop(nTop);
173 rRectangle.SetRight(nRight);
174 rRectangle.SetBottom(nBottom);
175 }
176}
177
179{
180 if (rRectangle.IsEmpty())
181 {
186 }
187 else
188 {
189 mrStream.WriteInt32(rRectangle.Left());
190 mrStream.WriteInt32(rRectangle.Top());
191 mrStream.WriteInt32(rRectangle.Right());
192 mrStream.WriteInt32(rRectangle.Bottom());
193 }
194}
195
197{
198 sal_Int32 nNumerator(0);
199 sal_Int32 nDenominator(0);
200
201 mrStream.ReadInt32(nNumerator);
202 mrStream.ReadInt32(nDenominator);
203
204 rFraction = Fraction(nNumerator, nDenominator);
205}
206
208{
209 if (!rFraction.IsValid())
210 {
211 SAL_WARN("tools.fraction", "'writeFraction()' write an invalid fraction");
214 }
215 else
216 {
217 mrStream.WriteInt32(rFraction.GetNumerator());
219 }
220}
221
222} // end namespace tools
223
224/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: color.hxx:51
sal_uInt8 GetBlue() const
Gets the blue value.
Definition: color.hxx:156
sal_uInt8 GetRed() const
Gets the red value.
Definition: color.hxx:140
sal_uInt8 GetGreen() const
Gets the green value.
Definition: color.hxx:148
sal_Int32 GetNumerator() const
Definition: fract.cxx:282
sal_Int32 GetDenominator() const
Definition: fract.cxx:292
bool IsValid() const
Definition: fract.hxx:49
Definition: gen.hxx:78
void setX(tools::Long nX)
Definition: gen.hxx:107
void setY(tools::Long nY)
Definition: gen.hxx:108
constexpr tools::Long getX() const
Definition: gen.hxx:105
constexpr tools::Long getY() const
Definition: gen.hxx:106
Definition: gen.hxx:212
constexpr tools::Long getHeight() const
Definition: gen.hxx:224
constexpr tools::Long Height() const
Definition: gen.hxx:218
constexpr tools::Long getWidth() const
Definition: gen.hxx:223
void setWidth(tools::Long nWidth)
Definition: gen.hxx:225
void setHeight(tools::Long nHeight)
Definition: gen.hxx:226
constexpr tools::Long Width() const
Definition: gen.hxx:217
SvStream & WriteInt32(sal_Int32 nInt32)
Definition: stream.cxx:953
SvStream & WriteUInt16(sal_uInt16 nUInt16)
Definition: stream.cxx:949
SvStream & ReadInt32(sal_Int32 &rInt32)
Definition: stream.cxx:825
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
Definition: stream.cxx:821
void writeFraction(Fraction const &rFraction)
void writeColor(const Color &rColor)
void writePoint(const Point &rPoint)
void readFraction(Fraction &rFraction)
void readRectangle(Rectangle &rRectangle)
void writeRectangle(const Rectangle &rRectangle)
constexpr void SetLeft(tools::Long v)
Definition: gen.hxx:505
void SetEmpty()
Definition: gen.hxx:555
constexpr void SetTop(tools::Long v)
Definition: gen.hxx:507
constexpr tools::Long Top() const
Definition: gen.hxx:502
constexpr void SetRight(tools::Long v)
Definition: gen.hxx:506
constexpr tools::Long Right() const
Definition: gen.hxx:501
constexpr void SetBottom(tools::Long v)
Definition: gen.hxx:508
constexpr tools::Long Left() const
Definition: gen.hxx:500
constexpr tools::Long Bottom() const
Definition: gen.hxx:503
constexpr bool IsEmpty() const
Definition: gen.hxx:558
constexpr ::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
constexpr ::Color COL_GRAY(0x80, 0x80, 0x80)
constexpr ::Color COL_GREEN(0x00, 0x80, 0x00)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_LIGHTCYAN(0x00, 0xFF, 0xFF)
constexpr ::Color COL_MAGENTA(0x80, 0x00, 0x80)
constexpr ::Color COL_LIGHTMAGENTA(0xFF, 0x00, 0xFF)
constexpr ::Color COL_BROWN(0x80, 0x80, 0x00)
constexpr ::Color COL_YELLOW(0xFF, 0xFF, 0x00)
constexpr ::Color COL_RED(0x80, 0x00, 0x00)
constexpr ::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
constexpr ::Color COL_LIGHTBLUE(0x00, 0x00, 0xFF)
constexpr ::Color COL_CYAN(0x00, 0x80, 0x80)
constexpr ::Color COL_LIGHTGREEN(0x00, 0xFF, 0x00)
constexpr ::Color COL_BLUE(0x00, 0x00, 0x80)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
#define SAL_WARN(area, stream)
Note: this class is a true marvel of engineering: because the author could not decide whether it's be...
constexpr sal_uInt16 COL_NAME_USER
constexpr sal_Int32 RECT_EMPTY_VALUE_RIGHT_BOTTOM