1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <dxfreprd.hxx>
25 //------------------DXFBoundingBox--------------------------------------------
28 void DXFBoundingBox::Union(const DXFVector
& rVector
)
30 if (bEmpty
==sal_True
) {
40 if (fMinX
>rVector
.fx
) fMinX
=rVector
.fx
;
41 if (fMinY
>rVector
.fy
) fMinY
=rVector
.fy
;
42 if (fMinZ
>rVector
.fz
) fMinZ
=rVector
.fz
;
43 if (fMaxX
<rVector
.fx
) fMaxX
=rVector
.fx
;
44 if (fMaxY
<rVector
.fy
) fMaxY
=rVector
.fy
;
45 if (fMaxZ
<rVector
.fz
) fMaxZ
=rVector
.fz
;
50 //------------------DXFPalette------------------------------------------------
53 DXFPalette::DXFPalette()
55 short i
,j
,nHue
,nNSat
,nVal
,nC
[3],nmax
,nmed
,nmin
;
58 pRed
=new sal_uInt8
[256];
59 pGreen
=new sal_uInt8
[256];
60 pBlue
=new sal_uInt8
[256];
62 // colors 0 - 9 (normal colors)
63 SetColor(0, 0x00, 0x00, 0x00); // actually never being used
64 SetColor(1, 0xff, 0x00, 0x00);
65 SetColor(2, 0xff, 0xff, 0x00);
66 SetColor(3, 0x00, 0xff, 0x00);
67 SetColor(4, 0x00, 0xff, 0xff);
68 SetColor(5, 0x00, 0x00, 0xff);
69 SetColor(6, 0xff, 0x00, 0xff);
70 SetColor(7, 0x0f, 0x0f, 0x0f); // actually white???
71 SetColor(8, 0x80, 0x80, 0x80);
72 SetColor(9, 0xc0, 0xc0, 0xc0);
75 // (Universal-Palette: 24 hues * 5 lightnesses * 2 saturations )
77 for (nHue
=0; nHue
<24; nHue
++) {
78 for (nVal
=5; nVal
>=1; nVal
--) {
79 for (nNSat
=0; nNSat
<2; nNSat
++) {
81 j
=nHue
-(nmax
<<3); if (j
>4) j
=j
-24;
95 for (j
=0; j
<3; j
++) nC
[j
]=(nC
[j
]>>1)+128;
97 for (j
=0; j
<3; j
++) nC
[j
]=nC
[j
]*nVal
/5;
98 SetColor((sal_uInt8
)(i
++),(sal_uInt8
)nC
[0],(sal_uInt8
)nC
[1],(sal_uInt8
)nC
[2]);
103 // Farben 250 - 255 (shades of gray)
104 for (i
=0; i
<6; i
++) {
105 nV
=(sal_uInt8
)(i
*38+65);
106 SetColor((sal_uInt8
)(250+i
),nV
,nV
,nV
);
111 DXFPalette::~DXFPalette()
119 void DXFPalette::SetColor(sal_uInt8 nIndex
, sal_uInt8 nRed
, sal_uInt8 nGreen
, sal_uInt8 nBlue
)
122 pGreen
[nIndex
]=nGreen
;
127 //------------------DXFRepresentation-----------------------------------------
130 DXFRepresentation::DXFRepresentation()
132 setTextEncoding(RTL_TEXTENCODING_IBM_437
);
133 setGlobalLineTypeScale(1.0);
137 DXFRepresentation::~DXFRepresentation()
142 sal_Bool
DXFRepresentation::Read( SvStream
& rIStream
, sal_uInt16 nMinPercent
, sal_uInt16 nMaxPercent
)
144 DXFGroupReader
* pDGR
;
151 pDGR
= new DXFGroupReader( rIStream
, nMinPercent
, nMaxPercent
);
154 while (pDGR
->GetG()!=0 || strcmp(pDGR
->GetS(),"EOF")!=0) {
155 if (pDGR
->GetG()==0 && strcmp(pDGR
->GetS(),"SECTION")==0) {
156 if (pDGR
->Read()!=2) {
160 if (strcmp(pDGR
->GetS(),"HEADER" )==0) ReadHeader(*pDGR
);
161 else if (strcmp(pDGR
->GetS(),"TABLES" )==0) aTables
.Read(*pDGR
);
162 else if (strcmp(pDGR
->GetS(),"BLOCKS" )==0) aBlocks
.Read(*pDGR
);
163 else if (strcmp(pDGR
->GetS(),"ENTITIES")==0) aEntities
.Read(*pDGR
);
169 bRes
=pDGR
->GetStatus();
173 if (bRes
==sal_True
&& aBoundingBox
.bEmpty
==sal_True
)
174 CalcBoundingBox(aEntities
,aBoundingBox
);
180 void DXFRepresentation::ReadHeader(DXFGroupReader
& rDGR
)
183 while (rDGR
.GetG()!=0 || (strcmp(rDGR
.GetS(),"EOF")!=0 && strcmp(rDGR
.GetS(),"ENDSEC")!=0) )
185 if (rDGR
.GetG()==9) {
186 if (strcmp(rDGR
.GetS(),"$EXTMIN")==0 ||
187 strcmp(rDGR
.GetS(),"$EXTMAX")==0)
195 } while (rDGR
.GetG()!=9 && rDGR
.GetG()!=0);
196 aVector
.fx
=rDGR
.GetF(10);
197 aVector
.fy
=rDGR
.GetF(20);
198 aVector
.fz
=rDGR
.GetF(30);
199 aBoundingBox
.Union(aVector
);
201 if (strcmp(rDGR
.GetS(),"$DWGCODEPAGE")==0)
205 // FIXME: we really need a whole table of
206 // $DWGCODEPAGE to encodings mappings
207 if ( (strcmp(rDGR
.GetS(),"ANSI_932")==0) ||
208 (strcmp(rDGR
.GetS(),"ansi_932")==0) ||
209 (strcmp(rDGR
.GetS(),"DOS932")==0) ||
210 (strcmp(rDGR
.GetS(),"dos932")==0) )
212 setTextEncoding(RTL_TEXTENCODING_MS_932
);
215 else if (strcmp(rDGR
.GetS(),"$LTSCALE")==0)
218 setGlobalLineTypeScale(getGlobalLineTypeScale() * rDGR
.GetF());
228 void DXFRepresentation::CalcBoundingBox(const DXFEntities
& rEntities
,
229 DXFBoundingBox
& rBox
)
231 DXFBasicEntity
* pBE
=rEntities
.pFirst
;
233 switch (pBE
->eType
) {
235 const DXFLineEntity
* pE
= (DXFLineEntity
*)pBE
;
241 const DXFPointEntity
* pE
= (DXFPointEntity
*)pBE
;
246 const DXFCircleEntity
* pE
= (DXFCircleEntity
*)pBE
;
259 const DXFArcEntity
* pE
= (DXFArcEntity
*)pBE
;
272 const DXFTraceEntity
* pE
= (DXFTraceEntity
*)pBE
;
280 const DXFSolidEntity
* pE
= (DXFSolidEntity
*)pBE
;
288 //const DXFTextEntity * pE = (DXFTextEntity*)pBE;
293 //const DXFShapeEntity * pE = (DXFShapeEntity*)pBE;
298 const DXFInsertEntity
* pE
= (DXFInsertEntity
*)pBE
;
302 pB
=aBlocks
.Search(pE
->m_sName
);
304 CalcBoundingBox(*pB
,aBox
);
305 if (aBox
.bEmpty
==sal_True
) break;
306 aP
.fx
=(aBox
.fMinX
-pB
->aBasePoint
.fx
)*pE
->fXScale
+pE
->aP0
.fx
;
307 aP
.fy
=(aBox
.fMinY
-pB
->aBasePoint
.fy
)*pE
->fYScale
+pE
->aP0
.fy
;
308 aP
.fz
=(aBox
.fMinZ
-pB
->aBasePoint
.fz
)*pE
->fZScale
+pE
->aP0
.fz
;
310 aP
.fx
=(aBox
.fMaxX
-pB
->aBasePoint
.fx
)*pE
->fXScale
+pE
->aP0
.fx
;
311 aP
.fy
=(aBox
.fMaxY
-pB
->aBasePoint
.fy
)*pE
->fYScale
+pE
->aP0
.fy
;
312 aP
.fz
=(aBox
.fMaxZ
-pB
->aBasePoint
.fz
)*pE
->fZScale
+pE
->aP0
.fz
;
317 //const DXFAttDefEntity * pE = (DXFAttDefEntity*)pBE;
322 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
327 const DXFVertexEntity
* pE
= (DXFVertexEntity
*)pBE
;
332 const DXF3DFaceEntity
* pE
= (DXF3DFaceEntity
*)pBE
;
339 case DXF_DIMENSION
: {
340 const DXFDimensionEntity
* pE
= (DXFDimensionEntity
*)pBE
;
344 pB
= aBlocks
.Search(pE
->m_sPseudoBlock
);
346 CalcBoundingBox(*pB
,aBox
);
347 if (aBox
.bEmpty
==sal_True
) break;
348 aP
.fx
=aBox
.fMinX
-pB
->aBasePoint
.fx
;
349 aP
.fy
=aBox
.fMinY
-pB
->aBasePoint
.fy
;
350 aP
.fz
=aBox
.fMinZ
-pB
->aBasePoint
.fz
;
352 aP
.fx
=aBox
.fMaxX
-pB
->aBasePoint
.fx
;
353 aP
.fy
=aBox
.fMaxY
-pB
->aBasePoint
.fy
;
354 aP
.fz
=aBox
.fMaxZ
-pB
->aBasePoint
.fz
;
359 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
364 //const DXFAttribEntity * pE = (DXFAttribEntity*)pBE;
370 case DXF_LWPOLYLINE
:
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */