File: cairoimporter.cpp

package info (click to toggle)
synfigstudio 1.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 165,832 kB
  • sloc: cpp: 211,947; ansic: 67,096; sh: 11,343; makefile: 3,220; objc: 1,400; csh: 729; asm: 284; perl: 238; python: 213; ruby: 44; xml: 11
file content (152 lines) | stat: -rw-r--r-- 3,738 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* === S Y N F I G ========================================================= */
/*!	\file cairoimporter.cpp
**	\brief It is the base class for all the cairo importers.
**
**	$Id$
**
**	\legal
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**	Copyright (c) 2012-2013 Carlos López
**
**	This package is free software; you can redistribute it and/or
**	modify it under the terms of the GNU General Public License as
**	published by the Free Software Foundation; either version 2 of
**	the License, or (at your option) any later version.
**
**	This package is distributed in the hope that it will be useful,
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**	General Public License for more details.
**	\endlegal
*/
/* ========================================================================= */

/* === H E A D E R S ======================================================= */

#ifdef USING_PCH
#	include "pch.h"
#else
#ifdef HAVE_CONFIG_H
#	include <config.h>
#endif

#include <cctype>

#include <algorithm>
#include <functional>
#include <map>

#include <glibmm.h>

#include "cairoimporter.h"

#include "general.h"
#include <synfig/localization.h>

#include "canvas.h"
#include "surface.h"
#include "string.h"

#endif

/* === M A C R O S ========================================================= */

/* === G L O B A L S ======================================================= */

using namespace etl;
using namespace std;
using namespace synfig;

CairoImporter::Book* synfig::CairoImporter::book_;

map<FileSystem::Identifier, CairoImporter::LooseHandle> *__open_cairoimporters;

/* === P R O C E D U R E S ================================================= */

/* === M E T H O D S ======================================================= */

bool
CairoImporter::subsys_init()
{
	book_=new Book();
	__open_cairoimporters=new map<FileSystem::Identifier, CairoImporter::LooseHandle>();
	return true;
}

bool
CairoImporter::subsys_stop()
{
	delete book_;
	delete __open_cairoimporters;
	return true;
}

CairoImporter::Book&
CairoImporter::book()
{
	return *book_;
}

CairoImporter::Handle
CairoImporter::open(const FileSystem::Identifier &identifier)
{
	if(identifier.filename.empty())
	{
		synfig::error(_("CairoImporter::open(): Cannot open empty filename"));
		return 0;
	}

	// If we already have an importer open under that filename,
	// then use it instead.
	if(__open_cairoimporters->count(identifier))
	{
		//synfig::info("Found cairo importer already open, using it...");
		return (*__open_cairoimporters)[identifier];
	}

	if(filename_extension(identifier.filename) == "")
	{
		synfig::error(_("CairoImporter::open(): Couldn't find extension"));
		return 0;
	}

	String ext(filename_extension(identifier.filename));
	if (ext.size()) ext = ext.substr(1); // skip initial '.'
	std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);


	if(!CairoImporter::book().count(ext))
	{
		synfig::error(_("CairoImporter::open(): Unknown file type -- ")+ext);
		return 0;
	}

	try {
		CairoImporter::Handle importer;
		importer=CairoImporter::book()[ext].factory(identifier);
		(*__open_cairoimporters)[identifier]=importer;
		return importer;
	}
	catch (const String& str)
	{
		synfig::error(str);
	}
	return 0;
}

CairoImporter::CairoImporter(const FileSystem::Identifier &identifier):
	identifier(identifier)
{
}


CairoImporter::~CairoImporter()
{
	// Remove ourselves from the open importer list
	map<FileSystem::Identifier,CairoImporter::LooseHandle>::iterator iter;
	for(iter=__open_cairoimporters->begin();iter!=__open_cairoimporters->end();++iter)
		if(iter->second==this)
		{
			__open_cairoimporters->erase(iter);
		}
}