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 "precompile.h"
21
22 #include <string.h>
23
24 #include "hwplib.h"
25 #include "hwpfile.h"
26 #include "htags.h"
27
Read(HWPFile & hwpf)28 bool HyperText::Read(HWPFile& hwpf)
29 {
30 size_t nRead = hwpf.ReadBlock(filename, 256);
31 nRead += hwpf.Read2b(bookmark, 16);
32 nRead += hwpf.ReadBlock(macro, 325);
33 if (hwpf.Read1b(type))
34 ++nRead;
35 nRead += hwpf.ReadBlock(reserve, 3);
36 if( type == 2 )
37 {
38 for( int i = 1; i < 256; i++)
39 {
40 filename[i-1] = filename[i];
41 if( filename[i] == 0 )
42 break;
43 }
44 }
45 return nRead == 617;
46 }
47
EmPicture(size_t tsize)48 EmPicture::EmPicture(size_t tsize)
49 : size(tsize >= 32 ? tsize - 32 : 0)
50 {
51 if (size != 0)
52 data.reset( new uchar[size] );
53 }
54 #ifdef _WIN32
55 #define unlink _unlink
56 #endif
~EmPicture()57 EmPicture::~EmPicture()
58 {
59 };
60
Read(HWPFile & hwpf)61 bool EmPicture::Read(HWPFile & hwpf)
62 {
63 if (size == 0)
64 return false;
65 hwpf.ReadBlock(name, 16);
66 hwpf.ReadBlock(type, 16);
67 name[0] = 'H';
68 name[1] = 'W';
69 name[2] = 'P';
70 return hwpf.ReadBlock(data.get(), size) != 0;
71 }
72
73
OlePicture(int tsize)74 OlePicture::OlePicture(int tsize)
75 : signature(0)
76 #ifdef _WIN32
77 , pis(nullptr)
78 #endif
79 {
80 size = tsize - 4;
81 if (size <= 0)
82 return;
83 };
84
~OlePicture()85 OlePicture::~OlePicture()
86 {
87 #ifdef _WIN32
88 if( pis )
89 pis->Release();
90 #endif
91 };
92
93 #define FILESTG_SIGNATURE_NORMAL 0xF8995568
94
Read(HWPFile & hwpf)95 void OlePicture::Read(HWPFile & hwpf)
96 {
97 if (size <= 0)
98 return;
99
100 // We process only FILESTG_SIGNATURE_NORMAL.
101 hwpf.Read4b(&signature, 1);
102 if (signature != FILESTG_SIGNATURE_NORMAL)
103 return;
104 #ifdef _WIN32
105 char *data = new char[size];
106 if (hwpf.ReadBlock(data,size) == 0)
107 {
108 delete [] data;
109 return;
110 }
111 FILE *fp;
112 char tname[200];
113 wchar_t wtname[200];
114 tmpnam(tname);
115 if (nullptr == (fp = fopen(tname, "wb")))
116 {
117 delete [] data;
118 return;
119 }
120 fwrite(data, size, 1, fp);
121 delete [] data;
122 fclose(fp);
123 MultiByteToWideChar(CP_ACP, 0, tname, -1, wtname, 200);
124 if( StgOpenStorage(wtname, nullptr,
125 STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_TRANSACTED,
126 nullptr, 0, &pis) != S_OK ) {
127 pis = nullptr;
128 unlink(tname);
129 return;
130 }
131 unlink(tname);
132 #else
133 hwpf.SkipBlock(size);
134 #endif
135 }
136
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
138