root/OpenSceneGraph/trunk/src/osgPlugins/txf/ReaderWriterTXF.cpp @ 13041

Revision 13041, 2.3 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 2006 Mathias Froehlich
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgDB/FileNameUtils>
15#include <osgDB/FileUtils>
16#include <osgDB/fstream>
17#include <osgDB/Registry>
18#include <osg/Notify>
19
20#include "TXFFont.h"
21
22class ReaderWriterTXF : public osgDB::ReaderWriter
23{
24    public:
25        ReaderWriterTXF()
26        {
27            supportsExtension("txf","TXF Font format");
28        }
29
30        virtual const char* className() const { return "TXF Font Reader/Writer"; }
31
32        virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
33        {
34            std::string ext = osgDB::getLowerCaseFileExtension(file);
35            if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
36
37            std::string fileName = osgDB::findDataFile(file, options);
38            if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
39
40            osgDB::ifstream stream;
41            stream.open(fileName.c_str(), std::ios::in | std::ios::binary);
42            if (!stream.is_open()) return ReadResult::FILE_NOT_FOUND;
43
44            TXFFont* impl = new TXFFont(fileName);
45            osg::ref_ptr<osgText::Font> font = new osgText::Font(impl);
46            if (!impl->loadFont(stream)) return ReadResult::FILE_NOT_HANDLED;
47            return font.release();
48        }
49
50        virtual ReadResult readObject(std::istream& stream, const osgDB::ReaderWriter::Options*) const
51        {
52            TXFFont* impl = new TXFFont("streamed font");
53            osg::ref_ptr<osgText::Font> font = new osgText::Font(impl);
54            if (!impl->loadFont(stream)) return ReadResult::FILE_NOT_HANDLED;
55            return font.release();
56        }
57};
58
59// now register with Registry to instantiate the above
60// reader/writer.
61REGISTER_OSGPLUGIN(txf, ReaderWriterTXF)
Note: See TracBrowser for help on using the browser.