|
From: <br...@us...> - 2010-05-02 23:59:46
|
Revision: 4137
http://openvrml.svn.sourceforge.net/openvrml/?rev=4137&view=rev
Author: braden
Date: 2010-05-02 23:59:40 +0000 (Sun, 02 May 2010)
Log Message:
-----------
Delegate the logic to get the pen start position to a helper function; pass the start position to the line_geometry constructor.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/node/vrml97/text.cpp
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-05-02 22:18:48 UTC (rev 4136)
+++ trunk/ChangeLog 2010-05-02 23:59:40 UTC (rev 4137)
@@ -1,5 +1,22 @@
2010-05-02 Braden McDaniel <br...@en...>
+ Delegate the logic to get the pen start position to a helper
+ function; pass the start position to the line_geometry
+ constructor.
+
+ * src/node/vrml97/text.cpp
+ (text_node::line_geometry::line_geometry(bool, bool, bool, const
+ openvrml::vec2f &)): Get the pen start position from the calling
+ context.
+ (get_pen_start_for_line(std::size_t, float, float, bool, bool,
+ bool)): Factored logic to determine the starting position for the
+ "pen" on a line from text_node::update_geometry.
+ (text_node::update_geometry()): Call get_pen_start_for_line to get
+ the pen start position for a line; pass this to the line_geometry
+ constructor.
+
+2010-05-02 Braden McDaniel <br...@en...>
+
Refactor some of the Text node rendering logic. Move logic
previously in text_node::update_geometry to members of the
text_node::text_geometry class.
Modified: trunk/src/node/vrml97/text.cpp
===================================================================
--- trunk/src/node/vrml97/text.cpp 2010-05-02 22:18:48 UTC (rev 4136)
+++ trunk/src/node/vrml97/text.cpp 2010-05-02 23:59:40 UTC (rev 4137)
@@ -161,7 +161,8 @@
public:
line_geometry(bool horizontal,
bool left_to_right,
- bool top_to_bottom);
+ bool top_to_bottom,
+ const openvrml::vec2f & pen_start);
const std::vector<openvrml::vec2f> & coord() const;
const std::vector<openvrml::int32> & coord_index() const;
@@ -1408,16 +1409,18 @@
* @param[in] top_to_bottom @c true if text is being rendered top-to-bottom;
* @c false if text is being rendered bottom-to-
* top.
+ * @param[in] pen_start starting position for the "pen".
*/
text_node::line_geometry::line_geometry(const bool horizontal,
const bool left_to_right,
- const bool top_to_bottom):
+ const bool top_to_bottom,
+ const openvrml::vec2f & pen_start):
horizontal_(horizontal),
left_to_right_(left_to_right),
top_to_bottom_(top_to_bottom),
x_min_(0), x_max_(0), y_min_(0), y_max_(0),
polygons_(0),
- pen_pos_(openvrml::make_vec2f())
+ pen_pos_(pen_start)
{}
const std::vector<openvrml::vec2f> & text_node::line_geometry::coord() const
@@ -2525,6 +2528,24 @@
# endif // OPENVRML_ENABLE_RENDER_TEXT_NODE
}
+ const openvrml::vec2f get_pen_start_for_line(const std::size_t line_num,
+ const float size,
+ const float spacing,
+ const bool horizontal,
+ const bool left_to_right,
+ const bool top_to_bottom)
+ {
+ const float line_advance = size * spacing * line_num;
+
+ openvrml::vec2f pen_pos = openvrml::make_vec2f();
+ if (horizontal) {
+ pen_pos.y(top_to_bottom ? -line_advance : line_advance);
+ } else {
+ pen_pos.x(left_to_right ? line_advance : -line_advance);
+ }
+ return pen_pos;
+ }
+
/**
* @brief Called to update @a text_geometry.
*
@@ -2574,28 +2595,20 @@
for (ucs4_string_t::const_iterator string = stringBegin;
string != this->ucs4_string.end();
++string) {
- float penPos[2] = { 0.0, 0.0 };
const size_t line = std::distance(stringBegin, string);
- const float lineAdvance = size * spacing * line;
- if (horizontal) {
- if (topToBottom) {
- penPos[1] -= lineAdvance;
- } else {
- penPos[1] += lineAdvance;
- }
- } else {
- if (leftToRight) {
- penPos[0] += lineAdvance;
- } else {
- penPos[0] -= lineAdvance;
- }
- }
+ const vec2f pen_start = get_pen_start_for_line(line,
+ size,
+ spacing,
+ horizontal,
+ leftToRight,
+ topToBottom);
using openvrml::int32;
auto_ptr<line_geometry> line_geom(new line_geometry(horizontal,
leftToRight,
- topToBottom));
+ topToBottom,
+ pen_start));
for (vector<char32_t>::const_iterator character = string->begin();
character != string->end(); ++character) {
assert(this->face);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|