nss: upgrade to release 3.73
[LibreOffice.git] / filter / source / graphicfilter / icgm / class1.cxx
blob07a6fe253e4e35d5084856ef342cde54e8b39fee
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 <sal/config.h>
21 #include <sal/log.hxx>
23 #include <o3tl/safeint.hxx>
25 #include "bundles.hxx"
26 #include "cgm.hxx"
27 #include "elements.hxx"
30 void CGM::ImplDoClass1()
32 tools::Long nInteger, nI0, nI1;
33 sal_uInt32 nUInteger;
35 switch ( mnElementID )
37 case 0x01 : /*Metafile Version*/
38 pElement->nMetaFileVersion = ImplGetI( pElement->nIntegerPrecision );
39 break;
40 case 0x02 : /*Metafile Description */break;
41 case 0x03 : /*VDC Type*/
43 nUInteger = ImplGetUI16();
44 switch( nUInteger )
46 case 0 : pElement->eVDCType = VDC_INTEGER; break;
47 case 1 : pElement->eVDCType = VDC_REAL; break;
48 default: mbStatus = false; break;
51 break;
52 case 0x04 : /*Integer Precision*/
54 nInteger = ImplGetI( pElement->nIntegerPrecision );
55 switch ( nInteger )
57 case 32 :
58 case 24 :
59 case 16 :
60 case 8 : pElement->nIntegerPrecision = nInteger >> 3; break;
61 default : mbStatus = false; break;
64 break;
65 case 0x05 : /*Real Precision*/
67 nUInteger = ImplGetUI16();
68 nI0 = ImplGetI( pElement->nIntegerPrecision ); // exponent
69 nI1 = ImplGetI( pElement->nIntegerPrecision ); // mantissa
70 switch( nUInteger )
72 case 0 :
73 pElement->eRealPrecision = RP_FLOAT;
74 switch ( nI0 )
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;
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;
106 break;
107 case 0x06 : /*Index Precision*/
109 nInteger = ImplGetI( pElement->nIntegerPrecision );
110 switch ( nInteger )
112 case 32 :
113 case 24 :
114 case 16 :
115 case 8 : pElement->nIndexPrecision = nInteger >> 3; break;
116 default : mbStatus = false; break;
119 break;
120 case 0x07 : /*Color Precision*/
122 nInteger = ImplGetI( pElement->nIntegerPrecision );
123 switch ( nInteger )
125 case 32 :
126 case 24 :
127 case 16 :
128 case 8 : pElement->nColorPrecision = nInteger >> 3; break;
129 default : mbStatus = false; break;
132 break;
133 case 0x08 : /*Color Index Precision*/
135 nInteger = ImplGetI( pElement->nIntegerPrecision );
136 switch ( nInteger )
138 case 32 :
139 case 24 :
140 case 16 :
141 case 8 : pElement->nColorIndexPrecision = nInteger >> 3; break;
142 default : mbStatus = false; break;
145 break;
146 case 0x09 : /*Maximum Colour Index*/
148 pElement->nColorMaximumIndex = ImplGetUI( pElement->nColorIndexPrecision );
149 if ( ( pElement->nColorMaximumIndex > 256 /*255*/ ) || ( pElement->nColorMaximumIndex == 0 ) )
150 mbStatus = false;
152 break;
153 case 0x0a : /*Color Value Extent*/
155 nI1 = 6;
157 break;
158 case 0x0b : /*MetaFile Element List */break;
159 case 0x0c : /*MetaFile Default Replacement*/
161 if ( mnElementSize > 1 )
163 std::unique_ptr<sal_uInt8[]> pBuf(new sal_uInt8[ mnElementSize ]);
164 memcpy( pBuf.get(), mpSource, mnElementSize );
165 maDefRepList.push_back( std::move(pBuf) );
166 maDefRepSizeList.push_back( mnElementSize );
168 mnParaSize = mnElementSize;
170 break;
171 case 0x0d : /*Font List*/
173 while ( mnParaSize < mnElementSize )
175 sal_uInt32 nSize = ImplGetUI(1);
177 if (o3tl::make_unsigned(mpEndValidSource - (mpSource + mnParaSize)) < nSize)
178 throw css::uno::Exception("attempt to read past end of input", nullptr);
180 pElement->aFontList.InsertName( mpSource + mnParaSize, nSize );
181 mnParaSize += nSize;
184 break;
185 case 0x0e : /*Character Set List*/
187 while ( mnParaSize < mnElementSize )
189 ImplGetUI16(); // skip CharSetType
190 sal_uInt32 nSize = ImplGetUI(1);
192 if (o3tl::make_unsigned(mpEndValidSource - (mpSource + mnParaSize)) < nSize)
193 throw css::uno::Exception("attempt to read past end of input", nullptr);
195 pElement->aFontList.InsertCharSet( mpSource + mnParaSize, nSize );
196 mnParaSize += nSize;
199 break;
200 case 0x0f : /*Character Coding Announcer*/
202 auto nCharacterCoding = ImplGetUI16();
203 if (nCharacterCoding <= CCA_EXT_8)
204 pElement->eCharacterCodingA = static_cast<CharacterCodingA>(nCharacterCoding);
205 else
206 SAL_WARN("filter.icgm", "CharacterCoding " << nCharacterCoding << " requested, but legal max is " << CCA_EXT_8);
208 break;
209 case 0x10 : /*Name Precision */break; // NS
210 case 0x11 : /*Maximum VDC Extent */break; // NS
211 case 0x12 : /*Segment Priority Extent */break; // NS
212 case 0x13 : /*Color Model */break; // NS
213 case 0x14 : /*Color Calibration */break; // NS
214 case 0x15 : /*Font Properties */break; // NS
215 case 0x16 : /*Glyph Mapping */break; // NS
216 case 0x17 : /*Symbol Library List */break; // NS
217 case 0xfc : /*Inquire Function Support */break;
218 case 0xfa : /*End Metafile Defaults Replacement */break;
219 case 0xf8 : /*Set Color Value Desc Extent */break;
220 default: break;
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */