00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifdef _MSC_VER
00040 # pragma warning (disable: 4786)
00041 #endif
00042
00043 #include "OSGTextPixmapFace.h"
00044 #include "OSGTextPixmapGlyph.h"
00045 #include "OSGTextLayoutResult.h"
00046 #include "OSGTextFaceFactory.h"
00047 #ifdef __sgi
00048 # include <assert.h>
00049 #else
00050 # include <cassert>
00051 #endif
00052
00053
00054 using namespace std;
00055
00056
00057 OSG_BEGIN_NAMESPACE
00058
00059
00060
00061
00062
00063
00064 TextPixmapGlyph TextPixmapFace::_emptyGlyph;
00065
00066
00067
00068
00069
00070
00071 TextPixmapFace::~TextPixmapFace()
00072 {
00073
00074 GlyphMap::iterator it;
00075 for (it = _glyphMap.begin(); it != _glyphMap.end(); ++it)
00076 {
00077 assert(it->second != 0);
00078 delete it->second;
00079 }
00080 }
00081
00082
00083
00084
00085
00086
00087 const TextGlyph &TextPixmapFace::getGlyph(TextGlyph::Index glyphIndex)
00088 {
00089 return getPixmapGlyph(glyphIndex);
00090 }
00091
00092
00093
00094
00095
00096
00097 const TextPixmapGlyph &TextPixmapFace::getPixmapGlyph(TextGlyph::Index glyphIndex)
00098 {
00099 if (glyphIndex == TextGlyph::INVALID_INDEX)
00100 return _emptyGlyph;
00101
00102
00103 GlyphMap::const_iterator it = _glyphMap.find(glyphIndex);
00104 if (it != _glyphMap.end())
00105 {
00106 assert(it->second != 0);
00107 return *(it->second);
00108 }
00109
00110
00111 auto_ptr<TextPixmapGlyph> glyph = createGlyph(glyphIndex);
00112
00113
00114 if (glyph.get() == 0)
00115 return _emptyGlyph;
00116
00117
00118 _glyphMap.insert(GlyphMap::value_type(glyphIndex, glyph.get()));
00119
00120
00121 return *(glyph.release());
00122 }
00123
00124
00125
00126
00127
00128
00129 ImagePtr TextPixmapFace::makeImage(const TextLayoutResult &layoutResult, Vec2f &offset)
00130 {
00131 Vec2f lowerLeft, upperRight;
00132 calculateBoundingBox(layoutResult, lowerLeft, upperRight);
00133 offset.setValues(lowerLeft.x(), upperRight.y());
00134
00135 ImagePtr imagePtr = Image::create();
00136 beginEditCP(imagePtr);
00137 {
00138 UInt32 width = static_cast<UInt32>(osgceil(upperRight.x() - lowerLeft.x()));
00139 UInt32 height = static_cast<UInt32>(osgceil(upperRight.y() - lowerLeft.y()));
00140 imagePtr->set(Image::OSG_I_PF, width, height);
00141 imagePtr->clear();
00142 UInt8 *buffer = imagePtr->getData();
00143
00144
00145 UInt32 i, numGlyphs = layoutResult.getNumGlyphs();
00146 for (i = 0; i < numGlyphs; ++i)
00147 {
00148 const TextPixmapGlyph &glyph = getPixmapGlyph(layoutResult.indices[i]);
00149 const Vec2f &pos = layoutResult.positions[i];
00150 Int32 x = static_cast<Int32>(pos.x() - lowerLeft.x() + 0.5f);
00151 Int32 y = static_cast<Int32>(pos.y() - lowerLeft.y() + 0.5f);
00152 glyph.putPixmap(x, y, buffer, width, height);
00153 }
00154 }
00155 endEditCP(imagePtr);
00156
00157 return imagePtr;
00158 }
00159
00160
00161
00162
00163
00164
00165 TextPixmapFace *TextPixmapFace::create(const std::string &family, Style style, UInt32 size)
00166 { return TextFaceFactory::the().createPixmapFace(family, style, size); }
00167
00168
00169 OSG_END_NAMESPACE
00170
00171
00172
00173
00174
00175 #ifdef OSG_SGI_CC
00176 #pragma set woff 1174
00177 #endif
00178
00179 #ifdef OSG_LINUX_ICC
00180 #pragma warning( disable : 177 )
00181 #endif
00182
00183 namespace
00184 {
00185 static OSG::Char8 cvsid_cpp[] = "@(#)$Id: OSGTextPixmapFace.cpp,v 1.2 2005/06/29 16:25:03 pdaehne Exp $";
00186 static OSG::Char8 cvsid_hpp[] = OSGTEXTPIXMAPFACE_HEADER_CVSID;
00187 static OSG::Char8 cvsid_inl[] = OSGTEXTPIXMAPFACE_INLINE_CVSID;
00188 }
00189
00190 #ifdef __sgi
00191 #pragma reset woff 1174
00192 #endif