Panda3D
dynamicTextGlyph.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file dynamicTextGlyph.cxx
10  * @author drose
11  * @date 2002-02-09
12  */
13 
14 #include "dynamicTextGlyph.h"
15 
16 #ifdef HAVE_FREETYPE
17 
18 #include "dynamicTextFont.h"
19 #include "dynamicTextPage.h"
20 #include "geomTextGlyph.h"
21 #include "geomVertexData.h"
22 #include "geomVertexFormat.h"
23 #include "geomTriangles.h"
24 #include "geomVertexWriter.h"
25 #include "textureAttrib.h"
26 #include "transparencyAttrib.h"
27 #include "colorAttrib.h"
28 #include "renderState.h"
29 #include "config_gobj.h"
30 
31 TypeHandle DynamicTextGlyph::_type_handle;
32 
33 /**
34  *
35  */
36 DynamicTextGlyph::
37 ~DynamicTextGlyph() {
38 }
39 
40 /**
41  * Returns a pointer to the first byte in the pixel buffer associated with the
42  * leftmost pixel in the indicated row, where 0 is the topmost row and _y_size
43  * - _margin * 2 - 1 is the bottommost row.
44  */
45 unsigned char *DynamicTextGlyph::
46 get_row(int y) {
47  nassertr(y >= 0 && y < _y_size - _margin * 2, nullptr);
48  nassertr(_page != nullptr, nullptr);
49 
50  // First, offset y by the glyph's start.
51  y += _y + _margin;
52  // Also, get the x start.
53  int x = _x + _margin;
54 
55  // Invert y.
56  y = _page->get_y_size() - 1 - y;
57 
58  int offset = (y * _page->get_x_size()) + x;
59  int pixel_width = _page->get_num_components() * _page->get_component_width();
60 
61  return _page->modify_ram_image() + offset * pixel_width;
62 }
63 
64 /**
65  * Erases the glyph from the texture map.
66  */
67 void DynamicTextGlyph::
68 erase(DynamicTextFont *font) {
69  nassertv(_page != nullptr);
70  nassertv(_page->has_ram_image());
71 
72  // The glyph covers the pixels from (_x, _y) over the rectangle (_x_size,
73  // _y_size), but it doesn't include _margin pixels around the interior of
74  // the rectangle. Erase all the pixels that the glyph covers.
75  _page->fill_region(_x + _margin,
76  _page->get_y_size() - (_y + _y_size - _margin),
77  _x_size - _margin * 2, _y_size - _margin * 2,
78  font->get_bg());
79 }
80 
81 /**
82  * Returns true if this glyph represents invisible whitespace, or false if it
83  * corresponds to some visible character.
84  */
85 bool DynamicTextGlyph::
86 is_whitespace() const {
87  return (_page == nullptr);
88 }
89 
90 #endif // HAVE_FREETYPE
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.