Application of Agg::trans_single_path Rendering text

Source: Internet
Author: User

I ' m using antigrain in a mapping application and am drawing  Road names bent to the shape of the road. i have 2  questions that have stumped me ... 1. some of my lines have points off screen and are  easily clipped for drawing the line. however, when i draw  The text i want it centered on only the visible portion  of the line. really all i want to do is start the  text at a certain offset in the trans_single_path variable  But i couldn ' T work out how to do that. any pointers or  alternate approaches would be greatly appreciated.2. on tight curves the text is stretched and sometimes  looks really odd  (http://www.compsof.com.au/textbending. GIF) . i understand it is not simple to draw text on  Tight angles but i was hoping someone had some pointers on  how to make it look a bit better.


Answer:

your first question is easy. trans_single_path accepts coordinates  With respect of the x axis. that is, you draw horizontal  text alongf x and it ' S eventually transformed. the coordinates   (x,0)  will lie on the curve  (polyline).  positive ys will  be on the left, negative - on the right. that ' S it.  you only need to center text along y=0.the second question  is more difficult. yes, i must admit trans_single_path might  be not the best way to draw. probably you need to  calculate the orientation and position of each letter and  Apply the affine transformation to the whole glyph. trans_single_path has a standard  Interface, void transform (double* x, double* y).  but it shouldn ' t  be in the general pipeline.

recently I ' ve been working with Agg::trans_single_path to draw text along
some agg::p ath_storage. Finally I did it but I ' ve noticed some strange
behaviour. Here ' s a description.
When I try to draw the text along path_storage with only 3 vertices, for
Example:
ps.move_to (+);
ps.line_to (a);
ps.line_to (a);


When I add some vertices:
ps.move_to (+);
ps.line_to (a);
ps.line_to (a);
ps.line_to (a);
The one before last was being ignored in calculations (


After short the I ' ve found out of that ' s because some code in void
Trans_single_path::finalize_path () which I do not understand:
if (M_src_vertices.size () > 2) {
if (m_src_vertices[m_src_vertices.size ()-2].dist * 10.0 <
m_src_vertices[m_src_vertices.size ()-3].dist) {
d = m_src_vertices[m_src_vertices.size ()-3].dist +
m_src_vertices[m_src_vertices.size ()-2].dist;
m_src_vertices[m_src_vertices.size ()-2] =
m_src_vertices[m_src_vertices.size ()-1];
m_src_vertices.remove_last ();
m_src_vertices[m_src_vertices.size ()-2].dist = D;
}}
commenting out those lines resolves described problems but I ' m not sure if
It's the right of the solving them.

This code protects us from have a very short last segment. When I was
experimenting, the last line segment sometimes is so short that tangent
calculation resulted in considerable inaccuracy. The meaning is that "if the
length of the last line segment are less than 1/10th of the previous one, we
Remove the previous ". And the bug was, this condition always worked. A
Quick fix is to put "m_src_vertices.close (false);" Before this "if".
Similarly, in Agg_trans_double_path.cpp

But I ' m still not sure if this protection makes sense. Or, maybe, this
"Tolerance" must is a parameter (property).

Agg::trans_single_path of rendered text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.