LibreOffice Module vcl (master)  1
TypeSerializer.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 
20 #include <TypeSerializer.hxx>
21 #include <tools/vcompat.hxx>
22 #include <sal/log.hxx>
23 
25  : GenericTypeSerializer(rStream)
26 {
27 }
28 
30 {
31  VersionCompat aCompat(mrStream, StreamMode::READ);
32 
33  sal_uInt16 nStyle;
34  Color aStartColor;
35  Color aEndColor;
36  sal_uInt16 nAngle;
37  sal_uInt16 nBorder;
38  sal_uInt16 nOffsetX;
39  sal_uInt16 nOffsetY;
40  sal_uInt16 nIntensityStart;
41  sal_uInt16 nIntensityEnd;
42  sal_uInt16 nStepCount;
43 
44  mrStream.ReadUInt16(nStyle);
45  readColor(aStartColor);
46  readColor(aEndColor);
47  mrStream.ReadUInt16(nAngle);
48  mrStream.ReadUInt16(nBorder);
49  mrStream.ReadUInt16(nOffsetX);
50  mrStream.ReadUInt16(nOffsetY);
51  mrStream.ReadUInt16(nIntensityStart);
52  mrStream.ReadUInt16(nIntensityEnd);
53  mrStream.ReadUInt16(nStepCount);
54 
55  rGradient.SetStyle(static_cast<GradientStyle>(nStyle));
56  rGradient.SetStartColor(aStartColor);
57  rGradient.SetEndColor(aEndColor);
58  rGradient.SetAngle(nAngle);
59  rGradient.SetBorder(nBorder);
60  rGradient.SetOfsX(nOffsetX);
61  rGradient.SetOfsY(nOffsetY);
62  rGradient.SetStartIntensity(nIntensityStart);
63  rGradient.SetEndIntensity(nIntensityEnd);
64  rGradient.SetSteps(nStepCount);
65 }
66 
68 {
69  VersionCompat aCompat(mrStream, StreamMode::WRITE, 1);
70 
71  mrStream.WriteUInt16(static_cast<sal_uInt16>(rGradient.GetStyle()));
72  writeColor(rGradient.GetStartColor());
73  writeColor(rGradient.GetEndColor());
74  mrStream.WriteUInt16(rGradient.GetAngle());
75  mrStream.WriteUInt16(rGradient.GetBorder());
76  mrStream.WriteUInt16(rGradient.GetOfsX());
77  mrStream.WriteUInt16(rGradient.GetOfsY());
80  mrStream.WriteUInt16(rGradient.GetSteps());
81 }
82 
84 {
85  sal_uInt16 nType = 0;
86  sal_uInt32 nDataSize = 0;
87  sal_uInt32 nUserId = 0;
88 
89  Size aSize;
90  MapMode aMapMode;
91  bool bMapAndSizeValid = false;
92 
93  {
94  VersionCompat aCompat(mrStream, StreamMode::READ);
95 
96  // Version 1
97  mrStream.ReadUInt16(nType);
98  mrStream.ReadUInt32(nDataSize);
99  mrStream.ReadUInt32(nUserId);
100 
101  if (aCompat.GetVersion() >= 2)
102  {
103  readSize(aSize);
104  ReadMapMode(mrStream, aMapMode);
105  bMapAndSizeValid = true;
106  }
107  }
108 
109  auto nRemainingData = mrStream.remainingSize();
110  if (nDataSize > nRemainingData)
111  {
112  SAL_WARN("vcl", "graphic link stream is smaller than requested size");
113  nDataSize = nRemainingData;
114  }
115 
116  std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nDataSize]);
117  mrStream.ReadBytes(pBuffer.get(), nDataSize);
118 
119  rGfxLink = GfxLink(std::move(pBuffer), nDataSize, static_cast<GfxLinkType>(nType));
120  rGfxLink.SetUserId(nUserId);
121 
122  if (bMapAndSizeValid)
123  {
124  rGfxLink.SetPrefSize(aSize);
125  rGfxLink.SetPrefMapMode(aMapMode);
126  }
127 }
128 
130 {
131  {
132  VersionCompat aCompat(mrStream, StreamMode::WRITE, 2);
133 
134  // Version 1
135  mrStream.WriteUInt16(sal_uInt16(rGfxLink.GetType()));
136  mrStream.WriteUInt32(rGfxLink.GetDataSize());
137  mrStream.WriteUInt32(rGfxLink.GetUserId());
138 
139  // Version 2
140  writeSize(rGfxLink.GetPrefSize());
141  WriteMapMode(mrStream, rGfxLink.GetPrefMapMode());
142  }
143 
144  if (rGfxLink.GetDataSize())
145  {
146  if (rGfxLink.GetData())
147  mrStream.WriteBytes(rGfxLink.GetData(), rGfxLink.GetDataSize());
148  }
149 }
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetEndColor(const Color &rColor)
GradientStyle GetStyle() const
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
SvStream & WriteMapMode(SvStream &rOStm, const MapMode &rMapMode)
Definition: mapmod.cxx:152
sal_uInt16 GetOfsY() const
void writeSize(const Size &rSize)
sal_uInt16 GetBorder() const
void SetBorder(sal_uInt16 nBorder)
void writeGfxLink(const GfxLink &rGfxLink)
void SetEndIntensity(sal_uInt16 nIntens)
void SetSteps(sal_uInt16 nSteps)
void SetOfsY(sal_uInt16 nOfsY)
void SetStartColor(const Color &rColor)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
sal_uInt64 remainingSize()
void readSize(Size &rSize)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
sal_uInt16 GetAngle() const
sal_uInt16 GetOfsX() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
void writeGradient(const Gradient &rGradient)
long const nBorder
sal_uInt16 GetEndIntensity() const
void SetOfsX(sal_uInt16 nOfsX)
sal_uInt16 GetSteps() const
const Color & GetStartColor() const
std::size_t ReadBytes(void *pData, std::size_t nSize)
unsigned char sal_uInt8
void SetAngle(sal_uInt16 nAngle)
const Color & GetEndColor() const
QPRO_FUNC_TYPE nType
#define SAL_WARN(area, stream)
void readGfxLink(GfxLink &rGfxLink)
SvStream & ReadMapMode(SvStream &rIStm, MapMode &rMapMode)
Definition: mapmod.cxx:136
TypeSerializer(SvStream &rStream)
void writeColor(const Color &rColor)
void SetStyle(GradientStyle eStyle)
void readGradient(Gradient &rGradient)
sal_uInt16 GetStartIntensity() const
void SetStartIntensity(sal_uInt16 nIntens)
void readColor(Color &rColor)