15 #include "textProperties.h"
16 #include "config_text.h"
17 #include "default_font.h"
18 #include "dynamicTextFont.h"
19 #include "staticTextFont.h"
37 _small_caps = text_small_caps;
38 _small_caps_scale = text_small_caps_scale;
41 _underscore_height = 0.0f;
44 _wordwrap_width = 0.0f;
45 _preserve_trailing_whitespace =
false;
46 _text_color.set(1.0f, 1.0f, 1.0f, 1.0f);
47 _shadow_color.set(0.0f, 0.0f, 0.0f, 1.0f);
48 _shadow_offset.set(0.0f, 0.0f);
50 _tab_width = text_tab_width;
62 TextProperties(
const TextProperties ©) {
72 operator = (
const TextProperties ©) {
73 _specified = copy._specified;
76 _small_caps = copy._small_caps;
77 _small_caps_scale = copy._small_caps_scale;
79 _underscore = copy._underscore;
80 _underscore_height = copy._underscore_height;
82 _indent_width = copy._indent_width;
83 _wordwrap_width = copy._wordwrap_width;
84 _preserve_trailing_whitespace = copy._preserve_trailing_whitespace;
85 _text_color = copy._text_color;
86 _shadow_color = copy._shadow_color;
87 _shadow_offset = copy._shadow_offset;
89 _draw_order = copy._draw_order;
90 _tab_width = copy._tab_width;
91 _glyph_scale = copy._glyph_scale;
92 _glyph_shift = copy._glyph_shift;
93 _text_scale = copy._text_scale;
101 bool TextProperties::
102 operator == (
const TextProperties &other)
const {
103 if (_specified != other._specified) {
107 if ((_specified & F_has_font) && _font != other._font) {
110 if ((_specified & F_has_small_caps) && _small_caps != other._small_caps) {
113 if ((_specified & F_has_small_caps_scale) && _small_caps_scale != other._small_caps_scale) {
116 if ((_specified & F_has_slant) && _slant != other._slant) {
119 if ((_specified & F_has_underscore) && _underscore != other._underscore) {
122 if ((_specified & F_has_underscore_height) && _underscore_height != other._underscore_height) {
125 if ((_specified & F_has_align) && _align != other._align) {
128 if ((_specified & F_has_indent) && _indent_width != other._indent_width) {
131 if ((_specified & F_has_wordwrap) && _wordwrap_width != other._wordwrap_width) {
134 if ((_specified & F_has_preserve_trailing_whitespace) && _preserve_trailing_whitespace != other._preserve_trailing_whitespace) {
137 if ((_specified & F_has_text_color) && _text_color != other._text_color) {
140 if ((_specified & F_has_text_color) && _text_color != other._text_color) {
143 if ((_specified & F_has_shadow_color) && _shadow_color != other._shadow_color) {
146 if ((_specified & F_has_shadow) && _shadow_offset != other._shadow_offset) {
149 if ((_specified & F_has_bin) && _bin != other._bin) {
152 if ((_specified & F_has_draw_order) && _draw_order != other._draw_order) {
155 if ((_specified & F_has_tab_width) && _tab_width != other._tab_width) {
158 if ((_specified & F_has_glyph_scale) && _glyph_scale != other._glyph_scale) {
161 if ((_specified & F_has_glyph_shift) && _glyph_shift != other._glyph_shift) {
164 if ((_specified & F_has_text_scale) && _text_scale != other._text_scale) {
179 (*this) = TextProperties();
191 if (other.has_font()) {
194 if (other.has_small_caps()) {
198 if (other.has_slant()) {
201 if (other.has_underscore()) {
204 if (other.has_underscore_height()) {
207 if (other.has_align()) {
210 if (other.has_indent()) {
213 if (other.has_wordwrap()) {
216 if (other.has_text_color()) {
217 set_text_color(other.get_text_color());
219 if (other.has_shadow_color()) {
220 set_shadow_color(other.get_shadow_color());
222 if (other.has_shadow()) {
228 if (other.has_draw_order()) {
231 if (other.has_tab_width()) {
238 if (other.has_glyph_shift()) {
241 if (other.has_glyph_scale()) {
245 if (other.has_text_scale()) {
256 void TextProperties::
257 write(ostream &out,
int indent_level)
const {
259 indent(out, indent_level)
260 <<
"default properties\n";
264 indent(out, indent_level)
265 <<
"with font " << _font->get_name() <<
"\n";
267 indent(out, indent_level)
268 <<
"with NULL font\n";
271 if (has_small_caps()) {
272 indent(out, indent_level)
275 if (has_small_caps_scale()) {
276 indent(out, indent_level)
280 indent(out, indent_level)
283 if (has_underscore()) {
284 indent(out, indent_level)
287 if (has_underscore_height()) {
288 indent(out, indent_level)
293 indent(out, indent_level)
295 switch (get_align()) {
309 out <<
"A_boxed_left\n";
313 out <<
"A_boxed_right\n";
317 out <<
"A_boxed_center\n";
323 indent(out, indent_level)
324 <<
"indent at " << get_indent() <<
" units.\n";
327 if (has_wordwrap()) {
328 indent(out, indent_level)
329 <<
"word-wrapping at " << get_wordwrap() <<
" units.\n";
332 if (has_text_color()) {
333 indent(out, indent_level)
334 <<
"text color is " << get_text_color() <<
"\n";
338 indent(out, indent_level)
341 if (has_shadow_color()) {
342 indent(out, indent_level)
343 <<
"shadow color is " << get_shadow_color() <<
"\n";
347 indent(out, indent_level)
348 <<
"bin is " <<
get_bin() <<
"\n";
350 if (has_draw_order()) {
351 indent(out, indent_level)
355 if (has_tab_width()) {
356 indent(out, indent_level)
360 if (has_glyph_scale()) {
361 indent(out, indent_level)
364 if (has_glyph_shift()) {
365 indent(out, indent_level)
369 if (has_text_scale()) {
370 indent(out, indent_level)
385 void TextProperties::
386 load_default_font() {
387 _loaded_default_font =
true;
389 if (!text_default_font.empty()) {
392 if (_default_font != (
TextFont *)NULL && _default_font->is_valid()) {
398 #ifdef COMPILE_IN_DEFAULT_FONT
401 _default_font =
new DynamicTextFont((
const char *)default_font_data,
402 default_font_size, 0);
404 ((DynamicTextFont *)_default_font.p())->set_winding_order(DynamicTextFont::WO_left);
409 string data((
const char *)default_font_data, default_font_size);
414 IDecompressStream in(&inz,
false);
422 if (bam_file.
open_read(in,
"default font stream")) {
423 PT(
PandaNode) node = bam_file.read_node();
429 #endif // HAVE_FREETYPE
430 #endif // COMPILE_IN_DEFAULT_FONT
The principle public interface to reading and writing Bam disk files.
A basic node of the scene graph or data graph.
void set_shadow(PN_stdfloat xoffset, PN_stdfloat yoffset)
Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offs...
bool open_read(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated filename for reading.
void set_font(TextFont *font)
Sets the font that will be used when making text.
PN_stdfloat get_glyph_scale() const
Returns the scale factor of each letter as specified by set_glyph_scale().
void add_properties(const TextProperties &other)
Sets any properties that are explicitly specified in other on this object.
PN_stdfloat get_glyph_shift() const
Returns the vertical shift of each letter as specified by set_glyph_shift().
void set_align(Alignment align_type)
Specifies the alignment of the text within its margins.
void set_underscore_height(PN_stdfloat underscore_height)
Specifies the vertical height of the underscore, relative to the text baseline.
void set_glyph_scale(PN_stdfloat glyph_scale)
Specifies the factor by which to scale each letter of the text as it is placed, in addition to any sc...
void set_bin(const string &bin)
Names the CullBin that the text geometry should be assigned to.
PN_stdfloat get_slant() const
Returns the factor by which the text is specified to slant to the right.
bool is_any_specified() const
Returns true if any properties have been specified, false otherwise.
void set_text_scale(PN_stdfloat text_scale)
Specifies the factor by which to scale the text, in addition to any scalings imposed by the node...
Filename get_value() const
Returns the variable's value.
PN_stdfloat get_text_scale() const
Returns the scale factor of the text as specified by set_text_scale().
void set_small_caps(bool small_caps)
Sets the small_caps flag.
An encapsulation of a font; i.e.
A StaticTextFont is loaded up from a model that was previously generated via egg-mkfont, and contains all of its glyphs already generated and available for use.
bool has_bin() const
Returns true if an explicit drawing bin has been set via set_bin(), false otherwise.
void set_wordwrap(PN_stdfloat wordwrap)
Sets the text up to automatically wordwrap when it exceeds the indicated width.
void set_small_caps_scale(PN_stdfloat small_caps_scale)
Sets the scale factor applied to lowercase letters from their uppercase equivalents, when the small_caps flag is in effect.
void set_slant(PN_stdfloat slant)
Specifies the factor by which the text slants to the right.
PN_stdfloat get_small_caps_scale() const
Returns the scale factor applied to lowercase letters from their uppercase equivalents, when the small_caps flag is in effect.
bool get_underscore() const
Returns the underscore flag.
int set_draw_order(int draw_order)
Sets the drawing order of text created by the TextNode.
void set_indent(PN_stdfloat indent)
Specifies the amount of extra space that is inserted before the first character of each line...
void set_underscore(bool underscore)
Sets the underscore flag.
const string & get_bin() const
Returns the drawing bin set with set_bin(), or empty string if no bin has been set.
static TextFont * load_font(const string &filename)
Loads the given filename up into a font, if it has not already been loaded, and returns the new font...
TextFont * get_font() const
Returns the font currently in use, if any.
void clear()
Unsets all properties that have been specified so far, and resets the TextProperties structure to its...
PN_stdfloat get_tab_width() const
Returns the width set via set_tab_width().
This defines the set of visual properties that may be assigned to the individual characters of the te...
TypeHandle is the identifier used to differentiate C++ class types.
void set_glyph_shift(PN_stdfloat glyph_shift)
Specifies a vertical amount to shift each letter of the text as it is placed.
void set_tab_width(PN_stdfloat tab_width)
Sets the width of each tab stop, in screen units.
LVector2 get_shadow() const
Returns the offset of the shadow as set by set_shadow().
int get_draw_order() const
Returns the drawing order set with set_draw_order().
PN_stdfloat get_underscore_height() const
Returns the vertical height of the underscore; see set_underscore_height().
bool get_small_caps() const
Returns the small_caps flag.