/src/libreoffice/drawinglayer/source/tools/emfpimage.cxx
Line | Count | Source |
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 | | |
23 | | namespace emfplushelper |
24 | | { |
25 | | void EMFPImage::Read(SvMemoryStream &s, sal_uInt32 dataSize, bool bUseWholeStream) |
26 | 0 | { |
27 | 0 | sal_uInt32 header, bitmapType; |
28 | 0 | s.ReadUInt32(header).ReadUInt32(type); |
29 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\timage\nEMF+\theader: 0x" << std::hex << header << " type: " << type << std::dec); |
30 | | |
31 | 0 | if (ImageDataTypeBitmap == type) |
32 | 0 | { |
33 | | // bitmap |
34 | 0 | s.ReadInt32(width).ReadInt32(height).ReadInt32(stride).ReadUInt32(pixelFormat).ReadUInt32(bitmapType); |
35 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\tbitmap width: " << width << " height: " << height << " stride: " << stride << " pixelFormat: 0x" << std::hex << pixelFormat << " bitmapType: 0x" << bitmapType << std::dec); |
36 | | |
37 | 0 | if ((bitmapType != 0) || (width == 0)) |
38 | 0 | { |
39 | | // non native formats |
40 | 0 | GraphicFilter filter; |
41 | 0 | filter.ImportGraphic(graphic, u"", s); |
42 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\tbitmap width: " << graphic.GetSizePixel().Width() << " height: " << graphic.GetSizePixel().Height()); |
43 | 0 | } |
44 | 0 | } |
45 | 0 | else if (ImageDataTypeMetafile == type) |
46 | 0 | { |
47 | | // metafile |
48 | 0 | sal_uInt32 mfType, mfSize; |
49 | 0 | s.ReadUInt32(mfType).ReadUInt32(mfSize); |
50 | |
|
51 | 0 | if (bUseWholeStream) |
52 | 0 | dataSize = s.remainingSize(); |
53 | 0 | else |
54 | 0 | dataSize -= 16; |
55 | |
|
56 | 0 | SAL_INFO("drawinglayer.emf", "EMF+\tmetafile type: " << mfType << " dataSize: " << mfSize << " real size calculated from record dataSize: " << dataSize); |
57 | | |
58 | 0 | GraphicFilter filter; |
59 | | // workaround buggy metafiles, which have wrong mfSize set (n#705956 for example) |
60 | 0 | SvMemoryStream mfStream(const_cast<char *>(static_cast<char const *>(s.GetData()) + s.Tell()), dataSize, StreamMode::READ); |
61 | 0 | 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 | 0 | } |
77 | 0 | } |
78 | | } |
79 | | |
80 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |