From 9e75926338fcb7eb4732acd54af4864b151b8d93 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 13 Jan 2020 13:41:37 +0000 Subject: [PATCH] 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 --- include/osgText/String | 3 +- src/osgPlugins/dxf/ReaderWriterDXF.cpp | 69 ++++++++++++++++++++++++++ src/osgPlugins/dxf/dxfEntity.cpp | 3 +- src/osgPlugins/dxf/dxfEntity.h | 9 +++- src/osgText/String.cpp | 10 +++- 5 files changed, 89 insertions(+), 5 deletions(-) diff --git a/include/osgText/String b/include/osgText/String index 3fb51e4ae..cc89c72a7 100644 --- a/include/osgText/String +++ b/include/osgText/String @@ -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 }; diff --git a/src/osgPlugins/dxf/ReaderWriterDXF.cpp b/src/osgPlugins/dxf/ReaderWriterDXF.cpp index a552c754d..c45e792b7 100644 --- a/src/osgPlugins/dxf/ReaderWriterDXF.cpp +++ b/src/osgPlugins/dxf/ReaderWriterDXF.cpp @@ -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=", "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(dxfEntity::getRegistryEntity("TEXT"))->font = fontFile; + + OSG_INFO<<"ReaderWriteDXF : Set fontFile to "<(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_UTF8; + OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_UTF8"<(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_UTF16; + OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_UTF16"<(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_UTF32; + OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_UTF32"<(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_SIGNATURE; + OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_SIGNATURE"<(dxfEntity::getRegistryEntity("TEXT"))->encoding = osgText::String::ENCODING_CURRENT_CODE_PAGE; + OSG_INFO<<"ReaderWriteDXF : Set encoding to osgText::String::ENCODING_CURRENT_CODE_PAGE"< _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 ); diff --git a/src/osgPlugins/dxf/dxfEntity.h b/src/osgPlugins/dxf/dxfEntity.h index ee553cb3d..96a915491 100644 --- a/src/osgPlugins/dxf/dxfEntity.h +++ b/src/osgPlugins/dxf/dxfEntity.h @@ -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); diff --git a/src/osgText/String.cpp b/src/osgText/String.cpp index 18529998c..32f95f94f 100644 --- a/src/osgText/String.cpp +++ b/src/osgText/String.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include 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);