Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGTextPixmapFace.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
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 // Static Class Variable implementations:
00062 // Author: pdaehne
00063 //----------------------------------------------------------------------
00064 TextPixmapGlyph TextPixmapFace::_emptyGlyph;
00065 
00066 
00067 //----------------------------------------------------------------------
00068 // Destructor
00069 // Author: pdaehne
00070 //----------------------------------------------------------------------
00071 TextPixmapFace::~TextPixmapFace()
00072 {
00073     // Delete all glyphs in the glyph cache
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 // Returns information about a glyph.
00085 // Author: pdaehne
00086 //----------------------------------------------------------------------
00087 const TextGlyph &TextPixmapFace::getGlyph(TextGlyph::Index glyphIndex)
00088 {
00089     return getPixmapGlyph(glyphIndex);
00090 }
00091 
00092 
00093 //----------------------------------------------------------------------
00094 // Returns information about a glyph.
00095 // Author: pdaehne
00096 //----------------------------------------------------------------------
00097 const TextPixmapGlyph &TextPixmapFace::getPixmapGlyph(TextGlyph::Index glyphIndex)
00098 {
00099     if (glyphIndex == TextGlyph::INVALID_INDEX)
00100         return _emptyGlyph;
00101 
00102     // Try to find the glyph in the map of glyphs
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     // We did not find the glyph, so we have to create it
00111     auto_ptr<TextPixmapGlyph> glyph = createGlyph(glyphIndex);
00112 
00113     // We could not create the glyph, return the empty glyph
00114     if (glyph.get() == 0)
00115         return _emptyGlyph;
00116 
00117     // Put the glyph into the glyph cache
00118     _glyphMap.insert(GlyphMap::value_type(glyphIndex, glyph.get()));
00119 
00120     // Return the glyph
00121     return *(glyph.release());
00122 }
00123 
00124 
00125 //----------------------------------------------------------------------
00126 // Creates a texture image with the result of a layout operation
00127 // Author: pdaehne
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         // Put the glyphs into the texture
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 // Tries to create a pixmap face
00163 // Author: pdaehne
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 /*                              cvs id's                                  */
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

Generated on Thu Aug 25 04:11:18 2005 for OpenSG by  doxygen 1.4.3