fixed: let the material fill the override chunk block
[opensg.git] / Source / System / Text / OSGTextPixmapGlyph.cpp
blob960b5d483d10f2da2962e7dbe3df81895200c736
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include "OSGTextPixmapGlyph.h"
41 OSG_BEGIN_NAMESPACE
44 //----------------------------------------------------------------------
45 // Destructor
46 // Author: pdaehne
47 //----------------------------------------------------------------------
48 TextPixmapGlyph::~TextPixmapGlyph(void)
50 delete [] _pixmap;
54 //----------------------------------------------------------------------
55 // Returns the width of the glyph
56 // Author: pdaehne
57 //----------------------------------------------------------------------
58 Real32 TextPixmapGlyph::getWidth(void) const
60 return static_cast<Real32>(_width);
63 //----------------------------------------------------------------------
64 // Returns the height of the glyph
65 // Author: pdaehne
66 //----------------------------------------------------------------------
67 Real32 TextPixmapGlyph::getHeight(void) const
69 return static_cast<Real32>(_height);
72 //----------------------------------------------------------------------
73 // Returns the x bearing of the glyph for horizontal layout
74 // Author: pdaehne
75 //----------------------------------------------------------------------
76 Real32 TextPixmapGlyph::getHoriBearingX(void) const
78 return static_cast<Real32>(_horiBearingX);
81 //----------------------------------------------------------------------
82 // Returns the y bearing of the glyph for horizontal layout
83 // Author: pdaehne
84 //----------------------------------------------------------------------
85 Real32 TextPixmapGlyph::getHoriBearingY(void) const
87 return static_cast<Real32>(_horiBearingY);
90 //----------------------------------------------------------------------
91 // Returns the x bearing of the glyph for vertical layout
92 // Author: pdaehne
93 //----------------------------------------------------------------------
94 Real32 TextPixmapGlyph::getVertBearingX(void) const
96 return static_cast<Real32>(_vertBearingX);
99 //----------------------------------------------------------------------
100 // Returns the y bearing of the glyph for vertical layout
101 // Author: pdaehne
102 //----------------------------------------------------------------------
103 Real32 TextPixmapGlyph::getVertBearingY(void) const
105 return static_cast<Real32>(_vertBearingY);
108 //----------------------------------------------------------------------
109 // Copies the glyph pixmap into a texture
110 // Author: pdaehne
111 //----------------------------------------------------------------------
112 void TextPixmapGlyph::putPixmap(Int32 x, Int32 y, UInt8 *tex,
113 UInt32 width, UInt32 height) const
115 if (_pixmap != 0)
117 // Clip the glyph at the left border of the texture
118 int left = 0;
119 int glyphWidth = _width;
120 int src = 0;
121 int dst = 0;
122 int delta = x;
123 if (delta < left)
125 delta = left - delta;
126 src += delta;
127 glyphWidth -= delta;
128 delta = left;
130 dst += delta;
132 // Clip the glyph at the right border of the texture
133 int right = width;
134 delta = right - dst;
135 if (delta < glyphWidth)
136 glyphWidth = delta;
138 // Clip the glyph at the bottom border of the texture
139 int bottom = 0;
140 int glyphHeight = _height;
141 delta = y - _height;
142 if (delta < bottom)
144 delta = bottom - delta;
145 src += delta * _pitch;
146 glyphHeight -= delta;
147 delta = bottom;
149 dst += delta * width;
151 // Clip the glyph at the top border of the texture
152 int top = height;
153 delta = top - y /*- _horiBearingY*/;
154 if (delta < 0)
155 glyphHeight += delta;
157 int xi, yi;
158 for (yi = glyphHeight; yi > 0; --yi)
160 unsigned char *srcPtr = &(_pixmap[src]);
161 unsigned char *dstPtr = &(tex[dst]);
162 for (xi = glyphWidth; xi > 0; --xi)
164 unsigned char p = 255 - ((255 - *dstPtr) * (255 - *srcPtr) / 255);
165 *dstPtr++ = p;
166 srcPtr++;
168 src += _pitch;
169 dst += width;
175 //----------------------------------------------------------------------
176 // Flips the glyph pixmap around the x axis
177 // Author: pdaehne
178 //----------------------------------------------------------------------
179 void TextPixmapGlyph::flipPixmap(void)
181 if (_pixmap == 0)
182 return;
183 unsigned char *ptr1 = _pixmap;
184 unsigned char *ptr2 = _pixmap + _pitch * (_height - 1);
185 unsigned int x, y;
186 for (y = _height >> 1; y > 0; --y)
188 for (x = 0; x < _width; ++x)
190 unsigned char h = ptr1[x];
191 ptr1[x] = ptr2[x];
192 ptr2[x] = h;
194 ptr1 += _pitch;
195 ptr2 -= _pitch;
200 OSG_END_NAMESPACE