1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #include "OSGTextPixmapGlyph.h"
44 //----------------------------------------------------------------------
47 //----------------------------------------------------------------------
48 TextPixmapGlyph::~TextPixmapGlyph(void)
54 //----------------------------------------------------------------------
55 // Returns the width of the glyph
57 //----------------------------------------------------------------------
58 Real32
TextPixmapGlyph::getWidth(void) const
60 return static_cast<Real32
>(_width
);
63 //----------------------------------------------------------------------
64 // Returns the height of the glyph
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
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
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
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
102 //----------------------------------------------------------------------
103 Real32
TextPixmapGlyph::getVertBearingY(void) const
105 return static_cast<Real32
>(_vertBearingY
);
108 //----------------------------------------------------------------------
109 // Copies the glyph pixmap into a texture
111 //----------------------------------------------------------------------
112 void TextPixmapGlyph::putPixmap(Int32 x
, Int32 y
, UInt8
*tex
,
113 UInt32 width
, UInt32 height
) const
117 // Clip the glyph at the left border of the texture
119 int glyphWidth
= _width
;
125 delta
= left
- delta
;
132 // Clip the glyph at the right border of the texture
135 if (delta
< glyphWidth
)
138 // Clip the glyph at the bottom border of the texture
140 int glyphHeight
= _height
;
144 delta
= bottom
- delta
;
145 src
+= delta
* _pitch
;
146 glyphHeight
-= delta
;
149 dst
+= delta
* width
;
151 // Clip the glyph at the top border of the texture
153 delta
= top
- y
/*- _horiBearingY*/;
155 glyphHeight
+= delta
;
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);
175 //----------------------------------------------------------------------
176 // Flips the glyph pixmap around the x axis
178 //----------------------------------------------------------------------
179 void TextPixmapGlyph::flipPixmap(void)
183 unsigned char *ptr1
= _pixmap
;
184 unsigned char *ptr2
= _pixmap
+ _pitch
* (_height
- 1);
186 for (y
= _height
>> 1; y
> 0; --y
)
188 for (x
= 0; x
< _width
; ++x
)
190 unsigned char h
= ptr1
[x
];