LibreOffice Module filter (master) 1
class1.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 <sal/config.h>
21#include <sal/log.hxx>
22
23#include <o3tl/safeint.hxx>
24
25#include "bundles.hxx"
26#include "cgm.hxx"
27#include "elements.hxx"
28
29
31{
32 tools::Long nInteger, nI0, nI1;
33 sal_uInt32 nUInteger;
34
35 switch ( mnElementID )
36 {
37 case 0x01 : /*Metafile Version*/
38 pElement->nMetaFileVersion = ImplGetI( pElement->nIntegerPrecision );
39 break;
40 case 0x02 : /*Metafile Description */break;
41 case 0x03 : /*VDC Type*/
42 {
43 nUInteger = ImplGetUI16();
44 switch( nUInteger )
45 {
46 case 0 : pElement->eVDCType = VDC_INTEGER; break;
47 case 1 : pElement->eVDCType = VDC_REAL; break;
48 default: mbStatus = false; break;
49 }
50 }
51 break;
52 case 0x04 : /*Integer Precision*/
53 {
54 nInteger = ImplGetI( pElement->nIntegerPrecision );
55 switch ( nInteger )
56 {
57 case 32 :
58 case 24 :
59 case 16 :
60 case 8 : pElement->nIntegerPrecision = nInteger >> 3; break;
61 default : mbStatus = false; break;
62 }
63 }
64 break;
65 case 0x05 : /*Real Precision*/
66 {
67 nUInteger = ImplGetUI16();
68 nI0 = ImplGetI( pElement->nIntegerPrecision ); // exponent
69 nI1 = ImplGetI( pElement->nIntegerPrecision ); // mantissa
70 switch( nUInteger )
71 {
72 case 0 :
73 pElement->eRealPrecision = RP_FLOAT;
74 switch ( nI0 )
75 {
76 case 9 :
77 if ( nI1 != 23 )
78 mbStatus = false;
79 pElement->nRealSize = 4;
80 break;
81 case 12 :
82 if ( nI1 != 52 )
83 mbStatus =false;
84 pElement->nRealSize = 8;
85 break;
86 default:
87 mbStatus = false;
88 break;
89 }
90 break;
91 case 1 :
92 pElement->eRealPrecision = RP_FIXED;
93 if ( nI0 != nI1 )
94 mbStatus = false;
95 if ( nI0 == 16 )
96 pElement->nRealSize = 4;
97 else if ( nI0 == 32 )
98 pElement->nRealSize = 8;
99 else
100 mbStatus = false;
101 break;
102 default :
103 mbStatus = false; break;
104 }
105 }
106 break;
107 case 0x06 : /*Index Precision*/
108 {
109 nInteger = ImplGetI( pElement->nIntegerPrecision );
110 switch ( nInteger )
111 {
112 case 32 :
113 case 24 :
114 case 16 :
115 case 8 : pElement->nIndexPrecision = nInteger >> 3; break;
116 default : mbStatus = false; break;
117 }
118 }
119 break;
120 case 0x07 : /*Color Precision*/
121 {
122 nInteger = ImplGetI( pElement->nIntegerPrecision );
123 switch ( nInteger )
124 {
125 case 32 :
126 case 24 :
127 case 16 :
128 case 8 : pElement->nColorPrecision = nInteger >> 3; break;
129 default : mbStatus = false; break;
130 }
131 }
132 break;
133 case 0x08 : /*Color Index Precision*/
134 {
135 nInteger = ImplGetI( pElement->nIntegerPrecision );
136 switch ( nInteger )
137 {
138 case 32 :
139 case 24 :
140 case 16 :
141 case 8 : pElement->nColorIndexPrecision = nInteger >> 3; break;
142 default : mbStatus = false; break;
143 }
144 }
145 break;
146 case 0x09 : /*Maximum Colour Index*/
147 {
148 pElement->nColorMaximumIndex = ImplGetUI( pElement->nColorIndexPrecision );
149 if ( ( pElement->nColorMaximumIndex > 256 /*255*/ ) || ( pElement->nColorMaximumIndex == 0 ) )
150 mbStatus = false;
151 }
152 break;
153 case 0x0a : /*Color Value Extent*/
154 break;
155 case 0x0b : /*MetaFile Element List */break;
156 case 0x0c : /*MetaFile Default Replacement*/
157 {
158 if ( mnElementSize > 1 )
159 {
160 std::unique_ptr<sal_uInt8[]> pBuf(new sal_uInt8[ mnElementSize ]);
161 memcpy( pBuf.get(), mpSource, mnElementSize );
162 maDefRepList.push_back( std::move(pBuf) );
163 maDefRepSizeList.push_back( mnElementSize );
164 }
166 }
167 break;
168 case 0x0d : /*Font List*/
169 {
170 while ( mnParaSize < mnElementSize )
171 {
172 sal_uInt32 nSize = ImplGetUI(1);
173
175 throw css::uno::Exception("attempt to read past end of input", nullptr);
176
177 pElement->aFontList.InsertName( mpSource + mnParaSize, nSize );
178 mnParaSize += nSize;
179 }
180 }
181 break;
182 case 0x0e : /*Character Set List*/
183 {
184 while ( mnParaSize < mnElementSize )
185 {
186 ImplGetUI16(); // skip CharSetType
187 sal_uInt32 nSize = ImplGetUI(1);
188
190 throw css::uno::Exception("attempt to read past end of input", nullptr);
191
192 pElement->aFontList.InsertCharSet( mpSource + mnParaSize, nSize );
193 mnParaSize += nSize;
194 }
195 }
196 break;
197 case 0x0f : /*Character Coding Announcer*/
198 {
199 auto nCharacterCoding = ImplGetUI16();
200 if (nCharacterCoding <= CCA_EXT_8)
201 pElement->eCharacterCodingA = static_cast<CharacterCodingA>(nCharacterCoding);
202 else
203 SAL_WARN("filter.icgm", "CharacterCoding " << nCharacterCoding << " requested, but legal max is " << CCA_EXT_8);
204 }
205 break;
206 case 0x10 : /*Name Precision */break; // NS
207 case 0x11 : /*Maximum VDC Extent */break; // NS
208 case 0x12 : /*Segment Priority Extent */break; // NS
209 case 0x13 : /*Color Model */break; // NS
210 case 0x14 : /*Color Calibration */break; // NS
211 case 0x15 : /*Font Properties */break; // NS
212 case 0x16 : /*Glyph Mapping */break; // NS
213 case 0x17 : /*Symbol Library List */break; // NS
214 case 0xfc : /*Inquire Function Support */break;
215 case 0xfa : /*End Metafile Defaults Replacement */break;
216 case 0xf8 : /*Set Color Value Desc Extent */break;
217 default: break;
218 }
219};
220
221
222/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CharacterCodingA
Definition: cgmtypes.hxx:100
@ CCA_EXT_8
Definition: cgmtypes.hxx:100
@ VDC_INTEGER
Definition: cgmtypes.hxx:89
@ VDC_REAL
Definition: cgmtypes.hxx:89
@ RP_FIXED
Definition: cgmtypes.hxx:85
@ RP_FLOAT
Definition: cgmtypes.hxx:85
bool mbStatus
Definition: cgm.hxx:55
sal_Int32 ImplGetI(sal_uInt32 nPrecision)
Definition: cgm.cxx:96
sal_uInt32 mnElementID
Definition: cgm.hxx:86
sal_uInt32 ImplGetUI16()
Definition: cgm.cxx:82
sal_uInt8 * mpSource
Definition: cgm.hxx:75
void ImplDoClass1()
Definition: class1.cxx:30
sal_uInt8 * mpEndValidSource
Definition: cgm.hxx:77
::std::vector< std::unique_ptr< sal_uInt8[]> > maDefRepList
Definition: cgm.hxx:72
::std::vector< sal_uInt32 > maDefRepSizeList
Definition: cgm.hxx:73
sal_uInt32 ImplGetUI(sal_uInt32 nPrecision)
Definition: cgm.cxx:128
sal_uInt32 mnElementSize
Definition: cgm.hxx:87
std::unique_ptr< CGMElements > pElement
Definition: cgm.hxx:69
sal_uInt32 mnParaSize
Definition: cgm.hxx:78
#define SAL_WARN(area, stream)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
long Long
unsigned char sal_uInt8