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 #include "OSGTextPixmapGlyph.h" 00040 00041 00042 using namespace std; 00043 00044 00045 OSG_BEGIN_NAMESPACE 00046 00047 00048 //---------------------------------------------------------------------- 00049 // Destructor 00050 // Author: pdaehne 00051 //---------------------------------------------------------------------- 00052 TextPixmapGlyph::~TextPixmapGlyph() 00053 { delete [] _pixmap; } 00054 00055 00056 //---------------------------------------------------------------------- 00057 // Returns the width of the glyph 00058 // Author: pdaehne 00059 //---------------------------------------------------------------------- 00060 Real32 TextPixmapGlyph::getWidth() const 00061 { return static_cast<Real32>(_width); } 00062 00063 00064 //---------------------------------------------------------------------- 00065 // Returns the height of the glyph 00066 // Author: pdaehne 00067 //---------------------------------------------------------------------- 00068 Real32 TextPixmapGlyph::getHeight() const 00069 { return static_cast<Real32>(_height); } 00070 00071 00072 //---------------------------------------------------------------------- 00073 // Returns the x bearing of the glyph for horizontal layout 00074 // Author: pdaehne 00075 //---------------------------------------------------------------------- 00076 Real32 TextPixmapGlyph::getHoriBearingX() const 00077 { return static_cast<Real32>(_horiBearingX); } 00078 00079 00080 //---------------------------------------------------------------------- 00081 // Returns the y bearing of the glyph for horizontal layout 00082 // Author: pdaehne 00083 //---------------------------------------------------------------------- 00084 Real32 TextPixmapGlyph::getHoriBearingY() const 00085 { return static_cast<Real32>(_horiBearingY); } 00086 00087 00088 //---------------------------------------------------------------------- 00089 // Returns the x bearing of the glyph for vertical layout 00090 // Author: pdaehne 00091 //---------------------------------------------------------------------- 00092 Real32 TextPixmapGlyph::getVertBearingX() const 00093 { return static_cast<Real32>(_vertBearingX); } 00094 00095 00096 //---------------------------------------------------------------------- 00097 // Returns the y bearing of the glyph for vertical layout 00098 // Author: pdaehne 00099 //---------------------------------------------------------------------- 00100 Real32 TextPixmapGlyph::getVertBearingY() const 00101 { return static_cast<Real32>(_vertBearingY); } 00102 00103 00104 //---------------------------------------------------------------------- 00105 // Copies the glyph pixmap into a texture 00106 // Author: pdaehne 00107 //---------------------------------------------------------------------- 00108 void TextPixmapGlyph::putPixmap(Int32 x, Int32 y, UInt8 *tex, 00109 UInt32 width, UInt32 height) const 00110 { 00111 if (_pixmap != 0) 00112 { 00113 // Clip the glyph at the left border of the texture 00114 int left = 0; 00115 int glyphWidth = _width; 00116 int src = 0; 00117 int dst = 0; 00118 int delta = x; 00119 if (delta < left) 00120 { 00121 delta = left - delta; 00122 src += delta; 00123 glyphWidth -= delta; 00124 delta = left; 00125 } 00126 dst += delta; 00127 00128 // Clip the glyph at the right border of the texture 00129 int right = width; 00130 delta = right - dst; 00131 if (delta < glyphWidth) 00132 glyphWidth = delta; 00133 00134 // Clip the glyph at the bottom border of the texture 00135 int bottom = 0; 00136 int glyphHeight = _height; 00137 delta = y - _height; 00138 if (delta < bottom) 00139 { 00140 delta = bottom - delta; 00141 src += delta * _pitch; 00142 glyphHeight -= delta; 00143 delta = bottom; 00144 } 00145 dst += delta * width; 00146 00147 // Clip the glyph at the top border of the texture 00148 int top = height; 00149 delta = top - y /*- _horiBearingY*/; 00150 if (delta < 0) 00151 glyphHeight += delta; 00152 00153 int xi, yi; 00154 for (yi = glyphHeight; yi > 0; --yi) 00155 { 00156 unsigned char *srcPtr = &(_pixmap[src]); 00157 unsigned char *dstPtr = &(tex[dst]); 00158 for (xi = glyphWidth; xi > 0; --xi) 00159 { 00160 unsigned char p = 255 - ((255 - *dstPtr) * (255 - *srcPtr) / 255); 00161 *dstPtr++ = p; 00162 srcPtr++; 00163 } 00164 src += _pitch; 00165 dst += width; 00166 } 00167 } 00168 } 00169 00170 00171 //---------------------------------------------------------------------- 00172 // Flips the glyph pixmap around the x axis 00173 // Author: pdaehne 00174 //---------------------------------------------------------------------- 00175 void TextPixmapGlyph::flipPixmap() 00176 { 00177 if (_pixmap == 0) 00178 return; 00179 unsigned char *ptr1 = _pixmap; 00180 unsigned char *ptr2 = _pixmap + _pitch * (_height - 1); 00181 unsigned int x, y; 00182 for (y = _height >> 1; y > 0; --y) 00183 { 00184 for (x = 0; x < _width; ++x) 00185 { 00186 unsigned char h = ptr1[x]; 00187 ptr1[x] = ptr2[x]; 00188 ptr2[x] = h; 00189 } 00190 ptr1 += _pitch; 00191 ptr2 -= _pitch; 00192 } 00193 } 00194 00195 00196 OSG_END_NAMESPACE 00197 00198 00199 /*------------------------------------------------------------------------*/ 00200 /* cvs id's */ 00201 00202 #ifdef OSG_SGI_CC 00203 #pragma set woff 1174 00204 #endif 00205 00206 #ifdef OSG_LINUX_ICC 00207 #pragma warning( disable : 177 ) 00208 #endif 00209 00210 namespace 00211 { 00212 static OSG::Char8 cvsid_cpp[] = "@(#)$Id: OSGTextPixmapGlyph.cpp,v 1.1 2005/03/03 13:43:07 a-m-z Exp $"; 00213 static OSG::Char8 cvsid_hpp[] = OSGTEXTPIXMAPGLYPH_HEADER_CVSID; 00214 static OSG::Char8 cvsid_inl[] = OSGTEXTPIXMAPGLYPH_INLINE_CVSID; 00215 } 00216 00217 #ifdef __sgi 00218 #pragma reset woff 1174 00219 #endif
1.5.5