Typo: cirle->circle
[LibreOffice.git] / hwpfilter / source / htags.cxx
blob6283e77ac479adb1a277cced6b670b93ea833829
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "precompile.h"
22 #include <string.h>
24 #include "hwplib.h"
25 #include "hwpfile.h"
26 #include "htags.h"
28 bool HyperText::Read(HWPFile & hwpf)
30 hwpf.Read1b(filename, 256);
31 hwpf.Read2b(bookmark, 16);
32 hwpf.Read1b(macro, 325);
33 hwpf.Read1b(&type, 1);
34 hwpf.Read1b(reserve, 3);
35 if( type == 2 )
37 for( int i = 1; i < 256; i++)
39 filename[i-1] = filename[i];
40 if( filename[i] == 0 )
41 break;
44 return true;
48 EmPicture::EmPicture(size_t tsize)
49 : size(tsize >= 32 ? tsize - 32 : 0)
51 if (size == 0)
52 data = 0;
53 else
54 data = new uchar[size];
56 #ifdef WIN32
57 #define unlink _unlink
58 #endif
59 EmPicture::~EmPicture(void)
61 if (data)
62 delete[]data;
65 bool EmPicture::Read(HWPFile & hwpf)
67 if (size == 0)
68 return false;
69 hwpf.Read1b(name, 16);
70 hwpf.Read1b(type, 16);
71 name[0] = 'H';
72 name[1] = 'W';
73 name[2] = 'P';
74 if (hwpf.ReadBlock(data, size) == 0)
75 return false;
76 return true;
80 OlePicture::OlePicture(int tsize)
81 : signature(0)
82 , pis(NULL)
84 size = tsize - 4;
85 if (size <= 0)
86 return;
87 #ifndef WIN32
88 pis = new char[size];
89 #endif
92 OlePicture::~OlePicture()
94 #ifdef WIN32
95 if( pis )
96 pis->Release();
97 #else
98 delete[] pis;
99 #endif
102 #define FILESTG_SIGNATURE_NORMAL 0xF8995568
104 bool OlePicture::Read(HWPFile & hwpf)
106 if (size <= 0)
107 return false;
109 // We process only FILESTG_SIGNATURE_NORMAL.
110 hwpf.Read4b(&signature, 1);
111 if (signature != FILESTG_SIGNATURE_NORMAL)
112 return false;
113 #ifdef WIN32
114 char *data = new char[size];
115 if( data == 0 || hwpf.ReadBlock(data,size) == 0 )
117 delete [] data;
118 return false;
120 FILE *fp;
121 char tname[200];
122 wchar_t wtname[200];
123 tmpnam(tname);
124 if (0 == (fp = fopen(tname, "wb")))
126 delete [] data;
127 return false;
129 fwrite(data, size, 1, fp);
130 delete [] data;
131 fclose(fp);
132 MultiByteToWideChar(CP_ACP, 0, tname, -1, wtname, 200);
133 if( StgOpenStorage(wtname, NULL,
134 STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_TRANSACTED,
135 NULL, 0, &pis) != S_OK ) {
136 pis = 0;
137 unlink(tname);
138 return false;
140 unlink(tname);
141 #else
142 if (pis == 0 || hwpf.ReadBlock(pis, size) == 0)
143 return false;
144 #endif
146 return true;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */