First cut of new osgText implementation.

This commit is contained in:
Robert Osfield
2003-03-02 21:05:05 +00:00
parent a826f5ee31
commit fbe674b321
71 changed files with 1933 additions and 7226 deletions

View File

@@ -1,205 +0,0 @@
#include <osgText/Font>
#include <osgText/Font>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
/////////////////////////////////////////////////////////////////////////////
// class Font
/////////////////////////////////////////////////////////////////////////////
bool Font_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy Font_Proxy
(
0,
"Font",
"Object Font",
0,
Font_writeLocalData
);
bool Font_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgText::Font &myobj = static_cast<const osgText::Font &>(obj);
fw.indent() << "parameters ";
fw << myobj.getPointSize() << " " << myobj.getTextureSize() << " ";
fw << fw.wrapString(myobj.getFontName()) << std::endl;
return true;
}
/////////////////////////////////////////////////////////////////////////////
// class BitmapFont
/////////////////////////////////////////////////////////////////////////////
bool BitmapFont_readLocalData(osg::Object &obj, osgDB::Input &fr);
osgDB::RegisterDotOsgWrapperProxy BitmapFont_Proxy
(
new osgText::BitmapFont,
"BitmapFont",
"Object Font RasterFont BitmapFont",
BitmapFont_readLocalData,
0
);
bool BitmapFont_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgText::BitmapFont &myobj = static_cast<osgText::BitmapFont &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("parameters")) {
int psize;
if (fr[1].getInt(psize) && fr[2].isInt() && fr[3].isString()) {
osgText::BitmapFont *temp = new osgText::BitmapFont(std::string(fr[3].getStr()), psize);
temp->copyAndInvalidate(myobj);
fr += 4;
itAdvanced = true;
}
}
return itAdvanced;
}
/////////////////////////////////////////////////////////////////////////////
// class PixmapFont
/////////////////////////////////////////////////////////////////////////////
bool PixmapFont_readLocalData(osg::Object &obj, osgDB::Input &fr);
osgDB::RegisterDotOsgWrapperProxy PixmapFont_Proxy
(
new osgText::PixmapFont,
"PixmapFont",
"Object Font RasterFont PixmapFont",
PixmapFont_readLocalData,
0
);
bool PixmapFont_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgText::PixmapFont &myobj = static_cast<osgText::PixmapFont &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("parameters")) {
int psize;
if (fr[1].getInt(psize) && fr[2].isInt() && fr[3].isString()) {
osgText::PixmapFont *temp = new osgText::PixmapFont(std::string(fr[3].getStr()), psize);
temp->copyAndInvalidate(myobj);
fr += 4;
itAdvanced = true;
}
}
return itAdvanced;
}
/////////////////////////////////////////////////////////////////////////////
// class TextureFont
/////////////////////////////////////////////////////////////////////////////
bool TextureFont_readLocalData(osg::Object &obj, osgDB::Input &fr);
osgDB::RegisterDotOsgWrapperProxy TextureFont_Proxy
(
new osgText::TextureFont,
"TextureFont",
"Object Font RasterFont TextureFont",
TextureFont_readLocalData,
0
);
bool TextureFont_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgText::TextureFont &myobj = static_cast<osgText::TextureFont &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("parameters")) {
int psize, txsize;
if (fr[1].getInt(psize) && fr[2].getInt(txsize) && fr[3].isString()) {
osgText::TextureFont *temp = new osgText::TextureFont(std::string(fr[3].getStr()), psize, txsize);
temp->copyAndInvalidate(myobj);
fr += 4;
itAdvanced = true;
}
}
return itAdvanced;
}
/////////////////////////////////////////////////////////////////////////////
// class OutlineFont
/////////////////////////////////////////////////////////////////////////////
bool OutlineFont_readLocalData(osg::Object &obj, osgDB::Input &fr);
osgDB::RegisterDotOsgWrapperProxy OutlineFont_Proxy
(
new osgText::OutlineFont,
"OutlineFont",
"Object Font VectorFont OutlineFont",
OutlineFont_readLocalData,
0
);
bool OutlineFont_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgText::OutlineFont &myobj = static_cast<osgText::OutlineFont &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("parameters")) {
int psize;
if (fr[1].getInt(psize) && fr[2].isInt() && fr[3].isString()) {
osgText::OutlineFont *temp = new osgText::OutlineFont(std::string(fr[3].getStr()), psize, 1);
temp->copyAndInvalidate(myobj);
fr += 4;
itAdvanced = true;
}
}
return itAdvanced;
}
/////////////////////////////////////////////////////////////////////////////
// class PolygonFont
/////////////////////////////////////////////////////////////////////////////
bool PolygonFont_readLocalData(osg::Object &obj, osgDB::Input &fr);
osgDB::RegisterDotOsgWrapperProxy PolygonFont_Proxy
(
new osgText::PolygonFont,
"PolygonFont",
"Object Font VectorFont PolygonFont",
PolygonFont_readLocalData,
0
);
bool PolygonFont_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgText::PolygonFont &myobj = static_cast<osgText::PolygonFont &>(obj);
bool itAdvanced = false;
if (fr[0].matchWord("parameters")) {
int psize;
if (fr[1].getInt(psize) && fr[2].isInt() && fr[3].isString()) {
osgText::PolygonFont *temp = new osgText::PolygonFont(std::string(fr[3].getStr()), psize, 1);
temp->copyAndInvalidate(myobj);
fr += 4;
itAdvanced = true;
}
}
return itAdvanced;
}

View File

@@ -1,100 +0,0 @@
#include <osgText/Paragraph>
#include <osgText/Font>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
bool Paragraph_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool Paragraph_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
// osgDB::RegisterDotOsgWrapperProxy Paragraph_Proxy
// (
// new osgText::Paragraph,
// "Paragraph",
// "Object Node Geode Paragraph",
// Paragraph_readLocalData,
// Paragraph_writeLocalData
// );
//
bool Paragraph_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgText::Paragraph &myobj = static_cast<osgText::Paragraph &>(obj);
bool itAdvanced = false;
// font
osgText::Font *font = dynamic_cast<osgText::Font *>(fr.readObject());
if (font) {
myobj.setFont(font);
itAdvanced = true;
}
// maximum chars
if (fr[0].matchWord("maximumNoCharactersPerLine")) {
int i;
if (fr[1].getInt(i)) {
myobj.setMaximumNoCharactersPerLine(i);
fr += 2;
itAdvanced = true;
}
}
// text
if (fr[0].matchWord("text") && fr[1].isString()) {
myobj.setText(std::string(fr[1].getStr()));
fr += 2;
itAdvanced = true;
}
// position
if (fr[0].matchWord("position")) {
osg::Vec3 p;
if (fr[1].getFloat(p.x()) && fr[2].getFloat(p.y()) && fr[3].getFloat(p.z())) {
myobj.setPosition(p);
fr += 4;
itAdvanced = true;
}
}
// alignment
if (fr[0].matchWord("alignment")) {
int i;
if (fr[1].getInt(i)) {
myobj.setAlignment(i);
fr += 2;
itAdvanced = true;
}
}
return itAdvanced;
}
bool Paragraph_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgText::Paragraph &myobj = static_cast<const osgText::Paragraph &>(obj);
// font
fw.writeObject(*myobj.getFont());
// maximum chars
fw.indent() << "maximumNoCharactersPerLine " << myobj.getMaximumNoCharactersPerLine() << std::endl;
// text
fw.indent() << "text " << myobj.getText() << std::endl;
// position
osg::Vec3 p = myobj.getPosition();
fw.indent() << "position " << p.x() << " " << p.y() << " " << p.z() << std::endl;
// alignment
fw.indent() << "alignment " << myobj.getAlignment() << std::endl;
return true;
}

View File

@@ -25,14 +25,14 @@ osgDB::RegisterDotOsgWrapperProxy Text_Proxy
bool Text_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgText::Text &myobj = static_cast<osgText::Text &>(obj);
osgText::Text &text = static_cast<osgText::Text &>(obj);
bool itAdvanced = false;
// position
if (fr[0].matchWord("position")) {
osg::Vec3 p;
if (fr[1].getFloat(p.x()) && fr[2].getFloat(p.y()) && fr[3].getFloat(p.z())) {
myobj.setPosition(p);
text.setPosition(p);
fr += 4;
itAdvanced = true;
}
@@ -42,7 +42,7 @@ bool Text_readLocalData(osg::Object &obj, osgDB::Input &fr)
if (fr[0].matchWord("color")) {
osg::Vec4 c;
if (fr[1].getFloat(c.x()) && fr[2].getFloat(c.y()) && fr[3].getFloat(c.z()) && fr[4].getFloat(c.w())) {
myobj.setColor(c);
text.setColor(c);
fr += 4;
itAdvanced = true;
}
@@ -52,17 +52,7 @@ bool Text_readLocalData(osg::Object &obj, osgDB::Input &fr)
if (fr[0].matchWord("drawMode")) {
int i;
if (fr[1].getInt(i)) {
myobj.setDrawMode(i);
fr += 2;
itAdvanced = true;
}
}
// bounding box
if (fr[0].matchWord("boundingBox")) {
int i;
if (fr[1].getInt(i)) {
myobj.setBoundingBox(i);
text.setDrawMode(i);
fr += 2;
itAdvanced = true;
}
@@ -72,22 +62,15 @@ bool Text_readLocalData(osg::Object &obj, osgDB::Input &fr)
if (fr[0].matchWord("alignment")) {
int i;
if (fr[1].getInt(i)) {
myobj.setAlignment(i);
text.setAlignment((osgText::Text::AlignmentType)i);
fr += 2;
itAdvanced = true;
}
}
// font
osgText::Font *font = dynamic_cast<osgText::Font *>(fr.readObject());
if (font) {
myobj.setFont(font);
itAdvanced = true;
}
// text
if (fr.matchSequence("text %s")) {
myobj.setText(std::string(fr[1].getStr()));
text.setText(std::string(fr[1].getStr()));
fr += 2;
itAdvanced = true;
}
@@ -97,30 +80,47 @@ bool Text_readLocalData(osg::Object &obj, osgDB::Input &fr)
bool Text_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgText::Text &myobj = static_cast<const osgText::Text &>(obj);
const osgText::Text &text = static_cast<const osgText::Text &>(obj);
if (text.getFont())
{
fw.indent() << "font " << text.getFont()->getFileName() << std::endl;
}
fw.indent() << "fontSize " << text.getFontWidth() << " " << text.getFontHeight() << std::endl;
// position
osg::Vec3 p = myobj.getPosition();
osg::Vec3 p = text.getPosition();
fw.indent() << "position " << p.x() << " " << p.y() << " " << p.z() << std::endl;
// color
osg::Vec4 c = myobj.getColor();
osg::Vec4 c = text.getColor();
fw.indent() << "color " << c.x() << " " << c.y() << " " << c.z() << " " << c.w() << std::endl;
// draw mode
fw.indent() << "drawMode " << myobj.getDrawMode() << std::endl;
// bounding box
fw.indent() << "boundingBox " << myobj.getBoundingBox() << std::endl;
fw.indent() << "drawMode " << text.getDrawMode() << std::endl;
// alignment
fw.indent() << "alignment " << myobj.getAlignment() << std::endl;
// font
fw.writeObject(*myobj.getFont());
fw.indent() << "alignment " << text.getAlignment() << std::endl;
// text
fw.indent() << "text " << fw.wrapString(myobj.getText()) << std::endl;
const osgText::Text::TextString& textstring = text.getText();
bool isACString = true;
for(osgText::Text::TextString::const_iterator itr=textstring.begin();
itr!=textstring.end() && isACString;
++itr)
{
if (*itr==0 || *itr>256) isACString=false;
}
if (isACString)
{
std::string str(textstring.begin(),textstring.end());
fw.indent() << "text " << fw.wrapString(str) << std::endl;
}
else
{
// do it the hardway...
}
return true;
}

View File

@@ -2,10 +2,7 @@ TOPDIR = ../../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
IO_Text.cpp \
IO_Font.cpp \
IO_Paragraph.cpp \
IO_Text.cpp
LIBS += -losgText $(OSG_LIBS) $(OTHER_LIBS)