Panda3D
config_text.cxx
1 // Filename: config_text.cxx
2 // Created by: drose (02Mar00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "config_text.h"
16 #include "staticTextFont.h"
17 #include "textFont.h"
18 #include "textGlyph.h"
19 #include "textNode.h"
20 #include "textProperties.h"
21 #include "dynamicTextFont.h"
22 #include "dynamicTextGlyph.h"
23 #include "dynamicTextPage.h"
24 #include "geomTextGlyph.h"
25 #include "geomTextGlyph.h"
26 #include "unicodeLatinMap.h"
27 #include "pandaSystem.h"
28 
29 #include "dconfig.h"
30 #include "config_express.h"
31 
32 Configure(config_text);
33 NotifyCategoryDef(text, "");
34 
35 ConfigureFn(config_text) {
36  init_libtext();
37 }
38 
39 ConfigVariableBool text_flatten
40 ("text-flatten", true,
41  PRC_DESC("Set this true to flatten text when it is generated, or false to "
42  "keep it as a deep hierarchy. Usually it's a performance "
43  "advantage to keep this true, but this also depends on the setting "
44  "of text-dynamic-merge. See TextNode::set_flatten_flags()."));
45 
46 ConfigVariableBool text_dynamic_merge
47 ("text-dynamic-merge", true,
48  PRC_DESC("Set this true to merge generated glyphs into the GeomVertexData "
49  "as the text is assembled, or false to wait for the flatten "
50  "operation. Usually it's a performance "
51  "advantage to keep this true. See TextNode::set_flatten_flags()."));
52 
53 ConfigVariableInt text_anisotropic_degree
54 ("text-anisotropic-degree", 1,
55  PRC_DESC("This is the default anisotropic-degree that is set on dynamic "
56  "font textures. Setting this to a value greater than 1 can help "
57  "smooth out the antialiasing for small letters."));
58 
59 ConfigVariableInt text_texture_margin
60 ("text-texture-margin", 2,
61  PRC_DESC("This is the number of texels of empty space reserved around each "
62  "glyph in the texture. Setting this value larger will decrease "
63  "the tendency for adjacent glyphs to bleed into each other at "
64  "small sizes, but it will increase amount of wasted texture "
65  "memory."));
66 
67 ConfigVariableDouble text_poly_margin
68 ("text-poly-margin", 0.0f,
69  PRC_DESC("This is the amount by which to make each glyph polygon larger "
70  "than strictly necessary, in screen units that are added to each "
71  "margin. Increasing this value will decrease the tendency for "
72  "letters to get chopped off at the edges, but it will also "
73  "increase the tendency for adjacent glyphs to bleed into each "
74  "other (unless you also increase text-texture-margin)."));
75 
76 ConfigVariableInt text_page_size
77 ("text-page-size", "256 256",
78  PRC_DESC("This is the default size for new textures created for dynamic "
79  "fonts."));
80 
81 ConfigVariableBool text_small_caps
82 ("text-small-caps", false,
83  PRC_DESC("This controls the default setting for "
84  "TextNode::set_small_caps()."));
85 
86 ConfigVariableDouble text_small_caps_scale
87 ("text-small-caps-scale", 0.8f,
88  PRC_DESC("This controls the default setting for "
89  "TextNode::set_small_caps_scale()."));
90 
91 ConfigVariableFilename text_default_font
92 ("text-default-font", "",
93  PRC_DESC("This names a filename that will be loaded at startup time as "
94  "the default font for any TextNode that does not specify a font "
95  "otherwise. The default is to use a special font that is "
96  "compiled into Panda, if available."));
97 
98 ConfigVariableDouble text_tab_width
99 ("text-tab-width", 5.0f,
100  PRC_DESC("This controls the default setting for "
101  "TextNode::set_tab_width()."));
102 
103 ConfigVariableInt text_push_properties_key
104 ("text-push-properties-key", 1,
105  PRC_DESC("This is the decimal character number that, embedded in "
106  "a string, is used to bracket the name of a TextProperties "
107  "structure added to the TextPropertiesManager object, to "
108  "control the appearance of subsequent text."));
109 
110 ConfigVariableInt text_pop_properties_key
111 ("text-pop-properties-key", 2,
112  PRC_DESC("This is the decimal character number that undoes the "
113  "effect of a previous appearance of text_push_properties_key."));
114 
115 ConfigVariableInt text_soft_hyphen_key
116 ("text-soft-hyphen-key", 3,
117  PRC_DESC("This is the decimal character number that, embedded in a "
118  "string, is identified as the soft-hyphen character."));
119 
120 ConfigVariableInt text_soft_break_key
121 ("text-soft-break-key", 4,
122  PRC_DESC("This is similar to text-soft-hyphen-key, except that "
123  "when it is used as a break point, no character is "
124  "introduced in its place."));
125 
126 ConfigVariableInt text_embed_graphic_key
127 ("text-embed-graphic-key", 5,
128  PRC_DESC("This is the decimal character number that, embedded in "
129  "a string, is used to bracket the name of a model "
130  "added to the TextPropertiesManager object, to "
131  "embed an arbitrary graphic image within a paragraph."));
132 
133 wstring
134 get_text_soft_hyphen_output() {
135  static wstring *text_soft_hyphen_output = NULL;
136  static ConfigVariableString
137  cv("text-soft-hyphen-output", "-",
138  PRC_DESC("This is the string that is output, encoded in the default "
139  "encoding, to represent the hyphen character that is "
140  "introduced when the line is broken at a soft-hyphen key."));
141 
142  if (text_soft_hyphen_output == NULL) {
143  TextEncoder encoder;
144  text_soft_hyphen_output = new wstring(encoder.decode_text(cv));
145  }
146 
147  return *text_soft_hyphen_output;
148 }
149 
150 ConfigVariableDouble text_hyphen_ratio
151 ("text-hyphen-ratio", 0.7,
152  PRC_DESC("If the rightmost whitespace character falls before this "
153  "fraction of the line, hyphenate a word to the right of that "
154  "if possible."));
155 
156 wstring
157 get_text_never_break_before() {
158  static wstring *text_never_break_before = NULL;
159  static ConfigVariableString
160  cv("text-never-break-before", ",.-:?!;",
161  PRC_DESC("This string represents a list of individual characters "
162  "that should never appear at the beginning of a line "
163  "following a forced break. Typically these will be "
164  "punctuation characters."));
165 
166  if (text_never_break_before == NULL) {
167  TextEncoder encoder;
168  text_never_break_before = new wstring(encoder.decode_text(cv));
169  }
170 
171  return *text_never_break_before;
172 }
173 
174 ConfigVariableInt text_max_never_break
175 ("text-max-never-break", 3,
176  PRC_DESC("If we have more than this number of text-never-break-before "
177  "characters in a row, do not treat any of them as special and "
178  "instead break the line wherever we can."));
179 
180 ConfigVariableDouble text_default_underscore_height
181 ("text-default-underscore-height", -0.2,
182  PRC_DESC("Specifies the default height of the underscore line, relative "
183  "to the text baseline, when underscoring is enabled."));
184 
186 ("text-minfilter", SamplerState::FT_linear,
187  PRC_DESC("The default texture minfilter type for dynamic text fonts"));
189 ("text-magfilter", SamplerState::FT_linear,
190  PRC_DESC("The default texture magfilter type for dynamic text fonts"));
192 ("text-wrap-mode", SamplerState::WM_border_color,
193  PRC_DESC("The default wrap mode for dynamic text fonts"));
195 ("text-quality-level", Texture::QL_best,
196  PRC_DESC("The default quality level for dynamic text fonts; see Texture::set_quality_level()."));
197 
199 ("text-render-mode", TextFont::RM_texture,
200  PRC_DESC("The default render mode for dynamic text fonts"));
201 
202 
203 
204 ////////////////////////////////////////////////////////////////////
205 // Function: init_libtext
206 // Description: Initializes the library. This must be called at
207 // least once before any of the functions or classes in
208 // this library can be used. Normally it will be
209 // called by the static initializers and need not be
210 // called explicitly, but special cases exist.
211 ////////////////////////////////////////////////////////////////////
212 void
213 init_libtext() {
214  static bool initialized = false;
215  if (initialized) {
216  return;
217  }
218  initialized = true;
219 
220  StaticTextFont::init_type();
221  TextFont::init_type();
222  TextGlyph::init_type();
223  TextNode::init_type();
224  TextProperties::init_type();
225 
226 #ifdef HAVE_FREETYPE
227  DynamicTextFont::init_type();
228  DynamicTextGlyph::init_type();
229  DynamicTextPage::init_type();
230  GeomTextGlyph::init_type();
231  GeomTextGlyph::init_type();
232 
235 
237  ps->add_system("Freetype");
238 #endif
239 }
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
This class is used as a namespace to group several global properties of Panda.
Definition: pandaSystem.h:29
This class can be used to convert text between multiple representations, e.g.
Definition: textEncoder.h:37
This is a convenience class to specialize ConfigVariable as a Filename type.
This is a convenience class to specialize ConfigVariable as a boolean type.
wstring decode_text(const string &text) const
Returns the given wstring decoded to a single-byte string, via the current encoding system...
Definition: textEncoder.I:568
void add_system(const string &system)
Intended for use by each subsystem to register itself at startup.
This is a convenience class to specialize ConfigVariable as a floating-point type.
This is a convenience class to specialize ConfigVariable as a string type.
This class specializes ConfigVariable as an enumerated type.
This is a convenience class to specialize ConfigVariable as an integer type.
static void register_with_read_factory()
Tells the BamReader how to create objects of type Geom.
Definition: geom.cxx:1671