Moved Font code across to using FontSizePair internally and on Font methods, but
still using original implemetations.
This commit is contained in:
parent
dea067050c
commit
f290b75bc9
@ -98,7 +98,7 @@ public:
|
|||||||
const osg::StateSet* getStateSet() const { return _stateset.get(); }
|
const osg::StateSet* getStateSet() const { return _stateset.get(); }
|
||||||
|
|
||||||
/** Set the pixel width and height hint.*/
|
/** Set the pixel width and height hint.*/
|
||||||
virtual void setFontResolution(unsigned int width, unsigned int height);
|
virtual void setFontResolution(const FontSizePair& fontSize);
|
||||||
|
|
||||||
unsigned int getFontWidth() const;
|
unsigned int getFontWidth() const;
|
||||||
unsigned int getFontHeight() const;
|
unsigned int getFontHeight() const;
|
||||||
@ -211,7 +211,7 @@ public:
|
|||||||
virtual std::string getFileName() const = 0;
|
virtual std::string getFileName() const = 0;
|
||||||
|
|
||||||
/** Set the pixel width and height hint.*/
|
/** Set the pixel width and height hint.*/
|
||||||
virtual void setFontResolution(unsigned int width, unsigned int height) = 0;
|
virtual void setFontResolution(const FontSizePair& fontSize) = 0;
|
||||||
|
|
||||||
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
|
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
|
||||||
virtual Glyph* getGlyph(unsigned int charcode) = 0;
|
virtual Glyph* getGlyph(unsigned int charcode) = 0;
|
||||||
|
@ -41,8 +41,8 @@ public:
|
|||||||
* the closest supported font size will be selected.*/
|
* the closest supported font size will be selected.*/
|
||||||
void setFontResolution(unsigned int width, unsigned int height);
|
void setFontResolution(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
unsigned int getFontWidth() const { return _fontWidth; }
|
unsigned int getFontWidth() const { return _fontSize.first; }
|
||||||
unsigned int getFontHeight() const { return _fontHeight; }
|
unsigned int getFontHeight() const { return _fontSize.second; }
|
||||||
|
|
||||||
|
|
||||||
/** Set the text using a osgText::String.*/
|
/** Set the text using a osgText::String.*/
|
||||||
@ -239,8 +239,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
// members which have public access.
|
// members which have public access.
|
||||||
unsigned int _fontWidth;
|
FontSizePair _fontSize;
|
||||||
unsigned int _fontHeight;
|
|
||||||
float _characterHeight;
|
float _characterHeight;
|
||||||
float _characterAspectRatio;
|
float _characterAspectRatio;
|
||||||
CharacterSizeMode _characterSizeMode;
|
CharacterSizeMode _characterSizeMode;
|
||||||
|
@ -58,8 +58,10 @@ FreeTypeFont::~FreeTypeFont()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeTypeFont::setFontResolution(unsigned int width, unsigned int height)
|
void FreeTypeFont::setFontResolution(const osgText::FontSizePair& fontSize)
|
||||||
{
|
{
|
||||||
|
int width = fontSize.first;
|
||||||
|
int height = fontSize.second;
|
||||||
int maxAxis = std::max(width, height);
|
int maxAxis = std::max(width, height);
|
||||||
int margin = _facade->getGlyphImageMargin() + (int)((float)maxAxis * _facade->getGlyphImageMarginRatio());
|
int margin = _facade->getGlyphImageMargin() + (int)((float)maxAxis * _facade->getGlyphImageMarginRatio());
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
|
|
||||||
virtual std::string getFileName() const { return _filename; }
|
virtual std::string getFileName() const { return _filename; }
|
||||||
|
|
||||||
virtual void setFontResolution(unsigned int width, unsigned int height);
|
virtual void setFontResolution(const osgText::FontSizePair& fontSize);
|
||||||
|
|
||||||
virtual osgText::Font::Glyph* getGlyph(unsigned int charcode);
|
virtual osgText::Font::Glyph* getGlyph(unsigned int charcode);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class ReaderWriterTXF : public osgDB::ReaderWriter
|
|||||||
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
|
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
|
||||||
|
|
||||||
std::ifstream stream;
|
std::ifstream stream;
|
||||||
stream.open(fileName.c_str(), std::ios::in | std::ios::binary);
|
stream.open(fileName.c_str(), std::ios::in | std::ios::binary);
|
||||||
if (!stream.is_open()) return ReadResult::FILE_NOT_FOUND;
|
if (!stream.is_open()) return ReadResult::FILE_NOT_FOUND;
|
||||||
|
|
||||||
TXFFont* impl = new TXFFont(fileName);
|
TXFFont* impl = new TXFFont(fileName);
|
||||||
|
@ -82,7 +82,7 @@ TXFFont::getFileName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TXFFont::setFontResolution(unsigned int, unsigned int)
|
TXFFont::setFontResolution(const osgText::FontSizePair&)
|
||||||
{
|
{
|
||||||
osg::notify(osg::INFO) << "TXFFont::setFontResolution(,) call is ignored." << std::endl;
|
osg::notify(osg::INFO) << "TXFFont::setFontResolution(,) call is ignored." << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
|
|
||||||
virtual std::string getFileName() const;
|
virtual std::string getFileName() const;
|
||||||
|
|
||||||
virtual void setFontResolution(unsigned int width, unsigned int height);
|
virtual void setFontResolution(const osgText::FontSizePair&);
|
||||||
|
|
||||||
virtual osgText::Font::Glyph* getGlyph(unsigned int charcode);
|
virtual osgText::Font::Glyph* getGlyph(unsigned int charcode);
|
||||||
|
|
||||||
|
@ -261,9 +261,9 @@ std::string Font::getFileName() const
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::setFontResolution(unsigned int width, unsigned int height)
|
void Font::setFontResolution(const FontSizePair& fontSize)
|
||||||
{
|
{
|
||||||
if (_implementation.valid()) _implementation->setFontResolution(width, height);
|
if (_implementation.valid()) _implementation->setFontResolution(fontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Font::getFontWidth() const
|
unsigned int Font::getFontWidth() const
|
||||||
|
@ -279,7 +279,7 @@ void Text::computeGlyphRepresentation()
|
|||||||
|
|
||||||
unsigned int lineNumber = 0;
|
unsigned int lineNumber = 0;
|
||||||
|
|
||||||
activefont->setFontResolution(_fontWidth,_fontHeight);
|
activefont->setFontResolution(_fontSize);
|
||||||
|
|
||||||
float hr = _characterHeight/(float)activefont->getFontHeight();
|
float hr = _characterHeight/(float)activefont->getFontHeight();
|
||||||
float wr = hr/_characterAspectRatio;
|
float wr = hr/_characterAspectRatio;
|
||||||
@ -696,9 +696,9 @@ void Text::computePositions(unsigned int contextID) const
|
|||||||
scale_font_vert=-scale_font_vert;
|
scale_font_vert=-scale_font_vert;
|
||||||
matrix.postMult(osg::Matrix::scale(scale_font_hori, scale_font_vert,1.0f));
|
matrix.postMult(osg::Matrix::scale(scale_font_hori, scale_font_vert,1.0f));
|
||||||
}
|
}
|
||||||
else if (pixelSizeVert>_fontHeight)
|
else if (pixelSizeVert>getFontHeight())
|
||||||
{
|
{
|
||||||
float scale_font = _fontHeight/pixelSizeVert;
|
float scale_font = getFontHeight()/pixelSizeVert;
|
||||||
matrix.postMult(osg::Matrix::scale(scale_font, scale_font,1.0f));
|
matrix.postMult(osg::Matrix::scale(scale_font, scale_font,1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,7 @@ using namespace osgText;
|
|||||||
//#define TREES_CODE_FOR_MAKING_SPACES_EDITABLE
|
//#define TREES_CODE_FOR_MAKING_SPACES_EDITABLE
|
||||||
|
|
||||||
TextBase::TextBase():
|
TextBase::TextBase():
|
||||||
_fontWidth(32),
|
_fontSize(32,32),
|
||||||
_fontHeight(32),
|
|
||||||
_characterHeight(32),
|
_characterHeight(32),
|
||||||
_characterAspectRatio(1.0f),
|
_characterAspectRatio(1.0f),
|
||||||
_characterSizeMode(OBJECT_COORDS),
|
_characterSizeMode(OBJECT_COORDS),
|
||||||
@ -55,8 +54,7 @@ TextBase::TextBase():
|
|||||||
|
|
||||||
TextBase::TextBase(const TextBase& textBase,const osg::CopyOp& copyop):
|
TextBase::TextBase(const TextBase& textBase,const osg::CopyOp& copyop):
|
||||||
osg::Drawable(textBase,copyop),
|
osg::Drawable(textBase,copyop),
|
||||||
_fontWidth(textBase._fontWidth),
|
_fontSize(textBase._fontSize),
|
||||||
_fontHeight(textBase._fontHeight),
|
|
||||||
_characterHeight(textBase._characterHeight),
|
_characterHeight(textBase._characterHeight),
|
||||||
_characterAspectRatio(textBase._characterAspectRatio),
|
_characterAspectRatio(textBase._characterAspectRatio),
|
||||||
_characterSizeMode(textBase._characterSizeMode),
|
_characterSizeMode(textBase._characterSizeMode),
|
||||||
@ -82,8 +80,7 @@ TextBase::~TextBase()
|
|||||||
|
|
||||||
void TextBase::setFontResolution(unsigned int width, unsigned int height)
|
void TextBase::setFontResolution(unsigned int width, unsigned int height)
|
||||||
{
|
{
|
||||||
_fontWidth = width;
|
_fontSize = FontSizePair(width,height);
|
||||||
_fontHeight = height;
|
|
||||||
computeGlyphRepresentation();
|
computeGlyphRepresentation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user