1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2
3 /* AbiWord
4 * Copyright (C) 1998 AbiSource, Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA.
20 */
21
22 #include <string.h>
23 #include "ut_string.h"
24
25 #include "ie_impGraphic_PNG.h"
26 #include "fg_GraphicRaster.h"
27
28 // supported suffixes
29 static IE_SuffixConfidence IE_ImpGraphicPNG_Sniffer__SuffixConfidence[] = {
30 { "png", UT_CONFIDENCE_PERFECT },
31 { "", UT_CONFIDENCE_ZILCH }
32 };
33
getSuffixConfidence()34 const IE_SuffixConfidence * IE_ImpGraphicPNG_Sniffer::getSuffixConfidence ()
35 {
36 return IE_ImpGraphicPNG_Sniffer__SuffixConfidence;
37 }
38
39 // supported mimetypes
40 static IE_MimeConfidence IE_ImpGraphicPNG_Sniffer__MimeConfidence[] = {
41 { IE_MIME_MATCH_FULL, "image/png", UT_CONFIDENCE_GOOD },
42 { IE_MIME_MATCH_BOGUS, "", UT_CONFIDENCE_ZILCH }
43 };
44
getMimeConfidence()45 const IE_MimeConfidence * IE_ImpGraphicPNG_Sniffer::getMimeConfidence ()
46 {
47 return IE_ImpGraphicPNG_Sniffer__MimeConfidence;
48 }
49
recognizeContents(const char * szBuf,UT_uint32 iNumbytes)50 UT_Confidence_t IE_ImpGraphicPNG_Sniffer::recognizeContents(const char * szBuf, UT_uint32 iNumbytes)
51 {
52 char str1[10] = "\211PNG";
53 char str2[10] = "<89>PNG";
54
55 if (!szBuf || iNumbytes<6) return UT_CONFIDENCE_ZILCH;
56
57 if ( !(strncmp(szBuf, str1, 4)) || !(strncmp(szBuf, str2, 6)) )
58 return UT_CONFIDENCE_PERFECT;
59 return UT_CONFIDENCE_ZILCH;
60 }
61
getDlgLabels(const char ** pszDesc,const char ** pszSuffixList,IEGraphicFileType * ft)62 bool IE_ImpGraphicPNG_Sniffer::getDlgLabels(const char ** pszDesc,
63 const char ** pszSuffixList,
64 IEGraphicFileType * ft)
65 {
66 *pszDesc = "Portable Network Graphics (.png)";
67 *pszSuffixList = "*.png";
68 *ft = getType ();
69 return true;
70 }
71
constructImporter(IE_ImpGraphic ** ppieg)72 UT_Error IE_ImpGraphicPNG_Sniffer::constructImporter(IE_ImpGraphic **ppieg)
73 {
74 *ppieg = new IE_ImpGraphic_PNG();
75 if (*ppieg == NULL)
76 return UT_IE_NOMEMORY;
77
78 return UT_OK;
79 }
80
81 // This actually creates our FG_Graphic object for a PNG
importGraphic(UT_ByteBuf * pBB,FG_Graphic ** ppfg)82 UT_Error IE_ImpGraphic_PNG::importGraphic(UT_ByteBuf* pBB,
83 FG_Graphic ** ppfg)
84 {
85 FG_GraphicRaster *pFGR;
86
87 pFGR = new FG_GraphicRaster();
88 if(pFGR == NULL)
89 return UT_IE_NOMEMORY;
90
91 if(!pFGR->setRaster_PNG(pBB)) {
92 DELETEP(pFGR);
93
94 return UT_IE_FAKETYPE;
95 }
96
97 *ppfg = static_cast<FG_Graphic *>(pFGR);
98 return UT_OK;
99 }
100
101