I have just fixed and checked the change to using UIntArray for non c string osgText::String's. I don't have any text to test it against, so please do a cvs update/test the attached files and let me know how you get on.
Robert.
On 9/19/06, Robert Osfield <[EMAIL PROTECTED]> wrote:
Hi Xueliang,
I have just reviewed the .ive code and frustratingly it does try to tackle the case of wchar's but does so incorrectly, reading I know what the author intended, but atlas use UByteArray rather than UIntArray. Unfortunately to fix it we'll need to rev the .ive version number, but the fix itself should be quite straightforward.
Robert.On 9/19/06, Xueliang Chai < [EMAIL PROTECTED]> wrote:Hi,All
I create an osgText Node,and use wchar_t type to set the texts,it shows correctly. but when I save the node to an IVE file,and read it again, I find it incorrect(The Chinese Text is showed incorrectly). It looks like pluginIVE can't support reading/writing the value with wchar_t type.how to solve the problem?Thank you for your reply.
Xueliang
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
#ifndef IVE_VERSION #define IVE_VERSION 1
/* The VERSION tag should be updated any time the IVE format changes in order to support backward compatibility (if implemented). VERSION is stored in the 2nd 4 bytes of the file */ #define VERSION_0001 1 #define VERSION_0002 2 #define VERSION_0003 3 #define VERSION_0004 4 #define VERSION_0005 5 #define VERSION_0006 6 #define VERSION_0007 7 #define VERSION_0008 8 #define VERSION_0009 9 #define VERSION_0010 10 #define VERSION_0011 11 #define VERSION_0012 12 #define VERSION_0013 13 #define VERSION_0014 14 #define VERSION_0015 15 #define VERSION_0016 16 #define VERSION_0017 17 #define VERSION_0018 18 #define VERSION VERSION_0018 /* The BYTE_SEX tag is used to check the endian of the IVE file being read in. The IVE format is always written in the native endian of the machine to provide optimum reading of the file. BYTE_SEX is stored in the first 4 bytes of the file */ #define ENDIAN_TYPE 0x01020304 #define OPPOSITE_ENDIAN_TYPE 0x04030201 #endif
/**********************************************************************
*
* FILE: Text.cpp
*
* DESCRIPTION: Read/Write osgText::Text in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Text.h"
#include "Drawable.h"
#include "Object.h"
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osg/Notify>
using namespace ive;
void Text::write(DataOutputStream* out){
// Write Text's identification.
out->writeInt(IVETEXT);
// If the osg class is inherited by any other class we should also write
this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Drawable*)(obj))->write(out);
}
else
throw Exception("Text::write(): Could not cast this osgText::Text to an
osg::Drawable.");
// Write Text's properties.
if( getFont() )
{
std::string fname = getFont()->getFileName();
if(!fname.empty())
{
if(out->getUseOriginalExternalReferences())
{
out->writeString(fname); //Saving file name with local directory
}
else
{
out->writeString(osgDB::getSimpleFileName(fname)); //Saving
original file name
}
}
else
out->writeString(""); //Blank string
}
else
out->writeString(""); //Blank string
out->writeUInt(getFontWidth());
out->writeUInt(getFontHeight());
out->writeFloat(getCharacterHeight());
out->writeFloat(getCharacterAspectRatio());
out->writeUInt(getCharacterSizeMode());
out->writeFloat(getMaximumWidth());
out->writeFloat(getMaximumHeight());
out->writeUInt(getAlignment());
out->writeQuat(getRotation()); //FIXME: controllare che ci sia
out->writeBool(getAutoRotateToScreen());
out->writeUInt(getLayout());
out->writeVec3(getPosition());
out->writeVec4(getColor());
out->writeUInt(getDrawMode());
// text :: Modified from osgPlugins::osg
const osgText::String& textstring = getText();
bool isACString = true;
osgText::String::const_iterator itr;
for(itr=textstring.begin();
itr!=textstring.end() && isACString;
++itr)
{
if (*itr==0 || *itr>256) isACString=false;
}
if (isACString)
{
std::string str;
for(itr=textstring.begin();
itr!=textstring.end();
++itr)
{
str += (char)(*itr);
}
//std::copy(textstring.begin(),textstring.end(),std::back_inserter(str));
out->writeBool(true);
out->writeString(str);
}
else
{
// do it the hardway...output each character as an int
osg::ref_ptr<osg::UIntArray> strarr = new
osg::UIntArray(textstring.size());
for(itr=textstring.begin();
itr!=textstring.end();
++itr)
{
strarr->push_back((*itr));
}
out->writeBool(false);
out->writeUIntArray(strarr.get());
}
}
void Text::read(DataInputStream* in){
// Peek on Text's identification.
int id = in->peekInt();
if(id == IVETEXT){
// Read Text's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read
this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Drawable*)(obj))->read(in);
}
else
throw Exception("Text::read(): Could not cast this osgText::Text to
an osg::Drawable.");
// Read Text's properties
unsigned int width, height;
float c_height, aspectRatio;
setFont(in->readString());
width = in->readUInt();
height = in->readUInt();
setFontResolution(width,height);
c_height = in->readFloat();
aspectRatio = in->readFloat();
setCharacterSize(c_height,aspectRatio);
setCharacterSizeMode((osgText::Text::CharacterSizeMode) in->readUInt());
setMaximumWidth(in->readFloat());
setMaximumHeight(in->readFloat());
setAlignment((osgText::Text::AlignmentType) in->readUInt());
//Nothing to do...
//setAxisAlignment((osgText::Text::AxisAlignment) in->readUint());
setRotation(in->readQuat());
setAutoRotateToScreen(in->readBool());
setLayout((osgText::Text::Layout) in->readUInt());
setPosition(in->readVec3());
setColor(in->readVec4());
setDrawMode(in->readUInt());
if(in->readBool())
setText(in->readString());
else
{
if ( in->getVersion() >= VERSION_0018 )
{
osgText::String textstr;
osg::ref_ptr<osg::UIntArray> arr = in->readUIntArray();
for(unsigned int i = 0; i < arr->getNumElements(); i++)
{
textstr.push_back( arr->at(i) );
}
setText(textstr);
}
else
{
// buggy original path, should have used a UIntArray originally,
now fixed above.
std::string textstr;
osg::ref_ptr<osg::UByteArray> arr = in->readUByteArray();
for(unsigned int i = 0; i < arr->getNumElements(); i++)
{
textstr += (char) arr->at(i);
}
setText(textstr);
}
}
}
else{
throw Exception("ShadeModel::read(): Expected ShadeModel
identification.");
}
}
_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
