LibreOffice Module drawinglayer (master) 1
emfpimage.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#include <vcl/graphicfilter.hxx>
20#include <sal/log.hxx>
21#include "emfpimage.hxx"
22
23namespace emfplushelper
24{
25 void EMFPImage::Read(SvMemoryStream &s, sal_uInt32 dataSize, bool bUseWholeStream)
26 {
27 sal_uInt32 header, bitmapType;
29 SAL_INFO("drawinglayer.emf", "EMF+\timage\nEMF+\theader: 0x" << std::hex << header << " type: " << type << std::dec);
30
32 {
33 // bitmap
35 SAL_INFO("drawinglayer.emf", "EMF+\tbitmap width: " << width << " height: " << height << " stride: " << stride << " pixelFormat: 0x" << std::hex << pixelFormat << " bitmapType: 0x" << bitmapType << std::dec);
36
37 if ((bitmapType != 0) || (width == 0))
38 {
39 // non native formats
41 filter.ImportGraphic(graphic, u"", s);
42 SAL_INFO("drawinglayer.emf", "EMF+\tbitmap width: " << graphic.GetSizePixel().Width() << " height: " << graphic.GetSizePixel().Height());
43 }
44 }
45 else if (ImageDataTypeMetafile == type)
46 {
47 // metafile
48 sal_uInt32 mfType, mfSize;
49 s.ReadUInt32(mfType).ReadUInt32(mfSize);
50
51 if (bUseWholeStream)
52 dataSize = s.remainingSize();
53 else
54 dataSize -= 16;
55
56 SAL_INFO("drawinglayer.emf", "EMF+\tmetafile type: " << mfType << " dataSize: " << mfSize << " real size calculated from record dataSize: " << dataSize);
57
59 // workaround buggy metafiles, which have wrong mfSize set (n#705956 for example)
60 SvMemoryStream mfStream(const_cast<char *>(static_cast<char const *>(s.GetData()) + s.Tell()), dataSize, StreamMode::READ);
61 filter.ImportGraphic(graphic, u"", mfStream);
62
63 // debug code - write the stream to debug file /tmp/emf-stream.emf
64#if OSL_DEBUG_LEVEL > 1
65 mfStream.Seek(0);
66 static sal_Int32 emfp_debug_stream_number = 0;
67 OUString emfp_debug_filename = "/tmp/emf-embedded-stream" +
68 OUString::number(emfp_debug_stream_number++) + ".emf";
69
70 SvFileStream file(emfp_debug_filename, StreamMode::WRITE | StreamMode::TRUNC);
71
72 mfStream.WriteStream(file);
73 file.Flush();
74 file.Close();
75#endif
76 }
77 }
78}
79
80/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_Int8 header[]
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const void * GetData()
sal_uInt64 Tell() const
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
sal_uInt64 Seek(sal_uInt64 nPos)
void Flush()
SvStream & ReadInt32(sal_Int32 &rInt32)
sal_uInt64 remainingSize()
SvStream & WriteStream(SvStream &rStream)
float u
#define SAL_INFO(area, stream)
@ ImageDataTypeMetafile
Definition: emfpimage.hxx:32
void Read(SvMemoryStream &s, sal_uInt32 dataSize, bool bUseWholeStream)
Definition: emfpimage.cxx:25