root/OpenSceneGraph/trunk/src/osgPlugins/ive/Text3D.cpp @ 13041

Revision 13041, 6.0 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/**********************************************************************
2 *
3 *    FILE:            Text3D.cpp
4 *
5 *    DESCRIPTION:    Read/Write osgText::Text3D in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerator
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 27.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Exception.h"
16#include "Text3D.h"
17#include "Text.h"
18#include "Drawable.h"
19#include "Object.h"
20
21#include <osgDB/FileUtils>
22#include <osgDB/FileNameUtils>
23#include <osg/Notify>
24
25using namespace ive;
26
27void Text3D::write(DataOutputStream* out){
28    // Write Text's identification.
29    out->writeInt(IVETEXT3D);
30    // If the osg class is inherited by any other class we should also write this to file.
31    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
32    if(obj){
33        ((ive::Drawable*)(obj))->write(out);
34    }
35    else
36        out_THROW_EXCEPTION("Text::write(): Could not cast this osgText::Text to an osg::Drawable.");
37
38    // Write Text's properties.
39    if( getFont() )
40    {
41        std::string fname = getFont()->getFileName();
42
43        if(!fname.empty())
44        {
45            if(out->getUseOriginalExternalReferences())
46            {
47                out->writeString(fname); //Saving file name with local directory
48            }
49            else
50            {
51                out->writeString(osgDB::getSimpleFileName(fname)); //Saving original file name
52            }
53        }
54        else
55            out->writeString(""); //Blank string
56    }
57    else
58        out->writeString(""); //Blank string
59
60    out->writeUInt(getFontWidth());
61    out->writeUInt(getFontHeight());
62    out->writeFloat(getCharacterHeight());
63    out->writeFloat(getCharacterAspectRatio());
64    out->writeUInt(getCharacterSizeMode());
65    out->writeFloat(getMaximumWidth());
66    out->writeFloat(getMaximumHeight());
67
68    out->writeFloat(getLineSpacing());
69
70    out->writeUInt(getAlignment());
71
72    out->writeQuat(getRotation()); //FIXME: controllare che ci sia
73
74    out->writeBool(getAutoRotateToScreen());
75    out->writeUInt(getLayout());
76    out->writeVec3(getPosition());
77//    out->writeVec4(getColor());
78    out->writeUInt(getDrawMode());
79
80    //for text3d's property
81    out->writeFloat(getCharacterDepth());
82    out->writeUInt(getRenderMode());
83
84    // text :: Modified from osgPlugins::osg
85    const osgText::String& textstring = getText();
86    bool isACString = true;
87    osgText::String::const_iterator itr;
88    for(itr=textstring.begin();
89        itr!=textstring.end() && isACString;
90        ++itr)
91    {
92        if (*itr==0 || *itr>256) isACString=false;
93    }
94
95    if (isACString)
96    {
97        std::string str;
98
99        for(itr=textstring.begin();
100            itr!=textstring.end();
101            ++itr)
102        {
103            str += (char)(*itr);
104        }
105
106        //std::copy(textstring.begin(),textstring.end(),std::back_inserter(str));
107
108        out->writeBool(true);
109        out->writeString(str);
110    }
111    else
112    {
113        // do it the hardway...output each character as an int
114        osg::ref_ptr<osg::UIntArray> strarr = new osg::UIntArray(textstring.size());
115
116        for(itr=textstring.begin();
117            itr!=textstring.end();
118            ++itr)
119        {
120            strarr->push_back((*itr));
121        }
122
123        out->writeBool(false);
124        out->writeUIntArray(strarr.get());
125    }
126}
127
128void Text3D::read(DataInputStream* in){
129    // Peek on Text3D's identification.
130    int id = in->peekInt();
131    if(id == IVETEXT3D){
132        // Read Text3D's identification.
133        id = in->readInt();
134        // If the osg class is inherited by any other class we should also read this from file.
135        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
136        if(obj){
137            ((ive::Drawable*)(obj))->read(in);
138        }
139        else
140            in_THROW_EXCEPTION("Text::read(): Could not cast this osgText::Text to an osg::Drawable.");
141        // Read Text's properties
142
143    unsigned int width, height;
144    float c_height, aspectRatio;
145
146    setFont(in->readString());
147
148    width = in->readUInt();
149    height = in->readUInt();
150
151    setFontResolution(width,height);
152
153    c_height = in->readFloat();
154    aspectRatio = in->readFloat();
155
156    setCharacterSize(c_height,aspectRatio);
157
158    setCharacterSizeMode((osgText::TextBase::CharacterSizeMode) in->readUInt());
159
160    setMaximumWidth(in->readFloat());
161    setMaximumHeight(in->readFloat());
162
163    if ( in->getVersion() >= VERSION_0020 )
164    {
165        setLineSpacing(in->readFloat());
166    }
167
168    setAlignment((osgText::TextBase::AlignmentType) in->readUInt());
169
170    //Nothing to do...
171    //setAxisAlignment((osgText::Text::AxisAlignment) in->readUint());
172
173    setRotation(in->readQuat());
174    setAutoRotateToScreen(in->readBool());
175    setLayout((osgText::Text::Layout) in->readUInt());
176
177    setPosition(in->readVec3());
178//    setColor(in->readVec4());
179    setDrawMode(in->readUInt());
180
181    //for text3d's property
182    setCharacterDepth(in->readFloat());
183    setRenderMode((osgText::Text3D::RenderMode) in->readUInt());
184
185    if(in->readBool())
186        setText(in->readString());
187    else
188    {
189        if ( in->getVersion() >= VERSION_0018 )
190        {
191            osgText::String textstr;
192            osg::ref_ptr<osg::UIntArray> arr = in->readUIntArray();
193            for(unsigned int i = 0; i < arr->getNumElements(); i++)
194            {
195                textstr.push_back( arr->at(i) );
196            }
197
198            setText(textstr);
199        }
200        else
201        {
202            // buggy original path, should have used a UIntArray originally, now fixed above.
203            std::string textstr;
204            osg::ref_ptr<osg::UByteArray> arr = in->readUByteArray();
205            for(unsigned int i = 0; i < arr->getNumElements(); i++)
206            {
207                textstr += (char) arr->at(i);
208            }
209
210            setText(textstr);
211        }
212    }
213
214    }
215    else{
216        in_THROW_EXCEPTION("Text3D::read(): Expected ShadeModel identification.");
217    }
218}
Note: See TracBrowser for help on using the browser.