Panda3D

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