Added support for using CurrentCodePage functionality with osgText::String

To the DXF plugin added Option string support for using CurrentCodePage|WidePage, UTF8, UTF16, UTF32 and FontFile=filename
This commit is contained in:
Robert Osfield 2020-01-13 13:41:37 +00:00
parent d969516595
commit 9e75926338
5 changed files with 89 additions and 5 deletions

View File

@ -60,7 +60,8 @@ class OSGTEXT_EXPORT String : public VectorUInt
ENCODING_UTF32, /// 32-bit signature
ENCODING_UTF32_BE, /// 32-bit big-endian
ENCODING_UTF32_LE, /// 32-bit little-endian
ENCODING_SIGNATURE /// detect encoding from signature
ENCODING_SIGNATURE, /// detect encoding from signature
ENCODING_CURRENT_CODE_PAGE /// Use Windows Current Code Page ecoding
};

View File

@ -36,6 +36,13 @@ public:
ReaderWriterdxf()
{
supportsExtension("dxf","Autodesk DXF format");
supportsOption("UTF8", "Assuming UTF8 encoding of dxf text");
supportsOption("UTF16", "Assuming UTF16 encoding of dxf text");
supportsOption("UTF32", "Assuming UTF32 encoding of dxf text");
supportsOption("SIGNATURE", "Detrmine encoding of dxf text from it's signative");
supportsOption("WideChar | CurrentCodePage", "Detrmine encoding of dxf text using CurrentCodePage (Windows only.)");
supportsOption("FontFile=<fontfile>", "Set the font file for dxf text");
}
virtual const char* className() const { return "Autodesk DXF Reader/Writer"; }
@ -143,6 +150,68 @@ ReaderWriterdxf::readNode(const std::string& filename, const osgDB::ReaderWriter
dxfEntity::getRegistryEntity("ARC")->setAccuracy(true,maxError,improveAccuracyOnly);
dxfEntity::getRegistryEntity("CIRCLE")->setAccuracy(true,maxError,improveAccuracyOnly);
} // accuracy options exists
{
std::istringstream iss(options->getOptionString());
std::string opt;
while (iss >> opt)
{
// split opt into pre= and post=
std::string pre_equals;
std::string post_equals;
size_t found = opt.find("=");
if (found != std::string::npos)
{
pre_equals = opt.substr(0, found);
post_equals = opt.substr(found + 1);
}
else
{
pre_equals = opt;
}
if (pre_equals == "FontFile")
{
std::string fontFile = post_equals.c_str();
if (!fontFile.empty())
{
dynamic_cast<dxfText*>(dxfEntity::getRegistryEntity("TEXT"))->font = fontFile;
OSG_INFO<<"ReaderWriteDXF : Set fontFile to "<<fontFile<<std::endl;
}
else
{
OSG_NOTICE << "Warning: invalid FontFile value: " << post_equals << std::endl;
}
}
else if (pre_equals=="UTF8")
{
dynamic_cast<dxfText*>(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_UTF8;
OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_UTF8"<<std::endl;
}
else if (pre_equals=="UTF16")
{
dynamic_cast<dxfText*>(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_UTF16;
OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_UTF16"<<std::endl;
}
else if (pre_equals=="UTF32")
{
dynamic_cast<dxfText*>(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_UTF32;
OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_UTF32"<<std::endl;
}
else if (pre_equals=="SIGNATURE")
{
dynamic_cast<dxfText*>(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_SIGNATURE;
OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_SIGNATURE"<<std::endl;
}
else if (pre_equals=="WideChar" || pre_equals=="CurrentCodePage")
{
dynamic_cast<dxfText*>(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_CURRENT_CODE_PAGE;
OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_CURRENT_CODE_PAGE"<<std::endl;
}
}
}
} // options exist

View File

@ -911,9 +911,8 @@ dxfText::drawScene(scene* sc)
ref_ptr<osgText::Text> _text = new osgText::Text;
_text->setText(_string, encoding);
_text->setFont(font);
_text->setCharacterSize( _height, 1.0/_xscale );
_text->setFont(font);
Quat qr( DegreesToRadians(_rotation), Z_AXIS );

View File

@ -307,7 +307,14 @@ public:
_vjustify(0) {}
virtual ~dxfText() {}
virtual dxfBasicEntity* create() { return new dxfText; }
virtual dxfBasicEntity* create()
{
dxfText* text = new dxfText;
text->encoding = encoding;
text->font = font;
return text;
}
virtual const char* name() { return "TEXT"; }
virtual void assign(dxfFile* dxf, codeValue& cv);
virtual void drawScene(scene* sc);

View File

@ -3,6 +3,8 @@
#include <osg/Notify>
#include <osg/Math>
#include <osgDB/ConvertUTF>
#include <iterator>
using namespace osgText;
@ -275,8 +277,14 @@ void String::set(const wchar_t* text)
}
}
void String::set(const std::string& text,Encoding encoding)
void String::set(const std::string& text, Encoding encoding)
{
if (encoding==ENCODING_CURRENT_CODE_PAGE)
{
set(osgDB::convertStringFromCurrentCodePageToUTF8(text), ENCODING_UTF8);
return;
}
clear();
look_ahead_iterator itr(text);